A method for improving JVM performance based on SIMD
By processing loop logic instructions in Java code into the SIMD instruction set, the Java Virtual Machine can run efficiently, solving the problem of wasted CPU processing power caused by loop code and improving CPU computing efficiency.
Patent Information
- Application Number
- CN202210912576.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-30
- Publication Date
- 2025-10-21
- Estimated Expiration
- 2042-07-30
AI Technical Summary
In existing technologies, Java Virtual Machines often execute loop code only after iterating a large number of times, resulting in wasted CPU processing power and low efficiency.
The loop logic instructions in Java code are processed into SIMD instruction sets. Data is loaded into the CPU at once using SIMD instruction sets for computation, avoiding the repetitive execution of simple tasks.
It improves the operating efficiency of the Java Virtual Machine and saves CPU processing power.
Smart Images

Figure CN115421849B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates specifically to the technical field of Java virtual machines, and in particular to a method for improving JVM performance based on SIMD. Background Art
[0002] Computer programs must be compiled into instructions for the CPU to recognize and execute operations. Therefore, the CPU's ability to process data is a key indicator of CPU performance. To improve this capability, semiconductor manufacturers have introduced instructions in CPUs that can process multiple data points simultaneously—SIMD instructions.
[0003] SIMD stands for Single Instruction Multiple Data. As the name suggests, a single instruction processes multiple data. For example, in a Single Instruction Single Data (SISD) CPU, after decoding the addition instruction, the execution unit first accesses memory to obtain the first operand, then accesses memory again to obtain the second operand, and only then can the summation be performed. In a SIMD CPU, after the instruction is decoded, several execution units access memory simultaneously, obtaining all operands at once for calculation. This feature makes SIMD particularly suitable for data-intensive operations such as multimedia applications.
[0004] JVM stands for Java Virtual Machine. It's a specification for computing devices—a fictional computer that emulates various computer functions on a real computer. The introduction of the Java virtual machine eliminates the need for recompilation when running the Java language on different platforms. The Java virtual machine shields platform-specific information from the Java language, allowing the Java compiler to generate target code (bytecode) that runs on the Java virtual machine and run unmodified on multiple platforms.
[0005] In the prior art, when a Java virtual machine is running, a loop code is often executed only after a large number of loops. Each loop performs simple and repetitive work, wasting CPU processing power and resulting in low operating efficiency of the Java virtual machine. Summary of the Invention
[0006] The purpose of the present invention is to provide a method for improving JVM performance based on SIMD, so as to solve the problem in the prior art proposed in the above background technology that when the Java virtual machine is running, the loop code often loops a large number of times before the code is executed. Each loop performs simple and repetitive work, which wastes the processing power of the CPU and leads to low operating efficiency of the Java virtual machine.
[0007] To achieve the above object, the present invention provides the following technical solutions:
[0008] A method for improving JVM performance based on SIMD, comprising the following steps:
[0009] S10, obtaining loop logic instructions in the Java code, processing the compiled loop logic instructions, and obtaining a SIMD instruction set;
[0010] S20, parsing the loop logic operation in the Java instruction to obtain an assembly instruction;
[0011] S30, sending the assembly instruction to the CPU via the SIMD instruction set;
[0012] S40: Obtain the calculation result returned by the CPU after SIMD operation.
[0013] The JVM (Java Virtual Machine) is a binary bytecode runtime environment that is responsible for loading bytecode into it and interpreting / compiling it into machine instructions for the corresponding platform (Unix, Windows, etc.) for execution. The Java virtual machine includes a JVM runtime data area and a parsed JVM runtime data area. The parsed JVM runtime data area includes a method area, a Java heap, a program counter, and a Java virtual machine stack.
[0014] Method area: The method area is a memory area shared by all threads. It is used to store data such as class information, constants, static variables, and code compiled by the just-in-time compiler that has been loaded by the Java virtual machine. The method area is also called the non-heap area. When the method area cannot meet the memory allocation requirements, an OutOfMemoryError exception is thrown.
[0015] Java heap: The Java heap is the largest memory area managed by the Java virtual machine. It is a memory area shared by all threads and is created when the virtual machine starts. The only purpose of this memory area is to store object instances.
[0016] Program Counter: The program counter is a small area of memory that stores the address (line number) of the bytecode instruction currently being executed by the current thread. Because the Java virtual machine implements multithreading by switching threads and allocating processor execution time, each processor only executes instructions from a single thread. Therefore, to ensure that the correct execution position can be restored after a thread switch, each thread has a separate program counter. These counters do not affect each other and are stored independently, known as "thread-private" memory. The program counter memory area is the only area in the virtual machine that does not provide for an OutOfMemoryError.
[0017] Java virtual machine stack: The Java virtual machine is thread-private, and its life cycle is the same as that of the thread. The Java virtual machine stack describes the memory model of Java method execution: each method creates a stack frame (StackFrame) when it is executed to store local variable tables, operand stacks, dynamic links, method exits and other information.
[0018] As a further solution of the present invention: in step S10, the method for processing the compiled loop logic instruction includes the following steps:
[0019] S11. The JVM compiles the Java code line by line, generates a compilation result corresponding to the Java code, and sends the compilation result to the CPU. The compilation result includes compiled loop logic instructions.
[0020] S12. Modify the original processing logic of the JVM using a single instruction set based on the compiled loop logic instructions to obtain a SIMD instruction set.
[0021] As a further solution of the present invention: Single Instruction Multiple Data (English: Single Instruction Multiple Data, abbreviation: SIMD) is a technology that uses one controller to control multiple processors and simultaneously performs the same operation on each of a group of data (also called "data vectors") to achieve spatial parallelism. The SIMD instruction set is the MMX (Multi-Media Extension) instruction set. The MMX instruction set is a SIMD multimedia instruction set designed by Intel, one of the SSE instruction set (Streaming SIMD Extensions), SE2 (Streaming SIMD Extensions 2) instruction set and SSE3 (Streaming SIMD Extensions 3) instruction sets.
[0022] As a further solution of the present invention: in step S12 of the embodiment of the present invention, the method of modifying the original processing logic of the JVM using a single instruction set based on the compiled loop logic instructions is to replace the processing logic of the single instruction set with parallel operation logic.
[0023] As a further solution of the present invention: the parallel operation logic includes the following steps:
[0024] S121, obtaining a first operand of a first storage area and a second operand of a second storage area;
[0025] S122. Divide the bytes of the first operand and the second operand in the same division manner to obtain at least two pieces of data, each piece of data having a corresponding position;
[0026] S123: Calculate the data at corresponding positions of the first operand and the second operand to obtain a calculation result.
[0027] As a further solution of the present invention: in step S122, the division method is: based on the number of bytes N of the operand, the operand is divided into n pieces of data, and the number of bytes of each piece of data is:
[0028]
[0029] As a further solution of the present invention: the loop logic instruction includes a loop addition operation, a loop subtraction operation, a loop multiplication operation and a loop division operation.
[0030] As a further solution of the present invention: in step S30, the SIMD instruction set of the CPU is used to load all the data into the CPU at once, and only one operation needs to be performed.
[0031] As a further solution of the present invention: in step S40, the method of performing SIMD operation by the CPU includes the following steps:
[0032] S41, obtaining an integer A of a first SIMD size and an integer B of a second SIMD size;
[0033] S42, performing an element-wise SIMD logical operation on corresponding elements of the first SIMD-sized integer A and the second SIMD-sized integer B to generate a SIMD-sized integer result R and a carry bit; and
[0034] In response to the integer size of A being greater than the integer size of B, R and the carry bit are updated in view of one or more elements of A that do not have a corresponding element or elements of B.
[0035] As a further solution of the present invention: in step S42, the integer A of the first SIMD size and the integer B of the second SIMD size both have integer sizes.
[0036] The present invention also discloses a system for improving JVM performance based on SIMD, the system comprising an instruction acquisition unit, a storage unit and a CPU, wherein the CPU is connected to the instruction acquisition unit and the storage unit, wherein:
[0037] An instruction fetch unit, configured to fetch operands, Java codes, and Java instructions;
[0038] A storage unit, the storage unit being used to load and run a Java virtual machine, the Java virtual machine being used to generate a SIMD instruction set based on Java code;
[0039] The CPU is used to calculate operands based on Java instructions and a SIMD instruction set to obtain calculation results.
[0040] Compared with the prior art, the beneficial effects of the present invention are: the present invention parses commonly used data loop logical operations into a SIMD instruction set, and loads all data into the CPU at one time by executing an operation based on the SIMD instruction set, thereby improving data calculation efficiency, avoiding the CPU from repeatedly executing simple tasks, saving CPU processing performance, and improving the operating efficiency of the Java virtual machine. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 Flowchart of a method for improving JVM performance based on SIMD.
[0042] Figure 2 This is a flowchart of step S10 in the method for improving JVM performance based on SIMD.
[0043] Figure 3 This is a flowchart of step S12 in the method for improving JVM performance based on SIMD.
[0044] Figure 4 This is a schematic diagram of SIMD calculation in a method for improving JVM performance based on SIMD.
[0045] Figure 5 A structural block diagram of a system for improving JVM performance based on SIMD. DETAILED DESCRIPTION
[0046] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0047] JVM stands for Java Virtual Machine. It's a specification for computing devices—a fictional computer that emulates various computer functions on a real computer. The introduction of the Java virtual machine eliminates the need for recompilation when running the Java language on different platforms. The Java virtual machine shields platform-specific information from the Java language, allowing the Java compiler to generate target code (bytecode) that runs on the Java virtual machine and run unmodified on multiple platforms.
[0048] In the prior art, when a Java virtual machine is running, a loop code is often executed only after a large number of loops. Each loop performs simple and repetitive work, wasting CPU processing power and resulting in low Java virtual machine operating efficiency. This is described in detail below with reference to an embodiment:
[0049] Example 1
[0050] See also Figure 1-3 In an embodiment of the present invention, a method for improving JVM performance based on SIMD includes the following steps:
[0051] S10, obtaining loop logic instructions in the Java code, processing the compiled loop logic instructions, and obtaining a SIMD instruction set;
[0052] In step S10 of the embodiment of the present invention, the method for processing the compiled loop logic instruction includes the following steps:
[0053] S11. The JVM compiles the Java code line by line, generates a compilation result corresponding to the Java code, and sends the compilation result to the CPU. The compilation result includes compiled loop logic instructions.
[0054] S12. Modify the original processing logic of the JVM using a single instruction set based on the compiled loop logic instructions to obtain a SIMD instruction set;
[0055] It should be noted that the JVM (Java Virtual Machine) is a binary bytecode runtime environment that is responsible for loading the bytecode into it and interpreting / compiling it into machine instructions for the corresponding platform (Unix, Windows, etc.) for execution. Each Java instruction has a detailed definition in the Java Virtual Machine specification, such as how to obtain operands and how to process operands.
[0056] Furthermore, the Java virtual machine includes a JVM runtime data area and a parsed JVM runtime data area, wherein the parsed JVM runtime data area includes a method area, a Java heap, a program counter, and a Java virtual machine stack, wherein:
[0057] Method area: The method area is a memory area shared by all threads. It is used to store data such as class information, constants, static variables, and code compiled by the just-in-time compiler that has been loaded by the Java virtual machine. The method area is also called the non-heap area. When the method area cannot meet the memory allocation requirements, an OutOfMemoryError exception is thrown.
[0058] Java Heap: The Java heap is the largest memory area managed by the Java Virtual Machine (JVM). It is a memory area shared by all threads and is created when the JVM starts. Its sole purpose is to store object instances. The Java Virtual Machine specification states that all object instances and arrays are allocated on the heap. The Java heap is the primary area managed by the garbage collector and is therefore also called the "GC heap." From a memory recycling perspective, the Java heap can be divided into the young generation and the old generation. From a memory allocation perspective, the thread-shared Java heap may contain multiple thread-private allocation buffers.
[0059] No matter how the Java heap is divided, it has nothing to do with the storage content. No matter which area, object instances are stored. Further division is to better reclaim memory or allocate memory faster.
[0060] According to the Java Virtual Machine specification, the Java heap can be located in physically discontinuous memory spaces. Current mainstream virtual machines are all scalable. If there is no memory in the heap to complete instance allocation and the heap cannot be expanded any further, an OutOfMemoryError exception will be thrown.
[0061] Program Counter: The program counter is a small area of memory that stores the address (line number) of the bytecode instruction currently being executed by the current thread. Because the Java virtual machine implements multithreading by switching threads and allocating processor execution time, each processor only executes instructions from a single thread. Therefore, to ensure that the correct execution position can be restored after a thread switch, each thread has a separate program counter. These counters do not affect each other and are stored independently, known as "thread-private" memory. The program counter memory area is the only area in the virtual machine that does not provide for an OutOfMemoryError.
[0062] Java virtual machine stack: The Java virtual machine is thread-private, and its life cycle is the same as that of the thread. The Java virtual machine stack describes the memory model of Java method execution: each method creates a stack frame (StackFrame) when it is executed to store local variable tables, operand stacks, dynamic links, method exits and other information.
[0063] In addition, Single Instruction Multiple Data (SIMD) is a technology that uses one controller to control multiple processors and simultaneously performs the same operation on each of a set of data (also called "data vectors") to achieve spatial parallelism. The SIMD instruction set is the MMX (Multi-Media Extension) instruction set. The MMX instruction set is a SIMD multimedia instruction set designed by Intel, one of the SSE instruction set (Streaming SIMD Extensions), SE2 (Streaming SIMD Extensions 2) instruction set, and SSE3 (Streaming SIMD Extensions 3) instruction sets.
[0064] Furthermore, in step S12 of the embodiment of the present invention, the method for modifying the original processing logic of the JVM using a single instruction set based on the compiled loop logic instructions is to replace the processing logic of the single instruction set with parallel operation logic, wherein the parallel operation logic includes the following steps:
[0065] S121, obtaining a first operand of a first storage area and a second operand of a second storage area;
[0066] S122. Divide the bytes of the first operand and the second operand in the same division manner to obtain at least two pieces of data, each piece of data having a corresponding position;
[0067] S123, performing an operation on the data at corresponding positions of the first operand and the second operand to obtain an operation result;
[0068] It should be noted that in step S122, the division method is: based on the number of bytes N of the operand, the operand is divided into n pieces of data, and the number of bytes of each piece of data is:
[0069] For example, a 16-bit operand is divided into 4 parts, and each part has 4 bytes.
[0070] In an embodiment of the present invention, the loop logic instruction includes a loop addition operation, a loop subtraction operation, a loop multiplication operation, and a loop division operation.
[0071] See also Figure 4 The SIMD mentioned above actually uses vectorized computing (vectorization, vectorized operation or array programming) to turn multiple for-loop calculations into one calculation. This transformation of multiple for-loop calculations into one calculation relies entirely on the CPU's SIMD instruction set. SIMD instructions can process 2, 4, 8 or more copies of data in one CPU instruction. On Intel processors, this processing technology is called SSE and later AVX; on ARM processors, this processing technology is called NEON.
[0072] Therefore, vectorized computing is to convert a loop - processing an array of 1 data at a time for a total of N times, into vectorization - processing an array of 8 data at a time for a total of N / 8 times.
[0073] S20, parsing the loop logic operation in the Java instruction to obtain an assembly instruction;
[0074] S30, sending the assembly instruction to the CPU via the SIMD instruction set;
[0075] In step S30 of the embodiment of the present invention, the SIMD instruction set of the CPU can load all the data into the CPU at once, and only one operation needs to be performed;
[0076] S40, obtaining the calculation result returned by the CPU after SIMD operation;
[0077] Furthermore, in step S40 of the embodiment of the present invention, the method in which the CPU performs SIMD operations includes the following steps:
[0078] S41, obtaining an integer A of a first SIMD size and an integer B of a second SIMD size;
[0079] S42, performing an element-wise SIMD logical operation on corresponding elements of the first SIMD-sized integer A and the second SIMD-sized integer B to generate a SIMD-sized integer result R and a carry bit; and
[0080] In response to the integer size of A being greater than the integer size of B, updating R and a carry bit in view of one or more elements of A not having a corresponding element or elements of B;
[0081] In step S42 of this embodiment, both the integer A of the first SIMD size and the integer B of the second SIMD size have integer sizes.
[0082] Example 2
[0083] See also Figure 1-3 In an embodiment of the present invention, a method for improving JVM performance based on SIMD includes the following steps:
[0084] S10, obtaining loop logic instructions in the Java code, processing the compiled loop logic instructions, and obtaining a SIMD instruction set;
[0085] In step S10 of the embodiment of the present invention, the method for processing the compiled loop logic instruction includes the following steps:
[0086] S11. The JVM compiles the Java code line by line, generates a compilation result corresponding to the Java code, and sends the compilation result to the CPU. The compilation result includes compiled loop logic instructions.
[0087] S12. Modify the original processing logic of the JVM using a single instruction set based on the compiled loop logic instructions to obtain a SIMD instruction set;
[0088] It should be noted that the JVM is a binary bytecode runtime environment that is responsible for loading the bytecode into it and interpreting / compiling it into machine instructions for the corresponding platform (Unix, Windows, etc.) for execution. Each Java instruction has a detailed definition in the Java Virtual Machine Specification, such as how to obtain operands and how to process operands.
[0089] Furthermore, the Java virtual machine includes a JVM runtime data area and a parsed JVM runtime data area, wherein the parsed JVM runtime data area includes a method area, a Java heap, a program counter, and a Java virtual machine stack, wherein:
[0090] Method area: The method area is a memory area shared by all threads. It is used to store data such as class information, constants, static variables, and code compiled by the just-in-time compiler that has been loaded by the Java virtual machine. The method area is also called the non-heap area. When the method area cannot meet the memory allocation requirements, an OutOfMemoryError exception is thrown.
[0091] Java Heap: The Java heap is the largest memory area managed by the Java Virtual Machine (JVM). It is a memory area shared by all threads and is created when the JVM starts. Its sole purpose is to store object instances. The Java Virtual Machine specification states that all object instances and arrays are allocated on the heap. The Java heap is the primary area managed by the garbage collector and is therefore also called the "GC heap." From a memory recycling perspective, the Java heap can be divided into the young generation and the old generation. From a memory allocation perspective, the thread-shared Java heap may contain multiple thread-private allocation buffers.
[0092] No matter how the Java heap is divided, it has nothing to do with the storage content. No matter which area, object instances are stored. Further division is to better reclaim memory or allocate memory faster.
[0093] According to the Java Virtual Machine specification, the Java heap can be located in physically discontinuous memory spaces. Current mainstream virtual machines are all scalable. If there is no memory in the heap to complete instance allocation and the heap cannot be expanded any further, an OutOfMemoryError exception will be thrown.
[0094] Program Counter: The program counter is a small area of memory that stores the address (line number) of the bytecode instruction currently being executed by the current thread. Because the Java virtual machine implements multithreading by switching threads and allocating processor execution time, each processor only executes instructions from a single thread. Therefore, to ensure that the correct execution position can be restored after a thread switch, each thread has a separate program counter. These counters do not affect each other and are stored independently, known as "thread-private" memory. The program counter memory area is the only area in the virtual machine that does not provide for an OutOfMemoryError.
[0095] Java virtual machine stack: The Java virtual machine is thread-private, and its life cycle is the same as that of the thread. The Java virtual machine stack describes the memory model of Java method execution: each method creates a stack frame (StackFrame) when it is executed to store local variable tables, operand stacks, dynamic links, method exits and other information.
[0096] In addition, Single Instruction Multiple Data (SIMD) is a technology that uses one controller to control multiple processors and simultaneously performs the same operation on each of a set of data (also called "data vectors") to achieve spatial parallelism. The SIMD instruction set is the MMX (Multi-Media Extension) instruction set. The MMX instruction set is a SIMD multimedia instruction set designed by Intel, one of the SSE instruction set (Streaming SIMD Extensions), SE2 (Streaming SIMD Extensions 2) instruction set, and SSE3 (Streaming SIMD Extensions 3) instruction sets.
[0097] Furthermore, in step S12 of the embodiment of the present invention, the method for modifying the original processing logic of the JVM using a single instruction set based on the compiled loop logic instructions is to replace the processing logic of the single instruction set with parallel operation logic, wherein the parallel operation logic includes the following steps:
[0098] S121, obtaining a first operand of a first storage area and a second operand of a second storage area;
[0099] S122. Divide the bytes of the first operand and the second operand in the same division manner to obtain at least two pieces of data, each piece of data having a corresponding position;
[0100] S123, performing an operation on the data at corresponding positions of the first operand and the second operand to obtain an operation result;
[0101] It should be noted that in step S122, the division method is: based on the number of bytes N of the operand, the operand is divided into n pieces of data, and the number of bytes of each piece of data is:
[0102] For example, a 16-bit operand is divided into 4 parts, and each part has 4 bytes.
[0103] In an embodiment of the present invention, the loop logic instruction includes a loop addition operation, a loop subtraction operation, a loop multiplication operation, and a loop division operation.
[0104] See also Figure 4The SIMD mentioned above actually uses vectorized computing (vectorization, vectorized operation or array programming) to turn multiple for-loop calculations into one calculation. This transformation of multiple for-loop calculations into one calculation relies entirely on the CPU's SIMD instruction set. SIMD instructions can process 2, 4, 8 or more copies of data in one CPU instruction. On Intel processors, this processing technology is called SSE and later AVX; on ARM processors, this processing technology is called NEON.
[0105] Therefore, vectorized computing is to convert a loop - processing an array of 1 data at a time for a total of N times, into vectorization - processing an array of 8 data at a time for a total of N / 8 times.
[0106] S20, parsing the loop logic operation in the Java instruction to obtain an assembly instruction;
[0107] S30, sending the assembly instruction to the CPU via the SIMD instruction set;
[0108] In step S30 of the embodiment of the present invention, the SIMD instruction set of the CPU can load all the data into the CPU at once, and only one operation needs to be performed;
[0109] S40, obtaining the calculation result returned by the CPU after SIMD operation;
[0110] Furthermore, in step S40 of the embodiment of the present invention, the method in which the CPU performs SIMD operations includes the following steps:
[0111] S41, obtaining an integer A of a first SIMD size and an integer B of a second SIMD size;
[0112] S42, performing an element-wise SIMD logical operation on corresponding elements of the first SIMD-sized integer A and the second SIMD-sized integer B to generate a SIMD-sized integer result R and a carry bit; and
[0113] In response to the integer size of A being greater than the integer size of B, updating R and a carry bit in view of one or more elements of A not having a corresponding element or elements of B;
[0114] In step S42 of this embodiment, both the integer A of the first SIMD size and the integer B of the second SIMD size have integer sizes.
[0115] See also Figure 5The present invention also discloses a system for improving JVM performance based on SIMD, the system comprising an instruction acquisition unit, a storage unit and a CPU, the CPU being connected to the instruction acquisition unit and the storage unit, wherein:
[0116] An instruction fetch unit 100, configured to fetch operands, Java code, and Java instructions;
[0117] A storage unit 200, the storage unit being used to load and run a Java virtual machine, the Java virtual machine being used to generate a SIMD instruction set based on Java code;
[0118] CPU 300 is used to calculate the operands based on Java instructions and SIMD instruction sets to obtain calculation results;
[0119] In an embodiment of the present invention, a method for a Java virtual machine to generate a SIMD instruction set based on Java code includes the following steps:
[0120] S11. The JVM compiles the Java code line by line, generates a compilation result corresponding to the Java code, and sends the compilation result to the CPU. The compilation result includes compiled loop logic instructions.
[0121] S12. Modify the original processing logic of the JVM using a single instruction set based on the compiled loop logic instructions to obtain a SIMD instruction set.
[0122] In an embodiment of the present invention, a method for calculating operands based on Java instructions and SIMD instruction sets includes the following steps:
[0123] S41, obtaining an integer A of a first SIMD size and an integer B of a second SIMD size;
[0124] S42, performing an element-wise SIMD logical operation on corresponding elements of the first SIMD-sized integer A and the second SIMD-sized integer B to generate a SIMD-sized integer result R and a carry bit; and
[0125] In response to the integer size of A being greater than the integer size of B, R and the carry bit are updated in view of one or more elements of A that do not have a corresponding element or elements of B.
[0126] In addition, some embodiments may include a storage medium having a program for executing the methods described in this specification on a computer, wherein the storage medium stores at least one instruction, at least one program, a code set, or an instruction set. When the at least one instruction, at least one program, a code set, or an instruction set is loaded and executed by a processor, the steps of the above-described method embodiments are implemented. Examples of computer-readable recording media include hardware devices specially configured to store and execute program commands: magnetic media such as hard disks, floppy disks, and magnetic tapes, optical recording media such as CD-ROMs and DVDs, magneto-optical media such as floppy disks, ROMs, RAMs, flash memories, etc. Examples of program commands include machine language codes written by a compiler and high-level language codes executed by a computer using an interpreter, etc.
[0127] Those skilled in the art will understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware to complete the process through at least one instruction, at least one program, code set or instruction set. The at least one instruction, at least one program, code set or instruction set can be stored in a non-volatile computer-readable storage medium. When the at least one instruction, at least one program, code set or instruction set is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory.
[0128] In summary, the present invention parses commonly used data loop logical operations into a SIMD instruction set, and loads all data into the CPU at one time by executing one operation based on the SIMD instruction set, thereby improving data calculation efficiency, avoiding the CPU from repeatedly performing simple tasks, saving CPU processing performance, and improving the operating efficiency of the Java virtual machine.
[0129] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above and that the invention can be embodied in other specific forms without departing from the spirit or essential characteristics of the invention. Therefore, the embodiments should be considered in all respects as illustrative and non-restrictive, and the scope of the invention is defined by the appended claims, not the foregoing description, and all variations within the meaning and range of equivalents of the claims are intended to be included therein. Any reference sign in a claim should not be construed as limiting the claim to which it relates.
[0130] In addition, it should be understood that although this specification is described in terms of implementation methods, not every implementation method contains only one independent technical solution. This narrative method of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment can also be appropriately combined to form other implementation methods that can be understood by those skilled in the art.
Claims
1. A method for improving JVM performance based on SIMD, characterized in that: The following steps are involved: S10. Obtain loop logic instructions in the Java code, process the compiled loop logic instructions, and obtain a SIMD instruction set; wherein, S11. The JVM compiles the Java code line by line, generates a compilation result corresponding to the Java code, and sends the compilation result to the CPU, wherein the compilation result includes the compiled loop logic instructions; S12. Modify the JVM's original processing logic using a single instruction set based on the compiled loop logic instructions, wherein the processing logic of the single instruction set is replaced by parallel operation logic to obtain a SIMD instruction set; S20, parsing the loop logic operation in the Java instruction to obtain an assembly instruction; S30, sending the assembly instruction to the CPU via the SIMD instruction set; wherein the SIMD instruction set of the CPU is used to load all the data into the CPU at once, and only one operation needs to be performed; S40. Obtain a calculation result returned by the CPU after SIMD operation; wherein, S41. Obtain an integer A of a first SIMD size and an integer B of a second SIMD size; S42. Perform element-level SIMD logical operation on corresponding elements of the integer A of the first SIMD size and the integer B of the second SIMD size to generate an integer result R of SIMD size and a carry bit; and in response to the integer size of A being greater than the integer size of B, update R and the carry bit in view of one or more elements of A that do not have a corresponding element or multiple elements of B.
2. The method for improving JVM performance based on SIMD according to claim 1, characterized in that: The SIMD instruction set is one of the MMX instruction set, SSE instruction set, SE2 instruction set, and SSE3 instruction set.
3. The method for improving JVM performance based on SIMD according to claim 1, characterized in that: The parallel operation logic includes the following steps: S121, obtaining a first operand of a first storage area and a second operand of a second storage area; S122. Divide the bytes of the first operand and the second operand in the same division manner to obtain at least two pieces of data, each piece of data having a corresponding position; S123: Calculate the data at corresponding positions of the first operand and the second operand to obtain a calculation result.
4. The method for improving JVM performance based on SIMD according to claim 3, characterized in that: In step S122, the division method is: based on the number of bytes N of the operand, the operand is divided into n pieces of data, and the number of bytes of each piece of data is: 。 5. The method for improving JVM performance based on SIMD according to claim 1, characterized in that: The loop logic instructions include loop addition operation, loop subtraction operation, loop multiplication operation and loop division operation.
6. The method for improving JVM performance based on SIMD according to claim 1, characterized in that: In step S42 , the integer A of the first SIMD size and the integer B of the second SIMD size both have integer sizes.
Citation Information
Patent Citations
Methods and apparatus to optimize application program interfaces in a virtual machine environment
CN101777006A
Instruction generation method and device and electronic equipment
CN112230995A