[go: up one dir, main page]

CN111258557B - Code processing method, device, electronic equipment and computer readable medium - Google Patents

Code processing method, device, electronic equipment and computer readable medium Download PDF

Info

Publication number
CN111258557B
CN111258557B CN202010048686.7A CN202010048686A CN111258557B CN 111258557 B CN111258557 B CN 111258557B CN 202010048686 A CN202010048686 A CN 202010048686A CN 111258557 B CN111258557 B CN 111258557B
Authority
CN
China
Prior art keywords
code
difference
preset
hot
compilation unit
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.)
Expired - Fee Related
Application number
CN202010048686.7A
Other languages
Chinese (zh)
Other versions
CN111258557A (en
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.)
Oppo Chongqing Intelligent Technology Co Ltd
Original Assignee
Oppo Chongqing Intelligent Technology 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 Oppo Chongqing Intelligent Technology Co Ltd filed Critical Oppo Chongqing Intelligent Technology Co Ltd
Priority to CN202010048686.7A priority Critical patent/CN111258557B/en
Publication of CN111258557A publication Critical patent/CN111258557A/en
Application granted granted Critical
Publication of CN111258557B publication Critical patent/CN111258557B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/20Software design
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • 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)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The application discloses a code processing method, a code processing device, electronic equipment and a computer readable medium, and relates to the technical field of computers. The method comprises the following steps: acquiring the code quantity of a compiling unit; acquiring the executed times of a compiling unit; determining whether the compiling unit is a hot code according to the code quantity and the executed times; and if the compiling unit is a hot code, executing a preset operation. Therefore, whether the compiling unit is the hot code is determined based on the code quantity and the executed times of the compiling unit, compared with the fact that the hot code is determined only according to the executed times, the judgment dimension is richer, and the hot code is determined more accurately.

Description

代码处理方法、装置、电子设备及计算机可读介质Code processing method, device, electronic device, and computer-readable medium

技术领域technical field

本申请涉及计算机技术领域,更具体地,涉及一种代码处理方法、装置、电子设备及计算机可读介质。The present application relates to the field of computer technology, and more specifically, to a code processing method, device, electronic equipment, and computer-readable medium.

背景技术Background technique

目前,JavaScript引擎通过字节码解释和热点代码编译成机器码的方式来执行JavaScript源代码,即通过编译器将Java源码编译成字节码,通过JVM(Java VirtualMachine,Java虚拟机)的解释器将字节码逐行解释为机器指令并执行。At present, the JavaScript engine executes the JavaScript source code by interpreting the bytecode and compiling the hotspot code into machine code, that is, compiling the Java source code into bytecode through the compiler, and passing through the JVM (Java Virtual Machine, Java Virtual Machine) interpreter Interpret bytecode line by line into machine instructions and execute them.

当虚拟机发现某个方法或者代码块运行特别频繁时,就会把这些代码认定为“hotspot code”(热点代码),将之记录下来保存到profile文件,为了提高热点代码的执行效率,在运行时,虚拟机将会把这些代码编译成机器码。When the virtual machine finds that a certain method or code block runs particularly frequently, it will identify these codes as "hotspot code" (hotspot code), record it and save it to the profile file, in order to improve the execution efficiency of the hotspot code, run , the virtual machine will compile these codes into machine code.

目前,确定热点代码的方式大多是统计方法函数或代码块的执行次数,将次数较高的方法函数或代码块作为热点代码,使得热点代码的确定不够准确。At present, most of the ways to determine hot codes are to count the execution times of method functions or code blocks, and use method functions or code blocks with higher frequency as hot codes, which makes the determination of hot codes not accurate enough.

发明内容Contents of the invention

本申请提出了一种代码处理方法、装置、电子设备及计算机可读介质,以改善上述缺陷。The present application proposes a code processing method, device, electronic equipment, and computer-readable medium to improve the above defects.

第一方面,本申请实施例提供了一种代码处理方法,包括:获取编译单元的代码数量;获取编译单元的被执行次数;根据所述代码数量和所述被执行次数,确定所述编译单元是否为热点代码;若所述编译单元为热点代码,则执行预设操作。In the first aspect, the embodiment of the present application provides a code processing method, including: obtaining the code quantity of the compilation unit; obtaining the execution times of the compilation unit; determining the compilation unit according to the code quantity and the execution times Whether it is a hot code; if the compilation unit is a hot code, perform a preset operation.

第二方面,本申请实施例还提供了代码处理装置,包括:第一获取模块、第二获取模块、确定模块和执行模块。第一获取模块,用于获取编译单元的代码数量。第二获取模块,用于获取编译单元的被执行次数。确定模块,用于根据所述代码数量和所述被执行次数,确定所述编译单元是否为热点代码。执行模块,用于若所述编译单元为热点代码,则执行预设操作。In a second aspect, the embodiment of the present application further provides a code processing device, including: a first acquisition module, a second acquisition module, a determination module, and an execution module. The first obtaining module is used to obtain the code quantity of the compilation unit. The second obtaining module is used to obtain the execution times of the compilation unit. A determining module, configured to determine whether the compilation unit is a hot code according to the code quantity and the executed times. An execution module, configured to execute a preset operation if the compilation unit is a hot code.

第三方面,本申请实施例还提供了一种电子设备,包括:一个或多个处理器;存储器;一个或多个应用程序,其中所述一个或多个应用程序被存储在所述存储器中并被配置为由所述一个或多个处理器执行,所述一个或多个应用程序配置用于执行上述方法。In a third aspect, the embodiment of the present application also provides an electronic device, including: one or more processors; memory; one or more application programs, wherein the one or more application programs are stored in the memory And configured to be executed by the one or more processors, the one or more application programs are configured to execute the above method.

第四方面,本申请实施例还提供了一种计算机可读介质,所述计算机可读介质存储有处理器可执行的程序代码,所述程序代码被所述处理器执行时使所述处理器执行上述方法。In a fourth aspect, the embodiment of the present application further provides a computer-readable medium, the computer-readable medium stores program code executable by a processor, and when the program code is executed by the processor, the processor Execute the method above.

本申请提供的代码处理方法、装置、电子设备及计算机可读介质,分别获取编译单元的代码数量和被执行次数,并且根据代码数量和所述被执行次数,确定所述编译单元是否为热点代码,在确定编译单元为热点代码的情况下,执行预设操作。因此,基于编译单元的代码数量和被执行次数来确定编译单元是否为热点代码,相比仅根据执行次数来确定热点代码而言,使得判断维度更加丰富,使得热点代码的确定更加准确。The code processing method, device, electronic equipment, and computer-readable medium provided by the present application respectively acquire the code quantity and the number of execution times of the compilation unit, and determine whether the compilation unit is a hot code according to the code quantity and the number of execution times , in the case that the compilation unit is determined to be a hot code, perform a preset operation. Therefore, determining whether a compilation unit is a hot code based on the number of codes of the compilation unit and the number of times it is executed, compared with determining the hot code only based on the number of executions, makes the judgment dimension more abundant and makes the determination of the hot code more accurate.

附图说明Description of drawings

为了更清楚地说明本申请实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings that need to be used in the description of the embodiments will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present application. For those skilled in the art, other drawings can also be obtained based on these drawings without any creative effort.

图1示出了现有技术提供的一种确定热点代码的方法示意图;Fig. 1 shows a schematic diagram of a method for determining hotspot codes provided by the prior art;

图2示出了本申请一实施例提供的一种代码处理方法的方法流程图;FIG. 2 shows a method flowchart of a code processing method provided by an embodiment of the present application;

图3示出了本申请另一实施例提供的一种代码处理方法的方法流程图;FIG. 3 shows a method flowchart of a code processing method provided by another embodiment of the present application;

图4示出了本申请一实施例提供的一种代码处理装置的模块框图;FIG. 4 shows a block diagram of a code processing device provided by an embodiment of the present application;

图5示出了本申请另一实施例提供的一种代码处理装置的模块框图;FIG. 5 shows a block diagram of a code processing device provided by another embodiment of the present application;

图6示出了本申请实施例提供的电子设备的模块框图;FIG. 6 shows a block diagram of an electronic device provided by an embodiment of the present application;

图7出了本申请实施例提供的用于保存或者携带实现根据本申请实施例的代码处理方法的程序代码的存储单元。Fig. 7 shows the storage unit provided by the embodiment of the present application for storing or carrying the program codes implementing the code processing method according to the embodiment of the present application.

具体实施方式Detailed ways

为了使本技术领域的人员更好地理解本申请方案,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述。In order to enable those skilled in the art to better understand the solutions of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.

目前,JavaScript引擎通过字节码解释和热点代码编译成机器码的方式来执行JavaScript源代码。其中,JavaScript引擎是一个专门处理JavaScript脚本的虚拟机。Currently, JavaScript engines execute JavaScript source code by interpreting bytecode and compiling hot code into machine code. Wherein, the JavaScript engine is a virtual machine specially processing JavaScript scripts.

Android有两种虚拟机执行环境:Dalvik和Art。在Dalvik虚拟机下,应用每次运行的时候,字节码都需要通过即时编译器(JIT)转换为机器码,才能被机器运行,这会拖慢应用的执行效率。在Android 4.4时,Art虚拟机开始替代Dalvik,在最开始的Art虚拟机中,应用在第一次安装的时候,系统会通过一个名称为dex2oat的工具将APK中的dex文件编译成包含本地机器码的oat文件存放下来。这样做之后,在程序执行的时候,就可以直接使用已经编译好的机器码以加快效率,这种预先编译机器码的机制叫做AOT。AOT的缺点是应用安装和系统升级之后的应用优化过程比较耗时(需要重新将dex字节码编译成本地机器码),且优化后的文件会占用额外的存储空间。Android has two virtual machine execution environments: Dalvik and Art. Under the Dalvik virtual machine, every time an application runs, the bytecode needs to be converted into machine code by a just-in-time compiler (JIT) before it can be run by the machine, which will slow down the execution efficiency of the application. In Android 4.4, the Art virtual machine began to replace Dalvik. In the original Art virtual machine, when the application was installed for the first time, the system would use a tool called dex2oat to compile the dex file in the APK to include the local machine. The oat file of the code is stored. After doing this, when the program is executed, you can directly use the compiled machine code to speed up the efficiency. This mechanism of pre-compiling the machine code is called AOT. The disadvantage of AOT is that the application optimization process after application installation and system upgrade is time-consuming (the dex bytecode needs to be recompiled into local machine code), and the optimized file will occupy additional storage space.

Android平台的绝大多数应用是使用Java语言写的,Java程序最初仅仅通过JAVA解释器(Interpreter)解释执行,即对字节码逐条解释执行,这种方式的执行速度相对会比较慢,尤其当某个方法或代码块运行特别频繁时,这种方式的执行效率就显得很低。于是后来在虚拟机中引入了JIT编译器,当虚拟机发现某个方法或者代码块运行特别频繁时,就会把这些代码认定为“hot spot code”(热点代码),将之记录下来保存到profile文件,为了提高热点代码的执行效率,在运行时,虚拟机将会把这些代码编译成与本地平台相关的机器码,而正是由JIT编译器负责这项任务。The vast majority of applications on the Android platform are written in the Java language. The Java program is initially interpreted and executed through the JAVA interpreter (Interpreter), that is, the bytecode is interpreted and executed one by one. The execution speed of this method is relatively slow, especially when When a certain method or code block runs very frequently, the execution efficiency of this method appears to be very low. So later a JIT compiler was introduced into the virtual machine. When the virtual machine finds that a certain method or code block runs particularly frequently, it will recognize these codes as "hot spot code" (hot spot code), record them and save them in the profile file, in order to improve the execution efficiency of hot codes, the virtual machine will compile these codes into machine codes related to the local platform at runtime, and it is the JIT compiler that is responsible for this task.

简单而言,profile文件记录了应用频繁运行的方法或者代码块,经由JIT或者AOT编译后得到.odex/.oat文件,该文件存有这些热点代码编译而成的二进制机器码,可直接交由底层cpu执行,从而提高了运行速度。To put it simply, the profile file records the methods or code blocks that the application frequently runs, and the .odex/.oat file is obtained after JIT or AOT compilation. The file stores the binary machine code compiled by these hot codes, which can be directly submitted to The underlying cpu executes, thus improving the running speed.

目前,热点代码的确定方式为,JavaScript引擎执行代码执行次数的统计操作,具体地,周期性地采样各个线程的栈顶的编译单元,基于计数器统计编译单元位于线程的栈顶的次数,如果该编译单元的执行次数大于一定数量,则判定该编译单元为热点代码,并且将该热点代码编译成机器码。其中,编译单元可以是函数(又称“方法”)或类,每个编译单元具有对应的单元描述信息,每个编译单元的单元描述信息用于描述该编译单元的功能。At present, the way to determine the hot code is that the JavaScript engine executes the statistical operation of the number of code executions. Specifically, it periodically samples the compilation unit at the top of the stack of each thread, and counts the number of times the compilation unit is located at the top of the thread stack based on the counter. If the If the execution times of the compilation unit is greater than a certain number, it is determined that the compilation unit is a hot code, and the hot code is compiled into machine code. Wherein, the compilation unit may be a function (also called "method") or a class, and each compilation unit has corresponding unit description information, and the unit description information of each compilation unit is used to describe the function of the compilation unit.

但是,发明人在研究中发现,目前的热点代码确定方法都是基于单个指标来判定热点代码,其中,该指标为代码执行次数。针对一些频繁被执行的编译单元,通过单个指标尚且能够准确确定热点代码,而对应一些代码数量繁多的编译单元,运行次数普遍比较低,如果此时依然仅采用执行次数来确定热点代码,则会导致代码数量繁多的编译单元很难被判定为热点代码,而使得该编译单元错过了运行时编译成机器码的机会,这便降低了JavaScript源码的执行速度。如图1所示,示出了一种确定热点代码的方法示意图。代码A内包括100行js代码,代码B内包括10行js代码,代码A的代码数量大于代码B的代码数量,统计模块负责统计代码A和代码B的被执行的次数,则统计结果为代码A被执行5次,代码B被执行20次,假设当前的次数阈值为15,则代码B的被执行次数大于次数阈值,则代码B被判定为热点代码,而代码A的被执行次数小于次数阈值,则代码A被判定为非热点代码。代码A因为代码数量过大,导致被执行次数过低,而无法被判定为热点代码。However, the inventor found in the research that the current methods for determining hot codes are all based on a single index to determine hot codes, wherein the index is the number of code execution times. For some frequently executed compilation units, hot codes can be accurately determined by a single indicator, and for some compilation units with a large number of codes, the number of executions is generally relatively low. If you still only use the number of executions to determine hot codes, then A compilation unit with a large number of codes is difficult to be judged as a hot code, so that the compilation unit misses the opportunity to be compiled into machine code at runtime, which reduces the execution speed of the JavaScript source code. As shown in FIG. 1 , a schematic diagram of a method for determining a hotspot code is shown. Code A includes 100 lines of js code, and code B includes 10 lines of js code. The number of codes in code A is greater than the number of codes in code B. The statistics module is responsible for counting the number of times codes A and B are executed, and the statistical result is code A is executed 5 times, and code B is executed 20 times. Assuming that the current number of times threshold is 15, the number of times code B is executed is greater than the number of times threshold, and code B is judged as a hot code, while the number of times code A is executed is less than the number of times threshold, code A is judged as a non-hot code. Code A cannot be judged as a hot code because the number of codes is too large and the number of times it is executed is too low.

因此,为了克服上述缺陷,本申请实施例提供了一种代码处理方法,如图2所示,该方法包括:S201至S204。Therefore, in order to overcome the above defects, the embodiment of the present application provides a code processing method, as shown in FIG. 2 , the method includes: S201 to S204.

S201:获取编译单元的代码数量。S201: Acquire the code quantity of the compilation unit.

其中,编译单元的代码数量可以是编译单元内的代码行数,则获取编译单元的代码数量可以统计编译单元的代码行数,将该代码行数作为该编译单元的代码数量。如图1所示,代码A的代码数量为100行,代码B的代码数量为10行。Wherein, the number of codes of the compilation unit may be the number of code lines in the compilation unit, and the acquisition of the code number of the compilation unit may count the number of code lines of the compilation unit, and use the number of code lines as the number of codes of the compilation unit. As shown in Figure 1, code A has 100 lines of code, and code B has 10 lines of code.

另外,编译单元的代码数量还可以是编译单元的数据大小,即编译单元所占用的存储空间的大小,则该数据大小与编译单元内的代码的数量成正比,即代码的数量越多,则数据大小越大。In addition, the number of codes in the compilation unit can also be the data size of the compilation unit, that is, the size of the storage space occupied by the compilation unit, and the data size is proportional to the number of codes in the compilation unit, that is, the more the number of codes, the The larger the data size.

S202:获取编译单元的被执行次数。S202: Obtain the execution times of the compilation unit.

作为一种实施方式,本申请实施例所提供的方法应用电子设备,则电子设备的操作系统内设置有统计模块,该统计模块可以是一个服务。该统计模块用于统计编译单元的被执行次数。As an implementation manner, if the method provided in the embodiment of the present application is applied to an electronic device, then an operating system of the electronic device is provided with a statistics module, and the statistics module may be a service. The statistical module is used to count the number of execution times of the compilation unit.

在一些实施例中,当编译单元被执行的时候,会返回一个指定信息至统计模块,则统计模块在获取到该指定信息的时候,能够知晓编译单元被执行,则统计所获取的指定信息的次数,就能够统计得到编译单元的被执行次数。其中,可以在编译单元内插入一个程序代码,该程序代码用于在被执行的时候,发送一个指定信息至统计模块。其中,该程序代码可以插入编译单元的多个代码行之间。例如,该程序代码位于var js=‘begin’的下一行,或者在var js=‘end’的前一行。In some embodiments, when the compilation unit is executed, it will return a specified information to the statistics module, and then the statistics module can know that the compilation unit is executed when the specified information is obtained, and the statistics of the obtained specified information The number of times, the number of times the compilation unit is executed can be counted. Wherein, a program code can be inserted into the compiling unit, and the program code is used to send a specified information to the statistical module when executed. Wherein, the program code can be inserted between multiple code lines of the compilation unit. For example, the program code is located on the next line of var js='begin', or on the previous line of var js='end'.

在另一些实施例中,在编译单元被执行的时候,会位于线程的栈顶,则统计模块可以监测线程的栈顶,统计该编译单元位于线程的栈顶的次数,进而统计得到编译单元的被执行次数。In some other embodiments, when the compilation unit is executed, it will be located at the top of the stack of the thread, then the statistical module can monitor the top of the stack of the thread, count the number of times the compilation unit is located at the top of the thread, and then obtain the statistics of the compilation unit Executed times.

S203:根据所述代码数量和所述被执行次数,确定所述编译单元是否为热点代码。S203: Determine whether the compilation unit is a hot code according to the code quantity and the execution times.

可以基于预先设定的规则,根据代码数量和被执行次数,确定编译单元是否为热点代码。Based on preset rules, it can be determined whether the compilation unit is a hot code according to the number of codes and the number of execution times.

其中,预先设定的规则可以是,代码数量和被执行次数之和,与预设数值的比对,根据比对结果判断编译单元是否为热点代码。例如,如果上述得到的之和的结果,大于预设数值,则判定编译单元是热点代码,如果,上述得到的之和的结果小于或等于预设数值,则判定编译单元不是热点代码。其中,预设数值可以预先设定的,例如,该预设数值可以是系统默认的方式判定编译单元是否为热点代码时所使用的。例如,默认的判定热点代码的方式为,获取编译单元的被执行的次数,与预设数值比对,如果大于该预设数值,则判定编译单元为热点代码,如果小于或等于预设数值,则判定编译单元不是热点代码。Wherein, the preset rule may be a comparison between the sum of the code quantity and the number of execution times and the preset value, and judge whether the compiling unit is a hot code according to the comparison result. For example, if the result of the sum obtained above is greater than a preset value, it is determined that the compilation unit is a hot code, and if the result of the sum obtained above is less than or equal to a preset value, it is determined that the compilation unit is not a hot code. Wherein, the preset value may be preset, for example, the preset value may be used by the system to determine whether the compilation unit is a hot code in a default manner. For example, the default way to determine the hot code is to obtain the number of executions of the compilation unit and compare it with the preset value. If it is greater than the preset value, it is determined that the compilation unit is a hot code. If it is less than or equal to the preset value, Then it is determined that the compilation unit is not a hot code.

于本申请实施例中,代码数量和被执行次数之和大于该预设数值的时候,可以判定编译单元为热点代码,因此,即使被执行次数不足,由于编译单元的代码数量比较大的情况下,依然可以使得该编译单元被判定为热点。In the embodiment of this application, when the sum of the number of codes and the number of executions is greater than the preset value, it can be determined that the compilation unit is a hot code. Therefore, even if the number of executions is insufficient, due to the relatively large number of codes in the compilation unit , can still cause the compilation unit to be judged as a hotspot.

当然,还可以将代码数量和被执行次数之乘积,与预设数值比对,以便在被执行次数不足的时候,代码数量能够增大该乘积的数值。当然,该预设数值也可以不是默认的判定热点代码时所使用的数值而是另外设置的数值,具体地,可以根据实际使用的需求而设定,在此不做限定。于本申请实施例中,使用代码数量和被执行次数之和的方式,判断编译单元是否为热点代码,具体地,请参考后续实施例。Of course, the product of the number of codes and the times of execution can also be compared with a preset value, so that when the number of times of execution is insufficient, the number of codes can increase the value of the product. Of course, the preset value may also not be the default value used when determining the hotspot code, but a value set separately. Specifically, it may be set according to actual use requirements, which is not limited here. In the embodiment of the present application, the sum of the number of codes and the number of execution times is used to determine whether the compilation unit is a hot code. For details, please refer to the subsequent embodiments.

S204:若所述编译单元为热点代码,则执行预设操作。S204: If the compilation unit is a hot code, perform a preset operation.

其中,所述预设操作可以是根据该热点代码生成配置文件。Wherein, the preset operation may be to generate a configuration file according to the hotspot code.

其中,配置文件用于记录所述指定应用程序的热点代码标识,该配置文件可以是profile文件。该profile文件为了提高热点代码的执行效率,在运行时,虚拟机将会把这些代码编译成与本地平台相关的机器码,而正是由JIT编译器负责这项任务。Wherein, the configuration file is used to record the hot code identification of the specified application program, and the configuration file may be a profile file. In order to improve the execution efficiency of hot codes in this profile file, the virtual machine will compile these codes into machine codes related to the local platform at runtime, and it is the JIT compiler that is responsible for this task.

简单而言,profile文件记录了应用频繁运行的方法或者代码块,经由JIT或者AOT编译后得到.odex/.oat文件,该文件存有这些热点代码编译而成的二进制机器码,可直接交由底层cpu执行,从而提高了运行速度。To put it simply, the profile file records the methods or code blocks that the application frequently runs, and the .odex/.oat file is obtained after JIT or AOT compilation. The file stores the binary machine code compiled by these hot codes, which can be directly submitted to The underlying cpu executes, thus improving the running speed.

作为一种实施方式,电子设备将所生成的配置文件发送至服务器,服务器将该profile文件与该应用程序的应用标识对应存储,以便记录该应用程序的profile文件。作为一种实施方式,该profile文件同时与应用程序的应用标识以及用户帐号对应存储,以便服务器能够记录用户帐号对应的用户在操作应用标识对应的应用程序时所产生的profile文件。As an implementation manner, the electronic device sends the generated configuration file to the server, and the server stores the profile file in correspondence with the application identifier of the application program, so as to record the profile file of the application program. As an implementation, the profile file is stored corresponding to the application ID of the application program and the user account, so that the server can record the profile file generated when the user corresponding to the user account operates the application program corresponding to the application ID.

服务器能够收集不同的用户终端上传的针对不同的应用程序的不同的profile文件,服务器能够将同一个应用程序对应的不同的profile文件整理成一个通用的profile文件,作为与该应用程序对应的profile文件。从而,在新的用户由服务器下载该应用程序的时候,服务器能够将该应用程序的安装文件和profile文件一起发送至用户终端,用户终端在安装该应用程序的时候,在安装应用过程中,调用dex2oat对热点代码进行编译,从而提升应用安装后的性能。The server can collect different profile files for different applications uploaded by different user terminals, and the server can organize different profile files corresponding to the same application program into a common profile file as the profile file corresponding to the application program . Therefore, when a new user downloads the application program from the server, the server can send the installation file of the application program and the profile file to the user terminal, and when the user terminal installs the application program, in the process of installing the application program, call dex2oat compiles the hotspot code to improve the performance of the application after installation.

作为另一种实施方式,该预设操作还可以是将该热点代码生成机器码,这样做之后,在程序执行的时候,就可以直接使用已经编译好的机器码以加快效率。As another implementation, the preset operation may also be to generate machine codes for the hotspot codes. After doing so, when the program is executed, the compiled machine codes can be directly used to speed up the efficiency.

请参阅图3,本申请实施例提供了一种代码处理方法,如图3所示,该方法包括:S301至S306。Please refer to FIG. 3 , the embodiment of the present application provides a code processing method, as shown in FIG. 3 , the method includes: S301 to S306.

S301:获取编译单元的代码数量。S301: Obtain the code quantity of the compilation unit.

S302:获取编译单元的被执行次数。S302: Obtain the execution times of the compilation unit.

S303:获取所述代码数量与预设数量阈值之间的第一差值。S303: Obtain a first difference between the code quantity and a preset quantity threshold.

其中,预先设置一个预设数量阈值,该预设数量阈值可以是预先设定的一个代码数量,如果编译单元的代码数量大于该预设数量阈值,则表示编译单元属于体量较大的编译单元,而如果编译单元的代码数量小于或等于该预设数量阈值,则表示编译单元属于体量较小的编译单元。Wherein, a preset number threshold is preset, and the preset number threshold can be a preset number of codes. If the code number of the compilation unit is greater than the preset number threshold, it means that the compilation unit belongs to a larger compilation unit. , and if the number of codes in the compilation unit is less than or equal to the preset number threshold, it means that the compilation unit belongs to a smaller compilation unit.

其中,预设数量阈值可以是根据经验而设定的,也可以是根据电子设备的运行参数而设定的,还可以是根据该编译代码的应用场景而设定,具体地,请参阅后续实施例。Wherein, the preset quantity threshold may be set based on experience, or set according to the operating parameters of the electronic equipment, or set according to the application scenario of the compiled code. For details, please refer to the follow-up implementation example.

S304:获取所述被执行次数与预设次数阈值之间的第二差值。S304: Obtain a second difference between the executed times and a preset times threshold.

其中,预先设置一个预设次数阈值,该预设次数阈值可以是预先设定的一个被执行次数,如果编译单元的被执行次数大于该预设次数阈值,则表示编译单元属于被执行次数较多的编译单元,而如果编译单元的被执行次数小于或等于该预设次数阈值,则表示编译单元属于被执行次数较少的编译单元。Wherein, a preset times threshold is set in advance, and the preset times threshold may be a preset number of execution times. If the number of times the compilation unit is executed is greater than the preset number of times threshold, it means that the compilation unit is executed more times. , and if the number of execution times of the coding unit is less than or equal to the preset number of times threshold, it indicates that the compilation unit belongs to the coding unit that is executed less frequently.

其中,预设次数阈值可以是根据经验而设定的,也可以是根据电子设备的运行参数而设定的,还可以是根据该编译代码的应用场景而设定,具体地,请参阅后续实施例。Wherein, the preset times threshold may be set based on experience, or set according to the operating parameters of the electronic device, or set according to the application scenario of the compiled code. For details, please refer to the follow-up implementation example.

S305:根据所述第一差值和所述第二差值,确定所述编译单元是否为热点代码。S305: Determine whether the compilation unit is a hot code according to the first difference value and the second difference value.

作为一种实施方式,获取第一差值和第二差值之和,记为待判定结果,判断所述判定结果是否大于指定数值,如果判定结果大于指定数值,则判定该编译单元为热点代码,如果判定结果小于或等于指定数值,则判定编译单元不是热点代码。As an implementation, the sum of the first difference and the second difference is obtained, recorded as the result to be determined, and whether the determination result is greater than the specified value is determined, and if the determination result is greater than the specified value, it is determined that the compilation unit is a hot code , if the judgment result is less than or equal to the specified value, it is judged that the compilation unit is not a hot code.

由于判定结果为第一差值和第二差值之和,则在被执行次数较少的时候,能够通过编译代码的代码数量使得该判定结果的数值增大,从而,使得代码数量较多的编译单元在被执行次数较少的时候,依然能够有较大的可能性被判定为热点代码。Since the judgment result is the sum of the first difference and the second difference, when the number of executions is small, the value of the judgment result can be increased by compiling the code, thereby making the code with a large number of codes When the compilation unit is executed less times, it is still more likely to be judged as hot code.

当然,还可以是获取第一差值和第二差值的乘积作为上述判定结果。Of course, it is also possible to obtain the product of the first difference and the second difference as the above determination result.

作为一种实施方式,可以为第一差值设定一个权重,以及为第二差值设定一个权重,在确定热点代码的时候,结合第一权重和第二权重共同确定。则根据所述第一差值和所述第二差值,确定所述编译单元是否为热点代码的具体实施方式可以是,根据所述第一差值、所述第一差值对应的第一权重、所述第二差值以及所述第二差值对应的第二权重,获取热点代码评估值;若所述热点代码评估值大于指定评估值,则判定所述编译单元为热点代码。As an implementation manner, a weight may be set for the first difference, and a weight may be set for the second difference, and when determining the hotspot code, the first weight and the second weight are jointly determined. Then according to the first difference and the second difference, the specific implementation manner of determining whether the compilation unit is a hot code may be, according to the first difference, the first difference corresponding to the first difference The weight, the second difference, and the second weight corresponding to the second difference obtain a hot code evaluation value; if the hot code evaluation value is greater than a specified evaluation value, it is determined that the compilation unit is a hot code.

其中,第一权重和第二权重可以是预先设定的数值,起到调节第一差值和第二差值的作用,同时也反映了第一差值和第二差值在用于确定编译单元是否为热点代码的时候,所占的比重。例如,第一权重越大,表示第一差值所占的比重越高,而第二权重越大,表示第二差值所占的比重越高。Wherein, the first weight and the second weight can be preset values, which play a role in adjusting the first difference and the second difference, and also reflect the role of the first difference and the second difference in determining the compilation The proportion of whether the unit is a hot code. For example, the greater the first weight, the higher the proportion of the first difference, and the greater the second weight, the higher the proportion of the second difference.

作为一种实施方式,根据所述第一差值、所述第一差值对应的第一权重、所述第二差值以及所述第二差值对应的第二权重获取热点代码评估值的实施方式可以是,获取第一差值和第一权重的乘积,作为第一乘积结果,获取第二差值和第二权重的乘积,作为第二乘积结果,获取第一乘积结果和第二乘积结果之和作为热点代码评估值。具体地,可以根据以下方式获取热点代码评估值:As an implementation manner, the hot code evaluation value is obtained according to the first difference, the first weight corresponding to the first difference, the second difference, and the second weight corresponding to the second difference An embodiment may be to obtain the product of the first difference and the first weight, as the result of the first product, obtain the product of the second difference and the second weight, as the result of the second product, obtain the result of the first product and the second product The sum of the results is used as the hot code evaluation value. Specifically, hot code evaluation values can be obtained in the following manner:

S_HOT=Y_CLN*CVW+Y_CEN*CEW;S_HOT=Y_CLN*CVW+Y_CEN*CEW;

其中,S_HOT为热点代码评估值,Y_CLN为所述第一差值,CVW为所述第一权重,Y_CEN为所述第二差值,CEW为所述第二权重。Wherein, S_HOT is a hot code evaluation value, Y_CLN is the first difference, CVW is the first weight, Y_CEN is the second difference, and CEW is the second weight.

具体地,设定代码数量为CLN,预设数量阈值为CLNT,被执行次数CEN,预设次数阈值为CENT,则第一差值为:Y_CLN=CLN-CLNT,当前的编译单元的代码数量,即当前编译单元的代码行数减去预设数量阈值的差值(Y_CLN)与编译单元的代码数量成正相关,即当前的编译单元的代码数量越大,第一差值的值越大,当前的编译单元的代码数量越小,第一差值的值越小。Specifically, the number of codes is set to CLN, the preset number threshold is CLNT, the number of times executed is CEN, and the preset number threshold is CENT, then the first difference is: Y_CLN=CLN-CLNT, the code number of the current compilation unit, That is, the difference (Y_CLN) between the number of lines of code in the current compilation unit and the preset number threshold is positively correlated with the number of codes in the compilation unit, that is, the larger the number of codes in the current compilation unit, the greater the value of the first difference, and the current The smaller the code amount of the compilation unit of is, the smaller the value of the first difference is.

第二差值为:Y_CEN=CEN-CENT,当前代码执行次数减去预设次数阈值的差值(Y_CEN)与代码热度成正相关,其中,编译单元的被执行次数能够表示其热度,即编译单元的被执行次数越高,表示该编译单元的热度越高。The second difference is: Y_CEN=CEN-CENT, the difference (Y_CEN) between the current code execution times minus the preset number of thresholds is positively correlated with the code popularity, where the number of times a compilation unit is executed can represent its popularity, that is, the compilation unit The higher the execution times, the higher the popularity of the compilation unit.

得到的热点代码评估值用于表示该编译单元被判定为热点代码的趋势,热点代码评估值越大,则表示该编译单元越有可能被判定为热点代码,而热点代码评估值越小,则表示该编译单元越有可能被判定为非热点代码。The obtained hot code evaluation value is used to indicate the trend of the compilation unit being judged as a hot code. The larger the hot code evaluation value, the more likely the compilation unit is judged as a hot code, and the smaller the hot code evaluation value, Indicates that the compilation unit is more likely to be judged as non-hot code.

因此,设定一个热点代码评估值,判断热点代码评估值是否大于指定评估值,如果热点代码评估值大于指定评估值,则判定所述编译单元为热点代码,如果热点代码评估值小于或等于指定评估值,则判定所述编译单元为非热点代码。例如,设定指定评估值为CHT,则比较S_HOT和CHT。若S_HOT>CHT,则认定编译单元为热点代码。Therefore, a hot code evaluation value is set to determine whether the hot code evaluation value is greater than the specified evaluation value. If the hot code evaluation value is greater than the specified evaluation value, it is determined that the compilation unit is a hot code. If the hot code evaluation value is less than or equal to the specified evaluation value, it is determined that the compilation unit is a non-hot code. For example, if the specified evaluation value is set to CHT, S_HOT and CHT are compared. If S_HOT>CHT, it is determined that the compilation unit is a hot code.

因此,如果编译单元的被执行的次数比较少,但是,编译单元的代码数量比较大的时候,虽然,Y_CEN*CEW数值比较小,但是,Y_CLN*CVW数值比较大,则S_HOT的数值依然比较大,则依然有可能使得热点代码评估值大于指定评估值,从而被判定为热点代码。Therefore, if the number of executions of the compilation unit is relatively small, but the code quantity of the compilation unit is relatively large, although the value of Y_CEN*CEW is relatively small, but the value of Y_CLN*CVW is relatively large, the value of S_HOT is still relatively large , it is still possible to make the hot code evaluation value greater than the specified evaluation value, and thus be determined as a hot code.

例如,上述图1所示,代码A的代码数量为100行,代码B的代码数量为10行,代码A被执行5次,代码B被执行20次,则在次数阈值为15的时候,代码A为非热点代码。那么,假设代码数量阈值为30,预设次数阈值为10,则第一差值为70行,第二差值为-5,则第一权重为0.5,第二权重为0.5,则热点代码评估值为32.5,即S_HOT=70*0.5-5*0.5=32.5,而32.5大于15,即代码A可以被判定为热点代码。For example, as shown in Figure 1 above, code A has 100 lines of code, code B has 10 lines of code, code A is executed 5 times, and code B is executed 20 times. When the number of times threshold is 15, the code A is a non-hotspot code. Then, assuming that the code number threshold is 30 and the preset number of times threshold is 10, then the first difference is 70 lines, and the second difference is -5, then the first weight is 0.5, and the second weight is 0.5, then hot code evaluation The value is 32.5, that is, S_HOT=70*0.5-5*0.5=32.5, and 32.5 is greater than 15, that is, code A can be determined as a hot code.

其中,预设数量阈值和预设次数阈值根据所述电子设备的设备信息和编译单元的应用场景而设定,下面将分别以设备信息和编译单元的应用场景评述预设数量阈值和预设次数阈值的设定。Wherein, the preset number threshold and the preset number of times threshold are set according to the device information of the electronic device and the application scenario of the compilation unit, and the preset number threshold and the preset number of times will be respectively commented on according to the device information and the application scenario of the compilation unit Threshold setting.

作为一种实施方式,编译单元在电子设备内运行,所述预设数量阈值和预设次数阈值根据所述电子设备的设备信息而设定。其中,该设备信息可以是电子设备的中央处理器的使用率,还可以是内存信息。As an implementation manner, the compiling unit runs in the electronic device, and the preset number threshold and the preset times threshold are set according to device information of the electronic device. Wherein, the device information may be the usage rate of the central processing unit of the electronic device, and may also be memory information.

其中,中央处理器的使用率可以通过查看电子设备的任务管理器而获取,例如,在安卓系统下,通过adb shell top指令获取CPU的使用率。则作为一种实施方式,中央处理器的使用率越大,则所述预设数量阈值和预设次数阈值越小,从而可以减少热点代码评估值,进而可以得到应用程序内的更多的热点代码,以便在执行该应用程序的时候,应用程序能够得到更快的执行速度,避免在中央处理器的使用率不高的时候,应用程序的执行速度过慢。Wherein, the utilization rate of the central processing unit can be obtained by checking the task manager of the electronic device, for example, under the Android system, the utilization rate of the CPU can be obtained through the adb shell top command. As an implementation, the greater the usage rate of the central processing unit, the smaller the preset number threshold and the preset number of times threshold, so that the hotspot code evaluation value can be reduced, and more hotspots in the application program can be obtained. code, so that when the application program is executed, the application program can be executed at a faster speed, and the execution speed of the application program is prevented from being too slow when the utilization rate of the central processing unit is not high.

作为另一种实施方式,内存信息包括内存容量,所述内存容量越大,所述预设数量阈值和预设次数阈值越小。其中,内存容量可以是电子设备的最大内存大小,也可以是电子设备当前的剩余内容空间,于本申请实施例中,将电子设备当前的剩余内容空间作为电子设备的内存容量。则电子设备当前的剩余内容空间越大,预设数量阈值和预设次数阈值越小,从而可以减少热点代码评估值,进而可以得到应用程序内的更多的热点代码,以便在执行该应用程序的时候,应用程序能够得到更快的执行速度。另外,由于内存容量比较大,有更多的存储空间可以存储热点代码,从而能够避免热点代码过多而导致电子设备的内存空间不足。As another implementation manner, the memory information includes memory capacity, and the larger the memory capacity, the smaller the preset number threshold and the preset times threshold are. The memory capacity may be the maximum memory size of the electronic device, or the current remaining content space of the electronic device. In the embodiment of the present application, the current remaining content space of the electronic device is used as the memory capacity of the electronic device. The larger the current remaining content space of the electronic device, the smaller the preset number threshold and the preset number of times threshold, so that the evaluation value of hot codes can be reduced, and more hot codes in the application can be obtained, so that when the application is executed When , the application can get faster execution speed. In addition, since the memory capacity is relatively large, there is more storage space for storing hot codes, thereby avoiding insufficient memory space of the electronic device caused by too many hot codes.

则在一些实施例中,可以预先设定内存空间级别,以及设定一个基准的预设数量阈值,定义为第一基准值,并且设定一个预设次数阈值的基准值,作为第二基准值。其中,内存空间级别可以是按照电子设备的内存最大值划分多个内存级别,例如,一共划分10个内存级别,如0-10%为内存级别1,10%-20%为内存级别2,以此类推,最高内存级别为内存级别10。例如,第一基准值对应内存级别5,第二基准值对应内存级别5,而每增加一个内存级别,将该第一基准值减小一个常数值C,且第二基准值减小一个常数值D,即内存级别6对应的预设数量阈值为第一基准值减C,内存级别6对应的预设次数阈值为第二基准值减D,而内存级别7对应的预设数量阈值为第一基准值减2C,预设次数阈值为第二基准值减2D。在内存级别5每降低一个内存级别,则该第一基准值增加一个常数值C,该第二基准值增加一个常数值D,即内存级别4对应的预设数量阈值为第一基准值加C,内存级别4对应的预设次数阈值为第二基准值加D,内存级别3对应的预设数量阈值为第一基准值加2C,内存级别3对应的预设次数阈值为第二基准值加2D,以此类推。因此,内存容量越大,所述预设次数阈值和预设次数阈值越小,内存容量越小,所述预设次数阈值和预设次数阈值越大。Then, in some embodiments, the memory space level can be preset, and a preset number threshold of a benchmark can be set, which is defined as the first benchmark value, and a benchmark value of a preset times threshold can be set as the second benchmark value . Wherein, the memory space level can be divided into multiple memory levels according to the maximum memory value of the electronic device. By analogy, the highest memory level is memory level 10. For example, the first benchmark value corresponds to memory level 5, and the second benchmark value corresponds to memory level 5, and each time a memory level is increased, the first benchmark value is decreased by a constant value C, and the second benchmark value is decreased by a constant value D, that is, the preset number threshold corresponding to memory level 6 is the first reference value minus C, the preset number threshold corresponding to memory level 6 is the second reference value minus D, and the preset number threshold corresponding to memory level 7 is the first The reference value minus 2C, and the preset number of times threshold is the second reference value minus 2D. When the memory level is reduced by one memory level, the first reference value is increased by a constant value C, and the second reference value is increased by a constant value D, that is, the preset quantity threshold corresponding to memory level 4 is the first reference value plus C , the preset count threshold corresponding to memory level 4 is the second reference value plus D, the preset count threshold corresponding to memory level 3 is the first reference value plus 2C, and the preset count threshold corresponding to memory level 3 is the second reference value plus 2D, and so on. Therefore, the larger the memory capacity, the smaller the preset times threshold and the preset times threshold, and the smaller the memory capacity, the larger the preset times threshold and the preset times threshold.

作为另一种实施方式,所述预设数量阈值和预设次数阈值根据所述编译单元的应用场景而设定。As another implementation manner, the preset number threshold and the preset times threshold are set according to an application scenario of the compiling unit.

其中,编辑单元的应用场景,可以是编译单元对应的应用程序的应用类型。具体地,获取编译单元对应的应用程序,然后,获取该应用程序的应用类型,该应用类型作为该编译单元的应用场景。Wherein, the application scenario of the editing unit may be the application type of the application program corresponding to the compiling unit. Specifically, the application program corresponding to the compilation unit is obtained, and then the application type of the application program is obtained, and the application type is used as an application scenario of the compilation unit.

应用程序的应用类型,可以是应用程序的开发商在开发的时候为应用程序设定的应用类型,也可以是应用程序在安装在电子设备上之后,用户为应用程序设定的应用类型,例如,用户在电子设备上安装某个应用程序,在安装完成并进入该应用程序之后,会显示一个对话框,指示用户为应用程序设定应用类型。则应用程序具体属于哪个应用类型,可以由用户根据需求而设定,例如,用户可以将某社交软件设置为音频类,或者设置为视频类,或者设置为社交类。The application type of the application program can be the application type set for the application program by the developer of the application program during development, or the application type set by the user for the application program after the application program is installed on the electronic device, for example , the user installs an application program on the electronic device, after the installation is completed and the application program is entered, a dialog box will be displayed to instruct the user to set the application type for the application program. The specific application type of the application program can be set by the user according to the needs. For example, the user can set a certain social software as an audio type, or as a video type, or as a social type.

另外,电子设备内安装有应用程序安装软件,例如ios系统内的Appstore。则在该应用程序安装软件内设置有应用程序列表,在该列表内用户能够下载应用程序并且能够更新和打开应用程序,而且该应用程序安装软件可以将不同的应用程序按照应用类型现实,比如,音频类、视频类或者游戏类等。因此,用户在使用该应用程序安装软件安装应用程序的时候,就已经能够知道该应用程序的应用类型。In addition, application installation software is installed in the electronic device, such as an Appstore in the ios system. Then, an application program list is set in the application program installation software, in which the user can download the application program and update and open the application program, and the application program installation software can display different application programs according to the application type, for example, audio, video, or game. Therefore, when the user installs the application program using the application program installation software, the user can already know the application type of the application program.

另外,考虑到有些应用程序可以播放视频也可以播放音频,则如果该应用程序支持视频播放的功能,就将该应用程序的类型设置为视频类型,如果不支持视频播放的功能,而仅仅支持音频播放的功能,则就将该应用程序的类型设置为音频类型。而具体地,应用程序是否支持视频播放功能,可以通过该应用程序的功能描述信息中,所包含的功能描述,例如,所支持的播放格式来判断是否支持视频格式的播放,也可以通过检测该应用程序的程序模块内是否播放视频播放模块,例如,某个视频播放的编解码算法等,从而能够确定该应用程序是否支持视频播放功能。In addition, considering that some applications can play both video and audio, if the application supports the function of video playback, set the type of the application to the video type; if it does not support the function of video playback, it only supports audio If the function of playing, the type of the application is set to the audio type. Specifically, whether the application supports the video playback function can be judged by the function description included in the function description information of the application, for example, the supported playback format, whether it supports the playback of the video format, or by detecting the Whether the video playback module is played in the program module of the application program, for example, the encoding and decoding algorithm of a certain video playback, etc., so as to determine whether the application program supports the video playback function.

再者,如果有些应用程序的功能多样化,则需要根据应用程序的具体操作行为而确定该应用程序的应用类型,例如,如果有些应用程序能够播放视频,也能够播放音频,例如一些视频播放软件,可以播放纯音频文件,也可以播放视频,则该应用程序的应用类型可以根据应用程序的使用记录而确定,即根据该应用程序的一定时间段内的使用记录,确定用户使用该应用程序是倾向于播放视频还是更倾向于播放音频。Furthermore, if some application programs have diversified functions, the application type of the application program needs to be determined according to the specific operation behavior of the application program. For example, if some application programs can play video, they can also play audio. For example, some video playback software , can play pure audio files, and can also play video, then the application type of the application can be determined according to the use records of the application, that is, according to the use records of the application within a certain period of time, it is determined whether the user uses the application Prefer video or prefer audio.

具体地,获取该应用程序在预设时间段内的所有用户的操作行为数据,其中,所有用户是指安装过该应用程序的所有用户,则该操作行为数据可以由应用程序对应的服务器内获取,也就是说,用户在使用该应用程序的时候会使用用户对应的用户账号登录该应用程序,而用户账号对应的操作行为数据会发送至应用程序对应的服务器,则服务器将所获取的操作行为数据与用户账号对应存储。在一些实施例中,电子设备发送针对应用程序的操作行为查询请求发送至该应用程序对应的服务器,服务器将一定预设时间段内的所有用户的操作行为数据发送至电子设备。Specifically, obtain the operation behavior data of all users of the application program within a preset time period, wherein all users refer to all users who have installed the application program, then the operation behavior data can be obtained from the server corresponding to the application program , that is to say, when using the application, the user will use the user account corresponding to the user to log in to the application, and the operation behavior data corresponding to the user account will be sent to the server corresponding to the application, and the server will obtain the operation behavior data The data is stored corresponding to the user account. In some embodiments, the electronic device sends an operation behavior query request for the application to a server corresponding to the application, and the server sends the operation behavior data of all users within a certain preset time period to the electronic device.

该操作行为数据包括所播放的音频文件的名称和时间、以及所播放的视频文件的名称和时间,通过分析该操作行为数据就能够确定在一定预设时间段内该应用程序播放的音频文件的数量以及总的时间,也可以得到该应用程序播放的视频文件的数量以及总的时间,则根据音频和视频文件的播放总时长在该预定时间段内的占比,确定应用程序的应用类型,具体地,获取音频和视频文件的播放总时长在该预定时间段内的占比,为方便描述,将音频文件的播放总时长在该预定时间段内的占比记为音频播放占比,将视频文件的播放总时长在该预定时间段内的占比记为视频播放占比,如果视频播放占比大于音频播放占比,则将应用程序的应用类型设定为视频类型,如果音频播放占比大于视频播放占比,则将应用程序的应用类型设定为音频类型。例如,预设时间段为30天,即720小时,而音频文件的播放总时长为200小时,则音频播放占比为27.8%,视频文件的播放总时长为330小时,则视频播放占比为45.8%,则视频播放占比大于音频播放占比,则将应用程序的应用类型设定为视频类型。The operation behavior data includes the name and time of the played audio file, and the name and time of the played video file. By analyzing the operation behavior data, it is possible to determine the number of audio files played by the application within a certain preset time period. Quantity and total time, also can get the quantity and the total time of the video file that this application program plays, then according to the proportion of the total playing time of audio and video files in this preset time period, determine the application type of application program, Specifically, the proportion of the total playing time of audio and video files within the predetermined time period is obtained. For the convenience of description, the proportion of the total playing time of audio files within the predetermined time period is recorded as the proportion of audio playback, and The proportion of the total playing time of the video file within the predetermined time period is recorded as the proportion of video playback. If the proportion of video playback is greater than the proportion of audio playback, the application type of the application is set to video type. If the proportion of audio playback is If the ratio is greater than the video playback ratio, set the application type of the application to the audio type. For example, the preset time period is 30 days, that is, 720 hours, and the total playing time of audio files is 200 hours, then the proportion of audio playing is 27.8%, and the total playing time of video files is 330 hours, then the proportion of video playing is 45.8%, the proportion of video playback is greater than the proportion of audio playback, and the application type of the application is set to the video type.

作为另一种实施方式,电子设备内的应用程序的UID是由一串数字构成的,且该数字的排列存在一定的规律性,不同的应用类型的应用程序的UID所对应的数字分段区域是不同的,例如,UID为00000至09999的应用程序同属于一个应用类型,因此,根据该应用程序的UID能够确定该应用程序对应的应用类型。As another implementation, the UID of the application program in the electronic device is composed of a series of numbers, and there is a certain regularity in the arrangement of the numbers, and the number segment area corresponding to the UID of the application program of different application types For example, applications with UIDs ranging from 00000 to 09999 belong to the same application type. Therefore, the application type corresponding to the application can be determined according to the UID of the application.

另外,该编译单元的应用场景还可以是该编译单元的功能,具体地,可以是该编译单元的开发人员在开发该编译单元的时候,编辑该编译单元的功能描述内容,然后,在该编译单元被执行的时候,读取该功能描述内容能够确定该编译单元的功能,作为该编译单元的应用场景。In addition, the application scenario of the compilation unit may also be the function of the compilation unit. Specifically, the developer of the compilation unit may edit the function description content of the compilation unit when developing the compilation unit, and then, in the compilation When the unit is executed, reading the function description can determine the function of the compilation unit as the application scenario of the compilation unit.

再者,编译单元可以被应用程序调用而执行,则确定调用该编译单元的应用程序,作为目标应用程序,确定该目标应用程序的应用类型,作为该编译单元的应用场景。Furthermore, if the compilation unit can be invoked and executed by an application program, the application program calling the compilation unit is determined as the target application program, and the application type of the target application program is determined as the application scenario of the compilation unit.

确定该应用场景的执行速度,具体地,预先设置多个执行速度级别。作为一种实施方式,每个执行速度级别对应至少一个应用场景,下面,以上述的应用场景为应用类别为例。例如,该执行速度级别包括执行速度级别1、执行速度级别2、、、、执行速度级别10。则可以预先设定一个预设次数阈值的基准值,作为第二基准值。The execution speed of the application scenario is determined, specifically, multiple execution speed levels are preset. As an implementation manner, each execution speed level corresponds to at least one application scenario. In the following, the above-mentioned application scenarios are used as application categories as examples. For example, the execution speed level includes execution speed level 1, execution speed level 2, ,,, execution speed level 10. Then, a reference value of a preset times threshold may be preset as the second reference value.

例如,第一基准值对应执行速度级别5,第二基准值对应执行速度级别5,而每增加一个执行速度级别,将该第一基准值减小一个常数值C,且第二基准值减小一个常数值D,即执行速度级别6对应的预设数量阈值为第一基准值减C,执行速度级别6对应的预设次数阈值为第二基准值减D,而执行速度级别7对应的预设数量阈值为第一基准值减2C,预设次数阈值为第二基准值减2D。在执行速度级别5每降低一个执行速度级别,则该第一基准值增加一个常数值C,该第二基准值增加一个常数值D,即执行速度级别4对应的预设数量阈值为第一基准值加C,执行速度级别4对应的预设次数阈值为第二基准值加D,执行速度级别3对应的预设数量阈值为第一基准值加2C,执行速度级别3对应的预设次数阈值为第二基准值加2D,以此类推。因此,应用场景的执行速度越快,则预设次数阈值和预设次数阈值越小。For example, the first reference value corresponds to execution speed level 5, and the second reference value corresponds to execution speed level 5, and each time an execution speed level is increased, the first reference value is reduced by a constant value C, and the second reference value decreases A constant value D, that is, the preset number threshold corresponding to the execution speed level 6 is the first reference value minus C, the preset number threshold corresponding to the execution speed level 6 is the second reference value minus D, and the preset number threshold corresponding to the execution speed level 7 is Let the number threshold be the first reference value minus 2C, and the preset number threshold be the second reference value minus 2D. When the execution speed level 5 is reduced by one execution speed level, the first reference value is increased by a constant value C, and the second reference value is increased by a constant value D, that is, the preset number threshold corresponding to the execution speed level 4 is the first reference value value plus C, the preset number threshold corresponding to the execution speed level 4 is the second reference value plus D, the preset number threshold corresponding to the execution speed level 3 is the first reference value plus 2C, and the preset number threshold corresponding to the execution speed level 3 Add 2D to the second base value, and so on. Therefore, the faster the execution speed of the application scenario is, the smaller the preset times threshold and the preset times threshold are.

因此,确定该编译单元对应的应用类别,确定该应用类别所属的执行速度级别,根据上述预先设定的执行速度级别对应的预设数量阈值和预设次数阈值,确定该应用场景的执行速度对应的预设次数阈值和预设次数阈值。其中,应用场景的执行速度可以是该编译单元运行时,所需求的执行速度,具体地,可以是编译单元对应的应用程序或者功能模块的执行速度。例如,该编译单元对应的功能是Node.js服务器,或者该编译单元对应的应用程序的类别是Node.js服务器能,JavaScript引擎商可以将CLNT和CENT的值给小,生成相对多的热点代码,加快执行速度。Therefore, determine the application category corresponding to the compilation unit, determine the execution speed level to which the application category belongs, and determine the execution speed corresponding The preset times threshold and the preset times threshold of . The execution speed of the application scenario may be the required execution speed when the compilation unit is running, specifically, it may be the execution speed of the application or function module corresponding to the compilation unit. For example, if the function corresponding to this compilation unit is Node.js server, or the type of application program corresponding to this compilation unit is Node.js server function, JavaScript engine vendors can reduce the values of CLNT and CENT to generate relatively more hot codes , to speed up execution.

再者,确定该应用场景的启动速度,具体地,预先设置多个启动速度级别。作为一种实施方式,每个启动速度级别对应至少一个应用场景,下面,以上述的应用场景为应用类别为例。例如,该启动速度级别包括启动速度级别1、启动速度级别2、、、、启动速度级别10。则可以预先设定一个预设次数阈值的基准值,作为第三基准值。Furthermore, the startup speed of the application scenario is determined, specifically, a plurality of startup speed levels are preset. As an implementation manner, each startup speed level corresponds to at least one application scenario. In the following, the above-mentioned application scenario is used as an example of an application category. For example, the startup speed level includes startup speed level 1, startup speed level 2, ,,, startup speed level 10. Then, a reference value of a preset times threshold may be preset as the third reference value.

例如,第一基准值对应启动速度级别5,第三基准值对应启动速度级别5,而每增加一个启动速度级别,将该第一基准值增加一个常数值C,且第三基准值增加一个常数值E,即启动速度级别6对应的预设数量阈值为第一基准值加C,启动速度级别6对应的预设次数阈值为第三基准值加E,而启动速度级别7对应的预设数量阈值为第一基准值加2C,预设次数阈值为第三基准值加2E。在启动速度级别5每降低一个启动速度级别,则该第一基准值减去一个常数值C,该第三基准值减去一个常数值E,即启动速度级别4对应的预设数量阈值为第一基准值减C,启动速度级别4对应的预设次数阈值为第三基准值减E,启动速度级别3对应的预设数量阈值为第一基准值减2C,启动速度级别3对应的预设次数阈值为第三基准值减2E,以此类推。因此,应用场景的启动速度越快,则预设次数阈值和预设次数阈值越大。其中,应用场景的启动速度可以是该编译单元运行时,所需求的启动速度,具体地,可以是编译单元对应的应用程序或者功能模块的启动速度。例如,该编译单元对应的功能是网页搜索,或者该编译单元对应的应用程序的类别是搜索功能,JavaScript引擎商可以将CLNT和CENT的值给大,生成相对少的热点代码,减少字节码到机器码的编译时间消耗,快速启动。For example, the first reference value corresponds to the starting speed level 5, and the third reference value corresponds to the starting speed level 5, and every time a starting speed level is increased, the first reference value is increased by a constant value C, and the third reference value is increased by a constant value C. The value E, that is, the preset number threshold corresponding to the starting speed level 6 is the first reference value plus C, the preset number threshold corresponding to the starting speed level 6 is the third reference value plus E, and the preset number corresponding to the starting speed level 7 The threshold is the first reference value plus 2C, and the preset times threshold is the third reference value plus 2E. Every time a starting speed level is reduced at the starting speed level 5, a constant value C is subtracted from the first reference value, and a constant value E is subtracted from the third reference value, that is, the preset quantity threshold corresponding to the starting speed level 4 is the first A reference value minus C, the preset number threshold corresponding to the starting speed level 4 is the third reference value minus E, the preset number threshold corresponding to the starting speed level 3 is the first reference value minus 2C, and the preset number corresponding to the starting speed level 3 The times threshold is the third reference value minus 2E, and so on. Therefore, the faster the start-up speed of the application scenario, the greater the preset times threshold and the preset times threshold. The startup speed of the application scenario may be the required startup speed when the compilation unit is running, specifically, it may be the startup speed of the application program or function module corresponding to the compilation unit. For example, if the function corresponding to this compilation unit is web search, or the type of application program corresponding to this compilation unit is a search function, JavaScript engine vendors can increase the values of CLNT and CENT to generate relatively few hot codes and reduce bytecodes Compile time consumption to machine code, fast startup.

S306:若所述编译单元为热点代码,则执行预设操作。S306: If the compilation unit is a hot code, perform a preset operation.

需要说明的是,上述步骤未详细描述的部分,可以参考前述实施例,在此不再赘述。It should be noted that for parts not described in detail in the above steps, reference may be made to the foregoing embodiments, and details are not repeated here.

请参阅图4,其示出了本申请实施例提供的一种代码处理装置400的结构框图。该装置可以包括:第一获取模块401、第二获取模块402、确定模块403和执行模块404。Please refer to FIG. 4 , which shows a structural block diagram of a code processing apparatus 400 provided by an embodiment of the present application. The apparatus may include: a first acquiring module 401 , a second acquiring module 402 , a determining module 403 and an executing module 404 .

第一获取模块401,用于获取编译单元的代码数量。The first obtaining module 401 is configured to obtain the code quantity of the compilation unit.

第二获取模块402,用于获取编译单元的被执行次数。The second acquiring module 402 is configured to acquire the execution times of the compilation unit.

确定模块403,用于根据所述代码数量和所述被执行次数,确定所述编译单元是否为热点代码。The determination module 403 is configured to determine whether the compilation unit is a hot code according to the code quantity and the executed times.

执行模块404,用于若所述编译单元为热点代码,则执行预设操作。The execution module 404 is configured to execute a preset operation if the compilation unit is a hot code.

所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述装置和模块的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that for the convenience and brevity of the description, the specific working process of the devices and modules described above can refer to the corresponding process in the foregoing method embodiments, which will not be repeated here.

请参阅图5,其示出了本申请实施例提供的一种代码处理装置500的结构框图。该装置可以包括:第一获取模块510、第二获取模块520、确定模块530和执行模块540。Please refer to FIG. 5 , which shows a structural block diagram of a code processing apparatus 500 provided by an embodiment of the present application. The apparatus may include: a first obtaining module 510 , a second obtaining module 520 , a determining module 530 and an executing module 540 .

第一获取模块510,用于获取编译单元的代码数量。The first obtaining module 510 is configured to obtain the code quantity of the compilation unit.

第二获取模块520,用于获取编译单元的被执行次数。The second acquiring module 520 is configured to acquire the execution times of the compilation unit.

确定模块530,用于根据所述代码数量和所述被执行次数,确定所述编译单元是否为热点代码。The determination module 530 is configured to determine whether the compilation unit is a hot code according to the code quantity and the executed times.

进一步地,确定模块包括第一差值获取子模块531、第二差值获取子模块532和确定子模块533。Further, the determination module includes a first difference acquisition submodule 531 , a second difference acquisition submodule 532 and a determination submodule 533 .

第一差值获取子模块531用于获取所述代码数量与预设数量阈值之间的第一差值。The first difference obtaining sub-module 531 is used to obtain a first difference between the code quantity and a preset quantity threshold.

第二差值获取子模块532用于获取所述被执行次数与预设次数阈值之间的第二差值。The second difference obtaining sub-module 532 is used to obtain a second difference between the executed times and a preset times threshold.

确定子模块533用于根据所述第一差值和所述第二差值,确定所述编译单元是否为热点代码。The determination sub-module 533 is configured to determine whether the compilation unit is a hot code according to the first difference value and the second difference value.

进一步,确定子模块533还用于根据所述第一差值、所述第一差值对应的第一权重、所述第二差值以及所述第二差值对应的第二权重,获取热点代码评估值;若所述热点代码评估值大于指定评估值,则判定所述编译单元为热点代码。Further, the determining sub-module 533 is also configured to obtain the hotspot according to the first difference, the first weight corresponding to the first difference, the second difference, and the second weight corresponding to the second difference A code evaluation value; if the hot code evaluation value is greater than a specified evaluation value, it is determined that the compilation unit is a hot code.

进一步,确定子模块533还用于根据以下方式获取热点代码评估值:Further, the determination sub-module 533 is also used to obtain hot code evaluation values in the following manner:

S_HOT=Y_CLN*CVW+Y_CEN*CEW;S_HOT=Y_CLN*CVW+Y_CEN*CEW;

其中,S_HOT为热点代码评估值,Y_CLN为所述第一差值,CVW为所述第一权重,Y_CEN为所述第二差值,CEW为所述第二权重。Wherein, S_HOT is a hot code evaluation value, Y_CLN is the first difference, CVW is the first weight, Y_CEN is the second difference, and CEW is the second weight.

其中,所述编译单元在电子设备内运行,所述预设数量阈值和预设次数阈值根据所述电子设备的内存信息而设定。所述内存信息包括内存容量,所述内存容量越大,所述预设数量阈值和预设次数阈值越小。Wherein, the compiling unit runs in the electronic device, and the preset number threshold and preset times threshold are set according to the memory information of the electronic device. The memory information includes memory capacity, and the larger the memory capacity is, the smaller the preset quantity threshold and the preset times threshold are.

另外,所述预设数量阈值和预设次数阈值根据所述编译单元的应用场景而设定。所述应用场景的执行速度越快,则预设数量阈值和预设次数阈值越小。所述应用场景的启动速度越快,则预设数量阈值和预设次数阈值越大。In addition, the preset number threshold and the preset times threshold are set according to the application scenario of the compiling unit. The faster the execution speed of the application scenario is, the smaller the preset number threshold and the preset times threshold are. The faster the startup speed of the application scenario is, the larger the preset number threshold and the preset times threshold are.

执行模块540,用于若所述编译单元为热点代码,则执行预设操作。The execution module 540 is configured to execute a preset operation if the compilation unit is a hot code.

所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述装置和模块的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that for the convenience and brevity of the description, the specific working process of the devices and modules described above can refer to the corresponding process in the foregoing method embodiments, which will not be repeated here.

在本申请所提供的几个实施例中,模块相互之间的耦合可以是电性,机械或其它形式的耦合。In several embodiments provided in the present application, the coupling between the modules may be electrical, mechanical or other forms of coupling.

另外,在本申请各个实施例中的各功能模块可以集成在一个处理模块中,也可以是各个模块单独物理存在,也可以两个或两个以上模块集成在一个模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。In addition, each functional module in each embodiment of the present application may be integrated into one processing module, each module may exist separately physically, or two or more modules may be integrated into one module. The above-mentioned integrated modules can be implemented in the form of hardware or in the form of software function modules.

请参考图6,其示出了本申请实施例提供的一种电子设备的结构框图。该电子设备100可以是智能手机、平板电脑、电子书等能够运行应用程序的电子设备。本申请中的电子设备100可以包括一个或多个如下部件:处理器110、存储器120、以及一个或多个应用程序,其中一个或多个应用程序可以被存储在存储器120中并被配置为由一个或多个处理器110执行,一个或多个程序配置用于执行如前述方法实施例所描述的方法。Please refer to FIG. 6 , which shows a structural block diagram of an electronic device provided by an embodiment of the present application. The electronic device 100 may be an electronic device capable of running application programs, such as a smart phone, a tablet computer, and an e-book. The electronic device 100 in the present application may include one or more of the following components: a processor 110, a memory 120, and one or more application programs, wherein one or more application programs may be stored in the memory 120 and configured to be used by One or more processors 110 are executed, and one or more programs are configured to execute the methods described in the foregoing method embodiments.

处理器110可以包括一个或者多个处理核。处理器110利用各种接口和线路连接整个电子设备100内的各个部分,通过运行或执行存储在存储器120内的指令、程序、代码集或指令集,以及调用存储在存储器120内的数据,执行电子设备100的各种功能和处理数据。可选地,处理器110可以采用数字信号处理(Digital Signal Processing,DSP)、现场可编程门阵列(Field-Programmable Gate Array,FPGA)、可编程逻辑阵列(Programmable LogicArray,PLA)中的至少一种硬件形式来实现。处理器110可集成中央处理器(CentralProcessing Unit,CPU)、图像处理器(Graphics Processing Unit,GPU)和调制解调器等中的一种或几种的组合。其中,CPU主要处理操作系统、用户界面和应用程序等;GPU用于负责显示内容的渲染和绘制;调制解调器用于处理无线通信。可以理解的是,上述调制解调器也可以不集成到处理器110中,单独通过一块通信芯片进行实现。Processor 110 may include one or more processing cores. The processor 110 uses various interfaces and lines to connect various parts of the entire electronic device 100, and executes or executes instructions, programs, code sets or instruction sets stored in the memory 120, and calls data stored in the memory 120 to execute Various functions of the electronic device 100 and processing data. Optionally, the processor 110 may use at least one of Digital Signal Processing (Digital Signal Processing, DSP), Field-Programmable Gate Array (Field-Programmable Gate Array, FPGA), and Programmable Logic Array (Programmable LogicArray, PLA). implemented in the form of hardware. The processor 110 may integrate one or a combination of a central processing unit (Central Processing Unit, CPU), an image processor (Graphics Processing Unit, GPU), a modem, and the like. Among them, the CPU mainly handles the operating system, user interface and application programs, etc.; the GPU is used to render and draw the displayed content; the modem is used to handle wireless communication. It can be understood that, the above-mentioned modem may not be integrated into the processor 110, but may be realized by a communication chip alone.

存储器120可以包括随机存储器(Random Access Memory,RAM),也可以包括只读存储器(Read-Only Memory)。存储器120可用于存储指令、程序、代码、代码集或指令集。存储器120可包括存储程序区和存储数据区,其中,存储程序区可存储用于实现操作系统的指令、用于实现至少一个功能的指令(比如触控功能、声音播放功能、图像播放功能等)、用于实现下述各个方法实施例的指令等。存储数据区还可以存储终端100在使用中所创建的数据(比如电话本、音视频数据、聊天记录数据)等。The memory 120 may include a random access memory (Random Access Memory, RAM), and may also include a read-only memory (Read-Only Memory). The memory 120 may be used to store instructions, programs, codes, sets of codes, or sets of instructions. The memory 120 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playback function, an image playback function, etc.) , instructions for implementing the following method embodiments, and the like. The storage data area can also store data created by the terminal 100 during use (such as phonebook, audio and video data, chat record data) and the like.

请参考图7,其示出了本申请实施例提供的一种计算机可读存储介质的结构框图。该计算机可读介质700中存储有程序代码,所述程序代码可被处理器调用执行上述方法实施例中所描述的方法。Please refer to FIG. 7 , which shows a structural block diagram of a computer-readable storage medium provided by an embodiment of the present application. Program codes are stored in the computer-readable medium 700, and the program codes can be invoked by a processor to execute the methods described in the foregoing method embodiments.

计算机可读存储介质700可以是诸如闪存、EEPROM(电可擦除可编程只读存储器)、EPROM、硬盘或者ROM之类的电子存储器。可选地,计算机可读存储介质700包括非易失性计算机可读介质(non-transitory computer-readable storage medium)。计算机可读存储介质700具有执行上述方法中的任何方法步骤的程序代码710的存储空间。这些程序代码可以从一个或者多个计算机程序产品中读出或者写入到这一个或者多个计算机程序产品中。程序代码710可以例如以适当形式进行压缩。The computer readable storage medium 700 may be an electronic memory such as flash memory, EEPROM (Electrically Erasable Programmable Read Only Memory), EPROM, hard disk, or ROM. Optionally, the computer-readable storage medium 700 includes a non-transitory computer-readable storage medium (non-transitory computer-readable storage medium). The computer-readable storage medium 700 has a storage space for program code 710 for executing any method steps in the above methods. These program codes can be read from or written into one or more computer program products. Program code 710 may, for example, be compressed in a suitable form.

综上所述,本申请实施例提供的代码处理方法、装置、电子设备及计算机可读介质,分别获取编译单元的代码数量和被执行次数,并且根据代码数量和所述被执行次数,确定所述编译单元是否为热点代码,在确定编译单元为热点代码的情况下,执行预设操作。因此,基于编译单元的代码数量和被执行次数来确定编译单元是否为热点代码,相比仅根据执行次数来确定热点代码而言,使得判断维度更加丰富,使得热点代码的确定更加准确。To sum up, the code processing method, device, electronic device, and computer-readable medium provided by the embodiments of the present application obtain the code quantity and the number of execution times of the compiling unit respectively, and determine the number of codes to be executed according to the number of codes and the number of execution times. Whether the above compilation unit is a hot code, and if it is determined that the compilation unit is a hot code, perform a preset operation. Therefore, determining whether a compilation unit is a hot code based on the number of codes of the compilation unit and the number of times it is executed, compared with determining the hot code only based on the number of executions, makes the judgment dimension more abundant and makes the determination of the hot code more accurate.

因此,通过引进指标“代码体量”,涵盖以往的热点代码判定盲区,将更多有价值的代码块编译成机器码,加快JavaScript源代码的运行速度。通过控制指标“代码体量阀值”和“代码执行次数阀值”大小,在各种运行场景中,灵活选择生成热点代码的多少,以满足不同场景对启动速度或执行速度的需求。Therefore, by introducing the indicator "code volume", it covers the blind spot of hot code judgment in the past, compiles more valuable code blocks into machine code, and speeds up the running speed of JavaScript source code. By controlling the indicators "code size threshold" and "code execution times threshold", in various running scenarios, the amount of hot code generated can be flexibly selected to meet the needs of different scenarios for startup speed or execution speed.

另外,上述方法不仅适用于JavaScript引擎,在JVM(Java虚拟机)中引入指标“代码体量”(即代码数量)也同样适用。和JavaScript类似,在Java中,当代码块运行达到一定次数之后,JVM会将代码块从字节码编译成机器码,从而加快执行速度。通过在JVM中引入“代码体量”,更多有价值的代码块会被判定为热点代码,加快Java源码的执行速度。In addition, the above method is not only applicable to the JavaScript engine, but also applicable to the introduction of the indicator "code volume" (that is, the number of codes) in the JVM (Java Virtual Machine). Similar to JavaScript, in Java, when a code block runs for a certain number of times, the JVM will compile the code block from bytecode to machine code to speed up execution. By introducing "code size" into the JVM, more valuable code blocks will be judged as hot codes, speeding up the execution of Java source code.

最后应说明的是:以上实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不驱使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围。Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, rather than limiting them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: it can still Modifications are made to the technical solutions described in the foregoing embodiments, or equivalent replacements are made to some of the technical features; and these modifications or replacements do not drive the essence of the corresponding technical solutions away from the spirit and scope of the technical solutions of the various embodiments of the present application.

Claims (10)

1.一种代码处理方法,其特征在于,包括:1. A code processing method, characterized in that, comprising: 获取编译单元的代码数量;Get the code count of the compilation unit; 获取编译单元的被执行次数;Get the execution times of the compilation unit; 获取所述代码数量与预设数量阈值之间的第一差值;Acquiring a first difference between the number of codes and a preset number threshold; 获取所述被执行次数与预设次数阈值之间的第二差值;Obtain a second difference between the executed times and a preset times threshold; 根据所述第一差值、所述第一差值对应的第一权重、所述第二差值以及所述第二差值对应的第二权重,获取热点代码评估值;Acquiring a hot code evaluation value according to the first difference, the first weight corresponding to the first difference, the second difference, and the second weight corresponding to the second difference; 若所述热点代码评估值大于指定评估值,则判定所述编译单元为热点代码;If the evaluation value of the hot code is greater than a specified evaluation value, then determine that the compilation unit is a hot code; 若所述编译单元为热点代码,则执行预设操作。If the compilation unit is a hot code, a preset operation is performed. 2.根据权利要求1所述的方法,其特征在于,所述根据所述第一差值、所述第一差值对应的第一权重、所述第二差值以及所述第二差值对应的第二权重,获取热点代码评估值,包括:2. The method according to claim 1, characterized in that, according to the first difference, the first weight corresponding to the first difference, the second difference and the second difference Corresponding to the second weight, obtain the hot code evaluation value, including: 根据以下方式获取热点代码评估值:Obtain hot code evaluation values according to the following methods: S_HOT=Y_CLN*CVW+Y_CEN*CEW;S_HOT=Y_CLN*CVW+Y_CEN*CEW; 其中,S_HOT为热点代码评估值,Y_CLN为所述第一差值,CVW为所述第一权重,Y_CEN为所述第二差值,CEW为所述第二权重。Wherein, S_HOT is a hot code evaluation value, Y_CLN is the first difference, CVW is the first weight, Y_CEN is the second difference, and CEW is the second weight. 3.根据权利要求1所述的方法,其特征在于,所述编译单元在电子设备内运行,所述预设数量阈值和预设次数阈值根据所述电子设备的内存信息而设定。3 . The method according to claim 1 , wherein the compiling unit runs in an electronic device, and the preset number threshold and preset times threshold are set according to memory information of the electronic device. 4 . 4.根据权利要求3所述的方法,其特征在于,所述内存信息包括内存容量,所述内存容量越大,所述预设数量阈值和预设次数阈值越小。4 . The method according to claim 3 , wherein the memory information includes memory capacity, and the larger the memory capacity is, the smaller the preset number threshold and the preset number of times threshold are. 5.根据权利要求1所述的方法,其特征在于,所述预设数量阈值和预设次数阈值根据所述编译单元的应用场景而设定。5. The method according to claim 1, wherein the preset number threshold and the preset times threshold are set according to an application scenario of the compiling unit. 6.根据权利要求5所述的方法,其特征在于,所述应用场景的执行速度越快,则预设数量阈值和预设次数阈值越小。6. The method according to claim 5, wherein the faster the execution speed of the application scenario is, the smaller the preset number threshold and the preset times threshold are. 7.根据权利要求5所述的方法,其特征在于,所述应用场景的启动速度越快,则预设数量阈值和预设次数阈值越大。7. The method according to claim 5, wherein the faster the start-up speed of the application scene is, the greater the preset number threshold and the preset times threshold are. 8.一种代码处理装置,其特征在于,包括:8. A code processing device, comprising: 第一获取模块,用于获取编译单元的代码数量;The first obtaining module is used to obtain the code quantity of the compilation unit; 第二获取模块,用于获取编译单元的被执行次数;The second acquisition module is used to acquire the execution times of the compilation unit; 确定模块,用于获取所述代码数量与预设数量阈值之间的第一差值,获取所述被执行次数与预设次数阈值之间的第二差值,根据所述第一差值、所述第一差值对应的第一权重、所述第二差值以及所述第二差值对应的第二权重,获取热点代码评估值,若所述热点代码评估值大于指定评估值,则判定所述编译单元为热点代码;A determining module, configured to obtain a first difference between the number of codes and a preset number threshold, and obtain a second difference between the number of times executed and a preset number of times threshold, according to the first difference, The first weight corresponding to the first difference, the second difference, and the second weight corresponding to the second difference obtain a hot code evaluation value, and if the hot code evaluation value is greater than a specified evaluation value, then determining that the compilation unit is a hot code; 执行模块,用于若所述编译单元为热点代码,则执行预设操作。An execution module, configured to execute a preset operation if the compilation unit is a hot code. 9.一种电子设备,其特征在于,包括:9. An electronic device, characterized in that it comprises: 一个或多个处理器;one or more processors; 存储器;memory; 一个或多个应用程序,其中所述一个或多个应用程序被存储在所述存储器中并被配置为由所述一个或多个处理器执行, 所述一个或多个应用程序配置用于执行如权利要求1-7任一项所述的方法。one or more application programs, wherein the one or more application programs are stored in the memory and configured to be executed by the one or more processors, the one or more application programs are configured to perform The method according to any one of claims 1-7. 10.一种计算机可读介质,其特征在于,所述计算机可读介质存储有处理器可执行的程序代码,所述程序代码被所述处理器执行时使所述处理器执行权利要求1-7任一项所述方法。10. A computer-readable medium, characterized in that, the computer-readable medium stores program code executable by a processor, and when the program code is executed by the processor, the processor performs claim 1- 7. The method described in any one.
CN202010048686.7A 2020-01-16 2020-01-16 Code processing method, device, electronic equipment and computer readable medium Expired - Fee Related CN111258557B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010048686.7A CN111258557B (en) 2020-01-16 2020-01-16 Code processing method, device, electronic equipment and computer readable medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010048686.7A CN111258557B (en) 2020-01-16 2020-01-16 Code processing method, device, electronic equipment and computer readable medium

Publications (2)

Publication Number Publication Date
CN111258557A CN111258557A (en) 2020-06-09
CN111258557B true CN111258557B (en) 2023-08-18

Family

ID=70950717

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010048686.7A Expired - Fee Related CN111258557B (en) 2020-01-16 2020-01-16 Code processing method, device, electronic equipment and computer readable medium

Country Status (1)

Country Link
CN (1) CN111258557B (en)

Families Citing this family (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111258656B (en) * 2020-01-20 2022-06-28 展讯通信(上海)有限公司 Data processing device and terminal
CN111858066B (en) * 2020-07-30 2022-07-15 中国空气动力研究与发展中心超高速空气动力研究所 CPU + GPU heterogeneous parallel optimization method in pneumatic theory unified algorithm
CN112559088B (en) * 2020-12-29 2024-12-17 Oppo广东移动通信有限公司 Configuration file optimization method, device, server and storage medium
CN113568634B (en) * 2021-06-28 2022-05-17 荣耀终端有限公司 Application-optimized processing method and processing device
CN113377378B (en) * 2021-07-02 2024-11-29 北京百度网讯科技有限公司 Processing method, device, equipment and storage medium for small program
CN115185530A (en) * 2022-06-25 2022-10-14 平安银行股份有限公司 Compiling method, device, equipment and storage medium based on code conversion
CN115563015B (en) * 2022-11-09 2023-07-07 科东(广州)软件科技有限公司 Code heat statistics method, device, equipment and storage medium
JP2025120610A (en) * 2024-02-05 2025-08-18 株式会社東芝 Development Support Equipment

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2000045257A2 (en) * 1999-01-28 2000-08-03 Ati International Srl Executing programs for a first computer architecture on a computer of a second architecture
CA2860223A1 (en) * 2011-12-23 2013-06-27 The Arizona Board Of Regents On Behalf Of The University Of Arizona Methods of micro-specialization in database management systems
CN103729235A (en) * 2013-12-24 2014-04-16 华为技术有限公司 Java virtual machine (JVM) and compiling method thereof
CN105511942A (en) * 2015-12-02 2016-04-20 华为技术有限公司 Recognition method and device for hot point intermediate code in language virtual machine
CN105589729A (en) * 2015-12-28 2016-05-18 北京锐安科技有限公司 Dynamic compiling method and device based on embedded virtual machine
CN105607912A (en) * 2015-12-24 2016-05-25 华为技术服务有限公司 Java object allocation optimization method, apparatus and device

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7150012B2 (en) * 2002-10-15 2006-12-12 Nokia Corporation Method and apparatus for accelerating program execution in platform-independent virtual machines

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2000045257A2 (en) * 1999-01-28 2000-08-03 Ati International Srl Executing programs for a first computer architecture on a computer of a second architecture
CA2860223A1 (en) * 2011-12-23 2013-06-27 The Arizona Board Of Regents On Behalf Of The University Of Arizona Methods of micro-specialization in database management systems
CN103729235A (en) * 2013-12-24 2014-04-16 华为技术有限公司 Java virtual machine (JVM) and compiling method thereof
CN105511942A (en) * 2015-12-02 2016-04-20 华为技术有限公司 Recognition method and device for hot point intermediate code in language virtual machine
CN105607912A (en) * 2015-12-24 2016-05-25 华为技术服务有限公司 Java object allocation optimization method, apparatus and device
CN105589729A (en) * 2015-12-28 2016-05-18 北京锐安科技有限公司 Dynamic compiling method and device based on embedded virtual machine

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
一种混合型运行时信息分析方法;韩洪波等;《微计算机应用》;第31卷(第9期);第34-42页 *

Also Published As

Publication number Publication date
CN111258557A (en) 2020-06-09

Similar Documents

Publication Publication Date Title
CN111258557B (en) Code processing method, device, electronic equipment and computer readable medium
CN111061484B (en) Code compiling method, device, server, user terminal and readable medium
CN111078318B (en) Configuration file processing method, device, system and storage medium
CN110941424B (en) Compilation parameter optimization method, device and electronic equipment
CN112948026B (en) Hotspot code processing method, device, server, electronic device and storage medium
CN107423213B (en) File descriptor distribution detection method and device
CN114238948B (en) Application program detection method, device, electronic device and storage medium
CN111625289B (en) Method and device for quickly starting application program and electronic equipment
CN109947624B (en) State monitoring method and device
CN112473144A (en) Game resource data processing method and device
CN108717374B (en) Method, device, and computer equipment for preheating when Java virtual machine is started
CN112667405B (en) Information processing method, device, equipment and storage medium
CN114911706B (en) Use case recommendation method, device, equipment and storage medium
WO2021115177A1 (en) Application installation method and apparatus, terminal device, server and storage medium
CN110543338A (en) dynamic loading method and device for files
CN110609689A (en) Application installation and operation method and device
JP3992102B2 (en) Compiler device, compilation method, compiler program, and recording medium
CN112559088B (en) Configuration file optimization method, device, server and storage medium
CN115705294B (en) Method, device, electronic device and medium for obtaining function call information
CN103154891A (en) Virtual machine stage detection
CN117632746A (en) Pile inserting processing method and device, storage medium and electronic equipment
CN112948012B (en) Configuration file push method, device, server and storage medium
CN111400135A (en) Method and device for extracting service data
CN107423093B (en) Control method and apparatus, computer apparatus, and computer-readable storage medium
CN107450937B (en) Application program running method and running device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20230818