Data processing system, data processing method, and electronic device
By introducing a method dispatch acceleration unit and a caching module into the Java Virtual Machine, virtual method dispatch is implemented using a single method dispatch instruction, which solves the problems of long execution cycle and high device overhead of Java virtual method dispatch, and improves efficiency and code density.
Patent Information
- Application Number
- CN202611331922.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-31
- Publication Date
- 2026-11-24
AI Technical Summary
In existing technologies, the execution cycle of Java virtual method dispatch is relatively long and the equipment overhead is large, resulting in low efficiency.
A data processing system is adopted, including a processor core, a Java Virtual Machine, and a method dispatch acceleration unit. Virtual method dispatch is implemented through a single method dispatch instruction. The method dispatch acceleration unit obtains the virtual method table pointer and method index from the object header of the target object, determines and executes the target virtual method, and optimizes virtual method calls in conjunction with a caching module.
It effectively shortens the execution cycle of virtual method dispatch, reduces equipment overhead, and increases code density.
Smart Images

Figure CN123157296A_ABST
Abstract
Description
Technical Field
[0001] This application relates to, but is not limited to, the field of computer technology, and in particular to a data processing system, a data processing method, and an electronic device. Background Technology
[0002] Java is an object-oriented language that typically relies on a virtual method allocation mechanism to achieve polymorphism. Under this mechanism, each object type maintains a virtual method table, which records the entry addresses of all virtual methods corresponding to that class and its parent classes. The virtual method table is searched based on the object's actual type to locate the entry address of the corresponding virtual method. Execution then jumps to that virtual method based on that entry address, achieving dynamic dispatch of virtual methods. Summary of the Invention
[0003] This application provides a data processing system, data processing method, and electronic device to address, to some extent, the problems of long execution cycles and high equipment costs associated with current virtual method dispatching.
[0004] The technical solution of this application embodiment is implemented as follows: This application provides a data processing system, which includes: a processor core, a virtual machine running on the processor core, and a method dispatch acceleration unit coupled to the processor core; The virtual machine is used to drive the processor core to execute method dispatch instructions in response to the virtual method call operation of the target object; The processor core is used to execute the method dispatch instruction, trigger the method dispatch acceleration unit to obtain the virtual method table pointer from the object header of the target object, determine the entry address of the target virtual method corresponding to the target object based on the virtual method table pointer and the method index of the target object, and execute the target virtual method based on the entry address, wherein the method index is the index of the target virtual method in the virtual method table.
[0005] This application also provides a RISC-V data processing system for Java bytecode, including a RISC-V architecture processor core, a Java Virtual Machine (JVM) running on the processor core, and a method dispatch acceleration unit hardware coupled to the processor core. The data processing system supports a custom RISC-V extended instruction set, including the method dispatch instruction `vcall`. The JVM is configured with a Just-In-Time (JIT) compiler and interpreter to compile / interpret the Java virtual method call bytecode `invokevirtual` to generate the method dispatch instruction. The method dispatch acceleration unit has a built-in hardware verification module that performs the following in one step when executing the method dispatch instruction: implicit null pointer verification of the object and validity verification of the virtual method index; verification exceptions directly trigger the corresponding JVM exception. The system can optionally be configured with a vtable cache module to cache the entry address of the virtual method and the object method association identifier. After successful verification, the method dispatch acceleration unit reads the vtable pointer from the object header, calculates the virtual method entry address, and jumps to execute; when the cache is hit, two memory loads are omitted.
[0006] This application provides a data processing method applied to a data processing system. The data processing system includes a processor core, a virtual machine running on the processor core, and a method dispatch acceleration unit coupled to the processor core. The method includes: The virtual machine responds to the virtual method call operation of the target object and drives the processor core to execute the method dispatch instruction; The processor core executes the method dispatch instruction, triggering the method dispatch acceleration unit to obtain the virtual method table pointer from the object header of the target object, determine the entry address of the target virtual method based on the virtual method table pointer and the method index of the target object, and execute the target virtual method based on the entry address. The method index is the index of the target virtual method in the virtual method table.
[0007] This application provides an electronic device, which includes any of the data processing systems described in this application.
[0008] This application provides a computer-readable storage medium storing a computer program or computer-executable instructions for implementing the data processing method provided in this application when executed by a processor.
[0009] This application provides a computer program product, including a computer program or computer executable instructions. When the computer program or computer executable instructions are executed by a processor, they implement the data processing method provided in this application.
[0010] The embodiments of this application have the following beneficial effects: This application provides a data processing system, a data processing method, and an electronic device. The data processing system includes a processor core, a virtual machine running on the processor core, and a method dispatch acceleration unit coupled to the processor core. The virtual machine is used to drive the processor core to execute method dispatch instructions in response to virtual method call operations of a target object. The processor core is used to execute the method dispatch instructions, triggering the method dispatch acceleration unit to obtain a virtual method table pointer from the object header of the target object, determine the entry address of the target virtual method corresponding to the target object based on the virtual method table pointer and the method index of the target object, and execute the target virtual method based on the entry address, effectively realizing virtual method dispatch. The technical solution of this application can compress multiple instructions into a single method dispatch instruction, so as to realize virtual method dispatch using the method dispatch acceleration unit, thereby effectively shortening the execution cycle of virtual method dispatch, reducing equipment overhead, and improving code density. Attached Figure Description
[0011] Figure 1 This is a schematic diagram of the structure of a data processing system provided in an embodiment of this application. Figure 1 ; Figure 2 This is a schematic diagram of the structure of a data processing system provided in an embodiment of this application. Figure 2 ; Figure 3 This is a schematic diagram of the structure of a data processing system provided in an embodiment of this application. Figure 3 ; Figure 4 This is a schematic diagram of the structure of a data processing system provided in an embodiment of this application. Figure 4 ; Figure 5 This is a schematic diagram of the encoding format of a method for dispatching instructions provided in an embodiment of this application; Figure 6 This is a schematic diagram of instruction pipeline processing of a data processing system provided in an embodiment of this application; Figure 7 This is a flowchart illustrating a data processing method provided in an embodiment of this application. Figure 1 ; Figure 8 This is a schematic diagram of the structure of a data processing system provided in an embodiment of this application. Figure 5 ; Figure 9 This is a flowchart illustrating a data processing method provided in an embodiment of this application. Figure 2 .
[0012] It should be noted that the terms "first" and "second" mentioned above are only used to distinguish between different options and do not represent the degree of superiority or inferiority of the options or their priority in the implementation process. Detailed Implementation
[0013] To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limitations on this application. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0014] Java, as an object-oriented language, typically relies on a virtual method dispatch mechanism to achieve polymorphism. Under this mechanism, each object type maintains a virtual method table, which is an array of addresses containing the entry addresses of all virtual methods corresponding to that class and its parent classes. The virtual method table is searched based on the object's actual type to locate the entry address of the corresponding virtual method. Execution then jumps to that virtual method based on that entry address, achieving dynamic virtual method dispatch. However, current virtual method dispatch implementations require the execution of multiple instructions in software, resulting in long execution cycles and significant equipment overhead.
[0015] Specifically, for example, objects, their object headers, virtual method tables, and virtual method code are all stored in memory. The object header can store a pointer (vtable pointer) to the virtual method table corresponding to its actual type, carrying the base address of that virtual method table in memory. Furthermore, the method index of the corresponding virtual method in the virtual method table is fixed for each object during compilation. This can also be understood as follows: during the compilation of an object, the virtual method dispatched to that object is determined from the virtual method table corresponding to the object type, thus obtaining the object's fixed method index, which is the index of the virtual method corresponding to the object in the virtual method table. Based on this, the implementation process of virtual method dispatch for a given object includes: The process involves requesting memory access to load a pointer to the virtual method table corresponding to the object type from the object header. Based on the pointer to the virtual method table, the object's method index, and the size of a single entry (element) in the virtual method table, the access address of the virtual method corresponding to the object is calculated. Another memory access request is made to load the entry address of the virtual method corresponding to the object from the virtual method table based on this access address. The virtual method is then executed based on this entry address, thus achieving virtual method dispatch for the object. The access address `target` satisfies: `target = vtbl + index × word_size`; where `target` represents the access address, `vtbl` represents the pointer to the virtual method table (i.e., the base address of the virtual method table), `index` represents the method index, and `word_size` represents the size of a single entry in the virtual method table.
[0016] In the Java technology field, the Java Virtual Machine (JVM) is a widely used virtual computer that translates the bytecode of a Java program into the instruction set corresponding to the device's operating system and drives the execution of that instruction set to run the Java program. However, currently, the JVM's implementation of virtual method dispatch requires the execution of multiple instructions by software, resulting in a long execution cycle and significant device overhead.
[0017] The bytecode involved in virtual method dispatch is the virtual method invocation bytecode `invokevirtual`. In the general RISC-V instruction set, the JVM typically compiles the virtual method invocation bytecode `invokevirtual` into the following sequence of instructions: `ld temp, 0(obj)` # Load instruction, where `obj` represents the object address, and 0 represents the address offset of the virtual method table pointer in the object header relative to the object address. This load instruction loads the virtual method table pointer corresponding to the object from memory into the `temp` register. The virtual method table pointer is a pointer to the virtual method table. `ld target, index×8(temp)` # Load instruction, where 8 is the size of a single entry in the virtual method table. This load instruction loads the data at the target address in memory into the `target` register. The target address is the access address of the entry point of the virtual method corresponding to the object. jalr target # Indirect jump instruction, jumps to the entry address to execute the virtual method. Clearly, the virtual method call operation described by the virtual method call bytecode `invokevirtual` requires at least three instructions in total. This large number of instructions results in a long execution cycle and significant device overhead. Furthermore, the virtual method call operation also includes null pointer check instructions for checking the object address. Null pointer check instructions are branch instructions, which are prone to branch prediction errors, further extending the instruction execution cycle and increasing device overhead. Therefore, the virtual method call bytecode `invokevirtual` may require four to five instructions in total, involving two to three memory access operations (two load instructions and an indirect jump instruction), as well as additional address calculations and jumps. This results in the overall virtual method dispatch consuming approximately 15 to 18 clock cycles, leading to a long execution cycle and significant device overhead.
[0018] Please refer to Figure 1This illustration shows a schematic diagram of a data processing system provided in an embodiment of this application. Optionally, the data processing system can be implemented in electronic devices such as mobile phones, computers, servers, and wearable devices. For example, the data processing system can be implemented on the processor of an electronic device. Figure 1 As shown, the data processing system 10 includes: a processor core 101, a virtual machine running on the processor core 101, and a method dispatch acceleration unit 102 coupled to the processor core 101.
[0019] The virtual machine responds to virtual method invocation operations of the target object, driving processor core 101 to execute method dispatch instructions. Processor core 101 executes the method dispatch instructions, triggering method dispatch acceleration unit 102 to obtain a virtual method table pointer from the target object's object header. Based on the virtual method table pointer and the target object's method index, it determines the entry address of the target virtual method corresponding to the target object and executes the target virtual method based on the entry address. The method index is the index of the target virtual method corresponding to the object in the virtual method table.
[0020] In some embodiments, the coupling of the method dispatch acceleration unit 102 with the processor core 101 emphasizes the control relationship between the processor core 101 and the method dispatch acceleration unit. The processor core 101 and the method dispatch acceleration unit 102 can be two relatively independent hardware units that can communicate with each other via an interface. Alternatively, the method dispatch acceleration unit 102 can be integrated onto the processor core 101. Figure 1 The following is an example of a method dispatch acceleration unit 102 integrated on the processor core 101.
[0021] In some embodiments, the method dispatch acceleration unit 102 can be a dedicated hardware circuit that can execute a call to the target virtual method corresponding to the target object under the trigger of a single method dispatch instruction, so as to realize the dynamic dispatch of the virtual method.
[0022] In some embodiments, the data processing system may be a device running on the Java language, which is a general-purpose, object-oriented programming language. Correspondingly, alternatively, the virtual machine may refer to the JVM (Java Virtual Machine), a virtual computer that runs Java programs.
[0023] In some embodiments, such as Figure 2As shown, the object, its object header, virtual method table, and virtual method code are all stored in the memory of the memory subsystem 103. The memory subsystem 103 also includes a memory controller. Triggered by the method dispatch instruction executed by the processor core 101, the method dispatch acceleration unit 102 performs access operations through the memory subsystem 103 to implement the virtual method invocation operation on the target object. Optionally, the method dispatch acceleration unit 102 is also used to obtain the virtual method table pointer from the object header of the target object, calculate the access address of the entry address of the target virtual method corresponding to the target object based on the virtual method table pointer and the method index of the target object, load the entry address of the target virtual method based on the access address, and execute the target virtual method based on the entry address. For example, the offset of the virtual method table pointer in the object header relative to the beginning of the object header is fixed. That is, the address offset of the virtual method table pointer in the object header relative to the object address is fixed. The object address, also known as the object header address, refers to the starting address of the object header in memory.
[0024] The method dispatch acceleration unit 102 can send a read request to the memory subsystem 103 to load the virtual method table pointer from the object header of the target object in memory based on the object address of the target object and the address offset of the virtual method table pointer; calculate the access address of the entry address of the target virtual method corresponding to the target object based on the virtual method table pointer, the method index of the target object, and the size of a single entry in the virtual method table; send a read request to the memory subsystem 103 to load the entry address of the target virtual method in memory based on the access address, and jump to that entry address to execute the target virtual method. Here, the access address target satisfies: target = vtbl + index × word_size; target represents the access address, vtbl represents the virtual method table pointer, index represents the method index of the target object, and word_size represents the size of a single entry in the virtual method table.
[0025] In some embodiments, the method dispatch acceleration unit 102 is further configured to, after determining the entry address of the target virtual method corresponding to the target object, modify the value stored in the program register PC of the processor core 101 to the entry address, so as to execute the target virtual method based on the entry address. In other embodiments, the method dispatch acceleration unit 102 may also be configured to, while modifying the value stored in the program register PC of the processor core 101 to the entry address, write the entry address of the next instruction of the method dispatch instruction into the link register to simulate the indirect jump instruction jalr, so that after the target virtual method is executed, it can return to execute the next instruction of the method dispatch instruction.
[0026] In some embodiments, the method dispatch acceleration unit 102 is further configured to perform an index validity check on the method index of the target object, and trigger index exception handling if the check result indicates that the method index is invalid. In some embodiments, the index validity check is at least used to check whether the data length of the method index is within the valid length range to determine whether the method index is valid data. Based on this, the method dispatch acceleration unit 102 can trigger index exception handling if the check result indicates that the data length of the method index is outside the valid length range, i.e., the method index is invalid. In some embodiments, index exception handling is used to trigger the virtual machine to throw an AbstractMethodError. For example, index exception handling is used to be caught by the virtual machine's exception handler to throw an AbstractMethodError. And in one example, after throwing an AbstractMethodError and processing it, the virtual machine can directly return to the next instruction of the method dispatch instruction or re-execute the method dispatch instruction.
[0027] In this embodiment, the virtual method invocation operation of the target object refers to the process of dispatching virtual methods for the target object. In response to the virtual method invocation operation of the target object, the virtual machine drives the processor core 101 to execute a method dispatch instruction. This instruction controls the method dispatch acceleration unit 102 to obtain the virtual method table pointer from the object header of the target object. Based on the virtual method table pointer and the method index of the target object, the entry address of the target virtual method corresponding to the target object is determined, and the target virtual method is executed based on the entry address, thus realizing the invocation of the target virtual method corresponding to the target object and completing the dynamic dispatch of the virtual method for the target object. Clearly, this embodiment can integrate virtual method dispatch into the method dispatch acceleration unit 102. By compressing multiple instructions into a single method dispatch instruction, the method dispatch acceleration unit can be used to implement virtual method dispatch, thereby effectively shortening the execution cycle of virtual method dispatch, reducing device overhead, and increasing code density.
[0028] In optional embodiments of this application, such as Figure 3 As shown, the data processing system also includes a cache module 104. The cache module, also known as the virtual method table cache module (Vtable Target Cache, VTC) 104 or vtable cache module 104, is used to cache the entry addresses of at least some of the virtual methods corresponding to objects.
[0029] The method dispatch acceleration unit 102 is further configured to execute the target virtual method based on the entry address of the target virtual method in the cache module 104 when the entry address of the target virtual method corresponding to the target object exists in the cache module 104; and to obtain the virtual method table pointer from the object header of the target object when the entry address of the target virtual method corresponding to the target object does not exist in the cache module 104, determine the entry address of the target virtual method based on the virtual method table pointer and the method index of the target object, and execute the target virtual method based on the entry address.
[0030] In this optional embodiment, the method dispatch acceleration unit 102, triggered by a method dispatch instruction, can determine whether the cache module 104 caches the entry address of the target virtual method corresponding to the target object, thereby determining whether the cache module 104 has hit the entry address of the target virtual method. If the entry address of the target virtual method exists in the cache module 104, i.e., the cache module 104 has hit the entry address of the target virtual method, the cache module 104 directly reads the entry address of the target virtual method and executes the target virtual method based on the read entry address. If the entry address of the target virtual method does not exist in the cache module 104, i.e., the cache module 104 has not hit the entry address of the target virtual method, the virtual method table pointer is loaded from the object header of the target object in memory, the access address of the entry address of the target virtual method is determined based on the virtual method table pointer and the method index of the target object, the entry address at the access address is loaded from memory, and the target virtual method is executed based on the entry address.
[0031] Thus, with the cache module 104 configured, since the cache module 104 caches the entry addresses of virtual methods corresponding to at least some objects, the method dispatch acceleration unit 102 can directly read the entry address of the target virtual method from the cache module 104 when the cache module 104 caches the entry address of the target virtual method corresponding to the target object. This allows for jumps to that entry address to execute the target virtual method, eliminating the need for at least two memory accesses to retrieve the entry address from memory. This effectively shortens the process of retrieving the target virtual method's entry address, reducing the execution latency of the target virtual method to approximately 4 to 6 clock cycles, further effectively shortening the execution cycle of virtual method dispatch. Testing shows that for calls to hot virtual methods (such as repeated calls to the same virtual method in a loop), the cache module 104 achieves a virtual method hit rate of over 90%. When the cache module hits a virtual method, the execution latency of the virtual method drops to approximately 4 to 6 clock cycles, and the average overall virtual method call latency drops to approximately 5 cycles, effectively shortening the execution cycle of virtual method dispatch.
[0032] In some embodiments, the caching module 104 is used to cache the correspondence between the entry address of a virtual method and the object method association identifier. The object method association identifier is used to identify the association between a virtual method and an object. The object method association identifier includes an object address and a method index, or it includes an object class pointer and a method index, or it includes an object's virtual method table pointer and a method index. Since the offset of the virtual method table pointer in the object header relative to the beginning of the object header (object address) is fixed, the object address can be used to locate the virtual method table pointer. Similarly, the object class pointer refers to the pointer to class metadata stored in the object header. Since the offset of the object class pointer in the object header relative to the beginning of the object header is fixed, and the offset of the virtual method table pointer in the object header relative to the beginning of the object header is also fixed, the addresses of the object class pointer and the virtual method table pointer in the object header are also relatively fixed. Therefore, the object class pointer can also locate the virtual method table pointer. Based on this, it is easy to understand that both the object address and the object class pointer can indicate the virtual method table pointer, which, combined with the object's method index, identifies the association between the virtual method and the object.
[0033] The method dispatch acceleration unit 102 is further configured to, when there is an entry address in the cache module 104 corresponding to the object method association identifier of the target object, execute the target virtual method based on the entry address in the cache module 104 corresponding to the object method association identifier of the target object; when there is no entry address in the cache module 104 corresponding to the object method association identifier of the target object, obtain the virtual method table pointer from the object header of the target object, determine the entry address of the target virtual method based on the virtual method table pointer and the method index of the target object, and execute the target virtual method based on the entry address.
[0034] For example, consider an object method association identifier that includes the object's virtual method table pointer and method index. The method dispatch acceleration unit 102, triggered by a method dispatch instruction, can retrieve the virtual method table pointer from the target object's object header and determine whether the cache module 104 caches the target object's method index and virtual method table pointer. This allows it to determine whether the cache module 104 has cached the entry address of the target virtual method corresponding to the target object, thus facilitating the determination of whether the cache module 104 has hit the entry address of the target virtual method.
[0035] When the cache module 104 caches the method index and virtual method table pointer of the target object, the method dispatch acceleration unit 102 assumes that the cache module 104 contains the entry address of the target virtual method. It then directly reads the entry address corresponding to the method index and virtual method table pointer of the target object from the cache module 104 and executes the target virtual method based on the read entry address. Conversely, when the cache module 104 does not cache the method index and virtual method table pointer of the target object, the method dispatch acceleration unit 102 assumes that the cache module 104 does not contain the entry address of the target virtual method. It then determines the access address of the target virtual method's entry address based on the virtual method table pointer and the method index of the target object, loads the entry address at that access address from memory, and executes the target virtual method based on that entry address.
[0036] Another example is the object method association identifier, which includes the object address and method index. The method dispatch acceleration unit 102, triggered by a method dispatch instruction, can directly determine whether the cache module 104 caches the method index and object address of the target object, thereby determining whether the cache module 104 caches the entry address of the target virtual method corresponding to the target object, thus facilitating the determination of whether the cache module 104 has hit the entry address of the target virtual method.
[0037] When the cache module 104 caches the method index and object address of the target object, the method dispatch acceleration unit 102 assumes that the cache module 104 contains the entry address of the target virtual method. It then directly reads the entry address corresponding to the method index and object address of the target object from the cache module 104 and executes the target virtual method based on the read entry address. Conversely, when the cache module 104 does not cache the method index and object address of the target object, the method dispatch acceleration unit 102 assumes that the cache module 104 does not contain the entry address of the target virtual method. It then loads a virtual method table pointer from the object header of the target object in memory, determines the access address of the target virtual method's entry address based on the virtual method table pointer and the target object's method index, loads the entry address at that access address from memory, and executes the target virtual method based on that entry address. It is easy to understand that, compared to the scheme where the object method association identifier includes the object's virtual method table pointer and method index, the scheme where the object method association identifier includes the object's object address and method index can save the memory access step of loading the virtual method table pointer when the cache module 104 hits the entry address of the target virtual method, and further shorten the execution cycle of virtual method dispatch.
[0038] In some embodiments, the correspondence between the entry address of a virtual method and the object method association identifier in the cache module 104 can be stored in a key-value pair format. The key in the key-value pair is the object method association identifier, and the value is the entry address of the virtual method. For example, the object method association identifier includes the object's virtual method table pointer (vtbl) and method index (index). The key-value pair in the cache module 104 is (vtbl, index) - addr, where addr represents the entry address of the virtual method. In some embodiments, the correspondence between the entry address of a virtual method and the object method association identifier in the cache module 104 can be stored in a tag-data format. The tag is the object method association identifier, and the data is the entry address of the virtual method. For example, the object method association identifier includes the object's virtual method table pointer and method index. The tag is the concatenated data of the object's corresponding virtual method table pointer and method index. The data length of the virtual method table pointer is 28 bits, and the data length of the method index is 12 bits, so the data length of the tag is 40 bits. The data is the entry address of the virtual method corresponding to the object, and the data length of this entry address is 64 bits.
[0039] In some embodiments, the cache module 104 may employ a fully associative or set-associative structure, comprising 8 to 32 entries. For example, the cache module 104 may be a 16-entry fully associative cache structure. Each entry records the object method association identifier of an object and the entry address of the virtual method corresponding to that object. When the object method association identifier includes a pointer to the object's virtual method table and a method index, each entry includes a label and data; the label includes the pointer to the object's virtual method table and the method index; the data is the entry address of the virtual method corresponding to that object.
[0040] In an optional embodiment of this application, the method dispatch acceleration unit 102 is further configured to cache the entry address of the target virtual method corresponding to the target object in the cache module 104 when the entry address of the target virtual method corresponding to the target object does not exist in the cache module 104. In some embodiments, the cache module 104 is configured to cache the correspondence between the entry address of the virtual method and the object method association identifier. The method dispatch acceleration unit 102 is further configured to cache the object method association identifier of the target object and the entry address of the target virtual method corresponding to the target object in the cache module 104 when the entry address corresponding to the object method association identifier of the target object does not exist in the cache module 104.
[0041] Specifically, optionally, the method dispatch acceleration unit 102 can be used to execute the target virtual method based on the entry address corresponding to the object method association identifier of the target object in the cache module 104 when the cache module 104 contains an entry address corresponding to the object method association identifier of the target object; when the cache module 104 does not contain an entry address corresponding to the object method association identifier of the target object, it can obtain the virtual method table pointer from the object header of the target object, determine the entry address of the target virtual method based on the virtual method table pointer and the method index of the target object, execute the target virtual method based on the entry address, and cache the object method association identifier of the target object and the entry address of the target virtual method corresponding to the target object in the cache module 104. This facilitates the direct reuse of the entry address of the target virtual method in the cache module 104 when encountering the virtual method call operation of the target object again, effectively shortening the process of obtaining the entry address of the target virtual method, reducing the execution latency of the target virtual method, and further effectively shortening the execution cycle of virtual method dispatch.
[0042] In some embodiments, the method dispatch acceleration unit 102 can directly cache the entry address of the target virtual method corresponding to the target object in the cache module 104 if the entry address of the target virtual method corresponding to the target object does not exist in the cache module 104.
[0043] In some embodiments, the method dispatch acceleration unit 102 may also cache the entry address of the target virtual method corresponding to the target object in the cache module 104 according to the Least Recently Used (LRU) strategy. The LRU strategy is used to limit the method dispatch acceleration unit 102 to selectively replace the entry address of the object that has been least recently hit with the entry address of the target object.
[0044] For example, the cache module 104 is a fully associative cache structure with 16 items. The method dispatch acceleration unit 102 can overwrite the object method association identifier of the target object and the entry address of the target virtual method corresponding to the target object into the eviction entry if the entry address of the target virtual method corresponding to the target object does not exist in the cache module 104. The eviction entry refers to the most recently missed entry.
[0045] By updating the cache module 104 according to the LRU policy, the hit rate of the cache module 104 can be guaranteed to a certain extent, while effectively limiting the size of the cache module 104 and ensuring that the cache module 104 occupies a small circuit area.
[0046] In an optional embodiment of this application, the method dispatch instruction includes address information and the method index of the target object. The address information indicates the object address of the target object. The method dispatch acceleration unit 102 is further configured to perform a null pointer check on the object address of the target object, and if the check result indicates that the object address is not null, obtain the virtual method table pointer from the object header of the target object based on the object address of the target object, determine the entry address of the target virtual method based on the virtual method table pointer and the method index of the target object, and execute the target virtual method based on the entry address.
[0047] In some embodiments, under the drive of a virtual machine, the processor core 101 can parse the method dispatch instruction to obtain address information, transmit the address information to the method dispatch acceleration unit 102, and trigger the method dispatch acceleration unit 102 to perform a null pointer check on the object address of the target object. If the check result indicates that the object address is not null, the virtual method table pointer is obtained from the object header of the target object based on the object address of the target object. The entry address of the target virtual method is determined based on the virtual method table pointer and the method index of the target object, and the target virtual method is executed based on the entry address. The null pointer check is used to check whether the object address is valid. For example, the null pointer check is used to check whether the object address is 0.
[0048] In some embodiments, the method dispatch acceleration unit 102 is further configured to perform a null pointer check on the object address of the target object. If the check result indicates that the object address is not null, and if the cache module 104 contains the entry address of the target virtual method corresponding to the target object, then the target virtual method is executed based on the entry address of the target virtual method in the cache module 104. If the cache module 104 does not contain the entry address of the target virtual method corresponding to the target object, then the virtual method table pointer is obtained from the object header of the target object, the entry address of the target virtual method is determined based on the virtual method table pointer and the method index of the target object, and the target virtual method is executed based on the entry address.
[0049] Optionally, the method dispatch acceleration unit 102 is further configured to trigger null pointer exception handling if the check result indicates that the object address is null. In some embodiments, null pointer exception handling is used to trigger an illegal instruction exception or a custom null pointer exception. In other embodiments, null pointer exception handling is used to trigger the virtual machine to throw a null pointer exception (NPE). For example, null pointer exception handling is used to be caught by the virtual machine's exception handler to throw an NPE. And in one example, after throwing and handling the NPE, the virtual machine can directly return to the next instruction of the method dispatch instruction or re-execute the method dispatch instruction.
[0050] For example, processor core 101 can be a processor core based on the RISC-V instruction set framework. The RISC-V instruction set framework has a standard Machine Trap Vector Table (MTVT) register, or a Supervisor Trap Vector Base Address Register (STVEC), both of which can be used to store the code base address of exception / interrupt handlers. The virtual machine can assign an exception number (e.g., 16) to the null pointer exception handler during its initialization. This exception number indicates the code base address of the null pointer exception handler. The virtual machine writes this exception number to the MTVT register / STVEC register so that the virtual machine's exception handler can perform pipeline flushing when the object address is null, and obtain the null pointer exception handler's code base address based on the exception number in the MTVT register / STVEC register, ensuring that a NPE is correctly thrown.
[0051] In this way, the method dispatch acceleration unit 102 performs a null pointer check on the object address before executing the target virtual method corresponding to the target object, effectively identifying invalid object addresses. This effectively avoids problems such as the virtual method table pointer failing to load or the entry address of the target virtual method being undetermined due to invalid object addresses. This, to a certain extent, prevents erroneous or unexecuted virtual method dispatch, ensuring the effective execution of virtual method dispatch. Furthermore, the null pointer exception handling triggered by the method dispatch acceleration unit 102 can reuse the virtual machine's exception mechanism, without requiring modification of the exception handling framework in related technologies.
[0052] In one alternative implementation, the address information in the method dispatch instruction may include the object address of the target object. The processor core 101, driven by a virtual machine, can parse the method dispatch instruction to obtain the object address of the target object, transmit the object address of the target object to the method dispatch acceleration unit 102, and trigger the method dispatch acceleration unit 102 to perform a null pointer check on the object address of the target object.
[0053] In some embodiments, the address information in the method dispatch instruction may include: a device identifier of a first source register. The first source register is used to store the object address of the target object. Optionally, the device identifier of the first source register may be the physical address of the first source register, or the device number of the first source register, which corresponds to the physical address. For example, the first source register may be a register configured by the virtual machine at startup to store the object address of the target object to which the virtual method dispatch occurs.
[0054] The method dispatch acceleration unit 102 is also used to read the object address of the target object from the first source register, perform a null pointer check on the object address, and if the check result indicates that the object address is not null, obtain the virtual method table pointer from the object header of the target object based on the object address of the target object, determine the entry address of the target virtual method based on the virtual method table pointer and the method index of the target object, and execute the target virtual method based on the entry address.
[0055] In some embodiments, under the drive of a virtual machine, the processor core 101 can parse the method dispatch instruction to obtain the device identifier of the first source register, transmit the device identifier of the first source register to the method dispatch acceleration unit 102, and trigger the method dispatch acceleration unit 102 to read the object address of the target object from the first source register and perform a null pointer check on the object address.
[0056] In some embodiments, the virtual machine can be used to respond to a virtual method call operation of a target object, write the object address of the target object into a first source register, and then drive the processor core 101 to execute a method dispatch instruction, which includes the device identifier of the first source register.
[0057] In some embodiments, such as Figure 4 As shown, the processor core 101 includes an instruction fetch unit 1011 and a decoding unit 1012. The instruction fetch unit 1011 reads the method dispatch instruction and passes it to the decoding unit 1012. The decoding unit 1012 parses the method dispatch instruction to trigger the method dispatch acceleration unit 102 to obtain the virtual method table pointer from the object header of the target object based on the object address of the target object, determine the entry address of the target virtual method based on the virtual method table pointer and the method index of the target object, and execute the target virtual method based on the entry address.
[0058] In an optional configuration, the decoding unit 1012 is used to parse the method dispatch instruction, obtain the device identifier of the first source register, and trigger the method dispatch acceleration unit 102 to read the object address of the target object from the first source register, perform a null pointer check on the object address, and if the check result indicates that the object address is not null, obtain the virtual method table pointer from the object header of the target object based on the object address of the target object, determine the entry address of the target virtual method based on the virtual method table pointer and the method index of the target object, and execute the target virtual method based on the entry address.
[0059] In an optional configuration, the instruction fetch unit 1011 can be a dedicated hardware circuit that supports reading method dispatch instructions under the drive of the virtual machine and passing the method dispatch instructions to the decoding unit 1012. For example, in response to a virtual method call operation of a target object, the virtual machine can drive the instruction fetch unit 1011 to jump and read the method dispatch instructions, so that after reading the method dispatch instructions, it can pass the method dispatch instructions to the decoding unit 1011. In another optional configuration, the decoding unit 1012 can be a dedicated hardware circuit that, upon receiving a method dispatch instruction, parses the method dispatch instruction to obtain the device identifier of the first source register included therein, transmits the device identifier to the method dispatch acceleration unit 102, and triggers the method dispatch acceleration unit 102 to read the object address of the target object from the first source register, performs a null pointer check on the object address, and, if the check result indicates that the object address is not null, obtains the virtual method table pointer from the object header of the target object based on the object address of the target object, determines the entry address of the target virtual method based on the virtual method table pointer and the method index of the target object, and executes the target virtual method based on the entry address; if the check result indicates that the object address is null, triggers null pointer exception handling.
[0060] It is easy to understand that a single method dispatch instruction can implement implicit null pointer checks. Compared with the explicit null pointer checks in related technologies, it does not require a separate branch and effectively avoids the additional overhead caused by branch prediction errors.
[0061] In an optional embodiment of this application, the method dispatch instruction further includes a target operation identifier, which is used to identify that the instruction type is a method dispatch instruction. The processor core 101 is also configured to parse instructions executed by the virtual machine driver. When a method dispatch instruction including the target operation identifier is parsed, the method dispatch acceleration unit 102 is triggered to obtain a virtual method table pointer from the object header of the target object based on the object address of the target object, determine the entry address of the target virtual method based on the virtual method table pointer and the method index of the target object, and execute the target virtual method based on the entry address.
[0062] The instructions executed by the processor core may include an operation identifier, which identifies the instruction type. When executing instructions under the drive of a virtual machine, the processor core 101 can parse the instruction to obtain the operation identifier. If the operation identifier is a target operation identifier, it indicates that a method dispatch instruction has been parsed, triggering the method dispatch acceleration unit 102 to obtain the virtual method table pointer from the object header of the target object based on the object address of the target object, determine the entry address of the target virtual method based on the virtual method table pointer and the method index of the target object, and execute the target virtual method based on the entry address.
[0063] In some embodiments, the method dispatch instruction can be a custom RISC-V instruction, without modifying the underlying Instruction Set Architecture (ISA) of the RISC-V instruction set architecture. This fully leverages the scalability of the RISC-V instruction set and allows coexistence with vector extensions. The format of the method dispatch instruction is a custom RISC-V encoding format, specifically the I-type format. The method dispatch instruction includes the opcode, destination operand (rd), main function code (funct3), source operand (rs), and immediate value (imm).
[0064] In this process, the values of the opcode and the main function code constitute the target operation identifier; the source operand is the device identifier of the first source register; the target operand is placeholder data; and the immediate value is the method index of the target object. That is, when the opcode is a first value and the main function code is a second value, the values of the opcode and the main function code constitute the target operation identifier. In other words, the method dispatch instruction includes an opcode of the first value and a main function code of the second value. The processor core 101 can be used to parse the instruction to obtain the opcode and main function code when executing the instruction under the drive of a virtual machine. When the opcode is the first value and the main function code is the second value, it indicates that a method dispatch instruction has been parsed, triggering the method dispatch acceleration unit 102 to execute the target virtual method corresponding to the target object.
[0065] In some embodiments, the opcode value can be a custom opcode. The main function code value can also be a custom function code. For example, the method dispatch instruction is encoded using an opcode allocated within the opcode space reserved under the RISC-V instruction set architecture, and its encoding format can be I-type or R-type. Specifically, for example, such as... Figure 5 As shown, the format of the method dispatch instruction is I-type, and its encoding can be 32-bit binary data. In this encoding, bits 1 to 7 are the opcode, bits 8 to 12 are the destination operand, bits 13 to 15 are the main function code, bits 16 to 20 are the source operand, and bits 21 to 32 are the immediate value, which is a 12-bit signed number. Specifically: in the encoding of the method dispatch instruction, method dispatch instruction [6:0] = opcode, method dispatch instruction [11:7] = rd, method dispatch instruction [14:12] = funct3, method dispatch instruction [19:15] = rs, and method dispatch instruction [31:20] = imm.
[0066] For example, in the method dispatch instruction, opcode = 0b0001011 (custom value), funct3 = 0b100, imm = method index of the target object, rd = 0x00, and rs = device identifier of the first source register. When the processor core 101 executes the instruction under the virtual machine's drive, it parses the instruction to obtain the opcode and main function code funct3. If the opcode value is 0b0001011 (i.e., the first value) and the main function code funct3 value is 0b100 (i.e., the second value), it indicates that a method dispatch instruction has been parsed. This triggers the method dispatch acceleration unit 102 to obtain the virtual method table pointer from the object header of the target object based on the object address of the target object. Based on the virtual method table pointer and the method index of the target object, it determines the entry address of the target virtual method and executes the target virtual method based on the entry address. As another example, since there are 4096 possible values for a 12-bit signed number (i.e., -2048 to 2047), and the method index in the virtual method table is a non-negative number (0 to 2047), the method dispatch acceleration unit 102 can be used to perform an index validity check on the method index of the target object to check whether the data length of the method index is within the valid length range (i.e., 0 to 2047).
[0067] For example, the data processing system 10 includes: a processor core 101, a virtual machine running on the processor core 101, a method dispatch acceleration unit 102 coupled to the processor core 101, and a memory subsystem 103. Objects and their fields are stored in the memory of the memory subsystem 103.
[0068] The processor core 101 includes an instruction fetch unit 1011 and a decoding unit 1012. For example... Figure 6 As shown, the processor pipeline of processor core 101 includes five standard stages: fetch (F), decode (D), execute (E), memory access (M), and write back (W). That is, processor core 101 needs to go through these five standard stages sequentially to execute a single instruction.
[0069] During the instruction fetching stage, the instruction fetching unit 1011 reads the method dispatch instruction (i.e., reads the binary code of the method dispatch instruction) and transmits the method dispatch instruction to the decoding unit 1012.
[0070] During the decoding stage, the decoding unit (also known as the extended instruction decoding unit) 1012 parses the received instruction, identifies the opcode with a value of 0b0001011 and the main function code funct3 with a value of 0b100, indicating that the received instruction is a method dispatch instruction (i.e., opcode = 0b0001011 and funct3 = 0b100 are identified, confirming the method dispatch instruction), and identifies the values of the source operand rs and the immediate value imm, obtains the device identifier of the first source register and the method index of the target object, and triggers the method dispatch acceleration unit 102 to perform the following operations during the execution stage.
[0071] During the execution phase, the method dispatch acceleration unit 102 reads the first source register rs to obtain the object address in the first source register, and performs a null pointer check on the object address. If the check result indicates that the object address is null, null pointer exception handling is triggered. If the check result indicates that the object address is not null, a first read request is sent to the memory subsystem 103. This first read request is used to request the loading of the virtual method table pointer from the object header of the target object in memory based on the object address of the target object and the address offset of the virtual method table pointer.
[0072] During the memory access phase, memory subsystem 103 responds to the first read request and sends a virtual method table pointer to method dispatch acceleration unit 102. Method dispatch acceleration unit 102 determines the access address of the target virtual method's entry point based on the virtual method table pointer and the method index of the target object, and sends a second read request to memory subsystem 103. This second read request is used to request the entry address of the target virtual method based on the access address. Memory subsystem 103 responds to the second read request and sends the entry address of the target virtual method to method dispatch acceleration unit 102. Method dispatch acceleration unit 102 executes the target virtual method based on the entry address.
[0073] Since the execution result of the method dispatch instruction is to obtain the entry address of the target virtual method dispatched to the target object, and to execute the target virtual method based on the entry address, it does not generate data that needs to be written back. Therefore, after the method dispatch acceleration unit 102 executes the target virtual method, there is no write-back operation in the write-back phase, and the method dispatch instruction is retired.
[0074] In optional embodiments of this application, the virtual machine includes at least one of the following: a just-in-time compiler, an interpreter, A just-in-time compiler is used to generate method dispatch instructions based on a system architecture description file, in response to the compilation operation of virtual method call bytecode (such as invokevirtual) of a target object. The system architecture description file is used to indicate the matching rules between instructions and bytecode. The interpreter, in response to the virtual method call bytecode of the target object, drives the processor core to jump and execute the method dispatch instructions inlined in the machine instruction template, which indicates the instruction sequence corresponding to the bytecode. The virtual method call bytecode describes the virtual method call operation of the target object.
[0075] The virtual machine is also used to respond to virtual method call operations of the target object, drive the processor core 101 to jump and execute the method dispatch instructions generated by the just-in-time compiler, or execute the interpretation and execution of the virtual method call bytecode of the target object through the interpreter, so as to drive the processor core 101 to jump and execute the method dispatch instructions inlined in the machine instruction template.
[0076] An interpreter is an execution component that translates bytecode into machine code line by line during program execution; it can be a component of a virtual machine. When the virtual machine starts, the interpreter generates a machine instruction template for the opcodes of each bytecode and records the mapping between the opcodes and the base addresses of the machine instruction templates. The machine instruction template is a sequence of executable machine code corresponding to each bytecode. During virtual machine execution, when interpreting and executing a bytecode, the interpreter, based on the mapping between the opcode and the base address of the machine instruction template, obtains the base address of the machine instruction template corresponding to the opcode of that bytecode, and modifies the program register of processor core 101 to that base address, so that processor core 101 jumps to execute the machine code in the machine instruction template corresponding to that bytecode based on that base address.
[0077] Optionally, based on this, assembly method dispatch instructions can be pre-inlined in the machine instruction template corresponding to the opcode of the virtual method call bytecode. When the interpreter responds to the interpretation and execution of the virtual method call bytecode of the target object, it can modify the program register of the processor core 101 to the base address of the machine instruction template corresponding to the opcode of the virtual method call bytecode, so that the processor core 101 jumps to execute the method dispatch instructions in the machine instruction template corresponding to the bytecode based on the base address, thereby driving the processor core 101 to jump to execute the method dispatch instructions inlined in the machine instruction template.
[0078] For example, the following instructions can be inlined into the machine instruction template corresponding to the opcode of the virtual method call bytecode `invokevirtual`, so that the interpreter no longer needs to call hundreds of lines of C code but directly uses inline assembly to dispatch instructions. The inline assembly method dispatch instructions are as follows: vcall obj_reg, method_index # Method dispatch instruction, where obj_reg represents the device identifier of the first register, and method_index represents the method index of the target object. # The method dispatch instruction retires; after the target virtual method returns, execution continues with the next instruction. A Just-In-Time (JIT) compiler is a dynamic compilation component that translates bytecode into machine code (i.e., machine instructions) at runtime. Combining the advantages of compiled execution and interpreted execution, the JIT compiler triggers compilation and caches machine code only on the first call to the code. Subsequent calls to the same code can directly execute the cached machine code, avoiding repeated translations. The JIT compiler uses a system architecture description file, which specifies the matching rules between instructions and bytecode. By modifying the matching rules between virtual method call bytecode and method dispatch instructions in the JIT's system architecture description file, the JIT can generate method dispatch instructions based on the system architecture description file when compiling virtual method call bytecode in response to the target object.
[0079] In some embodiments, it is assumed that the just-in-time compiler is a C2 compiler (a type of JIT). The C2 compiler has a system architecture description file (riscv.ad) under the RISC-V instruction set architecture. This system architecture description file is used to indicate the matching rules of registers, intermediate representation (IR) nodes, and machine instructions in the RISC-V instruction set.
[0080] The C2 compiler's bytecode compilation process includes: converting the bytecode into an IR graph, optimizing the IR graph, calling the matcher, traversing the optimized IR graph, and translating the nodes in the IR graph into machine code based on the matching rules described in the system architecture description file, ultimately obtaining all the machine code based on the bytecode conversion. The IR graph consists of nodes and directed edges. Nodes represent operations, values, or control flow; directed edges represent dependencies such as data flow, control flow, or memory dependencies between nodes.
[0081] Optionally, the matching rules of the IR node corresponding to the virtual method call bytecode in the system architecture description file can be modified in advance to change the instruction sequence in the system architecture description file that matches the IR node into method dispatch instructions (a type of machine instruction), so that the IR node matches the method dispatch instructions. When the C2 compiler responds to the compilation operation of the virtual method call bytecode of the target object, it can translate the IR node into method dispatch instructions based on the modified system architecture description file to generate method dispatch instructions.
[0082] Therefore, in response to a virtual method call operation of the target object, the virtual machine can directly drive the processor core 101 to jump and execute the method dispatch instruction generated by the just-in-time compiler. For example, the C2 compiler can pre-compile the bytecode into machine code and store it in a dedicated area of memory when the virtual machine starts, so that the virtual machine can drive the processor core 101 to jump and execute the pre-generated machine code in the dedicated area by modifying the program register of the processor core 101 during operation.
[0083] Furthermore, when the virtual machine includes a JIT compiler and an interpreter, the interpreter can, upon detecting hot bytecode and responding to its interpretation and execution, simultaneously invoke the JIT compiler to compile the hot bytecode based on the system architecture description file, generating the corresponding machine code. This allows the virtual machine to subsequently drive the processor core 101 to jump and execute the JIT-generated machine code in response to the processing operations described by the hot bytecode. Here, hot bytecode refers to the bytecode corresponding to hot method code, which is method code whose call count exceeds a threshold. Alternatively, in response to a virtual method call operation of a target object, the virtual machine can directly drive the processor core 101 to jump and execute the JIT-generated method dispatch instruction if pre-generated JIT machine code exists. Otherwise, if pre-generated JIT machine code is not available, the interpreter executes the interpretation and execution of the target object's virtual method call bytecode to drive the processor core 101 to jump and execute the method dispatch instruction inlined within the machine instruction template.
[0084] In this optional embodiment, by designing and compressing the multiple instructions for virtual method dispatch in related technologies into a single instruction, the JIT compiler can directly generate a single instruction (method dispatch instruction) when generating the instruction sequence corresponding to the virtual method call bytecode. This replaces the original, more complex instruction sequence that needed to be generated, including null pointer detection, address calculation, and memory access, effectively simplifying the JIT compilation logic, reducing the JIT compilation burden, and improving the execution efficiency of the compiled machine instruction code. Similarly, this also allows a small piece of inline assembly instruction to replace the hundreds of lines of C code originally involved in virtual method dispatch in the virtual method call bytecode branch of the interpreter's machine instruction template, simplifying the interpreter's compilation and interpretation burden, improving the interpreter's execution efficiency, and increasing the execution speed by approximately 2 times.
[0085] In an optional embodiment of this application, the virtual machine is further configured to drive the processor core 101 to execute a method dispatch instruction in response to a virtual method call operation of a target object, provided that the data processing system supports the method dispatch acceleration unit 102.
[0086] In some embodiments, the virtual machine may detect whether the data processing system supports the method dispatch acceleration unit 102 when it starts up.
[0087] In an optional scenario, the virtual machine triggers an illegal instruction exception when executing a non-existent illegal instruction. The virtual machine can utilize this mechanism to drive the processor core 101 to execute method dispatch instructions during its startup to detect whether the triggered illegal instruction exception will be caught. Based on the capture result, it can determine whether the data processing system supports the method dispatch acceleration unit 102. If the virtual machine catches an illegal instruction exception, it can determine that the data processor does not support the method dispatch acceleration unit 102; if it does not catch an illegal instruction exception, or if it catches the expected execution result of the method dispatch instruction, it can determine that the data processor supports the method dispatch acceleration unit 102.
[0088] Alternatively, a specific status register can be configured for the method dispatch instruction. The virtual machine reads this status register during its startup to check its existence, and then determines whether the data processing system supports the method dispatch acceleration unit 102 based on the detection result. If the virtual machine reads data from the status register, indicating its existence, it can determine that the data processor supports the method dispatch acceleration unit 102; if it does not read data from the status register, indicating its absence, it can determine that the data processor does not support the method dispatch acceleration unit 102.
[0089] In this optional embodiment, the virtual machine detects whether the data processing system supports the method dispatch acceleration unit 102 to effectively determine whether it supports the custom method dispatch instruction, thereby effectively avoiding the triggering of illegal instruction exceptions for the method dispatch instruction when the data processing system does not support the method dispatch acceleration unit 102, and reducing the code execution exception rate.
[0090] In this embodiment, the data processing system includes a processor core, a virtual machine running on the processor core, and a method dispatch acceleration unit coupled to the processor core. The virtual machine, in response to a virtual method call operation of a target object, drives the processor core to execute method dispatch instructions. The processor core, executing the method dispatch instructions, triggers the method dispatch acceleration unit to obtain a virtual method table pointer from the object header of the target object, determines the entry address of the target virtual method corresponding to the target object based on the virtual method table pointer and the method index of the target object, and executes the target virtual method based on the entry address, effectively realizing virtual method dispatch. This technical solution can compress multiple instructions into a single method dispatch instruction, utilizing the method dispatch acceleration unit to implement virtual method dispatch, thereby effectively shortening the execution cycle of virtual method dispatch, reducing device overhead, and increasing code density.
[0091] For ease of understanding, the technical solution of this application is further illustrated below with examples. For example, the data processing system includes: a processor core 101, a virtual machine running on the processor core 101, a method dispatch acceleration unit 102 coupled to the processor core 101, a memory subsystem 103, and a cache module 104. The data processing system is an operating system and supports the RISC-V instruction set architecture. The virtual machine is a JVM and includes a JIT and an interpreter. The cache module 104 is used to cache the correspondence between the entry address of a virtual method and the object method association identifier. The object method association identifier includes a pointer to the object's virtual method table and a method index.
[0092] The method dispatch acceleration unit 102 can be integrated into the processor core. Assume the opcode in the method dispatch instruction is 0b0001011 and the main function code funct3 is 0b100. For example... Figure 7 As shown, the process of virtual method dispatching implemented by the data processing system includes the following steps 701 to 713.
[0093] Step 701: In response to the virtual method call operation of the target object, the JVM drives the processor core 101 to execute the method dispatch instruction.
[0094] Step 702: The processor core reads and parses the instruction, identifying the opcode, main function code, source operand rs, destination operand rd, and immediate value imm in the instruction.
[0095] Step 703: When the processor core parses a method dispatch instruction with opcode 0b0001011 and main function code funct3 0b100, it triggers the method dispatch acceleration unit 102 to execute step 704.
[0096] Step 704: The method dispatch acceleration unit 102 reads the object address in the first source register identified by the source operand rs and sends it to the temporary signal obj.
[0097] Step 705: The method dispatch acceleration unit 102 performs a null pointer check on the temporary signal obj. If the check result indicates that the object address is null, step 706 is executed. If the check result indicates that the object address is not null, step 707 is executed.
[0098] Step 706: The method dispatch acceleration unit 102 triggers a null pointer exception, and the method dispatch instruction retires.
[0099] Step 707: The method dispatch acceleration unit 102 loads the virtual method table pointer from the object header based on the object address of the target object and the address offset of the virtual method table pointer.
[0100] Step 708: The method dispatch acceleration unit 102 searches the cache module 104 based on the method index and virtual method table pointer of the target object to determine whether the cache module 104 caches the method index and virtual method table pointer of the target object. This is to determine whether the cache module 104 caches the entry address of the target virtual method corresponding to the target object, thus facilitating the determination of whether the cache module 104 has hit the entry address of the target virtual method. If yes, proceed to step 709; otherwise, proceed to step 710.
[0101] Step 709: The method dispatch acceleration unit 102 reads the entry address corresponding to the method index and virtual method table pointer of the target object from the cache module 104 and executes step 713.
[0102] Step 710: The method dispatch acceleration unit 102 calculates the access address of the entry address of the target virtual method corresponding to the target object based on the virtual method table pointer and the method index of the target object. The access address target satisfies: target = vtbl + index × word_size.
[0103] Step 711: The method dispatch acceleration unit 102 loads the entry address from the memory access address.
[0104] Step 712: The method dispatch acceleration unit 102 caches the method index and virtual method table pointer of the target object, as well as the entry address of the corresponding target virtual method, into the cache module 104.
[0105] Step 713: The method dispatch acceleration unit 102 modifies the value of the program register PC to the entry address, so as to jump to the entry address to execute the target virtual method, and writes the entry address of the next instruction of the method dispatch instruction into the link register.
[0106] It should be noted that in some examples, at least one level cache is typically provided between the processor core 101 and memory. This cache can be replaced with an object header containing at least some objects. Based on this, in this embodiment, the process of the method dispatch acceleration unit 102 loading the virtual method table pointer from the object header may include: if the cache hits the object header of the target object, directly loading the virtual method table pointer from the cache; if the cache does not hit the object header, then loading the virtual method table pointer from memory. Since the access speed of memory is much slower than that of the cache, the loading speed of the virtual method table pointer can be significantly improved when the cache hits the object header of the target object, thereby further shortening the process of obtaining the entry address of the target virtual method, reducing the execution latency of the target virtual method, and shortening the execution cycle of virtual method dispatch. Furthermore, the technical solution of this application obviously mainly involves the JVM instruction generation adaptation direction, without modifying the Java application, and has the characteristic of being transparent to the upper layer.
[0107] It should be noted that, taking method dispatch instructions as an example, this serves as another illustrative illustration of the data processing system. For instance... Figure 8 As shown, assume that the Java source code includes the code obj.method() corresponding to the virtual method call bytecode invokevirtual.
[0108] In the data processing system, the JVM can detect whether the data processing system supports the method dispatch acceleration unit 102 during its startup to determine whether it supports method dispatch instructions. If the data processing system does not support the method dispatch acceleration unit 102, the JVM can invoke the JIT compiler to respond to the virtual method call bytecode invokevirtual, generating a general RISC-V instruction sequence so that the processor core 101 executes the general RISC-V instruction sequence. If the data processing system supports the method dispatch acceleration unit 102, the JVM can invoke the JIT compiler to respond to the virtual method call bytecode invokevirtual, generating method dispatch instructions so that the processor core 101 executes the method dispatch instructions, triggering the method dispatch acceleration unit 102 to perform the aforementioned steps.
[0109] The general RISC-V instruction sequence corresponding to the virtual method call bytecode invokevirtual includes: `beqz obj, .Lnull` # Null pointer check instruction; if the address of object `obj` is 0 (i.e., null), then jump to execute the code `.Lnull`. `ld tmp, 0(obj)` # Load instruction, where `obj` represents the object address, and `0` represents the address offset of the virtual method table pointer in the object header. The execution behavior of this load instruction is: load the virtual method table pointer corresponding to the object in memory into the `tmp` register. `ld target, index×8(temp)` # Load instruction, where 8 is the size of a single entry in the virtual method table. This load instruction loads the data at the target address in memory into the `target` register. The target address is the access address of the entry point of the virtual method corresponding to the object. jalr target # Indirect jump instruction, jumps to the entry address to execute the virtual method. j.Ldone # Unconditional jump instruction, jumps to execute code without conditions.Lnull .Lnull: call throw_NPE # Trigger a null pointer exception .Ldone: # Continue executing the next instruction The method dispatch instruction corresponding to the virtual method call bytecode `invokevirtual` is: `vcall obj_reg,method_index`. This method dispatch instruction, where `obj_reg` represents the device identifier in the first register and `method_index` represents the method index of the target object, implicitly performs null pointer checks, loads the virtual method table pointer, calculates access addresses, loads entry addresses, and performs entry address jumps.
[0110] In this example, multiple instructions can be compressed into a single method dispatch instruction to utilize the method dispatch acceleration unit to dispatch virtual methods to the target object, thereby effectively shortening the execution cycle of virtual method dispatch, reducing device overhead, and increasing code density. In particular, the entire processing flow can adopt a pipelined design, allowing the execution time of the virtual method table pointer loading memory access to overlap with the access address calculation, thus effectively shortening the process of obtaining the entry address of the target virtual method and further reducing the execution latency of the target virtual method. Furthermore, when the cache hits the object header of the target object, the process of obtaining the entry address of the target virtual method can be effectively shortened, reducing the execution latency of the target virtual method to approximately 10 clock cycles. Compared to the approximately 15 to 18 clock cycles required for virtual method dispatch via software execution in related technologies, the performance improvement of virtual method dispatch under this application's technical solution is approximately 40% to 50%, effectively shortening the execution cycle of virtual method dispatch. Furthermore, since the method dispatch acceleration unit 102 supports highly efficient polymorphic operation, the JVM can remove the rollback process when devirtualization fails, eliminate the virtualization path, and reduce redundant operations.
[0111] Using the technical solution of this application, when calling JIT, the same virtual method 10 is called repeatedly. 8 In the micro-benchmark test (SPECjvm2008 compiler.sunflow), the test time was 1.35 seconds when executing a general RISC-V instruction sequence; and 0.32 seconds when executing method dispatch instructions, representing a speedup of approximately 4.2 times and an overall device throughput improvement of 12%. This was achieved when the interpreter was invoked, and the same virtual method was called repeatedly 10 times. 8 The micro-benchmark testing speed is improved by approximately 2 times. The data processing system parameters include: support for the RISC-V Rocket Chip framework, a 64-bit RV64GC processor core, and a clock speed of 200MHz.
[0112] In this embodiment, the data processing system includes a processor core, a virtual machine running on the processor core, and a method dispatch acceleration unit coupled to the processor core. The virtual machine, in response to a virtual method call operation of a target object, drives the processor core to execute method dispatch instructions. The processor core, executing the method dispatch instructions, triggers the method dispatch acceleration unit to obtain a virtual method table pointer from the object header of the target object, determines the entry address of the target virtual method corresponding to the target object based on the virtual method table pointer and the method index of the target object, and executes the target virtual method based on the entry address, effectively realizing virtual method dispatch. This technical solution can compress multiple instructions into a single method dispatch instruction, utilizing the method dispatch acceleration unit to implement virtual method dispatch, thereby effectively shortening the execution cycle of virtual method dispatch, reducing device overhead, and increasing code density.
[0113] Please refer to Figure 9 This document illustrates a flowchart of a data processing method provided in an embodiment of this application. This data processing method can be applied to a data processing system, which includes a processor core, a virtual machine running on the processor core, and a method dispatch acceleration unit coupled to the processor core. Optionally, the data processing method can be applied to any of the data processing methods provided in the embodiments of this application. Figure 9 As shown, the data processing methods include: Step 901: In response to the virtual method call operation of the target object, the virtual machine drives the processor core to execute the method dispatch instruction.
[0114] Step 902: The processor core executes the method dispatch instruction, triggering the method dispatch acceleration unit to obtain the virtual method table pointer from the object header of the target object. Based on the virtual method table pointer and the method index of the target object, the entry address of the target virtual method corresponding to the target object is determined, and the target virtual method is executed based on the entry address. The method index is the index of the target virtual method in the virtual method table.
[0115] In this embodiment, the data processing system includes a processor core, a virtual machine running on the processor core, and a method dispatch acceleration unit coupled to the processor core. The virtual machine, in response to a virtual method call operation of a target object, drives the processor core to execute method dispatch instructions. The processor core, executing the method dispatch instructions, triggers the method dispatch acceleration unit to obtain a virtual method table pointer from the object header of the target object, determines the entry address of the target virtual method corresponding to the target object based on the virtual method table pointer and the method index of the target object, and executes the target virtual method based on the entry address, effectively realizing virtual method dispatch. This technical solution can compress multiple instructions into a single method dispatch instruction, utilizing the method dispatch acceleration unit to implement virtual method dispatch, thereby effectively shortening the execution cycle of virtual method dispatch, reducing device overhead, and increasing code density.
[0116] In some embodiments, the data processing system further includes: a caching module, which is used to cache the entry addresses of virtual methods corresponding to at least some objects; step 1102, the method dispatch acceleration unit obtains a virtual method table pointer from the object header of the target object, determines the entry address of the target virtual method corresponding to the target object based on the virtual method table pointer and the method index of the target object, and executes the target virtual method based on the entry address. The process of the method index being the index of the target virtual method in the virtual method table may include: If the entry address of the target virtual method corresponding to the target object exists in the cache module, the method dispatch acceleration unit executes the target virtual method based on the entry address in the cache module; if the entry address of the target virtual method corresponding to the target object does not exist in the cache module, the virtual method table pointer is obtained from the object header of the target object, the entry address of the target virtual method is determined based on the virtual method table pointer and the method index of the target object, and the target virtual method is executed based on the entry address.
[0117] In some embodiments, the caching module is used to cache the correspondence between the entry address of a virtual method and the object method association identifier. The object method association identifier includes the object address and the method index, or the object method association identifier includes the object class pointer and the method index, or the object method association identifier includes the object's virtual method table pointer and the method index. If the entry address of the target virtual method corresponding to the target object exists in the cache module, the method dispatch acceleration unit executes the target virtual method based on the entry address in the cache module; if the entry address of the target virtual method corresponding to the target object does not exist in the cache module, the process of obtaining the virtual method table pointer from the object header of the target object, determining the entry address of the target virtual method based on the virtual method table pointer and the method index of the target object, and executing the target virtual method based on the entry address may include: If the method dispatch acceleration unit has an entry address corresponding to the object method association identifier of the target object in the cache module, it executes the target virtual method based on the entry address corresponding to the object method association identifier of the target object in the cache module; if the entry address corresponding to the object method association identifier of the target object does not exist in the cache module, it obtains the virtual method table pointer from the object header of the target object, determines the entry address of the target virtual method based on the virtual method table pointer and the method index of the target object, and executes the target virtual method based on the entry address.
[0118] In some embodiments, the data processing method further includes: when the method dispatch acceleration unit does not have an entry address corresponding to the object method association identifier of the target object in the cache module, it caches the object method association identifier of the target object and the corresponding entry address in the cache module.
[0119] In some embodiments, the method dispatch instruction includes address information and a method index of the target object, where the address information indicates the object address of the target object; step 1102, the method dispatch acceleration unit obtains a virtual method table pointer from the object header of the target object, determines the entry address of the target virtual method corresponding to the target object based on the virtual method table pointer and the method index of the target object, and executes the target virtual method based on the entry address. The process of the method index being the index of the target virtual method in the virtual method table may include: The method dispatch acceleration unit performs a null pointer check on the object address. If the check result indicates that the object address is not null, it obtains the virtual method table pointer from the object header of the target object based on the object address of the target object. Based on the virtual method table pointer and the method index of the target object, it determines the entry address of the target virtual method and executes the target virtual method based on the entry address.
[0120] In some embodiments, the address information includes the device identifier of the first source register, which is used to store the object address of the target object; the process of the method dispatch acceleration unit performing a null pointer check on the object address may include: the method dispatch acceleration unit reading the object address from the first source register and performing a null pointer check on the object address.
[0121] In some embodiments, the method dispatch instruction further includes a target operation identifier; step 1102: the processor core executes the method dispatch instruction, triggering the method dispatch acceleration unit to obtain a virtual method table pointer from the object header of the target object, determine the entry address of the target virtual method corresponding to the target object based on the virtual method table pointer and the method index of the target object, and execute the target virtual method based on the entry address. The process of the method index being the index of the target virtual method in the virtual method table may include: The processor core parses the instructions executed by the virtual machine driver. When it parses a method dispatch instruction that includes the target operation identifier, it triggers the method dispatch acceleration unit to obtain the virtual method table pointer from the object header of the target object. Based on the virtual method table pointer and the method index of the target object, it determines the entry address of the target virtual method and executes the target virtual method based on the entry address.
[0122] In some embodiments, the method dispatch instruction is in the format of a RISC-V custom encoding format. The method dispatch instruction includes an opcode, a target operand, a main function code, a source operand, and an immediate value. The values of the opcode and the main function code in the method dispatch instruction form the target operation identifier. The value of the target operand is placeholder data. The source operand is the device identifier of the first source register. The value of the immediate value is the method index of the target object.
[0123] In some embodiments, the data processing method further includes: the method dispatch acceleration unit triggers null pointer exception handling when the check result indicates that the object address is null.
[0124] In some embodiments, a virtual machine includes at least one of the following: a just-in-time compiler, an interpreter, A just-in-time (JIT) compiler is used to generate method dispatch instructions based on a system architecture description file and in response to the compilation operation of virtual method call bytecode of a target object. The system architecture description file is used to indicate the matching rules between instructions and bytecode. The interpreter is used to interpret and execute the virtual method call bytecode of the target object, driving the processor core to jump and execute the method dispatch instructions inlined in the machine instruction template. The machine instruction template is used to indicate the instruction sequence corresponding to the bytecode. The virtual method call bytecode describes the virtual method call operation of the target object. Step 1101, the process of the virtual machine responding to the virtual method call operation of the target object and driving the processor core to execute the method dispatch instruction, may include: the virtual machine responding to the virtual method call operation of the target object and driving the processor core to jump to execute the method dispatch instruction generated by the just-in-time compiler, or, by executing the interpretation and execution operation of the virtual method call bytecode of the target object through the interpreter, so as to drive the processor core to jump to execute the method dispatch instruction inlined in the machine instruction template.
[0125] In some embodiments, step 1101, in response to a virtual method call operation of a target object, driving the processor core to execute a method dispatch instruction, may include: when the virtual machine determines that the data processing system supports a method dispatch acceleration unit, driving the processor core to execute a method dispatch instruction in response to a virtual method call operation of the target object.
[0126] In this embodiment, the data processing system includes a processor core, a virtual machine running on the processor core, and a method dispatch acceleration unit coupled to the processor core. The virtual machine, in response to a virtual method call operation of a target object, drives the processor core to execute method dispatch instructions. The processor core, executing the method dispatch instructions, triggers the method dispatch acceleration unit to obtain a virtual method table pointer from the object header of the target object, determines the entry address of the target virtual method corresponding to the target object based on the virtual method table pointer and the method index of the target object, and executes the target virtual method based on the entry address, effectively realizing virtual method dispatch. This technical solution can compress multiple instructions into a single method dispatch instruction, utilizing the method dispatch acceleration unit to implement virtual method dispatch, thereby effectively shortening the execution cycle of virtual method dispatch, reducing device overhead, and increasing code density.
[0127] This application also provides a Java-oriented RISC-V data processing system, which includes a RISC-V architecture processor core, a JVM running on the processor core, and a method dispatch acceleration unit hardware coupled to the processor core; the data processing system supports a custom RISC-V extended instruction set, including the method dispatch instruction vcall.
[0128] The JVM is equipped with a just-in-time (JIT) compiler and interpreter to compile / interpret the Java virtual method call bytecode (invokevirtual) and generate method dispatch instructions. The method dispatch acceleration unit has a built-in hardware verification module that performs the following in one step during method dispatch instruction execution: implicit null pointer verification of the object and validity verification of the virtual method index. Verification exceptions directly trigger the corresponding JVM exception. The data processing system can optionally be configured with a vtable cache module to cache the entry address of virtual methods and the object method association identifier. After successful verification, the method dispatch acceleration unit reads the vtable pointer from the object header, calculates the virtual method entry address, and jumps to execute the method. A cache hit eliminates two memory loads.
[0129] In some embodiments, the RISC-V data processing system for Java bytecode includes any of the data processing systems provided in the embodiments of this application.
[0130] This application also provides a processor that includes any of the data processing systems provided in this application.
[0131] This application also provides a chip that includes any of the data processing systems provided in this application.
[0132] This application also provides an electronic device, which includes any of the data processing systems, chips, or processors provided in this application.
[0133] This application also provides a computer-readable storage medium storing a computer program or computer-executable instructions for implementing the data processing method provided in this application when executed by a processor.
[0134] This application also provides a computer program product, including a computer program or computer executable instructions, which, when executed by a processor, implements the data processing method provided in this application.
[0135] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, and improvements made within the spirit and scope of this application are included within the scope of protection of this application.
Claims
1. A data processing system, characterized in that, The data processing system includes: a processor core, a virtual machine running on the processor core, and a method dispatch acceleration unit coupled to the processor core; The virtual machine is used to drive the processor core to execute method dispatch instructions in response to the virtual method call operation of the target object; The processor core is used to execute the method dispatch instruction, trigger the method dispatch acceleration unit to obtain the virtual method table pointer from the object header of the target object, determine the entry address of the target virtual method corresponding to the target object based on the virtual method table pointer and the method index of the target object, and execute the target virtual method based on the entry address, wherein the method index is the index of the target virtual method in the virtual method table.
2. The data processing system according to claim 1, characterized in that, The data processing system further includes a caching module, which is used to cache the entry addresses of virtual methods corresponding to at least some objects; The method dispatch acceleration unit is further configured to, when the entry address of the target virtual method corresponding to the target object exists in the cache module, execute the target virtual method based on the entry address in the cache module; when the entry address of the target virtual method corresponding to the target object does not exist in the cache module, obtain a virtual method table pointer from the object header of the target object, determine the entry address of the target virtual method based on the virtual method table pointer and the method index of the target object, and execute the target virtual method based on the entry address.
3. The data processing system according to claim 2, characterized in that, The caching module is used to cache the correspondence between the entry address of a virtual method and the object method association identifier. The object method association identifier includes the object address and the method index, or the object method association identifier includes the object class pointer and the method index, or the object method association identifier includes the object's virtual method table pointer and the method index. The method dispatch acceleration unit is further configured to, when an entry address corresponding to the object method association identifier of the target object exists in the cache module, execute the target virtual method based on the entry address corresponding to the object method association identifier of the target object in the cache module; when an entry address corresponding to the object method association identifier of the target object does not exist in the cache module, obtain a virtual method table pointer from the object header of the target object, determine the entry address of the target virtual method based on the virtual method table pointer and the method index of the target object, and execute the target virtual method based on the entry address.
4. The data processing system according to claim 3, characterized in that, The method dispatch acceleration unit is further configured to cache the object method association identifier and the corresponding entry address of the target object in the cache module when there is no entry address corresponding to the object method association identifier of the target object in the cache module.
5. The data processing system according to claim 1, characterized in that, The method dispatch instruction includes address information and the method index of the target object, wherein the address information indicates the object address of the target object; The method dispatch acceleration unit is further configured to perform a null pointer check on the object address, and if the check result indicates that the object address is not null, obtain a virtual method table pointer from the object header of the target object based on the object address of the target object, determine the entry address of the target virtual method based on the virtual method table pointer and the method index of the target object, and execute the target virtual method based on the entry address.
6. The data processing system according to claim 5, characterized in that, The address information includes the device identifier of the first source register, which is used to store the object address of the target object; The method dispatch acceleration unit is also used to read the object address from the first source register and perform a null pointer check on the object address.
7. The data processing system according to claim 1, characterized in that, The method for assigning instructions also includes a target operation identifier; The processor core is also configured to parse the instructions executed by the virtual machine driver. When the method dispatch instruction including the target operation identifier is parsed, the method dispatch acceleration unit is triggered to obtain the virtual method table pointer from the object header of the target object, determine the entry address of the target virtual method based on the virtual method table pointer and the method index of the target object, and execute the target virtual method based on the entry address.
8. The data processing system according to claim 7, characterized in that, The method dispatch instruction is in RISC-V custom encoding format. The method dispatch instruction includes an opcode, a target operand, a main function code, a source operand, and an immediate value. The values of the opcode and the main function code in the method dispatch instruction form the target operation identifier. The value of the target operand is placeholder data. The source operand is the device identifier of the first source register. The value of the immediate value is the method index of the target object.
9. The data processing system according to claim 5, characterized in that, The method dispatch acceleration unit is also used to trigger null pointer exception handling when the check result indicates that the address of the object is null.
10. The data processing system according to claim 1, characterized in that, The virtual machine includes at least one of the following: a just-in-time compiler, an interpreter, The just-in-time compiler is used to generate the method dispatch instructions based on the system architecture description file in response to the compilation operation of the virtual method call bytecode of the target object. The system architecture description file is used to indicate the matching rules between the instructions and the bytecode. The interpreter is used to drive the processor core to jump and execute the method dispatch instruction inlined in the machine instruction template in response to the interpretation and execution operation of the virtual method call bytecode of the target object. The machine instruction template is used to indicate the instruction sequence corresponding to the bytecode. The virtual method call bytecode describes the virtual method call operation of the target object. The virtual machine is also used to respond to a virtual method call operation of a target object by driving the processor core to jump to execute the method dispatch instruction generated by the just-in-time compiler, or by executing the interpretation and execution operation of the virtual method call bytecode of the target object through the interpreter, so as to drive the processor core to jump to execute the method dispatch instruction inline assembled in the machine instruction template.
11. The data processing system according to claim 1, characterized in that, The virtual machine is also used to drive the processor core to execute method dispatch instructions in response to the virtual method call operation of the target object, provided that the data processing system supports the method dispatch acceleration unit.
12. A data processing method, characterized in that, The method is applied to a data processing system, which includes a processor core, a virtual machine running on the processor core, and a method dispatch acceleration unit coupled to the processor core; the method includes: The virtual machine responds to the virtual method call operation of the target object and drives the processor core to execute the method dispatch instruction; The processor core executes the method dispatch instruction, triggering the method dispatch acceleration unit to obtain the virtual method table pointer from the object header of the target object, determine the entry address of the target virtual method based on the virtual method table pointer and the method index of the target object, and execute the target virtual method based on the entry address. The method index is the index of the target virtual method in the virtual method table.
13. An electronic device, characterized in that, The electronic device includes: the data processing system according to any one of claims 1 to 11.
