Disclosure of Invention
In view of the above problems, the present invention provides a method for loading a plug-in a virtual machine and an electronic terminal, so as to solve or partially solve the technical problem that the loading speed is slow when the plug-in is loaded for the first time.
In order to solve the above technical problem, the present invention provides a method for loading a plug-in a virtual machine, wherein a preset add-in mode of the virtual machine is configured as an interpretation-only mode, and the method comprises:
obtaining a plug-in to be loaded;
determining a corresponding preset loading mode when the plug-in to be loaded is loaded for the first time;
determining a byte code corresponding to the plug-in to be loaded from the plug-in to be loaded based on a corresponding preset loading mode when the plug-in to be loaded is loaded for the first time;
and interpreting and executing the byte code corresponding to the plug-in to be loaded so as to load the plug-in to be loaded.
Preferably, the determining, based on a preset loading mode corresponding to the first time of loading the to-be-loaded plugin, the bytecode corresponding to the to-be-loaded plugin from the to-be-loaded plugin specifically includes:
determining an executable file from the plug-in to be loaded based on a corresponding preset loading mode when the plug-in to be loaded is loaded for the first time;
determining the byte code corresponding to the plug-in to be loaded from the executable file.
Preferably, after the interpreting executes the bytecode corresponding to the plug-in to be loaded to load the plug-in to be loaded, the method further includes:
and compiling the code corresponding to the plug-in to be loaded into machine code.
Preferably, the compiling the code corresponding to the plug-in to be loaded into the machine code specifically includes:
analyzing codes executed in the plug-in to be loaded in real time, and determining hot codes from the executed codes;
and compiling the hot code to obtain the machine code.
Preferably, the analyzing the code executed in the plug-in to be loaded in real time and determining the hot code from the executed code specifically includes:
judging whether the execution frequency of the executed code is higher than a preset frequency threshold value;
if yes, determining the code of which the execution frequency is higher than the preset frequency threshold value in the executed codes as the hot code.
Preferably, the compiling the code corresponding to the plug-in to be loaded into the machine code specifically includes:
and fully compiling the code corresponding to the plug-in to be loaded so as to obtain the machine code.
Preferably, the compiling the code corresponding to the plug-in to be loaded into the machine code specifically includes:
judging whether a system corresponding to the electronic terminal is in an idle state or not in real time;
if so, compiling the code corresponding to the plug-in to be loaded into the machine code.
Preferably, the compiling the code corresponding to the plug-in to be loaded into the machine code specifically includes:
judging whether a system corresponding to the electronic terminal is in a charging state in real time;
if so, compiling the code corresponding to the plug-in to be loaded into the machine code.
Preferably, after the compiling the code corresponding to the plug-in to be loaded into the machine code, the method further includes:
receiving an instruction for reloading the plug-in to be loaded;
and based on the reloading instruction, the machine code is executed to reload and execute the plug-in to be loaded.
The invention discloses an electronic terminal, which loads a plug-in to be loaded in a virtual machine, wherein a preset loading mode of the virtual machine is configured to be an interpretation only mode, and the electronic terminal comprises:
the obtaining module is used for obtaining a plug-in to be loaded;
the first determining module is used for determining a corresponding preset loading mode when the plug-in to be loaded is loaded for the first time;
the second determining module is used for determining the byte code corresponding to the plug-in to be loaded from the plug-in to be loaded based on a corresponding preset loading mode when the plug-in to be loaded is loaded for the first time;
and the interpretation execution module is used for interpreting and executing the byte codes corresponding to the plug-ins to be loaded so as to load the plug-ins to be loaded.
Preferably, the second determining module specifically includes:
the third determining module is used for determining an executable file from the plug-in to be loaded based on a corresponding preset loading mode when the plug-in to be loaded is loaded for the first time;
and the fourth determining module is used for determining the byte code corresponding to the plug-in to be loaded from the executable file.
Preferably, the electronic terminal further includes:
the first compiling module is used for compiling the code corresponding to the plug-in to be loaded into the machine code after the byte code corresponding to the plug-in to be loaded is interpreted and executed so as to load the plug-in to be loaded.
Preferably, the first compiling module specifically includes:
the analysis module is used for analyzing the codes executed in the plug-in to be loaded in real time and determining hot codes from the executed codes;
and the second compiling module is used for compiling the hot code to obtain the machine code.
Preferably, the analysis module specifically includes:
the first judgment module is used for judging whether the execution frequency of the executed code is higher than a preset frequency threshold value;
and if so, determining the code with the execution frequency higher than the preset frequency threshold value in the executed codes as the hot code.
Preferably, the first compiling module specifically includes:
and the third compiling module is used for fully compiling the code corresponding to the plug-in to be loaded so as to obtain the machine code.
Preferably, the first compiling module specifically includes:
the second judgment module judges whether a system corresponding to the electronic terminal is in an idle state in real time;
and if so, compiling the code corresponding to the plug-in to be loaded into the machine code.
Preferably, the first compiling module specifically includes:
the third judgment module is used for judging whether a system corresponding to the electronic terminal is in a charging state in real time;
and if so, compiling the code corresponding to the plug-in to be loaded into the machine code.
Preferably, the electronic terminal further includes:
the receiving module is used for receiving a command for reloading the plug-in to be loaded after compiling the code corresponding to the plug-in to be loaded into the machine code;
and the loading module is used for operating the machine code based on the reloading instruction so as to reload and operate the plug-in to be loaded.
The invention discloses a computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the above-mentioned method.
The invention discloses a computer device, which comprises a memory, a processor and a computer program stored on the memory and capable of running on the processor, and is characterized in that the steps of the method are realized when the processor executes the program.
The technical scheme provided in the embodiment of the application at least has the following technical effects or advantages:
the invention provides a method for loading a plug-in a virtual machine and an electronic terminal. In order to solve the technical problem that the loading speed is low when the current plug-in is loaded for the first time, the method comprises the steps of firstly obtaining a plug-in to be loaded, and determining a corresponding preset loading mode when the plug-in to be loaded is loaded for the first time; then, based on a corresponding preset loading mode when the plug-in to be loaded is loaded for the first time, because the preset loading mode of the virtual machine is configured to be an interpretation mode only, in the mode, only the byte code corresponding to the plug-in to be loaded needs to be determined from the plug-in to be loaded; the plug-in to be loaded is loaded by interpreting and executing the byte code corresponding to the plug-in to be loaded, and the plug-in to be loaded is not started by compiling all the codes of the plug-in into machine codes when the plug-in is loaded for the first time, so that the problem of slow loading speed caused by time consumption of compiling is avoided, and the plug-in loading speed can be improved.
The foregoing description is only an overview of the technical solutions of the present invention, and the embodiments of the present invention are described below in order to make the technical means of the present invention more clearly understood and to make the above and other objects, features, and advantages of the present invention more clearly understandable.
Detailed Description
Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
The name to which the invention relates is explained as follows:
the dex file is an executable file on an Android platform, each plug-in has a dex file, all source codes of the plug-in are contained in the dex file, and the corresponding source codes can be obtained through a decompilation tool.
ART virtual machine, introduced starting from Android 4.4, is an option on Android 4.4, Android 5 and later is a default option. The ART virtual machine executes the dex2 at command, and the default dex2 at procedure compiling rule is as follows: and (4) fully compiling. Because the ART virtual machine executes local machine code, the system compiles the byte code in the early dex file into the machine code at one time during the software installation process (if a plug-in is operated, the plug-in loading process). The compiling method of obtaining machine code by compiling in advance is called full compiling. The process of plug-in loading is slow, precisely because it is compiled in advance.
Therefore, in order to improve the loading speed of loading the plug-in for the first time, the invention provides a method for loading the plug-in the virtual machine.
The preset adding mode of the virtual machine is configured to be an interpretation-only mode, and the interpretation-only mode in the embodiment of the invention means that only the byte codes of the plug-ins to be loaded are interpreted, and the byte codes of the plug-ins to be loaded are directly prohibited from being compiled into machine codes when the plug-ins to be loaded are loaded for the first time.
In this mode, the first time the plug-in is loaded, the plug-in is not compiled, but only the byte code in the plug-in (also called boot code, used to boot the plug-in) is interpreted, so the first time the plug-in is loaded can be booted quickly. When the equipment idles and charges, the codes in the plug-in are compiled into machine codes for being used in the next loading. Of course, in order to improve the efficiency of compiling, in the process of loading and running the plug-in for the first time, since the code in the plug-in is analyzed during the execution, the analysis result of the code is saved. Therefore, when the equipment is idled and charged, the ART virtual machine can only compile the frequently executed codes (called as hot codes in the invention) according to the analysis result, and does not compile other codes. Through the implementation mode, the plug-in can be quickly loaded when the plug-in is loaded for the first time, and the performance is not lost when the plug-in is loaded again and runs.
However, the plug-ins described in the prior art can only be loaded in a 'full compilation' manner, because when a plug-in is started through a plug-in framework, hybrid compilation cannot be used because the installation logic of the system itself of the electronic terminal is not executed, and what is executed when the plug-in is loaded is the old logic, namely: the plug-in is still loaded in a 'full compilation' manner, and cannot enjoy the benefits of hybrid compilation. In the present invention, however, the plug-in must go through the dex2oat process, and the dex2oat requires various input parameters. Therefore, the application modifies the parameter-filter-in the dex2oat, thereby realizing the default behavior of the dex2oat process on the ART virtual machine.
In a specific implementation process, a process of loading the plug-in is actually a process of dynamically loading a code by the system, and if a virtual machine used in the current electronic terminal is an ART virtual machine, in the process of dynamically loading the code, the system executes a dex2oat command:
dex2oat command: -dex-file ═ xxxx.apk; -at-file ═ xxxx.odex; -filter ═ speed.
Wherein:
-dex-file is an input parameter of the dex2oat command, meaning: APK being executed is xxxx.
-at-file is an input parameter to the dex2 at command, meaning: the output result after the command is executed is xxxx.
-the compiler-filter is an input parameter of the dex2oat command, which is used to specify the compilation mode of the current dex2oat command.
In the prior art, the loading plug-in usually sets "— compiler-filter ═ speed". The meaning is as follows: the current dex2oat process requires maximum compilation of machine code, and this compilation mode is called "full compilation" compilation mode. The invention modifies the full compiling mode in the virtual machine into the interpretation mode, namely: "- - -filter-speed" is modified as: "- - - -filter ═ interpret-only". Through the modification of the parameters, the full compiling mode in the virtual machine can be modified into the interpretation-only mode. 'Interpretet-only' is literally understood to mean "explain only" the schema, and to explain further: in the current mode, all code is interpreted and executed, and is not compiled into any machine code. Whereas, since the Android system is backward compatible, the bytecode-level compatibility is naturally supported for this modification. Therefore, when the ART virtual machine loads the plug-in, the modification can still ensure the normal operation of the plug-in loading.
The above is an introduction of the present invention to loading a plug-in, and in order to more clearly illustrate and explain the present invention, the present invention discloses a method for loading a plug-in a virtual machine in the following embodiments.
Referring to fig. 1, specifically described below, an embodiment of the present invention discloses a method for loading a plug-in a virtual machine, where a preset add-on mode of the virtual machine is configured as an explain-only mode, and specifically includes the following steps:
and step 11, obtaining a plug-in unit to be loaded.
In a specific implementation process, the plug-in to be loaded is placed into a virtual machine, and the virtual machine is used for loading and running the plug-in to be loaded. The virtual machine in the embodiment of the invention refers to an ART virtual machine running in an android system, so that the ART virtual machine obtains the plug-in to be loaded. The plug-in to be loaded in the embodiment of the invention is not limited in type, for example, some plug-in programs can help users to browse the internet more conveniently or call an internet access auxiliary function, some plug-ins can help users to pay online, and the like.
When the plug-in is loaded for the first time, a plurality of processes such as downloading, installing, starting and running are actually included. After the first loading of the plug-in, the plug-in is loaded again (the second loading and subsequent multiple loads may also be called reloading) only represents that the running plug-in is started.
And step 12, determining a corresponding preset loading mode when the plug-in to be loaded is loaded for the first time.
In the embodiment of the present invention, determining the preset loading mode corresponding to the first loading of the plug-in to be loaded specifically includes: executing a dex2oat command on the to-be-loaded plug-in, and determining that a corresponding preset loading mode when the to-be-loaded plug-in is loaded for the first time is an interpretation only mode, wherein the interpretation only mode is specifically used for interpreting and executing the byte codes of the to-be-loaded plug-in, and the byte codes of the to-be-loaded plug-in are prohibited from being compiled into machine codes when the to-be-loaded plug-in is loaded for the first time.
That is to say, the preset loading mode corresponding to the first loading of the plug-in to be loaded is the interpretation-only mode. In the prior art, the first-time loading mode of the plug-in is actually a 'full-compilation' mode, that is, when the plug-in is loaded for the first time, the code of the plug-in needs to be compiled into machine code in its entirety, and then the machine code is executed to load the plug-in. In the embodiment of the present invention, an input parameter "- - -filter" in the dex2oat command is modified as follows: "- - - -filter ═ interpret-only". That is, embodiments of the present invention modify the first-time loading mode of a plug-in from a 'fully compiled' mode to an 'explain only' mode. Therefore, when executing the dex2oat command, the preset loading mode corresponding to the first loading of the plug-in to be loaded is determined as the interpretation-only mode based on the modified input parameters. Of course, when the loading mode is changed, in the process of executing the first loading of the plug-in to be loaded according to the embodiment of the present invention, the plug-in to be loaded may be loaded according to the loading mode specified in the explain-only mode. The interpretation-only mode in the embodiment of the invention is to interpret and execute only the byte codes of the plug-ins to be loaded, and directly forbid the byte codes of the plug-ins to be loaded from being compiled into machine codes when the plug-ins to be loaded are loaded for the first time. Therefore, when the plug-in is loaded for the first time, the byte code of the plug-in to be loaded can be directly interpreted and executed by adopting the interpretation loading mode to achieve the purpose of quickly starting the plug-in to be loaded, the byte code in the plug-in to be loaded does not need to be compiled into machine code for starting, and the situation that the starting is slowed down due to the time consumed by compiling does not occur, which is the difference between the embodiment of the invention and the prior art.
And step 13, determining the byte code corresponding to the plug-in to be loaded from the plug-in to be loaded based on the corresponding preset loading mode when the plug-in to be loaded is loaded for the first time.
In a specific implementation process, the plug-in to be loaded actually consists of a large amount of codes, and of course, different codes can be classified according to functions. In order to describe the plug-in to be loaded according to the embodiment of the present invention in more detail, the present invention refers to a code contained in an executable file (dex file) in the plug-in to be loaded as a bytecode (which may also be called a boot code), and mainly functions to boot the plug-in to be loaded. And the code in the plug-in to be loaded contains bytecode.
Therefore, as an optional implementation manner, in a specific implementation process of determining the bytecode corresponding to the plug-in to be loaded from the plug-in to be loaded based on the preset loading mode corresponding to the plug-in to be loaded when the plug-in to be loaded is loaded for the first time, the executable file is determined from the plug-in to be loaded based on the preset loading mode corresponding to the plug-in to be loaded when the plug-in to be loaded is loaded for the first time; determining the byte code corresponding to the plug-in to be loaded from the executable file.
The executable file refers to a dex file, each plug-in has the dex file, all source codes of the plug-in are contained in the dex file, and the corresponding source codes can be obtained through a decompilation tool.
Therefore, when executing the dex file, the bytecode corresponding to the plug-in to be loaded is obtained to start the plug-in to be loaded.
Of course, since it is determined in the embodiment of the present invention that the preset loading mode for loading the to-be-loaded plug-in for the first time is the interpretation-only mode, the bytecode for executing the to-be-loaded plug-in is directly interpreted according to the manner specified by the interpretation-only mode to achieve the purpose of quickly starting the to-be-loaded plug-in, and the bytecode in the to-be-loaded plug-in does not need to be compiled into the machine code for starting, so that the situation that the starting is slowed down due to the time consumed by the compiling does not occur.
And 14, interpreting and executing the byte codes corresponding to the plug-ins to be loaded so as to load the plug-ins to be loaded.
After the above steps, in order to facilitate the reloading of the plug-in to be loaded, the code corresponding to the plug-in to be loaded is compiled into machine code. That is to say, in the embodiment of the present invention, when the plug-in is loaded for the first time, the byte code corresponding to the plug-in to be loaded is interpreted and executed to load the plug-in. When the plug-in to be loaded is loaded again (the second loading and the subsequent multiple loading can also be called reloading), the plug-in to be loaded is loaded by running the machine code, so that after the first loading, the code corresponding to the plug-in to be loaded needs to be compiled into the machine code. And at this time, the code corresponding to the plug-in to be loaded comprises the byte code in the dex file.
In a specific implementation, there are two compiling methods.
And if the code corresponding to the plug-in to be loaded is compiled in a 'full compiling' mode, fully compiling the code corresponding to the plug-in to be loaded so as to obtain the machine code. Furthermore, the full compilation is performed on all codes corresponding to the plug-in to be loaded, so as to obtain the machine code.
One way to compile the code corresponding to the plug-in to be loaded is a partially compiled way. In the specific implementation process of compiling the code corresponding to the plug-in to be loaded into the machine code, analyzing the code executed in the plug-in to be loaded in real time, and determining a hot code from the executed code; and compiling the hot code to obtain the machine code. Generally, the plug-in to be loaded runs after being started, so that in the process of starting running, the ART virtual machine analyzes the code executed in the plug-in to be loaded in real time, wherein the executed code not only comprises byte codes used in starting, but also comprises codes called in the running process. And determines hot code from the executed code. Hot code, which refers to code that executes at a frequency above a preset frequency threshold. Therefore, in the specific process of determining the hot code from the executed code, whether the execution frequency of the executed code is higher than a preset frequency threshold value is judged; if yes, determining the code of which the execution frequency is higher than the preset frequency threshold value in the executed codes as the hot code. After determining the hot code, the hot code is compiled to obtain the machine code.
Further, as an alternative embodiment, the "full compilation" may be performed on a plug-in that is "interpreted only" and loaded when the device is idle and charging. Such reloading of the plug-in may then take advantage of the "fully compiled" plug-in. Therefore, in order to reduce the operating pressure of the electronic terminal, whether a system corresponding to the electronic terminal is in an idle state or not can be judged in real time; if so, compiling the code corresponding to the plug-in to be loaded into the machine code. Or judging whether a system corresponding to the electronic terminal is in a charging state in real time; if so, compiling the code corresponding to the plug-in to be loaded into the machine code.
As an alternative embodiment, after compiling the code corresponding to the plug-in to be loaded into the machine code, an instruction for reloading the plug-in to be loaded may be received; and then based on the reloading instruction, the machine code is executed to reload and execute the plug-in to be loaded.
The following embodiments describe an electronic terminal based on the same inventive concept. The electronic terminal loads the plug-in to be loaded in the virtual machine, and the preset loading mode of the virtual machine is configured to be the interpretation-only mode.
Referring to fig. 2, the electronic terminal includes:
an obtaining module 21, configured to obtain a plug-in to be loaded;
the first determining module 22 is configured to determine a preset loading mode corresponding to the first loading of the plug-in to be loaded;
a second determining module 23, configured to determine, based on a preset loading mode corresponding to the first time of loading the to-be-loaded plug-in, a bytecode corresponding to the to-be-loaded plug-in from the to-be-loaded plug-in;
and the interpretation execution module 24 is configured to interpret and execute the bytecode corresponding to the plug-in to be loaded so as to load the plug-in to be loaded.
As an optional embodiment, the second determining module 23 specifically includes:
the third determining module is used for determining an executable file from the plug-in to be loaded based on a corresponding preset loading mode when the plug-in to be loaded is loaded for the first time;
and the fourth determining module is used for determining the byte code corresponding to the plug-in to be loaded from the executable file.
As an optional embodiment, the electronic terminal further includes:
the first compiling module is used for compiling the code corresponding to the plug-in to be loaded into the machine code after the byte code corresponding to the plug-in to be loaded is interpreted and executed so as to load the plug-in to be loaded.
As an optional embodiment, the first compiling module specifically includes:
the analysis module is used for analyzing the codes executed in the plug-in to be loaded in real time and determining hot codes from the executed codes;
and the second compiling module is used for compiling the hot code to obtain the machine code.
As an optional embodiment, the analysis module specifically includes:
the first judgment module is used for judging whether the execution frequency of the executed code is higher than a preset frequency threshold value;
and if so, determining the code with the execution frequency higher than the preset frequency threshold value in the executed codes as the hot code.
As an optional embodiment, the first compiling module specifically includes:
and the third compiling module is used for fully compiling the code corresponding to the plug-in to be loaded so as to obtain the machine code.
As an optional embodiment, the first compiling module specifically includes:
the second judgment module judges whether a system corresponding to the electronic terminal is in an idle state in real time;
and if so, compiling the code corresponding to the plug-in to be loaded into the machine code.
As an optional embodiment, the first compiling module specifically includes:
the third judgment module is used for judging whether a system corresponding to the electronic terminal is in a charging state in real time;
and if so, compiling the code corresponding to the plug-in to be loaded into the machine code.
As an optional embodiment, the electronic terminal further includes:
the receiving module is used for receiving a command for reloading the plug-in to be loaded after compiling the code corresponding to the plug-in to be loaded into the machine code;
and the loading module is used for operating the machine code based on the reloading instruction so as to reload and operate the plug-in to be loaded.
An embodiment of the invention discloses a computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the above-mentioned method embodiment.
The embodiment of the invention discloses computer equipment which comprises a memory, a processor and a computer program which is stored on the memory and can run on the processor, wherein the steps of the method embodiment are realized when the processor executes the program.
Through one or more embodiments of the present invention, the present invention has the following advantageous effects or advantages:
the invention provides a method for loading a plug-in a virtual machine and an electronic terminal. In order to solve the technical problem that the loading speed is low when the current plug-in is loaded for the first time, the method comprises the steps of firstly obtaining a plug-in to be loaded, and determining a corresponding preset loading mode when the plug-in to be loaded is loaded for the first time; then, based on a corresponding preset loading mode when the plug-in to be loaded is loaded for the first time, because the preset loading mode of the virtual machine is configured to be an interpretation mode only, in the mode, only the byte code corresponding to the plug-in to be loaded needs to be determined from the plug-in to be loaded; the plug-in to be loaded is loaded by interpreting and executing the byte code corresponding to the plug-in to be loaded, and the plug-in to be loaded is not started by compiling all the codes of the plug-in into machine codes when the plug-in is loaded for the first time, so that the problem of slow loading speed caused by time consumption of compiling is avoided, and the plug-in loading speed can be improved.
The algorithms and displays presented herein are not inherently related to any particular computer, virtual machine, or other apparatus. Various general purpose systems may also be used with the teachings herein. The required structure for constructing such a system will be apparent from the description above. Moreover, the present invention is not directed to any particular programming language. It is appreciated that a variety of programming languages may be used to implement the teachings of the present invention as described herein, and any descriptions of specific languages are provided above to disclose the best mode of the invention.
In the description provided herein, numerous specific details are set forth. It is understood, however, that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure an understanding of this description.
Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the invention, various features of the invention are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the disclosure and aiding in the understanding of one or more of the various inventive aspects. However, the disclosed method should not be interpreted as reflecting an intention that: that the invention as claimed requires more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into this detailed description, with each claim standing on its own as a separate embodiment of this invention.
Those skilled in the art will appreciate that the modules in the device in an embodiment may be adaptively changed and disposed in one or more devices different from the embodiment. The modules or units or components of the embodiments may be combined into one module or unit or component, and furthermore they may be divided into a plurality of sub-modules or sub-units or sub-components. All of the features disclosed in this specification (including any accompanying claims, abstract and drawings), and all of the processes or elements of any method or apparatus so disclosed, may be combined in any combination, except combinations where at least some of such features and/or processes or elements are mutually exclusive. Each feature disclosed in this specification (including any accompanying claims, abstract and drawings) may be replaced by alternative features serving the same, equivalent or similar purpose, unless expressly stated otherwise.
Furthermore, those skilled in the art will appreciate that while some embodiments herein include some features included in other embodiments, rather than other features, combinations of features of different embodiments are meant to be within the scope of the invention and form different embodiments. For example, in the following claims, any of the claimed embodiments may be used in any combination.
The various component embodiments of the invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. Those skilled in the art will appreciate that a microprocessor or Digital Signal Processor (DSP) may be used in practice to implement some or all of the functionality of some or all of the components of a gateway, proxy server, system according to embodiments of the present invention. The present invention may also be embodied as apparatus or device programs (e.g., computer programs and computer program products) for performing a portion or all of the methods described herein. Such programs implementing the present invention may be stored on computer-readable media or may be in the form of one or more signals. Such a signal may be downloaded from an internet website or provided on a carrier signal or in any other form.
It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, and that those skilled in the art will be able to design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention may be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means may be embodied by one and the same item of hardware. The usage of the words first, second and third, etcetera do not indicate any ordering. These words may be interpreted as names.
The invention discloses A1, a method for loading plug-ins in a virtual machine, which is characterized in that a preset adding mode of the virtual machine is configured to be an interpretation-only mode, and the method comprises the following steps:
obtaining a plug-in to be loaded;
determining a corresponding preset loading mode when the plug-in to be loaded is loaded for the first time;
determining a byte code corresponding to the plug-in to be loaded from the plug-in to be loaded based on a corresponding preset loading mode when the plug-in to be loaded is loaded for the first time;
and interpreting and executing the byte code corresponding to the plug-in to be loaded so as to load the plug-in to be loaded.
A2, the method as recited in a1, wherein the determining, from the to-be-loaded plug-in, the bytecode corresponding to the to-be-loaded plug-in based on a preset loading mode corresponding to when the to-be-loaded plug-in is loaded for the first time includes:
determining an executable file from the plug-in to be loaded based on a corresponding preset loading mode when the plug-in to be loaded is loaded for the first time;
determining the byte code corresponding to the plug-in to be loaded from the executable file.
A3, the method according to any of the claims A1-A2, wherein after the interpreting executes the bytecode corresponding to the plug-in to be loaded to load the plug-in to be loaded, the method further comprises:
and compiling the code corresponding to the plug-in to be loaded into machine code.
A4, the method as claimed in A3, wherein the compiling the code corresponding to the plug-in to be loaded into machine code specifically includes:
analyzing codes executed in the plug-in to be loaded in real time, and determining hot codes from the executed codes;
and compiling the hot code to obtain the machine code.
A5, the method according to a4, wherein the analyzing the code executed in the plug-in to be loaded in real time and determining the hot code from the executed code, specifically comprises:
judging whether the execution frequency of the executed code is higher than a preset frequency threshold value;
if yes, determining the code of which the execution frequency is higher than the preset frequency threshold value in the executed codes as the hot code.
A6, the method as claimed in A3, wherein the compiling the code corresponding to the plug-in to be loaded into machine code specifically includes:
and fully compiling the code corresponding to the plug-in to be loaded so as to obtain the machine code.
A7, the method as claimed in A3, wherein the compiling the code corresponding to the plug-in to be loaded into machine code specifically includes:
judging whether a system corresponding to the electronic terminal is in an idle state or not in real time;
if so, compiling the code corresponding to the plug-in to be loaded into the machine code.
A8, the method as claimed in A3, wherein the compiling the code corresponding to the plug-in to be loaded into machine code specifically includes:
judging whether a system corresponding to the electronic terminal is in a charging state in real time;
if so, compiling the code corresponding to the plug-in to be loaded into the machine code.
A9, the method as in A3, wherein after compiling the code corresponding to the plug-in to be loaded into machine code, the method further comprises:
receiving an instruction for reloading the plug-in to be loaded;
and based on the reloading instruction, the machine code is executed to reload and execute the plug-in to be loaded.
B10, an electronic terminal, wherein the electronic terminal is configured to load a plug-in to be loaded in a virtual machine, a preset loading mode of the virtual machine is configured as an interpretation-only mode, and the electronic terminal comprises:
the obtaining module is used for obtaining a plug-in to be loaded;
the first determining module is used for determining a corresponding preset loading mode when the plug-in to be loaded is loaded for the first time;
the second determining module is used for determining the byte code corresponding to the plug-in to be loaded from the plug-in to be loaded based on a corresponding preset loading mode when the plug-in to be loaded is loaded for the first time;
and the interpretation execution module is used for interpreting and executing the byte codes corresponding to the plug-ins to be loaded so as to load the plug-ins to be loaded.
B11, the electronic terminal according to B10, wherein the second determining module specifically includes:
the third determining module is used for determining an executable file from the plug-in to be loaded based on a corresponding preset loading mode when the plug-in to be loaded is loaded for the first time;
and the fourth determining module is used for determining the byte code corresponding to the plug-in to be loaded from the executable file.
B12, the electronic terminal according to any of claims B10-B11, further comprising:
the first compiling module is used for compiling the code corresponding to the plug-in to be loaded into the machine code after the byte code corresponding to the plug-in to be loaded is interpreted and executed so as to load the plug-in to be loaded.
B13, the electronic terminal according to B12, wherein the first compiling module specifically includes:
the analysis module is used for analyzing the codes executed in the plug-in to be loaded in real time and determining hot codes from the executed codes;
and the second compiling module is used for compiling the hot code to obtain the machine code.
B14, the electronic terminal as recited in B13, wherein the analysis module specifically comprises:
the first judgment module is used for judging whether the execution frequency of the executed code is higher than a preset frequency threshold value;
and if so, determining the code with the execution frequency higher than the preset frequency threshold value in the executed codes as the hot code.
B15, the electronic terminal according to B12, wherein the first compiling module specifically includes:
and the third compiling module is used for fully compiling the code corresponding to the plug-in to be loaded so as to obtain the machine code.
B16, the electronic terminal according to B12, wherein the first compiling module specifically includes:
the second judgment module judges whether a system corresponding to the electronic terminal is in an idle state in real time;
and if so, compiling the code corresponding to the plug-in to be loaded into the machine code.
B17, the electronic terminal according to B12, wherein the first compiling module specifically includes:
the third judgment module is used for judging whether a system corresponding to the electronic terminal is in a charging state in real time;
and if so, compiling the code corresponding to the plug-in to be loaded into the machine code.
B18, the electronic terminal according to B12, characterized in that the electronic terminal further comprises:
the receiving module is used for receiving a command for reloading the plug-in to be loaded after compiling the code corresponding to the plug-in to be loaded into the machine code;
and the loading module is used for operating the machine code based on the reloading instruction so as to reload and operate the plug-in to be loaded.
C19, a computer-readable storage medium, having a computer program stored thereon, wherein the program, when executed by a processor, carries out the steps of the method according to any one of a1-a 9.
D20, a computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the steps of the method according to any one of a1-a9 when executing the program.