object creation

  1. create object

    1. Like in the Spring framework, classes are generally singletons, and it will be judged whether they have been created before they are created. If it is not created, or the scope is not a singleton, a new object will be created.
  2. binary byte stream in class format

    1. class specifies the format of bytes.
    2. Can be obtained from files, networks, databases, other files.
  3. Need to detect whether the class is loaded at runtime

    1. How to judge? current class loader -> parent delegation model
    2. Determine whether the class is loaded according to the class loader
    3. Are the two classes the same
      1. The class loader is the same
      2. The fully qualified name of the class matches
  4. How to load, usually classloader

    1. The parent delegation model, in order to ensure that the class is the same and not loaded repeatedly
      1. Check if you have loaded it first. no, next step
      2. Do not load it yourself first, delegate the loading class loading of the combination.
      3. If you can't load it, just load it yourself
      4. At the top is the Boostrap class loader -- only recognizes certain classes
    2. Destruction of the model
      1. proposed after the model, so
      2. The more basic class is loaded by the upper loader. If the basic class needs to call back the user's code, bootsrap will scan it in time and will not load it, so it has to entrust the subclass loader (thread context class loader) to load.
        1. SPI,JDBC
      3. Introduce OSGI.
        1. Modular hot deployment. Each module has its own classloader
        2. Certain classes are handed over to the parent class loader, and the rest are either loaded by themselves or handed over to the peer class loader
  5. load class

    1. verify
    2. Preparation - allocate method area memory constant pool, set the zero value of class variable
    3. Classes involved in parse loading - along with validation
    4. Class initialization, initializing class variables: static modules, etc.
    5. Java types that can be used directly by the virtual machine
  6. Allocate memory - heap object memory

  7. set zero value

  8. Set object header, class information, GC age range

  9. Initialize instance variables, etc.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325154454&siteId=291194637