There is a high wall between Java and C + + that is surrounded by dynamic memory allocation and garbage collection techniques. People outside the wall want to go in, the people inside the wall want to go out.
1.java Memory Distribution
Program counter
Stacks (local variables, operands, dynamic links, method exits)
Each method from the call until the completion of the process, corresponding to a stack frame in the virtual machine stack into the stack of the process. The memory space required for local variables is allocated at compile time, and when entering a method, this method needs to allocate how much local variable space in the frame is fully deterministic. The size of the local variable table is not changed while the method is running.
Heap (storing object instances and arrays, also known as GC heaps)
Method area
Stores the class information, constants, static variables, and immediate compiler-compiled code data that have been loaded by the virtual machine.
2. Heap allocation method
Pointer collisions (Bump the Pointer) for garbage collection using compact policies
Idle lists (free list)
3. Object memory allocation synchronization policy
Synchronizing Memory Allocations
Tlab (local thread allocation buffer, each thread has its own buffer and only synchronizes when the buffer has been redistributed)
4. Object Space
Object header (run-time data for the object itself: Hashcode, GC generational age, lock State ...) Class meta data)
Instance data
Snap To fill
5. Object access and positioning
Using handles
Direct pointer
6. Garbage Collection Strategy
Tag-purge policy
Replication Algorithms
Tagging-sorting algorithms
7. Garbage collector
- Serial "is a single-threaded, Stop-the-world, collector using the replication algorithm.
- "Parnew" is a multi-threaded, Stop-the-world, using the copy algorithm of the collector. Unlike "Parallel scavenge", it can be used with the "CMS" collector. For example, "Parnew" does the synchronization required so that it can continue running in the concurrency phase of the CMS.
- "Parallel Scavenge" is a multi-threaded, Stop-the-world, replication algorithm collector.
- "Serial old" is a single-threaded, Stop-the-world, use tag-purge-compress collector.
- The "CMS" (Concurrent Mark Sweep) is a concurrent, short-stop collector.
- "Parallel old" is a multi-threaded, collector using the compression algorithm.
http://ifeve.com/our_collectors/
Java Memory Management