Java performance involves many things. I always wanted to write a summary.
In the first part, we will introduce the class loader, which is mainly used to load the required classes when the Java virtual machine is running.
I. These classes have two parts: one is the Java class in your application, and the other is the class file in Java API. The loader has two important tasks:
1. Loading: locate a class and import its binary data representation.
2. Linking: perform verification, preparation, and possible parsing.
Verify: ensure that the import type is correct
Preparation: Prepare sufficient memory for the class variables and initialize the corresponding variables.
Resolution: changes from symbolic reference to direct reference, and loads all classes referenced by this class.
Ii. Default class loader in JVM:
1. $ java_home/JRE/lib/RT. jar is loaded by bootstrap Class Loader:
Note: Sun/MISC/launcher $ extclass, Sun/MISC/launcher $ appclass
It is the root class loader of all class loaders.
2. extention Class Loader:
Source: $ java_home/JRE/lib/EXT/*. Jar
3. system class loader. At this level, the class in the User-Defined $ classpath is loaded.
The user-defined classloader is a sub-class loader of system class loader.
Iii. class loading sequence:
1. First, search from the loaded cache. If it has been loaded, return
2. Load (recursive search) from the parent classloader to ensure that all classes in the API are loaded by bootstrap class loader.
3. If 2 cannot be found, use the current classloader for loading.
This also shows that a class loader can only see its ancestor class loader and its own loaded class. The class loaded by the sub-class loader is invisible.
System class loader can be obtained through Cl. getsystemclassloader.
4. Specify the system classloader parameters:
Boot class path (bootstrap cl)
-Xbootclasspath: <dir | zip | jar separated by; or:>
-Xbootclasspath:/a (append to the end)
-Xbootclasspath:/P (prepend to the front)
Extention class path (extention cl)
-Djava. Ext. dirs = <dir | zip | jar separated by; or:>
System class path (system cl)
-CP or-classpath <dir | zip | jar separated by; or:>
-Djava. Class. Path = <dir | zip | jar separated by; or:>
5. explicit and implicit Loading
1. Explicit mode:
Cl. loadclass () (Cl is an instance of Java. Lang. classloader)
Class. forname () (the current classloader is the start classloader)
2. Implicit mode:
When it is used as a reference, the class is instantiated, and an inheritance relationship is generated, JVM will perform necessary parsing and load the class
Therefore, classloader explicitly loads a class and implicitly loads all its reference classes.
6. classloader tracking information:
Java-verbose: Class (class loading)
Java-verbose: GC (GC output)
Java-verbose: JNI (JNI output)
7. Path in classloader
Urlclassloader L = new urlclassloader (new URL [] {new URL ("file: // D:/eclipse3.1/workspace/testclass /")});
Urlclassloader L = new urlclassloader (new URL [] {new URL ("file: // D:/eclipse3.1/workspace/testclass ")});
End with '/', indicating the directory path. All the classes below can be loaded. If it is not ended with '/', it means it is a jar or ZIP file.
The classloader of the parent class of the subclass must be the classloader of the subclass or the ancestor classloader. Classes of the same name loaded by different classloader cannot be cast to each other.
Obtain information about the current JVM thread Stack:
Windows:
CTRL + break
Unix/Linux:
CTRL +/
Kill-Quit <pid>
Kill-sigquit <pid>
References:
Inside the Java Virtual Machine
Demystifying class Loading Problems
Http://www-128.ibm.com/developerworks/java/library/j-dclp1/index.html
Java platform performance: strategies and tactics
Http://java.sun.com/docs/books/performance/1st_edition/html/JPTitle.fm.html
Http://www.javaperformancetuning.com/tips/nio.shtml