CN114610417A - Interface calling method and device and storage medium - Google Patents

Interface calling method and device and storage medium Download PDF

Info

Publication number
CN114610417A
CN114610417A CN202011337494.4A CN202011337494A CN114610417A CN 114610417 A CN114610417 A CN 114610417A CN 202011337494 A CN202011337494 A CN 202011337494A CN 114610417 A CN114610417 A CN 114610417A
Authority
CN
China
Prior art keywords
interface function
cache
calling
interface
information
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.)
Pending
Application number
CN202011337494.4A
Other languages
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.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies Co Ltd
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 Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to CN202011337494.4A priority Critical patent/CN114610417A/en
Publication of CN114610417A publication Critical patent/CN114610417A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4488Object-oriented
    • G06F9/449Object-oriented method invocation or resolution
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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/445Program loading or initiating
    • G06F9/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4482Procedural
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/544Buffers; Shared memory; Pipes

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The application relates to an interface calling method, an interface calling device and a storage medium, wherein the interface calling method comprises the following steps: responding to the calling of an interface function in an application program, and determining a storage address of the interface function according to the type of a target object calling the interface function and first cache information; and reading the interface function from the storage address, and executing the interface function, wherein the first cache information is determined according to the storage address of the application program in the memory and preset second cache information when the application program is loaded to the memory. The embodiment of the application can pre-fill the first cache information, so that the cache hit rate of the interface function when being called for the first time is improved, the times of dynamically searching the interface function during operation are reduced, and the execution efficiency and the operation performance of the application program are improved.

Description

Interface calling method and device and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to an interface calling method, an interface calling device, and a storage medium.
Background
Object-oriented programming techniques support multiple inheritance and multiple implementations. For example, in Java programming, one interface class can inherit multiple interface classes (i.e., multi-inheritance), and one interface class can also be implemented by multiple classes (i.e., multi-implementation). When the source code has a call to an interface function in a multi-inheritance or multi-implementation interface class, in the compiling stage, a compiler generally cannot determine the real type of an object calling the interface function, that is, cannot determine the address of the called interface function, and only in the program running stage, the address of the called interface function can be determined in a dynamic searching mode. However, dynamically searching the address of the interface function at runtime is time-consuming, which affects the execution efficiency of the program.
Disclosure of Invention
In view of this, an interface calling method, an interface calling apparatus and a storage medium are provided.
In a first aspect, an embodiment of the present application provides an interface calling method, including: responding to the calling of an interface function in an application program, and determining a storage address of the interface function according to the type of a target object calling the interface function and first cache information; reading the interface function from the storage address, and executing the interface function, wherein the first cache information is determined according to the storage address of the application program in the memory and preset second cache information when the application program is loaded to the memory, the second cache information includes a plurality of second cache entries, each second cache entry corresponds to a call position of the interface function, and the second cache entries include an identifier of a type to which an object calling the interface function belongs and an identifier of the interface function in a function table of the type.
According to the interface calling method, when the application program is loaded into the memory, the first cache information can be determined according to the storage address of the application program in the memory and the preset second cache information, so that the storage address of the interface function is cached in the first cache information before the interface function is called for the first time, namely the first cache information is prefilled; in the running process of the application program, when the interface function is called, the storage address of the interface function can be determined from the pre-filled first cache information according to the type of the target object calling the interface function, the interface function is read and executed from the storage address, and the calling of the interface function is completed, so that the cache hit rate of the interface function when the interface function is called for the first time can be improved, the number of times of dynamically searching the interface function during running is reduced, and the execution efficiency and the running performance of the application program are improved.
According to the first aspect, in a first possible implementation manner of the interface calling method, the first cache information includes a plurality of first cache entries, the first cache entries correspond to the second cache entries, and the first cache entries include a storage address of a type to which an object that calls an interface function belongs and a storage address of the interface function.
According to the first aspect, in a second possible implementation manner of the interface call method, the method further includes: determining calling information of each interface function in the application program, wherein the calling information comprises calling position identification of the interface function, identification of a type to which an object calling the interface function belongs and identification of the interface function in a function table of the type; and determining second cache information according to the calling information of each interface function.
In this embodiment, the accuracy of the second cache information may be improved by determining the call information of each interface function in the application program and determining the second cache information according to the call information of each interface function.
According to a second possible implementation manner of the first aspect, in a third possible implementation manner of the interface calling method, the determining calling information of each interface function in the application program includes: sampling and compiling the source code of the application program to generate a sampling object code, wherein the sampling and compiling is used for inserting preset sampling codes behind the calling positions of all interface functions in the source code in the compiling process; and executing the sampling target code to obtain the calling information of each interface function.
In this embodiment, by sampling and compiling the source code of the application program, a preset sampling code may be inserted behind the calling position of each interface function in the source code, and a sampling object code is generated, and after executing the sampling object code, the calling information of each interface function may be obtained, which is simple and convenient, and may improve the efficiency of obtaining the calling information of the interface function.
According to a third possible implementation manner of the first aspect, in a fourth possible implementation manner of the interface call method, the determining second cache information according to call information of each interface function includes: and in the process of compiling the source code to generate the executable file of the application program, respectively creating second cache entries corresponding to the calling positions of the interface functions according to the calling information of the interface functions to obtain second cache information, wherein the second cache information is located in the executable file.
In this embodiment, in the process of generating the executable file of the application program by compiling the source code, the second cache entries corresponding to the interface functions are respectively created according to the call information of the interface functions to obtain the second cache information, so that not only can the generation efficiency of the second cache information be improved, but also the second cache information can be stored in the executable file of the application program, and the installation or deployment of the application program is not affected.
According to the first aspect, in a fifth possible implementation manner of the interface calling method, the determining a storage address of the interface function according to a type to which a target object calling the interface function belongs and first cache information includes: determining a first cache entry corresponding to the calling position of the interface function from the first cache information; and under the condition that the type of the target object for calling the interface function is the same as the type in the first cache entry, acquiring the storage address of the interface function in the first cache entry. In this way, the memory address of the interface function can be quickly determined.
According to the first aspect, in a sixth possible implementation manner of the interface calling method, a calling position of each interface function corresponds to at least one second cache entry.
In this way, at least one piece of calling information of each interface function calling position can be cached, so that the hit rate of the first cache entry corresponding to the second cache entry can be improved.
According to the first aspect, in a seventh possible implementation manner of the interface calling method, the second cache information is updated to the first cache information in a manner of backfilling a storage address. In this way, the use of cache space may be reduced.
In an eighth possible implementation manner of the interface calling method according to the first aspect as well as one or more of the multiple possible implementation manners of the first aspect, the executable file of the application program is generated by compiling through a ark compiler, and the application program includes a component of the emotional operating system EMUI and a program running on the emotional operating system EMUI.
In a second aspect, an embodiment of the present application provides an interface invoking device, including: the address acquisition module responds to the calling of an interface function in an application program and determines a storage address of the interface function according to the type of a target object calling the interface function and first cache information; and the execution module is used for reading the interface function from the storage address and executing the interface function, wherein the first cache information is determined according to the storage address of the application program in the memory and preset second cache information when the application program is loaded to the memory, the second cache information comprises a plurality of second cache entries, each second cache entry corresponds to the calling position of one interface function, and the second cache entries comprise an identifier of the type to which the object calling the interface function belongs and an identifier of the interface function in the function table of the type.
The interface calling device of the embodiment of the application can determine the first cache information according to the storage address of the application program in the memory and the preset second cache information when the application program is loaded to the memory, so that the storage address of the interface function is cached in the first cache information before the interface function is called for the first time, namely, the first cache information is prefilled; in the running process of the application program, when the interface function is called, the storage address of the interface function can be determined from the pre-filled first cache information according to the type of the target object calling the interface function, the interface function is read and executed from the storage address, and the calling of the interface function is completed, so that the cache hit rate of the interface function when the interface function is called for the first time can be improved, the number of times of dynamically searching the interface function during running is reduced, and the execution efficiency and the running performance of the application program are improved.
According to the second aspect, in a first possible implementation manner of the interface calling device, the first cache information includes a plurality of first cache entries, the first cache entries correspond to the second cache entries, and the first cache entries include a storage address of a type to which an object that calls an interface function belongs and a storage address of the interface function.
According to a second aspect, in a second possible implementation manner of the interface invoking device, the device further includes: the calling information determining module is used for determining calling information of each interface function in the application program, wherein the calling information comprises a calling position identifier of the interface function, an identifier of a type to which an object calling the interface function belongs and an identifier of the interface function in a function table of the type; and the cache information determining module is used for determining second cache information according to the calling information of each interface function.
In this embodiment, the accuracy of the second cache information may be improved by determining the call information of each interface function in the application program and determining the second cache information according to the call information of each interface function.
In a third possible implementation manner of the interface calling device according to the second possible implementation manner of the second aspect, the calling information determining module includes: the sampling compiling submodule is used for sampling and compiling the source code of the application program to generate a sampling object code, and the sampling compiling is used for inserting preset sampling codes behind the calling positions of all interface functions in the source code in the compiling process; and the sampling execution submodule is used for executing the sampling object code to obtain the calling information of each interface function.
In this embodiment, by sampling and compiling the source code of the application program, a preset sampling code may be inserted behind the calling position of each interface function in the source code, and a sampling object code is generated, and after executing the sampling object code, the calling information of each interface function may be obtained, which is simple and convenient, and may improve the efficiency of obtaining the calling information of the interface function.
According to a third possible implementation manner of the second aspect, in a fourth possible implementation manner of the interface calling apparatus, the cache information determining module includes: and the cache information determining submodule is used for respectively creating second cache entries corresponding to the calling positions of the interface functions according to the calling information of the interface functions to obtain second cache information in the process of compiling the source code to generate the executable file of the application program, wherein the second cache information is located in the executable file.
In this embodiment, in the process of generating the executable file of the application program by compiling the source code, the second cache entries corresponding to the interface functions are respectively created according to the call information of the interface functions to obtain the second cache information, so that not only can the generation efficiency of the second cache information be improved, but also the second cache information can be stored in the executable file of the application program, and the installation or deployment of the application program is not affected.
According to the second aspect, in a fifth possible implementation manner of the interface call apparatus, the address obtaining module includes: the cache entry determining submodule is used for determining a first cache entry corresponding to the calling position of the interface function from the first cache information; and the storage address determining submodule is used for acquiring the storage address of the interface function in the first cache entry under the condition that the type of the target object for calling the interface function is the same as the type in the first cache entry. In this way, the memory address of the interface function can be quickly determined.
In a sixth possible implementation manner of the interface calling device according to the second aspect, a calling location of each interface function corresponds to at least one second cache entry.
In this way, at least one piece of calling information of each interface function calling position can be cached, so that the hit rate of the first cache entry corresponding to the second cache entry can be improved.
According to the second aspect, in a seventh possible implementation manner of the interface calling device, the second cache information is updated to the first cache information by backfilling a storage address. In this way, the use of cache space may be reduced.
In an eighth possible implementation manner of the interface calling apparatus according to the second aspect or one or more of the multiple possible implementation manners of the second aspect, the executable file of the application program is generated by compiling with a canoe compiler, and the application program includes a component of the emotional operating system EMUI and a program running on the emotional operating system EMUI.
In a third aspect, an embodiment of the present application provides an interface calling apparatus, including a processor and a memory for storing processor-executable instructions, where the processor is configured to implement the interface calling method of the first aspect or one or more of the multiple possible implementation manners of the first aspect when executing the instructions.
When the application program is loaded into the memory, the interface calling device of the embodiment of the application program can determine the first cache information according to the storage address of the application program in the memory and the preset second cache information, so that the storage address of the interface function is cached in the first cache information before the interface function is called for the first time, namely, the first cache information is prefilled; in the running process of the application program, when the interface function is called, the storage address of the interface function can be determined from the pre-filled first cache information according to the type of the target object calling the interface function, the interface function is read and executed from the storage address, and the calling of the interface function is completed, so that the cache hit rate of the interface function when the interface function is called for the first time can be improved, the number of times of dynamically searching the interface function during running is reduced, and the execution efficiency and the running performance of the application program are improved.
In a fourth aspect, embodiments of the present application provide a non-transitory computer-readable storage medium, on which computer program instructions are stored, which, when executed by a processor, implement the interface calling method of the first aspect or one or more of the many possible implementations of the first aspect.
According to the embodiment of the application, when the application program is loaded into the memory, the first cache information can be determined according to the storage address of the application program in the memory and the preset second cache information, so that the storage address of the interface function is cached in the first cache information before the interface function is called for the first time, namely the first cache information is prefilled; in the running process of the application program, when the interface function is called, the storage address of the interface function can be determined from the pre-filled first cache information according to the type of the target object for calling the interface function, the interface function is read and executed from the storage address, and the calling of the interface function is completed, so that the cache hit rate of the interface function when the interface function is called for the first time can be improved, the number of times of dynamically searching the interface function in running is reduced, and the execution efficiency and the running performance of the application program are improved.
In a fifth aspect, embodiments of the present application provide a computer program product, which includes computer-readable code or a non-transitory computer-readable storage medium carrying computer-readable code, and when the computer-readable code runs in an electronic device, a processor in the electronic device executes an interface calling method of the first aspect or one or more of the many possible implementations of the first aspect.
According to the embodiment of the application, when the application program is loaded into the memory, the first cache information can be determined according to the storage address of the application program in the memory and the preset second cache information, so that the storage address of the interface function is cached in the first cache information before the interface function is called for the first time, namely the first cache information is prefilled; in the running process of the application program, when the interface function is called, the storage address of the interface function can be determined from the pre-filled first cache information according to the type of the target object calling the interface function, the interface function is read and executed from the storage address, and the calling of the interface function is completed, so that the cache hit rate of the interface function when the interface function is called for the first time can be improved, the number of times of dynamically searching the interface function during running is reduced, and the execution efficiency and the running performance of the application program are improved.
These and other aspects of the present application will be more readily apparent in the following description of the embodiment(s).
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate exemplary embodiments, features, and aspects of the application and, together with the description, serve to explain the principles of the application.
Fig. 1 is a schematic diagram illustrating an application scenario of an interface calling method according to an embodiment of the present application.
Fig. 2 is a schematic diagram illustrating an application scenario of an interface calling method according to an embodiment of the present application.
Fig. 3 shows a schematic structural diagram of a terminal device according to an embodiment of the present application.
Fig. 4 shows a block diagram of a software structure of a terminal device according to an embodiment of the present application.
FIG. 5 shows a flow diagram of an interface invocation method according to an embodiment of the present application.
Fig. 6 is a schematic diagram illustrating a processing procedure of an interface calling method according to an embodiment of the present application.
FIG. 7 illustrates a schematic diagram of an interface of a compiler according to an embodiment of the present application.
Fig. 8 is a schematic diagram illustrating an execution effect of an interface calling method according to an embodiment of the present application.
Fig. 9 shows a block diagram of an interface invocation device according to an embodiment of the present application.
Detailed Description
Various exemplary embodiments, features and aspects of the present application will be described in detail below with reference to the accompanying drawings. In the drawings, like reference numbers indicate functionally identical or similar elements. While the various aspects of the embodiments are presented in drawings, the drawings are not necessarily drawn to scale unless specifically indicated.
The word "exemplary" is used exclusively herein to mean "serving as an example, embodiment, or illustration. Any embodiment described herein as "exemplary" is not necessarily to be construed as preferred or advantageous over other embodiments.
Furthermore, in the following detailed description, numerous specific details are set forth in order to provide a better understanding of the present application. It will be understood by those skilled in the art that the present application may be practiced without some of these specific details. In some instances, methods, means, elements and circuits that are well known to those skilled in the art have not been described in detail so as not to obscure the present application.
In object-oriented programming techniques, an interface class may include at least one interface function (also referred to as an interface method). In order to better understand the technical solution of the embodiments of the present application, a plurality of implementations of the interface class are exemplarily described below by way of examples.
Assuming that there are two interface classes IntfA and IntfB, the interface class IntfA includes an interface function sayCat (), the interface class IntfB includes an interface function sayDog (), and both subclasses SubClassA and SubClassB implement IntfA and IntfB, as shown in table 1 below specifically:
TABLE 1 interface classes and subclasses thereof
Figure BDA0002797601220000051
In table 1, the interface class IntfA is implemented by both subclass subcassa and subcassb, that is, one interface class is implemented by multiple classes, and the implementation manner is multiple implementations of interface classes. Similarly, the interface class IntfB is realized by both subclass SubClassA and subclass SubClassB, and is also realized by more than one subclass.
The subclass SubClassA realizes both the interface class IntfA and the interface class IntfB, i.e., one class realizes a plurality of interface classes. Likewise, the subclass SubClassB implements both IntfA and IntfB interface classes. In the related art, the multi-inheritance of a class is similar to the implementation of multiple interface classes by one class, and details are not repeated here.
When an interface function is called on an object, the compiler cannot determine the true type of the object that called the interface function at compile time. For example, in the following mutter () function, the interface function sayCat () is called on the object intf, and the object intf may be the object of the subclass SubClassA or the object of the subclass SubClassB:
Figure BDA0002797601220000061
since the compiler cannot determine whether the incoming parameter intf of the mutter () function is an object of the subclass SubClassA or SubClassB at the time of compilation, the compiler will put the statement "intf.saycat (); "translate into the following four steps to dynamically find the correct interface function and call when the program runs:
step 1, determining the real type realType of intf during operation;
step 2, acquiring a function table mTable (also called a method table) associated with the real type realType of intf, namely a set of functions included in the real type realType, for example, the function table of SubClassA includes an interface function sayCat () and an interface function sayDog ();
step 3, searching the address addr of the interface function sayCat () in the function table mTable;
and step 4, calling sayCat () according to the searched address addr.
The statement "intf.sayCat (); "pseudo code after compiler conversion, can be illustrated as follows:
Figure BDA0002797601220000062
when the number of interface functions included in the interface class is large, it takes time to perform the above four steps, especially step 3, and the operation efficiency of the program is seriously affected.
However, experience has shown that when the same interface function call is executed multiple times, the objects that call the interface function are usually of the same type. For example, intf.saycat () is executed a plurality of times, assuming that the type of object intf is SubClassA when intf.saycat () is executed for the first time, the type of object intf is also SubClassA with a high probability when intf.saycat () is executed again.
According to the above experience, the prior art adopts an inline cache technique, associates each interface function call with a cache entry, and stores the type of the object and the address of the interface function determined when the interface function call is executed for the first time to the corresponding cache entry. For example, when intf.sayCat () is executed for the first time, the addresses of the determined types SubClassA and sayCat () of the object intf can be saved to the corresponding cache entries. The cache occupied by the cache entry can be applied to the system according to actual conditions.
When executing intf.sayCat () for the second time, firstly, according to the corresponding cache entry, judging whether the type of intf is the same as the type SubClassA stored in the cache entry, if so, directly using the address of the interface function sayCat () stored in the cache entry without searching the address of the sayCat () in the function table of the SubClassA.
For example, in the following source code, the function mutter () is executed three times, and intf.sayCat () is called three times:
Figure BDA0002797601220000071
when the inline cache technology is used, after the mutter () function in the source code is converted by the compiler, pseudo codes related to the inline cache mechanism are added, which can be shown as follows:
Figure BDA0002797601220000072
wherein cacheTable represents a cache table for storing cache entries. After the source code is compiled, the contents of the cache table cacheTable are empty (which may be represented as XXX, for example). The cache table cacheTable can be illustrated as follows:
0[XXX,XXX]
1[XXX,XXX]
2[XXX,XXX]
3[XXX,XXX]
in the cache table, 0, 1, 2, and 3 are cache entry numbers, and correspond to the 0 th call location, the 1 st call location, the 2 nd call location, and the 3 rd call location, respectively. Each cache entry includes two fields, the 0 th field representing the type and the 1 st field representing the address of the interface function.
In the pseudo code, the cache entry corresponding to intf.sayCat () is the 1 st cache entry, cacheTable [1] [0] represents the 0 th field of the 1 st cache entry, and cacheTable [1] [1] represents the 1 st field of the 1 st cache entry.
When intf.saycat () is executed for the first time, because the content of the 1 st cache entry in the cache table is empty, when searching in the cache table, a hit cannot be reached. Under the condition that the cache entries are searched for in a missing mode for the first time, the addresses of the actual type SubClassA and the function sayCat () of intf when the sayCat () is called for the first time are stored to the corresponding cache entries, namely the 1 st cache entry, and the updated cache table cacheTable is as follows:
0[XXX,XXX]
1[ SubClassA, sayCat () ]
2[XXX,XXX]
3[XXX,XXX]
When the sayCat () is called for the second time and the third time, because the real type of intf is consistent with the type stored in the 1 st cache entry, when the intf.sayCat () is executed for the second time and the third time, the address of the sayCat () can be directly obtained from the 1 st field in the 1 st cache entry, so that the searching speed of an interface function sayCat () is increased, and the program running efficiency is further improved.
However, when the inline cache technique is used, since the initial content of the cache entry in the cache table is empty, there is inevitably a cache miss when the interface function call is executed for the first time, which affects the program execution efficiency and causes performance loss.
In order to solve the technical problem, the application provides an interface calling method. The interface calling method can reduce the condition that the cache entries cannot be hit when the interface function calling is executed for the first time, thereby improving the program execution efficiency and the operation performance.
Fig. 1 is a schematic diagram illustrating an application scenario of an interface calling method according to an embodiment of the present application. As shown in fig. 1, the interface calling method according to the embodiment of the present application is applied to a first device 10, at least one application program 20 is deployed or installed in the first device 10, and the application program 20 is generated by compiling a source code 40 in a second device 30.
Wherein, the first device 10 may be a server or a terminal device capable of running an application; the second device 30 may be any type of device that may be used for application development (including the writing, compiling, etc. of the source code 40), such as a desktop computer, mainframe computer, laptop, server, etc. The present application is not limited to a particular type of first device 10 and second device 30.
Fig. 2 is a schematic diagram illustrating an application scenario of an interface calling method according to an embodiment of the present application. As shown in fig. 2, the interface calling method according to the embodiment of the present application is applied to the first device 10, and unlike fig. 1, the first device 10 in fig. 2 includes a source code 40 and an application 20 generated by compiling the source code. That is, the first device 10 in fig. 2 may be used for development (e.g., writing, compiling, etc. of the source code 40) and execution of the application 20.
The interface calling method according to the embodiment of the present application may also be applied to the second device 30. In this application scenario, the second device 30 includes the source code 40 and the application program 20 generated by compiling the source code, that is, the second device 30 is used for developing and running the application program 20.
In a possible implementation manner, the terminal device related to the present application may refer to a device having a wireless connection function, the wireless connection function refers to being connected with other terminal devices through wireless connection manners such as wifi and bluetooth, and the terminal device of the present application may also have a function of communicating through wired connection. The terminal device of the application can be a touch screen, can also be a non-touch screen, and can also be screen-free, the touch screen can control the terminal device in a manner of clicking, sliding and the like on a display screen through fingers, a touch pen and the like, the non-touch screen device can be connected with input devices such as a mouse, a keyboard, a touch panel and the like, the terminal device is controlled through the input devices, and the screen-free device can be a screen-free Bluetooth sound box and the like. For example, the terminal device of the present application may be a smart phone, a netbook, a tablet computer, a notebook computer, a wearable electronic device (such as a smart band, a smart watch, and the like), a TV, a virtual reality device, a sound, electronic ink, and the like.
Fig. 3 shows a schematic structural diagram of a terminal device according to an embodiment of the present application. Taking the terminal device as a mobile phone as an example, fig. 3 shows a schematic structural diagram of the mobile phone 200.
The mobile phone 200 may include a processor 210, an external memory interface 220, an internal memory 221, a USB interface 230, a charging management module 240, a power management module 241, a battery 242, an antenna 1, an antenna 2, a mobile communication module 251, a wireless communication module 252, an audio module 270, a speaker 270A, a receiver 270B, a microphone 270C, an earphone interface 270D, a sensor module 280, keys 290, a motor 291, an indicator 292, a camera 293, a display 294, a SIM card interface 295, and the like. The sensor module 280 may include a gyroscope sensor 280A, an acceleration sensor 280B, a proximity light sensor 280G, a fingerprint sensor 280H, and a touch sensor 280K (of course, the mobile phone 200 may also include other sensors, such as a temperature sensor, a pressure sensor, a distance sensor, a magnetic sensor, an ambient light sensor, an air pressure sensor, a bone conduction sensor, and the like, which are not shown in the figure).
It is to be understood that the illustrated structure of the embodiment of the present application does not specifically limit the mobile phone 200. In other embodiments of the present application, handset 200 may include more or fewer components than shown, or combine certain components, or split certain components, or a different arrangement of components. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
Processor 210 may include one or more processing units, such as: the processor 210 may include an Application Processor (AP), a modem processor, a Graphics Processing Unit (GPU), an Image Signal Processor (ISP), a controller, a memory, a video codec, a Digital Signal Processor (DSP), a baseband processor, and/or a Neural-Network Processing Unit (NPU), etc. The different processing units may be separate devices or may be integrated into one or more processors. Wherein the controller can be the neural center and the command center of the cell phone 200. The controller can generate an operation control signal according to the instruction operation code and the timing signal to complete the control of instruction fetching and instruction execution.
A memory may also be provided in processor 210 for storing instructions and data. In some embodiments, the memory in the processor 210 is a cache memory. The memory may hold instructions or data that have just been used or recycled by processor 210. If the processor 210 needs to use the instruction or data again, it can be called directly from the memory. Avoiding repeated accesses reduces the latency of the processor 210, thereby increasing the efficiency of the system.
The processor 210 may operate the interface calling method provided in the embodiment of the present application, so as to improve the cache hit rate when the interface function is called for the first time, reduce the number of times of dynamically searching the interface function during operation, and further improve the execution efficiency and the operation performance of the application program. The processor 210 may include different devices, for example, when the CPU and the GPU are integrated, the CPU and the GPU may cooperate to execute the interface calling method provided in the embodiment of the present application, for example, part of the algorithm in the interface calling method is executed by the CPU, and another part of the algorithm is executed by the GPU, so as to obtain faster processing efficiency.
The display screen 294 is used to display images, video, and the like. The display screen 294 includes a display panel. The display panel may adopt a Liquid Crystal Display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (active-matrix organic light-emitting diode, AMOLED), a flexible light-emitting diode (FLED), a miniature, a Micro-oeld, a quantum dot light-emitting diode (QLED), and the like. In some embodiments, the cell phone 200 may include 1 or N display screens 294, N being a positive integer greater than 1. The display screen 294 may be used to display information input by or provided to the user as well as various Graphical User Interfaces (GUIs). For example, the display 294 may display a photograph, video, web page, or file, among others. As another example, the display 294 may display a graphical user interface. The graphical user interface comprises a status bar, a hidden navigation bar, a time and weather widget (widget) and an application icon, such as a browser icon. The status bar includes the name of the operator (e.g., china mobile), the mobile network (e.g., 4G), the time and the remaining power. The navigation bar includes a back key icon, a home key icon, and a forward key icon. Further, it is understood that in some embodiments, a Bluetooth icon, a Wi-Fi icon, an add-on icon, etc. may also be included in the status bar. It will also be appreciated that in other embodiments, a Dock bar may also be included in the graphical user interface, and that a commonly used application icon may be included in the Dock bar, etc. When the processor 210 detects a touch event of a finger (or a stylus, etc.) of a user with respect to an application icon, in response to the touch event, a user interface of an application corresponding to the application icon is opened and displayed on the display 294.
In the embodiment of the present application, the display screen 294 may be an integrated flexible display screen, or a spliced display screen formed by two rigid screens and a flexible screen located between the two rigid screens may be adopted.
The cameras 293 (front camera or rear camera, or one camera may be used as both front camera and rear camera) are used for capturing still images or video. In general, the camera 293 may include a photosensitive element such as a lens group including a plurality of lenses (convex or concave lenses) for collecting an optical signal reflected by an object to be photographed and transferring the collected optical signal to an image sensor, and an image sensor. And the image sensor generates an original image of the object to be shot according to the optical signal.
Internal memory 221 may be used to store computer-executable program code, including instructions. The processor 210 executes various functional applications and data processing of the cellular phone 200 by executing instructions stored in the internal memory 221. The internal memory 221 may include a program storage area and a data storage area. Wherein the storage program area may store an operating system, codes of application programs (such as a camera application, a WeChat application, etc.), and the like. The data storage area can store data (such as images, videos and the like acquired by a camera application) and the like created in the use process of the mobile phone 200.
The internal memory 221 may further store one or more computer programs 1310 corresponding to the interface calling method provided by the embodiment of the present application. The one or more computer programs 1304 are stored in the memory 221 and configured to be executed by the one or more processors 210, the one or more computer programs 1310 including instructions that may be used to perform the steps as in the respective embodiments of fig. 5 or 6.
In addition, the internal memory 221 may include a high-speed random access memory, and may further include a nonvolatile memory, such as at least one magnetic disk storage device, a flash memory device, a universal flash memory (UFS), and the like.
Of course, the code of the interface calling method provided in the embodiment of the present application may also be stored in the external memory. In this case, the processor 210 may execute the code of the interface call method stored in the external memory through the external memory interface 220.
The function of the sensor module 280 is described below.
The gyro sensor 280A may be used to determine the motion attitude of the cellular phone 200. In some embodiments, the angular velocity of the handpiece 200 about three axes (i.e., x, y, and z axes) may be determined by the gyro sensor 280A. I.e., the gyro sensor 280A may be used to detect the current state of motion of the handset 200, such as shaking or standing still.
When the display screen in the embodiment of the present application is a foldable screen, the gyro sensor 280A may be used to detect a folding or unfolding operation acting on the display screen 294. The gyro sensor 280A may report the detected folding operation or unfolding operation as an event to the processor 210 to determine the folded state or unfolded state of the display screen 294.
The acceleration sensor 280B can detect the magnitude of acceleration of the cellular phone 200 in various directions (typically three axes). I.e., the gyro sensor 280A may be used to detect the current state of motion of the handset 200, such as shaking or standing still. When the display screen in the embodiment of the present application is a foldable screen, the acceleration sensor 280B may be used to detect a folding or unfolding operation acting on the display screen 294. The acceleration sensor 280B may report the detected folding operation or unfolding operation as an event to the processor 210 to determine the folded state or unfolded state of the display screen 294.
The proximity light sensor 280G may include, for example, a Light Emitting Diode (LED) and a light detector, such as a photodiode. The light emitting diode may be an infrared light emitting diode. The mobile phone emits infrared light outwards through the light emitting diode. The handset uses a photodiode to detect infrared reflected light from nearby objects. When sufficient reflected light is detected, it can be determined that there is an object near the handset. When insufficient reflected light is detected, the handset can determine that there are no objects near the handset. When the display screen in the embodiment of the present application is a foldable display screen, the proximity light sensor 280G may be disposed on a first screen of the foldable display screen 294, and the proximity light sensor 280G may detect a folding angle or an unfolding angle of the first screen and the second screen according to an optical path difference of an infrared signal.
The gyro sensor 280A (or the acceleration sensor 280B) may transmit the detected motion state information (such as an angular velocity) to the processor 210. The processor 210 determines whether the mobile phone 200 is currently in the hand-held state or the tripod state (for example, when the angular velocity is not 0, it indicates that the mobile phone 200 is in the hand-held state) based on the motion state information.
The fingerprint sensor 280H is used to collect a fingerprint. The mobile phone 200 can utilize the collected fingerprint characteristics to realize fingerprint unlocking, access to an application lock, fingerprint photographing, fingerprint incoming call answering and the like.
The touch sensor 280K is also referred to as a "touch panel". The touch sensor 280K may be disposed on the display screen 294, and the touch sensor 280K and the display screen 294 form a touch screen, which is also called a "touch screen". The touch sensor 280K is used to detect a touch operation applied thereto or nearby. The touch sensor can communicate the detected touch operation to the application processor to determine the touch event type. Visual output related to touch operations may be provided through the display screen 294. In other embodiments, the touch sensor 280K can be disposed on the surface of the mobile phone 200 at a different location than the display 294.
Illustratively, the display 294 of the cell phone 200 displays a home interface that includes icons for a plurality of applications (e.g., a camera application, a WeChat application, etc.). The user clicks an icon of the camera application in the main interface through the touch sensor 280K, and the processor 210 is triggered to start the camera application and open the camera 293. Display screen 294 displays an interface, such as a viewfinder interface, for a camera application.
The wireless communication function of the mobile phone 200 can be implemented by the antenna 1, the antenna 2, the mobile communication module 251, the wireless communication module 252, the modem processor, the baseband processor, and the like.
The antennas 1 and 2 are used for transmitting and receiving electromagnetic wave signals. Each antenna in the handset 200 may be used to cover a single or multiple communication bands. Different antennas can also be multiplexed to improve the utilization of the antennas. For example: the antenna 1 may be multiplexed as a diversity antenna of a wireless local area network. In other embodiments, the antenna may be used in conjunction with a tuning switch.
The mobile communication module 251 can provide a solution including 2G/3G/4G/5G wireless communication applied to the handset 200. The mobile communication module 251 may include at least one filter, switch, power amplifier, Low Noise Amplifier (LNA), etc. The mobile communication module 251 can receive electromagnetic waves from the antenna 1, and filter, amplify, etc. the received electromagnetic waves, and transmit the electromagnetic waves to the modem processor for demodulation. The mobile communication module 251 can also amplify the signal modulated by the modem processor, and convert the signal into electromagnetic wave through the antenna 1 to radiate the electromagnetic wave. In some embodiments, at least some of the functional modules of the mobile communication module 251 may be disposed in the processor 210. In some embodiments, at least some of the functional modules of the mobile communication module 251 may be provided in the same device as at least some of the modules of the processor 210. In this embodiment, the mobile communication module 251 may also be used for information interaction with other terminal devices.
The modem processor may include a modulator and a demodulator. The modulator is used for modulating a low-frequency baseband signal to be transmitted into a medium-high frequency signal. The demodulator is used for demodulating the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then passes the demodulated low frequency baseband signal to a baseband processor for processing. The low frequency baseband signal is processed by the baseband processor and then transferred to the application processor. The application processor outputs sound signals through an audio device (not limited to the speaker 270A, the receiver 270B, etc.) or displays images or video through the display screen 294. In some embodiments, the modem processor may be a stand-alone device. In other embodiments, the modem processor may be provided in the same device as the mobile communication module 251 or other functional modules, independent of the processor 210.
The wireless communication module 252 may provide solutions for wireless communication applied to the mobile phone 200, including Wireless Local Area Networks (WLANs) (e.g., wireless fidelity (Wi-Fi) networks), Bluetooth (BT), Global Navigation Satellite System (GNSS), Frequency Modulation (FM), Near Field Communication (NFC), Infrared (IR), and the like. The wireless communication module 252 may be one or more devices that integrate at least one communication processing module. The wireless communication module 252 receives electromagnetic waves via the antenna 2, performs frequency modulation and filtering processing on electromagnetic wave signals, and transmits the processed signals to the processor 210. The wireless communication module 252 may also receive a signal to be transmitted from the processor 210, perform frequency modulation on the signal, amplify the signal, and convert the signal into electromagnetic waves via the antenna 2 to radiate the electromagnetic waves.
In addition, the mobile phone 200 can implement an audio function through the audio module 270, the speaker 270A, the receiver 270B, the microphone 270C, the earphone interface 270D, and the application processor. Such as music playing, recording, etc. The handset 200 may receive key 290 inputs, generating key signal inputs relating to user settings and function control of the handset 200. The cell phone 200 can generate a vibration alert (e.g., an incoming call vibration alert) using the motor 291. The indicator 292 in the mobile phone 200 may be an indicator light, and may be used to indicate a charging status, a power change, or an indication message, a missed call, a notification, or the like. The SIM card interface 295 in the handset 200 is used to connect a SIM card. The SIM card can be attached to and detached from the mobile phone 200 by being inserted into the SIM card interface 295 or being pulled out from the SIM card interface 295.
It should be understood that in practical applications, the mobile phone 200 may include more or less components than those shown in fig. 3, and the embodiment of the present application is not limited thereto. The illustrated handset 200 is merely an example, and the handset 200 may have more or fewer components than shown in the figures, may combine two or more components, or may have a different configuration of components. The various components shown in the figures may be implemented in hardware, software, or a combination of hardware and software, including one or more signal processing and/or application specific integrated circuits.
The software system of the terminal device may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the application takes an Android system with a layered architecture as an example, and illustrates a software structure of a terminal device.
Fig. 4 is a block diagram of a software structure of the terminal device according to the embodiment of the present application.
The layered architecture divides the software into several layers, each layer having a clear role and division of labor. The layers communicate with each other through a software interface. In some embodiments, the Android system is divided into four layers, an application layer, an application framework layer, an Android runtime (Android runtime) and system library, and a kernel layer from top to bottom.
The application layer may include a series of application packages.
As shown in fig. 4, the application package may include phone, camera, gallery, calendar, phone call, map, navigation, WLAN, bluetooth, music, video, short message, etc. applications.
The application framework layer provides an Application Programming Interface (API) and a programming framework for the application program of the application layer. The application framework layer includes a number of predefined functions.
As shown in FIG. 4, the application framework layers may include a window manager, content provider, view system, phone manager, resource manager, notification manager, and the like.
The window manager is used for managing window programs. The window manager can obtain the size of the display screen, judge whether a status bar exists, lock the screen, intercept the screen and the like.
The content provider is used to store and retrieve data and make it accessible to applications. The data may include video, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
The view system includes visual controls such as controls to display text, controls to display pictures, and the like. The view system may be used to build applications. The display interface may be composed of one or more views. For example, the display interface including the short message notification icon may include a view for displaying text and a view for displaying pictures.
The telephone manager is used for providing a communication function of the terminal equipment. Such as management of call status (including on, off, etc.).
The resource manager provides various resources for the application, such as localized strings, icons, pictures, layout files, video files, and the like.
The notification manager enables the application to display notification information in the status bar, can be used to convey notification-type messages, can disappear automatically after a brief dwell, and does not require user interaction. Such as a notification manager used to inform download completion, message alerts, etc. The notification manager may also be a notification that appears in the form of a chart or scroll bar text at the top status bar of the system, such as a notification of a background running application, or a notification that appears on the screen in the form of a dialog window. For example, text information is prompted in the status bar, a prompt tone is given, the terminal device vibrates, an indicator light flickers, and the like.
The Android Runtime comprises a core library and a virtual machine. The Android runtime is responsible for scheduling and managing an Android system.
The core library comprises two parts: one part is a function which needs to be called by java language, and the other part is a core library of android.
The application layer and the application framework layer run in a virtual machine. And executing java files of the application program layer and the application program framework layer into a binary file by the virtual machine. The virtual machine is used for performing the functions of object life cycle management, stack management, thread management, safety and exception management, garbage collection and the like.
The system library may include a plurality of functional modules. For example: surface managers (surface managers), Media Libraries (Media Libraries), three-dimensional graphics processing Libraries (e.g., OpenGL ES), 2D graphics engines (e.g., SGL), and the like.
The surface manager is used to manage the display subsystem and provide fusion of 2D and 3D layers for multiple applications.
The media library supports a variety of commonly used audio, video format playback and recording, and still image files, among others. The media library may support a variety of audio-video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
The three-dimensional graphic processing library is used for realizing three-dimensional graphic drawing, image rendering, synthesis, layer processing and the like.
The 2D graphics engine is a drawing engine for 2D drawing.
The kernel layer is a layer between hardware and software. The inner core layer at least comprises a display driver, a camera driver, an audio driver and a sensor driver.
FIG. 5 shows a flow diagram of an interface invocation method according to an embodiment of the present application. The method may be applied to the first device 10. As shown in fig. 5, the interface calling method includes:
step S501, responding to the calling of an interface function in an application program, and determining a storage address of the interface function according to the type of a target object calling the interface function and first cache information;
step S502, reading the interface function from the storage address and executing the interface function;
wherein the first cache information is determined according to a storage address of the application program in the memory and preset second cache information when the application program is loaded to the memory,
the second cache information comprises a plurality of second cache entries, each second cache entry corresponds to the calling position of one interface function, and the second cache entries comprise the identification of the type of the object calling the interface function and the identification of the interface function in the function table of the type.
In this embodiment, the second cache information may be determined before step S501 is executed. The following exemplifies a manner of determining the second cache information.
In a possible implementation manner, when determining the second cache information, the call information of each interface function in the application program may be determined first, where the call information includes a call position identifier of the interface function, an identifier of a type to which an object that calls the interface function belongs, and an identifier of the interface function in a function table of the type, and then the second cache information is determined according to the call information of each interface function.
Wherein the application programs may include operating system components and programs running on the operating system. The operating system may include a computer operating system, a mobile phone operating system and other operating systems. The computer operating system may be, for example, a Windows operating system, a Linux operating system, etc., and the mobile phone operating system may be, for example, an Android system, an emotional operating system emui (emulation User interface), etc. The application is not limited to a particular type of operating system. When the operating system is an emotional operating system EMUI (emulation User interface), the application programs may include components of the emotional operating system EMUI and programs running on the emotional operating system EMUI.
When the second cache information is determined, the calling information of each interface function in the application program can be determined through modes of breakpoint debugging, sampling and the like. The calling information of the interface function may include a calling position identifier of the interface function, an identifier of a type to which an object calling the interface function belongs, and an identifier of the interface function in a function table of the type.
For example, the call information of the interface function may be represented as 2[5,6], where 2 represents the call location identifier of the interface function, 5 represents the identifier of the type to which the object calling the interface function belongs, i.e. classIndex, and 6 represents the identifier of the interface function in the function table of the type, i.e. methodIndex.
In a possible implementation manner, the calling position of each interface function may correspond to at least one piece of calling information. For example, multiple breakpoint debugging or sampling can be performed on the calling position of the interface function, the type of the object calling the interface function is checked, and if the type of the object calling the interface function does not change or the probability of the type change is smaller than a preset probability threshold value in the multiple breakpoint debugging or sampling process, the calling position of the interface function can be considered to correspond to one piece of calling information; if the type of the object calling the interface function changes and is switched between at least two types or the probability of the type change is greater than a preset probability threshold value in the process of debugging or sampling the breakpoints for multiple times, the calling position of the interface function can be considered to correspond to two or more pieces of calling information. Those skilled in the art can set the maximum number of pieces of call information corresponding to the call position of each interface function according to the actual situation, which is not limited in the present application.
In a possible implementation manner, determining the calling information of each interface function in the application program may include: sampling and compiling the source code of the application program to generate a sampling object code, wherein the sampling and compiling is used for inserting preset sampling codes behind the calling positions of all interface functions in the source code in the compiling process; and executing the sampling target code to obtain the calling information of each interface function.
When the compiler performs sampling compilation on the source code of the application program, a preset sampling code can be inserted behind the calling position of each interface function in the source code to generate a sampling object code. That is, the sample object code includes code of source code converted by a compiler and sample code inserted after the call position of each interface function.
When the sampling code is executed, the information of the type to which the object calling the interface function belongs (for example, the identification of the type, namely the subscript of the type in the class array in the file generated by compiling) and the information of the interface function (for example, the identification of the interface function, namely the subscript of the interface function in the function table of the type) can be automatically captured according to the calling position of the sampling code. The sampling code may also write the captured call information into a predetermined file (e.g., a text file for storing the call information) for saving for later use. The preset file may be a text file, a word file, an excel file, or the like. The specific type of the preset file can be set by those skilled in the art according to practical situations, and the present application is not limited thereto.
For example, in the following source code, the calling position of the interface function is a statement "intf.saycat (); ":
Figure BDA0002797601220000151
when the compiler samples and compiles the source code, the source code can be positioned behind the calling position of the interface function, namely the statement "intf.sayCat (); "after, insert the sampling code. The sample object code generated after the compiler performs sample compilation on the source code is as follows:
Figure BDA0002797601220000152
the last three lines are sampling codes inserted by the compiler in the sampling compilation process, a statement "classIndex ═ get index of realType in the executable" is used for obtaining the identifier of the real type to which the object intf calling the interface function sayCat () belongs, a statement "methodIndex ═ get index of sayCat in mTable" is used for obtaining the identifier of the interface function sayCat () in the function table mTable of the real type to which the object intf belongs, and a statement "save classIndex and methodIndex of current existence file" is used for saving the obtained classIndex and methodIndex in a preset file.
In a possible implementation manner, after the sampling object code is generated, the sampling object code may be executed to obtain the call information of each interface function, and meanwhile, the call information of each interface function may also be saved to a preset file. The calling information can be represented by the following format:
calling position identification [ identification of a type to which an object calling the interface function belongs, identification of the interface function in a function table of the type ], namely calling position identification [ classIndex, methodIndex ].
For example, the invocation information for the 0-3 rd invocation position may be expressed as:
0[2,5]
1[3,1]
2[5,6]
3[1,0]
in a possible implementation manner, the calling information may also be represented by other manners such as a table, a two-dimensional matrix, a two-dimensional array, and the like, and the representation manner of the calling information is not limited in the present application.
By sampling and compiling the source code of the application program, the preset sampling code can be inserted behind the calling position of each interface function in the source code, the sampling object code is generated, and the calling information of each interface function can be obtained after the sampling object code is executed.
In a possible implementation manner, after the call information of each interface function is obtained, the second cache information may be determined according to the call information of each interface function. The second cache information may include a plurality of second cache entries, where the second cache entries may include an identification of a type to which an object calling the interface function belongs and an identification of the interface function in a function table of the type. Corresponding second cache entries can be respectively established according to the calling information of each interface function, the second cache entries correspond to the calling information one by one, namely each second cache entry corresponds to one piece of calling information. In one possible implementation, the second cache information may be represented by a cache table cacheTable.
The calling position of each interface function can correspond to at least one piece of calling information, and under the condition that the second cache entries correspond to the calling information one by one, the calling position of each interface function can correspond to at least one second cache entry. In this way, at least one piece of calling information of each interface function calling position can be cached, so that the hit rate of the first cache entry corresponding to the second cache entry can be improved.
In a possible implementation manner, the determining the second cache information according to the call information of each interface function may include: and in the process of compiling the source code to generate the executable file of the application program, respectively creating second cache entries corresponding to the calling positions of the interface functions according to the calling information of the interface functions to obtain second cache information, wherein the second cache information is located in the executable file.
After determining the calling information of each interface function, in the process of compiling the source code to generate the executable file of the application program, the compiler may allocate at least one second cache entry to the calling position of each interface function, read classIndex and methodIndex in the calling information corresponding to each calling position from a preset text for storing the calling information, and write the classIndex and methodIndex in the corresponding second cache entry, thereby obtaining second cache information, where the second cache information is located in the executable file of the application program.
The compiler used in compiling may be different according to the development environment of the source code or the execution environment of the application program. For example, when the application is a component of the emotive operating system EMUI or a program running on the emotive operating system EMUI, an executable file of the application may be generated by compiling the application with a canoe compiler. The specific type of compiler is not limited by this application.
In the process of compiling the source code to generate the executable file of the application program, the second cache entries corresponding to the interface functions are respectively created according to the calling information of the interface functions to obtain the second cache information, so that the generation efficiency of the second cache information can be improved, and the second cache information can be stored in the executable file of the application program without influencing the installation or deployment of the application program.
According to the embodiment, the accuracy of the second cache information can be improved by determining the calling information of each interface function in the application program and determining the second cache information according to the calling information of each interface function.
In a possible implementation manner, after the source code is compiled and the executable file of the application program is generated, the executable file of the application program may be installed or deployed on a target device (e.g., the first device in fig. 1), and after the installation or deployment is completed, the application program may be run.
When the application program is loaded to the memory, the first cache information can be determined according to the storage address of the application program in the memory and the second cache information. The first cache information comprises a plurality of first cache entries, the first cache entries correspond to second cache entries in the second cache information, and the first cache entries comprise storage addresses of types to which objects calling interface functions belong and storage addresses of the interface functions.
For example, when the application program is loaded into the memory and a dynamic link is executed, the contents of each second cache entry in the second cache information may be analyzed, and according to the storage address of the application program in the memory, the storage address of the class corresponding to the classIndex in each second cache entry in the memory and the storage address of the interface function corresponding to the methodIndex are respectively determined, and according to the determined storage addresses, the corresponding first cache entry is established, so as to obtain the first cache information.
In a possible implementation manner, the second cache information may be updated to the first cache information by backfilling the storage address. That is, for any second cache entry, the classIndex in the second cache entry may be updated to the storage address of the class corresponding to the classIndex in the memory, and the methodIndex in the second cache entry may be updated to the storage address of the interface function corresponding to the methodIndex, so as to obtain the first cache entry corresponding to the second cache entry. And the second cache information is updated to the first cache information in a memory address backfilling mode, so that the use of cache space can be reduced. It should be understood that the present application is not limited to the determination manner of the first cache information.
In a possible implementation manner, the first cache information may be represented by a cache table, which is schematically shown as follows:
0[SubClassA_addr,sayDog_addr]
1[SubClassA_addr,sayCat_addr]
2[SubClassB_addr,sayDog_addr]
3[SubClassB_addr,sayCat_addr]
wherein SubClassA _ addr represents the storage address of the type SubClassA; subclasb _ addr represents the storage address of the type subclasb; sayDog _ addr in the 0 th first cache entry represents the storage address of the interface function sayDog () in the type SubClassA; sayCat _ addr in the 1 st first cache entry represents the storage address of an interface function sayCat () in the type SubClassA; sayDog _ addr in the 2 nd first cache entry represents the storage address of the interface function sayDog () in the type subclasb; sayCat _ addr in the 3 rd first cache entry represents the storage address of the interface function sayCat () in the type subclasb.
In a possible implementation manner, after the first cache information is determined, in the running process of the application program, the calling of the interface function in the application program may be responded, and in step S501, the storage address of the interface function is determined according to the type to which the target object calling the interface function belongs and the first cache information.
That is to say, when an interface function in an application program is called, the storage address of the interface function may be determined according to the type of the target object calling the interface function and the first cache information, without using a dynamic lookup manner.
In one possible implementation, step S501 may include: determining a first cache entry corresponding to the calling position of the interface function from the first cache information; judging whether the type of the target object calling the interface function is the same as (or matched with) the type in the first cache entry; under the condition that the type of the target object for calling the interface function is the same as the type in the first cache entry, the information in the first cache entry can be considered to be matched with the calling information of the interface function, and the storage address of the interface function can be directly acquired from the first cache entry. In this way, the memory address of the interface function can be quickly determined.
In a possible implementation manner, when the type of the target object calling the interface function is different from the type in the first cache entry, the storage address of the interface function may be determined in a dynamic lookup manner.
In a possible implementation manner, after the storage address of the interface function is determined in step S501, in step S502, the interface function may be read from the storage address and executed to complete the call of the interface function.
For example, the application includes the following source code, where the interface function intf.saycat () is called three times:
Figure BDA0002797601220000181
the first cache information of the application program is:
0[SubClassA_addr,sayDog_addr]
1[SubClassA_addr,sayCat_addr]
2[SubClassB_addr,sayDog_addr]
3[SubClassB_addr,sayCat_addr]
when the first execution interface function intf.sayCat () is called, the real type of the object intf is SubClassA, and the object intf is matched with a first cache entry '1 [ SubClassA _ addr, sayCat _ addr ]' in the first cache information, so that when the first execution interface function intf.sayCat () is called, the cache can be hit, the storage address of the intf.sayCat () is quickly determined, and the execution efficiency is accelerated.
According to the interface calling method, when the application program is loaded into the memory, the first cache information can be determined according to the storage address of the application program in the memory and the preset second cache information, so that the storage address of the interface function is cached in the first cache information before the interface function is called for the first time, namely the first cache information is prefilled; in the running process of the application program, when the interface function is called, the storage address of the interface function can be determined from the pre-filled first cache information according to the type of the target object calling the interface function, the interface function is read and executed from the storage address, and the calling of the interface function is completed, so that the cache hit rate of the interface function when the interface function is called for the first time can be improved, the number of times of dynamically searching the interface function during running is reduced, and the execution efficiency and the running performance of the application program are improved.
The interface calling method in the embodiment of the application can be used for optimizing the search process of the interface function or the interface method, and can be applied to a plurality of versions of ark compilers, such as the ark compiler 2.0. The components of the emotional operation system EMUI and the programs running on the emotional operation system EMUI are compiled through the ark compiler, so that the performance of the components of the emotional operation system EMUI can be optimized, and the execution efficiency and the running performance of the programs running on the emotional operation system EMUI can be improved.
Fig. 6 is a schematic diagram illustrating a processing procedure of an interface calling method according to an embodiment of the present application. As shown in fig. 6, the processing procedure of the interface calling method may include steps S601 to S609, and may be divided into three stages, i.e., sampling, optimizing and compiling, and running. The sampling stage is used for acquiring calling information of each interface function in the application program, the optimizing and compiling stage is used for generating second cache information, and the running stage is a calling execution stage of the interface function.
Firstly, in a sampling stage, in step S601, a source code of an application program may be sampled and compiled to generate a sampling object code, where in the sampling compilation, a preset sampling code may be inserted behind a calling position of each interface function in the source code during the compilation process, and in step S602, the sampling object code is executed to obtain calling information of each interface function.
After obtaining the calling information of each interface function, entering an optimization compilation stage, in step S603, taking the calling information and the source code of each interface function as the input of the optimization compilation, executing the optimization compilation, and in the process of generating the executable file of the application program by the optimization compilation, the compiler may respectively create a second cache entry corresponding to the calling position of each interface function according to the calling information of each interface function, so as to obtain second cache information. And the second cache information is positioned in the executable file of the application program.
And entering an operation stage after the second cache information is obtained. The operation stage can be divided into a first cache information pre-filling stage (including step S604) and an interface function calling stage (including steps S605 to S609).
In step S604, pre-filling of the first cache information may be performed, and specifically, when the application program is loaded into the memory or the application program is dynamically linked, the second cache information may be updated to the first cache information in a manner of backfilling the storage address according to the storage address of the application program in the memory and the second cache information. Then, in the execution process of the application program, the interface function may be called according to the first cache information, specifically, in step S605, in response to the call of the interface function in the application program, a first cache entry corresponding to the call position of the interface function is determined from the first cache information, and in step S606, it is determined whether the type of the target object calling the interface function is the same as the type in the first cache entry, if so, step S607 is executed to obtain the storage address of the interface function in the first cache entry, otherwise, step S608 is executed to dynamically search the storage address of the interface function. After the memory address of the interface function is acquired in step S607 or S608, the interface function may be read from the memory address and executed in step S609 to complete the call of the interface function.
In this embodiment, call information of each interface function in an application program is obtained through sampling and compiling, second cache information is generated through optimized compiling, and according to the second cache information, when the application program is loaded into a memory or when the application program is dynamically linked, the first cache information is pre-filled, so that when the application program calls the interface function for the first time, a storage address of the interface function can be quickly determined through the pre-filled first cache information, the cache hit rate of the interface function when the interface function is called for the first time can be improved, the number of times of dynamically searching the interface function during running is reduced, and further the execution efficiency and the running performance of the application program are improved.
In a possible implementation manner, in order to facilitate the execution of the sampling compilation and the optimization compilation, a sampling compilation shortcut and an optimization compilation shortcut may be added to an operation interface of a compiler. The shortcuts may include toolbar buttons, menu lists, shortcuts, and the like, which are not limited in this application.
FIG. 7 is a diagram illustrating an interface for operating a compiler according to an embodiment of the present application. As shown in fig. 7, a sample button 720 and an optimize compile button 730 may be added to a toolbar 710 of the compiler operation interface 700. When the sampling button is triggered, step S601 and step S602 in fig. 6 are executed, and when the optimized compiling button 730 is triggered, step S603 in fig. 6 is executed.
Fig. 8 is a schematic diagram illustrating an execution effect of an interface calling method according to an embodiment of the present application. As shown in fig. 8, art (android runtime) represents an average search time of an interface function when a preset interface test set is executed on a runtime environment of the android system. MAPLE (multiple Architecture Programming Language Environment) represents a ark compiler, and MAPLE-RT (MAPLE-RunTime) represents the average lookup time of an interface function when the interface test set is executed on a MAPLE running environment without using the interface calling method of the embodiment of the present application, and MAPLE-RT is about one time slower than ART. MAPLE-OPT-RT (MAPLE-optimization-RunTime) represents the average lookup time of the interface function when the interface test set is executed on the MAPLE running environment after the interface calling method of the application, and MAPLE-OPT-RT is more than twice as fast as ART. Therefore, after the interface calling method of the embodiment of the application is used, the average search time of the interface function is obviously reduced, and the running performance of the application program is obviously improved.
In another embodiment, the interface execution time using the interface calling method of the embodiment of the present application and the interface execution time not using the interface calling method of the embodiment of the present application may be respectively tested, and the test result is analyzed, as specifically shown in table 2 below, where the interface execution time 1 represents the interface execution time when the interface calling method of the embodiment of the present application is used, and the interface execution time 2 represents the interface execution time when the interface calling method of the embodiment of the present application is not used.
Table 2 interface execution time comparison
Figure BDA0002797601220000201
As can be seen from table 2, the interface execution times using the interface calling method according to the embodiment of the present application are all reduced to different degrees, so that the operation performance is improved.
In a possible implementation manner, when determining whether an application uses the interface calling method of the embodiment of the present application, it may be first determined whether a calling location of an interface function of the application is associated with a cache table by an executable file of the reverse application, and if there is an associated cache table, it may be determined whether classIndex and methodIndex values stored in the cache table of the executable file have obvious identifying characteristics, instead of an unordered binary sequence. If classIndex and methodIndex values have obvious identifying characteristics, the application is considered to use the interface calling method of the embodiment of the application. Typically, the identification features of classIndex and methodIndex are: the classIndex has a value of less than 100000 and the methodIndex has a value of less than 2000.
For example, when determining whether an application uses the interface call method of the embodiment of the present application, binary codes of the application may be analyzed, and if the interface call method of the embodiment of the present application is used, an obvious address fetching operation may be found at a call position of an interface function, where a specific behavior characteristic is "fixed address + offset". For example:
the address fetch operation one:
adrp x0,
__inline_cache_table$$_home_l00510180_usr1_mapleSDK_maple_sdk_0706_3_gconly_deve co_build_apk_unzip_helloworld_classes2_dex+48;
and (5) address fetching operation II:
adrp x0,
__inline_cache_table$$_home_l00510180_usr1_mapleSDK_maple_sdk_0706_3_gconly_deve co_build_apk_unzip_helloworld_classes2_dex+40。
as can be seen from the two address fetching operations, the fixed addresses of the two address fetching operations are both storage addresses of the cache table:
__inline_cache_table$$_home_l00510180_usr1_mapleSDK_maple_sdk_0706_3_gconly_deveco_build_apk_unzip_helloworld_classes2_dex,
the offsets of the corresponding cache tables are different for different interface function calls only, the offset being 48 for the first address fetch operation and 40 for the second address fetch operation.
Furthermore, the data stored in the cache table should also have a certain regularity, for example, for the following cache table:
__inline_cache_table$$_home_l00510180_usr1_mapleSDK_maple_sdk_0706_3_gconly_deveco_build_apk_unzip_helloworld_classes2_dex,
the [ classIndex, methodIndex ] in the binary content has a certain rule: classIndex <100000, methodIndex < 2000.
By the address operation and the rule of the data stored in the cache table, whether the application program uses the interface calling method of the embodiment of the application can be determined.
Fig. 9 shows a block diagram of an interface invoking device according to an embodiment of the present application. As shown in fig. 9, the interface calling apparatus is applied to the first device 10, and includes:
the address obtaining module 91, in response to the call of an interface function in an application program, determines a storage address of the interface function according to the type of a target object calling the interface function and the first cache information;
an execution module 92 for reading the interface function from the memory address and executing the interface function,
wherein the first cache information is determined according to a storage address of the application program in the memory and preset second cache information when the application program is loaded to the memory,
the second cache information comprises a plurality of second cache entries, each second cache entry corresponds to the calling position of one interface function, and the second cache entries comprise the identification of the type of the object calling the interface function and the identification of the interface function in the function table of the type.
In a possible implementation manner, the first cache information includes a plurality of first cache entries, the first cache entries correspond to the second cache entries, and the first cache entries include a storage address of a type to which an object that calls an interface function belongs and a storage address of the interface function.
In one possible implementation, the apparatus further includes: the calling information determining module is used for determining calling information of each interface function in the application program, wherein the calling information comprises a calling position identifier of the interface function, an identifier of a type to which an object calling the interface function belongs and an identifier of the interface function in a function table of the type; and the cache information determining module is used for determining second cache information according to the calling information of each interface function.
In a possible implementation manner, the calling information determining module includes: the sampling compiling submodule is used for sampling and compiling the source code of the application program to generate a sampling object code, and the sampling compiling is used for inserting preset sampling codes behind the calling positions of all interface functions in the source code in the compiling process; and the sampling execution submodule is used for executing the sampling object code to obtain the calling information of each interface function.
In a possible implementation manner, the cache information determining module includes: and the cache information determining submodule is used for respectively creating second cache entries corresponding to the calling positions of the interface functions according to the calling information of the interface functions to obtain second cache information in the process of compiling the source code to generate the executable file of the application program, wherein the second cache information is located in the executable file.
In a possible implementation manner, the address obtaining module 91 includes: the cache entry determining submodule is used for determining a first cache entry corresponding to the calling position of the interface function from the first cache information; and the storage address determining submodule is used for acquiring the storage address of the interface function in the first cache entry under the condition that the type of the target object for calling the interface function is the same as the type in the first cache entry.
In one possible implementation, the call location of each interface function corresponds to at least one second cache entry.
In a possible implementation manner, the second cache information is updated to the first cache information by means of backfilling of the storage address.
In one possible implementation manner, the executable file of the application program is generated by compiling through a arklet compiler, and the application program comprises components of the emotional operating system EMUI and a program running on the emotional operating system EMUI.
An embodiment of the present application provides an interface calling apparatus, including: a processor and a memory for storing processor-executable instructions; wherein the processor is configured to implement the above method when executing the instructions.
Embodiments of the present application provide a non-transitory computer readable storage medium having stored thereon computer program instructions which, when executed by a processor, implement the above-described method.
Embodiments of the present application provide a computer program product comprising computer readable code, or a non-transitory computer readable storage medium carrying computer readable code, which when run in a processor of an electronic device, the processor in the electronic device performs the above method.
The computer readable storage medium may be a tangible device that can hold and store the instructions for use by the instruction execution device. The computer readable storage medium may be, for example, but not limited to, an electronic memory device, a magnetic memory device, an optical memory device, an electromagnetic memory device, a semiconductor memory device, or any suitable combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: a portable computer diskette, a hard disk, a Random Access Memory (RAM), a Read-Only Memory (ROM), an erasable Programmable Read-Only Memory (EPROM or flash Memory), a Static Random Access Memory (SRAM), a portable Compact Disc Read-Only Memory (CD-ROM), a Digital Versatile Disc (DVD), a Memory stick, a floppy disk, a mechanical coding device, such as a punch card or in-groove bump structure having instructions stored thereon, and any suitable combination of the foregoing.
The computer readable program instructions or code described herein may be downloaded to the respective computing/processing device from a computer readable storage medium, or to an external computer or external storage device via a network, such as the internet, a local area network, a wide area network, and/or a wireless network. The network may include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers and/or edge servers. The network adapter card or network interface in each computing/processing device receives computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in a computer-readable storage medium in the respective computing/processing device.
The computer program instructions for carrying out operations of the present application may be assembler instructions, Instruction Set Architecture (ISA) instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including an object oriented programming language such as Smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The computer-readable program instructions may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of Network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider). In some embodiments, the electronic circuitry can execute computer-readable program instructions to implement aspects of the present application by utilizing state information of the computer-readable program instructions to personalize custom electronic circuitry, such as Programmable Logic circuits, Field-Programmable Gate arrays (FPGAs), or Programmable Logic Arrays (PLAs).
Various aspects of the present application are described herein with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the application. It will be understood that each block of the flowchart illustrations and/or block diagrams, and combinations of blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer-readable program instructions.
These computer-readable program instructions may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions/acts specified in the flowchart and/or block diagram block or blocks. These computer readable program instructions may also be stored in a computer readable storage medium that can direct a computer, programmable data processing apparatus, and/or other devices to function in a particular manner, such that the computer readable medium storing the instructions comprises an article of manufacture including instructions which implement the function/act specified in the flowchart and/or block diagram block or blocks.
The computer readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other devices to cause a series of operational steps to be performed on the computer, other programmable apparatus or other devices to produce a computer implemented process such that the instructions which execute on the computer, other programmable apparatus or other devices implement the functions/acts specified in the flowchart and/or block diagram block or blocks.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of instructions, which comprises one or more executable instructions for implementing the specified logical function(s). In some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved.
It is also noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by hardware (e.g., a Circuit or an ASIC) for performing the corresponding function or action, or by combinations of hardware and software, such as firmware.
While the invention has been described in connection with various embodiments, other variations to the disclosed embodiments can be understood and effected by those skilled in the art in practicing the claimed invention, from a review of the drawings, the disclosure, and the appended claims. In the claims, the word "comprising" does not exclude other elements or steps, and the word "a" or "an" does not exclude a plurality. A single processor or other unit may fulfill the functions of several items recited in the claims. The mere fact that certain measures are recited in mutually different dependent claims does not indicate that a combination of these measures cannot be used to advantage.
The foregoing description of the embodiments of the present application has been presented for purposes of illustration and description and is not intended to be exhaustive or limited to the embodiments disclosed. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen in order to best explain the principles of the embodiments, the practical application, or improvements made to the technology in the marketplace, or to enable others of ordinary skill in the art to understand the embodiments disclosed herein.

Claims (20)

1. An interface calling method, comprising:
responding to the calling of an interface function in an application program, and determining a storage address of the interface function according to the type of a target object calling the interface function and first cache information;
reading the interface function from the memory address and executing the interface function,
wherein the first cache information is determined according to a storage address of the application program in the memory and preset second cache information when the application program is loaded to the memory,
the second cache information comprises a plurality of second cache entries, each second cache entry corresponds to the calling position of one interface function, and the second cache entries comprise the identification of the type of the object calling the interface function and the identification of the interface function in the function table of the type.
2. The method of claim 1, wherein the first cache information comprises a plurality of first cache entries, wherein the first cache entries correspond to the second cache entries, and wherein the first cache entries comprise a storage address of a type to which an object that calls an interface function belongs and a storage address of the interface function.
3. The method of claim 1, further comprising:
determining calling information of each interface function in the application program, wherein the calling information comprises calling position identification of the interface function, identification of a type to which an object calling the interface function belongs and identification of the interface function in a function table of the type;
and determining second cache information according to the calling information of each interface function.
4. The method of claim 3, wherein the determining the calling information of each interface function in the application program comprises:
sampling and compiling the source code of the application program to generate a sampling object code, wherein the sampling and compiling is used for inserting preset sampling codes behind the calling positions of all interface functions in the source code in the compiling process;
and executing the sampling target code to obtain the calling information of each interface function.
5. The method according to claim 4, wherein the determining second cache information according to the call information of each interface function comprises:
in the process of compiling the source code to generate the executable file of the application program, respectively creating second cache entries corresponding to the calling positions of the interface functions according to the calling information of the interface functions to obtain second cache information,
wherein the second cache information is located in the executable file.
6. The method according to claim 1, wherein the determining the storage address of the interface function according to the type of the target object calling the interface function and the first cache information comprises:
determining a first cache entry corresponding to the calling position of the interface function from the first cache information;
and under the condition that the type of the target object for calling the interface function is the same as the type in the first cache entry, acquiring the storage address of the interface function in the first cache entry.
7. The method of claim 1, wherein the call location of each interface function corresponds to at least one second cache entry.
8. The method of claim 1, wherein the second cache information is updated to the first cache information by backfilling the memory address.
9. The method according to any one of claims 1 to 8, wherein the executable file of the application program is generated by compiling a canoe compiler, and the application program comprises a component of an emotional operating system EMUI and a program running on the emotional operating system EMUI.
10. An interface invocation apparatus, comprising:
the address acquisition module responds to the calling of an interface function in an application program and determines a storage address of the interface function according to the type of a target object calling the interface function and first cache information;
an execution module to read the interface function from the memory address and execute the interface function,
wherein the first cache information is determined according to a storage address of the application program in the memory and preset second cache information when the application program is loaded to the memory,
the second cache information comprises a plurality of second cache entries, each second cache entry corresponds to the calling position of one interface function, and the second cache entries comprise the identification of the type of the object calling the interface function and the identification of the interface function in the function table of the type.
11. The apparatus of claim 10, wherein the first cache information comprises a plurality of first cache entries, wherein the first cache entries correspond to the second cache entries, and wherein the first cache entries comprise a storage address of a type to which an object that calls an interface function belongs and a storage address of the interface function.
12. The apparatus of claim 10, further comprising:
the calling information determining module is used for determining calling information of each interface function in the application program, wherein the calling information comprises a calling position identifier of the interface function, an identifier of a type to which an object calling the interface function belongs and an identifier of the interface function in a function table of the type;
and the cache information determining module is used for determining second cache information according to the calling information of each interface function.
13. The apparatus of claim 12, wherein the invocation information determining module comprises:
the sampling compiling submodule is used for sampling and compiling the source code of the application program to generate a sampling object code, and the sampling compiling is used for inserting preset sampling codes behind the calling positions of all interface functions in the source code in the compiling process;
and the sampling execution submodule is used for executing the sampling object code to obtain the calling information of each interface function.
14. The apparatus of claim 13, wherein the cache information determining module comprises:
a cache information determining submodule, configured to create, according to the call information of each interface function, a second cache entry corresponding to the call position of each interface function to obtain second cache information in the process of compiling the source code to generate the executable file of the application program,
wherein the second cache information is located in the executable file.
15. The apparatus of claim 10, wherein the address obtaining module comprises:
the cache entry determining submodule is used for determining a first cache entry corresponding to the calling position of the interface function from the first cache information;
and the storage address determining submodule is used for acquiring the storage address of the interface function in the first cache entry under the condition that the type of the target object for calling the interface function is the same as the type in the first cache entry.
16. The apparatus of claim 10, wherein the call location of each interface function corresponds to at least one second cache entry.
17. The apparatus of claim 10, wherein the second cache information is updated to the first cache information by backfilling the memory address.
18. The apparatus according to any one of claims 10 to 17, wherein the executable file of the application program is generated by compiling by a arklet compiler, and the application program comprises components of an emotional operating system EMUI and a program running on the emotional operating system EMUI.
19. An interface invocation apparatus, comprising:
a processor;
a memory for storing processor-executable instructions;
wherein the processor is configured to implement the method of any one of claims 1-9 when executing the instructions.
20. A non-transitory computer readable storage medium having computer program instructions stored thereon, wherein the computer program instructions, when executed by a processor, implement the method of any of claims 1-9.
CN202011337494.4A 2020-11-25 2020-11-25 Interface calling method and device and storage medium Pending CN114610417A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011337494.4A CN114610417A (en) 2020-11-25 2020-11-25 Interface calling method and device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011337494.4A CN114610417A (en) 2020-11-25 2020-11-25 Interface calling method and device and storage medium

Publications (1)

Publication Number Publication Date
CN114610417A true CN114610417A (en) 2022-06-10

Family

ID=81857126

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011337494.4A Pending CN114610417A (en) 2020-11-25 2020-11-25 Interface calling method and device and storage medium

Country Status (1)

Country Link
CN (1) CN114610417A (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130061007A1 (en) * 2011-09-02 2013-03-07 International Business Machines Corporation Generating code that calls functions based on types of memory
CN109426570A (en) * 2017-08-29 2019-03-05 阿里巴巴集团控股有限公司 A kind of acquisition methods of data, device and equipment

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130061007A1 (en) * 2011-09-02 2013-03-07 International Business Machines Corporation Generating code that calls functions based on types of memory
CN109426570A (en) * 2017-08-29 2019-03-05 阿里巴巴集团控股有限公司 A kind of acquisition methods of data, device and equipment

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
TAQUANGTU: "Address of a method of an object in C++", Retrieved from the Internet <URL:https://stackoverflow.com/questions/46190709/address-of-a-method-of-an-object-in-c> *
华为云开发者联盟: "编译器优化丨Cache优化", Retrieved from the Internet <URL:https://www.cnblogs.com/huaweiyun/p/16944502.html> *

Similar Documents

Publication Publication Date Title
WO2021057868A1 (en) Interface switching method and electronic device
JP2023514631A (en) Interface layout method, apparatus and system
CN111666055B (en) Data transmission method and device
CN113157230A (en) Data transmission method and related equipment
CN114520868B (en) Video processing method, device and storage medium
CN115623115B (en) Method, device, system and storage medium for creating application shortcut across devices
EP4407421A1 (en) Device collaboration method and related apparatus
CN112835495B (en) Method and device for opening application program and terminal equipment
CN111125602B (en) Page construction method, device, equipment and storage medium
US20220292141A1 (en) Quick Application Startup Method and Related Apparatus
CN114489429B (en) Terminal equipment, long screen capturing method and storage medium
US20240220184A1 (en) Screen projection method and related apparatus
CN114520867B (en) Camera control method based on distributed control and terminal equipment
CN116954409A (en) Application display method and device and storage medium
CN114610417A (en) Interface calling method and device and storage medium
CN116028148A (en) Interface processing method and device and electronic equipment
CN115113832A (en) Cross-device synchronous display control method and system
CN116700554B (en) Information display method, electronic device and readable storage medium
US20240129619A1 (en) Method and Apparatus for Performing Control Operation, Storage Medium, and Control
CN114513760B (en) Font library synchronization method, device and storage medium
CN113535137A (en) Method, device and related product for loading and running application program
CN113448858A (en) Class conflict detection method, device, equipment and readable storage medium
CN116450228A (en) Method for running application program and electronic device
CN117806744A (en) Control display method and electronic equipment
CN116700811A (en) Application running method and related device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination