JVM load principle

xiaoxiao2021-04-04  250

JVM load principle

The operating system is completed through JVM in JDK, complete the JVM environment by step 4 below. 1. Create a JVM load environment and configuration 2. Load JVM.DLL3. Initialize Jvm.dll and hang it to Jnienv (JNi Call Interface) Instance 4. Call the Jnienv instance to load and process the Class class.

When we run and debug Java programs, it is often mentioned to a JVM concept. JVM is an environment running in the Java program, but he also has an application of an operating system, so he also has his own life cycle. There are also your own code and data space. First, come on the taste of JDK, whether you are a beginner or a master, is a J2EE programmer or a J2SE programmer, JDK is always helping us do something. We are learning Java first Masters will provide us with JDK this. It acts as a role in the entire system of Java? I am very exclaimed that Sun Masters designed genius, can make such a complete system structure so perfect. JDK in this system Act as a production and machining center, generating all data outputs, is the execution center of all instructions and strategies. Itself provides Java's full solution that can develop all applications and system programs that Java can support. Say a problem, everyone will Asked, why is there any J2ME, J2EE these things, these two things are simple, used to simplify the development and construction process in their respective fields. JDK In addition to JVM, there are some core APIs, integrated APIs, users The tool, development technology, development tools and APIs are well formed. There are so many nonsense, come to the topic related things. JVM is in the bottom of the JDK, responsible for the interaction of the operating system, used to block the operating system The environment provides a complete Java operating environment, so it is also a virtual computer. The operating system is completed through java.exe in JDK, and the JVM environment is completed by step 4. 1. Create a JVM loading environment and configuration 2. Load JVM.DLL3. Initialize JVM.dll and pending the JNIENV (JNI Call Interface) Instance 4. Call the JNIENV instance to load and process the Class class. One. The JVM load environment, the way JVM is provided is the dynamic connection file of the operating system. Since it is a file, how do Java find this path? When you call Java Test, the operating system will be in your Java.exe program in Path, Java.exe is configured by the following procedure to determine the path of the JVM and the relevant parameters. The following is an analysis of Windows implementation. First find the JRE path, Java is the current Java.exe absolute path through the GetApplicationHome API, C: /J2SDK1.4.2_09/bin/java.exe, then it will intercept to the absolute path C: /J2SDK1.4.2_09/, Judging whether the C: /J2SDK1.4.2_09/bin/java.dll file exists, if there is a C: /J2SDK1.4.2_09/ as the JRE path, if there is no existence, it is judged C: /J2SDK1.4.2_09/JRE/bin /java.dll exists, if this C: /J2SDK1.4.2_09/jre is the JRE path. If there is no call getPublicjrehome check hkey_local_machine / software / javasoft / java runtime environment / "Current JRE version number" / javahome's path is JRE path. Then load the JVM.cfg file JRE path / lib / arch (CPU architecture) / jvm.cfgarch (CPU architecture) is judged by java_md.c, only two of the Windows platforms in this function: Win64 The 'IA64', which is the 'i386'.

Taking me as an example: c: /j2sdk1.4.2_09/jRE/LIB/i386/jvm.cfg. The main content is as follows: -client known-server known-hotspot aliased_to -client-classic warn-native error-Green Error In our JDK directory, JRE / BIN / Server and JRE / BIN / Client have a jvm.dll file, while Java is managing these different versions of JVM.dll through a JVM.cfg profile. Through the file we can define those JDKs to support those JVMs, the front section is the JVM name, the back is the parameter, and the known represents the existence of JVM. AliaSed_to means a separate alias, WARN means a JVM alternative, Error said there is no abnormality. In running Java XXX, Java.exe will check the current JVM type by checkjvmtype. Java can specify a specific JVM type by two parameters, and specify the JVM name in the jvm.cfg file, the second The method is to specify directly that the methods they perform are "java -j", "java -xxaltjvm =" or "java -j-xxaltjvm =", respectively. If it is the first parameter transmission method, the checkjvmtype function takes the JVM name behind the parameter '-j', and then finds the JVM name before you find the same name, the '-' before you find the JVM name directly. Value; and the second method, it will return directly "-xxaltjvm =" or "-j-xxaltjvm =", the JVM type name; if you do not specify any of the two methods in the two methods when running Java, CheckJVMTYPE The JVM name in the first configuration in the configuration file is taken, and the '-' of the previous name returns to this value. This return value of the CheckJVMTYPE function will match the absolute path of JVM.dll in the following functions. If this is not specified, this will use the first JVM in JVM.cfg. You can test it over the console via set _java_launcher_debug = 1. Finally, the path of JVM.dll, JRE path / bin / jvm type string / jvm.dll is the file path of the JVM, but if the path specified by the -xxaltjvm = parameter is used when calling the Java program, it is directly The PATH / JVM.DLL file is a file path for JVM.DLL. Two: Loading JVM.dll The JVM path has been found through the first step, and Java is loaded into the jvm.dll file through LoadJavava. The load is very simple to call the Windows API function: loadLibrary loads the JVM.dll dynamic connection library. Then put the export function JNI_CREATEJAVAVM and JNI_GETDEFAULTJAVAVMINITARGS in JVM.dll to the createJavAVM and getDefaultjavavMinitargs function pointer variables in the invocationFunctions variable. JVM.DLL load work declares completed.

Three: Initializing the JVM, get a local call interface, so you can call the JVM function in Java. Calling InvocationFunctions-> CreateJavavm is also an instance of JNI_CREATEJAVAVM method to get JNIENV structures in JVM. 4: Run the Java program. There are two ways of java programs, one is Class. When running jar, java -jar xxx.jar runs, java.exe calls the getMainClassName function, the function gets the JNIENV instance and then call Java class java.util .jar.jarfilejnienv method getManifest () and getting the value of GetAttributes ("main-class" in the returned Manifest object: MAIN-Class's main class name of MAIN-CLASS as specified by MAIN-INF / Manifest.mf Run the primary class. Then the main function will call the LoadClass method in java.c to load the main class (FindClass using the JNIENV instance). The main function is directly called Java.c loadClass method to load the class. If it is a Class method. The main function is directly called Java.c loadClass method to load the class. The main function calls the jnienv instance's getStaticMethodID method to find the "public static void main (string [] args) method in the loaded Class primary class, and determine if the method is a public method, then call the JAVA class. MAIN method.

转载请注明原文地址:https://www.9cbs.com/read-131851.html

New Post(0)