Object Creation

Creation process:

After receiving new instructions,

1. Check whether the referenced class is loaded represented, parsed, initialized, if not, executing the class loading mechanism (loading mechanism can be determined based on memory size);

2. allocate memory

  Two Distribution

    Pointer collision (Bump the Pointer)

      - pointer collision means: java heap regular (i.e., the function uses a compression algorithm with a finishing garbage collector, such as: Serial, ParNew with other collectors Compact process) in the case,

              To allocate an object is the movement of the pointer to the idle memory space, the moving distance equal to the size of the object;

    Free list (Free List)

      - free list means: java heap irregular (i.e., the garbage collector without using a compression algorithm housekeeping functions, such as: Based on Mark-Sweep collector algorithm CMS etc.) in the case,

              Need to have a table to record the piece is empty, how much size, so as to find a space of sufficient size to allocate memory when allocating memory for the object;

  Thread-safety issues:

    Since the java runtime, create an object of the operation is very frequent

    JVM thread in order to avoid conflict operations in two ways:

        A dispensing sync memory operation;

        Second, each thread a small piece of pre-allocated heap memory in java, this small piece of memory called thread-local allocation buffer (Thread Local Allocation Buffer, TLAB), which thread needs to allocate memory to create an object allocated on the corresponding TLAB , assign a new TLAB when TLAB runs out, will sync lock;

          JVM whether TLAB, by -XX: +/- UseTLAB parameter set;

3. Set which this object is an instance of the class, how to find information such as metadata, hash object do, GC target sub-information-generation age. This information is stored in the object header object.

Guess you like

Origin www.cnblogs.com/zhushaolong/p/11361028.html