A synchronous load reduction method for Android activity management service based on escape analysis

Through the escape analysis method, static analysis and synchronous lock optimization of AMS source code in the Android system, the load problem caused by application of AMS services in different application activities is solved, and the system performance is improved.

CN115437929BActive Publication Date: 2025-02-11BEIHANG UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211032356.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-26
Publication Date
2025-02-11
Estimated Expiration
2042-08-26

AI Technical Summary

Technical Problem

In Android system, different application activities apply for Activity Management Services (AMS) will cause a large load and affect system performance.

Method used

Using the method based on escape analysis, the AMS source code is statically analyzed, object access information is extracted, equivalent classes are divided, and synchronization locks are reassigned, so that different equivalent classes use different synchronization locks, thereby optimizing the execution of synchronization blocks.

Benefits of technology

By optimizing the synchronization lock, synchronous blocks that could not be parallel can be executed in parallel, significantly improving the execution efficiency of the system. Experimental data shows that the running time during the startup stage of the Android system can be increased by more than 10%.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115437929B_ABST
    Figure CN115437929B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for reducing the synchronization load of an Android activity management service based on escape analysis, and belongs to the technical field of Android systems. The present invention comprises: performing a static analysis based on escape analysis on an AMS source code, extracting object access information in the code; dividing the synchronization blocks into equivalence classes according to the object access information and the synchronization locks of each synchronization block; dividing the synchronization blocks with intersections of access objects into the same equivalence class, and the access object sets of synchronization blocks of different equivalence classes do not intersect each other; according to the equivalence class division result, reallocating the synchronization locks of the synchronization blocks in the code, so that different equivalence classes use different synchronization locks, and then outputting the optimized AMS code. The present invention optimizes the synchronization locks, so that synchronization blocks that were originally not parallel can be executed in parallel, thereby significantly improving the execution efficiency of the system, and can be completed in the static analysis stage of the program before the system is deployed, without increasing the load of the system during operation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of Android systems, and in particular, relates to an Android activity management service synchronous load reduction method based on escape analysis. Background Art

[0002] AMS (Activity Manager Service) is one of the core services in Android. It is responsible for starting, switching, and scheduling the four major components (Activity, Service, Broadcast Receiver, and ContentProvider) in the system, as well as managing and scheduling application processes. Its responsibilities are similar to the process management and scheduling modules in the operating system, so it plays a very important role in the Android system. When applying for AMS services, different application activities need to "lock / unlock" key resources, which will generate a large load during system operation.

[0003] Escape Analysis is a control flow insensitive cross-function program static analysis method. In the escape analysis algorithm, escape is defined as follows: when a variable or object is allocated in a method, the pointer or reference of the variable is returned or globally referenced. In this case, the variable or object can be referenced by objects in other methods or threads. This phenomenon is called pointer escape. The escape analysis method is based on pointer references. It is a cross-function global data flow analysis method. Its direct purpose is to analyze the life cycle information of variables or objects. Summary of the invention

[0004] Aiming at the problem that a large load will be generated when different application activities apply for AMS services in an Android system, the present invention provides an Android activity management service synchronization load reduction method based on escape analysis.

[0005] The method for reducing synchronous load of an Android activity management service based on escape analysis provided by the present invention comprises the following steps:

[0006] Step 1: Perform static analysis based on escape analysis on the AMS source code to be optimized, extract object access information in the code, and determine all objects that need to be synchronized in the code range of each synchronization block;

[0007] Step 2, according to the object access information and the synchronization lock of each synchronization block, the synchronization blocks are divided into equivalence classes; the synchronization blocks with overlapping access objects are divided into the same equivalence class, and the access object sets of synchronization blocks in different equivalence classes are disjoint;

[0008] Step 3: According to the equivalence class division result, the synchronization locks of the synchronization blocks in the code are reallocated so that different equivalence classes use different synchronization locks, and then the optimized AMS code is output.

[0009] In the step 1, the synchronization block is abstractly represented as a six-tuple of information, including: an identifier that uniquely identifies the synchronization block, a synchronization lock, a local variable set, a global variable set, a local function set, and a global function set. Among them, the local variable set includes local variables directly accessed in the synchronization block code, including local variables defined inside the synchronization block, local variables of the function where the synchronization block is located, and function parameter variables read and written in the synchronization block; the global variable set includes member variables of the class where the synchronization block is located accessed in the synchronization block code and static member variables of other static classes; the local function set includes member functions of the class where the synchronization block is located accessed in the synchronization block code and other class member functions within the scope of static analysis; the global function set includes static member functions of static classes accessed in the synchronization block code, other class member functions and library functions beyond the scope of static analysis.

[0010] In the step 1, the access object set of the synchronization block is determined, and the objects that need to be synchronized in the code range of the synchronization block are recorded in the set, including: first, the AMS source code is statically analyzed to obtain a tuple representation of each synchronization block and member function; wherein the member function is represented as a seven-tuple information, including: a function identifier, a function name, a function parameter set, a local variable set, a global variable set, a local function set, and a global function set; then, for each synchronization block, local variables and global variables that do not need to be synchronized are removed, and according to the access object set of the synchronization block and the function call relationship, the access object set of the member function is merged into the synchronization block, and finally the access object set of the synchronization block is determined.

[0011] The advantages and positive effects of the present invention are: 1) The method of the present invention optimizes the synchronization lock so that the synchronization blocks that were originally not parallel can be executed in parallel, thereby significantly improving the execution efficiency of the system. Preliminary experimental data show that through the optimization of the synchronization lock, the running time of the Android system startup phase can be increased by more than 10%. 2) The method of the present invention can be completed in the static analysis phase of the program before system deployment, without increasing the load on the system during operation. 3) The method of the present invention follows the conservative optimization principle of "ensuring correctness", and the semantics of the optimized code are consistent with those before optimization. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] Figure 1 The present invention discloses an Android AMS activity management service module synchronization load optimization method based on escape analysis;

[0013] Figure 2It is a schematic diagram of the final calculation result of the synchronized block object access set in an embodiment of the present invention;

[0014] Figure 3 Schematic diagram of the division of synchronization block equivalence classes in an embodiment of the present invention. DETAILED DESCRIPTION

[0015] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments.

[0016] The present invention provides an Android activity management service synchronization load reduction method based on escape analysis, an implementation example Figure 1 As shown, the specific description is given below.

[0017] Figure 1 (1) represents the AMS source code to be optimized. The optimization method of the embodiment of the present invention is performed on Java source code, and the input is the Java source code to be optimized. The optimized Java source code is generated by the method of the present invention, and the execution results of the two are equivalent.

[0018] Figure 1 In (2), the code is statically analyzed based on escape analysis. After static analysis, (3) object access information is extracted from the code to be optimized. Specifically, which objects that need to be synchronized are accessed in the code range of each synchronization block.

[0019] Figure 1 In (4), the synchronization blocks are divided into equivalence classes according to the object access information and the synchronization locks of each synchronization block, and the equivalence class division result is obtained in (5).

[0020] According to the result of equivalence class division, (6) the synchronization locks of the synchronization blocks in the code are reallocated so that different equivalence classes use different synchronization locks. Through the optimization of synchronization locks, the synchronization blocks that were originally incompatible with parallel execution can be executed in parallel, thereby improving the execution efficiency of the system.

[0021] The final output is the optimized AMS code (7) that optimizes the synchronization lock.

[0022] The static analysis method for optimizing codes in the present invention is based on the idea of ​​escape analysis, and necessary modifications are made in combination with the specific needs of the present invention for code optimization.

[0023] For the convenience of description, the present invention uses SyncBlock to refer to the synchronization block in the abstract representation and related pseudo code description, and the six-tuple can be used.<ID,Lock,LocalVarSet,GlobalVarSet,LocalFunSet,GlobalFunSet> To indicate, the meanings of each item are explained as follows:

[0024] ID is the identifier of the synchronization block, which can uniquely identify a synchronization block. In the actual implementation process, it can be represented by an integer.

[0025] ·Lock stands for synchronization lock. In each synchronization block, a synchronization lock is used at the beginning of the synchronization block. In a Java program, a synchronization lock is generally an object instance of a class or a variable of a basic data class, which can be a local variable or a global variable. When the synchronization block starts to execute, the program will first check whether the synchronization lock is available. If it is available, the code of the synchronization block will continue to execute. Otherwise, the thread will be blocked on the synchronization lock. When the execution of the synchronization block code ends, the synchronization lock will be released to allow other threads to request the synchronization lock. This synchronization lock only allows access requests from at most one thread at a time.

[0026] ·LocalVarSet represents a set of local variables, specifically local variables directly accessed in this synchronized block code, including local variables defined inside synchronized blocks, local variables of the function where the synchronized block is located and function parameter variables that are read and written in synchronized blocks. It should be noted here that there may be multiple synchronized blocks inside a class member function, and there may be multiple synchronized blocks to access local variables in a function. However, since the local variables inside a method are stored on the stack, the local variables accessed by multiple synchronized blocks are not the same variables during actual execution, so the local variables inside the method still belong to the local variable set here.

[0027] ·GlobalVarSet represents a set of global variables, including member variables of the class where the synchronized block is located and static member variables of other static classes in the AMS source code. The meaning of local and global here is relative to the synchronized block. For data member variables in a class, since all synchronized blocks in this class can access them, they are classified as global variables.

[0028] LocalFunSet represents a local function set, including the member functions of the class in which the synchronized block is located that are accessed in the synchronized block code and other class member functions within the scope of static analysis.

[0029] GlobalFunSet represents a set of global functions, including static member functions of static classes accessed in synchronized block codes, member functions of other classes beyond the scope of static analysis, and library functions.

[0030] Similar to synchronized blocks, member functions can use seven-tuples<ID,FunName,ParamSet,LocalVarSet,GlobalVarSet,LocalFunSet,GlobalFunSet> The meanings of each item are as follows:

[0031] ID represents the identifier of a function, which uniquely identifies a member function within a class and can be represented by an integer when implemented.

[0032] FunName indicates the function name of the function. The function name, together with the parameter list ParamSet, can be used to identify the specific function called by the function during analysis.

[0033] ·ParamSet represents the parameter set of a function. The parameter here refers to the formal parameter when declaring the function, mainly referring to the parameter type. The parameter list here is mainly used to identify the called function when processing the function call, so the parameter name can be omitted. In order not to affect the error of object access information during analysis, each parameter definition will also add a local variable in LocalVarSet.

[0034] The meanings of the other four items LocalVarSet, GlobalVarSet, LocalFunSet, and GlobalFunSet are the same as those in the synchronized block, except that they analyze the code in the member function, so they will not be repeated here.

[0035] Unlike the classic escape analysis, the equivalence class referred to in the present invention is the equivalence class for dividing the synchronization blocks in the code, rather than dividing the objects into equivalence classes. Because the purpose of the classic escape analysis is to determine whether the object in the method has escaped and thus determine its life cycle, while the purpose of the static analysis performed by the present invention is to determine which objects the synchronization block in the code specifically accesses, thereby determining the synchronization lock that it should use based on the set of objects it accesses. After the equivalence class division algorithm, the following equivalence class set can be obtained:

[0036] Equivalence class set: {EC 0 , E.C. 1 , ..., EC i , ...}. Among them, EC i is the equivalence class numbered i.

[0037] Equivalence Class EC i ={SyncBlock 0 ,SyncBlock 1 , ..., SyncBlock i , ...}.SyncBlock i For the equivalence class EC i The result of the final equivalence class division is a set of synchronized blocks, where synchronized blocks with overlapping access objects belong to the same equivalence class, and synchronized blocks of different equivalence classes have disjoint access object sets.

[0038] The division of synchronization block sets based on equivalence classes in the method of the present invention is specifically described below with reference to an example code.

[0039] The sample code is as follows:

[0040]

[0041]

[0042] The above is a simple Java sample code. There is a class SampleClass in the code, which has 4 member variables, namely append, work, record, and another. There are 2 member functions foo1 and foo2, and 3 synchronized blocks.

[0043] By performing static analysis on the above sample code, we can obtain the parsing results shown in Table 1, and then we can get the tuple representation of the synchronization block.

[0044] Table 1 Sample code analysis results

[0045] Synchronized block or function name Local variable collection Global variable collection Local function set Global function collection Synchronous block 1 len1 MAX_SIZE, append AddAppend Φ(empty set) Synchronous block 2 len2 MAX_SIZE, work Record Φ Synchronous block 3 i、N another Φ System.out.print AddAppend i append、work Φ Φ Record j record、work Φ Φ

[0046] According to the above, the global and local here are relative to the synchronization block and member function. Here, the class member variables can be shared between the synchronization blocks and member functions, and their status is equivalent to that of global variables, so they are classified into the global variable set. For the access to the object member function, such as append.size(), this situation belongs to one of the several cases of object access described above, rather than the access to the local function. The six-tuple representation of the synchronization block 1 is <1, this, {len1}, {append, MAX_SIZE}, {AddAppend}, Φ>. The sextuple representation of synchronized block 2 is <2, this, {len2}, {work, MAX_SIZE}, {Record}, ​​Φ>, and the sextuple representation of synchronized block 3 is <3, this, {N, i}, {another}, Φ, {System.out.print()}>. Here, synchronized block 3 accesses the library function System.out.print(). It can be judged that access to this function does not require additional synchronization operations. The virtual machine and operating system have shielded the details of the specific implementation, so the access to this function here will not affect the calculation results of the access object set that needs to be synchronized in the end.

[0047] According to the results in Table 1, we need to further find and remove local variables and global variables that do not need synchronization, so that we can get the preliminary object access set of each synchronized block and member function, as shown in Table 2. First, local variables are allocated in the running stack and are unique to the thread, so the thread does not need synchronization to access local variables. For the global variable MAX_SIZE, because it is an immutable constant modified by final, access to it does not need synchronization.

[0048] Table 2 Preliminary results of object access collection

[0049] Synchronized block or function name Object Access Collection Synchronous block 1 append Synchronous block 2 work Synchronous block 3 another AddAppend append、work Record record、work

[0050] exist Figure 2 The final calculation result of the synchronized block object access set is shown in . According to the synchronized block access object set and function call relationship diagram described in Table 2, further cross-function analysis can get the final result. In this example, synchronized block 1 accesses the AddAppend method, and the object access set of the AddAppend method needs to be merged into synchronized block 1. Similarly, the object access set of the Record method also needs to be merged into synchronized block 2. Figure 2 In the figure, the object collection accessed by synchronized blocks after cross-function analysis is shown. The object collection accessed by synchronized block 1 is {append, work}, the object collection accessed by synchronized block 2 is {work, record}, ​​and the object collection accessed by synchronized block 3 is {another}.

[0051] according to Figure 2 In the case where the synchronized block in accesses a collection of objects, the synchronized blocks can be divided into equivalence classes. Figure 3 The equivalence class division of synchronization blocks is shown in the figure. The three synchronization blocks in the example code can be divided into two equivalence class synchronization block sets. Synchronization block 1 and synchronization block 2 both access the object work, and the accessed object sets have intersections, so they are divided into the same equivalence class. The object sets accessed by synchronization block 3 have no intersection with them, so it belongs to another separate equivalence class.

[0052] Experimental data show that the running time of the Android system startup phase can be increased by more than 10% through synchronization lock optimization. Therefore, it can be proved that the method of the present invention can significantly improve the execution efficiency of the system by optimizing the synchronization lock, so that the synchronization blocks that were originally not parallel can be executed in parallel, and the semantics of the optimized code are consistent with those before optimization.

Claims

1. A method for synchronous load reduction of Android activity management service based on escape analysis, characterized in that: include: Step 1: Perform static analysis based on escape analysis on the AMS source code to be optimized, extract object access information in the code, and determine the objects that need to be synchronized in the code range of each synchronization block; AMS stands for Activity Management Services; The synchronization block is abstractly represented as a six-tuple of information, including: an identifier ID that uniquely identifies the synchronization block, a synchronization lock Lock, a local variable set LocalVarSet, a global variable set GlobalVarSet, a local function set LocalFunSet, and a global function set GlobalFunSet; Step 2, dividing the synchronization blocks into equivalence classes according to the object access information and the synchronization locks of each synchronization block; wherein the synchronization blocks with overlapping access objects are divided into the same equivalence class, and the access object sets of synchronization blocks in different equivalence classes are disjoint; Step 3, according to the equivalence class division result, the synchronization locks of the synchronization blocks in the code are reallocated, and the synchronization blocks of different equivalence classes use different synchronization locks so that the synchronization blocks of different equivalence classes can be executed in parallel, and then the optimized AMS code is output.

2. The method according to claim 1, characterized in that: In step 1, each synchronization block is represented by a six-tuple, and the six-tuple includes: (1) An identifier ID that uniquely identifies a synchronization block; (2) Synchronous lock Lock: In each synchronized block, a synchronous lock is used at the beginning of the synchronized block. The synchronous lock only allows access requests from at most one thread at a time. When a synchronized block starts to execute, the program first checks whether the synchronous lock is available. If it is available, the code of the synchronized block continues to be executed. Otherwise, the thread is blocked on the synchronous lock. After the execution of the synchronized block code is completed, the synchronous lock is released. (3) Local variable set LocalVarSet, including local variables directly accessed in the synchronized block code, including local variables defined inside the synchronized block, local variables of the synchronized block function read and written in the synchronized block, and function parameter variables; (4) Global variable set GlobalVarSet, including member variables of the class where the synchronized block is located that are accessed in the synchronized block code and static member variables of other static classes in the AMS source code; (5) Local function set LocalFunSet, including the class member functions of the synchronized block accessed in the synchronized block code and other class member functions within the scope of static analysis; (6) Global function set GlobalFunSet, including static member functions of static classes accessed in the synchronized block code, other class member functions beyond the scope of static analysis, and library functions.

3. The method according to claim 1 or 2, characterized in that: In the step 1, the access object set of the synchronization block is determined, and the objects that need to be synchronized in the code range of the synchronization block are recorded in the set, including: first, the AMS source code is statically analyzed to obtain a tuple representation of each synchronization block and member function; wherein the member function is represented as a seven-tuple information, including: a function identifier, a function name, a function parameter set, a local variable set, a global variable set, a local function set, and a global function set; then, for each synchronization block, local variables and global variables that do not need to be synchronized are removed, and according to the access object set of the synchronization block and the function call relationship, the access object set of the member function is merged into the synchronization block, and finally the access object set of the synchronization block is determined.

Citation Information

Patent Citations

  • Concurrent-program test method based on lock-object splitting strategy and test system thereof

    CN107391381A

  • Service processing method, electronic equipment and computer readable storage medium

    CN112835722A