Java Virtual Machine - 2.3 HotSpot virtual machine object

 

Creating objects

Step1 class loading inspection

When they find a new instruction, check:

  1. Whether the parameters of the instruction can locate the symbols in a reference to the class constant pool;
  2. This symbolic references and checks on behalf of the class has already been loaded, parsed and initialized. If not, then you must perform the appropriate class loading process.

 

Step2 allocate memory for the new object is

Object required memory size can be fully established after the class has finished loading. There are two ways of distribution, the choice of which distribution of regular java heap whether the decision; and whether regular java heap and used by the garbage collector with or without compression decided to organize functions.

Two Distribution:

  1. Pointer collision (Bump the Pointer): structured memory
  2. Free list (Free List): Memory irregularities

 

Step3 how to allocate memory to ensure the security thread

Two options:

  1. All memory allocation operation to synchronize. (Not recommended)
  2. Each thread is assigned in advance a small java heap memory, called the local cache assigned thread (Thread Local Allocation Buffer, TLAB). Each thread will first allocate memory in TLAB inside, this operation without synchronization. Only when TLAB runs out and assign a new TLAB, only need to synchronize locked. Virtual machine using TLAB, by -XX: +/- UseTLAB to set the parameters.

 

Step4 initialized to zero value

Assigned to the virtual machine memory is initialized to zero value (not including the object header). If you were using TLAB, this step can be assigned to TLAB advance.

It ensures that the object instance field may not be assigned an initial value can be used directly.

 

Step5 necessary to set the object header

For example, this object is an instance of the class which, like how to find metadata, hash code objects, GC generational age and whether to enable biased locking ...

 

 

Step6 performed <init> method

All values ​​are the values ​​of zero before <init> execution. After the implementation of new instructions, will then execute <init>, the initialization of the objects as a programmer.

 

Guess you like

Origin www.cnblogs.com/frankcui/p/10969248.html