A method and system for simplifying bytecode instruction set

By optimizing constant assignment, instance domain access and constant pool index encoding based on registers, the problem of low execution efficiency of operand stack instruction set is solved, and the instruction length reduction and execution performance improvement is achieved.

CN114428639BActive Publication Date: 2024-11-15BEIJING WATCH DATA SYSTEM CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111600610.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-24
Publication Date
2024-11-15
Estimated Expiration
2041-12-24

AI Technical Summary

Technical Problem

The bytecode instruction set based on the operand stack is less efficient in execution during method call, has a large RAM overhead, and has a long instruction length, which affects performance.

Method used

Bytecode instruction set based on registers is adopted to generate streamlined instructions by optimizing constant assignment, instance domain access, constant pool index coding, operand separation and register multiplexing, reducing instruction length and improving execution performance.

Benefits of technology

Bytecode length is reduced, execution performance is improved, RAM overhead is reduced, and execution efficiency of resource-constrained devices such as smart SE and secure MCU chips is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114428639B_ABST
    Figure CN114428639B_ABST
Patent Text Reader

Abstract

The present invention relates to an instruction simplification method and system for a bytecode instruction set. The method of the present invention can optimize the instruction of assigning a constant to a register and the instruction of using the register as an operand in the initial instruction into an instruction with a constant operand, or directly generate an instruction with a constant operand, convert the instruction of accessing the instance domain of the current instance or generate a proprietary instruction of accessing the instance domain of the current instance, encode the sub-constant pool index operand in the instruction to the operation code of the adjacent instruction, determine the type of the sub-constant pool by the operation code, separate the variable-length operand from the instruction code in the variable-length instruction, generate a pseudo-instruction for static domain initialization, the pseudo-instruction can replace the traditional static domain component, optimize the instruction of reusing the register into the instruction of multiplexing the register, and combine a group of instructions with similar functions and not commonly used into one instruction. The method of the present invention can reduce the length of the bytecode and improve the execution performance of the bytecode.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of instruction set simplification, and in particular relates to an instruction simplification method and system for a bytecode instruction set. Background Art

[0002] A virtual machine is an abstract computer generated by a software application or instruction sequence executed by a processor. A virtual machine can execute instruction sets supported by the virtual machine. There are two types of instruction sets: operand stack-based and register-based. Compared with register-based instruction sets, operand stack-based instruction sets use a stack frame structure. The method call process involves stacking and popping. The bytecode execution process also involves the stacking and popping of the operand stack. Although the RAM overhead is small, the execution efficiency is low. Summary of the invention

[0003] In view of the defects existing in the prior art, the purpose of the present invention is to provide a method and system for simplifying instructions of a register-based bytecode instruction set. The method of the present invention can optimize the instructions for assigning constants to registers and the instructions for using registers as operands in the initial instructions into simplified instructions, or directly generate simplified instructions with constants, convert the instructions for accessing the current instance domain into instructions for accessing the current instance domain, encode the constant pool index operand in the instruction to the opcode position adjacent to the instruction, separate the variable-length operands from the instruction code in each instruction, generate pseudo-instructions for static domain initialization, and pseudo-instructions can replace traditional static domain components, optimize the instructions for reusing registers into instructions for multiplexing registers, and combine a group of similar functions and infrequently used instructions into one instruction. Through the above steps, the length of the bytecode can be reduced, and the execution performance of the bytecode can be improved.

[0004] To achieve the above purpose, the technical solution adopted by the present invention is: optimizing the instructions for assigning constants to registers and the instructions for using the registers as operands in the initial instructions to obtain simplified instructions that directly use constant operands, or directly generating simplified instructions that use constant operands; converting the instructions for accessing the instance domain of the initial instructions as registers corresponding to the this parameter of the method according to a preset instruction format to obtain instance domain-specific instructions for accessing the current instance; splitting the constant pool into multiple sub-constant pools, the constant pool index in the instruction is the sub-constant pool index, and the sub-constant pool index helps the instruction adopt a shorter encoding method of the sub-constant pool index; the constant pool of the initial instruction The index operand is encoded to the position adjacent to the opcode of the instruction; thereby the opcode of the instruction using the constant pool index is obtained through the position of the constant pool index, and the type of the sub-constant pool is determined through the opcode; the variable-length operand in the initial instruction is separated from the instruction code; the static field type and initial configuration value of the static field in the initial instruction are obtained, and pseudo-instructions corresponding to each static field are generated, and the pseudo-instructions can replace traditional static field components; instructions that reuse registers are optimized to obtain instructions that reuse registers; a group of instructions with similar functions are combined into one instruction, and the operation type operand in the instruction is used to specify the operation type of the combined instruction to obtain the corresponding compound multi-operation instruction.

[0005] Furthermore, the instructions for assigning constants to registers include arithmetic and logical operation instructions, jump instructions after comparison with literal constants, and instructions for accessing array members.

[0006] Further, the instruction for accessing the instance domain whose object is the register corresponding to the this parameter of the method in the initial instruction is converted according to a preset instruction format to obtain an instance domain-specific instruction for accessing the current instance, including: deleting the operand of the specified instance according to the preset instruction format from the instruction for accessing the instance domain whose object is the register corresponding to the this parameter of the method to obtain an instance domain-specific instruction for accessing the current instance; the instance domain-specific instruction for accessing the current instance can be further optimized, and the register to be set or returned can be specified by default.

[0007] Further, encoding the constant pool index operand in each instruction of the initial instruction into the operation code of the adjacent instruction includes: uniformly encoding the constant pool index operand in each instruction after the specified code; or uniformly encoding the constant pool index operand in each instruction in front of the instruction code.

[0008] An instruction simplification system for a bytecode instruction set comprises the following devices: a first merging processing device, used for optimizing instructions for assigning constants to registers and instructions for using registers as operands in the initial instructions, obtaining simplified instructions for directly using constant operands, or directly generating simplified instructions for using constant operands; an instruction conversion device, used for converting instructions for accessing instance domains in the initial instructions for registers corresponding to the this parameter of a method according to a preset instruction format, obtaining instance domain-specific instructions for accessing the current instance; a constant pool splitting device, used for splitting a constant pool into a plurality of sub-constant pools, wherein the constant pool index in the instruction is the sub-constant pool index; a constant pool index operand encoding device, used for encoding the constant pool index operand in each instruction of the initial instructions. code to the operation code of the adjacent instruction; thereby obtaining the operation code of the instruction using the constant pool index through the position of the constant pool index, and determining the type of the sub-constant pool through the operation code; an operand separation device, used to separate the variable-length operands in each instruction in the initial instruction from the instruction code; a pseudo-instruction generation device, used to obtain the static domain type and initial configuration value of the static domain instruction in the initial instruction, and generate a pseudo-instruction corresponding to each static domain; a second merging processing device, used to optimize the instructions that reuse registers to obtain instructions that reuse registers; a compound multi-operation instruction acquisition device, used to combine a group of instructions with similar functions into one instruction, and use the operation type operand in the instruction to specify the operation type of the compounded instruction to obtain the corresponding compound multi-operation instruction.

[0009] Furthermore, the instructions for assigning constants to registers include arithmetic and logical operation instructions, jump instructions after comparison with literal constants, and instructions for accessing array members.

[0010] Further, the instruction conversion device includes a unit: a register operand deletion unit, which is used to delete the operand of the specified instance according to a preset instruction format from the instruction that accesses the register corresponding to the this parameter of the method whose object is the instance domain, so as to obtain the instance domain-specific instruction for accessing the current instance; the instance domain-specific instruction for accessing the current instance can be further optimized, and the register to be set or the result to be returned can be specified by default.

[0011] Furthermore, the constant pool index operand encoding device includes a first encoding unit or a second encoding unit: the first encoding unit is used to uniformly encode the constant pool index operand in each instruction to the back of the specified code; the second encoding unit is used to uniformly encode the constant pool index operand in each instruction to the front of the instruction code.

[0012] The effect of the present invention is that: by adopting the method described in the present invention, the instructions for assigning constants to registers and the instructions for using registers as operands in the initial instructions can be optimized into simplified instructions, or simplified instructions with constants can be directly generated, the instructions for accessing the current instance domain can be converted into instructions for accessing the current instance domain, the constant pool index operand in the instruction is encoded into the operation code of the adjacent instruction, the variable-length operands in each instruction are separated from the instruction code, pseudo instructions for initializing the static domain are generated, the instruction length is adjusted according to the configuration item, the instructions for reusing registers are optimized into instructions for multiplexing registers, and a group of instructions with similar functions are combined into one instruction. Through the above steps, the initial instructions are simplified and then the instructions are simplified, so that the length of the bytecode can be reduced and the execution performance of the bytecode can be improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] Figure 1 is a flow chart of the method of the present invention;

[0014] Figure 2 is a structural diagram of the system of the present invention; DETAILED DESCRIPTION

[0015] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments.

[0016] like Figure 1 As shown, a method for simplifying a bytecode instruction set is applied to a user terminal. The method for simplifying a bytecode instruction set is executed by an application software installed in the user terminal. The user terminal is a terminal device for executing the method for simplifying a bytecode instruction set to convert initial code instructions, such as a desktop computer, a laptop computer, a tablet computer or a mobile phone, and includes the following steps:

[0017] S110, optimizing the instructions for assigning constants to registers and the instructions for using the registers as operands to obtain simplified instructions for directly using constant operands, or directly generating simplified instructions for using constant operands.

[0018] The initial instruction consists of multiple instructions, each of which consists of an operation code and an operand. The operation code specifies the operation to be performed. The instruction may contain one or more operands, or may not contain any operands. The operand represents the numerical value required for the operation of the instruction.

[0019] Among them, the above-mentioned rules for instruction optimization processing in this embodiment can be configured in the above-mentioned bytecode instruction set, which can be a register-based virtual machine instruction set, which is used for resource-constrained devices such as smart SE and secure MCU chips. Various object-oriented and architecture-neutral programs are specially designed for virtual machines of resource-constrained devices such as smart SE and secure MCU chips, which can reduce the size of the bytecode as much as possible, which can not only reduce the chip's persistent storage requirements, but also improve the execution efficiency of the code.

[0020] Specifically, the register in this embodiment is 16 bits, so one basic data unit in the instruction represents a 16-bit binary register. For example, the bytecodes of boolean, byte, short, reference type and returnAddress type all occupy one basic data unit, that is, only one register is required; the bytecode of int type needs to occupy two basic data units, so two consecutively numbered register pairs are required to represent it.

[0021] The instruction for assigning a constant to a specified register and the instruction for using the register as an operand can be optimized to an instruction for directly using the constant operand, or a simplified instruction for using the constant operand can be directly generated. In one embodiment, the instruction for assigning a constant to a register includes arithmetic and logical operation instructions, jump instructions after comparison with literal constants, and array member access instructions.

[0022] Taking the addition operation as an example, the above merging process is explained. The following two unoptimized instructions can be optimized into one simplified instruction.

[0023] const-c4 rC C assigns the constant C to register rC (an instruction to assign a constant to a specified register);

[0024] add rA rA rC adds the values ​​in registers rA and rC and assigns the result to register rA (instructions using registers as operands)

[0025] After the merging process, it can be simplified to add-c4 rA C, which adds the constant C and the value of register rA, and assigns the result to register rA (an instruction that directly uses constant operands). Other instructions are simplified by similar merging operations, which will not be described one by one.

[0026] Arithmetic and logical operation instructions are shown in Table 1.

[0027] Table 1

[0028] Instruction annotation code Instruction encoding type Instruction Function Description add-c4 rA B op A|B rA=rA+B add-c8 rAA rBB CC op AA BB CC rAA=rBB+CC sub-c8 rAA rBB CC op AA BB CC rAA=rBB-CC and-c8 rAA rBB CC op AA BB CC rAA=rBB&CC or-c8 rAA,rBB,CC op AA BB CC rAA=rBB|CC xor-c8 rAA,rBB,CC op AA BB CC rAA=rBB^CC

[0029] The jump instructions after comparison with the literal value are shown in Table 2.

[0030] Table 2

[0031]

[0032]

[0033] The instructions for accessing array members are shown in Table 3.

[0034] Table 3

[0035]

[0036] Specify a constant value index or specify a constant value index and assign a specified constant value. Since the simplified instructions obtained after the above-mentioned method of simplification do not need to assign constants to registers, the length of the bytecode is reduced, and the execution of instructions does not need to read constants from registers, which can improve execution performance.

[0037] S120, converting the instruction of the register corresponding to the this parameter of the method in the initial instruction for accessing the instance domain according to a preset instruction format to obtain an instance domain-specific instruction for accessing the current instance.

[0038] Specifically, the instruction for accessing the instance domain object as the register corresponding to the this parameter of the method deletes the operand of the specified instance according to the preset instruction format, and obtains the instance domain-specific instruction for accessing the current instance; the instance domain-specific instruction of the current instance can be further optimized, and the register to be set or returned can be specified by default.

[0039] The general format of instructions for accessing instance fields is explained by taking the reading of the instance field of the object type as an example: getfield-o rAArBB CCcpi instruction is encoded as op AA BB CC, and the instruction length is 4 bytes, where rAA stores the value of the returned instance field, rBB is the object to access the instance field, and CC is the constant pool index of the instance field, specifically specifying which instance field in the object. If the object accessing the instance field is the register corresponding to the this parameter, that is, the register corresponding to the first parameter of the method, by designing a new instruction format, the operand rBB is not included (that is, it is implicitly the current instance specified by the this parameter of the method), so that the instruction can reduce one register operand, and the bytecode length is reduced by one byte. Reducing the register read once when executing the instruction can improve the execution performance. The instruction code specifies the result register by default, and can also reduce one register, further reducing the length of the bytecode.

[0040] The instance domain-specific instructions for accessing the current instance are shown in Table 4.

[0041] Table 4

[0042]

[0043] S130, split the constant pool into multiple sub-constant pools, and the constant pool index in the instruction is the sub-constant pool index.

[0044] The constant pool mentioned in the JavaCard virtual machine specification includes 6 reference types: class reference type, instance field reference type, static field reference type, virtual method reference type, Super method reference type, and static method reference type. These 6 reference types are placed in one constant pool, that is, the constant pool is split into 6 sub-constant pools, each of which corresponds to the corresponding sub-constant pool index.

[0045] In order to use a single-byte constant pool index in an instruction, the present invention proposes the concept of a sub-constant pool, that is, each reference type is placed in a sub-constant pool separately, and six sub-constant pools form a large constant pool. The position order of each sub-constant pool is not important, so that the constant pool index in each type of instruction is the index of the corresponding sub-constant pool.

[0046] S140, encoding the constant pool index operand in each instruction of the initial instruction into the opcode of the adjacent instruction; thereby obtaining the opcode of the instruction using the constant pool index through the position of the constant pool index, and determining the type of the sub-constant pool through the opcode.

[0047] Specify the encoding position of the constant pool index, from which the opcode of the instruction can be determined, and further the type of the constant pool can be determined. Instructions such as creating instances, instance type conversion, static fields, instance fields, and method calls all include operands of constant pool indexes. By encoding the constant pool index operand to the opcode immediately adjacent to the instruction (behind or before, depending on the size of the instruction encoding), the position of the instruction code can be determined by the position of the constant pool index. By analyzing the instruction code, the specific operation type of the instruction can be determined, and finally the type of sub-constant pool to be accessed can be determined.

[0048] Since the constant pool is split into multiple sub-constant pools in the present embodiment, problems arise when the bytecode of the method is linked during the application installation process. It is only known that the constant pool index position of the instruction cannot determine the index of that sub-constant pool. If it is stipulated that the index of the sub-constant pool must be placed behind the instruction code (or in front), the position of the instruction code can be easily determined, and the specific operation type of the instruction can be determined by analyzing the instruction code, and the sub-constant pool type of access can be finally determined. That is, the constant pool index operand in each instruction can be uniformly encoded to the back of the specified code in this application, and the constant pool index operand in each instruction can also be uniformly encoded to the front of the instruction code.

[0049] The following is an example of accessing a static field instruction: putfield-b rAA rBB CC must be encoded in the form of op CCAA BB, where CC is the constant pool index and must be placed after op. The relative positions of AA and BB are irrelevant.

[0050] S150, separating the variable-length operands from the instruction code in each instruction in the initial instructions.

[0051] Specifically, variable-length operands and instruction codes can be separated, and variable-length operands can be placed uniformly at the end of the method (or other appropriate locations). The instruction only needs to contain an offset of a fixed length, so there is no need to consider instruction alignment issues, thereby improving the reading efficiency and execution efficiency of instructions.

[0052] The corresponding instructions are shown in Table 5.

[0053] Table 5

[0054]

[0055] The data format corresponding to the packedswitch instruction is shown in Table 6.

[0056] Table 6

[0057]

[0058]

[0059] The data format corresponding to the sparseswitch instruction is shown in Table 7.

[0060] Table 7

[0061]

[0062] S160, obtaining the static field type and initial configuration value of the static field in the initial instruction, and generating a pseudo instruction corresponding to each static field.

[0063] In a high-level language, a class defines a static field, which sets the initialization value. The compiler generates a special <clinit>Method to handle the initialization of static fields. High-level languages ​​can define array type static fields, where the array can specify initial values; high-level language compilers generally need to generate instructions for creating new arrays and assigning initial values ​​to array members; high-level languages ​​can define basic type static fields with initial values, and high-level language compilers generally need to generate instructions for assigning static fields; currently JavaCard handles <clinit>The mechanism of the method is implemented by simulation in the code conversion tool <clinit>Instructions in the method extract the static type and corresponding initial value and save them for use in subsequent conversion steps.

[0064] The present invention is designed to generate a special pseudo instruction based on the static field type and initial configuration value of the static field. First, the type of each static field and the set initial value are recorded, and then a pseudo instruction in a unified format is generated based on the information corresponding to each static field. The pseudo instruction refers to an instruction that does not need to be actually executed by the virtual machine. When the application is installed, the installation program obtains the initialization data of the corresponding instance field, and the virtual machine can establish the static field data area required for the application program to execute. By generating the corresponding pseudo instruction, the compiler can simplify the subsequent conversion tool <clinit>The processing flow of the method is improved, and the static domain component in the traditional executable program is removed, and the function of the component is to record the initialization information of all static domains in the application package.

[0065] The static domain initialization instructions are shown in Table 8.

[0066] Table 8

[0067]

[0068]

[0069] S170, optimizing the instructions for reusing registers to obtain instructions for multiplexing registers.

[0070] For example, the operands in two registers can be operated, and the result can be assigned to another register. Take the addition operation as an example: the function of the add rAA rBB rCC instruction is rAA = rBB + rCC; if the compiler can determine that the current value of a certain operand register will no longer be used in the future, if the current value of the rBB register is no longer used, taking the addition operation as an example, the following instructions can be generated: the function of the add rBB rCC instruction is rBB = BB + rCC; the length of the add rAA rBB rCC instruction is 4 bytes, and the length of the add rBB rCC instruction is 3 bytes. Multiplexing registers can reduce the length of bytecodes, reduce the time to read instructions when executing instructions, improve execution performance, and reduce the demand for registers. The instructions for multiplexing registers are shown in Table 9.

[0071] Table 9

[0072] Instruction annotation code Instruction encoding Instruction Function Description add-2r rAA rBB op AA BB rAA=rAA+rBB and-2r rAA rBB op AA BB rAA=rAA&rBB

[0073] S180, compound a group of instructions with similar functions into one instruction, and use the operation type operand in the instruction to specify the operation type of the compounded instruction, to obtain a corresponding compound multi-operation instruction.

[0074] After obtaining the above instructions, a group of instructions with similar functions can be compounded and streamlined to obtain the corresponding compound multi-operation instructions. In devices with limited resources, such as smart cards, security elements, etc., their applications mainly use operations of short data types, and operations of int data types are rarely used; the design of the instruction set generally uses only a range that can be represented by one byte (0 to 255) for the opcode. If each int number operation uses an independent opcode, the possibility of subsequent expansion of instructions for commonly used operations is reduced. Therefore, some uncommon instructions are compounded into one instruction, and the specific operation type is specified by the operation type operand in the instruction, thereby reducing the use of instruction codes in the instruction set and reserving available opcodes for subsequent expansion instructions. The rules for compound instruction streamlining can be configured in the above bytecode instruction set. Specifically, the compound multi-operation instructions are shown in Table 10.

[0075] Table 10

[0076]

[0077]

[0078] In this embodiment, the instructions that assign constants to registers and the instructions that use registers as operands in the initial instructions can be optimized into simplified instructions, or simplified instructions with constants can be directly generated, the instructions that access the current instance domain can be converted into instructions that access the current instance domain, the constant pool index operand in the instruction is encoded into the opcode of the adjacent instruction, the variable-length operands in each instruction are separated from the instruction code, pseudo instructions for static domain initialization are generated, the instructions that reuse registers are optimized into instructions that reuse registers, and a group of instructions with similar functions are combined into one instruction. Through the above steps, the initial instructions are simplified and then the instructions are simplified, so that the length of the bytecode can be reduced and the execution performance of the bytecode can be improved.

[0079] like Figure 2 As shown, a bytecode instruction set instruction simplification system 100 can be configured in a user terminal. The system is used to execute any embodiment of the aforementioned bytecode instruction set instruction simplification method, and includes the following devices: a first merging processing device 110, an instruction conversion device 120, a constant pool splitting device 130, a constant pool index operand encoding device 140, an operand separation device 150, a pseudo-instruction generating device 160, a second merging processing device 170 and a compound multi-operation instruction acquiring device 180.

[0080] The first merging processing device 110 is used to optimize the instructions that assign constants to registers and the instructions that use registers as operands in the initial instructions to obtain simplified instructions that directly use constant operands, or directly generate simplified instructions that use constant operands.

[0081] The instructions for assigning constants to registers include arithmetic and logic operation instructions, jump instructions after comparison with literal constants, and instructions for accessing array members.

[0082] The instruction conversion device 120 is used to convert the instruction of the register corresponding to the method's this parameter in the initial instruction for accessing the instance domain according to a preset instruction format to obtain an instance domain-specific instruction for accessing the current instance.

[0083] In a specific embodiment, the instruction conversion device 120 includes a unit: a register operand deletion unit, which is used to delete the operand of the specified instance according to a preset instruction format for instructions that access the instance domain object as the register corresponding to the this parameter of the method, and obtain an instance domain-specific instruction for accessing the current instance; the instance domain-specific instruction of the current instance can specify the register to be set or return the result by default.

[0084] The constant pool splitting device 130 is used to split the constant pool into multiple sub-constant pools, and the constant pool index in the instruction is the sub-constant pool index.

[0085] The constant pool index operand encoding device 140 is used to encode the constant pool index operand in each instruction of the initial instruction into the operation code of the adjacent instruction; thereby obtaining the operation code of the instruction using the constant pool index through the position of the constant pool index, and determining the type of the sub-constant pool through the operation code.

[0086] In a specific embodiment, the constant pool index operand encoding device 140 includes a first encoding unit or a second encoding unit.

[0087] The first encoding unit is used to uniformly encode the constant pool index operand in each instruction behind the designated code; the second encoding unit is used to uniformly encode the constant pool index operand in each instruction in front of the instruction code.

[0088] The operand separation device 150 is used to separate the variable-length operands from the instruction code in each instruction in the initial instruction.

[0089] The pseudo instruction generating device 160 is used to obtain the static field type and initial configuration value of the static field instruction in the initial instruction, and generate a pseudo instruction corresponding to each static field.

[0090] The second merging processing device 170 is used to optimize the instructions of repeatedly using registers to obtain instructions of multiplexing registers.

[0091] The composite multi-operation instruction acquisition device 180 is used to combine a group of instructions with similar functions into one instruction, and use the operation type operand in the instruction to specify the operation type of the composite instruction to obtain the corresponding composite multi-operation instruction.

[0092] In this embodiment, the instructions that assign constants to registers and the instructions that use registers as operands in the initial instructions can be optimized into simplified instructions, or simplified instructions with constants can be directly generated, the instructions that access the current instance domain can be converted into instructions that access the current instance domain, the constant pool index operand in the instruction is encoded into the opcode of the adjacent instruction, the variable-length operands in each instruction are separated from the instruction code, pseudo instructions for static domain initialization are generated, the instruction length is adjusted according to the configuration items, the instructions that reuse registers are optimized into instructions that reuse registers, and a group of instructions with similar functions are combined into one instruction. Through the above steps, the initial instructions are simplified and then the instructions are simplified, so that the length of the bytecode can be reduced and the execution performance of the bytecode can be improved.

[0093] Those skilled in the art should understand that the method and system described in the present invention are not limited to the embodiments described in the specific implementation manner, and the above specific description is only for the purpose of explaining the present invention, and is not used to limit the present invention. Those skilled in the art can derive other implementation methods according to the technical solution of the present invention, which also belong to the technical innovation scope of the present invention, and the protection scope of the present invention is defined by the claims and their equivalents.< / clinit> < / clinit> < / clinit> < / clinit>

Claims

1. A method for simplifying a bytecode instruction set, characterized in that: The following steps are involved: Optimizing instructions for assigning constants to registers and instructions for using the registers as operands in the initial instructions to obtain instructions that directly use constant operands, or directly generating instructions that use constant operands; The instruction for accessing the instance domain of the method as the this parameter corresponding to the register in the initial instruction is converted according to the preset instruction format to obtain the instance domain-specific instruction for accessing the current instance; Split the constant pool into multiple sub-constant pools, and the constant pool index in the instruction is the sub-constant pool index; Encoding the constant pool index operand in each instruction of the initial instruction to the opcode position immediately adjacent to the instruction; thereby obtaining the opcode of the instruction using the constant pool index through the position of the constant pool index, and determining the type of the sub-constant pool through the opcode; Separating variable-length operands from instruction codes in variable-length instructions; Obtaining a static field type and an initial configuration value of a static field, and generating a pseudo instruction corresponding to each static field declaration, wherein the pseudo instruction can replace a traditional static field component; Optimize the instructions for repeatedly using registers to obtain instructions for multiplexing registers; A group of instructions with similar functions and which are not frequently used are combined into one instruction, and the operation type operand in the instruction is used to specify the operation type of the combined instruction, so as to obtain the corresponding compound multi-operation instruction.

2. The method for simplifying a bytecode instruction set as claimed in claim 1, characterized in that: The instructions for assigning constants to registers include arithmetic and logic operation instructions, jump instructions after comparison with literal constants, and instructions for accessing array members.

3. The method for simplifying a bytecode instruction set as claimed in claim 1, characterized in that: The instruction of converting the instance of the instance domain to be accessed into the register corresponding to the this parameter of the method according to the preset instruction format to obtain the instance domain-specific instruction for accessing the current instance includes: The instruction for accessing the instance domain as the register corresponding to the this parameter of the method deletes the operand of the specified instance according to the preset instruction format, so as to obtain the instance domain-specific instruction for accessing the current instance; the instance domain-specific instruction of the current instance can be further optimized, and the register to be set or the result to be returned can be specified by default.

4. The method for simplifying a bytecode instruction set as claimed in claim 1, wherein: Encode the constant pool index operand in each instruction with a constant pool index immediately adjacent to the instruction's opcode, including: Uniformly encode the constant pool index operand in the instruction after the specified code; Alternatively, the constant pool index operands in the instruction are uniformly encoded in front of the instruction code.

5. An instruction reduction system for a bytecode instruction set, characterized in that: Includes the following devices: A first merging processing device is used to optimize the instructions that assign constants to registers and the instructions that use the registers as operands in the initial instructions to obtain instructions that directly use constant operands, or directly generate instructions that use constant operands; An instruction conversion device, used for converting the instruction for accessing the instance domain of the instance as the method's this parameter corresponding register in the initial instruction according to a preset instruction format to obtain an instance domain-specific instruction for accessing the current instance; A constant pool splitting device, used for splitting the constant pool into a plurality of sub-constant pools, wherein the constant pool index in the instruction is the index of the sub-constant pool, and the sub-constant pool index helps the instruction adopt a shorter encoding method of the sub-constant pool index; A constant pool index operand encoding device is used to encode the constant pool index operand in the instruction to a position adjacent to the operation code of the instruction; thereby obtaining the operation code of the instruction using the constant pool index through the position of the constant pool index, and the type of the sub-constant pool can be determined through the operation code; An operand separation device, used for separating the variable-length operands in the instruction from the instruction code; A pseudo-instruction generating device, used for obtaining the static domain type and initial configuration value of the static domain instruction, and generating a pseudo-instruction corresponding to each static domain declaration, wherein the pseudo-instruction can replace the traditional static domain component; The second merging processing device is used to optimize the instructions of the repeatedly used registers to obtain the instructions of the multiplexed registers; A composite multi-operation instruction acquisition device is used to combine a group of instructions with similar functions and not commonly used into one instruction, and use the operation type operand in the instruction to specify the operation type of the composite instruction to obtain the corresponding composite multi-operation instruction.

6. The instruction reduction system of a bytecode instruction set as claimed in claim 5, characterized in that: The instructions for assigning constants to registers include arithmetic and logic operation instructions, jump instructions after comparison with literal constants, and instructions for accessing array members.

7. The instruction reduction system of a bytecode instruction set as claimed in claim 5, characterized in that: The instruction conversion device comprises a unit: A register operand deletion unit is used to delete the operand of the specified instance according to a preset instruction format from the instruction for accessing the register corresponding to the this parameter of the method whose instance domain is the instance, so as to obtain the instance domain-specific instruction for accessing the current instance; the instance domain-specific instruction of the current instance can be further optimized, and the register to be set or the result to be returned can be specified by default.

8. The instruction reduction system of a bytecode instruction set as claimed in claim 5, characterized in that: The constant pool index operand encoding device includes a first encoding unit or a second encoding unit: The first encoding unit is used to uniformly encode the constant pool index operand in each instruction behind the designated code; The second encoding unit is used to uniformly encode the constant pool index operand in each instruction in front of the instruction code.