WO2022156056A1 - 基于程序源码切片重组的软件动态更新热补丁合成方法 - Google Patents

基于程序源码切片重组的软件动态更新热补丁合成方法 Download PDF

Info

Publication number
WO2022156056A1
WO2022156056A1 PCT/CN2021/081558 CN2021081558W WO2022156056A1 WO 2022156056 A1 WO2022156056 A1 WO 2022156056A1 CN 2021081558 W CN2021081558 W CN 2021081558W WO 2022156056 A1 WO2022156056 A1 WO 2022156056A1
Authority
WO
WIPO (PCT)
Prior art keywords
basic components
conversion function
source code
program
statement
Prior art date
Application number
PCT/CN2021/081558
Other languages
English (en)
French (fr)
Inventor
蒋炎岩
赵泽林
许畅
马晓星
Original Assignee
南京大学
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 南京大学 filed Critical 南京大学
Publication of WO2022156056A1 publication Critical patent/WO2022156056A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates
    • G06F8/656Updates while running
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/71Version control; Configuration management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/72Code refactoring
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3692Test management for test results analysis
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • the invention relates to the technical field of software dynamic update, in particular to a software dynamic update hot patch synthesis method and system based on program source code slice reorganization.
  • the object state transition function Before the developer sends an update request, the object state transition function needs to be prepared.
  • the underlying support system uses the object state conversion function to convert some objects to make them compatible with the new version of the program, so that the updated program can continue to execute correctly.
  • the existing technology can only use predefined simple rules to try to combine, and can only deal with conversions between primary types. , constant assignment, etc., cannot cope with the complex updates involved in real software, such as changes in data representation methods and data structures.
  • the present invention provides a method and system for synthesizing hot patches for software dynamic update based on program source code slice reorganization, which can automatically analyze program codes of old and new versions, and extract basic components and data stream slices for constructing conversion functions. And then use them to automatically synthesize object state transition functions to help developers and reduce manual burdens.
  • the present invention adopts the following technical solutions:
  • a software dynamic update hot patch synthesis method based on program source code slice reorganization comprises the following steps:
  • S1 analyze the source code and/or binary code of the new and old versions of the program through the static program, and extract a certain amount of basic components and data stream slices corresponding to the dynamic update;
  • Type information of placeholders, placeholders, and other elements including Java keywords, class names, method names, and operators;
  • the data flow slice refers to a method body that declares or uses the same variable. sequence of program statements;
  • the source of the basic component includes two parts: one is to extract the conditional statements and loop statements included in each line of code in the old and new versions of the program source code as basic components; Access components contained in API methods in third-party libraries;
  • the basic components include four categories: 1) instance range access components, static range access components; 2) instance method access components, static method access components; 3) constructor function components; 4) source code statement components.
  • step S1 the process of extracting a certain amount of basic components corresponding to dynamic updates includes the following steps:
  • S101 analyze the source code information, replace the variables and constants in a line of statements with placeholders, retain the corresponding type information, extract them into source code statement components, and retain the location information in the source code; replace the methods declared in the class, Constructors and value domains are extracted as 1), 2), and 3) class basic components, and the call instances and parameters required in the definition are replaced with placeholders;
  • S102 analyze the bytecode information, extract the methods, constructors, and value ranges declared in the class into 1), 2), and 3) basic components of the class, and replace the calling instances and parameters required in the declaration with placeholders symbol;
  • step S1 the process of extracting a certain amount of data stream slices corresponding to dynamic updates includes the following steps:
  • S111 starting from the last statement in a method body that declares or uses the target type variable, reversely traverses all the statements in the method body: 1) initializes a variable set; 2) when checking a statement, if a certain statement created or used by the statement If a variable exists in the variable set, put all the variables used by the statement into the variable set, and then continue to check the next statement;
  • step S112 the corresponding basic components obtained in step S1 are used to represent the data stream slices obtained by the analysis, and at the same time, the same data stream slices are merged.
  • step S112 the use of the corresponding basic components obtained in step S1 to represent the data stream slice obtained by analysis means: after obtaining a data stream slice, the basic components corresponding to the sentences are stored in order.
  • step S2 the enumeration proposes the combination of the obtained basic components, and the process of automatically generating the corresponding conversion function according to its data flow relationship includes the following steps:
  • step S23 select the conversion function with the highest similarity, if it has generated the variable of the target type, then test and verify it, if the verification passes, output the conversion function, and end the process; otherwise, go to step S24;
  • step S25 place the basic component filled with known variables at the end of the conversion function selected in step S23 to form a new conversion function, and put it into the conversion function set, and go to step S22.
  • step S22 the calculation of the similarity between each conversion function in the conversion function set and the data stream slice refers to:
  • For a transformation function calculate its similarity to each data stream slice, and select the maximum value as the similarity of the transformation function.
  • step S3 the process of running the generated conversion function on the test case, reporting the test report to the developer, and outputting the correct conversion function at the same time includes the following steps:
  • S32 in the test verification phase, compare whether the state of the target type in the object state is equal to the state after the conversion. If they are equal, it is determined that the conversion for the target type is correct. If the conversion function to be tested passes the verification of all test cases , the conversion function to be tested is judged to be correct.
  • the present invention proposes a software dynamic update hot patch synthesis system based on program source code slice reorganization, the synthesis system includes a static program analysis component, a data flow analysis component, a conversion function generation module and a test module;
  • the static program analysis component is used to parse the information of each code line in the source code, replace all variables and constants therein with placeholders, and retain the corresponding type information, so as to obtain all types of basic components from the source code, and then Parse the bytecode information, and obtain other types of basic components except the source code statement components; among them, in the process of obtaining the basic components, the static program analysis component is based on the composition information of the basic components, that is, "placeholder position and type information" + reserved keywords" to exclude the same basic building blocks;
  • the data flow analysis component is used for starting from the last statement in a method body that created or used the target type variable, and reversely traverses all the statements in the inspection method body: 1) initialize a set of related variables; 2) when checking a statement, if A variable created or used by the statement exists in the variable set, then put all the variables used by the statement into the variable set, and continue to check the next statement; after obtaining a data flow slice, the data flow analysis component will The basic components corresponding to the statements are saved in order, and the same data stream slices are excluded;
  • the conversion function generation module is used to enumerate the proposed combination of basic components, and automatically generate a corresponding conversion function according to its data flow relationship, where the conversion function is a conversion operation sequence from a known type to a target type;
  • the test module is used to run the generated conversion function on the test case, report the test report to the developer, and output the correct conversion function at the same time.
  • FIG. 1 is a flow chart of a method for synthesizing a hot patch for software dynamic update based on program source code slice reorganization according to the present invention.
  • FIG. 2 is a schematic diagram of the principle of step 1 in a specific embodiment.
  • FIG. 3 is a flow chart of steps 2 and 3 in a specific embodiment.
  • S1 analyze the source code and/or binary code of the new and old versions of the program through the static program, and extract a certain amount of basic components and data stream slices corresponding to the dynamic update;
  • Type information of placeholders, placeholders, and other elements including Java keywords, class names, method names, and operators;
  • the data flow slice refers to a method body that declares or uses the same variable. sequence of program statements.
  • the present invention mainly includes four steps:
  • Step 1 Analyze the source code and/or binary code of the new and old versions of the program through static programs, and extract a large number of potential basic components and data flow slices for dynamic update;
  • Step 2 Enumerate the combination of basic components, and automatically generate potential conversion functions according to their data flow relationships
  • Step 3 Run the conversion function on the test case, report the test report to the developer, and output the correct conversion function.
  • the basic component is the basic unit that composes the conversion function, which consists of variable placeholders ( ⁇ ), type information of the placeholders and other elements (Java keywords, class names, method names, operators, etc. )composition.
  • ⁇ 1 .M( ⁇ 2 , ⁇ 3 ) represents the basic building block of a method call, which contains three variable placeholders ( ⁇ 1 for C type, ⁇ 2 for integer type, ⁇ 3 for string type ) and A method name (M), where ⁇ 2 and ⁇ 3 are the parameters accepted by the method M.
  • the return value type of method M is boolean, and there are already C type variable V 1 , integer type variable V 2 , and string type variable V 3 , then all three placeholders can be filled.
  • the source of basic components includes two parts: one is that every line of code in the program source code of the old and new versions, including conditional statements and loop statements, can be extracted as basic components; the other is the third-party libraries that the program depends on (including API methods in the JDK standard library).
  • Basic components include the following types:
  • the static program analysis component automatically analyzes the source code and bytecode information of the old and new versions of the program, and obtains basic components therefrom.
  • the variables and constants in a line of statements are replaced with placeholders, while the corresponding type information is retained, extracted as source code statement components, and the location information in the source code is retained.
  • the methods, constructors and value ranges declared in the class are extracted into 1), 2), and 3) basic components of the class, and the call instances and parameters required in the definition are replaced with placeholders.
  • the data flow slice refers to a sequence of several program statements that declare or use the same variable in a method body.
  • the present invention starts from the last statement in a method body that declares or uses a target type variable, and reversely traverses and checks all statements in the method body: 1) initialize a variable set; 2) when checking a statement, if a certain statement created or used by the statement If a variable exists in the variable set, put all the variables used by the statement into the variable set, and continue to check the next statement.
  • the data stream slices obtained by the analysis are represented by the corresponding basic components obtained in the first step, and the same data stream slices are merged at the same time to improve the efficiency of the function synthesis in the second step.
  • FIG. 2 shows the content of step 1.
  • the main function is to analyze the program, extract the basic components, and prepare for the subsequent synthetic transformation function.
  • the input and output of step 1 are shown in Table 1.
  • the source code is the source code for realizing the target program, and the binary code refers to the compiled target program and the dependent tripartite library.
  • the static program analysis component first parses the information of each code line in the source code, replaces all variables and constants with placeholders, and retains the corresponding type information. From the source code, all types of basic building blocks can be obtained.
  • the static program analysis component parses the bytecode information to obtain other types of basic components in addition to the source code statement components. In the process of acquiring basic components, the static program analysis component can exclude the same basic components according to the composition information of basic components, that is, "placeholder location and type information + reserved keywords", reducing the overall number.
  • the data flow analysis component starts from the last statement in a method body that creates or uses the target type variable, and reversely traverses and checks all statements in the method body, specifically: 1) Initialize a set of related variables; 2) When checking a statement, if the A variable created or used by a statement exists in the variable collection, put all variables used by the statement into the variable collection, and continue checking the next statement. After the data flow analysis component obtains a data flow slice, it will save the basic components corresponding to the statements in order, and exclude the same data flow slice to reduce the overall number.
  • the synthetic conversion function refers to finding a conversion operation sequence from a known type to a target type by using the basic components and data stream slices in step 1: 1) Initially, the old version target type is regarded as Knowing the type, initialize an empty transformation function set; 2) Calculate the similarity to the data stream slice for each transformation function in the transformation function set, and sort; 3) Choose the best transformation function, if it has generated the target Type variables, you need to test and verify them, otherwise, starting from its known type, select all available basic components, that is, each variable placeholder in the basic component can be filled with known variables; 4) Fill in the The full basic components are placed at the end of the conversion function in 3) to form a new conversion function, and put into the conversion function set, returning to 2).
  • the test verification refers to using the test case provided by the developer to detect whether the state of the target type obtained through conversion conforms to the correctness of the object state conversion in the scenario of software dynamic update.
  • the present invention runs the test case on the program of the new version first, and obtains the object state of the new version at the point set by the developer.
  • the state of the target type in the object state is compared for equality with the transformed state. If they are equal, the conversion for the target type is correct. If the conversion function to be tested passes the verification of all test cases, the conversion function is correct.
  • Figure 3 shows the content of steps 2 and 3.
  • the main function is to generate a conversion function for a target type, and use test cases to verify the correct conversion function.
  • Table 2 shows the input and output of steps two and three. Due to the complexity of the two steps, the specific implementation is divided into four parts.
  • a primitive is currently available if it contains no placeholders (such as a static range access construct), or if all placeholders can be filled with variables that already exist and have matching types.
  • Existing variables include an object instance (O) of the target type of the old version and variables already generated in the current conversion function.
  • O object instance
  • an empty conversion function is initialized, and the existing variable is only O.
  • the procedural composition component first creates a copy of the current transformation function, and then places the populated available component at the end of the transformation function copy, thereby creating a new transformation function.
  • Each new transformation function is put into a collection.
  • the new conversion function created each time essentially only contains a filled basic component.
  • step 2 all the generated conversion functions need to be sorted, so as to select the optimal one and enter the next round of generation.
  • Both transformation functions and data stream slices are composed of basic building blocks, so the similarity between them can be calculated. For a transformation function, calculate its similarity to each data stream slice, and choose the maximum value as its similarity. The conversion function with the highest similarity is passed to the next cycle.
  • a conversion function needs to be validated if it has produced a variable that matches the target type.
  • the verification standard is whether the target type variable conforms to the correctness of the state after conversion. If it does not need to be verified, proceed to the "Select Available Components" step, otherwise verify.
  • the developer needs to prepare a test set that contains test cases that can fully test the different object states of the target class.
  • the present invention will run the test case on the new version of the program, and use the object serialization technology to write the object state of the target class into the file at the time specified by the developer.
  • the present invention runs a test case on the program of the old version first, and then calls the conversion function at the moment specified by the developer. Since the current conversion function is for the target type, you can obtain a converted target type status after running, and then compare the status with the target type status in the corresponding serialization file. If the two states are different, the verification is not passed, and jump to the "Select Available Components" step. If the two states are the same, the transition function passes validation on this test case. If the conversion function verifies on all test cases, the correct conversion function for the target type is found.

Abstract

本发明公开了一种基于程序源码切片重组的软件动态更新热补丁合成方法,包括:通过静态程序分析新、旧版本程序的源码和/或二进制代码,提取一定量动态更新相关的基本构件和数据流切片;枚举提出得到的基本构件的组合,并根据其数据流关系自动生成对应的转换函数;在测试用例上运行生成的转换函数,输出正确的转换函数。本发明能够自动分析新旧版本程序代码,提取出构造转换函数的基本构件和数据流切片,进而利用他们自动合成对象状态转换函数,帮助开发者,大幅减轻人工负担。

Description

基于程序源码切片重组的软件动态更新热补丁合成方法 技术领域
本发明涉及软件动态更新技术领域,具体而言涉及一种基于程序源码切片重组的软件动态更新热补丁合成方法和系统。
背景技术
相比于离线更新的先停机再重启的更新策略,软件动态更新的核心思想是在旧版本程序运行时刻,对其进行版本更新。软件动态更新的特点包括:
1)动态地监测更新请求,并在收到请求后,短暂暂停旧版本程序的运行;
2)在更新时刻,对已加载进内存的代码替换为新版本,同时利用对象状态转换函数,转换内存中已创建的与新版本程序不兼容的对象状态。
在开发者发出更新请求前,需要准备好对象状态转换函数。而底层的支撑系统,则利用该对象状态转换函数,对部分对象进行转换,使其与新版本程序兼容,进而使得更新后的程序能够正确的继续执行。在代码涉及的数据结构发生变化时,目前仍缺少一种可靠的生成对象状态转换函数的方法,是因为现有技术仅能利用预定义的简单规则进行尝试组合,只能处理如初级类型间转换、常量赋值等,无法应对现实的软件涉及的复杂更新,如数据表示方法、数据结构的改变。
发明内容
本发明针对现有技术中的不足,提供一种基于程序源码切片重组的软件动态更新热补丁合成方法和系统,能够自动分析新旧版本程序代码,提取出构造转换函数的基本构件和数据流切片,进而利用它们自动合成对象状态转换函数,帮助开发者,答复减轻人工负担。
为实现上述目的,本发明采用以下技术方案:
一种基于程序源码切片重组的软件动态更新热补丁合成方法,所述合成方法包括以下步骤:
S1,通过静态程序分析新、旧版本程序的源码和/或二进制代码,提取一定量动态更新对应的基本构件和数据流切片;所述基本构件是组成对象状态转换函数的基本单位,由变量占位符、占位符的类型信息,以及包括Java关键字、类名、方法名和操作符在内的其他元素组成;所述数据流切片是指在一个方法体内,声明或使用了相同变量的若干程序语句序列;
S2,枚举提出得到的基本构件的组合,并根据其数据流关系自动生成对应的转换函数,所述转换函数为从已知类型到目标类型的转换操作序列;
S3,在测试用例上运行生成的转换函数,将测试报告报告给开发者,同时输出正确的转换函数。
为优化上述技术方案,采取的具体措施还包括:
进一步地,步骤S1中,所述基本构件的来源包括两个部分:一是将新旧两个版本程序源码中的每一行代码包括的条件语句和循环语句抽取为基本构件;二是对应程序所依赖的第三 方库中的API方法所包含的访问构件;
所述基本构件包含4种类别:1)实例值域访问构件、静态值域访问构件;2)实例方法访问构件、静态方法访问构件;3)构造函数构件;4)源码语句构件。
进一步地,步骤S1中,提取一定量动态更新对应的基本构件的过程包括以下步骤:
S101,分析源码信息,将一行语句中的变量和常量都替换为占位符,同时保留对应的类型信息,抽取为源码语句构件,并且保留在源码中的位置信息;将类中声明的方法、构造函数和值域,抽取为1)、2)、3)类基本构件,将定义中所需的调用实例和参数都替换为占位符;
S102,分析字节码信息,将类中声明的方法、构造函数和值域,抽取为1)、2)、3)类基本构件,将声明中所需的调用实例和参数都替换为占位符;
S103,对于相同构件进行合并,提取得到最终的动态更新对应的基本构件。
进一步地,步骤S1中,提取一定量动态更新对应的数据流切片的过程包括以下步骤:
S111,从一个方法体中最后一条声明或使用了目标类型变量的语句出发,逆向遍历检查方法体内所有语句:1)初始化一个变量集合;2)检查一条语句时,如果该语句创建或使用的某个变量存在于变量集合中,则把该语句使用的所有变量放入变量集合,再继续检查下一条语句;
S112,采用步骤S1中获得的对应基本构件表示分析所得的数据流切片,同时对相同数据流切片进行合并。
进一步地,步骤S112中,所述采用步骤S1中获得的对应基本构件表示分析所得的数据流切片是指:在得到一个数据流切片后,将其中语句对应的基本构件按照顺序保存下来。
进一步地,步骤S2中,所述枚举提出得到的基本构件的组合,并根据其数据流关系自动生成对应的转换函数的过程包括以下步骤:
S21,初始时,将旧版本目标类型视为已知类型,初始化空的转换函数集合;
S22,对转换函数集合中的每个转换函数计算与数据流切片的相似度,并排序;
S23,选择相似度最高的转换函数,如果它已经生成了目标类型的变量,则对其进行测试验证,如果验证通过,输出转换函数,结束流程;否则进入步骤S24;
S24,从它的已知类型出发,选出所有可用的基本构件,可用的基本构件是指基本构件中的每个变量占位符均与某个已知变量类型匹配;
S25,将使用已知变量填满后的基本构件放在步骤S23中选择的转换函数尾部,组成新的转换函数,并放入转换函数集合,转入步骤S22。
进一步地,步骤S22中,所述对转换函数集合中的每个转换函数计算与数据流切片的相似度是指:
对于一个转换函数,计算它与每个数据流切片的相似度,选择最大值作为该转换函数的相似度。
进一步地,步骤S3中,所述在测试用例上运行生成的转换函数,将测试报告报告给开发者,同时输出正确的转换函数的过程包括以下步骤:
S31,在新版本程序上运行测试用例,并在开发者设置的更新点处获取新版本的对象状态;
S32,在测试验证阶段比较该对象状态中目标类型的状态是否与转换后的状态相等,如果相等,判定针对该目标类型的这次转换是正确的,如果待测转换函数通过所有测试用例的验证,则判断待测转换函数是正确的。
基于前述方法,本发明提出一种基于程序源码切片重组的软件动态更新热补丁合成系统,所述合成系统包括静态程序分析组件、数据流分析组件、转换函数生成模块和测试模块;
所述静态程序分析组件用于解析源码中每个代码行的信息,将其中的所有变量和常量替换为占位符,同时保留对应的类型信息,以从源码中获取所有类型的基本构件,再解析字节码信息,从中获取除源码语句构件之外的其他类型基本构件;其中,在获取基本构件的过程中,静态程序分析组件根据基本构件的组成信息,即“占位符位置和类型信息+保留的关键字”来排除相同的基本构件;
所述数据流分析组件用于从一个方法体中最后一条创建或使用了目标类型变量的语句出发,逆向遍历检查方法体内所有语句:1)初始化一个相关变量集合;2)检查一条语句时,如果该语句创建或使用的某个变量存在于变量集合中,则把该语句使用的所有变量放入变量集合,并继续检查下一条语句;其中,数据流分析组件在得到一个数据流切片后,将其中语句对应的基本构件按照顺序保存下来,同时排除相同的数据流切片;
所述转换函数生成模块用于枚举提出得到的基本构件的组合,并根据其数据流关系自动生成对应的转换函数,所述转换函数为从已知类型到目标类型的转换操作序列;
所述测试模块用于在测试用例上运行生成的转换函数,将测试报告报告给开发者,同时输出正确的转换函数。
本发明的有益效果是:
1)能够定义软件动态更新场景下的对象状态转换的“正确性”,即生成的对象状态转换函数应该符合的标准。
2)能够自动分析新旧版本程序代码,提取出构造转换函数的基本构件和数据流切片,进而利用它们自动合成对象状态转换函数,帮助开发者,答复减轻人工负担;
3)能够自动运行测试用例来验证生成的对象状态转换函数是否正确,帮助开发者快速发现正确的目标。
附图说明
图1是本发明的基于程序源码切片重组的软件动态更新热补丁合成方法的流程图。
图2是具体实施例中步骤一的原理示意图。
图3是具体实施例中步骤二和三的流程图。
具体实施方式
现在结合附图对本发明作进一步详细的说明。
需要注意的是,发明中所引用的如“上”、“下”、“左”、“右”、“前”、“后”等的用语,亦仅为便于叙述的明了,而非用以限定本发明可实施的范围,其相对关系的改变或调整,在 无实质变更技术内容下,当亦视为本发明可实施的范畴。
结合图1,本发明提及一种基于程序源码切片重组的软件动态更新热补丁合成方法,所述合成方法包括以下步骤:
S1,通过静态程序分析新、旧版本程序的源码和/或二进制代码,提取一定量动态更新对应的基本构件和数据流切片;所述基本构件是组成对象状态转换函数的基本单位,由变量占位符、占位符的类型信息,以及包括Java关键字、类名、方法名和操作符在内的其他元素组成;所述数据流切片是指在一个方法体内,声明或使用了相同变量的若干程序语句序列。
S2,枚举提出得到的基本构件的组合,并根据其数据流关系自动生成对应的转换函数,所述转换函数为从已知类型到目标类型的转换操作序列。
S3,在测试用例上运行生成的转换函数,将测试报告报告给开发者,同时输出正确的转换函数。
本发明主要包含四个步骤:
步骤一、通过静态程序分析新、旧版本程序的源码和(或)二进制代码,提取大量的动态更新潜在的基本构件和数据流切片;
步骤二、枚举基本构件的组合,并根据其数据流关系自动生成潜在的转换函数;
步骤三,在测试用例上运行转换函数,并把测试报告报告给开发者,同时输出正确的转换函数。
所述的步骤一中,基本构件是组成转换函数的基本单位,是由变量占位符(□)、占位符的类型信息和其他元素(Java关键字、类名、方法名、操作符等)组成。例如,□ 1.M(□ 2,□ 3)表示一个方法调用的基本构件,其包含三个变量占位符(C类型的□ 1,整数类型的□ 2,字符串类型的□ 3)和一个方法名(M),其中□ 2,□ 3是方法M接受的参数。假设方法M的返回值类型是布尔类型(boolean),且已存在C类型变量V 1,整数类型变量V 2,和字符串类型变量V 3,那么三个占位符都可以被填充。而填充后的基本构件可以生成一个新的布尔类型变量V 4:boolean V 4=V 1.M(V 2,V 3)。
基本构件的来源包括两个部分:一是新旧两个版本程序源码中的每一行代码,包括了条件语句和循环语句,都可以抽取为基本构件;二是该程序所依赖的第三方库(包括JDK标准库)中的API方法。基本构件包含如下类型:
1)实例值域访问构件、静态值域访问构件;
2)实例方法访问构件、静态方法访问构件;
3)构造函数构件;
4)源码语句构件。
所述步骤一中,静态程序分析组件,自动分析新旧版本程序的源码和字节码信息,从中获取基本构件。在分析源码信息时,把一行语句中的变量和常量都替换为占位符,同时保留对应的类型信息,抽取为源码语句构件,并且保留在源码中的位置信息。同时把类中声明的方法、构造函数和值域,抽取为1)、2)、3)类基本构件,把定义中所需的调用实例和参数都替换为占位符。在分析字节码信息时,只把类中声明的方法、构造函数和值域,抽取为1)、 2)、3)类基本构件,把声明中所需的调用实例和参数都替换为占位符。在抽取基本构件后,对于相同构件进行合并,提高步骤三中函数合成的效率。
所述步骤一中,数据流切片是指在一个方法体内,声明或使用了相同变量的若干程序语句序列。本发明从一个方法体中最后一条声明或使用了目标类型变量的语句出发,逆向遍历检查方法体内所有语句:1)初始化一个变量集合;2)检查一条语句时,如果该语句创建或使用的某个变量存在于变量集合中,则把该语句使用的所有变量放入变量集合,并继续检查下一条语句。分析所得的数据流切片用步骤一中获得的对应基本构件进行表示,同时对相同数据流切片进行合并,提高步骤二函数合成的效率。
图2所示为步骤一内容,主要功能是分析程序,抽取基本构件,为后续合成转换函数做准备。步骤一的输入和输出为如表1所示,源码是实现目标程序的源码,而二进制代码则指编译后的目标程序和依赖的三方库。静态程序分析组件首先解析源码中每个代码行的信息,把其中的所有变量和常量替换为占位符,同时保留对应的类型信息。从源码中,可以获取所有类型的基本构件。静态程序分析组件接着解析字节码信息,从中获取除源码语句构件之外的其他类型基本构件。在获取基本构件的过程中,静态程序分析组件可以根据基本构件的组成信息,即“占位符位置和类型信息+保留的关键字”来排除相同的基本构件,减少总体数量。
表1步骤一的输入输出
Figure PCTCN2021081558-appb-000001
数据流分析组件从一个方法体中最后一条创建或使用了目标类型变量的语句出发,逆向遍历检查方法体内所有语句,具体为:1)初始化一个相关变量集合;2)检查一条语句时,如果该语句创建或使用的某个变量存在于变量集合中,则把该语句使用的所有变量放入变量集合,并继续检查下一条语句。数据流分析组件在得到一个数据流切片后,会把其中语句对应的基本构件按照顺序保存下来,同时排除相同的数据流切片,减少总体数量。
所述步骤二中,合成转换函数是指,利用步骤一中的基本构件和数据流切片,找到一个从已知类型到目标类型的转换操作序列:1)初始时,把旧版本目标类型视为已知类型,初始化空的转换函数集合;2)对转换函数集合中的每个转换函数计算与数据流切片的相似度,并排序;3)选择最好的转换函数,如果它已经生成了目标类型的变量,则需要对其测试验证,否则从它的已知类型出发,选出所有可用的基本构件,即基本构件中的每个变量占位符可被已知变量填充;4)把填满后的基本构件放在3)中的转换函数尾部,组成新的转换函数,并放入转换函数集合,回到2)。
所述步骤三中,测试验证是指利用开发者提供的测试用例,检测经过转换获得的目标类型的状态是否符合软件动态更新场景下的对象状态转换的正确性。本发明先在新版本程序上运行测试用例,并在开发者设置的点处获取新版本的对象状态。在测试验证阶段比较该对象状态中目标类型的状态是否与转换后的状态相等。如果相等,则说明针对该目标类型的这次转换是正确的。如果待测转换函数通过所有测试用例的验证,则说明该转换函数是正确的。
图3所示为步骤二和三内容,主要功能是为一个目标类型生成转换函数,同时利用测试用例验证判断正确的转换函数。表2所示为步骤二、三的输入输出。由于两个步骤的复杂性,具体实施内容分为4个部分阐述。
a)选择可用构件
对于一个基本构件,如果其不包含占位符(如静态值域访问构件),或者所有占位符可以被已存在且类型匹配的变量填充,则该基本构件是当前可用的。已存在的变量包括了旧版本目标类型的一个对象实例(O)和当前转换函数中已生成的变量。在初次进入步骤三时,初始化一个空的转换函数,已存在的变量只有O。在选择可用构件时,遍历每个基本构件,找出当前可用的并放入可用构件集合。
表2步骤二、三的输入输出
Figure PCTCN2021081558-appb-000002
b)生成新的转换函数
对于一个可用构件,程序合成组件首先创建一个当前转换函数的副本,然后把填充好的可用构件放在转换函数副本的尾部,从而创建了一个新的转换函数。每个新的转换函数都被放入到一个集合中。在初次进入步骤三时,由于当前转换函数为空,每次创建的新转换函数本质上只包含了一个被填充的基本构件。
c)选择最优转换函数
步骤二需要对已生成的所有转换函数进行排序,从而选择最优的一个,进入下一轮的生成。转换函数和数据流切片都是由基本构件组成,因此可以计算它们间的相似度。对于一个转换函数,计算它与每个数据流切片的相似度,然后选择最大值当做它的相似度。相似度最大的转换函数,传入下一轮循环。
d)验证转换函数
在选择了最优转换函数后,需要判断是否对其进行验证,以及判断是否通过验证。对于一个转换函数,如果它已生成的某个变量与目标类型一致,则需要对其进行验证。验证的标准是该目标类型变量在转换后是否符合状态一致的正确性。如果不需要对其验证,则进入“选择可用构件”步骤,否则进行验证。
为了验证转换函数,开发者需要准备一个测试集合,其包含的测试用例能够完备地测试目标类的不同对象状态。在测试转换函数前,本发明会在新版本程序上运行测试用例,在开发者指定的时刻利用对象序列化技术,把目标类的对象状态写入文件。
在测试一个转换函数时,本发明先在旧版本程序上运行一个测试用例,然后在开发者指定的时刻调用该转换函数。由于当前转换函数是针对目标类型的,运行后可以获取一个转换后的目标类型状态,然后对比该状态和对应的序列化文件中的目标类型状态。如果两个状态不同,则没有通过验证,跳转到“选择可用构件”步骤。如果两个状态相同,则该转换函数 在此测试用例上通过验证。如果该转换函数在所有测试用例上都能通过验证,则发现目标类型的正确转换函数。
以上仅是本发明的优选实施方式,本发明的保护范围并不仅局限于上述实施例,凡属于本发明思路下的技术方案均属于本发明的保护范围。应当指出,对于本技术领域的普通技术人员来说,在不脱离本发明原理前提下的若干改进和润饰,应视为本发明的保护范围。

Claims (9)

  1. 一种基于程序源码切片重组的软件动态更新热补丁合成方法,其特征在于,所述合成方法包括以下步骤:
    S1,通过静态程序分析新、旧版本程序的源码和/或二进制代码,提取一定量动态更新对应的基本构件和数据流切片;所述基本构件是组成对象状态转换函数的基本单位,由变量占位符、占位符的类型信息,以及包括Java关键字、类名、方法名和操作符在内的其他元素组成;所述数据流切片是指在一个方法体内,声明或使用了相同变量的若干程序语句序列;
    S2,枚举提出得到的基本构件的组合,并根据其数据流关系自动生成对应的转换函数,所述转换函数为从已知类型到目标类型的转换操作序列;
    S3,在测试用例上运行生成的转换函数,将测试报告报告给开发者,同时输出正确的转换函数。
  2. 根据权利要求1所述的基于程序源码切片重组的软件动态更新热补丁合成方法,其特征在于,步骤S1中,所述基本构件的来源包括两个部分:一是将新旧两个版本程序源码中的每一行代码包括的条件语句和循环语句抽取为基本构件;二是对应程序所依赖的第三方库中的API方法所包含的访问构件;
    所述基本构件包含4种类别:1)实例值域访问构件、静态值域访问构件;2)实例方法访问构件、静态方法访问构件;3)构造函数构件;4)源码语句构件。
  3. 根据权利要求2所述的基于程序源码切片重组的软件动态更新热补丁合成方法,其特征在于,步骤S1中,提取一定量动态更新对应的基本构件的过程包括以下步骤:
    S101,分析源码信息,将一行语句中的变量和常量都替换为占位符,同时保留对应的类型信息,抽取为源码语句构件,并且保留在源码中的位置信息;将类中声明的方法、构造函数和值域,抽取为1)、2)、3)类基本构件,将定义中所需的调用实例和参数都替换为占位符;
    S102,分析字节码信息,将类中声明的方法、构造函数和值域,抽取为1)、2)、3)类基本构件,将声明中所需的调用实例和参数都替换为占位符;
    S103,对于相同构件进行合并,提取得到最终的动态更新对应的基本构件。
  4. 根据权利要求1所述的基于程序源码切片重组的软件动态更新热补丁合成方法,其特征在于,步骤S1中,提取一定量动态更新对应的数据流切片的过程包括以下步骤:
    S111,从一个方法体中最后一条声明或使用了目标类型变量的语句出发,逆向遍历检查方法体内所有语句:1)初始化一个变量集合;2)检查一条语句时,如果该语句创建或使用的某个变量存在于变量集合中,则把该语句使用的所有变量放入变量集合,再继续检查下一条语句;
    S112,采用步骤S1中获得的对应基本构件表示分析所得的数据流切片,同时对相同数据流切片进行合并。
  5. 根据权利要求1所述的基于程序源码切片重组的软件动态更新热补丁合成方法,其特征在于,步骤S112中,所述采用步骤S1中获得的对应基本构件表示分析所得的数据流切片是指:在得到一个数据流切片后,将其中语句对应的基本构件按照顺序保存下来。
  6. 根据权利要求1所述的基于程序源码切片重组的软件动态更新热补丁合成方法,其特征在于,步骤S2中,所述枚举提出得到的基本构件的组合,并根据其数据流关系自动生成对应的转换函数的过程包括以下步骤:
    S21,初始时,将旧版本目标类型视为已知类型,初始化空的转换函数集合;
    S22,对转换函数集合中的每个转换函数计算与数据流切片的相似度,并排序;
    S23,选择相似度最高的转换函数,如果它已经生成了目标类型的变量,则对其进行测试验证,如果验证通过,输出转换函数,结束流程;否则进入步骤S24;
    S24,从它的已知类型出发,选出所有可用的基本构件,可用的基本构件是指基本构件中的每个变量占位符均与某个已知变量类型匹配;
    S25,将使用已知变量填满后的基本构件放在步骤S23中选择的转换函数尾部,组成新的转换函数,并放入转换函数集合,转入步骤S22。
  7. 根据权利要求6所述的基于程序源码切片重组的软件动态更新热补丁合成方法,其特征在于,步骤S22中,所述对转换函数集合中的每个转换函数计算与数据流切片的相似度是指:
    对于一个转换函数,计算它与每个数据流切片的相似度,选择最大值作为该转换函数的相似度。
  8. 根据权利要求1所述的基于程序源码切片重组的软件动态更新热补丁合成方法,其特征在于,步骤S3中,所述在测试用例上运行生成的转换函数,将测试报告报告给开发者,同时输出正确的转换函数的过程包括以下步骤:
    S31,在新版本程序上运行测试用例,并在开发者设置的更新点处获取新版本的对象状态;
    S32,在测试验证阶段比较该对象状态中目标类型的状态是否与转换后的状态相等,如果相等,判定针对该目标类型的这次转换是正确的,如果待测转换函数通过所有测试用例的验证,则判断待测转换函数是正确的。
  9. 一种基于权利要求1-8任意一项中所述方法的基于程序源码切片重组的软件动态更新热补丁合成系统,其特征在于,所述合成系统包括静态程序分析组件、数据流分析组件、转换函数生成模块和测试模块;
    所述静态程序分析组件用于解析源码中每个代码行的信息,将其中的所有变量和常量替换为占位符,同时保留对应的类型信息,以从源码中获取所有类型的基本构件,再解析字节码信息,从中获取除源码语句构件之外的其他类型基本构件;其中,在获取基本构件的过程中,静态程序分析组件根据基本构件的组成信息,即“占位符位置和类型信息+保留的关键字”来排除相同的基本构件;
    所述数据流分析组件用于从一个方法体中最后一条创建或使用了目标类型变量的语句出发,逆向遍历检查方法体内所有语句:1)初始化一个相关变量集合;2)检查一条语句时,如果该语句创建或使用的某个变量存在于变量集合中,则把该语句使用的所有变量放入变量集合,并继续检查下一条语句;其中,数据流分析组件在得到一个数据流切片后,将其中语句对应的基本构件按照顺序保存下来,同时排除相同的数据流切片;
    所述转换函数生成模块用于枚举提出得到的基本构件的组合,并根据其数据流关系自动生成对应的转换函数,所述转换函数为从已知类型到目标类型的转换操作序列;
    所述测试模块用于在测试用例上运行生成的转换函数,将测试报告报告给开发者,同时输出正确的转换函数。
PCT/CN2021/081558 2021-01-19 2021-03-18 基于程序源码切片重组的软件动态更新热补丁合成方法 WO2022156056A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202110073391.XA CN112764788B (zh) 2021-01-19 2021-01-19 基于程序源码切片重组的软件动态更新热补丁合成方法
CN202110073391.X 2021-01-19

Publications (1)

Publication Number Publication Date
WO2022156056A1 true WO2022156056A1 (zh) 2022-07-28

Family

ID=75703404

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/081558 WO2022156056A1 (zh) 2021-01-19 2021-03-18 基于程序源码切片重组的软件动态更新热补丁合成方法

Country Status (3)

Country Link
CN (1) CN112764788B (zh)
LU (1) LU500618B1 (zh)
WO (1) WO2022156056A1 (zh)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060010435A1 (en) * 2001-10-31 2006-01-12 Microsoft Corporation Dynamic software update
CN101162428A (zh) * 2007-11-22 2008-04-16 上海交通大学 软件动态演化中构件运行时状态的获取和转换方法
CN105528231A (zh) * 2016-01-21 2016-04-27 华中科技大学 一种基于中间辅助函数的软件动态升级方法及系统
EP3029568A1 (en) * 2014-12-05 2016-06-08 Sap Se Remote update of software components
CN111045670A (zh) * 2019-12-13 2020-04-21 中国科学院信息工程研究所 一种二进制代码与源代码间复用关系的识别方法与装置

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7657855B1 (en) * 2007-05-25 2010-02-02 Xilinx, Inc. Efficient timing graph update for dynamic netlist changes
CN104572445B (zh) * 2014-12-17 2017-10-27 南京大学 用于检测Web服务组合中BPEL流程数据竞争的方法
CN106991183B (zh) * 2017-03-27 2019-09-06 福建数林信息科技有限公司 一种商业智能etl的封装方法及系统
CN107358347A (zh) * 2017-07-05 2017-11-17 西安电子科技大学 基于工业大数据的装备集群健康状态评估方法
CN111506493A (zh) * 2019-12-31 2020-08-07 中国石油大学(华东) 一种基于程序切片的缺陷自动修复的修复位置确定方法

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060010435A1 (en) * 2001-10-31 2006-01-12 Microsoft Corporation Dynamic software update
CN101162428A (zh) * 2007-11-22 2008-04-16 上海交通大学 软件动态演化中构件运行时状态的获取和转换方法
EP3029568A1 (en) * 2014-12-05 2016-06-08 Sap Se Remote update of software components
CN105528231A (zh) * 2016-01-21 2016-04-27 华中科技大学 一种基于中间辅助函数的软件动态升级方法及系统
CN111045670A (zh) * 2019-12-13 2020-04-21 中国科学院信息工程研究所 一种二进制代码与源代码间复用关系的识别方法与装置

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
XIE GUOZHEN: "An Assertion-based Software Dynamic Update Technique", MASTER THESIS, TIANJIN POLYTECHNIC UNIVERSITY, CN, no. 8, 15 August 2016 (2016-08-15), CN , XP055952921, ISSN: 1674-0246 *

Also Published As

Publication number Publication date
LU500618B1 (en) 2022-03-03
CN112764788B (zh) 2023-06-16
CN112764788A (zh) 2021-05-07

Similar Documents

Publication Publication Date Title
Deng et al. Bogor/kiasan: A k-bounded symbolic execution for checking strong heap properties of open systems
Claessen et al. QuickCheck: a lightweight tool for random testing of Haskell programs
US7243090B2 (en) System and method for specification tracking in a Java compatibility testing environment
Dennis et al. Modular verification of code with SAT
Leitner et al. Reconciling manual and automated testing: The autotest experience
US7895575B2 (en) Apparatus and method for generating test driver
Madhavan et al. Contract-based resource verification for higher-order functions with memoization
CN110633200A (zh) 用于测试智能合约的方法和设备
US5355479A (en) Interface conformance verification system
CN116341428B (zh) 构建参考模型的方法、芯片验证方法及系统
CN113626324A (zh) 一种面向Move语言虚拟机的模糊测试方法
Celik et al. iCoq: Regression proof selection for large-scale verification projects
Derrick et al. Z2SAL: a translation-based model checker for Z
Cañizares et al. New ideas: automated engineering of metamorphic testing environments for domain-specific languages
US20180217922A1 (en) Application testing
Khurshid Generating structurally complex tests from declarative constraints
WO2022156056A1 (zh) 基于程序源码切片重组的软件动态更新热补丁合成方法
Iqbal et al. Exhaustive simulation and test generation using fuml activity diagrams
Li et al. Dynamic symbolic execution for polymorphism
Smith et al. Proving temporal properties of Z specifications using abstraction
CN115098355A (zh) 基于历史数据驱动的jvm测试程序生成方法
Mesnard et al. Towards a framework for algorithm recognition in binary code
Beckert et al. Regression verification for Java using a secure information flow calculus
CN113434430A (zh) 一种sql查询语句性能检测方法和装置
CN113282495A (zh) 一种基于轨迹监控的Java软件故障定位方法

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: 21920445

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: 21920445

Country of ref document: EP

Kind code of ref document: A1