the class inspection in JVM

来源:互联网 发布:哪里购买淘宝店铺 编辑:程序博客网 时间:2024/05/16 11:42
before the Java classloader begin to excute a class file, it will need to check out the file four times.
1.check the structure of the file
 the first inspection happen before the class was loaded. JVM will check the Magic number 0XCAFEBABE to make sure it load a Java class file. Then it will check the main version and sub version to ensure the JVM can support it.
also JVM will check the type and length of all parts of the class file.
2.check the semantic of the type data
 this phrase happen in the link stage. it will check all parts of the file. the inspection will detect the structures. also it will make sure that the class file observes the java language specification
3.byte code inspection
 in this phrase the jvm will analyse the byte code stream via data graph. it is excuted in the link stage. for example, the jvm will ensure that operate stack contains the correct value and type, the local param has been evaluated before using, and in the class field it contains the rigth type, when a method was called, it pass the right value and type param. the bytecode inspection also will ensure that every operation should be legal.
4.symbol reference inspection
in the dynamic link stage, if a symbol reference including in one class file is resolving, the jvm will trace such reference to make sure it is correct. if the jvm find that the class which the referenc point to can not be loaded it will throw a NoClassDefFoundError exception. if not, the jvm will load the class if necessary and then replace the symbol reference with direct reference.