Methods and related components for speeding up Java application startup
By introducing target class loaders and archive file mapping technology into the Java Virtual Machine, the problem of excessively long startup time for Java applications was solved, and the class loading process was optimized and startup speed was improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SOUTHERN POWER GRID DIGITAL GRID RESEARCH INSTITUTE CO LTD
- Filing Date
- 2023-03-17
- Publication Date
- 2026-05-05
AI Technical Summary
In existing technologies, the startup time of Java applications is relatively long, mainly due to the time-consuming class loading process. This is especially true when the application is large, as the JVM needs to load and verify a large number of class files, which limits the startup speed.
By introducing the target class loader into the Java Virtual Machine, generating a klass object, determining whether it is shareable, writing the fully qualified name to the shared list, loading the class file into the archive file, mapping the archive file into memory when the application starts, and updating the system dictionary, the number of class loading steps is reduced.
It expands the scope of class sharing, significantly improves the startup speed of Java applications, and shortens startup time.
Smart Images

Figure CN116302349B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method, apparatus, device, and medium for accelerating the startup speed of Java applications. Background Technology
[0002] With the increasing size of applications, their complex business scenarios, rich functionalities, and numerous dependencies on third-party technologies and business components contribute to their large size. During application startup, a large number of third-party dependencies need to be traversed to complete the class loading process. Due to the large number of dependent JAR (Java Archive File) packages, the class loading process is lengthy, resulting in a significant increase in application startup time. Therefore, there is an urgent need to shorten application startup time. When the JVM (Java Virtual Machine) needs to use a class, it locates the class file on disk, loads it, verifies the bytecode file, prepares, parses, initializes, and loads it into memory according to its internal data structure before the class can be used. However, this process consumes a significant amount of time. When the application is large and requires loading many classes, each class loading step takes considerable time, slowing down the application startup. For packaged JAR files, as long as the content of the JAR file remains unchanged, the class data within the JAR file is always the same. The JVM runs the same loading steps every time it starts, consuming a significant amount of time. The JDK has already done work on how to shorten application startup time by introducing the CDS (Class-Data Sharing) feature.
[0003] The current JDK's CDS feature allows the JVM to perform only one loading, linking, and initialization operation, then dumps the class data to a file. When the JVM starts and needs to load a class, it first searches for the required class in the dump file. If the required class data is found in the dump file, it loads it into JVM memory; otherwise, it executes the class loading process. However, the current CDS technology only supports classes loaded by the Bootstrap classloader and the Ext Classloader, offering limited improvement to application startup speed.
[0004] In summary, how to further improve the startup speed of applications is a problem that needs to be solved. Summary of the Invention
[0005] In view of this, the purpose of this invention is to provide a method, apparatus, device, and medium for accelerating the startup speed of Java applications, thereby further improving the startup speed of applications. The specific solution is as follows:
[0006] In a first aspect, this application discloses a method for accelerating the startup speed of Java applications, applied to a Java Virtual Machine, comprising:
[0007] Obtain the target class file from the disk, and use the target class loader to load and parse the target class file to generate the corresponding klass object; wherein, the target class loader is any one of the bootstrap class loader, extension class loader, and application class loader;
[0008] Determine whether the klass object can be shared; if so, write the fully qualified name of the target class file into the preset sharing list.
[0009] Read the preset shared list and load the class file corresponding to each of the fully qualified names so that the corresponding class data can be written to the preset archive file;
[0010] During the startup process of a Java application, the preset archive file is mapped into memory so that after a class loading operation is triggered, the target class data corresponding to the class loading operation can be retrieved from the memory, and the system dictionary can be updated using the target class data.
[0011] Optionally, the step of loading and parsing the target class file using the target class loader to generate the corresponding klass object includes:
[0012] The corresponding target class loader is determined based on the directory and path information of the target class file, so that the target class file can be loaded and parsed using the target class loader to generate the corresponding klass object.
[0013] Optionally, determining whether the klass object can be shared includes:
[0014] The system dictionary's shared class determines whether the klass object can be shared.
[0015] Optionally, after determining whether the klass object can be shared, the method further includes:
[0016] If not, it is determined that the fully qualified name of the target class file cannot be written to the preset shared list.
[0017] Optionally, reading the preset shared list and loading the class file corresponding to each fully qualified name to write the corresponding class data to the preset archive file includes:
[0018] Read the fully qualified names from the preset shared list and load the class file corresponding to each fully qualified name until all class files are loaded, then write the corresponding class data to the preset archive file.
[0019] Optionally, the step of retrieving the target class data corresponding to the class loading operation from the memory and updating the system dictionary using the target class data includes:
[0020] Determine the target klass object corresponding to the class loading operation, and determine whether target class data corresponding to the target klass object exists in the memory;
[0021] If it exists, the target class data is retrieved from the memory, and the system dictionary is updated using the target class data.
[0022] Optionally, after determining whether target class data corresponding to the target klass object exists in the memory, the method further includes:
[0023] If it does not exist, the class file corresponding to the class loading operation will be used as the target class file;
[0024] The process jumps back to the step of retrieving the target class file from the disk and using the target class loader to load and parse the target class file to generate the corresponding klass object, until the target class data corresponding to the class loading operation is retrieved from the memory, and then the system dictionary is updated using the target class data.
[0025] Secondly, this application discloses an apparatus for accelerating the startup speed of Java applications, applied to a Java Virtual Machine, comprising:
[0026] The file loading module is used to obtain the target class file from the disk, and use the target class loader to load and parse the target class file to generate the corresponding klass object; wherein, the target class loader is any one of the bootstrap class loader, extension class loader and application class loader;
[0027] The judgment module is used to determine whether the klass object can be shared. If so, the fully qualified name of the target class file is written into the preset sharing list.
[0028] The archive file writing module is used to read the preset shared list and load the class file corresponding to each of the fully qualified names, so as to write the corresponding class data to the preset archive file;
[0029] The mapping module is used to map the preset archive file into memory during the startup process of the Java application, so that after the class loading operation is triggered, the target class data corresponding to the class loading operation can be obtained from the memory, and the system dictionary can be updated using the target class data.
[0030] Thirdly, this application discloses an electronic device, including:
[0031] Memory, used to store computer programs;
[0032] A processor for executing the computer program to implement the steps of the aforementioned disclosed method for accelerating the startup speed of Java applications.
[0033] Fourthly, this application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the steps of the aforementioned disclosed method for accelerating the startup speed of Java applications.
[0034] As can be seen, this application obtains the target class file from the disk through the Java Virtual Machine and loads and parses the target class file using a target class loader to generate the corresponding klass object. The target class loader can be any one of the bootstrap class loader, extension class loader, and application class loader. It determines whether the klass object can be shared; if so, it writes the fully qualified name of the target class file into a preset sharing list. It reads the preset sharing list and loads the class file corresponding to each fully qualified name to write the corresponding class data to a preset archive file. During the Java application startup process, the preset archive file is mapped into memory so that after a class loading operation is triggered, the target class data corresponding to the class loading operation is retrieved from memory, and the system dictionary is updated using the target class data. Therefore, this application, in addition to supporting classes loaded by the bootstrap class loader and extension class loader, also adds classes loaded by the application class loader, expanding the class sharing scope of the CDS feature, significantly increasing the number of classes that can be dumped, and significantly improving the application startup speed. After the Java Virtual Machine (JVM) retrieves the target class file from the disk, it uses the corresponding target class loader to record and parse it, dumping the corresponding class data into a pre-defined archive file. During Java application startup, the pre-defined archive file is directly mapped into memory, and the target class data corresponding to the current class loading operation is retrieved from memory. This target class data is then used to update the system dictionary. This process eliminates the need to reload the class file to obtain the corresponding class data, reducing class loading steps, shortening application startup time, and improving application startup speed. Attached Figure Description
[0035] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0036] Figure 1 This application discloses a flowchart of a method for accelerating the startup speed of Java applications;
[0037] Figure 2 This is a flowchart illustrating a method for accelerating the startup speed of Java applications disclosed in this application;
[0038] Figure 3 This application discloses a flowchart for generating an LST file;
[0039] Figure 4 This application discloses a flowchart of a specific method for accelerating the startup speed of Java applications;
[0040] Figure 5 This application discloses a flowchart for generating a JSA archive file;
[0041] Figure 6 This application discloses a flowchart for using a JSA archive file;
[0042] Figure 7 This is a schematic diagram of a device structure for accelerating the startup speed of Java applications disclosed in this application;
[0043] Figure 8 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation
[0044] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.
[0045] The current JDK's CDS feature allows the JVM to perform only one loading, linking, and initialization operation, then dumps the class data to a file. When the JVM starts and needs to load a class, it first searches for the required class in the dumped file. If the required class data is found in the dumped file, it loads it into JVM memory; otherwise, it executes the class loading process. However, the current CDS technology only supports classes loaded by the Bootstrap classloader and Ext Classloader, offering limited improvement to application startup speed. Therefore, this application discloses a method, apparatus, device, and medium to accelerate Java application startup, further improving application startup speed.
[0046] See Figure 1 and Figure 2 As shown in the figure, this application discloses a method for accelerating the startup speed of Java applications, applied to a Java Virtual Machine, the method comprising:
[0047] Step S11: Obtain the target class file from the disk, and use the target class loader to load and parse the target class file to generate the corresponding klass object; wherein, the target class loader is any one of the bootstrap class loader, extension class loader, and application class loader.
[0048] In this embodiment, when the Java Virtual Machine (JVM) needs to use a certain class, it locates and retrieves the target class file from the disk. After being loaded and parsed by the target class loader, a corresponding klass object is generated. For example... Figure 3 As shown, the target class loader can be any one of the bootstrap class loader, extension class loader, and application class loader. That is, in addition to supporting classes loaded by the bootstrap class loader and extension class loader, this application also adds classes loaded by the application class loader, expanding the class sharing scope of CDS features, significantly increasing the number of classes that can be dumped, and significantly improving application startup speed.
[0049] Step S12: Determine whether the klass object can be shared. If so, write the fully qualified name of the target class file into the preset sharing list.
[0050] In this embodiment, determining whether the klass object can be shared specifically includes: judging whether the klass object can be shared based on the shared classes in the system dictionary. That is, this embodiment determines whether the klass object can be shared by checking the shared classes in the system dictionary. If the klass object can be shared, the fully qualified name of the target class file is written into a preset sharing list, where the preset sharing list is specifically an .lst file. In other words, the above scheme can write shareable classes into an .lst file to generate the .lst file.
[0051] Furthermore, after determining whether the klass object can be shared, the process further includes: if not, determining that the fully qualified name of the target class file cannot be written to the preset sharing list. That is, if the klass object cannot be shared, determining that the fully qualified name of the target class file cannot be written to the preset sharing list, meaning that dumping cannot be performed.
[0052] Step S13: Read the preset shared list and load the class file corresponding to each fully qualified name so as to write the corresponding class data to the preset archive file.
[0053] In this embodiment, the Java Virtual Machine (JVM) reads a preset shared list, i.e., the contents of the .lst file, and then loads the class file corresponding to each fully qualified name. After the class is loaded, the SystemDictionary is updated, and the JVM writes its corresponding data into memory, and then dumps this data to a preset archive file, specifically a JSA archive file. That is, the above method can record the class data in the .lst file into the JSA archive file and generate the JSA archive file.
[0054] Step S14: During the Java application startup process, the preset archive file is mapped into memory so that after the class loading operation is triggered, the target class data corresponding to the class loading operation is obtained from the memory, and the system dictionary is updated using the target class data.
[0055] In this embodiment, during the Java application startup process, the Java Virtual Machine (JVM) maps the JSA archive file into memory. After the class loading operation is triggered, the JVM first retrieves the target class data corresponding to the class loading operation from this mapped memory, and then updates the system dictionary using the target class data. This process eliminates the need to reload class files to obtain the corresponding class data, reducing class loading steps, shortening application startup time, and improving application startup speed.
[0056] As can be seen, this application obtains the target class file from the disk through the Java Virtual Machine and loads and parses the target class file using a target class loader to generate the corresponding klass object. The target class loader can be any one of the bootstrap class loader, extension class loader, and application class loader. It determines whether the klass object can be shared; if so, it writes the fully qualified name of the target class file into a preset sharing list. It reads the preset sharing list and loads the class file corresponding to each fully qualified name to write the corresponding class data to a preset archive file. During the Java application startup process, the preset archive file is mapped into memory so that after a class loading operation is triggered, the target class data corresponding to the class loading operation is retrieved from memory, and the system dictionary is updated using the target class data. Therefore, this application, in addition to supporting classes loaded by the bootstrap class loader and extension class loader, also adds classes loaded by the application class loader, expanding the class sharing scope of the CDS feature, significantly increasing the number of classes that can be dumped, and significantly improving the application startup speed. After the Java Virtual Machine (JVM) retrieves the target class file from the disk, it uses the corresponding target class loader to record and parse it, dumping the corresponding class data into a pre-defined archive file. During Java application startup, the pre-defined archive file is directly mapped into memory, and the target class data corresponding to the current class loading operation is retrieved from memory. This target class data is then used to update the system dictionary. This process eliminates the need to reload the class file to obtain the corresponding class data, reducing class loading steps, shortening application startup time, and improving application startup speed.
[0057] See Figure 4 As shown, this application discloses a specific method for accelerating the startup speed of Java applications. Compared to the previous embodiment, this embodiment further explains and optimizes the technical solution. Specifically, it includes:
[0058] Step S21: Obtain the target class file from the disk, and determine the corresponding target class loader based on the directory information and path information of the target class file, so as to use the target class loader to load and parse the target class file to generate the corresponding klass object; wherein, the target class loader is any one of the bootstrap class loader, extension class loader and application class loader.
[0059] In this embodiment, the corresponding target class loader is determined based on the directory and path information of the target class file. For example, the bootstrap class loader is responsible for loading JAR files and classes in the %JAVA_HOME% / lib directory or all classes in the path specified by the -Xbootclasspath parameter; the extension class loader is mainly responsible for loading JAR files and classes in the %JRE_HOME% / lib / ext directory or JAR files in the path specified by the java.ext.dirs system variable; the application class loader is a user-oriented loader responsible for loading all JAR files and classes in the current application's classpath.
[0060] Step S22: Determine whether the klass object can be shared. If so, write the fully qualified name of the target class file into the preset sharing list.
[0061] Step S23: Read the fully qualified names in the preset shared list and load the class file corresponding to each fully qualified name until all class files are loaded, and then write the corresponding class data to the preset archive file.
[0062] In this embodiment, see Figure 5 As shown, the Java Virtual Machine (JVM) reads the contents of the .lst file and then loads the corresponding classes. After a class is loaded, the system dictionary is updated. Once all class files corresponding to the .lst file have been loaded, the JVM writes the corresponding class data to the JSA archive file.
[0063] Step S24: During the Java application startup process, the preset archive file is mapped into memory so that after the class loading operation is triggered, the target klass object corresponding to the class loading operation is determined, and it is determined whether there is target class data corresponding to the target klass object in the memory.
[0064] In this embodiment, see Figure 6 As shown, a pre-defined archive file is mapped into memory during the Java application startup process. After the class loading operation is triggered, the target klass object corresponding to the class loading operation is first determined, and then it is determined whether the target class data corresponding to the target klass object exists in memory, that is, whether the target class data corresponding to the target klass object can be retrieved from memory.
[0065] Step S25: If it exists, retrieve the target class data from the memory and update the system dictionary using the target class data.
[0066] In this embodiment, if target class data corresponding to the target klass object exists in memory, the target class data is directly retrieved from memory, and the system dictionary is updated using the target class data. That is, this embodiment does not require reloading the class file to obtain the corresponding class data. Instead, the class data is mapped to memory through the archive file and then retrieved directly from memory, thereby reducing the class loading steps, shortening the application startup time, and improving the application startup speed.
[0067] Furthermore, after determining whether target class data corresponding to the target klass object exists in the memory, the process further includes: if it does not exist, using the class file corresponding to the class loading operation as the target class file; re-jumping to the step of retrieving the target class file from the disk and using the target class loader to load and parse the target class file to generate the corresponding klass object, until the target class data corresponding to the class loading operation is retrieved from the memory, and then using the target class data to update the system dictionary. That is, if the corresponding target class data does not exist in memory, the normal class loading process is executed again, i.e., parsing, linking, initialization, etc. In other words, using the class file corresponding to the class loading operation as the target class file, re-jumping to the step of retrieving the target class file from the disk and using the target class loader to load and parse the target class file to generate the corresponding klass object, until the target class data corresponding to the class loading operation is retrieved from the memory, and then using the target class data to update the system dictionary.
[0068] For a more detailed description of the process of step S22, please refer to the relevant content disclosed in the foregoing embodiments, which will not be repeated here.
[0069] As can be seen, in this embodiment, after obtaining the target class file, the corresponding target class loader is determined based on its directory and path information, and then the target class loader is used to load and parse it. The target class loader includes not only the bootstrap class loader and extension class loader, but also the application class loader, thereby expanding the class sharing scope of CDS features, significantly increasing the number of classes that can be dumped, and significantly improving application startup speed. Furthermore, after the class data is written to the archive file, the archive file is mapped into memory during the Java application startup process. Thus, after the class loading operation is triggered, if the target class data corresponding to the target klass object exists in memory, it can be directly retrieved from memory without reloading the class file to obtain the corresponding class data, reducing class loading steps, shortening application startup time, and improving application startup speed. If the target class data does not exist in memory, the normal class loading process is executed.
[0070] See Figure 7As shown in the figure, this application discloses an apparatus for accelerating the startup speed of Java applications, the apparatus comprising:
[0071] The file loading module 11 is used to obtain the target class file from the disk and load and parse the target class file using the target class loader to generate the corresponding klass object; wherein the target class loader is any one of the bootstrap class loader, extension class loader and application class loader.
[0072] The judgment module 12 is used to determine whether the klass object can be shared. If so, the fully qualified name of the target class file is written into the preset sharing list.
[0073] The archive file writing module 13 is used to read the preset shared list and load the class file corresponding to each of the fully qualified names, so as to write the corresponding class data to the preset archive file;
[0074] The mapping module 14 is used to map the preset archive file into memory during the startup process of the Java application so that after the class loading operation is triggered, the target class data corresponding to the class loading operation can be obtained from the memory and the system dictionary can be updated using the target class data.
[0075] As can be seen, this application obtains the target class file from the disk through the Java Virtual Machine and loads and parses the target class file using a target class loader to generate the corresponding klass object. The target class loader can be any one of the bootstrap class loader, extension class loader, and application class loader. It determines whether the klass object can be shared; if so, it writes the fully qualified name of the target class file into a preset sharing list. It reads the preset sharing list and loads the class file corresponding to each fully qualified name to write the corresponding class data to a preset archive file. During the Java application startup process, the preset archive file is mapped into memory so that after a class loading operation is triggered, the target class data corresponding to the class loading operation is retrieved from memory, and the system dictionary is updated using the target class data. Therefore, this application, in addition to supporting classes loaded by the bootstrap class loader and extension class loader, also adds classes loaded by the application class loader, expanding the class sharing scope of the CDS feature, significantly increasing the number of classes that can be dumped, and significantly improving the application startup speed. After the Java Virtual Machine (JVM) retrieves the target class file from the disk, it uses the corresponding target class loader to record and parse it, dumping the corresponding class data into a pre-defined archive file. During Java application startup, the pre-defined archive file is directly mapped into memory, and the target class data corresponding to the current class loading operation is retrieved from memory. This target class data is then used to update the system dictionary. This process eliminates the need to reload the class file to obtain the corresponding class data, reducing class loading steps, shortening application startup time, and improving application startup speed.
[0076] Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Specifically, it may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the method for accelerating the startup speed of Java applications disclosed in any of the foregoing embodiments.
[0077] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.
[0078] The processor 21 may include one or more processing cores, such as a quad-core processor or an octa-core processor. The processor 21 may be implemented using at least one hardware form selected from DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 21 may also include a main processor and a coprocessor. The main processor, also known as a CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, the processor 21 may integrate a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, the processor 21 may also include an AI (Artificial Intelligence) processor, which is used to handle computational operations related to machine learning.
[0079] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored on it include operating system 221, computer program 222 and data 223, etc., and the storage method can be temporary storage or permanent storage.
[0080] The operating system 221 manages and controls the various hardware devices and computer programs 222 on the electronic device 20 to enable the processor 21 to perform calculations and processing on the massive amounts of data 223 in the memory 22. The operating system 221 can be Windows, Unix, Linux, etc. The computer program 222, in addition to including a computer program capable of performing the method for accelerating the startup speed of Java applications executed by the electronic device 20 as disclosed in any of the foregoing embodiments, may further include computer programs capable of performing other specific tasks. The data 223 may include data received by the electronic device from external devices, as well as data collected by its own input / output interface 25.
[0081] Furthermore, embodiments of this application also disclose a computer-readable storage medium storing a computer program, which, when loaded and executed by a processor, implements the method steps disclosed in any of the foregoing embodiments for accelerating the startup speed of Java applications.
[0082] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.
[0083] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0084] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0085] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0086] The present invention has provided a detailed description of a method, apparatus, device, and storage medium for accelerating the startup speed of Java applications. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A method for accelerating the startup speed of Java applications, characterized in that, Applied to the Java Virtual Machine, including: Obtain the target class file from the disk, and use the target class loader to load and parse the target class file to generate the corresponding klass object; wherein, the target class loader is any one of the bootstrap class loader, extension class loader, and application class loader; Determine whether the klass object can be shared; if so, write the fully qualified name of the target class file into the preset sharing list. Read the preset shared list and load the class file corresponding to each of the fully qualified names so that the corresponding class data can be written to the preset archive file; During the startup process of a Java application, the preset archive file is mapped into memory so that after a class loading operation is triggered, the target class data corresponding to the class loading operation can be obtained from the memory, and the system dictionary can be updated using the target class data. The step of retrieving the target class data corresponding to the class loading operation from the memory and updating the system dictionary using the target class data includes: Determine the target klass object corresponding to the class loading operation, and determine whether target class data corresponding to the target klass object exists in the memory; If it exists, the target class data is retrieved from the memory, and the system dictionary is updated using the target class data; If it does not exist, the class file corresponding to the class loading operation will be used as the target class file; The process jumps back to the step of retrieving the target class file from the disk and using the target class loader to load and parse the target class file to generate the corresponding klass object, until the target class data corresponding to the class loading operation is retrieved from the memory, and then the system dictionary is updated using the target class data.
2. The method for accelerating the startup speed of Java applications according to claim 1, characterized in that, The process of loading and parsing the target class file using the target class loader to generate the corresponding klass object includes: The corresponding target class loader is determined based on the directory and path information of the target class file, so that the target class file can be loaded and parsed using the target class loader to generate the corresponding klass object.
3. The method for accelerating the startup speed of Java applications according to claim 1, characterized in that, The determination of whether the klass object can be shared includes: The system dictionary's shared class determines whether the klass object can be shared.
4. The method for accelerating the startup speed of Java applications according to claim 1, characterized in that, After determining whether the klass object can be shared, the method further includes: If not, it is determined that the fully qualified name of the target class file cannot be written to the preset shared list.
5. The method for accelerating the startup speed of Java applications according to claim 1, characterized in that, The step of reading the preset shared list and loading the class file corresponding to each fully qualified name, so as to write the corresponding class data to the preset archive file, includes: Read the fully qualified names from the preset shared list and load the class file corresponding to each fully qualified name until all class files are loaded, then write the corresponding class data to the preset archive file.
6. An apparatus for accelerating the startup speed of Java applications, characterized in that, Applied to the Java Virtual Machine, including: The file loading module is used to obtain the target class file from the disk, and use the target class loader to load and parse the target class file to generate the corresponding klass object; wherein, the target class loader is any one of the bootstrap class loader, extension class loader and application class loader; The judgment module is used to determine whether the klass object can be shared. If so, the fully qualified name of the target class file is written into the preset sharing list. The archive file writing module is used to read the preset shared list and load the class file corresponding to each of the fully qualified names, so as to write the corresponding class data to the preset archive file; The mapping module is used to map the preset archive file into memory during the startup process of a Java application, so that after a class loading operation is triggered, the target class data corresponding to the class loading operation can be obtained from the memory, and the system dictionary can be updated using the target class data; Specifically, the mapping module is used to determine the target klass object corresponding to the class loading operation, and to determine whether target class data corresponding to the target klass object exists in the memory; if it exists, the target class data is retrieved from the memory and the system dictionary is updated using the target class data; if it does not exist, the class file corresponding to the class loading operation is used as the target class file; the process jumps back to the step of retrieving the target class file from the disk and loading and parsing the target class file using the target class loader to generate the corresponding klass object, until the target class data corresponding to the class loading operation is retrieved from the memory, and then the system dictionary is updated using the target class data.
7. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the steps of the method for accelerating the startup speed of a Java application as described in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, Used to store computer programs; wherein, when executed by a processor, the computer programs implement the steps of the method for accelerating the startup speed of Java applications as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Mechanism for class data sharing using extension and application class-loaders
US20150317167A1