CN-116302349-B - Method for accelerating Java application program starting speed and related components thereof
Abstract
The application discloses a method for accelerating the starting speed of Java application programs and related components, which are applied to the technical field of Java virtual machines and comprise the steps of loading and analyzing target class files acquired from a disk by using a target class loader to generate klass objects, enabling the target class loader to be any one of a guide class loader, an extension class loader and an application program class loader, if klass objects can be shared, writing full-limited names of the target class loader into a preset sharing list, reading the preset sharing list, loading corresponding class files so as to write corresponding class data into the preset archive files, mapping the preset archive files into a memory in the starting process of the Java application programs, acquiring target class data corresponding to class loading operation from the memory after class loading operation is triggered, and updating a system dictionary by using the target class data. The class sharing range of CDS characteristics is enlarged, and the starting speed of the application program is improved.
Inventors
- XIN HUA
- ZHANG QI
- LI CHENGHONG
- CHEN MINGJIE
- YANG GUOMING
- Hao Mingkang
- WANG SHUANG
Assignees
- 南方电网数字电网研究院有限公司
Dates
- Publication Date
- 20260505
- Application Date
- 20230317
Claims (8)
- 1. A method for accelerating the starting speed of Java application programs is characterized by being applied to a Java virtual machine and comprising the following steps: Obtaining a target class file from a disk, and loading and analyzing the target class file by using a target class loader to generate a corresponding klass object, wherein the target class loader is any one kind of loader of a guide class loader, an extension class loader and an application program class loader; Judging whether the klass objects can be shared or not, if so, writing the full-limit names of the target class files into a preset sharing list; Reading the preset sharing list, and loading class files corresponding to each full-limit name so as to write corresponding class data into preset archive files; mapping the preset archive file into a memory in the starting process of a java application program, so that after class loading operation is triggered, target class data corresponding to the class loading operation is obtained from the memory, and a system dictionary is updated by using the target class data; The obtaining the target class data corresponding to the class loading operation from the memory, and updating the system dictionary by using the target class data includes: Determining a target klass object corresponding to the class loading operation, and judging whether target class data corresponding to the target klass object exists in the memory; If so, acquiring the target class data from the memory, and updating a system dictionary by using the target class data; If not, taking the class file corresponding to the class loading operation as a target class file; And re-jumping to the step of acquiring the target class file from the disk, loading and analyzing the target class file by using a target class loader to generate a corresponding klass object until target class data corresponding to the class loading operation is acquired from the memory, and updating a system dictionary by using the target class data.
- 2. The method for accelerating the start-up of a Java application according to claim 1, wherein said loading and parsing the target class file with the target class loader to generate the corresponding klass objects comprises: And determining a corresponding target class loader based on the directory information and the path information of the target class file so as to load and analyze the target class file by using the target class loader to generate a corresponding klass object.
- 3. The method for speeding up the start of a Java application according to claim 1, wherein the determining whether the klass objects can be shared comprises: A determination is made as to whether the klass objects can be shared based on a sharing class of the system dictionary.
- 4. The method for accelerating the start-up of a Java application according to claim 1, wherein after said determining whether said klass objects can be shared, further comprising: If not, judging that the full-limit name of the target class file cannot be written into a preset sharing list.
- 5. The method for accelerating the start-up speed of a Java application according to claim 1, wherein the reading the preset sharing list and loading the class file corresponding to each of the fully qualified names so as to write the corresponding class data into the preset archive file comprises: And reading the full-limit names in the preset sharing list, loading class files corresponding to each full-limit name until all the class files are loaded, and writing corresponding class data into preset archive files.
- 6. An apparatus for accelerating the starting speed of a Java application, which is applied to a Java virtual machine, comprising: The file loading module is used for acquiring a target class file from a disk, and loading and analyzing the target class file by utilizing a target class loader to generate a corresponding klass object, wherein the target class loader is any one kind of loader of a guide class loader, an extension class loader and an application program class loader; the judging module is used for judging whether the klass objects can be shared or not, if yes, writing the full-limit names of the target class files into a preset sharing list; The archive file writing module is used for reading the preset sharing list, and loading class files corresponding to each full-limit name so as to write corresponding class data into the preset archive file; The mapping module is used for mapping the preset archive file into a memory in the starting process of the java application program so as to acquire target class data corresponding to class loading operation from the memory after class loading operation is triggered, and updating a system dictionary by utilizing the target class data; The mapping module is specifically configured to determine a target klass object corresponding to the class loading operation, determine whether target class data corresponding to the target klass object exists in the memory, acquire the target class data from the memory and update a system dictionary using the target class data if the target class data exists, and re-jump to the step of acquiring the target class file from the disk and loading and analyzing the target class file by using a target class loader to generate a corresponding klass object if the target class data corresponding to the class loading operation does not exist, and then update the system dictionary using the target class data.
- 7. An electronic device, comprising: A memory for storing a computer program; A processor for executing the computer program to implement the steps of the method for accelerating the start-up speed of a Java application according to any one of claims 1 to 5.
- 8. A computer readable storage medium for storing a computer program, wherein the computer program when executed by a processor implements the steps of the method for accelerating the start-up of a Java application according to any one of claims 1 to 5.
Description
Method for accelerating Java application program starting speed and related components thereof Technical Field The present invention relates to the field of computer technologies, and in particular, to a method, an apparatus, a device, and a medium for accelerating a Java application program start speed. Background Under the trend that the volume of the current application program is larger and larger, the service scene of the application program is complex, rich service functions are included, the deployment package depends on more third-party technologies and service components, and the volume is larger. In the starting process of the application program, a great number of third-party dependencies need to be traversed and searched to complete the class loading process, and the class loading process is longer due to more dependent JAR (Java ARCHIVE FILE) packages, so that the starting time of the application program is long, and the starting time of the application program needs to be shortened urgently. When a certain class is needed by the JVM (Java Virtual Machine, i.e., the Java virtual machine), the JVM finds the class file from the disk, loads the class file, verifies the bytecode file, prepares, parses, initializes, and loads the class file into the memory according to its internal data structure, where the class can be used, but the process takes a lot of time, and when the application program is larger and more classes need to be loaded, each class takes a lot of time through class loading steps, so that the starting speed of the application program is reduced. For packed JAR packets, the data of the class in the JAR packet is always the same as long as the content of the JAR packet is unchanged. The JVM runs the same loading step each time it is started, consuming a lot of time. JDK has performed related work on how to shorten the startup time of an application, introducing CDS (Class-DATA SHARING, class data sharing) features. The CDS characteristic of the JDK is that the JVM only performs loading, linking and initializing actions once, and then class data is dumped into a file. When a certain class needs to be loaded after the JVM is started, the JVM searches the needed class from a dumped file, and the needed class data in the dumped file is loaded into a JVM memory if the re-execution class loading process is not found. However, current CDS technology only supports classes loaded by Bootstrap classloader (boot class loader) and Ext Classloader (extension class loader), with limited application launch speed boost. In summary, how to further increase the starting speed of the application is a problem to be solved at present. Disclosure of Invention Accordingly, the present invention is directed to a method, apparatus, device and medium for accelerating the starting speed of a Java application, which can further accelerate the starting speed of the application. The specific scheme is as follows: In a first aspect, the present application discloses a method for accelerating the starting speed of a Java application, which is applied to a Java virtual machine, and includes: Obtaining a target class file from a disk, and loading and analyzing the target class file by using a target class loader to generate a corresponding klass object, wherein the target class loader is any one kind of loader of a guide class loader, an extension class loader and an application program class loader; Judging whether the klass objects can be shared or not, if so, writing the full-limit names of the target class files into a preset sharing list; Reading the preset sharing list, and loading class files corresponding to each full-limit name so as to write corresponding class data into preset archive files; And mapping the preset archive file into a memory in the starting process of the java application program, so that after class loading operation is triggered, target class data corresponding to the class loading operation is obtained from the memory, and a system dictionary is updated by using the target class data. Optionally, the loading and parsing the target class file by using a target class loader to generate a corresponding klass object includes: And determining a corresponding target class loader based on the directory information and the path information of the target class file so as to load and analyze the target class file by using the target class loader to generate a corresponding klass object. Optionally, the determining whether the klass objects can be shared includes: A determination is made as to whether the klass objects can be shared based on a sharing class of the system dictionary. Optionally, after the determining whether the klass objects can be shared, the method further includes: If not, judging that the full-limit name of the target class file cannot be written into a preset sharing list. Optionally, the reading the preset sharing list, and loading a class file corresponding to each full-defi