A code migration method based on bytecode dynamic transcoding technology

Through the code migration method based on bytecode dynamic transcoding technology, the process migration problem of Java programs between different nodes is solved, the complete migration of Java source code and status information is realized, and the smooth operation of Java programs on different platforms is ensured. and state recovery.

CN118259963BActive Publication Date: 2024-12-31HUAIAN OF JIANGSU ELECTRIC POWER CO POWER SUPPLY +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410365091.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-28
Publication Date
2024-12-31
Estimated Expiration
2044-03-28

AI Technical Summary

Technical Problem

Traditional process migration technology is difficult to effectively capture and restore the status information of Java programs, especially when cross-platform migration, and it is impossible to achieve platform-independent and complete process state migration.

Method used

Using the code migration method based on bytecode dynamic transcoding technology, by building Java virtual machines and Java migration units, segmenting, encapsulating, migrating and restoring Java source code, realizing the state packet encapsulation and migration of Java programs, ensuring that the processes are different Complete migration between nodes.

Benefits of technology

It realizes the complete migration of Java source code, data and process status information, ensures the smooth migration and recovery of Java programs between different nodes, and solves the problems of platform irrelevance and state recovery.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118259963B_ABST
    Figure CN118259963B_ABST
Patent Text Reader

Abstract

The present invention relates to the technical field of Java source code migration, and discloses a code migration method based on bytecode dynamic transcoding technology, including: constructing a code migration system, the system including a Java virtual machine and a Java migration unit, the Java migration unit including: a Java segmentation and encapsulation module, a Java migration module and a Java recovery module, any module in the Java migration unit has data interaction with other modules; and using a strong migration scheme, after the Java virtual machine determines the execution state of the Java program, the Java migration unit completely migrates the Java source code, data and process state information from the source node to the target node through a series of execution steps such as encapsulation, migration and recovery. The present invention enables the Java program to realize process migration between different nodes on the basis of Java source code integrity migration.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of Java source code migration, in particular to a code migration method based on bytecode dynamic transcoding technology. Background Art

[0002] With the development of modern computer technology, the performance of computer systems has been continuously improved, while the price has been continuously reduced, making the advantages of cluster-based distributed systems in terms of scalability and cost-effectiveness more and more obvious; at the same time, the demand for high-performance computing in various fields has made the application of cluster systems more and more extensive. In order to more effectively utilize the computing resources in the cluster, maintain the load balance of the cluster, and ensure the correct execution of computing tasks, process migration technology is needed.

[0003] In a multi-machine environment based on personal workstations, each computing node is not dedicated and is not necessarily a homogeneous system. When a workstation user needs to reclaim private computing resources or the cluster load is unbalanced, the computing task needs to be migrated to a new node for continued execution, while retaining the completed workload and making the migration platform-independent as much as possible.

[0004] Process migration not only migrates the original code, but also migrates the state information of the process at the break point. How to capture and restore the state data of the process is the core content of the study of process migration technology. Traditional process migration systems generally rely on special hardware and software environments. According to the characteristics of the Java architecture, a method based on JPDA and modified bytecode is used to implement process migration. The capture of process status is achieved through JPDA; the recovery of process status is the difficulty of code migration. When restoring the process, the program must jump to the breakpoint to continue execution, but some variable declaration statements cannot be skipped. Through JPDA, only the process data can be viewed and modified, and objects cannot be declared, nor can the program's running process be changed. The present invention uses a code migration method based on bytecode dynamic transcoding technology, which changes the program running process and solves these problems.

[0005] Patent No. CN117075960A discloses a method for cross-platform code migration, which reconstructs the dependent library of the application to be migrated through a program reconstruction method to obtain a target library suitable for running in the target operating system, and converts the application to be migrated into a target application suitable for running in the target operating system through a compatibility layer; CN116382776A discloses a cross-platform API migration method, which logically splits the API data structure of the old platform to obtain the data units that constitute the API data structure, and establishes a mapping relationship between each data unit and the target configuration position of the new platform according to the field information contained in each data unit; However, none of them provides a solution for the process migration of Java programs. Summary of the invention

[0006] The present invention first constructs a code migration system, and then constructs a code migration method based on the code migration system. The specific technical scheme is as follows:

[0007] A code migration method based on bytecode dynamic transcoding technology comprises the following steps:

[0008] Step 1: construct a code migration system, including: a Java virtual machine and a Java migration unit, and there is data interaction between the Java virtual machine and the Java migration unit;

[0009] The Java migration unit includes: Java segmentation and packaging module, Java migration module and Java recovery module. Any module in the Java migration unit has data interaction with other modules.

[0010] Step 2: When the Java source code is migrated from the source node to the target node, the Java segmentation and packaging module actively establishes a connection with the source node, scans the Java source code on the source node, and segments the Java source code into meta-code blocks through the Maven tool running on the source node, and transmits the meta-code blocks to the Java virtual machine;

[0011] Step 3: The Java virtual machine loads and determines the execution status of the Java program, and returns the determination result to the Java segmentation and encapsulation module, which performs the encapsulation operation to obtain the status data packet to which the meta-code block belongs;

[0012] Step 4: The Java segmentation and packaging module transmits the state data packet of the meta-code block to the Java migration module, and the Java migration module migrates the state data packet of the meta-code block to the Java recovery module, and the Java recovery module performs a recovery operation on the Java source code;

[0013] Step 5: The target node performs a process recovery operation on the migrated Java source code.

[0014] Preferably, the Java segmentation and packaging module is used to segment and package the Java source code on the source node, the Java migration module is used to migrate the Java source code from the source node to the target node, and the Java recovery module is used to restore the Java source code on the target node.

[0015] Preferably, the code migration system uses a strong migration method to migrate all Java source code, data and process status information from a source node to a target node, and the source node and the target node use the same operating system.

[0016] Preferably, the operating system used by the source node and the target node is one of the Windows operating system, HarmonyOS operating system, macOS operating system, and Linux operating system.

[0017] The present invention has the following beneficial effects:

[0018] The present invention uses a strong migration solution. After the Java virtual machine determines the execution status of the Java program, the Java migration unit completely migrates the Java source code, data and process status information from the source node to the target node through a series of execution steps such as encapsulation, migration and recovery.

[0019] The present invention enables Java programs to realize process migration between different nodes based on the Java source code integrity migration. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] Figure 1 This is a schematic diagram of the code migration system architecture;

[0021] Figure 2 This is a flow chart for determining the execution status of a Java program. DETAILED DESCRIPTION

[0022] A code migration method based on bytecode dynamic transcoding technology comprises the following steps:

[0023] Step 1: Build a code migration system, such as Figure 1 As shown, the system includes: a Java virtual machine and a Java migration unit, and there is data interaction between the Java virtual machine and the Java migration unit;

[0024] The Java virtual machine is used to load and process Java programs;

[0025] The Java migration unit is used to encapsulate, migrate and restore Java source code, which specifically includes: Java segmentation and encapsulation module, Java migration module and Java recovery module. Any module in the Java migration unit has data interaction with other modules;

[0026] The Java segmentation and packaging module is used to segment and package Java source code on the source node;

[0027] The Java migration module is used to migrate Java source code from the source node to the target node;

[0028] The Java recovery module is used to recover Java source code on the target node;

[0029] The code migration system uses a strong migration method to migrate all Java source code, data and process status information from node I (node ​​I is used as the source node) to node II (node ​​II is used as the target node). Node I and node II use the same operating system, which is one of the Windows operating system, HarmonyOS operating system, macOS operating system and Linux operating system.

[0030] Step 2: When the code migration system receives an instruction to migrate all Java source code, data, and process status information from node I to node II, the code migration system performs the following operations:

[0031] Step S1, the Java segmentation and packaging module actively establishes a connection with node I, performs a scanning operation on the Java source code on node I, and divides the Java source code into meta-code blocks C and C through the Maven tool running on node I. i , and the meta code block C i Transfer to the Java virtual machine;

[0032] Step S2: The Java virtual machine loads and obtains the execution status of the Java program, and defines a status identifier Is to represent the execution status of the Java program. The specific provisions of the status identifier Is are as follows:

[0033]

[0034] If the Java program runs to the meta code block C i (i is the serial number of the meta-code block C, i=1, 2, ..., n), the Java virtual machine suspends the meta-code block C i The execution process of the metacode block C i The previous meta code block C 1 , C 2 ,…,C i-1 The running status of the is marked as completed, and the status flag is updated. 1 =11,Is 2 =11,…,Is i-1 =11, save the meta code block C 1 , C 2 ,…,C i-1 The values ​​of local variables and objects in the C i The execution process updates the current meta code block C i Status information, such as Figure 2 As shown, the specific judgment process is:

[0035] (1) If the meta-code block C i If it is not executed, the Java virtual machine directly marks the meta code block Ci The execution status is "Executing", and the status flag is updated. i =01;

[0036] Java virtual machine record meta code block C i The bytecode file F i , and according to the meta code block C i The execution process updates the bytecode file F i ;

[0037] (2) If the meta-code block C i If the code block is being executed but has not yet been completed, the Java virtual machine marks the meta code block C i The execution status is "Executing", and the status flag is updated. i =01;

[0038] The Java virtual machine discards the metacode block C i The executed process further records the meta code block C i The bytecode file F i , and according to the meta code block C i The execution process updates the bytecode file F i ;

[0039] (3) If the meta-code block C i The execution is completed, then the Java virtual machine marks the meta code block C i The next block of code C i+1 The execution status is "Executing", and the status flag is updated. i =11, Is i+1 =01; At this point, the Java virtual machine saves the meta code block C i Get the values ​​of local variables and objects in the meta code block C i+1 The image of all local variables and objects in the metacode block C is converted into serializable data, and the metacode block C is further recorded. i+1 The bytecode file F i+1 , and according to the meta code block C i+1 The execution process updates the bytecode file F i+1 ;

[0040] Step S3, after the execution status of the Java program is determined, the Java segmentation and encapsulation module is executed to perform the encapsulation operation. The specific process is as follows:

[0041] (1) Define the migration number α of source code S 1 ∈Z q * , status data packet Sp i The migration property parameter β 1i ∈Zq * , status data packet Sp i Name Number i ∈{0, 1} * , where the prime number q is an additive group G 1 The order of, {0, 1} * Represents a binary string of arbitrary length;

[0042] (2) Calculate the encapsulation mark α of the source code S 2 =α 1 ×P, status data packet Sp i Package attribute information β 2i =β 1i ×P, where P is the additive group G 1 The generator of

[0043] (3) Calculate the migration mark Ip of source code S = H 1 (P, α 2 ), status data packet Sp i Packaging information i =α 1 ×H 1 (ζ i , β 2i ), where the hash function H 1 is: {0, 1} * →G 1 ; and define a bilinear map e: G 1 ×G 1 →G 2 , G 2 is a multiplicative group of order q;

[0044] (4) Calculate the status data packet Sp i The first package factor λ 1i =H 2 (ζ i , β 2i , α 2 ), the second packaging factor λ 2i =H 2 (ζ i , β 2i , Ip), where the hash function H 2 is: {0, 1} * →Z q * ;

[0045] (5) Generate status data packet Sp accordingly i If the package number i =λ 1i ×I i +λ2i ×β 1i ×Ip;

[0046] (6) Output status data packet Sp i = {source code S migration mark Ip, source code S packaging mark α 2 , status data packet Sp i Package attribute information β 2i , the first packaging factor λ 1i , the second packaging factor λ 2i , package numberIf i , status indicator Is i , meta code block C i};

[0047] After that, the Java segmentation and encapsulation module converts the meta code block C i Status packet Sp i Transfer to Java migration module;

[0048] Step S4, the Java migration module performs a migration on the meta code block C i Status packet Sp i Implement migration operations, meta code block C i Status packet Sp i Migrated to the Java recovery module, the Java recovery module performs recovery operations on the Java source code. The specific process is as follows:

[0049] (1) From the randomly selected state data packet Sp i Extract the migration mark Ip of the source code S and the packaging mark α of the source code S 2 , package numberIf i , package attribute information β 2i , the first packaging coefficient λ 1i , the second packaging coefficient λ 2i 、Name Numberζ i ;

[0050] (2) Calculate the meta-code block C in the source code i The first auxiliary recovery parameter V Ⅰ =e(If i , P),

[0051] (3) Calculate the meta-code block C in the source code i The second auxiliary recovery parameter V Ⅱ =e(λ 1i , H 1 (ζ i , β 2i ), α 2 )(λ 2i ×β 2i, IP);

[0052] (4) If the equation V Ⅰ =V Ⅱ If true, it means that the Java source code has been completely migrated;

[0053] Step S5, node II scans each meta-code block C i When the state flag Is is found to exist in the execution state of the meta-code block, that is, the state flag Is=01, node II modifies the bytecode file, adds a program jump instruction, skips the running meta-code block, and directly jumps to the bytecode corresponding to the meta-code block in the execution state;

[0054] Node II loads the modified bytecode file, parses the bytecode file, and performs compatibility detection and compilation optimization on the Java source code. It then loads the values ​​of local variables and objects of each executed meta-code block, restores and runs the Java program, and completes the migration process of the Java source code.

Claims

1. A code migration method based on bytecode dynamic transcoding technology, characterized in that: The following steps are involved: Step 1: construct a code migration system, including: a Java virtual machine and a Java migration unit, and there is data interaction between the Java virtual machine and the Java migration unit; The Java migration unit includes: Java segmentation and packaging module, Java migration module and Java recovery module. Any module in the Java migration unit has data interaction with other modules. Step 2: When the Java source code is migrated from the source node to the target node, the Java segmentation and packaging module actively establishes a connection with the source node, scans the Java source code on the source node, and segments the Java source code into meta-code blocks through the Maven tool running on the source node, and transmits the meta-code blocks to the Java virtual machine; Step 3: The Java virtual machine loads and determines the execution status of the Java program, and returns the determination result to the Java segmentation and encapsulation module, which performs the encapsulation operation to obtain the status data packet to which the meta-code block belongs; The Java segmentation and encapsulation module performs encapsulation operations as follows: Define the migration number α1∈Z of source code S q * , status data packet Sp i The migration property parameter β 1i ∈Z q * , status data packet Sp i Name Number i ∈{0, 1} * , where the prime number q is the order of the additive group G1, {0, 1} * Represents a binary string of arbitrary length; Calculate the encapsulation mark α2=α1×P of the source code S, the state data packet Sp i Package attribute information β 2i =β 1i ×P, where P is the generator of the additive group G1; Calculate the migration mark Ip=H1(P, α2) of the source code S, the state data packet Sp i Packaging information i =α1×H1(ζ i , β 2i ), where the hash function H1 is: {0, 1} * →G1; and define a bilinear map e: G1×G1→G2, where G2 is a multiplicative group of order q; Calculate the status packet Sp i The first package factor λ 1i =H2(ζ i , β 2i , α2), the second packaging coefficient λ 2i =H2(ζ i , β 2i , Ip), where the hash function H2 is: {0, 1} * →Z q * ; Generate a status data packet Sp based on this i If the package number i =λ 1i ×I i +λ 2i ×β 1i ×Ip; Output status data packet Sp i ={source code S migration tag Ip, source code S encapsulation tag α2, status data packet Sp i Package attribute information β 2i , the first packaging factor λ 1i , the second packaging factor λ 2i , package numberIf i , status indicator Is i , meta code block C i }; Step 4: The Java segmentation and packaging module transmits the state data packet of the meta-code block to the Java migration module, and the Java migration module migrates the state data packet of the meta-code block to the Java recovery module, and the Java recovery module performs a recovery operation on the Java source code; The method by which the Java recovery module performs recovery operations on Java source code is as follows: From a randomly selected state packet Sp i Extract the migration mark Ip of the source code S, the packaging mark α2 of the source code S, and the packaging number If i , package attribute information β 2i , the first packaging coefficient λ 1i , the second packaging coefficient λ 2i 、Name Numberζ i ; Calculate the meta-code block C in the source code i The first auxiliary recovery parameter V Ⅰ =e(If i , P), Calculate the meta-code block C in the source code i The second auxiliary recovery parameter V Ⅱ =e(λ 1i , H1(ζ i , β 2i ),α2)(λ 2i ×β 2i , IP); If the equation V Ⅰ =V Ⅱ If true, it means that the Java source code has been completely migrated; The target node scans each meta code block C i When a meta-code block in execution state is found, the bytecode file is modified to add a program jump instruction, skip the running meta-code block, and directly jump to the bytecode corresponding to the meta-code block in execution state; The target node loads the modified bytecode file, parses the bytecode file, performs compatibility detection and compilation optimization on the Java source code, then loads the values ​​of local variables and objects of each executed meta-code block, restores and runs the Java program, and thus completes the migration process of the Java source code; Step 5: The target node performs a process recovery operation on the migrated Java source code.

2. The code migration method based on bytecode dynamic transcoding technology according to claim 1, characterized in that: The Java segmentation and packaging module is used to segment and package the Java source code on the source node, the Java migration module is used to migrate the Java source code from the source node to the target node, and the Java recovery module is used to restore the Java source code on the target node.

3. The code migration method based on bytecode dynamic transcoding technology according to claim 1, characterized in that: The code migration system uses a strong migration method to migrate all Java source code, data and process status information from a source node to a target node, and the source node and the target node use the same operating system.

4. The code migration method based on bytecode dynamic transcoding technology according to claim 3 is characterized in that: The operating system used by the source node and the target node is one of the Windows operating system, HarmonyOS operating system, macOS operating system, and Linux operating system.