Flow of class loading for a simple program

后端 未结 5 2156
说谎
说谎 2020-12-02 04:28

I am just now beginning to learn the internal architecture of Java. I have roughly understood the concept of class loading which loads the required classes when jvm

5条回答
  •  甜味超标
    2020-12-02 05:12

    JVM maintains a runtime pool in permgen area where classes are loaded. Whenever a class is referenced default class loader finds the class in the class path and loads it into this pool. And this is not specific to user defined classes or classes provided in JDK. When a class is referenced it is loaded into the memory.

    Classes loaded by the ClassLoader are stored internally in the ClassLoader instance

    // The classes loaded by this class loader. The only purpose of this table
    // is to keep the classes from being GC'ed until the loader is GC'ed.
    private final Vector> classes = new Vector<>();
    

    When class needs to be added to the memory following function is called:

    // Invoked by the VM to record every loaded class with this loader.
    void addClass(Class c) {
        classes.addElement(c);
    }
    

    Found a useful diagram on how Class Loaders work.

    enter image description here

提交回复
热议问题