[go: up one dir, main page]

WO2012062081A1 - Method for online updating java classes based on reconstruction of byte-code files - Google Patents

Method for online updating java classes based on reconstruction of byte-code files Download PDF

Info

Publication number
WO2012062081A1
WO2012062081A1 PCT/CN2011/072410 CN2011072410W WO2012062081A1 WO 2012062081 A1 WO2012062081 A1 WO 2012062081A1 CN 2011072410 W CN2011072410 W CN 2011072410W WO 2012062081 A1 WO2012062081 A1 WO 2012062081A1
Authority
WO
WIPO (PCT)
Prior art keywords
class
offset
old
new
update
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Ceased
Application number
PCT/CN2011/072410
Other languages
French (fr)
Chinese (zh)
Inventor
曹春
马晓星
吕建
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Nanjing University
Nanjing Tech University
Original Assignee
Nanjing University
Nanjing Tech University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Nanjing University, Nanjing Tech University filed Critical Nanjing University
Publication of WO2012062081A1 publication Critical patent/WO2012062081A1/en
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45504Abstract machines for programme code execution, e.g. Java virtual machine [JVM], interpreters, emulators

Definitions

  • the invention belongs to the field of computer applications, and is specifically an efficient Java class online updating method based on bytecode file reconstruction. Background technique
  • Software is the product of human brain work. There is no perfect software in the world, and it is difficult for developers to complete a software system that does not require improvement. Software always requires constant maintenance by developers, such as bug fixes, efficiency improvements, feature enhancements, and code refactoring.
  • JVM Java Virtual Machine
  • the Java language is mainly composed of classes, and the classes are mainly composed of domain and method definitions.
  • the JVM will map the read bytecode file to the corresponding runtime metadata. This is the first layer of processing of the binary at runtime.
  • the JVM calls his online compiler to compile the bytecode into the corresponding machine code, and the CPU reads these machine instructions to perform the corresponding functions.
  • the JVM creates an object in the memory allocated heap area.
  • the type information corresponding to the object is related to the class metadata. The information mainly describes the domain corresponding to each offset of the object space, and the instance method that the object can run.
  • the dynamic update system defines a basic semantic for maintaining consistency of updates: new code is not run before the update, and the old code is not run after the update. In addition to this, basic type safety is also guaranteed during the update process.
  • Dynamic update systems generally require an update preparation step, mainly by analyzing changes made to the new and old versions of the program and outputting the information to a file, and the programmer may need to write some update patches.
  • the Java classes that need to be processed are mainly divided into the following three types in the analysis phase:
  • class update When the class's parent class, interface collection, domain collection, and method collection change, the class needs to be reloaded into the virtual machine using the JVM's dynamic loading mechanism, and the class definition and domain definition and method definition are mapped to corresponding operations. Time metadata. An update to this type of definition change is called a class update.
  • the class update causes the runtime class metadata to be regenerated, and at the same time the method bytecode changes, and the method machine code changes. Due to the uniqueness of the type, replacing the new class requires removing the old class definition from the runtime type management mechanism. Specifically:
  • the method body update causes the bytecode of the method to change, and at the same time the bytecode of the method changes. Specifically:
  • the update requires the program to run to a secure point, and the security point needs to be able to stop all user threads and scan the user thread, determining that there are no restricted methods in the thread's run stack.
  • the method of changing the machine code is a restricted method.
  • the user can also specify the restricted method according to the program logic. When a method is removed, these methods are also marked as restricted methods to ensure the semantics of the update.
  • the machine code that references the method update needs to be fixed.
  • the general practice is to recompile.
  • the machine code of the method needs to be recompiled. If you can ensure that this offset update does not change before and after, the recompilation caused by the reference method update can be eliminated, improving the efficiency of the update.
  • This paper proposes a method to combine and analyze and reconstruct the bytecode binary file to adjust the dynamic loading class mechanism at runtime to reduce the recompilation caused by the update of the reference method. Summary of the invention
  • the technical problem to be solved by the present invention is to provide a Java class online update method based on bytecode file reconstruction, which reduces the change of runtime metadata by reducing the dynamic loading class mechanism at runtime, and reduces the reference method.
  • the recompilation brought by the update improves the efficiency of the update.
  • the invention relates to a Java class online updating method based on bytecode file reconstruction, which mainly comprises the following steps:
  • step 1) above is:
  • the JVM-based update analysis tool traverses all classes twice,
  • the bytecode invariant method is marked as a restricted method with the bytecode unchanged.
  • markup class Take a class C in the old version, and judge whether it has the same C class in the new version, if it does not exist, mark c as a reduced class; if it exists, further compare Whether the definition of the class has changed, and the steps to determine whether the class definition has changed are:
  • step b) sequentially fetch a field f from the sorted list, and continue to fetch the next domain if there is no identical domain f' in the new class; c) otherwise, if it can destroy the premise without destroying the premise Domain f allocates the same offset of f, puts it into the layout context, and continues from step b);
  • the specific step of the method of marking the class existence class is to take a method in the class existence class to determine whether it has the same method in the new version class:
  • step 1.3 the specific steps of the tag reference structure change class are:
  • step 1.3.2 If the instruction is new/anewarray/multianewarray, if the instance field size of the target class it accesses is determined to change in step 1.1.3 above, then the method of marking the method as a structural change class is used. ;
  • step 3.1 The detailed process of step 3.1) is:
  • the invention combines and analyzes a binary file in a dynamic update of a Java program, and combines a new VM dynamic loading class mechanism to reduce the overhead of recompilation of machine code by dynamic update at runtime. , improve the efficiency of the update.
  • Figure 1 shows the different update operations based on the updates that occur in the Java class.
  • Figure 2 shows the class-level tagging process of the analysis tool of the present invention
  • FIG. 3 shows a flow of analyzing and marking the class structure of the analysis tool of the present invention
  • Figure 4 shows the flow of analysis and labeling of the method body by the analysis tool of the present invention
  • Figure 5 shows the flow of the analysis tool of the present invention to find a reference update method.
  • FIG. 6 is a content of a class in a different version of a program before and after a Java program update in an embodiment.
  • Figure 7 is a table of the methods of classes A and B in Figure 6,
  • Figure 8 is a bytecode of the class B method m3 of Figure 6. detailed description
  • Figure 6 shows the contents of the classes in different versions of the program before and after a Java program update.
  • the figure on the left is the class in the version 1 program, and the one on the right is the class in the version 2 program.
  • the A is judged to have the same class A' in the version 2, and then it is judged whether the class structure of the class A has changed.
  • the Object class has not changed, the class A domain has not changed, and the object size has not changed.
  • the class A has added methods, so the class structure changes.
  • Class A is marked as a class with a class but a structural change.
  • the method implementation in A is compared.
  • the flow of the comparison method of Figure 4 will be compared in class C. Time to elaborate.
  • the class B is taken out for analysis, and it is found that the same class B' exists in the second version, and then it is judged whether the structure of the class B changes.
  • the parent class A of class B is marked as a class but the structure changes, and B is inevitably marked as a class but the structure changes.
  • the details of B change are continuously determined. It is found that the new instance domain j is added to B, and the static domain s is reduced. The instance domain i is unchanged before and after the update, and the offset can be kept unchanged by the adjustment. After that, the size of the class instance is determined.
  • the method offset of class B is continuously determined. It is found that class B removes the implementation of method m2 and overwrites the method ml in parent class A, and the method m3 remains unchanged. The offset of the method in class B can be maintained, as shown in Figure 7.
  • the implementation of the method in A will be compared according to the flow of FIG. 4, and the bytecode of the method m3 in B is as shown in FIG. 8. According to the flow of Figure 4, the first two instructions of m3 can be judged as the same instruction by opcode.
  • the third instruction has operands and the same, but since the operand of the instruction refers to the symbol in ConstantPool, it is necessary to take out the symbol for comparison and find that it is different. Therefore, it can be judged that the method m3 has changed before and after the update.
  • the class C is extracted for analysis, and it is found that the same class C' exists in version 2, and then it is determined whether the structure of class C has changed. According to the flow of Figure 3, the parent class, domain, and method of class C have not changed, so class C is marked as a class and the structure has not changed. Continue to compare the method of class C. According to the flow of Figure 4, it can also be judged that the ml method has changed, and the method ml in class C is marked as a restricted method.
  • class D is taken for analysis, and it is found that the same class D' exists in version two, and then the class is judged. Whether the structure of C has changed. Analysis can be found that the D class is completely consistent before and after the update, but the D class refers to the class B. In the subsequent second traversal, according to the flow of Figure 5, find out the method that needs to be recompiled. According to the flow of Figure 2, after class D is compared, class E is taken for analysis, and it is found that class E does not exist in version two, so all methods in class E are marked as restricted methods.
  • the first traversal is completed after class E is compared. Then a second traversal to find out which method needs to be recompiled.
  • a second traversal to find out which method needs to be recompiled.
  • the method m in D it is found that the method has no change in the displacements of the methods ml, m2, and m3 in B.
  • the initialization method of D it is found that the size of the object of B changes, so the constructor needs to be recompiled, and the initialization method is marked as a constrained method of 0SR.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Security & Cryptography (AREA)
  • Devices For Executing Special Programs (AREA)
  • Stored Programmes (AREA)

Abstract

A method for online updating Java classes based on the reconstruction of byte-code files is provided. The method analyzes and reconstructs the binary files when it performs dynamic updates on the Java programs, combining a new mechanism of dynamically loading the classes by a virtual machine (VM), to reduce the costs brought by the dynamic updates recompiling the machine code on running time, and improve the update efficiency.

Description

一种基于字节码文件重构的 Java类在线更新方法  A Java class online update method based on bytecode file reconstruction

技术领域 Technical field

本发明属于计算机应用领域, 具体是一种基于字节码文件重构的高效 Java类在线更新方法。 背景技术  The invention belongs to the field of computer applications, and is specifically an efficient Java class online updating method based on bytecode file reconstruction. Background technique

软件是人的脑力劳动创造出来的产物。 世界上没有完美的软件, 开发者也很难一蹴而就, 完成交付一 个不需要改进的软件系统。 软件总需要开发者对其进行不断维护, 例如 bug 的修复、 效率的改进、 功能的 增强以及代码重构等。  Software is the product of human brain work. There is no perfect software in the world, and it is difficult for developers to complete a software system that does not require improvement. Software always requires constant maintenance by developers, such as bug fixes, efficiency improvements, feature enhancements, and code refactoring.

传统软件更新需要终止正在运行的软件, 然后某些场合, 尤其比较重要的软件系统, 终止正在运行的 软件的代价很大。 为此, 一种在线软件更新技术就显的十分重要。 基于 JVM (Java虚拟机)的软件更新系 统, 由于虚拟机的易于修改特性而具有很高的研究价值。  Traditional software updates require the termination of running software, and in some cases, especially the more important software systems, the cost of terminating the running software is high. To this end, an online software update technology is very important. A software update system based on JVM (Java Virtual Machine) has high research value due to the easy-to-modify features of virtual machines.

在机器上运行 Java程序要经过编写源码, 编译源码, 启动 JVM加载类文件运行等步骤。 Java语言主 要是由类组成, 而类主要是由域和方法定义组成。 在 JVM加载类文件后, JVM将把读取的字节码文件映 射成相应的运行时刻元数据。 这是对二进制文件在运行时刻的第一层处理。 当需要执行方法时, JVM会调 用他的在线编译器将字节码编译成相应机器码, CPU读取这些机器指令执行相应功能。 JVM会在内存分 配的堆区中创建对象, 对象对应的类型信息和类元数据相关, 这些信息主要描述了对象空间各偏移对应的 域, 以及该对象能够运行的实例方法。  To run a Java program on a machine, you need to write the source code, compile the source code, and start the JVM to load the class file to run. The Java language is mainly composed of classes, and the classes are mainly composed of domain and method definitions. After the JVM loads the class file, the JVM will map the read bytecode file to the corresponding runtime metadata. This is the first layer of processing of the binary at runtime. When a method needs to be executed, the JVM calls his online compiler to compile the bytecode into the corresponding machine code, and the CPU reads these machine instructions to perform the corresponding functions. The JVM creates an object in the memory allocated heap area. The type information corresponding to the object is related to the class metadata. The information mainly describes the domain corresponding to each offset of the object space, and the instance method that the object can run.

动态更新系统为保持更新的一致性, 定义了一个基本语义: 更新前不运行新代码, 更新后不运行旧代 码。 除此之外在更新过程中也要保证基本的类型安全。  The dynamic update system defines a basic semantic for maintaining consistency of updates: new code is not run before the update, and the old code is not run after the update. In addition to this, basic type safety is also guaranteed during the update process.

动态更新系统一般需要一个更新准备步骤, 主要是通过分析比较新旧版本程序发生的改变并将这些信 息输出到文件中, 同时程序员也可能需要编写一些更新补丁。  Dynamic update systems generally require an update preparation step, mainly by analyzing changes made to the new and old versions of the program and outputting the information to a file, and the programmer may need to write some update patches.

根据新旧版本 Java类发生的改变不同, 在分析阶段主要将需要处理的 Java类划分为如下三种: According to the changes made by the new and old versions of the Java class, the Java classes that need to be processed are mainly divided into the following three types in the analysis phase:

1. 当类的父类、 接口集合、 域集合、 方法集合发生改变时, 需要将该类利用 JVM 的动态加载机制 重新加载进虚拟机, 将类定义以及域定义、 方法定义映射成相应的运行时刻元数据。 这种类定 义发生改变的更新称为类更新。 1. When the class's parent class, interface collection, domain collection, and method collection change, the class needs to be reloaded into the virtual machine using the JVM's dynamic loading mechanism, and the class definition and domain definition and method definition are mapped to corresponding operations. Time metadata. An update to this type of definition change is called a class update.

2. 当类定义没有发生改变仅有方法的实现发生改变时, 这时只要为需要将方法对应的 VM元数据进 行更新即可。 这种类定义未变化但存在方法字节码改变更新称为方法体更新。  2. When the class definition has not changed, only the implementation of the method changes. In this case, you only need to update the VM metadata corresponding to the method. This class definition is unchanged but there is a method bytecode change update called method body update.

3. 当类定义和方法字节码没有任何改变, 但由于存在方法引用了类更新的类, 则需要将相应方法 的机器码进行更新。 这种字节码没有发生改变, 但引用了类更新类的方法更新称为引用方法更 新。 不同的更新会导致运行时刻元数据发生更改, 而动态更新就是要替换运行时刻元数据。 对上述分析得 到的不同更新, 在运行在线更新时需要采取不同的处理方式: 3. When there is no change in the class definition and method bytecode, but because there is a class that references the class update class, you need to update the machine code of the corresponding method. This bytecode has not changed, but a method update that references a class update class is called a reference method update. Different updates cause the runtime metadata to change, and dynamic updates replace the runtime metadata. Different updates to the above analysis require different approaches when running online updates:

1. 类更新:  1. Class update:

类更新使得运行时刻类元数据需要重新生成, 与此同时方法字节码也发生改变, 方法机器码也 随之改变。 由于类型的唯一性, 在替换新类是需要将旧类定义从运行时刻类型管理机制中移 除。 具体为:  The class update causes the runtime class metadata to be regenerated, and at the same time the method bytecode changes, and the method machine code changes. Due to the uniqueness of the type, replacing the new class requires removing the old class definition from the runtime type management mechanism. Specifically:

1 运行系统中移除旧类元数据 2动态加载新类 3 生成新的类元数据、 域元数据、 方法元数据 4编译方法  1 Remove old class metadata from running system 2 Dynamically load new class 3 Generate new class metadata, domain metadata, method metadata 4 Compilation method

2. 方法体更新:  2. Method body update:

方法体更新使得方法的字节码发生改变, 与此同时方法的字节码也发生改变。 具体为:  The method body update causes the bytecode of the method to change, and at the same time the bytecode of the method changes. Specifically:

1替换方法元数据中的字节码部分 2重新编译方法  1 Replacement method bytecode part in metadata 2 Recompilation method

3. 引用方法更新:  3. Reference method update:

引用方法的机器码中有部分指令的操作数发生改变, 这个时候一种简单的解决方法就是重新编译 整个方法, 但这显然不是最佳方法。 具体为:  The operand of some of the machine code in the reference method has changed. A simple solution at this time is to recompile the whole method, but this is obviously not the best method. Specifically:

1重新编译方法。  1 Recompile the method.

更新需要程序运行到一个安全点, 而安全点需要能够停止所有用户线程, 并扫描用户线程, 判定线程 运行栈中没有受限方法。 机器码发生改变的方法是受限方法, 此外, 用户也可以根据程序逻辑指定受限方 法。 当某方法被删除后, 为了确保更新语义, 这些方法也要被标记为受限的方法。  The update requires the program to run to a secure point, and the security point needs to be able to stop all user threads and scan the user thread, determining that there are no restricted methods in the thread's run stack. The method of changing the machine code is a restricted method. In addition, the user can also specify the restricted method according to the program logic. When a method is removed, these methods are also marked as restricted methods to ensure the semantics of the update.

引用方法更新的机器码需要修复,一般做法是重新编译。这类方法的特点: 一是字节码没有发生改变, 二是引用了类更新类。 虽然它的字节码没有改变, 引用的方法也皆存在于新旧版本中, 但由于 JVM 的动 态类加载机制会将新类对应的元数据分配到新的偏移, 这就导致引用方法更新的方法的机器码需要重新编 译了。 如果可以确保这种偏移更新前后不发生改变, 那么引用方法更新导致的重编译就可以免去, 提高更 新的效率。 本文提出一种方法结合分析并重构字节码二进制文件, 在运行时刻调整动态加载类的机制, 来 达到减少引用方法更新带来的重编译。 发明内容  The machine code that references the method update needs to be fixed. The general practice is to recompile. The characteristics of this type of method: First, the bytecode has not changed, and the second is to reference the class update class. Although its bytecode has not changed, the referenced methods are also present in the new and old versions, but because the dynamic class loading mechanism of the JVM will assign the metadata corresponding to the new class to the new offset, this leads to the reference method update. The machine code of the method needs to be recompiled. If you can ensure that this offset update does not change before and after, the recompilation caused by the reference method update can be eliminated, improving the efficiency of the update. This paper proposes a method to combine and analyze and reconstruct the bytecode binary file to adjust the dynamic loading class mechanism at runtime to reduce the recompilation caused by the update of the reference method. Summary of the invention

本发明所要解决的技术问题是提供一种基于字节码文件重构的 Java类在线更新方法,该方法通过在运 行时刻调整动态加载类的机制, 降低运行时刻元数据的变更, 减少了引用方法更新带来的重编译, 从而提 高了更新的效率。  The technical problem to be solved by the present invention is to provide a Java class online update method based on bytecode file reconstruction, which reduces the change of runtime metadata by reducing the dynamic loading class mechanism at runtime, and reduces the reference method. The recompilation brought by the update improves the efficiency of the update.

本发明所述的一种基于字节码文件重构的 Java类在线更新方法, 其主要包含以下步骤:  The invention relates to a Java class online updating method based on bytecode file reconstruction, which mainly comprises the following steps:

1 ) 分析新旧版本程序中二进制字节码文件, 找出类更新、 类方法体更新、 类引用方法更新所针对的 类; 1) Analyze the binary bytecode file in the old and new versions of the program, and find out the class update, class method body update, and class reference method update. Class

2) 根据分析结果在运行时刻找寻合适的更新点;  2) Find suitable update points at runtime according to the analysis results;

3 ) 在运行时刻, 根据类发生的更新, 对其做相应的更新操作, 具体为:  3) At runtime, according to the update of the class, the corresponding update operation is performed, specifically:

3.1 ) 对于类更新的类, 将新类替换旧类;  3.1) For classes that are updated by the class, replace the old class with the old one;

3.2) 对于类方法体更新的类, 将其定义的方法重新读取并初始化可用;  3.2) For the class updated by the class method body, re-read and initialize the methods defined by it;

3.3 ) 对于类引用方法更新的类, 将存在相应引用的方法重新编译;  3.3) For classes whose class reference method is updated, recompile the method with the corresponding reference;

4) 将堆区中类型改变的类实例转换成新类型实例。  4) Convert the class instance of the type change in the heap to a new type instance.

上述步骤 1 ) 的过程为:  The process of step 1) above is:

基于 JVM的更新的分析工具对所有类遍历两遍,  The JVM-based update analysis tool traverses all classes twice,

第一次遍历:  First traversal:

1.1 )根据旧版本中类在新版中出现的情况, 对旧版本类进行分类, 标记出减少的类和新旧版本中都存 在的类; 对新旧版本中都存在的类, 进一步标记出类定义变化和类定义不变化的类;  1.1) According to the situation of the class in the old version in the new version, classify the old version class, mark the classes that exist in the reduced class and the old and new versions; further mark the class definition changes for the classes that exist in the new and old versions. And classes whose class definitions do not change;

1.2 )根据旧版本中类存在的类中方法在新版中出现的情况, 标记出减少的方法、 都存在但方法体变化 的方法, 以及都存在且方法体不变的方法;  1.2) According to the situation in the new version of the methods in the class in the old version, the methods of reducing, the methods that exist but the method body changes, and the methods that exist and the method body are unchanged are marked;

第二次遍历:  The second traversal:

1.3 ) 对那些存在于新旧版本中且方法体保持不变的方法, 标记出引用类定义改变的类的方法; 标记输出结果:  1.3) For those methods that exist in the old and new versions and whose method body remains the same, mark the method that references the class whose class definition changed; Mark the output:

1.4) 将步骤 1.1 ) 中减少的类、 类定义变化的类中的所有方法, 类定义不变的类中方法体发生改变的 方法、 方法体不变但引用类定义改变的类的方法标记为受限方法;  1.4) Reduce the class in step 1.1), all the methods in the class whose class definition changes, the method in which the method body in the class definition is unchanged, the method whose method body is unchanged but the class that references the class definition change is marked as Restricted method

15 ) 将步骤 1.4) 中标记出的受限方法中, 字节码不变的方法标记为字节码不变的受限方法。  15) In the restricted method marked in step 1.4), the bytecode invariant method is marked as a restricted method with the bytecode unchanged.

上述步骤 1.1 )标记类的具体步骤为: 在旧版本中取一类 C, 判断其在新版本中是否存在同样的 C类, 若不存在则标记 c为减少的类; 若存在, 则进一步比较类的定义是否发生改变, 而判断类定义是否发生改 变的步骤为:  The specific steps of the above step 1.1) markup class are: Take a class C in the old version, and judge whether it has the same C class in the new version, if it does not exist, mark c as a reduced class; if it exists, further compare Whether the definition of the class has changed, and the steps to determine whether the class definition has changed are:

1.1.1 ) 判断二进制文件中的类基本信息是否发生改变, 若父类为减少的类则标记该类类继承关系变 化;  1.1.1) Determine whether the basic information of the class in the binary file has changed. If the parent class is a reduced class, mark the class inheritance relationship change;

1.1.2)判断并标记域存在域在运行时刻偏移是否能保持不变, 根据相应 VM平台的实例域的布局计算 出实例域在堆区对象实例空间中的偏移, 该偏移与域出现在二进制文件中的顺序相关, 对编译器生 成的二进制字节码文件进行重构, 调整域出现的顺序;  1.1.2) Determining and marking whether the domain existence domain can remain unchanged at runtime, and calculating the offset of the instance domain in the heap object instance space according to the layout of the instance domain of the corresponding VM platform, the offset and the domain Appear the order in the binary file, reconstruct the binary bytecode file generated by the compiler, and adjust the order in which the fields appear;

1.1.3 ) 在 1.1.2) 调整布局之后, 必要时判断并标记出类的实例大小是否发生改变;  1.1.3) After adjusting the layout in 1.1.2), judge and mark if the instance size of the class has changed if necessary;

1.1.4)判断并标记方法存在方法在运行时刻偏移是否能保持不变, 根据相应 VM平台实例方法偏移算 法计算出偏移, 该偏移与方法出现在二进制文件中的顺序有关, 必要时对编译器生成的二进制字节 码文件进行重构, 调整方法出现的顺序; 1.1.4) Judging and Marking Method Existence Method Whether the offset can be kept unchanged at runtime, the offset is calculated according to the corresponding VM platform instance method offset algorithm, and the offset is related to the order in which the method appears in the binary file. The binary bytes generated by the compiler The code file is reconstructed, and the order in which the methods appear is adjusted;

1.1.5 )若有以上之一发生改变, 则判定该类定义改变; 否则判定为类定义不变, 将调整过的字节码写 入文件中。  1.1.5) If one of the above changes, it is determined that the definition of the class changes; otherwise, the class definition is unchanged, and the adjusted bytecode is written into the file.

上述步骤 1丄 2) 的调整并判断域偏移是否发生改变的详细步骤是:  The detailed steps of adjusting the above steps 1丄 2) and determining whether the domain offset has changed are:

前提: 调整过程中如果发现填补空位导致增大对象实例大小, 则停止调整。  Prerequisites: If you find that filling the gaps during the adjustment process increases the size of the object instance, stop the adjustment.

a) 将旧类域进行布局, 并将域按照偏移排序;  a) Layout the old class domain and sort the fields by offset;

b) 从排序后的列表中按序取出一域 f, 若在新类中不存在相同定义域 f'则继续取下一域; c) 否则, 若其能在不破坏前提的情况下将该域 f分配 f同样的偏移, 则将其放入布局上下文 中, 从步骤 b)继续;  b) sequentially fetch a field f from the sorted list, and continue to fetch the next domain if there is no identical domain f' in the new class; c) otherwise, if it can destroy the premise without destroying the premise Domain f allocates the same offset of f, puts it into the layout context, and continues from step b);

d) 否则, 标记该域位移改变, 将其放入布局上下文中从步骤 b)继续。  d) Otherwise, mark the domain displacement change and place it in the layout context from step b) to continue.

上述步骤 1丄 4) 的调整并判断方法偏移是否发生改变的详细步骤是:  The detailed steps of adjusting the above steps 1丄 4) and determining whether the method offset has changed are:

a) 先分别将新旧两类实例方法在方法表中的偏移确定, 得到方法表 mtable与 mtable';  a) First determine the offset of the new and old instance methods in the method table, and get the method table mtable and mtable';

b ) 在旧类方法表 mtable 中取出一个方法 m, 若新类中方法 m'偏移与之相同, 即 m.offset==m'.offset, 则继续去旧类中取下一个方法;  b) Take a method m in the old class method table mtable. If the method m' offset in the new class is the same, ie m.offset==m'.offset, continue to take the next method in the old class;

c)否则, 若该旧类方法在旧类方法表中的偏移 m.offSet是属于新类方法表中父类继承方法范围, 则标记该方法偏移变化; c) Otherwise, if the offset m.off Se t of the old class method in the old class method table belongs to the range of the parent class inheritance method in the new class method table, mark the method offset change;

d) 否则, 若该旧类方法在旧类方法表中的偏移 m.offSet是属于该类定义方法范围, 则将新类中 方法偏移与新类方法表中该偏移处方法偏移交换, 即 d) Otherwise, if the offset m.off Se t of the old class method in the old class method table belongs to the scope of the class definition method, then the method offset in the new class and the offset method in the new class method table Offset swap, ie

mtable' [m' .offset] = mtable' [m.offset];  Mtable' [m' .offset] = mtable' [m.offset];

mtable' [m' .offset] .offset = m, .offset;  Mtable' [m' .offset] .offset = m, .offset;

mtable' [m.offset] = m,;  Mtable' [m.offset] = m,;

m, .offset=m.offset;  m, .offset=m.offset;

e ) 否则, 若该旧类方法在旧类方法表中的偏移超出新类方法表长度, 则扩展新类方法表大小, 将新类方法表同一方法偏移  e) Otherwise, if the offset of the old class method in the old class method table exceeds the length of the new class method table, the new class method table size is expanded, and the new class method table is offset by the same method.

Extend(mtable');  Extend(mtable');

mtable' [m' .offset] = null;  Mtable' [m' .offset] = null;

mtable' [m.offset] = m,;  Mtable' [m.offset] = m,;

m'.offset=m. offset  M'.offset=m. offset

上述步骤 1.2) 中, 标记类存在类的方法的具体步骤是在类存在类中取出一方法, 判断其在新版本类 中是否存在同样的方法:  In the above step 1.2), the specific step of the method of marking the class existence class is to take a method in the class existence class to determine whether it has the same method in the new version class:

1.2.1 ) 若不存在, 则标记该方法为减少的方法; 1.2.2 ) 若存在则对方法存在方法判断进一步判断方法体是否改变的步骤为: 1.2.1) If it does not exist, mark the method as a reduced method; 1.2.2) If there is a method, the method for judging the method existence method to further determine whether the method body is changed is:

a) 按序取新旧版本方法的指令 insnOld, insnNew;  a) The instruction to take the old and new version methods insnOld, insnNew;

b ) 若 insnOld与 insnNew不是同一条指令, 则判定该方法体发生改变;  b) if insnOld and insnNew are not the same instruction, it is determined that the method body has changed;

c ) 若 insnOlde与 insnNew是同一条指令, 则若其没有引用 Constant Pool, 则按指令格式比 较该指令各域; 若引用了 Constant Pool, 则取出 Constant Pool中的内容进行比较; 若比较结 果不同, 则判定该方法体发生改变。  c) If insnOlde and insnNew are the same instruction, if they do not refer to Constant Pool, compare the fields of the instruction according to the instruction format; if the Constant Pool is referenced, take the contents of the Constant Pool for comparison; if the comparison result is different, Then it is determined that the method body changes.

步骤 1.3 ) 中, 标记引用结构发生改变类的具体步骤为:  In step 1.3), the specific steps of the tag reference structure change class are:

1.3.1 ) 取出一条指令,  1.3.1) Take an instruction,

1.3.2 ) 若该指令是 new/anewarray/multianewarray, 若其访问的目标类的实例域大小在上述步骤 1.1.3 ) 中被判定发生改变, 则标记该方法为弓 I用结构变化类的方法;  1.3.2) If the instruction is new/anewarray/multianewarray, if the instance field size of the target class it accesses is determined to change in step 1.1.3 above, then the method of marking the method as a structural change class is used. ;

1.3.3 ) 若该指令是 instanceof/checkcast, 若其访问的目标类的继承结构在上述 1丄 1 ) 步骤中被判定发 生变化, 则标记该方法为弓 I用结构变化类的方法;  1.3.3) If the instruction is instanceof/checkcast, if the inheritance structure of the target class it accesses is determined to change in the above step 1), then the method is marked as a method of using the structural change class;

1.3.4 ) 若该指令是 getfield/putfield/getstatic/putstatic/invokevirtual/invokespecial之一, 若其访问的目标 方法、 目标域的偏移在上述步骤 1.1.2 ) 和 1.1.4) 中被判定发生改变, 则标记该方法为引用结构变化类的 方法。  1.3.4) If the instruction is one of getfield/putfield/getstatic/putstatic/invokevirtual/invokespecial, if the target method of the access, the offset of the target domain is determined to occur in steps 1.1.2) and 1.1.4) above To change, mark the method as a method of referencing a structure change class.

步骤 3.1 ) 的详细过程是:  The detailed process of step 3.1) is:

3.1.1 ) 移除旧版本的类;  3.1.1) Remove the old version of the class;

3.1.2 ) 修改 ClassLoader的 path已找到新类对应的字节码数据流;  3.1.2) Modify the path of the ClassLoader to find the bytecode data stream corresponding to the new class;

3.1.3 )通过动态类加载机制加载新类, 加载类之后, 把旧类的 VM元数据属性置换给新类, 修改类型 系统中类型 Id, 将旧类 Id赋给新类;  3.1.3) Load the new class through the dynamic class loading mechanism. After loading the class, replace the VM metadata attribute of the old class with the new class, modify the type Id in the type system, and assign the old class Id to the new class.

3.1.4 )修改静态数据表中静态域和方法的偏移, 将相应位置处数据替换成新类对应的指针; 实例域和 实例方法的偏移通过分析调整字节码二进制文件;  3.1.4) Modify the offset of the static field and method in the static data table, and replace the data at the corresponding position with the pointer corresponding to the new class; the offset of the instance field and the instance method adjust the bytecode binary file through analysis;

3.1.5 ) 调整之后进行初始化、 实例化等后续操作。  3.1.5) After the adjustment, perform subsequent operations such as initialization and instantiation.

本发明在对 Java程序进行动态更新时对二进制文件进行分析、 重构的基础上, 结合一种新的 VM动 态加载类机制, 以减少运行时刻动态更新对机器码的重编译所带来的开销, 提高更新的效率。 附图说明  The invention combines and analyzes a binary file in a dynamic update of a Java program, and combines a new VM dynamic loading class mechanism to reduce the overhead of recompilation of machine code by dynamic update at runtime. , improve the efficiency of the update. DRAWINGS

图 1显示了根据 Java类发生的更新不同进行不同的更新操作。  Figure 1 shows the different update operations based on the updates that occur in the Java class.

图 2显示了本发明的分析工具对类层次的标记流程,  Figure 2 shows the class-level tagging process of the analysis tool of the present invention,

图 3显示了本发明的分析工具对类结构进行分析标记的流程,  FIG. 3 shows a flow of analyzing and marking the class structure of the analysis tool of the present invention,

图 4显示了本发明的分析工具对方法体进行分析标记的流程, 图 5显示了本发明的分析工具找出引用更新方法的流程, Figure 4 shows the flow of analysis and labeling of the method body by the analysis tool of the present invention, Figure 5 shows the flow of the analysis tool of the present invention to find a reference update method.

图 6是实施例中一次 Java程序更新前后不同版本程序中类的内容,  6 is a content of a class in a different version of a program before and after a Java program update in an embodiment.

图 7是图 6中类 A、 B的方法表,  Figure 7 is a table of the methods of classes A and B in Figure 6,

图 8是图 6中类 B方法 m3的字节码。 具体实施方式  Figure 8 is a bytecode of the class B method m3 of Figure 6. detailed description

以下结合具体实施例对本发明作进一步描述。  The invention is further described below in conjunction with specific embodiments.

如图 6所示为一次 Java程序更新前后不同版本程序中类的内容。 其中左图列出的为版本一程序中的 类, 右图中列出的是版本二程序中的类。  Figure 6 shows the contents of the classes in different versions of the program before and after a Java program update. The figure on the left is the class in the version 1 program, and the one on the right is the class in the version 2 program.

在分析的阶段, 采用图 2所示之流程, 首先将版本一中类按照继承关系进行拓扑排序, 于是取出进行 比较的顺序为 A B C D E。  In the analysis stage, the flow shown in Figure 2 is used. First, the version one class is topologically sorted according to the inheritance relationship, and then the order of comparison is A B C D E.

按照图 2之流程, 取出 A判断出版本二中存在同样的类 A' , 接着判断类 A的类结构是否发生改变。 按照图 3之流程, A的父类更新前后都是 Object类未变化, A类域未变化, 对象大小也同样未变化, A类 增加了方法, 所以类结构发生变化。 通过进一步分析比较, 可以判断 A类方法 ml的偏移可以保持不变。 将类 A标记成类存在但结构变化的类, 接着按照图 4之流程比较 A中方法实现, 但由于这里没有给出 A中 方法的实现, 关于图 4之比较方法流程将在比较类 C的时候阐述。  According to the flow of Fig. 2, the A is judged to have the same class A' in the version 2, and then it is judged whether the class structure of the class A has changed. According to the flow of Figure 3, before and after the parent class update of A, the Object class has not changed, the class A domain has not changed, and the object size has not changed. The class A has added methods, so the class structure changes. By further analysis and comparison, it can be judged that the offset of the class A method ml can be kept unchanged. Class A is marked as a class with a class but a structural change. Then, according to the flow of Figure 4, the method implementation in A is compared. However, since the implementation of the method in A is not given here, the flow of the comparison method of Figure 4 will be compared in class C. Time to elaborate.

按照图 2之流程, 比较完 A之后接着取出类 B进行分析, 发现版本二中存在同样的类 B' , 接着判断 类 B的结构是否发生改变。 按照图 3之流程, B类的父类 A类被被标记为类存在但结构发生改变, B受其 影响必然被同样标记为类存在但结构发生改变的。 按照图 3之流程继续判断 B改变的细节, 发现 B中增加 了新实例域 j, 减少了静态域 s, 实例域 i更新前后不变, 且其偏移可以通过调整保持不变。 之后, 判断 类实例大小, 由于减少了是静态域, 增加了实例域, 所以 B类实例大小增大。 按照图 3之流程继续判断类 B的方法偏移情况, 发现类 B移除了方法 m2的实现, 并覆写了父类 A中的方法 ml , 方法 m3保持不变。 B 类中方法的偏移均可以保持, 如图 7所示。接着将会按照图 4之流程比较 A中方法的实现, B中方法 m3的 字节码如图 8所示。 按照图 4之流程, 比较 m3 的前两条指令时通过 opcode即可判断为相同指令。 第三条 指令均有操作数且相同, 但由于该指令的操作数引用了 ConstantPool 中的符号, 所以需要取出该符号进 行比较发现不同, 于是比较至此即可判断方法 m3更新前后发生了改变。  According to the flow of Fig. 2, after comparing A, the class B is taken out for analysis, and it is found that the same class B' exists in the second version, and then it is judged whether the structure of the class B changes. According to the flow of Figure 3, the parent class A of class B is marked as a class but the structure changes, and B is inevitably marked as a class but the structure changes. According to the flow of Figure 3, the details of B change are continuously determined. It is found that the new instance domain j is added to B, and the static domain s is reduced. The instance domain i is unchanged before and after the update, and the offset can be kept unchanged by the adjustment. After that, the size of the class instance is determined. Since the static domain is reduced and the instance domain is increased, the size of the class B instance is increased. According to the flow of Figure 3, the method offset of class B is continuously determined. It is found that class B removes the implementation of method m2 and overwrites the method ml in parent class A, and the method m3 remains unchanged. The offset of the method in class B can be maintained, as shown in Figure 7. Next, the implementation of the method in A will be compared according to the flow of FIG. 4, and the bytecode of the method m3 in B is as shown in FIG. 8. According to the flow of Figure 4, the first two instructions of m3 can be judged as the same instruction by opcode. The third instruction has operands and the same, but since the operand of the instruction refers to the symbol in ConstantPool, it is necessary to take out the symbol for comparison and find that it is different. Therefore, it can be judged that the method m3 has changed before and after the update.

按照图 2之流程, 比较完类 B之后取出类 C进行分析, 发现版本二中存在同样的类 C' ,接着判断类 C 的结构是否发生改变。 按照图 3之流程, 类 C的父类、 域、 方法均未改变, 于是类 C被标记为类存在且结 构未变。 继续比较类 C的方法 ml的, 按照图 4之流程, 同样可判断 ml方法发生改变, 将类 C中方法 ml 标记为受限方法。  According to the flow of Figure 2, after class B is compared, the class C is extracted for analysis, and it is found that the same class C' exists in version 2, and then it is determined whether the structure of class C has changed. According to the flow of Figure 3, the parent class, domain, and method of class C have not changed, so class C is marked as a class and the structure has not changed. Continue to compare the method of class C. According to the flow of Figure 4, it can also be judged that the ml method has changed, and the method ml in class C is marked as a restricted method.

按照图 2之流程, 比较完类 C之后取出类 D进行分析, 发现版本二中存在同样的类 D' , 接着判断类 C的结构是否发生改变。 分析可发现 D类更新前后完全一致, 但 D类引用了类 B。 将在后续的第二次遍历 中, 按照图 5之流程, 找出需要重新编译的方法。 按照图 2之流程, 比较完类 D之后取出类 E进行分析, 发现版本二中并不存在类 E, 所以类 E中所有方法均标记为受限方法。 According to the flow of Figure 2, after class C is compared, class D is taken for analysis, and it is found that the same class D' exists in version two, and then the class is judged. Whether the structure of C has changed. Analysis can be found that the D class is completely consistent before and after the update, but the D class refers to the class B. In the subsequent second traversal, according to the flow of Figure 5, find out the method that needs to be recompiled. According to the flow of Figure 2, after class D is compared, class E is taken for analysis, and it is found that class E does not exist in version two, so all methods in class E are marked as restricted methods.

按照图 2之流程, 比较完类 E之后第一遍遍历结束。接着进行第二次遍历来找出需要重新编译的方法。 按照图 5之流程, 在分析 D中方法 m时, 发现该方法引用了 B中的方法 ml、 m2、 m3的位移均未发生改变。 但在分析 D的初始化方法时, 发现 B的对象大小发生改变, 所以该构造方法需要重新编译, 将该初始化方 法标记为可 0SR的受限方法。  According to the flow of Figure 2, the first traversal is completed after class E is compared. Then a second traversal to find out which method needs to be recompiled. According to the flow of Fig. 5, when analyzing the method m in D, it is found that the method has no change in the displacements of the methods ml, m2, and m3 in B. However, when analyzing the initialization method of D, it is found that the size of the object of B changes, so the constructor needs to be recompiled, and the initialization method is marked as a constrained method of 0SR.

所有分析结束后, 我们需要重构类 A和类 B的二进制字节码文件, 以保证在运行时刻加载时可以保证 相应方法和域的位移不变。  After all the analysis is complete, we need to reconstruct the binary bytecode files of class A and class B to ensure that the displacement of the corresponding method and domain is unchanged when loading at runtime.

在运行时刻更新时,按照图 1之流程加载并更新程序。 A与类 B需要重新加载类并生成新的 VM元数据, 以及编译新的方法; 类 C需要将方法 ml重新编译; 类 D需要将其初始化方法重新编译; 类 E将其移除即 可, 这一点可以有 JVM的垃圾回收管理机制来完成。  When the runtime is updated, the program is loaded and updated according to the flow of Figure 1. A and class B need to reload the class and generate new VM metadata, and compile new methods; class C needs to recompile method ml; class D needs to recompile its initialization method; class E removes it, This can be done with the JVM's garbage collection management mechanism.

我们的静态分析工具在分析阶段确定所有类的方法表, 并通过一系列调整手段尽量保证更新前后都存 在的方法位移不变, 并将结果反馈到原始二进制文件中。 通过我们的静态分析工具, 可以有效的降低那些 字节码发生改变但机器码需要重新编译的方法的数量。  Our static analysis tools determine the method tables for all classes during the analysis phase, and try to ensure that the method displacements that exist before and after the update are unchanged through a series of adjustments, and the results are fed back into the original binary. With our static analysis tools, you can effectively reduce the number of methods that change bytecode but machine code needs to be recompiled.

Claims

权 利 要 求 Rights request 1、 一种基于字节码文件重构的 Java类在线更新方法, 其特征在于包含以下步骤: 1. A Java class online update method based on bytecode file reconstruction, which is characterized by the following steps: 1 ) 分析新旧版本程序中二进制字节码文件, 找出类更新、 类方法体更新、 类引用方法更新所针对的 类;  1) Analyze the binary bytecode file in the old and new versions of the program, and find out the class for which the class update, the class method body update, and the class reference method update are targeted; 2) 根据分析结果在运行时刻找寻合适的更新点;  2) Find suitable update points at runtime according to the analysis results; 3 ) 在运行时刻, 根据类发生的更新, 对其做相应的更新操作, 具体为:  3) At runtime, according to the update of the class, the corresponding update operation is performed, specifically: 3.1 ) 对于类更新的类, 将新类替换旧类;  3.1) For classes that are updated by the class, replace the old class with the old one; 3.2) 对于类方法体更新的类, 将其定义的方法重新读取并初始化可用;  3.2) For the class updated by the class method body, re-read and initialize the methods defined by it; 3.3 ) 对于类引用方法更新的类, 将存在相应引用的方法重新编译;  3.3) For classes whose class reference method is updated, recompile the method with the corresponding reference; 4) 将堆区中类型改变的类实例转换成新类型实例。  4) Convert the class instance of the type change in the heap to a new type instance. 2、 根据权利要求 1所述的基于字节码文件重构的 Java类在线更新方法, 其特征在于上述步骤 1 ) 的 过程为:  2. The Java class online update method based on bytecode file reconstruction according to claim 1, wherein the process of the above step 1) is: 基于 JVM的更新的分析工具对所有类遍历两遍,  The JVM-based update analysis tool traverses all classes twice, 第一次遍历:  First traversal: 1.1 )根据旧版本中类在新版中出现的情况, 对旧版本类进行分类, 标记出减少的类和新旧版本中都存 在的类; 对新旧版本中都存在的类, 进一步标记出类定义变化和类定义不变化的类;  1.1) According to the situation of the class in the old version in the new version, classify the old version class, mark the classes that exist in the reduced class and the old and new versions; further mark the class definition changes for the classes that exist in the new and old versions. And classes whose class definitions do not change; 1.2 )根据旧版本中类存在的类中方法在新版中出现的情况, 标记出减少的方法、 都存在但方法体变化 的方法, 以及都存在且方法体不变的方法;  1.2) According to the situation in the new version of the methods in the class in the old version, the methods of reducing, the methods that exist but the method body changes, and the methods that exist and the method body are unchanged are marked; 第二次遍历:  The second traversal: 1.3 ) 对那些存在于新旧版本中且方法体保持不变的方法, 标记出引用类定义改变的类的方法; 标记输出结果:  1.3) For those methods that exist in the old and new versions and whose method body remains the same, mark the method that references the class whose class definition changed; Mark the output: 1.4) 将步骤 11 ) 中减少的类、 类定义变化的类中的所有方法, 类定义不变的类中方法体发生改变的 方法、 方法体不变但引用类定义改变的类的方法标记为受限方法;  1.4) Reduce the class in step 11), all methods in the class whose class definition changes, the method in which the method body in the class definition is changed, the method body whose method body is unchanged but the class whose class definition is changed is marked as Restricted method 1.5 ) 将步骤 14) 中标记出的受限方法中, 字节码不变的方法标记为字节码不变的受限方法。  1.5) In the restricted method marked in step 14), the bytecode invariant method is marked as a restricted method with the bytecode unchanged. 3、根据权利要求 2所述基于字节码文件重构的 Java类在线更新方法, 其特征在于上述步骤 1.1 )标记 类的具体步骤为: 在旧版本中取一类 C, 判断其在新版本中是否存在同样的 C类, 若不存在则标记 C为减 少的类; 若存在, 则进一步比较类的定义是否发生改变, 而判断类定义是否发生改变的步骤为:  3. The Java class online update method based on bytecode file reconstruction according to claim 2, wherein the step 1.1) the specific step of marking the class is: taking a class C in the old version, and determining that it is in the new version. Whether the same C class exists in the middle, if it does not exist, the mark C is a reduced class; if it exists, further compare whether the definition of the class changes, and the step of determining whether the class definition changes: 1.1.1 ) 判断二进制文件中的类基本信息是否发生改变, 若父类为减少的类则标记该类类继承关系变 化; 1.1.1) Determine whether the basic information of the class in the binary file has changed. If the parent class is a reduced class, mark the class inheritance relationship change; 1.1.2)判断并标记域存在域在运行时刻偏移是否能保持不变, 根据相应 VM平台的实例域的布局计算 出实例域在堆区对象实例空间中的偏移, 该偏移与域出现在二进制文件中的顺序相关, 对编译器生 成的二进制字节码文件进行重构, 调整域出现的顺序; 1.1.2) Determining and marking whether the domain existence domain can remain unchanged at runtime, and calculating the offset of the instance domain in the heap object instance space according to the layout of the instance domain of the corresponding VM platform, the offset and the domain Appear the order in the binary file, reconstruct the binary bytecode file generated by the compiler, and adjust the order in which the fields appear; 1.1.3 ) 在 1.1.2) 调整布局之后, 必要时判断并标记出类的实例大小是否发生改变;  1.1.3) After adjusting the layout in 1.1.2), judge and mark if the instance size of the class has changed if necessary; 1.1.4)判断并标记方法存在方法在运行时刻偏移是否能保持不变, 根据相应 VM平台实例方法偏移算 法计算出偏移, 该偏移与方法出现在二进制文件中的顺序有关, 必要时对编译器生成的二进制字节 码文件进行重构, 调整方法出现的顺序;  1.1.4) Judging and Marking Method Existence Method Whether the offset can be kept unchanged at runtime, the offset is calculated according to the corresponding VM platform instance method offset algorithm, and the offset is related to the order in which the method appears in the binary file. Refactoring the binary bytecode file generated by the compiler, and adjusting the order in which the methods appear; 1.1.5 )若有以上之一发生改变, 则判定该类定义改变; 否则判定为类定义不变, 将调整过的字节码写 入文件中。  1.1.5) If one of the above changes, it is determined that the definition of the class changes; otherwise, the class definition is unchanged, and the adjusted bytecode is written into the file. 4、 根据权利要求 3 所述的基于字节码文件重构的 Java类在线更新方法, 其特征在于上述步骤 1.1.2) 的调整并判断域偏移是否发生改变的详细步骤是:  4. The Java class online update method based on bytecode file reconstruction according to claim 3, wherein the detailed steps of adjusting 1.1.2) and determining whether the domain offset has changed are: 前提: 调整过程中如果发现填补空位导致增大对象实例大小, 则停止调整,  Prerequisites: If the gap is found to increase the size of the object instance during the adjustment process, the adjustment is stopped. a) 将旧类域进行布局, 并将域按照偏移排序;  a) Layout the old class domain and sort the fields by offset; b) 从排序后的列表中按序取出一域 f, 若在新类中不存在相同定义域 f'则继续取下一域; c) 否则, 若其能在不破坏前提的情况下将该域 f分配 f同样的偏移, 则将其放入布局上下文 中, 从步骤 b)继续;  b) sequentially fetch a field f from the sorted list, and continue to fetch the next domain if there is no identical domain f' in the new class; c) otherwise, if it can destroy the premise without destroying the premise Domain f allocates the same offset of f, puts it into the layout context, and continues from step b); d) 否则, 标记该域位移改变, 将其放入布局上下文中从步骤 b)继续。  d) Otherwise, mark the domain displacement change and place it in the layout context from step b) to continue. 5、 根据权利要求 3 所述的基于字节码文件重构的 Java类在线更新方法, 其特征在于上述步骤 1.1.4) 的调整并判断方法偏移是否发生改变的详细步骤是:  5. The Java class online update method based on bytecode file reconstruction according to claim 3, wherein the detailed steps of adjusting the above step 1.1.4 and determining whether the method offset is changed are: a) 先分别将新旧两类实例方法在方法表中的偏移确定, 得到方法表 mtable与 mtable';  a) First determine the offset of the new and old instance methods in the method table, and get the method table mtable and mtable'; b ) 在旧类方法表 mtable 中取出一个方法 m, 若新类中方法 m'偏移与之相同, 即 m.offset==m'.offset, 则继续去旧类中取下一个方法;  b) Take a method m in the old class method table mtable. If the method m' offset in the new class is the same, ie m.offset==m'.offset, continue to take the next method in the old class; c )否则, 若该旧类方法在旧类方法表中的偏移 m.offSet是属于新类方法表中父类继承方法范围, 则标记该方法偏移变化; c) Otherwise, if the offset m.off Se t of the old class method in the old class method table belongs to the range of the parent class inheritance method in the new class method table, mark the method offset change; d) 否则, 若该旧类方法在旧类方法表中的偏移 m.offSet是属于该类定义方法范围, 则将新类中 方法偏移与新类方法表中该偏移处方法偏移交换, 即 d) Otherwise, if the offset m.off Se t of the old class method in the old class method table belongs to the scope of the class definition method, then the method offset in the new class and the offset method in the new class method table Offset swap, ie mtable' [m' .offset] = mtable' [m. offset];  Mtable' [m' .offset] = mtable' [m. offset]; mtable' [m' .offset] .offset = m, .offset;  Mtable' [m' .offset] .offset = m, .offset; mtable, [m. offset] = m,;  Mtable, [m. offset] = m,; m, .offset=m.offset;  m, .offset=m.offset; e ) 否则, 若该旧类方法在旧类方法表中的偏移超出新类方法表长度, 则扩展新类方法表大小, 将新类方法表同一方法偏移 e) Otherwise, if the offset of the old class method in the old class method table exceeds the length of the new class method table, then expand the new class method table size, Offset the new class method table to the same method Extend(mtable');  Extend(mtable'); ratable' [m' .offset] = null;  Ratable' [m' .offset] = null; ratable' [m.offset] = m,;  Ratable' [m.offset] = m,; m'.offset=m. offset o  M'.offset=m. offset o 6、根据权利要求 2所述的基于字节码文件重构的 Java类在线更新方法,其特征在于上述步骤 1.2)中, 标记类存在类的方法的具体步骤是在类存在类中取出一方法, 判断其在新版本类中是否存在同样的方法: The method for updating a Java class online based on bytecode file reconstruction according to claim 2, wherein in the step 1.2), the specific step of the method for marking the class existence class is to take a method in the class existence class. , to determine whether it exists in the new version of the class: 1.2.1 ) 若不存在, 则标记该方法为减少的方法; 1.2.1) If it does not exist, mark the method as a reduced method; 1.2.2) 若存在则对方法存在方法判断进一步判断方法体是否改变的步骤为:  1.2.2) If there is a method, the method for judging the method existence method to further determine whether the method body is changed is: a) 按序取新旧版本方法的指令 insnOld, insnNew;  a) The instruction to take the old and new version methods insnOld, insnNew; b) 若 insnOld与 insnNew不是同一条指令, 则判定该方法体发生改变;  b) If insnOld and insnNew are not the same instruction, it is determined that the method body has changed; c) 若 insnOlde与 insnNew是同一条指令, 则若其没有引用 Constant Pool, 则按指令格式比 较该指令各域; 若引用了 Constant Pool, 则取出 Constant Pool中的内容进行比较; 若比较结 果不同, 则判定该方法体发生改变。  c) If insnOlde and insnNew are the same instruction, if they do not refer to Constant Pool, compare the fields of the instruction according to the instruction format; if the Constant Pool is referenced, take the contents of the Constant Pool for comparison; if the comparison result is different, Then it is determined that the method body changes. 7、 根据权利要求 2所述的基于字节码文件重构的 Java类在线更新方法, 其特征在于步骤 1.3 ) 中, 标 记引用结构发生改变类的具体步骤为:  7. The Java class online update method based on bytecode file reconstruction according to claim 2, wherein in step 1.3), the specific steps of the tag reference structure change class are: 1.3.1 ) 取出一条指令,  1.3.1) Take an instruction, 1.3.2) 若该指令是 new/anewarray/multianewarray, 若其访问的目标类的实例域大小在上述步骤 1.1.3 ) 中被判定发生改变, 则标记该方法为弓 I用结构变化类的方法;  1.3.2) If the instruction is new/anewarray/multianewarray, if the instance field size of the target class it accesses is determined to change in step 1.1.3 above, then the method of marking the method as a structural change class for the bow I is marked. ; 1.3.3 ) 若该指令是 instanceof/checkcast, 若其访问的目标类的继承结构在上述 1.1.1 ) 步骤中被判定发 生变化, 则标记该方法为弓 I用结构变化类的方法;  1.3.3) If the instruction is instanceof/checkcast, if the inheritance structure of the target class it accesses is determined to change in step 1.1.1) above, then the method is marked as a method of using the structural change class; 1.3.4) 若该指令是 getfield/putfield/getstatic/putstatic/invokevirtual/invokespecial之一, 若其访问的目标 方法、 目标域的偏移在上述步骤 1丄 2) 和 1.1.4) 中被判定发生改变, 则标记该方法为引用结构变化类的 方法。  1.3.4) If the instruction is one of getfield/putfield/getstatic/putstatic/invokevirtual/invokespecial, if the target method of accessing, the offset of the target domain is determined to occur in steps 1丄2) and 1.1.4) above To change, mark the method as a method of referencing a structure change class. 8、根据权利要求 1中所述的基于字节码文件重构的 Java类在线更新方法, 其特征为步骤 3.1 )的详细 过程是:  8. The Java class online update method based on bytecode file reconstruction according to claim 1, wherein the detailed process of step 3.1) is: 3.1.1 ) 移除旧版本的类;  3.1.1) Remove the old version of the class; 3.1.2) 修改 ClassLoader的 path已找到新类对应的字节码数据流;  3.1.2) Modify the path of the ClassLoader to find the bytecode data stream corresponding to the new class; 3.1.3 )通过动态类加载机制加载新类, 加载类之后, 把旧类的 VM元数据属性置换给新类, 修改类型 系统中类型 Id, 将旧类 Id赋给新类;  3.1.3) Load the new class through the dynamic class loading mechanism. After loading the class, replace the VM metadata attribute of the old class with the new class, modify the type Id in the type system, and assign the old class Id to the new class. 3.1.4)修改静态数据表中静态域和方法的偏移, 将相应位置处数据替换成新类对应的指针; 实例域和 实例方法的偏移通过分析调整字节码二进制文件保持不变; 3.1.5 ) 调整之后进行类的初始化、 实例化等后续操作。 3.1.4) Modify the offset of the static domain and method in the static data table, and replace the data at the corresponding location with the pointer corresponding to the new class; The offset of the instance method is adjusted by adjusting the bytecode binary file; 3.1.5) After the adjustment, the initialization, instantiation and other subsequent operations of the class are performed.
PCT/CN2011/072410 2010-11-12 2011-04-02 Method for online updating java classes based on reconstruction of byte-code files Ceased WO2012062081A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201010544102.1 2010-11-12
CN201010544102.1A CN101963914B (en) 2010-11-12 2010-11-12 Byte-code file reconstruction-based Java type online updating method

Publications (1)

Publication Number Publication Date
WO2012062081A1 true WO2012062081A1 (en) 2012-05-18

Family

ID=43516796

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2011/072410 Ceased WO2012062081A1 (en) 2010-11-12 2011-04-02 Method for online updating java classes based on reconstruction of byte-code files

Country Status (2)

Country Link
CN (1) CN101963914B (en)
WO (1) WO2012062081A1 (en)

Families Citing this family (21)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101963914B (en) * 2010-11-12 2013-02-27 南京大学 Byte-code file reconstruction-based Java type online updating method
CN102736905B (en) * 2011-04-12 2015-04-15 深圳市金蝶中间件有限公司 Method for dynamically replacing field in classes
CN102831057B (en) * 2012-08-13 2015-02-11 于秀山 Method for analyzing software function change and influence thereof by using function diagram
CN103973475B (en) * 2013-02-05 2018-07-06 腾讯科技(深圳)有限公司 Different patch packet generation method and method for down loading, server, client
CN103942051B (en) * 2014-04-15 2017-04-05 新浪网技术(中国)有限公司 Application dispositions method and device based on PAAS platforms
CN104380250B (en) * 2014-05-21 2017-09-08 华为技术有限公司 A kind of dynamic creation can add the system and method with dismountable binary file
EP2987079A4 (en) * 2014-05-21 2016-04-06 Huawei Tech Co Ltd A system and method thereof for creating dynamically attachable and detachable binary files
EP3048552A1 (en) * 2015-01-21 2016-07-27 Samsung Electronics Co., Ltd. Apparatus and method for running multiple instances of a same application in mobile devices
US9575740B2 (en) 2015-01-21 2017-02-21 Samsung Electronics Co., Ltd. Apparatus and method for running multiple instances of a same application in mobile devices
US9519468B2 (en) * 2015-02-13 2016-12-13 Oracle International Corporation Modular co-versioning in a dynamically linked runtime environment
CN105068852A (en) * 2015-09-22 2015-11-18 普元信息技术股份有限公司 System and method for realizing Java class on-line hot updating in cloud computing environment
CN106708494B (en) * 2015-11-18 2020-11-27 北京神州泰岳软件股份有限公司 JAR upgrading method and device
US10067757B2 (en) * 2015-11-20 2018-09-04 Google Llc Dynamic update of an application in compilation and deployment with hot-swapping
CN106020822B (en) * 2016-05-18 2019-03-26 腾讯科技(成都)有限公司 Weak reference implementation method and device towards Pool object
CN109445807A (en) * 2017-08-28 2019-03-08 腾讯科技(深圳)有限公司 Realize the method, apparatus and computer readable storage medium of application program update
CN110704082A (en) * 2019-09-25 2020-01-17 许昌许继软件技术有限公司 Continuous integration method and system for monitoring platform
CN113535137A (en) * 2020-04-15 2021-10-22 华为技术有限公司 Method, apparatus and related products for loading and running application
CN111880806B (en) * 2020-07-23 2023-11-21 无锡融卡科技有限公司 Application execution method and application execution system
US11392364B2 (en) * 2020-09-28 2022-07-19 Red Hat, Inc. Adaptive hot reload for class changes
CN112363954B (en) * 2020-12-08 2021-07-30 南京大学 Software Dynamic Update Testing Method Based on Object State Consistency
CN115904551A (en) * 2022-11-18 2023-04-04 中科世通亨奇(北京)科技有限公司 Method and device for dynamically replacing Class in spring by bean

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101963914A (en) * 2010-11-12 2011-02-02 南京大学 Byte-code file reconstruction-based Java type online updating method

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100489778C (en) * 2007-11-22 2009-05-20 上海交通大学 Method for implementing dynamic update of Java program

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101963914A (en) * 2010-11-12 2011-02-02 南京大学 Byte-code file reconstruction-based Java type online updating method

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
GUTIANXIAO.: "Changes between Version 9 and Version 10 of DCodeDoc", 10 September 2010 (2010-09-10), Retrieved from the Internet <URL:http://moon.nju.edu.cn/trac/dilepis/wiki/DCodeDoc?action=diff&version=10> [retrieved on 20110707] *
GUTIANXIAO.: "Design Document for Code Dynamic Updates", 10 September 2010 (2010-09-10), Retrieved from the Internet <URL:http://moon.nju.edu.cn/trac/dilepis/wiki/DCodeDoc> [retrieved on 20110707] *
SUBRAMANIAN SURIYA ET AL.: "Dynamic Software Updates: A VM-centric Approach.", THE ACM SIGPLAN CONFERENCE ON PROGRAMMING LANGUAGE DESIGN AND IMPLEMENTATION (PLDI), vol. 44, no. ISSUE, June 2009 (2009-06-01), DUBLIN, IRELAND, pages 1 - 12 *

Also Published As

Publication number Publication date
CN101963914B (en) 2013-02-27
CN101963914A (en) 2011-02-02

Similar Documents

Publication Publication Date Title
WO2012062081A1 (en) Method for online updating java classes based on reconstruction of byte-code files
US11175896B2 (en) Handling value types
Dmitriev Towards flexible and safe technology for runtime evolution of java language applications
US9891900B2 (en) Generation of specialized methods based on generic methods and type parameterizations
US7367015B2 (en) Method and system for software program editing in common language runtime environment (CLRE)
Würthinger et al. Dynamic code evolution for Java
US5848274A (en) Incremental byte code compilation system
CN107924326B (en) Override migration methods for updated types
CN105493042A (en) Concurrent accesses of dynamically typed object data
CN101194230A (en) Method and apparatus for translating program code with coordination of access to shared resources
CN111966424A (en) Method and system for using complex constants
US10346310B2 (en) Cache block apparatus and methods
Gu et al. Javelus: A low disruptive approach to dynamic software updates
Aslam et al. Introducing TakaTuka: a Java virtualmachine for motes
Aslam et al. Optimized java binary and virtual machine for tiny motes
Stadler et al. Lazy continuations for Java virtual machines
Alliet et al. Complete translation of unsafe native code to safe bytecode
Graur et al. Specializing generic Java data structures
Bieniusa et al. The architecture of the DecentVM: Towards a decentralized virtual machine for many-core computing
Hirshman Virtual machines: Features and futures
Jeon et al. Reuse of JIT compiled code based on binary code patching in JavaScript engine
Neverov et al. Experiences with an object-oriented, multi-stage language
Puder Byte code transformations using XSL stylesheets
Pape et al. Extending a Java Virtual Machine to Dynamic Object-oriented Languages
Haggett Tokenisation and Compression of Java Class Files for Mobile Devices

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 11839936

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 11839936

Country of ref document: EP

Kind code of ref document: A1