CN117369861A - Thread management policy configuration method and related device for application program - Google Patents

Thread management policy configuration method and related device for application program Download PDF

Info

Publication number
CN117369861A
CN117369861A CN202311301671.7A CN202311301671A CN117369861A CN 117369861 A CN117369861 A CN 117369861A CN 202311301671 A CN202311301671 A CN 202311301671A CN 117369861 A CN117369861 A CN 117369861A
Authority
CN
China
Prior art keywords
thread
target
information
binary
class
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
CN202311301671.7A
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.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen 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 Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN202311301671.7A priority Critical patent/CN117369861A/en
Publication of CN117369861A publication Critical patent/CN117369861A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/71Version control; Configuration management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/52Binary to binary
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

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

Abstract

The embodiment of the application provides a thread management policy configuration method and a related device for an application program, and relates to the technical field of computers and clouds. The method comprises the following steps: identifying thread realization calling information in a first binary file to determine calling position information corresponding to the thread realization calling information, positioning the thread realization calling information in the first binary file based on the calling position information, marking target class indication information at a position indicated by the calling position information to obtain a second binary file, acquiring target thread management byte codes based on the target class information marked in the second binary file, and updating the target thread management byte codes to the marked position of the target class information in the second binary file to obtain a target binary file corresponding to an application program, thereby solving the technical problem that the configuration efficiency of a thread management strategy in the related art is quite low, and improving the configuration efficiency of the thread management strategy.

Description

Thread management policy configuration method and related device for application program
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and an apparatus for configuring a thread management policy of an application program.
Background
A thread (thread) is the smallest unit that an operating system can schedule for operations. It is included in the process and is the actual unit of operation in the process. One thread refers to a single sequential control flow in a process, and multiple threads may be concurrent in a process, each thread executing different tasks of an application in parallel. In order to enable smooth task running, the thread needs to be treated. Thread governance generally refers to managing thread operations through unified scheduling and resource pool techniques, normalizing and regulating thread operations.
In the related technology, in order to realize the use and management of threads in source codes, generally, an developer is allowed to manually search for the thread related realization developer to search for and locate the thread related realization, and then write the thread management related code, thereby realizing the use and management of project use threads at the source code level. And the developer performs source code compiling and constructing to obtain project products and release the project products. And running the application program, and enabling the thread management logic to take effect when the business module executes the trigger application thread logic.
However, after the developer searches and locates the thread-related implementation, the developer writes the thread-management-related code, and the configuration efficiency of the thread management policy is quite low.
Disclosure of Invention
The embodiment of the application provides a thread management policy configuration method and a related device for an application program, which are used for solving the technical problem that the configuration efficiency of the thread management policy in the related technology is quite low and can improve the configuration efficiency of the thread management policy.
In one aspect, an embodiment of the present application provides a method for configuring a thread management policy of an application program, including:
identifying thread realization calling information in a first binary file to determine calling position information corresponding to the thread realization calling information, wherein the thread realization calling information is used for calling a thread, the calling position information is used for indicating the position of the thread realization calling information in the first binary file, and the first binary file is compiled by a source code file of an application program;
positioning the thread realization calling information in the first binary file based on the calling position information, identifying the target thread class of the thread called by the positioned thread realization calling information, and marking target class indication information at the position indicated by the calling position information to obtain a second binary file, wherein the target class indication information is used for indicating the target thread class;
And acquiring a target thread management byte code based on the target class information marked in the second binary file, and updating the target thread management byte code to the marked position of the target class information in the second binary file to obtain a target binary file corresponding to the application program, wherein the target thread management byte code is configured as a management thread.
On the other hand, the embodiment of the application also provides a thread management policy configuration device of the application program, which comprises:
the thread identification module is used for identifying thread realization calling information in the first binary file to determine calling position information corresponding to the thread realization calling information, wherein the thread realization calling information is used for calling a thread, the calling position information is used for indicating the position of the thread realization calling information in the first binary file, and the first binary file is obtained by compiling a source code file of an application program;
the thread marking module is used for positioning the thread realization calling information in the first binary file based on the calling position information, identifying the target thread category of the thread called by the positioned thread realization calling information, marking target category indication information at the position indicated by the calling position information to obtain the second binary file, wherein the target category indication information is used for indicating the target thread category;
The thread management module is used for acquiring target thread management byte codes based on the target category information marked in the second binary file, updating the target thread management byte codes to the marked position of the target category information in the second binary file to obtain a target binary file corresponding to the application program, and the target thread management byte codes are configured to manage threads.
Alternatively, the thread identification module, when identifying thread implementation call information in the first binary, may be configured to either:
acquiring a first binary file obtained after compiling a source code file of an application program is finished, and identifying thread realization calling information in the first binary file obtained after compiling is finished;
and in the process of compiling the source code file of the application program, acquiring a first binary file obtained by compiling part of source codes, and identifying thread realization calling information in the first binary file obtained by compiling part of source codes.
Optionally, the first binary file is stored in the compiled directory, and when identifying the thread implementation call information in the first binary file to determine call location information corresponding to the thread implementation call information, the thread identification module may be configured to:
Reading a first binary file from the compiled catalog through a class reading interface of the byte code editing tool;
traversing the first binary file through a class access interface of the byte code editing tool to determine thread realization calling information in the first binary file, and determining the position of the thread realization calling information as calling position information corresponding to the thread realization calling information.
Optionally, when the class access interface of the bytecode editing tool traverses the first binary file to determine the thread implementation call information in the first binary file, the thread identification module may be configured to:
traversing the first binary file through the class access interface to determine byte code information in the first binary file, wherein the byte code information comprises a first target parameter, and the first target parameter is used for representing an inherited parent class;
if the first target parameter comprises a thread identification keyword, determining byte code information comprising the first target parameter as thread realization information, and searching a second target parameter and a third target parameter from call information defined by the thread realization information through a class access interface, wherein the second target parameter is used for representing a class to which the second target parameter belongs, and the third target parameter is used for representing the name of the class;
And if at least one of the second target parameter or the parent class of the second target parameter comprises a thread identification keyword and the third target parameter comprises a thread start identifier, determining call information defined by the thread realization information as thread realization call information.
Optionally, when identifying the target thread class of the thread called by the located thread implementation calling information, the thread marking module may be configured to:
acquiring a method binary instruction from the positioned thread realization calling information through a class access interface of a byte code editing tool;
and determining the target thread category of the thread called by the thread realization calling information based on the instruction return value of the method binary instruction and the instruction name of the method binary instruction.
Optionally, the thread marking module may be configured to determine, based on the instruction return value of the method binary instruction and the instruction name of the method binary instruction, a target thread class of the thread called by the thread implementation calling information, where the target thread class is at least one of:
if the instruction return value of the method binary instruction is the target return value and the instruction name of the method binary instruction comprises at least one of a first thread category keyword or a second thread keyword, determining that the target thread category is a main thread Cheng Leibie;
If the instruction return value of the method binary instruction is not the target return value and the instruction name of the method binary instruction comprises other keywords, determining the target thread type as the input/output thread type, wherein the other keywords are different from the first thread type keywords and the second thread keywords;
if the instruction return value of the method binary instruction is not the target return value and the instruction name of the method binary instruction is null, determining the target thread class as the cache thread class.
Optionally, when the thread marking module marks the target class indication information at the location indicated by the call location information, the thread marking module may be configured to:
detecting whether target class indication information is marked at a position indicated by calling position information through a class access interface of a byte code compiling tool;
and in the case that the condition that the target class indication information is not marked at the position indicated by the calling position information is detected, marking the target class indication information at the position indicated by the calling position information through a class writing interface of a byte code compiling tool.
Optionally, the target class information includes a target binary character, and when the thread management module obtains the target thread management byte code based on the target class information marked in the second binary file, the thread management module may be configured to:
Acquiring a first mapping relation, wherein the first mapping relation is used for representing the mapping relation between binary characters and thread management byte codes, and the thread management byte codes are obtained by compiling source codes configured as management threads;
and determining a matched binary character matched with the target binary character from the first mapping relation, and determining the thread management byte code mapped by the matched binary character as a target thread management byte code.
Optionally, the target thread management bytecode is configured with a thread management parameter or is not configured with a thread management parameter;
if the target thread management bytecode is not configured with the target thread management parameter, the thread management module is further configured to:
acquiring a second mapping relation which is used for representing the mapping relation between the binary character and the thread management parameter;
determining a matched binary character matched with the target binary character from the second mapping relation, and determining a thread management parameter mapped by the matched binary character as a target thread management parameter;
and writing the target thread management parameters into the target thread management byte codes.
In another aspect, embodiments of the present application further provide an electronic device including a memory, a processor, and a computer program stored on the memory, the processor executing the computer program to perform the steps of the method of any of the embodiments of the present application.
In another aspect, embodiments of the present application further provide a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the method of any of the embodiments of the present application.
In another aspect, embodiments of the present application also provide a computer program product comprising a computer program which, when executed by a processor, implements the steps of the method of any of the embodiments of the present application.
According to the technical scheme, the calling information is realized by identifying the thread in the first binary file, so that the calling position information corresponding to the thread realization calling information is determined, the thread realization calling information is used for calling the thread, the calling position information is used for indicating the position of the thread realization calling information in the first binary file, and the first binary file is obtained by compiling the source code file of the application program; positioning the thread realization calling information in the first binary file based on the calling position information, identifying the target thread class of the thread called by the positioned thread realization calling information, and marking target class indication information at the position indicated by the calling position information to obtain a second binary file, wherein the target class indication information is used for indicating the target thread class; based on the target category information marked in the second binary file, the target thread management byte codes are obtained and updated to the marked position of the target category information in the second binary file, so that the target binary file corresponding to the application program is obtained, the target thread management byte codes are configured to manage threads, thereby automatically identifying threads and inserting the thread management byte codes, reducing the configuration complexity of the thread management strategy, directly inserting the thread management byte codes, wherein the inserted thread management byte codes are compiled, reducing the compiling time of the thread management byte codes, and improving the efficiency. In addition, as thread identification and thread management byte code insertion are performed on the binary file, codes are used for threads contained in the binary dependency library, and thread governance can be performed on the threads, so that adaptability is improved. In addition, the source code can be modified in an invasive way, so that the stability of the source code operation can be improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings that are required to be used in the description of the embodiments of the present application will be briefly described below.
FIG. 1 is a flow chart of thread use and management in source code in the related art according to an embodiment of the present application;
FIG. 2 is a schematic diagram of an implementation environment of a method for configuring a thread management policy of an application according to an embodiment of the present application;
FIG. 3 is a flowchart of a method for configuring a thread management policy of an application according to an embodiment of the present application;
fig. 4 is a schematic diagram of a preparation flow before a main flow of the present embodiment starts;
FIG. 5 is a flowchart of another method for configuring a thread management policy of an application according to an embodiment of the present application;
FIG. 6 is a schematic flow chart of thread identification according to an embodiment of the present application;
FIG. 7 is a schematic flow chart of a thread marking according to an embodiment of the present application;
FIG. 8 is a schematic diagram of a thread management code implantation process according to an embodiment of the present application;
fig. 9 is a schematic structural diagram of a thread management policy configuration device for an application according to an embodiment of the present application;
Fig. 10 is a schematic structural diagram of a Gradle plug-in module according to an embodiment of the present application;
fig. 11 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
Embodiments of the present application are described below with reference to the drawings in the present application. It should be understood that the embodiments described below with reference to the drawings are exemplary descriptions for explaining the technical solutions of the embodiments of the present application, and the technical solutions of the embodiments of the present application are not limited.
As used herein, the singular forms "a", "an", and "the" are intended to include the plural forms as well, unless expressly stated otherwise, as understood by those skilled in the art. It will be further understood that the terms "comprises" and "comprising," when used in this application, specify the presence of stated features, information, data, steps, operations, elements, and/or components, but do not preclude the presence or addition of other features, information, data, steps, operations, elements, components, and/or groups thereof, all of which may be included in the present application. It will be understood that when an element is referred to as being "connected" or "coupled" to another element, it can be directly connected or coupled to the other element or intervening elements may be present. Further, "connected" or "coupled" as used herein may include wirelessly connected or wirelessly coupled. The term "and/or" as used herein indicates at least one of the items defined by the term, e.g. "a and/or B" indicates implementation as "a", or as "a and B".
For the purpose of making the objects, technical solutions and advantages of the present application more apparent, the embodiments of the present application will be described in further detail below with reference to the accompanying drawings.
Referring to fig. 1, fig. 1 is a schematic flow chart of using and managing threads in source code in the related art according to an embodiment of the present application. The method as shown in fig. 1 may include:
step one: in the current scheme, in order to realize the use and management of threads in source codes, an developer is generally allowed to manually search for the related realization of the threads from source code files.
Step two: after the developer searches and positions the thread related realization, writing thread management related codes, and realizing the use and management of project use threads at the source code level.
Step three: and the developer performs source code compiling and constructing to obtain project products and release the project products.
Step four: the user runs the application program, and when the business module executes the trigger application thread logic, the thread management logic takes effect.
It can be understood that in the related technical scheme, the method for thread management is generally implemented by writing codes in project source codes, so that on one hand, the process of manually searching for the application of the threads in the source code file is complicated, and on the other hand, the efficiency of associating the application of the threads with the management of the threads is low. In addition, since the developer mainly configures thread instructions for source codes, and uses codes for threads contained in the binary dependency library, thread governance cannot be performed. In addition, invasive modification of the source code is required, which may cause unstable operation of the source code.
It can be appreciated that the technical solution of the present embodiment may be applicable to a situation where the thread management policy needs to be frequently adjusted. Specifically, in the related art, each update or modification needs to be performed on the source code, and the source code is recompiled after the update or modification is completed. Therefore, when the thread management policy is updated frequently, that is, the source code is updated and modified frequently, each time the source code is modified, and it takes more time to compile after the source code is modified, which increases the time for updating or modifying the thread management policy.
Therefore, in order to address at least one technical problem or a place needing improvement in the related art, the application proposes a method and a related device for configuring a thread management policy of an application program, in the scheme, through identifying thread implementation calling information for calling threads in a first binary file, so as to determine calling position information corresponding to the thread implementation calling information for indicating the position of the thread implementation calling information in the first binary file, then, positioning the thread implementation calling information in the first binary file based on the calling position information, identifying a target thread type of the thread called by the positioned thread implementation calling information, and marking target type indicating information for indicating the target thread type at the position indicated by the calling position information, so as to obtain a second binary file, acquiring target thread management byte codes configured as management threads based on the target type information marked in the second binary file, and updating the target thread management byte codes to the mark of the target type information in the second binary file, so as to obtain the target binary file corresponding to the application program, thereby improving the configuration efficiency of the thread management policy can be realized.
Alternatively, the present application may relate to cloud technology. For example, the thread management code is stored by the cloud, and for example, the method of the embodiments of the present application is performed by the cloud server.
The Cloud technology (Cloud technology) is based on the general terms of network technology, information technology, integration technology, management platform technology, application technology and the like applied by a Cloud computing business model, can form a resource pool, is used as required, and is flexible and convenient. Cloud computing technology will become an important support. The cloud storage (cloud storage) is a new concept that extends and develops in the concept of cloud computing, and the distributed cloud storage system (hereinafter referred to as a storage system for short) refers to a storage system that provides data storage and target service access functions for the outside through functions such as cluster application, grid technology, and distributed storage file system, and a large number of storage devices (storage devices are also referred to as storage nodes) of different types in a network are combined to cooperate through application software or an application interface.
The technical solutions of the embodiments of the present application and technical effects produced by the technical solutions of the present application are described below by describing several exemplary embodiments. It should be noted that the following embodiments may be referred to, or combined with each other, and the description will not be repeated for the same terms, similar features, similar implementation steps, and the like in different embodiments.
Referring to fig. 2, fig. 2 is a schematic diagram of an implementation environment of a thread management policy configuration method for an application according to an embodiment of the present application. The method of the present embodiment may be applied to the implementation environment schematic diagram shown in fig. 2. Wherein the terminal 210 communicates with the server 220 through a network. The data storage system may store data that server 220 needs to process. The data storage system may be integrated on server 220 or may be located on a cloud or other network server.
In this embodiment, the data storage system may be configured to store relevant data of the present scheme, such as at least one of the first mapping relationship, the second mapping relationship, or the thread management bytecode.
Specifically, the source code may be input through the terminal 210, and the thread management policy configuration method of the application program in the embodiment of the present application is executed through the server 220; the thread management policy configuration method for executing the application program of the embodiment of the present application by the terminal 210 is not limited herein.
The terminal 210 may be, but not limited to, various personal computers, notebook computers, smart phones, tablet computers, internet of things devices and portable wearable devices, and the internet of things devices may be smart speakers, smart televisions, smart air conditioners, smart vehicle devices, etc. The portable wearable device may be a smart watch, smart bracelet, headset, or the like. Server 220 may be implemented as a stand-alone server or as a cluster of servers.
Referring to fig. 3, fig. 3 is a flowchart of a thread management policy configuration method for an application according to an embodiment of the present application. The method as shown in fig. 3 may be applied to an electronic device, which may include, but is not limited to, at least one of a terminal or a server. The method as shown in fig. 3 may include:
s310, identifying thread realization calling information in the first binary file to determine calling position information corresponding to the thread realization calling information, wherein the thread realization calling information is used for calling a thread, and the calling position information is used for indicating the position of the thread realization calling information in the first binary file.
The first binary file is obtained by compiling a source code file of the application program. In particular, source code may refer to high-level code or assembly code generated by a programmer. The source code is easy to read and modify. It is written by a programmer in any readable high-level or medium-level language. The source code contains comments that are made by the programmer for better understanding. The source code is provided to a language translator, which converts it into machine-understandable code, referred to as machine code or object code. The computer cannot understand the direct source code, calculate the mechanism solution machine code and execute it. It is considered to be an essential component of a computer. Briefly, we can say that source code is a set of instructions/commands and statements written by a programmer using a computer programming language such as C, C ++, java, python, assembly language, and the like. Thus, statements written in any programming language are referred to as source code. Bytecode (binary) is an intermediate code between source code and machine code. It is a low-level code that is the result of compiling source code written in a high-level language. It is handled by a virtual machine like a Java Virtual Machine (JVM).
In this embodiment, the first binary file obtained by compiling a part of the source codes in the source code file may be the first binary file obtained by compiling all the source codes in the source code file, which is not limited herein. An application refers to a computer program that, when run in user mode, can interact with a user to perform a particular task or tasks, with a visual user interface. Source code may refer to the code of the most original program written. In this embodiment, the source code may be code written by a developer. Wherein the programming language in which the source code is written may include, but is not limited to, at least one of C/C++, BASIC, C# or JAVA.
In one possible implementation, identifying thread implementation call information in the first binary file may include:
and acquiring a first binary file obtained after compiling the source code file of the application program, and identifying thread realization calling information in the first binary file obtained after compiling.
In this embodiment, after all the source code files are compiled, a first binary file obtained after the compiling is completed is obtained, and then thread realization calling information in the first binary file obtained after the compiling is completed by identifying the source code files of the application program.
In another possible implementation, identifying the thread implementation call information in the first binary file may include:
and in the process of compiling the source code file of the application program, acquiring a first binary file obtained by compiling part of source codes, and identifying thread realization calling information in the first binary file obtained by compiling part of source codes.
In this embodiment, the thread implementation calling information in the first binary file obtained by compiling a part of source codes can be identified in the process of compiling the source code file, that is, the thread implementation calling information in the first binary file obtained by compiling a part of source codes can be identified while compiling, so that the efficiency of identifying the thread implementation calling information can be improved.
Alternatively, when the source code compiling is executed to the transform stage, the thread identification task is triggered to start, so that the thread realization calling information in the first binary file is identified. Specifically, in the stage of analyzing and converting the source code, the type or value of the node corresponding to the source code after some plug in is executed is changed, but one attribute (the type is SourceLocation) in the node always records the position of the first row and column of the source code, so that row and column information in the source code can be obtained.
S320, positioning the thread realization calling information in the first binary file based on the calling position information, identifying the target thread category of the thread called by the positioned thread realization calling information, and marking the target category indication information at the position indicated by the calling position information to obtain the second binary file.
The target thread type indication information is used for indicating the target thread type. The target thread class may be one of a plurality of preset thread classifications. Alternatively, the plurality of thread classifications may include, but is not limited to, at least one of a main thread, an Input Output (IO) thread, or a cache thread.
In this embodiment, the target class indication information is marked at a location indicated by the call location information in the first binary file, thereby marking the location of the thread implementation call information in the first binary for subsequent insertion of thread management bytecodes configured as management threads. The second binary file may be understood as a binary file obtained by marking the target class indication information at the location indicated by the call location information in the first binary file.
It should be noted that, the identified call location information may be cached in the memory, and when the call location information needs to be located on the thread implementation call information in the first binary file, the call location information cached in the memory may be used to locate the thread implementation call information in the first binary file.
S330, based on the target category information marked in the second binary file, acquiring a target thread management byte code, and updating the target thread management byte code to the marked position of the target category information in the second binary file to obtain a target binary file corresponding to the application program, wherein the target thread management byte code is configured as a management thread.
Wherein the target thread-management bytecode may be one of a plurality of thread-management bytecodes. The target second binary may refer to a binary for which the thread management policy is configured.
In this embodiment, if the second binary file has not been inserted with the thread management bytecode before, updating the target thread management bytecode to the tag of the target class information in the second binary file may refer to inserting the target thread management bytecode to the tag of the target class information in the second binary file. If the old thread management byte code is inserted before the second binary file, the target thread management byte code is updated to the mark of the target class information in the second binary file, and the old thread management byte code inserted at the mark of the target class information can be replaced by the target thread management byte code.
According to the technical scheme, the calling information is realized by identifying the thread in the first binary file, so that the calling position information corresponding to the thread realization calling information is determined, the thread realization calling information is used for calling the thread, the calling position information is used for indicating the position of the thread realization calling information in the first binary file, and the first binary file is obtained by compiling the source code file of the application program; positioning the thread realization calling information in the first binary file based on the calling position information, identifying the target thread class of the thread called by the positioned thread realization calling information, and marking target class indication information at the position indicated by the calling position information to obtain a second binary file, wherein the target class indication information is used for indicating the target thread class; based on the target category information marked in the second binary file, the target thread management byte codes are obtained and updated to the marked position of the target category information in the second binary file, so that the target binary file corresponding to the application program is obtained, the target thread management byte codes are configured to manage threads, thereby automatically identifying threads and inserting the thread management byte codes, reducing the configuration complexity of the thread management strategy, directly inserting the thread management byte codes, wherein the inserted thread management byte codes are compiled, reducing the compiling time of the thread management byte codes, and improving the efficiency. In addition, as thread identification and thread management byte code insertion are performed on the binary file, codes are used for threads contained in the binary dependency library, and thread governance can be performed on the threads, so that adaptability is improved. In addition, the source code can be modified in an invasive way, so that the stability of the source code operation can be improved.
In one possible implementation, the target category information may include target binary characters. Binary characters may refer to one-bit hexadecimal digits of a four-bit binary code.
It will be appreciated that by inserting the target binary character as the target class information, i.e. in the binary file, the target binary character representing the target thread class, the memory space required for the second binary file can be reduced. For example, 00 represents the first thread Cheng Leibie, 01 represents the second thread class, 11 represents the third thread Cheng Leibie, and the like, and is not limited thereto. For another example, a represents the first thread Cheng Leibie, B represents the second thread class, C represents the third thread Cheng Leibie, D represents the fourth thread Cheng Leibie, etc., and may be provided as needed, without limitation.
In one possible implementation manner, the first binary file is stored in a compiling directory, and thread realization calling information in the first binary file is identified to determine calling position information corresponding to the thread realization calling information, including:
reading a first binary file from the compiled catalog through a class reading interface of the byte code editing tool;
traversing the first binary file through a class access interface of the byte code editing tool to determine thread realization calling information in the first binary file, and determining the position of the thread realization calling information as calling position information corresponding to the thread realization calling information.
In this embodiment, optionally, common tools for processing bytecodes include, but are not limited to, at least one of ASM, javasist, or AspectJ. ASM is a Java bytecode manipulation framework. It can modify existing classes in binary form or dynamically generate classes. ASM can directly generate binary class file, and can dynamically change class behavior before class is loaded into Java virtual machine. After the ASM reads information from the class file, class behavior can be changed, class information can be analyzed, and even a new class can be generated according to the user requirements. The class-read interface of the ASM may be a ClassReader class. The class access interface of the ASM may be a classtester. The class write interface of the ASM may be ClassWriter. Javaist is an open source class library that analyzes, edits and creates Java bytecodes, which can be directly edited and generated. With respect to bcel, asm, etc., a developer can dynamically change the structure of a class or dynamically generate a class without knowing the virtual machine instructions. java ssist is simple and easy to use and fast. AspectJ is an implementation of the Java language of AOP, which defines AOP syntax, and has a specialized compiler to generate Class files that adhere to the Java byte encoding specification. Compared with Java sist, aspectJ or reflection, ASM can process each command of byte code at a lower layer, process the speed faster, and occupy less memory.
In general, ASM has two API types: tree API and initiator API.
(1) Tree API: also referred to as an object model. Reading the content of the class into the memory to construct a tree structure, positioning the elements in the tree structure when processing the elements such as the Method and the Field, and finally writing a new class file;
(2) Visitor API: also known as event models. When the corresponding content of the class file is scanned, the corresponding method in the API is called back, and the original class file can be covered after the processing is finished to realize code injection. Several of the core classes are as follows:
ClassReader: analyzing the compiled class file, and acquiring at least one of class names, interfaces, member names, method parameters and the like in the file;
ClassWriter: reconstructing the compiled class for modifying class names, attributes, methods, etc. and generating a new class file;
ClassVisitor: class information is accessed. Including at least one of notes marked on the class, class construction methods, class fields, class methods, or static code blocks, etc.;
AdviceAdapter: the method and the device realize a method identifier interface and mainly access information of a method. The method is used for carrying out byte code operation on a specific method;
FieldVisitor: accessing a specific class member;
AnnogionVisitor: specific annotation information is accessed.
It will be appreciated that at least one of ASM, javasist or AspectJ bytecode editing tools may be used as desired, and is not limited herein.
According to the technical scheme, the first binary file is read from the compiling catalog through the class reading interface of the byte code editing tool, the first binary file is traversed through the class access interface of the byte code editing tool, so that thread realization calling information in the first binary file is determined, and the position of the thread realization calling information is determined to be calling position information corresponding to the thread realization calling information, namely, the byte code editing tool can be directly called to realize the identification of the thread realization calling information in the first binary file, the identification efficiency of the thread realization calling information can be improved, and the thread management policy configuration efficiency of an application program can be improved.
It should be noted that, in this embodiment, the configuration of the thread management policy may be performed on at least two binary files at the same time. In particular, different binary files may be configured under different directories such that each binary file is acquired simultaneously from different directories.
In one possible implementation, traversing the first binary through a class access interface of a bytecode editing tool to determine thread implementation call information in the first binary includes:
traversing the first binary file through the class access interface to determine byte code information in the first binary file, wherein the byte code information comprises a first target parameter, and the first target parameter is used for representing an inherited parent class;
if the first target parameter comprises a thread identification keyword, determining byte code information comprising the first target parameter as thread realization information, and searching a second target parameter and a third target parameter from call information defined by the thread realization information through a class access interface, wherein the second target parameter is used for representing a class to which the second target parameter belongs, and the third target parameter is used for representing the name of the class;
and if at least one of the second target parameter or the parent class of the second target parameter comprises a thread identification keyword and the third target parameter comprises a thread start identifier, determining call information defined by the thread realization information as thread realization call information.
In the present embodiment, the byte code editing tool is exemplified as ASM.
Binary products in a source code compiling catalog (the binary products comprise products after source code compiling and products after compiling of a three-party library) can be loaded firstly, namely, compiled binary files are loaded; and traversing and reading the byte code file in the item by using the ClassVisistor, rewriting a visual method of the ClassVisistor, and acquiring a superName parameter, and when the superName parameter is matched with the thread identification key, considering the superName parameter as the thread implementation.
Alternatively, the thread identifying key may be as shown in table 1:
TABLE 1
Thread identification key (superName)
Java/lang/Runnable
Java/lang/Thread
Java/util/concurrent/Future
In addition to identifying thread implementations by rewriting the visit method, thread calls inside the method are identified by the following method:
inheritance implements the method initiator method and rewrites its visittmethodinsn method, determining whether to implement for the thread using the name and the owner parameters of the visittmethodinsn method. When owner or its parent identifies a key for a thread, and the value of name is the thread start identification: when 'run' or 'start', the function is determined to be a thread implementation call.
According to the technical scheme, the first binary file is traversed through the class access interface to determine the byte code information comprising the first target parameter in the first binary file, if the first target parameter comprises the thread identification key word, the byte code information comprising the first target parameter is determined to be thread realization information, and the second target parameter and the third target parameter are searched from call information defined by the thread realization information through the class access interface; if at least one of the second target parameter or the parent class of the second target parameter includes a thread identification keyword and the third target parameter includes a thread start identifier, determining call information defined by the thread implementation information as thread implementation call information, that is, determining whether the call is implemented by the thread by searching the first target parameter, the second target parameter and the third target parameter, and determining that the call is implemented by the thread is simple and easy.
In one possible implementation, identifying a target thread class for a thread invoked by the located thread implementation invocation information includes:
acquiring a method binary instruction from the positioned thread realization calling information through a class access interface of a byte code editing tool;
and determining the target thread category of the thread called by the thread realization calling information based on the instruction return value of the method binary instruction and the instruction name of the method binary instruction.
In this embodiment, the bytecode compilation tool may be an ASM. Specifically, a custom method identifier implementation class's visittmethodinsn method may be used, where a binary instruction set of the method may be obtained, where the binary instruction set includes at least one method binary instruction. From the obtained method instruction set sum, single instructions are extracted through traversal, and the types of thread implementation are distinguished through return values and instruction names of the instructions.
According to the technical scheme, the method binary instruction is obtained from the located thread realization calling information through the class access interface of the byte code editing tool, the target thread class of the thread called by the thread realization calling information is determined based on the instruction return value of the method binary instruction and the instruction name of the method binary instruction, that is, the byte code editing tool can be directly called to realize the identification of the target thread class, the identification efficiency of the target thread class can be improved, and the thread management policy configuration efficiency of an application program can be improved.
In one possible implementation, determining a target thread class of the thread invoked by the thread implementation call information based on the instruction return value of the method binary instruction and the instruction name of the method binary instruction includes at least one of:
if the instruction return value of the method binary instruction is the target return value and the instruction name of the method binary instruction comprises at least one of a first thread category keyword or a second thread keyword, determining that the target thread category is a main thread Cheng Leibie;
if the instruction return value of the method binary instruction is not the target return value and the instruction name of the method binary instruction comprises other keywords, determining the target thread type as the input/output thread type, wherein the other keywords are different from the first thread type keywords and the second thread keywords;
if the instruction return value of the method binary instruction is not the target return value and the instruction name of the method binary instruction is null, determining the target thread class as the cache thread class.
Wherein the target return value may be Void. The first thread class key may be MainLoope and the second thread class key may be getMainHandler. The other keywords may be keywords other than the first thread category keyword and the second thread category keyword.
In this embodiment, the determination of the target thread class may be implemented through table 2:
TABLE 2
According to the technical scheme of the embodiment, if the instruction return value of the method binary instruction is the target return value and the instruction name of the method binary instruction comprises at least one of a first thread category keyword or a second thread keyword, determining that the target thread category is a main thread Cheng Leibie; if the instruction return value of the method binary instruction is not the target return value and the instruction name of the method binary instruction comprises other keywords, determining the target thread type as the input/output thread type, wherein the other keywords are different from the first thread type keywords and the second thread keywords; if the instruction return value of the method binary instruction is not the target return value and the instruction name of the method binary instruction is null, determining the target thread class as the cache thread class, and judging the target thread class is simple and easy.
In one possible implementation, marking the target class indication information at the location indicated by the call location information includes:
detecting whether target class indication information is marked at a position indicated by calling position information through a class access interface of a byte code compiling tool;
And in the case that the condition that the target class indication information is not marked at the position indicated by the calling position information is detected, marking the target class indication information at the position indicated by the calling position information through a class writing interface of a byte code compiling tool.
In this embodiment, optionally, the returned value of the visittmethod method is replaced by the custom method by the rewritten visittmethod of the classinitiator; in a self-defined method Visiator method, rewriting a visitCode method to obtain a function method; and comparing whether the setName method exists or not through a character string contacts method, and judging whether the thread is marked or not. If the setName method is already called in the identified thread method, the thread is marked; otherwise, the thread needs to be marked.
According to the technical scheme of the embodiment, whether the target class indication information is marked at the position indicated by the calling position information is detected through the class access interface of the byte code compiling tool; under the condition that the target class indication information is not marked at the position indicated by the calling position information is detected, the target class indication information is marked at the position indicated by the calling position information through a class writing interface of a byte code compiling tool, so that the condition that threads are missed to mark can be reduced, the success rate of thread missed to mark is improved, and the success rate of thread management policy configuration of an application program is further improved.
In one possible implementation, the target class information includes a target binary character, and the obtaining the target thread management bytecode based on the target class information marked in the second binary file includes:
acquiring a first mapping relation, wherein the first mapping relation is used for representing the mapping relation between binary characters and thread management byte codes, and the thread management byte codes are obtained by compiling source codes configured as management threads;
and determining a matched binary character matched with the target binary character from the first mapping relation, and determining the thread management byte code mapped by the matched binary character as a target thread management byte code.
The first mapping relationship may be a pre-configured mapping relationship. In this embodiment, for different thread types, source codes for managing threads may be written by a developer, then the source codes for managing threads are compiled to obtain thread management byte codes, and then the first mapping relationship is determined according to binary characters corresponding to each thread type and the thread management byte codes corresponding to each thread type. Specifically, the binary characters and thread management bytecodes that map to each other correspond to the same thread class.
In this embodiment, the source code for managing the thread may be source code for managing the running logic of the thread, or may be a case of managing the running logic of the thread, the parameters of the thread, or the like, which is not limited herein.
According to the technical scheme, a first mapping relation is obtained, wherein the first mapping relation is used for representing the mapping relation between binary characters and thread management byte codes, and the thread management byte codes are obtained by compiling source codes configured as management threads; the method comprises the steps of determining a matched binary character matched with a target binary character from a first mapping relation, determining a thread management byte code mapped by the matched binary character as a target thread management byte code, and obtaining the target thread management byte code in a relatively quick manner, so that the efficiency of determining and obtaining the target thread management byte code can be improved, and further, the efficiency of configuring the thread management strategy of an application program is improved.
In this embodiment, the thread management bytecode may be configured with a thread management parameter, that is, the thread management bytecode is compiled from source code for managing threads configured with the thread management parameter. Alternatively, the thread management bytecode may be a bytecode that is not configured with a thread management parameter, that is, the thread management bytecode is compiled from source code for managing a thread that is not configured with a thread management parameter.
In particular, the thread management parameters may include, but are not limited to, at least one of a thread pool number, a thread timeout configuration, or a thread pool saturation rejection policy, among others.
In this embodiment, the target thread-management bytecode is configured with or without thread-management parameters. If the target thread management byte code is configured with the thread management parameters, the thread management policy can be quickly configured, so that the efficiency of the thread management policy configuration is improved.
In another possible implementation, if the target thread management bytecode is not configured with the target thread management parameter, the method further includes:
acquiring a second mapping relation which is used for representing the mapping relation between the binary character and the thread management parameter;
determining a matched binary character matched with the target binary character from the second mapping relation, and determining a thread management parameter mapped by the matched binary character as a target thread management parameter;
and writing the target thread management parameters into the target thread management byte codes.
The second mapping relationship may be a pre-configured mapping relationship. In this embodiment, the second mapping relationship may be determined for different threads Cheng Leibie according to the binary character corresponding to each thread class and the thread management parameter corresponding to each thread class. Specifically, the binary characters and thread management parameters that map to each other correspond to the same thread class.
The second mapping between binary characters and thread management parameters may be as shown in table 3.
TABLE 3 Table 3
According to the technical scheme, the second mapping relation is obtained and is used for representing the mapping relation between the binary characters and the thread management parameters; determining a matched binary character matched with the target binary character from the second mapping relation, and determining a thread management parameter mapped by the matched binary character as a target thread management parameter; the target thread management parameters are written into the target thread management byte codes, so that the efficiency of acquiring the target thread management parameters can be improved, and the efficiency of configuring the thread management policy is further improved.
It should be noted that at least one of the first mapping relationship or the second mapping relationship may be set as required. That is, the thread management bytecode mapped by the binary character may be set as needed, or the thread management parameter mapped by the binary character may be set as needed.
According to the technical scheme of the embodiment, at least one of the thread management byte codes or the thread management parameters can be dynamically changed by setting the thread management byte codes mapped by the binary characters or setting at least one of the thread management parameters mapped by the binary characters, so that the flexibility of the thread management policy configuration is improved.
Optionally, the electronic device may include a thread identifying module, a thread marking module, and a thread management module, where the thread identifying module may identify thread implementation call information in the first binary file, the thread marking module marks target class indication information, and the thread management module updates the target thread management byte code to a mark of the target class information in the second binary file.
In one possible implementation, the thread identification module, the thread marking module and the thread management module may share a common memory.
In this embodiment, after determining the call location information corresponding to the call information for implementing the thread, the thread identification module may store the call location information in the shared memory. And then, the thread marking module reads the calling position information from the memory, further positions the thread realization calling information in the first binary file based on the calling position information, identifies the target thread category of the thread called by the positioned thread realization calling information, and marks the target category indication information at the position indicated by the calling position information to obtain the second binary file. The second binary file is then stored in a common memory. And then, the thread management module reads the second binary file from the shared memory, and then updates the target thread management byte code to the mark of the target category information in the second binary file to obtain the target binary file corresponding to the application program.
In another possible implementation, the thread identification module, the thread marking module, and the thread management module may use different memories.
In this embodiment, after determining the call location information corresponding to the call information for implementing the thread, the thread identification module may store the call location information in the first memory. And then, in the identification process of the thread identification module, the thread marking module reads the calling position information from the first memory, further positions the thread realization calling information in the first binary file based on the calling position information, identifies the target thread category of the thread called by the positioned thread realization calling information, and marks the target category indication information at the position indicated by the calling position information to obtain the second binary file. The second binary file is then stored in a second memory. And then, in the process of marking the information by the thread marking module, the thread management module reads the second binary file from the second memory, and then updates the target thread management byte code to the mark of the target category information in the second binary file to obtain the target binary file corresponding to the application program.
According to the technical scheme, in the process of identifying the thread identifying module, the thread marking module can read calling position information from the first memory, and in the process of marking the information by the thread marking module, the thread management module reads the second binary file from the second memory, and then the target thread management byte codes are updated to the mark of the target category information in the second binary file, so that the target binary file corresponding to the application program is obtained, and the configuration efficiency of the thread management strategy can be improved.
For ease of understanding, the following embodiments are described with respect to ASM-based application thread governance based on any of the above embodiments.
Please refer to fig. 4-8. Fig. 4 is a schematic diagram of a preparation flow before a main flow of the present embodiment starts. Fig. 5 is a flowchart of another thread management policy configuration method for an application according to an embodiment of the present application. Fig. 6 is a schematic flow chart of thread identification according to an embodiment of the present application. Fig. 7 is a schematic flow chart of a thread marking according to an embodiment of the present application. Fig. 8 is a schematic diagram of an implantation flow of thread management code according to an embodiment of the present application.
As shown in fig. 4, before the main flow of the present embodiment starts, the following preparation needs to be completed first:
preparation work one: the developer codes an interface related to thread management to obtain a template code for thread management; and compiling the template code of the thread management to obtain a binary product of the thread management.
The abstract interfaces mainly define the following types of interfaces: thread identification creation, thread scheduling functions, thread pool implementation (including thread pool rejection policies), thread lifecycle monitoring interfaces, thread anomaly detection interfaces.
Preparation work II: the developer adds a plug-in for thread governance to the project configuration file.
Preparation work III: configuring relevant parameters of thread management.
After the preparation work is finished, the main flow of the scheme triggers the thread treatment of the application program when the developer finishes encoding and executes source code compiling.
As shown in fig. 5, the main flow of thread governance may include:
step one: and a developer of the source code engineering completes a source code writing task, and compiles and constructs the project source codes by using a gradle tool.
Step two: when the source code compiling is executed to a transform stage, the self-defined thread identification task in the thread treatment plug-in is triggered to start execution. After the thread identification task is started and executed, the binary codes containing the thread characteristics in the binary files are identified through the ClassVisitor provided by the ASM, and the thread information is stored in the binary files after the identification is successful.
Step three: after the thread information contained in the binary file in the compiled product is identified, the binary character related to the thread mark in the thread management binary file is written into the thread calling position in the compiled product by using a classWriter provided by ASM, and the thread (thread category and thread name) for marking the binary product is used.
Step four: after the addition of the binary characters related to the thread identification is completed, the threads are required to be associated to different thread pools according to the types of the threads for execution (thread scheduling). Here too, by thread category, different thread scheduling binary characters are extracted from the thread management binary file, and then the binary characters are added to the original compiled product. The thread class is shown in table 3.
Step five: after the steps are executed, the main flow implemented by the scheme is completed; the source code engineering continues to pack the project according to standard application program packing logic to obtain a final product installation package; when the user installs and uses the application, the relevant thread governance logic implanted during compiling is validated.
Alternatively, thread governance may be assisted by a Gradle plug-in. Gradle is a high-level build system and build tool that allows custom build logic through plug-ins.
As shown in fig. 6, the thread contained in the binary product (bytecode) generated in the source code compiling process can be identified by the following method. The gradle plug-in provided by the scheme comprises a Task (Task) for optimizing and identifying the thread, and the Task in the plug-in is executed to identify the thread, wherein the Task flow comprises the following steps:
Step one: the thread optimization recognition task triggers execution after source code engineering execution gradle compiling and binary file (byte code) generation.
Step two: the thread optimization task uses a ClassReader class provided by ASM to load binary products (the binary products comprise source codes and compiled products of a three-party library) in a source code compiling catalog; and traversing and reading the byte code file in the item by using the ClassVisistor, rewriting a visual method of the ClassVisistor and acquiring a superName parameter, and considering the superName parameter as a thread implementation when the superName parameter is matched with the table 1.
In addition to identifying thread implementations by rewriting the visit method, thread calls inside the method are identified by the following method:
inheritance implements the method initiator method and rewrites its visittmethodinsn method, determining whether to implement for the thread using the name and the owner parameters of the visittmethodinsn method. When the owner or its parent identifies a key for a thread and the value of name is 'run' or 'start', it is determined that the function is to be invoked for the thread.
Step three: and when the thread calling information is successfully identified, caching the identified thread calling result and the thread calling position into a memory.
After identifying the thread call information in the binary file, the ASM is required to mark and classify the threads for providing data support for subsequent thread scheduling logic. The flow diagram of the thread mark is shown in fig. 7:
step one: after the thread identification task is executed, the thread marking task is actively pulled up to run. The thread marking task reads a binary (bytecode) file into memory using a ClassReader provided by ASM.
Step two: the thread identification task reads the thread identification result from the memory and locates the realization of the thread call according to the thread identification result; after the positioning thread is called and realized, replacing a return value of the visitMethod method with a customized method Visiator through a rewritten visitMethod of the ClassVisiator; in a self-defined method Visiator method, rewriting a visitCode method to obtain a function method; and comparing whether the setName method exists or not through a character string contacts method, and judging whether the thread is marked or not. If the setName method is already called in the identified thread method, the thread is marked; otherwise, the thread needs to be marked.
Step three: thread marking and classification; when an untagged thread is encountered, the binary instruction set of the method can be obtained using the visittmethodinsn method of the custom method Visiator implementation class. From the obtained method instruction set sum, single instructions are extracted through traversal, and the thread implementation is distinguished through the return value and the instruction name of the instructions, wherein the distinguishing mode is shown in table 2.
After the thread marking is completed, thread management code instrumentation may be performed. The implantation of the thread management code refers to that a binary file (corresponding to the relevant code of thread governance) executed when an application program runs is dynamically implanted into a compiled product by using ASM according to the rule configured by the thread configuration module in the compiling process. The flow of thread management code instrumentation is shown in FIG. 8:
step one: after the thread marking task is completed, the thread management binary code (byte code) injection task is started.
Step two: after the task is started, binary marking information in an original compiled binary product is firstly obtained from a memory;
step three: reading an original binary product by using a ClassReader, extracting a corresponding thread pool classification binary code (A, B, C, D) from the thread management binary product by combining the marking information and the thread classification information in the step two, and writing the thread pool classification binary code (A, B, C, D) into the original binary file by using the ClassWriter provided by the ASM; and extracting exception handling binary files of different classified threads from the thread management binary products according to the thread classification information, and adding the exception handling binary files to the original compiled products.
Step four: after the association of the threads and the thread pools in the compiled binary product is completed in the step three (the thread management code is injected), the initialized binary information of the thread management is written into the Application of the Application by using the ClassWriter provided by the ASM by reading the current configuration thread management configuration information (the number of the thread pools, the thread pool saturation rejection strategy and the like) from the thread configuration management module. Thus, the code injection of the thread governance is completed.
According to the thread governance method, under the condition that project source codes are not modified, dynamic governance of project thread use can be achieved in the compiling period through plug-in configuration parameterization; on one hand, the complexity of thread treatment work is reduced; on the other hand, the invasive modification of the source code by the thread governance is avoided.
Referring to fig. 9, fig. 9 is a schematic structural diagram of a thread management policy configuration device for an application according to an embodiment of the present application. The apparatus 900 as shown in fig. 9 may include a thread identification module 910, a thread marking module 920, and a thread management module 930, where:
the thread identifying module 910 is configured to identify thread implementation calling information in a first binary file, so as to determine calling location information corresponding to the thread implementation calling information, where the thread implementation calling information is used for calling a thread, and the calling location information is used for indicating a location of the thread implementation calling information in the first binary file, where the first binary file is obtained by compiling a source code file of an application program;
The thread marking module 920 is configured to locate the thread implementation calling information in the first binary file based on the calling location information, identify a target thread class of the thread called by the located thread implementation calling information, and mark target class indication information at a location indicated by the calling location information, to obtain a second binary file, where the target class indication information is used to indicate a target thread class;
the thread management module 930 is configured to obtain a target thread management bytecode based on the target class information marked in the second binary file, and update the target thread management bytecode to the marked position of the target class information in the second binary file to obtain a target binary file corresponding to the application program, where the target thread management bytecode is configured to manage the thread.
Alternatively, the thread identification module 910, when identifying thread implementation call information in the first binary, may be used for any of the following:
acquiring a first binary file obtained after compiling a source code file of an application program is finished, and identifying thread realization calling information in the first binary file obtained after compiling is finished;
and in the process of compiling the source code file of the application program, acquiring a first binary file obtained by compiling part of source codes, and identifying thread realization calling information in the first binary file obtained by compiling part of source codes.
Optionally, the first binary file is stored in the compiled directory, and when identifying the thread implementation call information in the first binary file to determine the call location information corresponding to the thread implementation call information, the thread identification module 910 may be configured to:
reading a first binary file from the compiled catalog through a class reading interface of the byte code editing tool;
traversing the first binary file through a class access interface of the byte code editing tool to determine thread realization calling information in the first binary file, and determining the position of the thread realization calling information as calling position information corresponding to the thread realization calling information.
Optionally, when the class access interface of the bytecode editing tool traverses the first binary file to determine the thread implementation call information in the first binary file, the thread identification module 910 may be configured to:
traversing the first binary file through the class access interface to determine byte code information in the first binary file, wherein the byte code information comprises a first target parameter, and the first target parameter is used for representing an inherited parent class;
if the first target parameter comprises a thread identification keyword, determining byte code information comprising the first target parameter as thread realization information, and searching a second target parameter and a third target parameter from call information defined by the thread realization information through a class access interface, wherein the second target parameter is used for representing a class to which the second target parameter belongs, and the third target parameter is used for representing the name of the class;
And if at least one of the second target parameter or the parent class of the second target parameter comprises a thread identification keyword and the third target parameter comprises a thread start identifier, determining call information defined by the thread realization information as thread realization call information.
Optionally, the thread marking module 920 may be configured to, when identifying the target thread class of the thread called by the located thread implementation call information:
acquiring a method binary instruction from the positioned thread realization calling information through a class access interface of a byte code editing tool;
and determining the target thread category of the thread called by the thread realization calling information based on the instruction return value of the method binary instruction and the instruction name of the method binary instruction.
Optionally, the thread marking module 920 may be configured to determine at least one of the following when determining a target thread class of the thread called by the thread implementation calling information based on the instruction return value of the method binary instruction and the instruction name of the method binary instruction:
if the instruction return value of the method binary instruction is the target return value and the instruction name of the method binary instruction comprises at least one of a first thread category keyword or a second thread keyword, determining that the target thread category is a main thread Cheng Leibie;
If the instruction return value of the method binary instruction is not the target return value and the instruction name of the method binary instruction comprises other keywords, determining the target thread type as the input/output thread type, wherein the other keywords are different from the first thread type keywords and the second thread keywords;
if the instruction return value of the method binary instruction is not the target return value and the instruction name of the method binary instruction is null, determining the target thread class as the cache thread class.
Alternatively, the thread marking module 920 may be configured to, when marking the target class indication information at the location indicated by the call location information:
detecting whether target class indication information is marked at a position indicated by calling position information through a class access interface of a byte code compiling tool;
and in the case that the condition that the target class indication information is not marked at the position indicated by the calling position information is detected, marking the target class indication information at the position indicated by the calling position information through a class writing interface of a byte code compiling tool.
Optionally, the target class information includes a target binary character, and when the thread management module 930 obtains the target thread management bytecode based on the target class information marked in the second binary file, the thread management module may be configured to:
Acquiring a first mapping relation, wherein the first mapping relation is used for representing the mapping relation between binary characters and thread management byte codes, and the thread management byte codes are obtained by compiling source codes configured as management threads;
and determining a matched binary character matched with the target binary character from the first mapping relation, and determining the thread management byte code mapped by the matched binary character as a target thread management byte code.
Optionally, the target thread management bytecode is configured with a thread management parameter or is not configured with a thread management parameter;
if the target thread management bytecode is not configured with target thread management parameters, the thread management module 930 is further configured to:
acquiring a second mapping relation which is used for representing the mapping relation between the binary character and the thread management parameter;
determining a matched binary character matched with the target binary character from the second mapping relation, and determining a thread management parameter mapped by the matched binary character as a target thread management parameter;
and writing the target thread management parameters into the target thread management byte codes.
Referring to fig. 10, fig. 10 is a schematic structural diagram of a Gradle plug-in unit according to an embodiment of the present application. The Gradle plugin 1000 of the present embodiment is configured as a thread management policy configuration device of an application program, and is configured as thread management. The Gradle plug-in as shown in FIG. 10 may include a thread identification module 1010, a thread marking module 1020, a thread management module 1030, and a thread management configuration module 1040.
The thread identification module 1010 is configured to identify a thread implementation call and a location of the thread implementation call. The thread marking module 1020 is configured to identify and mark a class of a thread. The thread management module 1030 is used to embed thread management bytecodes in the binary file. The thread management configuration module 1040 is configured to provide the developer with at least one of configuration thread management parameters, source code for managing threads, or thread management bytecodes for managing threads.
In this embodiment, how to identify, classify, mark, insert thread management byte codes, configure thread management parameters, etc. may refer to the description of any one of the above embodiments, and will not be described herein.
The apparatus of the embodiments of the present application may perform the method provided by the embodiments of the present application, and implementation principles of the method are similar, and actions performed by each module in the apparatus of each embodiment of the present application correspond to steps in the method of each embodiment of the present application, and detailed functional descriptions of each module of the apparatus may be referred to in the corresponding method shown in the foregoing, which is not repeated herein.
An electronic device is provided in an embodiment of the present application, including a memory, a processor, and a computer program stored on the memory, where the processor executes the computer program to implement steps of a method of any embodiment of the present application.
In an alternative embodiment, an electronic device is provided, as shown in fig. 11, the electronic device 1100 shown in fig. 11 includes: a processor 1101 and a memory 1103. The processor 1101 is coupled to a memory 1103, such as via a bus 1102. Optionally, the electronic device 1100 may further include a transceiver 1104, where the transceiver 1104 may be used for data interaction between the electronic device and other electronic devices, such as transmission of data and/or reception of data, etc. It should be noted that, in practical applications, the transceiver 1104 is not limited to one, and the structure of the electronic device 1100 is not limited to the embodiments of the present application.
The processor 1101 may be a CPU (Central Processing Unit ), general purpose processor, DSP (Digital Signal Processor, data signal processor), ASIC (Application Specific Integrated Circuit ), FPGA (Field Programmable Gate Array, field programmable gate array) or other programmable logic device, transistor logic device, hardware components, or any combination thereof. Which may implement or perform the various exemplary logic blocks, modules, and circuits described in connection with this disclosure. The processor 1101 may also be a combination that performs computing functions, such as a combination comprising one or more microprocessors, a combination of a DSP and a microprocessor, or the like.
Bus 1102 may include a path that communicates information between the components. Bus 1102 may be a PCI (Peripheral Component Interconnect, peripheral component interconnect Standard) bus or an EISA (Extended Industry Standard Architecture ) bus, or the like. Bus 1102 may be divided into address bus, data bus, control bus, and the like. For ease of illustration, only one thick line is shown in FIG. 11, but not only one bus or one type of bus.
The Memory 1103 may be a ROM (Read Only Memory) or other type of static storage device that can store static information and instructions, a RAM (Random Access Memory ) or other type of dynamic storage device that can store information and instructions, an EEPROM (Electrically Erasable Programmable Read Only Memory ), a CD-ROM (Compact Disc Read Only Memory, compact disc Read Only Memory) or other optical disk storage, optical disk storage (including compact discs, laser discs, optical discs, digital versatile discs, blu-ray discs, etc.), magnetic disk storage media, other magnetic storage devices, or any other medium that can be used to carry or store a computer program and that can be Read by a computer, without limitation.
The memory 1103 is used for storing a computer program for executing the embodiments of the present application, and is controlled to be executed by the processor 1101. The processor 1101 is configured to execute a computer program stored in the memory 1103 to implement the steps shown in the foregoing method embodiments.
Embodiments of the present application provide a computer readable storage medium having a computer program stored thereon, where the computer program, when executed by a processor, may implement the steps and corresponding content of the foregoing method embodiments.
The embodiments of the present application also provide a computer program product, which includes a computer program, where the computer program can implement the steps of the foregoing method embodiments and corresponding content when executed by a processor.
It should be understood that, although the flowcharts of the embodiments of the present application indicate the respective operation steps by arrows, the order of implementation of these steps is not limited to the order indicated by the arrows. In some implementations of embodiments of the present application, the implementation steps in the flowcharts may be performed in other orders as desired, unless explicitly stated herein. Furthermore, some or all of the steps in the flowcharts may include multiple sub-steps or multiple stages based on the actual implementation scenario. Some or all of these sub-steps or phases may be performed at the same time, or each of these sub-steps or phases may be performed at different times, respectively. In the case of different execution time, the execution sequence of the sub-steps or stages may be flexibly configured according to the requirement, which is not limited in the embodiment of the present application.
The foregoing is merely an optional implementation manner of some implementation scenarios of the present application, and it should be noted that, for those skilled in the art, other similar implementation manners based on the technical ideas of the present application are adopted without departing from the technical ideas of the solution of the present application, which also belongs to the protection scope of the embodiments of the present application.

Claims (13)

1. A method for configuring a thread management policy of an application program, comprising:
identifying thread realization calling information in a first binary file to determine calling position information corresponding to the thread realization calling information, wherein the thread realization calling information is used for calling a thread, the calling position information is used for indicating the position of the thread realization calling information in the first binary file, and the first binary file is compiled by a source code file of an application program;
positioning the thread realization calling information in the first binary file based on the calling position information, identifying the positioned target thread class of the thread called by the thread realization calling information, and marking target class indication information at the position indicated by the calling position information to obtain a second binary file, wherein the target class indication information is used for indicating the target thread class;
And acquiring a target thread management byte code based on the target class information marked in the second binary file, and updating the target thread management byte code to the marked position of the target class information in the second binary file to obtain a target binary file corresponding to the application program, wherein the target thread management byte code is configured as a management thread.
2. The method of claim 1, wherein identifying thread implementation call information in the first binary file comprises any one of:
acquiring a first binary file obtained after compiling a source code file of an application program is finished, and identifying thread realization calling information in the first binary file obtained after compiling is finished;
and in the process of compiling the source code file of the application program, acquiring a first binary file obtained by compiling part of source codes, and identifying thread realization calling information in the first binary file obtained by compiling part of source codes.
3. The method of claim 1, wherein the first binary file is stored in a compiled directory, and wherein the identifying the thread implementation call information in the first binary file to determine call location information corresponding to the thread implementation call information comprises:
Reading the first binary file from the compiled catalog through a class reading interface of a byte code editing tool;
traversing the first binary file through a class access interface of the byte code editing tool to determine thread realization calling information in the first binary file, and determining the position of the thread realization calling information as calling position information corresponding to the thread realization calling information.
4. The method of claim 3, wherein traversing the first binary through a class access interface of the bytecode editing tool to determine thread implementation call information in the first binary comprises:
traversing the first binary file through the class access interface to determine byte code information in the first binary file, wherein the byte code information comprises a first target parameter, and the first target parameter is used for representing an inherited parent class;
if the first target parameter comprises a thread identification keyword, determining byte code information comprising the first target parameter as thread realization information, and searching a second target parameter and a third target parameter from call information defined by the thread realization information through the class access interface, wherein the second target parameter is used for representing the belonged class, and the third target parameter is used for representing the name of the class;
And if at least one of the second target parameter or the parent class of the second target parameter comprises the thread identification keyword and the third target parameter comprises a thread start identifier, determining call information defined by the thread realization information as thread realization call information.
5. The method of claim 1, wherein identifying the located thread implements a target thread class for the thread called by the call information, comprising:
acquiring a method binary instruction from the positioned thread realization calling information through a class access interface of a byte code editing tool;
and determining the target thread category of the thread called by the thread realization calling information based on the instruction return value of the method binary instruction and the instruction name of the method binary instruction.
6. The method of claim 5, wherein the determining the target thread class of the thread called by the thread implementation call information based on the instruction return value of the method binary instruction and the instruction name of the method binary instruction comprises at least one of:
if the instruction return value of the method binary instruction is a target return value and the instruction name of the method binary instruction comprises at least one of a first thread category keyword or a second thread keyword, determining that the target thread category is a main thread Cheng Leibie;
If the instruction return value of the method binary instruction is not the target return value and the instruction name of the method binary instruction comprises other keywords, determining the target thread category as an input/output thread category, wherein the other keywords are different from the first thread category keywords and the second thread keywords;
and if the instruction return value of the method binary instruction is not the target return value and the instruction name of the method binary instruction is null, determining that the target thread class is the cache thread class.
7. The method of claim 1, wherein the tagging the target class indication information at the location indicated by the call location information comprises:
detecting whether target class indication information is marked at the position indicated by the calling position information through a class access interface of a byte code compiling tool;
and marking the target category indication information at the position indicated by the calling position information through a class writing interface of the byte code compiling tool under the condition that the target category indication information is not marked at the position indicated by the calling position information.
8. The method of claim 1, wherein the target class information comprises target binary characters, and wherein the obtaining target thread management bytecode based on the target class information marked in the second binary file comprises:
Acquiring a first mapping relation, wherein the first mapping relation is used for representing the mapping relation between binary characters and thread management byte codes, and the thread management byte codes are obtained by compiling source codes configured as management threads;
and determining a matched binary character matched with the target binary character from the first mapping relation, and determining the thread management byte code mapped by the matched binary character as the target thread management byte code.
9. The method of claim 8, wherein the target thread management bytecode is configured with thread management parameters or is not configured with thread management parameters;
if the target thread management bytecode is not configured with target thread management parameters, the method further includes:
acquiring a second mapping relation, wherein the second mapping relation is used for representing the mapping relation between binary characters and thread management parameters;
determining a matched binary character matched with the target binary character from the second mapping relation, and determining a thread management parameter mapped by the matched binary character as a target thread management parameter;
and writing the target thread management parameters into the target thread management byte codes.
10. A thread management policy configuration apparatus for an application program, comprising:
the thread identification module is used for identifying thread realization calling information in a first binary file to determine calling position information corresponding to the thread realization calling information, wherein the thread realization calling information is used for calling a thread, the calling position information is used for indicating the position of the thread realization calling information in the first binary file, and the first binary file is compiled by a source code file of an application program;
the thread marking module is used for positioning the thread realization calling information in the first binary file based on the calling position information, identifying the positioned target thread class of the thread called by the thread realization calling information, marking target class indication information at the position indicated by the calling position information to obtain a second binary file, wherein the target class indication information is used for indicating the target thread class;
the thread management module is used for acquiring target thread management byte codes based on the target category information marked in the second binary file, updating the target thread management byte codes to the marked position of the target category information in the second binary file to obtain a target binary file corresponding to the application program, and the target thread management byte codes are configured to manage threads.
11. An electronic device comprising a memory, a processor and a computer program stored on the memory, characterized in that the processor executes the computer program to carry out the steps of the method according to any one of claims 1-9.
12. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method according to any of claims 1-9.
13. A computer program product comprising a computer program, characterized in that the computer program, when being executed by a processor, implements the steps of the method according to any one of claims 1-9.
CN202311301671.7A 2023-10-08 2023-10-08 Thread management policy configuration method and related device for application program Pending CN117369861A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311301671.7A CN117369861A (en) 2023-10-08 2023-10-08 Thread management policy configuration method and related device for application program

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311301671.7A CN117369861A (en) 2023-10-08 2023-10-08 Thread management policy configuration method and related device for application program

Publications (1)

Publication Number Publication Date
CN117369861A true CN117369861A (en) 2024-01-09

Family

ID=89406970

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311301671.7A Pending CN117369861A (en) 2023-10-08 2023-10-08 Thread management policy configuration method and related device for application program

Country Status (1)

Country Link
CN (1) CN117369861A (en)

Similar Documents

Publication Publication Date Title
US9891900B2 (en) Generation of specialized methods based on generic methods and type parameterizations
TWI536263B (en) Projecting native application programming interfaces of an operating system into other programming languages
KR101795844B1 (en) Runtime system
US7840939B1 (en) Method for managing annotation inheritance
US8141035B2 (en) Method for accessing internal states of objects in object oriented programming
US20120084750A1 (en) Method for Efficiently Managing Property Types and Constraints In a Prototype Based Dynamic Programming Language
US10649744B1 (en) Systems and methods for handling renaming of programming constructs in programming environments
KR102100531B1 (en) Immutable object types
US20130019225A1 (en) Incremental Inferences for Developing Data Models
CN114138748A (en) Database mapping file generation method, device, equipment and storage medium
JP4806158B2 (en) System and method for declaratively defining and using subclasses in markup
CN111475150B (en) Cross-language binding method, device, equipment and storage medium
CN117369861A (en) Thread management policy configuration method and related device for application program
CN114020278B (en) Data processing method, device, equipment and storage medium
CN105393216B (en) Run-time memory is adjusted
US10311392B2 (en) Just in time compilation (JIT) for business process execution
Wille Presenting C
Albert ILog Rules, embedding rules in C++: Results and limits
CN115981652B (en) Language interoperation method, device, storage medium and program product
CN117234466B (en) Enterprise management software development method, system, equipment and storage medium
CN113296834B (en) Android closed source service type information extraction method based on reverse engineering
CN115878163A (en) Automatic annotation method, terminal device, and computer-readable storage medium
Evangelinou et al. Mapping Kotlin IR to source code elements to visualize program analysis results
RU2021138979A (en) SYSTEM AND METHOD FOR DYNAMIC VISUALIZATION OF SOFTWARE ELEMENTS
Ali iPhone SDK 3 programming: advanced mobile development for Apple iPhone and iPod touch

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication