WO2015021809A1 - Dynamic language code execution method and apparatus - Google Patents

Dynamic language code execution method and apparatus Download PDF

Info

Publication number
WO2015021809A1
WO2015021809A1 PCT/CN2014/078956 CN2014078956W WO2015021809A1 WO 2015021809 A1 WO2015021809 A1 WO 2015021809A1 CN 2014078956 W CN2014078956 W CN 2014078956W WO 2015021809 A1 WO2015021809 A1 WO 2015021809A1
Authority
WO
WIPO (PCT)
Prior art keywords
code
dynamic language
language code
cache
bytecode
Prior art date
Application number
PCT/CN2014/078956
Other languages
French (fr)
Chinese (zh)
Inventor
孙昌青
谭柱成
Original Assignee
优视科技有限公司
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 优视科技有限公司 filed Critical 优视科技有限公司
Publication of WO2015021809A1 publication Critical patent/WO2015021809A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44568Immediately runnable code

Definitions

  • DYNAMIC LANGUAGE CODE EXECUTION METHOD AND APPARATUS The present application claims priority to Chinese Patent Application No. 201310357191.2, entitled “Dynamic Language Code Execution Method and Apparatus", filed on August 15, 2013, the entire contents of which are incorporated herein by reference. This is incorporated herein by reference.
  • TECHNICAL FIELD The present invention relates to the field of mobile communication technologies, and in particular, to a dynamic language code execution method and apparatus.
  • a primary object of the present invention is to provide a dynamic language code execution method and apparatus to solve the problem of relatively large overhead when dynamic language code is executed in the prior art.
  • a dynamic language code execution method comprises: when the dynamic language code is executed, caching the code generated when the dynamic language code is executed, obtaining the cache code of the dynamic language code; and acquiring the cache code of the dynamic language code and the dynamic language code when the dynamic language code is executed again The dynamic code is executed based on the cache code.
  • the code generated when the dynamic language code is executed is cached, and the step of obtaining the cache code of the dynamic language code includes: when the dynamic language code is executed, buffering the bytecode generated when the dynamic language code is executed, The bytecode is used as the cache code for the dynamic language code.
  • the step of obtaining the cache code of the dynamic language code and executing the dynamic language code based on the cache code of the dynamic language code comprises: acquiring the bytecode when the dynamic language code is executed again, and acquiring the word The section code is converted to native code; the dynamic language code is executed by executing native code.
  • the step of buffering the bytecode generated when the dynamic language code is executed includes: establishing a bytecode cache hash table; and buffering the bytecode generated when the dynamic language code is executed into the bytecode cache hash table, wherein When the bytecode is cached, the identifier of the dynamic language code identifies the cached bytecode.
  • the step of obtaining the bytecode includes: obtaining the bytecode corresponding to the dynamic language code by the identifier of the dynamic language code.
  • the step of obtaining the cache code of the dynamic language code includes: when the dynamic language code is executed, the native code generated when the dynamic language code is executed is cached, and Use the native code as the cache code.
  • the step of obtaining the cache code of the dynamic language code and executing the dynamic language code based on the cache code of the dynamic language code comprises: obtaining the native code when the dynamic language code is executed again, by executing the native code Execute dynamic language code.
  • the step of caching the native code generated when the dynamic language code is executed comprises: establishing a native code cache hash table; and buffering the native code generated when the dynamic language code is executed into a native code cache hash table, wherein the cached native code is cached When the identifier of the dynamic language code is identified, the cached native code is identified.
  • the step of obtaining the native code includes: obtaining the native code corresponding to the dynamic language code by the identifier of the dynamic language code.
  • the dynamic language code execution method further includes: determining whether there is a cache code of the dynamic language code; wherein, if it is determined that the cache code of the dynamic language code exists, performing the dynamic on the cache code Language code; if it is determined that there is no cache code of the dynamic language code, the cache code of the dynamic language code generated when the dynamic language code is executed is obtained, and the generated cache code is added to the cache.
  • another dynamic language code execution method comprising: obtaining an execution request of a dynamic language code; determining whether the dynamic language generation exists a cache code of the code, the code generated when the dynamic language code is executed; if the cache code of the dynamic language code exists, the dynamic language code is executed on the basis of the cache code.
  • executing the dynamic language code on the basis of the cache code comprises: determining a type of the cache code, the cache code including a bytecode and a native code of the dynamic language code; if the cache The code is a native code of the dynamic language code, and the native code is executed to implement the dynamic language code; if the cache code is a bytecode of the dynamic language code, the bytecode is converted Being native code, and executing the native code to implement execution of the dynamic language code. Further, the method further includes: if there is no cache code of the dynamic language code, storing a cache code generated when the dynamic language code is executed.
  • storing the cache code corresponding to the dynamic language code includes: storing a bytecode generated when the dynamic language code is executed, and using the bytecode as a cache code of the dynamic language code; or storing The native code generated when the dynamic language code is executed, and the native code is used as a cache code of the dynamic language code; or, the native code corresponding to the dynamic language code issued by the WebApp publisher or the Web Server is stored. Further, storing the bytecode generated when the dynamic language code is executed, including: storing the bytecode in a pre-established bytecode hash table, and pairing the word according to the identifier of the dynamic language code The section code is identified.
  • storing the native code generated when the dynamic language code is executed comprises: storing the native code in a pre-established native code hash table, and identifying the native code according to the identifier of the dynamic language code .
  • a dynamic language code execution apparatus comprises: a cache unit, configured to cache code generated when the dynamic language code is executed when the dynamic language code is executed, obtain a cache code of the dynamic language code, and an execution unit, configured to acquire the dynamic language when the dynamic language code is executed again The code's cache code and execute the dynamic language based on the cache code of the dynamic language code Code.
  • the cache unit is configured to cache the bytecode generated when the dynamic language code is executed when the dynamic language code is executed, and use the bytecode as the cache code of the dynamic language code;
  • the execution unit is configured to convert the bytecode into a native code. Code; Execute dynamic language code by executing native code.
  • the cache unit is configured to cache the bytecode generated when the dynamic language code is executed in the following manner: Establish a bytecode cache hash table, and cache the bytecode generated when the dynamic language code is executed to the bytecode cache hash. In the table, where the bytecode is cached, the identifier of the dynamic language code identifies the cached bytecode.
  • the execution unit is configured to obtain the bytecode in the following manner: the bytecode corresponding to the dynamic language code is obtained by the identifier of the dynamic language code. Further, the cache unit is configured to cache the native code generated when the dynamic language code is executed when the dynamic language code is executed, and use the native code as the cache code, and the execution unit is configured to execute the dynamic language code by executing the native code. Further, the cache unit is configured to cache the native code generated when the dynamic language code is executed in the following manner: Establish a native code cache hash table, and cache the native code generated when the dynamic language code is executed into the native code cache hash table, where When the native code is cached, the identifier of the dynamic language code identifies the cached native code.
  • the execution unit is used to obtain the native code in the following manner:
  • the native code corresponding to the dynamic language code is obtained by the identification of the dynamic language code.
  • the dynamic language code execution apparatus further includes: a determining unit, configured to determine, before the execution of the dynamic language code, whether there is a cache code of the dynamic language code, wherein the execution unit is configured to determine, when the cache code of the dynamic language code exists, The dynamic language code is executed on the basis of the cache code, and the cache unit is configured to obtain the cache code of the dynamic language code generated when the dynamic language code is executed, and add the generated cache code to the cache code when the dynamic language code is not present. In the cache.
  • a dynamic language code execution apparatus comprising: an obtaining unit, configured to acquire an execution request of a dynamic language code; and a determining unit, configured to determine whether the existence a cache code of the dynamic language code, the cache code is a code generated when the dynamic language code is executed; an execution unit, configured to: when the cache code of the dynamic language code exists, on the cache code Executing the dynamic language code.
  • the execution unit includes: a first determining subunit, configured to determine a type of the cache code, the cache code includes a bytecode and a native code of the dynamic language code; and a first execution subunit, When the cache code is a native code of the dynamic language code, executing the native code to implement execution of the dynamic language code; a conversion subunit, configured to: when the cache code is a word of the dynamic language code When the code is coded, the bytecode is converted into a native code.
  • the device further includes: a cache unit, configured to store, when the cache code of the dynamic language code does not exist, a cache code generated when the dynamic language code is executed.
  • a computer readable medium having program code executable by a processor, the program code causing a processor to perform the steps of: obtaining an execution request of a dynamic language code; Whether there is a cache code of the dynamic language code, the cache code being code generated when the dynamic language code is executed; if there is a cache code of the dynamic language code, performing the dynamic on the cache code Language code.
  • the code generated when the dynamic language code is executed is cached when the dynamic language code is executed, the cache code of the dynamic language code is obtained, and when the dynamic language code is executed again, the cache of the dynamic language code is directly obtained.
  • the code executes the dynamic language code on the basis of the cache code of the dynamic language code, so that the step of code generation is not necessary to be repeated on the basis of the dynamic language code, and the problem that the overhead of the dynamic language code execution in the prior art is relatively large is solved. , in turn, achieves the effect of reducing the overhead of dynamic language code execution.
  • FIG. 1 is a schematic diagram of a dynamic language code execution apparatus according to a first embodiment of the present invention
  • FIG. 2 is a schematic diagram of a dynamic language code execution apparatus according to a second embodiment of the present invention.
  • FIG. 3 is a flowchart of a method of executing a dynamic language code according to a first embodiment of the present invention
  • Embodiments of the present invention provide a dynamic language code execution apparatus for executing a dynamic language code.
  • 1 is a schematic diagram of a dynamic language code execution apparatus according to a first embodiment of the present invention. As shown in FIG. 1, the dynamic language code execution device includes a cache unit 10 and an execution unit 20.
  • the cache unit 10 is configured to cache code generated when the dynamic language code is executed when the dynamic language code is executed, to obtain a cache code of the dynamic language code.
  • the dynamic language of the present invention refers to a programming language in which the program structure can be changed at runtime (for example, a new function can be introduced at runtime, and an existing function can be deleted, etc.).
  • JS scripting language, Ruby (object-oriented programming) language, and Python (object-oriented, literal translation computer programming language) are all dynamic languages.
  • a JS script language code is described as an example of a dynamic language code.
  • the cache unit 10 may cache the code generated when the JS scripting language code is executed, thereby obtaining the cache code of the JS scripting language code.
  • the cache code can be either bytecode or native code.
  • the JS scripting language code is analyzed and processed, a corresponding parse tree is generated, and corresponding bytecodes are further generated, and the native code is generated by the JIT method.
  • the cache unit 10 can be cached.
  • the generated bytecode can also cache the generated native code.
  • the execution unit 20 is configured to acquire the cache code of the dynamic language code when the dynamic language code is executed again, and execute the dynamic language code on the basis of the cache code of the dynamic language code.
  • the execution unit 20 may obtain, from the cache unit 10, the cache code cached into the cache unit 10 by the dynamic language code when it was previously executed, and execute the dynamic language code based on the cache code. For example, when the JS scripting language code is executed again, if the bytecode of the JS scripting language code is cached in the cache unit 10, the execution unit 20 may obtain the JS scripting language code from the cache unit 10 and cache it to the cache unit when it was previously executed. Bytecode in 10, and The bytecode is converted into native code, and the JS scripting language code is executed by executing the native code. At this time, the bytecode generation processing is omitted, and the system overhead is saved.
  • the execution unit 20 obtains the JS script language code from the cache unit 10 and caches it to the cache unit 10 when it is executed.
  • the native code in the implementation of the JS scripting language code by executing the native code not only omits the bytecode generation process, but also omits the native code generation process, further saving system overhead.
  • the cache unit 10 may cache the bytecode generated when the dynamic language code is executed, and use the bytecode as the dynamic language code. Cache code.
  • the execution unit 20 may convert the bytecode buffered in the cache unit 10 into a native code, and execute the dynamic language code by executing the native code.
  • the cache unit 10 may cache the bytecode generated when the JS scripting language code is executed, and use the bytecode as the cache code of the dynamic language code.
  • the execution unit 20 may convert the bytecode of the JS scripting language code buffered in the cache unit 10 into a native code, and execute the JS scripting language code by executing the native code.
  • the cache unit 10 may be a bytecode buffer hash table.
  • the bytecode cache hash table can cache the bytecode generated when the dynamic language code is executed.
  • the cached bytecode can be identified by the identifier of the dynamic language code.
  • the identifier of the dynamic language code may be the file name of the dynamic language code, so the bytecode may be identified according to the file name of the dynamic language code.
  • the execution unit 20 can obtain the bytecode corresponding to the dynamic language code by using the identifier of the dynamic language code.
  • the file name of the JS scripting language code may be in the form of document.url + index, so when the bytecode generated when the JS scripting language code is executed is cached in the bytecode buffer hash table, the The bytecode keyword generated by the file name of the JS scripting language code document.url + index identifies the corresponding bytecode of the cache.
  • the execution unit 20 can obtain the bytecode corresponding to the JS scripting language code by using the bytecode keyword generated by the file name document.url+index of the JS scripting language code.
  • the cache unit 10 may also cache the native code.
  • the cache unit 10 can cache the native code generated when the dynamic language code is executed, and use the native code as the cache code of the dynamic language code.
  • the execution unit 20 may directly acquire the native code cached in the cache unit 10, and execute the dynamic language code by executing the native code.
  • the cache unit 10 can cache the native code generated when the JS scripting language code is executed, and use the native code as a dynamic language code. Save the code.
  • the execution unit 20 may directly acquire the native code of the JS scripting language code cached in the cache unit 10, and execute the JS scripting language code by executing the native code.
  • the cache unit 10 may be a native code cache hash table.
  • the native code cache hash table can cache native code generated when dynamic language code is executed.
  • the cached bytecode can be identified by the identifier of the dynamic language code.
  • the identifier of the dynamic language code may be the file name of the dynamic language code, so the native code may be identified according to the file name of the dynamic language code.
  • the execution unit 20 can acquire the native code corresponding to the dynamic language code by using the identifier of the dynamic language code.
  • the file name of the JS scripting language code can be in the form of document.url + index, so when the native code generated when the JS scripting language code is executed is cached in the native code cache hash table, the JS script can be passed.
  • the native code key generated by the file name of the language code document.url + index identifies the corresponding native code of the cache.
  • the execution unit 20 can obtain the native code corresponding to the JS scripting language code by using the native code keyword generated by the file name document.url + index of the JS scripting language code.
  • 2 is a schematic diagram of a dynamic language code execution apparatus according to a second embodiment of the present invention. This embodiment can be used as a preferred embodiment of the embodiment shown in FIG.
  • the dynamic language code execution device includes a cache unit 10, an execution unit 20, and a determination unit 30.
  • the functions of the cache unit 10 and the execution unit 20 are the same as those of the cache unit 10 and the execution unit 20 in the embodiment shown in FIG. 1, and details are not described herein again.
  • the determining unit 30 is configured to determine whether the cache code of the dynamic language code exists before the execution of the dynamic language code. Specifically, the determining unit 30 may determine, according to the identifier of the dynamic language code, whether the cache code corresponding to the dynamic language code exists in the cache unit 10.
  • the determining unit 30 may determine, according to the bytecode keyword generated by the identifier of the dynamic language code, whether the bytecode corresponding to the dynamic language code exists in the cache unit 10; the determining unit 30 may also generate the identifier according to the identifier of the dynamic language code.
  • the native code keyword determines whether the native code corresponding to the dynamic language code exists in the cache unit 10; the determining unit 30 can also determine the cache unit 10 according to the bytecode keyword and the native code keyword generated by the identifier of the dynamic language code. Whether the bytecode and the native code corresponding to the dynamic language code exist at the same time.
  • execution unit 20 may execute the dynamic language code on a cached code basis.
  • the execution unit 20 may convert the bytecode into a native code, and execute the dynamic language code by executing the native code; when determining the existence of the native code of the dynamic language code, Execution unit 20 may execute native code to execute the dynamic language code.
  • a cache code of the dynamic language code is generated, and the cache unit 10 can cache the generated cache code.
  • the text format JS file or code may be analyzed to generate a corresponding parse tree, and the corresponding bytecode is further generated, and the JIT method is used to generate the native code.
  • the cache unit 10 can cache the generated bytecode and native code to update the cache unit 10.
  • the dynamic language code cached in the cache unit 10 may be cached according to the bytecode keyword generated by the identifier of the dynamic language code.
  • the corresponding bytecode is converted into native code, and the dynamic language code is executed by executing native code to reduce the execution overhead of the dynamic language code.
  • the native code corresponding to the dynamic language code cached in the cache unit 10 may be obtained according to the native code keyword generated by the identifier of the dynamic language code, and the dynamic language code is executed by executing the native code.
  • Embodiments of the present invention provide a dynamic language code execution method for executing a dynamic language code. It should be noted that the steps shown in the flowchart of the accompanying drawings may be executed in a computer system such as a set of computer executable instructions, and, although the logical order is shown in the flowchart, in some cases, The steps shown or described may be performed in an order different than that herein.
  • the embodiment of the present invention further provides a dynamic language code execution method, which can be executed by the dynamic language code execution device provided by the embodiment of the present invention.
  • the dynamic language code execution device of the embodiment of the present invention can also be used.
  • the dynamic language code execution method provided by the embodiment of the present invention is executed.
  • the dynamic language code execution method of the embodiment includes the following steps: Step S101: When the dynamic language code is executed, the code generated when the dynamic language code is executed is cached, and the cache code of the dynamic language code is obtained.
  • the dynamic language code may be a JS scripting language code. Need to execute JS scripts When the language code is used, the code generated when the JS scripting language code is executed can be cached, thereby obtaining the cache code of the JS scripting language code.
  • the JS script language code when executed, the JS file or code in the text format is analyzed and processed, a corresponding parse tree is generated, and corresponding bytecodes are further generated, and the native code is generated by the JIT method. Therefore, the bytecode generated when the JS scripting language code is executed may be cached, so that the cache code of the JS scripting language code is bytecode; or the native code generated when the JS scripting language code is executed may be cached, thereby obtaining the The cache code of the JS scripting language code is a native code; the bytecode and the native code generated when the JS scripting language code is executed may also be cached, thereby obtaining the cache code of the JS scripting language code as a bytecode and a native code.
  • the bytecode cache hash table may be first established, so that the bytecode generated when the cached dynamic language code is executed may be the bytecode.
  • the bytecode generated during the execution of the cached dynamic language code is cached in the cache hash table.
  • the cached bytecode can be identified according to the identifier of the dynamic language code. For example, the bytecode can be identified based on a bytecode keyword generated by the filename of the dynamic language code.
  • the native code cache hash table may be first established, so that the native code generated when the cached dynamic language code is executed may be the native code cache hash table.
  • the native code generated when the dynamic language code is executed is cached, that is, the native code generated when the dynamic language code is executed is cached into the native code cache hash table.
  • the native code generated when the dynamic language code is executed is cached into the native code cache hash table.
  • the cached native code can be identified according to the identifier of the dynamic language code. For example, the native code can be identified based on the native code keywords generated by the filename of the dynamic language code.
  • Step S102 when the dynamic language code is executed again, acquire the cache code of the dynamic language code and execute the dynamic language code on the basis of the cache code of the dynamic language code.
  • the cache code of the dynamic language code when the dynamic language code is executed again, the cache code of the dynamic language code may be acquired and executed on the basis of the cache code of the dynamic language code.
  • the byte code buffered by the dynamic language code when executed previously may be obtained, and the dynamic language code is executed on the basis of the byte code code, and the native code cached by the dynamic language code when executed previously may also be obtained.
  • the bytecode cached by the JS scripting language code at the time of execution may be obtained, and the bytecode is converted into native code, and the JS scripting language code is executed by executing the native code; Can get the native code cached by the JS scripting language code before execution, and will be JS scripting language
  • the code generates a bytecode, and executes the JS scripting language code by executing the cached native code corresponding to the bytecode; and can also obtain the bytecode and the native code cached by the JS scripting language code before execution, by executing the cached native code.
  • the code executes the JS scripting language code.
  • the cache code of the dynamic language code may be obtained by using a bytecode keyword generated by the identifier of the dynamic language code to obtain a cached bytecode corresponding to the dynamic language code; and the cache code for obtaining the dynamic language code may also be used.
  • the cached code corresponding to the dynamic language code is obtained by the native code keyword generated by the identifier of the dynamic language code, and the cache code of the dynamic language code may further include the dynamic language obtained by using the bytecode keyword generated by the identifier of the dynamic language code.
  • the cached bytecode and the native code keyword corresponding to the code obtain the cached native code corresponding to the dynamic language code.
  • the dynamic language code execution method may further include determining whether there is a cache code of the dynamic language code. If it is determined that the cache code of the dynamic language code exists, the dynamic language code is executed on the basis of the cache code; if it is determined that the cache code of the dynamic language code does not exist, the cache code of the dynamic language code generated when the dynamic language code is executed is acquired , and add the generated cache code to the cache.
  • the bytecode keyword generated by the identifier of the dynamic language code may be used to determine whether there is a cached bytecode corresponding to the dynamic language code, if it is determined that a dynamic language exists
  • the bytecode of the cache corresponding to the code can be converted into native code, and the dynamic language code is executed by executing the native code.
  • the native code keyword generated by the identifier of the dynamic language code (such as a file name, etc.) may also be used to determine whether there is a cached native code corresponding to the dynamic language code, and if it is determined that there is a cache corresponding to the dynamic language code.
  • the native code can execute dynamic language code by executing native code. If it is determined that there is no cached bytecode corresponding to the dynamic language code and the corresponding cached native code, the corresponding bytecode and the corresponding native code may be generated when the dynamic language code is executed, and the generated correspondence may be The bytecode and corresponding native code are added to the cache, for example, and can be added to the bytecode cache hash table and the native code cache hash table, respectively. Thus, when the dynamic language code is executed again, the execution overhead of the dynamic language code can be reduced by executing the cached bytecode or the cached native code.
  • 4 is a flow chart of a method of executing a JS scripting language code in accordance with an embodiment of the present invention.
  • the JS scripting language code execution method can be used as a preferred embodiment of the embodiment shown in Fig. 4, wherein the features can be combined with the features in the embodiment shown in Fig. 3.
  • the JS scripting language code execution method of this embodiment includes the following steps: Step S401: Acquire a JS scripting language code execution request. After receiving the JS scripting language code execution request, it is determined that the JS scripting language code needs to be executed. Step S402, initializing a bytecode buffer hash table.
  • the bytecode buffer hash table may be a bytecode buffer hash table in the foregoing embodiment for buffering the bytecode generated during execution.
  • the bytecode buffer hash table may be given a certain value, so that the bytecode buffer hash table may further store the bytecode based on the storage space corresponding to the given value, for initializing , you can also clear the bytecode stored in the bytecode cache hash table before.
  • Step S403 initializing a native code cache hash table.
  • the native code cache hash table may cache the hash table for the native code in the previous embodiment for caching the native code generated during execution.
  • it is possible to assign a certain value to the native code cache hash table so that the native code cache hash table can further store the native code based on the storage space corresponding to the given value.
  • it can also be Clear the previously stored bytecode in the native code cache hash table.
  • Step S404 determining whether the bytecode buffer can be used.
  • the file name of the JS scripting language code can be document.url + index, with document.url + index as the identifier of the JS scripting language code.
  • Hash Keyl is a bytecode keyword that can be generated according to the file name document.url + index of the JS scripting language code, and Hash Keyl can identify the JS scripting language code.
  • Hash Value 1 can identify the corresponding bytecode generated after the JS scripting language code is compiled. For determining whether the bytecode buffer can be used, the Hash Keyl may be used to find the Hash Value 1 bytecode corresponding to the Hash Key1 according to the Hash Keyl, if there is a Hash Value 1 bytecode corresponding to the Hash Key1.
  • step S405A1 loading the JS scripting language code.
  • step S405A2 the JS script language code is compiled into a bytecode. Before compiling the JS scripting language code to bytecode, the compiled JS scripting language code can be analyzed and processed, a corresponding parse tree is generated, and the corresponding bytecode is further generated.
  • Step S405A3 buffering the bytecode.
  • the condition that the JS script language code can use the bytecode cache may include the JS scripting language code that can use the bytecode corresponding to the HTTP cache and the JS scripting language code in the bytecode cache. There is no corresponding record in the table.
  • the bytecode can be cached by establishing a bytecode buffer hash table. The bytecode buffered in the bytecode buffer hash table can be marked by the identifier of the JS scripting language code, for example, by Hash Value 1.
  • the cache bytecode can cache the internal JS scripting language code and the external JS scripting language code that are currently applied. Cache bytecode can also cache some common JS scripting language framework code, so that cross-application caching can be achieved. Step S405A4, updating the corresponding record in the bytecode buffer hash table.
  • the bytecode of the JS scripting language code may be cached into a bytecode buffer hash table to update the bytecode record cached in the bytecode buffer hash table.
  • Step S405B Obtain a bytecode cache corresponding to the JS script language code from the bytecode cache hash table.
  • step S406 it is determined whether the native code cache can be used. When the JIT is called, the bytecode is first searched in the native code cache hash table for the cached native code corresponding to the bytecode before being converted into the native code.
  • the file name of the JS scripting language code can be document.url + index, with document.url + index as the identifier of the JS scripting language code.
  • the Hash Key2 may be a native code keyword generated according to the address of the bytecode, and may identify the bytecode, where the Hash Key2 may be the Hash Valuel in step S404.
  • Hash Value2 can identify the corresponding native code after the bytecode conversion.
  • the hash code may be used in the native code cache hash table to find whether there is a cached native code corresponding to Hash Value2, if there is a hash of the hash corresponding to the hash code in the native code cache hash table.
  • the code indicates that the native code cache can be used. If the native code of the cache corresponding to Hash Value2 does not exist in the native code cache hash table, the native code cache cannot be used. After judging, if it is determined that the native code buffer is not available, step S407A1 is performed; if it is determined that the native code buffer can be used, step S407B is performed. Step S407A1, converting the bytecode to a native code. Step S407 A2, the native code is cached. Native code can be cached by creating a native code cache hash table. Native code cached in the native code cache hash table can be tagged with the identity of the JS scripting language code. For example, you can mark it with Hash Value2.
  • the native code of all hotspot codes of the current application may be cached. Step S407A3, updating the corresponding record in the native code cache hash table.
  • the native code of the JS scripting language code may be cached into a native code cache hash table to update the native code record cached in the native code cache hash table. In this way, when the JS scripting language code is executed again, the native code corresponding to the JS scripting language code can be obtained from the native code cache hash table by using the identifier of the JS scripting language code, and the native code is executed to execute the JS.
  • Script language Word code which can improve the execution efficiency, which can reduce the execution cost of the JS scripting language code.
  • Step S407B Obtain a native code cache corresponding to the bytecode from the native code cache hash table. If the native code corresponding to the JS scripting language code can be found in the native code cache hash table according to the identifier of the JS scripting language code, the native code can be obtained from the native code cache hash table. Step S408, executing a native code.
  • the JS scripting language code can be executed by executing native code.
  • the effect of reducing the execution overhead of the JS scripting language code is achieved.
  • the JS scripting language code execution method can be implemented on a Firefox 23 browser.
  • the JS script language code execution method of the embodiment of the present invention can reduce the overhead of loading and executing the game by the client, and improve the loading efficiency.
  • the HTML5 large game BananaBread provided by mozilla is loaded for the first time on the Firefox 23 browser, the overhead of executing the JS function of the game using the JS script language code execution method of the embodiment of the present invention is obviously reduced.
  • the native code corresponding to the dynamic language sent by the WebAPP publisher to the browser may be directly cached and executed; in order to reduce the execution overhead of the dynamic language code, The corresponding native code that converts the JS scripting language code into the browser through the Web Server providing tool is directly cached and executed by the Web Server. From the above description, it can be seen that the embodiment of the present invention achieves the effect of reducing the overhead of dynamic language code execution. Obviously, those skilled in the art should understand that the above modules or steps of the present invention can be implemented by a general-purpose computing device, which can be concentrated on a single computing device or distributed over a network composed of multiple computing devices.
  • the invention is not limited to any specific combination of hardware and software.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Devices For Executing Special Programs (AREA)
  • Memory System Of A Hierarchy Structure (AREA)

Abstract

Disclosed are a dynamic language code execution method and apparatus. The dynamic language code execution method comprises: during execution of dynamic language code, buffering code generated during the execution of dynamic language code, to obtain buffered code of the dynamic language code; during re-execution of the dynamic language code, acquiring the buffered code of the dynamic language code and executing the dynamic language code based on the buffered code of the dynamic language code. The present invention reduces the overheads of executing dynamic language code.

Description

动态语言代码执行方法和装置 本申请要求于 2013年 8月 15日提交中国专利局、 申请号为 201310357191.2、发 明名称为 "动态语言代码执行方法和装置"的中国专利申请的优先权, 其全部内容通 过引用结合在本申请中。 技术领域 本发明涉及移动通信技术领域, 具体而言, 涉及一种动态语言代码执行方法和装 置。 背景技术 浏览器在执行动态语言代码, 例如脚本语言 JS (JavaScript) 代码时, 需要将文 本格式的 JS文件或代码进行分析处理, 生成相应的语法分析树, 并进一步生成相应 的字节码, 以及通过 JIT (也即, 即时编译技术, 是指在运行阶段把字节码翻译成原 生代码, 然后直接执行生成的原生代码的一种优化技术)方式生成原生代码。发明人 发现, 由于生成字节码或生成原生代码会存在比较大的开销, 因而, 每次重复执行这 个过程会引起不必要的开销, 例如, 在浏览器加载 HTML5应用过程来说, 每次重复 执行这个过程会引起不必要的开销。  DYNAMIC LANGUAGE CODE EXECUTION METHOD AND APPARATUS The present application claims priority to Chinese Patent Application No. 201310357191.2, entitled "Dynamic Language Code Execution Method and Apparatus", filed on August 15, 2013, the entire contents of which are incorporated herein by reference. This is incorporated herein by reference. TECHNICAL FIELD The present invention relates to the field of mobile communication technologies, and in particular, to a dynamic language code execution method and apparatus. BACKGROUND When a browser executes a dynamic language code, such as a script language JS (JavaScript) code, it is necessary to analyze a JS file or code in a text format, generate a corresponding parse tree, and further generate a corresponding bytecode, and Native code is generated by JIT (that is, instant compilation technology, which is an optimization technique that translates bytecode into native code at run time and then directly executes the generated native code). The inventor has found that there is a relatively large overhead in generating bytecode or generating native code, so that each iteration of the process can cause unnecessary overhead, for example, each time the browser loads the HTML5 application process. Executing this process can cause unnecessary overhead.
针对现有技术中动态语言代码执行时开销比较大的问题, 目前尚未提出有效的 解决方案。 发明内容 本发明的主要目的在于提供一种动态语言代码执行方法和装置,以解决现有技术 中动态语言代码执行时开销比较大的问题。 为了实现上述目的,根据本发明的一个方面,提供了一种动态语言代码执行方法。 该方法包括: 在动态语言代码执行时, 缓存动态语言代码执行时生成的代码, 得到动 态语言代码的缓存代码; 以及在动态语言代码再次执行时, 获取动态语言代码的缓存 代码并在动态语言代码的缓存代码的基础上执行动态语言代码。 进一步地, 在动态语言代码执行时, 缓存动态语言代码执行时生成的代码, 得到 动态语言代码的缓存代码的步骤包括: 在动态语言代码执行时, 缓存动态语言代码执 行时生成的字节码, 并将字节码作为动态语言代码的缓存代码。在动态语言代码再次 执行时,获取动态语言代码的缓存代码并在动态语言代码的缓存代码的基础上执行动 态语言代码的步骤包括: 在动态语言代码再次执行时, 获取字节码, 并将字节码转换 为原生代码; 通过执行原生代码执行动态语言代码。 进一步地, 缓存动态语言代码执行时生成的字节码的步骤包括: 建立字节码缓存 哈希表; 将动态语言代码执行时生成的字节码缓存到字节码缓存哈希表中, 其中, 缓 存字节码时,将动态语言代码的标识对缓存的字节码进行标识。获取字节码的步骤包 括: 通过动态语言代码的标识获取动态语言代码对应的字节码。 进一步地, 在动态语言代码执行时, 缓存动态语言代码执行时生成的代码, 得到 动态语言代码的缓存代码的步骤包括: 在动态语言代码执行时, 缓存动态语言代码执 行时生成的原生代码, 并将原生代码作为缓存代码。在动态语言代码再次执行时, 获 取动态语言代码的缓存代码并在动态语言代码的缓存代码的基础上执行动态语言代 码的步骤包括: 在动态语言代码再次执行时, 获取原生代码, 通过执行原生代码执行 动态语言代码。 进一步地, 缓存动态语言代码执行时生成的原生代码的步骤包括: 建立原生代码 缓存哈希表; 将动态语言代码执行时生成的原生代码缓存到原生代码缓存哈希表中, 其中, 缓存原生代码时, 将动态语言代码的标识对缓存的原生代码进行标识。获取原 生代码的步骤包括: 通过动态语言代码的标识获取动态语言代码对应的原生代码。 进一步地, 在动态语言代码执行之前, 该动态语言代码执行方法还包括: 判断是 否存在动态语言代码的缓存代码; 其中, 如果确定存在动态语言代码的缓存代码, 则 在缓存代码的基础上执行动态语言代码; 如果确定不存在动态语言代码的缓存代码, 则获取动态语言代码执行时生成的动态语言代码的缓存代码,并将生成的缓存代码添 加到缓存中。 为了实现上述目的,根据本发明的另一方面,提供了另一种动态语言代码执行方 法, 该方法可以包括: 获取动态语言代码的执行请求; 判断是否存在所述动态语言代 码的缓存代码,所述缓存代码为执行所述动态语言代码时产生的代码; 如果存在所述 动态语言代码的缓存代码, 在所述缓存代码的基础上执行所述动态语言代码。 进一步地, 在所述缓存代码的基础上执行所述动态语言代码, 包括: 判断所述缓 存代码的类型,所述缓存代码包括所述动态语言代码的字节码和原生代码; 如果所述 缓存代码是所述动态语言代码的原生代码,则执行所述原生代码以实现执行所述动态 语言代码; 如果所述缓存代码是所述动态语言代码的字节码, 则将所述字节码转换为 原生代码, 并执行所述原生代码以实现执行所述动态语言代码。 进一步地, 所述方法还包括: 如果不存在所述动态语言代码的缓存代码, 存储所 述动态语言代码执行时产生的缓存代码。 进一步地, 存储所述动态语言代码对应的缓存代码, 包括: 存储所述动态语言代 码执行时生成的字节码, 并将所述字节码作为所述动态语言代码的缓存代码; 或者, 存储所述动态语言代码执行时生成的原生代码,并将所述原生代码作为所述动态 语言代码的缓存代码; 或者, 存储 WebApp发布方或 Web Server下发的动态语言代码对应的原生代码。 进一步地, 存储执行所述动态语言代码时生成的字节码, 包括: 在预先建立的字 节码哈希表中存储所述字节码,并根据所述动态语言代码的标识对所述字节码进行标 识。 进一步地, 存储所述动态语言代码执行时生成的原生代码, 包括: 在预先建立的 原生代码哈希表中存储所述原生代码,并根据所述动态语言代码的标识对所述原生代 码进行标识。 为了实现上述目的,根据本发明的另一方面,提供了一种动态语言代码执行装置。 该装置包括: 缓存单元, 用于在动态语言代码执行时, 缓存动态语言代码执行时生成 的代码,得到动态语言代码的缓存代码;执行单元,用于在动态语言代码再次执行时, 获取动态语言代码的缓存代码并在动态语言代码的缓存代码的基础上执行动态语言 代码。 进一步地, 缓存单元用于在动态语言代码执行时, 缓存动态语言代码执行时生成 的字节码, 并将字节码作为动态语言代码的缓存代码; 执行单元用于将字节码转换为 原生代码; 通过执行原生代码执行动态语言代码。 进一步地, 缓存单元用于采用以下方式缓存动态语言代码执行时生成的字节码: 建立字节码缓存哈希表,将动态语言代码执行时生成的字节码缓存到字节码缓存哈希 表中, 其中, 缓存字节码时, 将动态语言代码的标识对缓存的字节码进行标识。 执行 单元用于采用以下方式获取字节码:通过动态语言代码的标识获取动态语言代码对应 的字节码。 进一步地, 缓存单元用于在动态语言代码执行时, 缓存动态语言代码执行时生成 的原生代码, 并将原生代码作为缓存代码,执行单元用于通过执行原生代码执行动态 语言代码。 进一步地, 缓存单元用于采用以下方式缓存动态语言代码执行时生成的原生代 码: 建立原生代码缓存哈希表,将动态语言代码执行时生成的原生代码缓存到原生代 码缓存哈希表中, 其中, 缓存原生代码时, 将动态语言代码的标识对缓存的原生代码 进行标识。执行单元用于采用以下方式获取原生代码: 通过动态语言代码的标识获取 动态语言代码对应的原生代码。 进一步地, 动态语言代码执行装置还包括: 判断单元, 用于在动态语言代码执行 之前, 判断是否存在动态语言代码的缓存代码, 其中, 执行单元用于在确定存在动态 语言代码的缓存代码时,在缓存代码的基础上执行动态语言代码, 缓存单元用于在确 定不存在动态语言代码的缓存代码时,获取动态语言代码执行时生成的动态语言代码 的缓存代码, 并将生成的缓存代码添加到缓存中。 为了实现上述目的,根据本发明的另一方面,提供了一种动态语言代码执行装置, 其特征在于, 包括: 获取单元, 用于获取动态语言代码的执行请求; 判断单元, 用于 判断是否存在所述动态语言代码的缓存代码,所述缓存代码为执行所述动态语言代码 时产生的代码; 执行单元, 用于当存在所述动态语言代码的缓存代码时, 在所述缓存 代码的基础上执行所述动态语言代码。 进一步地,所述执行单元包括:第一判断子单元,用于判断所述缓存代码的类型, 所述缓存代码包括所述动态语言代码的字节码和原生代码; 第一执行子单元,用于当 所述缓存代码是所述动态语言代码的原生代码时,执行所述原生代码以实现执行所述 动态语言代码; 转换子单元, 用于当所述缓存代码是所述动态语言代码的字节码时, 将所述字节码转换为原生代码。 进一步地, 所述装置还包括: 缓存单元, 用于当不存在所述动态语言代码的缓存 代码时, 存储所述动态语言代码执行时产生的缓存代码。 In view of the problem that the overhead of dynamic language code execution in the prior art is relatively large, an effective solution has not been proposed yet. SUMMARY OF THE INVENTION A primary object of the present invention is to provide a dynamic language code execution method and apparatus to solve the problem of relatively large overhead when dynamic language code is executed in the prior art. In order to achieve the above object, according to an aspect of the present invention, a dynamic language code execution method is provided. The method comprises: when the dynamic language code is executed, caching the code generated when the dynamic language code is executed, obtaining the cache code of the dynamic language code; and acquiring the cache code of the dynamic language code and the dynamic language code when the dynamic language code is executed again The dynamic code is executed based on the cache code. Further, when the dynamic language code is executed, the code generated when the dynamic language code is executed is cached, and the step of obtaining the cache code of the dynamic language code includes: when the dynamic language code is executed, buffering the bytecode generated when the dynamic language code is executed, The bytecode is used as the cache code for the dynamic language code. When the dynamic language code is executed again, the step of obtaining the cache code of the dynamic language code and executing the dynamic language code based on the cache code of the dynamic language code comprises: acquiring the bytecode when the dynamic language code is executed again, and acquiring the word The section code is converted to native code; the dynamic language code is executed by executing native code. Further, the step of buffering the bytecode generated when the dynamic language code is executed includes: establishing a bytecode cache hash table; and buffering the bytecode generated when the dynamic language code is executed into the bytecode cache hash table, wherein When the bytecode is cached, the identifier of the dynamic language code identifies the cached bytecode. The step of obtaining the bytecode includes: obtaining the bytecode corresponding to the dynamic language code by the identifier of the dynamic language code. Further, when the dynamic language code is executed, the code generated when the dynamic language code is executed is cached, and the step of obtaining the cache code of the dynamic language code includes: when the dynamic language code is executed, the native code generated when the dynamic language code is executed is cached, and Use the native code as the cache code. When the dynamic language code is executed again, the step of obtaining the cache code of the dynamic language code and executing the dynamic language code based on the cache code of the dynamic language code comprises: obtaining the native code when the dynamic language code is executed again, by executing the native code Execute dynamic language code. Further, the step of caching the native code generated when the dynamic language code is executed comprises: establishing a native code cache hash table; and buffering the native code generated when the dynamic language code is executed into a native code cache hash table, wherein the cached native code is cached When the identifier of the dynamic language code is identified, the cached native code is identified. The step of obtaining the native code includes: obtaining the native code corresponding to the dynamic language code by the identifier of the dynamic language code. Further, before the execution of the dynamic language code, the dynamic language code execution method further includes: determining whether there is a cache code of the dynamic language code; wherein, if it is determined that the cache code of the dynamic language code exists, performing the dynamic on the cache code Language code; if it is determined that there is no cache code of the dynamic language code, the cache code of the dynamic language code generated when the dynamic language code is executed is obtained, and the generated cache code is added to the cache. In order to achieve the above object, according to another aspect of the present invention, there is provided another dynamic language code execution method, the method comprising: obtaining an execution request of a dynamic language code; determining whether the dynamic language generation exists a cache code of the code, the code generated when the dynamic language code is executed; if the cache code of the dynamic language code exists, the dynamic language code is executed on the basis of the cache code. Further, executing the dynamic language code on the basis of the cache code comprises: determining a type of the cache code, the cache code including a bytecode and a native code of the dynamic language code; if the cache The code is a native code of the dynamic language code, and the native code is executed to implement the dynamic language code; if the cache code is a bytecode of the dynamic language code, the bytecode is converted Being native code, and executing the native code to implement execution of the dynamic language code. Further, the method further includes: if there is no cache code of the dynamic language code, storing a cache code generated when the dynamic language code is executed. Further, storing the cache code corresponding to the dynamic language code includes: storing a bytecode generated when the dynamic language code is executed, and using the bytecode as a cache code of the dynamic language code; or storing The native code generated when the dynamic language code is executed, and the native code is used as a cache code of the dynamic language code; or, the native code corresponding to the dynamic language code issued by the WebApp publisher or the Web Server is stored. Further, storing the bytecode generated when the dynamic language code is executed, including: storing the bytecode in a pre-established bytecode hash table, and pairing the word according to the identifier of the dynamic language code The section code is identified. Further, storing the native code generated when the dynamic language code is executed comprises: storing the native code in a pre-established native code hash table, and identifying the native code according to the identifier of the dynamic language code . In order to achieve the above object, according to another aspect of the present invention, a dynamic language code execution apparatus is provided. The device comprises: a cache unit, configured to cache code generated when the dynamic language code is executed when the dynamic language code is executed, obtain a cache code of the dynamic language code, and an execution unit, configured to acquire the dynamic language when the dynamic language code is executed again The code's cache code and execute the dynamic language based on the cache code of the dynamic language code Code. Further, the cache unit is configured to cache the bytecode generated when the dynamic language code is executed when the dynamic language code is executed, and use the bytecode as the cache code of the dynamic language code; the execution unit is configured to convert the bytecode into a native code. Code; Execute dynamic language code by executing native code. Further, the cache unit is configured to cache the bytecode generated when the dynamic language code is executed in the following manner: Establish a bytecode cache hash table, and cache the bytecode generated when the dynamic language code is executed to the bytecode cache hash. In the table, where the bytecode is cached, the identifier of the dynamic language code identifies the cached bytecode. The execution unit is configured to obtain the bytecode in the following manner: the bytecode corresponding to the dynamic language code is obtained by the identifier of the dynamic language code. Further, the cache unit is configured to cache the native code generated when the dynamic language code is executed when the dynamic language code is executed, and use the native code as the cache code, and the execution unit is configured to execute the dynamic language code by executing the native code. Further, the cache unit is configured to cache the native code generated when the dynamic language code is executed in the following manner: Establish a native code cache hash table, and cache the native code generated when the dynamic language code is executed into the native code cache hash table, where When the native code is cached, the identifier of the dynamic language code identifies the cached native code. The execution unit is used to obtain the native code in the following manner: The native code corresponding to the dynamic language code is obtained by the identification of the dynamic language code. Further, the dynamic language code execution apparatus further includes: a determining unit, configured to determine, before the execution of the dynamic language code, whether there is a cache code of the dynamic language code, wherein the execution unit is configured to determine, when the cache code of the dynamic language code exists, The dynamic language code is executed on the basis of the cache code, and the cache unit is configured to obtain the cache code of the dynamic language code generated when the dynamic language code is executed, and add the generated cache code to the cache code when the dynamic language code is not present. In the cache. In order to achieve the above object, in accordance with another aspect of the present invention, a dynamic language code execution apparatus is provided, comprising: an obtaining unit, configured to acquire an execution request of a dynamic language code; and a determining unit, configured to determine whether the existence a cache code of the dynamic language code, the cache code is a code generated when the dynamic language code is executed; an execution unit, configured to: when the cache code of the dynamic language code exists, on the cache code Executing the dynamic language code. Further, the execution unit includes: a first determining subunit, configured to determine a type of the cache code, the cache code includes a bytecode and a native code of the dynamic language code; and a first execution subunit, When the cache code is a native code of the dynamic language code, executing the native code to implement execution of the dynamic language code; a conversion subunit, configured to: when the cache code is a word of the dynamic language code When the code is coded, the bytecode is converted into a native code. Further, the device further includes: a cache unit, configured to store, when the cache code of the dynamic language code does not exist, a cache code generated when the dynamic language code is executed.
为了实现上述目的,根据本发明的另一方面,提供了具有处理器可执行的程序代 码的计算机可读介质,所述程序代码使处理器执行下述步骤: 获取动态语言代码的执 行请求; 判断是否存在所述动态语言代码的缓存代码,所述缓存代码为执行所述动态 语言代码时产生的代码; 如果存在所述动态语言代码的缓存代码,在所述缓存代码的 基础上执行所述动态语言代码。  In order to achieve the above object, in accordance with another aspect of the present invention, a computer readable medium having program code executable by a processor, the program code causing a processor to perform the steps of: obtaining an execution request of a dynamic language code; Whether there is a cache code of the dynamic language code, the cache code being code generated when the dynamic language code is executed; if there is a cache code of the dynamic language code, performing the dynamic on the cache code Language code.
通过本发明, 由于在动态语言代码执行时, 对动态语言代码执行时生成的代码进 行了缓存, 得到了动态语言代码的缓存代码, 并且在动态语言代码再次执行时, 直接 获取动态语言代码的缓存代码并在动态语言代码的缓存代码的基础上执行动态语言 代码, 从而可以不必在动态语言代码的基础上重复执行代码生成的步骤,解决了现有 技术中动态语言代码执行时开销比较大的问题,进而达到了降低动态语言代码执行开 销的效果。 附图说明  According to the present invention, since the code generated when the dynamic language code is executed is cached when the dynamic language code is executed, the cache code of the dynamic language code is obtained, and when the dynamic language code is executed again, the cache of the dynamic language code is directly obtained. The code executes the dynamic language code on the basis of the cache code of the dynamic language code, so that the step of code generation is not necessary to be repeated on the basis of the dynamic language code, and the problem that the overhead of the dynamic language code execution in the prior art is relatively large is solved. , in turn, achieves the effect of reducing the overhead of dynamic language code execution. DRAWINGS
构成本申请的一部分的说明书附图用来提供对本发明的进一步理解,本发明的示 意性实施例及其说明用于解释本发明, 并不构成对本发明的不当限定。 在附图中: 图 1是根据本发明第一实施例的动态语言代码执行装置的示意图;  The accompanying drawings, which are incorporated in the claims of the claims In the drawings: FIG. 1 is a schematic diagram of a dynamic language code execution apparatus according to a first embodiment of the present invention;
图 2是根据本发明第二实施例的动态语言代码执行装置的示意图;  2 is a schematic diagram of a dynamic language code execution apparatus according to a second embodiment of the present invention;
图 3是根据本发明第一实施例的动态语言代码执行方法的流程图;  3 is a flowchart of a method of executing a dynamic language code according to a first embodiment of the present invention;
图 4是根据本发明实施例的脚本语言 JS代码执行方法的流程图。 具体实施方式 需要说明的是,在不冲突的情况下,本申请中的实施例及实施例中的特征可以相 互组合。 下面将参考附图并结合实施例来详细说明本发明。 为了使本技术领域的人员更好地理解本发明方案,下面将结合本发明实施例中的 附图, 对本发明实施例中的技术方案进行清楚、 完整地描述, 显然, 所描述的实施例 仅仅是本发明一部分的实施例, 而不是全部的实施例。基于本发明中的实施例, 本领 域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都应当属于 本发明保护的范围。 需要说明的是, 本发明的说明书和权利要求书及上述附图中的术语 "包括" 以 及他的任何变形, 意图在于覆盖不排他的包含, 例如, 包含了一系列步骤或单元的过 程、 方法、 系统、 产品或设备不必限于清楚地列出的那些步骤或单元, 而是可包括没 有清楚地列出的或对于这些过程、 方法、 产品或设备固有的其它步骤或单元。 本发明实施例提供了一种动态语言代码执行装置,该动态语言代码执行装置用于 执行动态语言代码。 图 1是根据本发明第一实施例的动态语言代码执行装置的示意图。 如图 1所示, 该动态语言代码执行装置包括缓存单元 10和执行单元 20。 缓存单元 10用于在动态语言代码执行时, 缓存所述动态语言代码执行时生成的 代码, 得到所述动态语言代码的缓存代码。 需要说明的是, 本发明的动态语言是指在 运行时程序结构可以改变(如: 在运行时新的函数可以被引进、 已有的函数可以被删 除等程序结构的改变) 的编程语言。 例如 JS脚本语言、 Ruby (面向对象程序设计) 语言和 Python (面向对象、直译式计算机程序设计语言)等都是动态语言。 以下在本 发明实施例中, 以 JS脚本语言代码作为动态语言代码的例子进行描述。 在需要执行 JS脚本语言代码时, 缓存单元 10可以缓存该 JS脚本语言代码执行时生成的代码, 从而得到该 JS脚本语言代码的缓存代码。 缓存代码可以是字节码, 也可以是原生代 码。 在执行 JS脚本语言代码时, 通过对 JS脚本语言代码进行分析处理, 生成相应的 语法分析树, 并进一步生成相应的字节码, 以及通过 JIT方式生成原生代码, 此时, 缓存单元 10可以缓存生成的字节码, 也可以缓存生成的原生代码。 执行单元 20用于在动态语言代码再次执行时, 获取该动态语言代码的缓存代码 并在该动态语言代码的缓存代码的基础上执行该动态语言代码。 执行单元 20可以从 缓存单元 10中获取该动态语言代码在之前执行时缓存到缓存单元 10中的缓存代码, 并在该缓存代码的基础上执行该动态语言代码。 例如, 在 JS脚本语言代码再次执行 时, 如果缓存单元 10中缓存的是 JS脚本语言代码的字节码, 执行单元 20可以从缓 存单元 10中获取 JS脚本语言代码在之前执行时缓存到缓存单元 10中的字节码, 并 将字节码转换成原生代码, 通过执行原生代码来执行 JS脚本语言代码, 此时, 省略 了字节码的生成处理过程, 节省了系统开销。 或者, 如果缓存单元 10中缓存的是 JS 脚本语言代码的原生代码, 在 JS脚本语言代码再次执行时, 由执行单元 20从缓存单 元 10中获取 JS脚本语言代码在之前执行时缓存到缓存单元 10中的原生代码, 通过 执行原生代码来执行 JS脚本语言代码, 这样, 不仅省略了字节码的生成处理过程, 而且省略了原生代码的生成处理过程, 进一步节省了系统开销。 可选地, 在本发明实施例的动态语言代码执行装置中, 在动态语言代码执行时, 缓存单元 10可以缓存动态语言代码执行时生成的字节码, 并将字节码作为动态语言 代码的缓存代码。 在该动态语言代码再次执行时, 执行单元 20可以将缓存在缓存单 元 10中的该字节码转换为原生代码, 通过执行该原生代码执行该动态语言代码。 例 如, 在 JS脚本语言代码执行时, 缓存单元 10可以缓存该 JS脚本语言代码执行时生 成的字节码, 并将字节码作为动态语言代码的缓存代码。 在该 JS脚本语言代码再次 执行时, 执行单元 20可以将缓存在缓存单元 10中的该 JS脚本语言代码的字节码转 换为原生代码, 通过执行该原生代码执行该 JS脚本语言代码。 在本发明实施例的动态语言代码执行装置中, 缓存单元 10可以是字节码缓存哈 希表。字节码缓存哈希表可以缓存动态语言代码执行时生成的字节码。在将动态语言 代码执行时生成的字节码缓存到字节码缓存哈希表中时,可以通过该动态语言代码的 标识对缓存的字节码进行标识。 动态语言代码的标识可以是动态语言代码的文件名, 因此字节码可以根据该动态语言代码的文件名进行标识。这样,在该动态语言代码再 次执行时, 执行单元 20可以通过该动态语言代码的标识获取该动态语言代码对应的 字节码。 4 is a flow chart of a scripting language JS code execution method in accordance with an embodiment of the present invention. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS It should be noted that, in the case of no conflict, the features in the embodiments and embodiments of the present application may be Mutual combination. The invention will be described in detail below with reference to the drawings in conjunction with the embodiments. The technical solutions in the embodiments of the present invention will be clearly and completely described in the following with reference to the accompanying drawings in the embodiments of the present invention. It is an embodiment of the invention, but not all of the embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative efforts shall fall within the scope of the present invention. It should be noted that the term "comprising" and any variations thereof in the specification and claims of the present invention and the above drawings are intended to cover a non-exclusive inclusion, for example, a process or method comprising a series of steps or units. The system, the product, or the device is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not explicitly listed or inherent to such processes, methods, products, or devices. Embodiments of the present invention provide a dynamic language code execution apparatus for executing a dynamic language code. 1 is a schematic diagram of a dynamic language code execution apparatus according to a first embodiment of the present invention. As shown in FIG. 1, the dynamic language code execution device includes a cache unit 10 and an execution unit 20. The cache unit 10 is configured to cache code generated when the dynamic language code is executed when the dynamic language code is executed, to obtain a cache code of the dynamic language code. It should be noted that the dynamic language of the present invention refers to a programming language in which the program structure can be changed at runtime (for example, a new function can be introduced at runtime, and an existing function can be deleted, etc.). For example, JS scripting language, Ruby (object-oriented programming) language, and Python (object-oriented, literal translation computer programming language) are all dynamic languages. Hereinafter, in the embodiment of the present invention, a JS script language code is described as an example of a dynamic language code. When it is necessary to execute the JS scripting language code, the cache unit 10 may cache the code generated when the JS scripting language code is executed, thereby obtaining the cache code of the JS scripting language code. The cache code can be either bytecode or native code. When executing the JS scripting language code, the JS scripting language code is analyzed and processed, a corresponding parse tree is generated, and corresponding bytecodes are further generated, and the native code is generated by the JIT method. At this time, the cache unit 10 can be cached. The generated bytecode can also cache the generated native code. The execution unit 20 is configured to acquire the cache code of the dynamic language code when the dynamic language code is executed again, and execute the dynamic language code on the basis of the cache code of the dynamic language code. The execution unit 20 may obtain, from the cache unit 10, the cache code cached into the cache unit 10 by the dynamic language code when it was previously executed, and execute the dynamic language code based on the cache code. For example, when the JS scripting language code is executed again, if the bytecode of the JS scripting language code is cached in the cache unit 10, the execution unit 20 may obtain the JS scripting language code from the cache unit 10 and cache it to the cache unit when it was previously executed. Bytecode in 10, and The bytecode is converted into native code, and the JS scripting language code is executed by executing the native code. At this time, the bytecode generation processing is omitted, and the system overhead is saved. Alternatively, if the cache code of the JS script language code is cached in the cache unit 10, when the JS script language code is executed again, the execution unit 20 obtains the JS script language code from the cache unit 10 and caches it to the cache unit 10 when it is executed. The native code in the implementation of the JS scripting language code by executing the native code, not only omits the bytecode generation process, but also omits the native code generation process, further saving system overhead. Optionally, in the dynamic language code execution apparatus of the embodiment of the present invention, when the dynamic language code is executed, the cache unit 10 may cache the bytecode generated when the dynamic language code is executed, and use the bytecode as the dynamic language code. Cache code. When the dynamic language code is executed again, the execution unit 20 may convert the bytecode buffered in the cache unit 10 into a native code, and execute the dynamic language code by executing the native code. For example, when the JS scripting language code is executed, the cache unit 10 may cache the bytecode generated when the JS scripting language code is executed, and use the bytecode as the cache code of the dynamic language code. When the JS scripting language code is executed again, the execution unit 20 may convert the bytecode of the JS scripting language code buffered in the cache unit 10 into a native code, and execute the JS scripting language code by executing the native code. In the dynamic language code execution apparatus of the embodiment of the present invention, the cache unit 10 may be a bytecode buffer hash table. The bytecode cache hash table can cache the bytecode generated when the dynamic language code is executed. When the bytecode generated when the dynamic language code is executed is cached into the bytecode cache hash table, the cached bytecode can be identified by the identifier of the dynamic language code. The identifier of the dynamic language code may be the file name of the dynamic language code, so the bytecode may be identified according to the file name of the dynamic language code. Thus, when the dynamic language code is executed again, the execution unit 20 can obtain the bytecode corresponding to the dynamic language code by using the identifier of the dynamic language code.
例如, JS脚本语言代码的文件名可以是 document.url + index的形式, 因此, 在 将该 JS脚本语言代码执行时生成的字节码缓存到字节码缓存哈希表中时, 可以通过 该 JS脚本语言代码的文件名 document.url + index生成的字节码关键字对缓存的对应 的字节码进行标识。这样, 在该 JS脚本语言代码再次执行时, 执行单元 20可以通过 该 JS脚本语言代码的文件名 document.url + index生成的字节码关键字获取该 JS脚本 语言代码对应的字节码。 可选地, 在本发明实施例的动态语言代码执行装置中, 缓存单元 10也可以缓存 原生代码。 在动态语言代码执行时, 缓存单元 10可以缓存动态语言代码执行时生成 的原生代码, 并将原生代码作为动态语言代码的缓存代码。在该动态语言代码再次执 行时,执行单元 20可以直接获取缓存在缓存单元 10中的该原生代码,通过执行该原 生代码执行该动态语言代码。例如, 在 JS脚本语言代码执行时, 缓存单元 10可以缓 存该 JS脚本语言代码执行时生成的原生代码, 并将原生代码作为动态语言代码的缓 存代码。在该 JS脚本语言代码再次执行时, 执行单元 20可以直接获取缓存在缓存单 元 10中的该 JS脚本语言代码的原生代码, 通过执行该原生代码执行该 JS脚本语言 代码。 在本发明实施例的动态语言代码执行装置中, 缓存单元 10可以是原生代码缓存 哈希表。原生代码缓存哈希表可以缓存动态语言代码执行时生成的原生代码。在将动 态语言代码执行时生成的原生代码缓存到原生代码缓存哈希表中时,可以通过该动态 语言代码的标识对缓存的字节码进行标识。动态语言代码的标识可以是动态语言代码 的文件名, 因此原生代码可以根据该动态语言代码的文件名进行标识。这样, 在该动 态语言代码再次执行时, 执行单元 20可以通过该动态语言代码的标识获取该动态语 言代码对应的原生代码。 例如, JS脚本语言代码的文件名可以是 document.url + index的形式, 因此, 在 将该 JS脚本语言代码执行时生成的原生代码缓存到原生代码缓存哈希表中时, 可以 通过该 JS脚本语言代码的文件名 document.url + index生成的原生代码关键字对缓存 的对应的原生代码进行标识。 这样, 在该 JS脚本语言代码再次执行时, 执行单元 20 可以通过该 JS脚本语言代码的文件名 document.url + index生成的原生代码关键字获 取该 JS脚本语言代码对应的原生代码。 图 2是根据本发明第二实施例的动态语言代码执行装置的示意图。该实施例可以 作为图 1所示实施例的一种优选实施方式。 如图 2所示, 该动态语言代码执行装置包括缓存单元 10、 执行单元 20和判断单 元 30。 缓存单元 10、执行单元 20的作用与图 1所示实施例中的缓存单元 10、执行单元 20的作用相同, 在此不再赘述。 判断单元 30用于在动态语言代码执行之前, 判断是否存在该动态语言代码的缓 存代码。具体地,判断单元 30可以根据该动态语言代码的标识判断缓存单元 10中是 否存在该动态语言代码对应的缓存代码。 例如, 判断单元 30可以根据该动态语言代码的标识生成的字节码关键字判断缓 存单元 10中是否存在该动态语言代码对应的字节码;判断单元 30也可以根据该动态 语言代码的标识生成的原生代码关键字判断缓存单元 10中是否存在该动态语言代码 对应的原生代码; 判断单元 30还可以根据该动态语言代码的标识生成的字节码关键 字和原生代码关键字判断缓存单元 10中是否同时存在该动态语言代码对应的字节码 和原生代码。 在确定存在动态语言代码的缓存代码时, 执行单元 20可以在缓存代码的基础上 执行动态语言代码。 例如, 在确定存在该动态语言代码的字节码时, 执行单元 20可以将字节码转换 成原生代码,通过执行原生代码执行该动态语言代码; 在确定存在该动态语言代码的 原生代码时, 执行单元 20可以在执行原生代码以执行该动态语言代码。 在确定不存在动态语言代码的缓存代码时, 生成动态语言代码的缓存代码, 缓存 单元 10可以缓存生成的缓存代码。 具体地, 在确定不存在动态语言代码的缓存代码 时, 可以将文本格式的 JS文件或代码进行分析处理以生成相应的语法分析树, 并进 一步生成相应的字节码, 以及通过 JIT方式生成原生代码, 在生成字节码和原生代码 后, 缓存单元 10可以缓存生成的字节码和原生代码以更新缓存单元 10。 这样,在本发明实施例的动态语言代码执行装置中,在该动态语言代码再次执行 时, 可以根据该动态语言代码的标识生成的字节码关键字将缓存单元 10中缓存的该 动态语言代码对应的字节码转换成原生代码,通过执行原生代码执行该动态语言代码 以降低动态语言代码的执行开销。 在该动态语言代码再次执行时,也可以根据该动态 语言代码的标识生成的原生代码关键字获取缓存单元 10中缓存的该动态语言代码对 应的原生代码,通过执行原生代码执行该动态语言代码以降低动态语言代码的执行开 销。 本发明实施例提供了一种动态语言代码执行方法, 用于执行动态语言代码。 需要说明的是,在附图的流程图示出的步骤可以在诸如一组计算机可执行指令的 计算机系统中执行, 并且, 虽然在流程图中示出了逻辑顺序, 但是在某些情况下, 可 以以不同于此处的顺序执行所示出或描述的步骤。 本发明实施例还提供了一种动态语言代码执行方法,该动态语言代码执行方法可 以通过本发明实施例提供的动态语言代码执行装置来执行,本发明实施例的动态语言 代码执行装置也可以用于执行本发明实施例提供的动态语言代码执行方法。 图 3是根据本发明第一实施例的动态语言代码执行方法的流程图。 如图 3所示, 该实施例的动态语言代码执行方法包括以下步骤: 步骤 S101 , 在动态语言代码执行时, 缓存动态语言代码执行时生成的代码, 得 到动态语言代码的缓存代码。 在本发明实施例中, 动态语言代码可以是 JS脚本语言代码。在需要执行 JS脚本 语言代码时, 可以缓存该 JS脚本语言代码执行时生成的代码, 从而得到该 JS脚本语 言代码的缓存代码。 具体地, 在 JS脚本语言代码执行时, 通过将文本格式的 JS文件 或代码进行分析处理, 生成相应的语法分析树, 并进一步生成相应的字节码, 以及通 过 JIT方式生成原生代码。 因此, 可以缓存该 JS脚本语言代码执行时生成的字节码, 从而得到该 JS脚本语言代码的缓存代码为字节码;也可以缓存该 JS脚本语言代码执 行时生成的原生代码, 从而得到该 JS脚本语言代码的缓存代码为原生代码; 还可以 缓存该 JS脚本语言代码执行时生成的字节码和原生代码,从而得到该 JS脚本语言代 码的缓存代码为字节码和原生代码。 在本发明实施例中, 为了缓存动态语言代码执行时生成的字节码,可以首先建立 字节码缓存哈希表,这样, 缓存动态语言代码执行时生成的字节码可以是在字节码缓 存哈希表中缓存动态语言代码执行时生成的字节码。将动态语言代码执行时生成的字 节码缓存到字节码缓存哈希表中时,可以根据动态语言代码的标识对缓存的字节码进 行标识。例如,可以根据该动态语言代码的文件名生成的字节码关键字对该字节码进 行标识。 在本发明实施例中, 为了缓存动态语言代码执行时生成的原生代码,可以首先建 立原生代码缓存哈希表,这样, 缓存动态语言代码执行时生成的原生代码可以是在原 生代码缓存哈希表中缓存动态语言代码执行时生成的原生代码, 即,将动态语言代码 执行时生成的原生代码缓存到原生代码缓存哈希表中。将动态语言代码执行时生成的 原生代码缓存到原生代码缓存哈希表中时,可以根据动态语言代码的标识对缓存的原 生代码进行标识。例如,可以根据该动态语言代码的文件名生成的原生代码关键字对 该原生代码进行标识。 步骤 S102, 在动态语言代码再次执行时, 获取动态语言代码的缓存代码并在动 态语言代码的缓存代码的基础上执行动态语言代码。 在本发明实施例中,在动态语言代码再次执行时,可以获取该动态语言代码的缓 存代码并在该动态语言代码的缓存代码的基础上执行该动态语言代码。具体地,可以 获取该动态语言代码在之前执行时缓存的字节码,并在该字节码码的基础上执行该动 态语言代码, 也可以获取该动态语言代码在之前执行时缓存的原生代码, 并在该原生 代码的基础上执行该动态语言代码,也可以获取该动态语言代码在之前执行时缓存的 字节码和原生代码, 并在该字节码和原生代码的基础上执行该动态语言代码。 例如, 在 JS脚本语言代码再次执行时, 可以获取该 JS脚本语言代码在之前执行 时缓存的字节码, 并将该字节码转换成原生代码, 通过执行原生代码执行 JS脚本语 言代码; 也可以获取 JS脚本语言代码在之前执行时缓存的原生代码, 并将 JS脚本语 言代码生成字节码,通过执行该字节码对应的缓存的原生代码执行 JS脚本语言代码; 还可以获取 JS脚本语言代码在之前执行时缓存的字节码和原生代码, 通过执行缓存 的原生代码执行 JS脚本语言代码。 在本发明实施例中,获取动态语言代码的缓存代码可以包括通过动态语言代码的 标识生成的字节码关键字获取动态语言代码对应的缓存的字节码;获取动态语言代码 的缓存代码也可以包括通过动态语言代码的标识生成的原生代码关键字获取动态语 言代码对应的缓存的原生代码,获取动态语言代码的缓存代码还可以包括通过动态语 言代码的标识生成的字节码关键字获取动态语言代码对应的缓存的字节码和原生代 码关键字获取动态语言代码对应的缓存的原生代码。 这样,通过执行该字节码和该原生代码来执行该动态语言代码, 降低了动态语言 代码的执行开销。 在本发明实施例中,在动态语言代码执行之前, 该动态语言代码执行方法还可以 包括判断是否存在动态语言代码的缓存代码。 如果确定存在动态语言代码的缓存代 码, 则在缓存代码的基础上执行动态语言代码; 如果确定不存在动态语言代码的缓存 代码, 则获取所述动态语言代码执行时生成的动态语言代码的缓存代码, 并将生成的 缓存代码添加到缓存中。 具体地, 在动态语言代码执行之前, 可以根据该动态语言代码的标识(如文件名 等)生成的字节码关键字判断是否存在动态语言代码对应的缓存的字节码, 如果确定 存在动态语言代码对应的缓存的字节码, 则可以将该字节码转化成原生代码,通过执 行原生代码来执行动态语言代码。在动态语言代码执行之前, 也可以根据该动态语言 代码的标识(如文件名等)生成的原生代码关键字判断是否存在动态语言代码对应的 缓存的原生代码, 如果确定存在动态语言代码对应的缓存的原生代码, 则可以通过执 行原生代码来执行动态语言代码。如果确定不存在动态语言代码对应的缓存的字节码 和对应的缓存的原生代码,则可以在执行该动态语言代码时生成对应的字节码和对应 的原生代码,并可以将该生成的对应的字节码和对应的原生代码添加到缓存中,例如, 可以分别添加到字节码缓存哈希表中和原生代码缓存哈希表中。 这样, 该动态语言代码再次执行时,可以通过执行缓存的字节码或者缓存的原生 代码以降低该动态语言代码的执行开销。 图 4是根据本发明实施例的 JS脚本语言代码执行方法的流程图。 该实施例的 JS 脚本语言代码执行方法可以作为图 4所示实施例的一种优选实施方式,其中的特征可 以与图 3所示实施例中的特征相结合。 如图 4所示, 该实施例的 JS脚本语言代码执行方法包括以下步骤: 步骤 S401 , 获取 JS脚本语言代码执行请求。 在接收到 JS脚本语言代码执行请求之后, 确定需要执行 JS脚本语言代码。 步骤 S402, 初始化字节码缓存哈希表。 该字节码缓存哈希表可以为前述实施例中的字节码缓存哈希表,用于缓存执行过 程中生成的字节码。 对于初始化字节码缓存哈希表,可以是为字节码缓存哈希表赋予一定的数值, 使 得字节码缓存哈希表可以基于赋予的数值对应的存储空间进一步存储字节码,对于初 始化, 还可以是清空字节码缓存哈希表中之前存储的字节码。 步骤 S403 , 初始化原生代码缓存哈希表。 该原生代码缓存哈希表可以为前述实施例中的原生代码缓存哈希表,用于缓存执 行过程中生成的原生代码。 对于初始化原生代码缓存哈希表, 可以是为原生代码缓存哈希表赋予一定的数 值,使得原生代码缓存哈希表可以基于赋予的数值对应的存储空间进一步存储原生代 码, 对于初始化, 还可以是清空原生代码缓存哈希表中之前存储的字节码。 步骤 S404, 判断是否可使用字节码缓存。 For example, the file name of the JS scripting language code may be in the form of document.url + index, so when the bytecode generated when the JS scripting language code is executed is cached in the bytecode buffer hash table, the The bytecode keyword generated by the file name of the JS scripting language code document.url + index identifies the corresponding bytecode of the cache. Thus, when the JS scripting language code is executed again, the execution unit 20 can obtain the bytecode corresponding to the JS scripting language code by using the bytecode keyword generated by the file name document.url+index of the JS scripting language code. Optionally, in the dynamic language code execution apparatus of the embodiment of the present invention, the cache unit 10 may also cache the native code. When the dynamic language code is executed, the cache unit 10 can cache the native code generated when the dynamic language code is executed, and use the native code as the cache code of the dynamic language code. When the dynamic language code is executed again, the execution unit 20 may directly acquire the native code cached in the cache unit 10, and execute the dynamic language code by executing the native code. For example, when the JS scripting language code is executed, the cache unit 10 can cache the native code generated when the JS scripting language code is executed, and use the native code as a dynamic language code. Save the code. When the JS scripting language code is executed again, the execution unit 20 may directly acquire the native code of the JS scripting language code cached in the cache unit 10, and execute the JS scripting language code by executing the native code. In the dynamic language code execution apparatus of the embodiment of the present invention, the cache unit 10 may be a native code cache hash table. The native code cache hash table can cache native code generated when dynamic language code is executed. When the native code generated when the dynamic language code is executed is cached into the native code cache hash table, the cached bytecode can be identified by the identifier of the dynamic language code. The identifier of the dynamic language code may be the file name of the dynamic language code, so the native code may be identified according to the file name of the dynamic language code. Thus, when the dynamic language code is executed again, the execution unit 20 can acquire the native code corresponding to the dynamic language code by using the identifier of the dynamic language code. For example, the file name of the JS scripting language code can be in the form of document.url + index, so when the native code generated when the JS scripting language code is executed is cached in the native code cache hash table, the JS script can be passed. The native code key generated by the file name of the language code document.url + index identifies the corresponding native code of the cache. Thus, when the JS scripting language code is executed again, the execution unit 20 can obtain the native code corresponding to the JS scripting language code by using the native code keyword generated by the file name document.url + index of the JS scripting language code. 2 is a schematic diagram of a dynamic language code execution apparatus according to a second embodiment of the present invention. This embodiment can be used as a preferred embodiment of the embodiment shown in FIG. As shown in FIG. 2, the dynamic language code execution device includes a cache unit 10, an execution unit 20, and a determination unit 30. The functions of the cache unit 10 and the execution unit 20 are the same as those of the cache unit 10 and the execution unit 20 in the embodiment shown in FIG. 1, and details are not described herein again. The determining unit 30 is configured to determine whether the cache code of the dynamic language code exists before the execution of the dynamic language code. Specifically, the determining unit 30 may determine, according to the identifier of the dynamic language code, whether the cache code corresponding to the dynamic language code exists in the cache unit 10. For example, the determining unit 30 may determine, according to the bytecode keyword generated by the identifier of the dynamic language code, whether the bytecode corresponding to the dynamic language code exists in the cache unit 10; the determining unit 30 may also generate the identifier according to the identifier of the dynamic language code. The native code keyword determines whether the native code corresponding to the dynamic language code exists in the cache unit 10; the determining unit 30 can also determine the cache unit 10 according to the bytecode keyword and the native code keyword generated by the identifier of the dynamic language code. Whether the bytecode and the native code corresponding to the dynamic language code exist at the same time. Upon determining that there is a cache code for the dynamic language code, execution unit 20 may execute the dynamic language code on a cached code basis. For example, when it is determined that the bytecode of the dynamic language code exists, the execution unit 20 may convert the bytecode into a native code, and execute the dynamic language code by executing the native code; when determining the existence of the native code of the dynamic language code, Execution unit 20 may execute native code to execute the dynamic language code. When it is determined that there is no cache code of the dynamic language code, a cache code of the dynamic language code is generated, and the cache unit 10 can cache the generated cache code. Specifically, when determining that there is no cache code of the dynamic language code, the text format JS file or code may be analyzed to generate a corresponding parse tree, and the corresponding bytecode is further generated, and the JIT method is used to generate the native code. The code, after generating the bytecode and the native code, the cache unit 10 can cache the generated bytecode and native code to update the cache unit 10. Thus, in the dynamic language code execution apparatus of the embodiment of the present invention, when the dynamic language code is executed again, the dynamic language code cached in the cache unit 10 may be cached according to the bytecode keyword generated by the identifier of the dynamic language code. The corresponding bytecode is converted into native code, and the dynamic language code is executed by executing native code to reduce the execution overhead of the dynamic language code. When the dynamic language code is executed again, the native code corresponding to the dynamic language code cached in the cache unit 10 may be obtained according to the native code keyword generated by the identifier of the dynamic language code, and the dynamic language code is executed by executing the native code. Reduce the execution overhead of dynamic language code. Embodiments of the present invention provide a dynamic language code execution method for executing a dynamic language code. It should be noted that the steps shown in the flowchart of the accompanying drawings may be executed in a computer system such as a set of computer executable instructions, and, although the logical order is shown in the flowchart, in some cases, The steps shown or described may be performed in an order different than that herein. The embodiment of the present invention further provides a dynamic language code execution method, which can be executed by the dynamic language code execution device provided by the embodiment of the present invention. The dynamic language code execution device of the embodiment of the present invention can also be used. The dynamic language code execution method provided by the embodiment of the present invention is executed. 3 is a flow chart of a method of executing a dynamic language code in accordance with a first embodiment of the present invention. As shown in FIG. 3, the dynamic language code execution method of the embodiment includes the following steps: Step S101: When the dynamic language code is executed, the code generated when the dynamic language code is executed is cached, and the cache code of the dynamic language code is obtained. In an embodiment of the invention, the dynamic language code may be a JS scripting language code. Need to execute JS scripts When the language code is used, the code generated when the JS scripting language code is executed can be cached, thereby obtaining the cache code of the JS scripting language code. Specifically, when the JS script language code is executed, the JS file or code in the text format is analyzed and processed, a corresponding parse tree is generated, and corresponding bytecodes are further generated, and the native code is generated by the JIT method. Therefore, the bytecode generated when the JS scripting language code is executed may be cached, so that the cache code of the JS scripting language code is bytecode; or the native code generated when the JS scripting language code is executed may be cached, thereby obtaining the The cache code of the JS scripting language code is a native code; the bytecode and the native code generated when the JS scripting language code is executed may also be cached, thereby obtaining the cache code of the JS scripting language code as a bytecode and a native code. In the embodiment of the present invention, in order to cache the bytecode generated when the dynamic language code is executed, the bytecode cache hash table may be first established, so that the bytecode generated when the cached dynamic language code is executed may be the bytecode. The bytecode generated during the execution of the cached dynamic language code is cached in the cache hash table. When the bytecode generated when the dynamic language code is executed is cached into the bytecode cache hash table, the cached bytecode can be identified according to the identifier of the dynamic language code. For example, the bytecode can be identified based on a bytecode keyword generated by the filename of the dynamic language code. In the embodiment of the present invention, in order to cache the native code generated when the dynamic language code is executed, the native code cache hash table may be first established, so that the native code generated when the cached dynamic language code is executed may be the native code cache hash table. The native code generated when the dynamic language code is executed is cached, that is, the native code generated when the dynamic language code is executed is cached into the native code cache hash table. When the native code generated when the dynamic language code is executed is cached into the native code cache hash table, the cached native code can be identified according to the identifier of the dynamic language code. For example, the native code can be identified based on the native code keywords generated by the filename of the dynamic language code. Step S102, when the dynamic language code is executed again, acquire the cache code of the dynamic language code and execute the dynamic language code on the basis of the cache code of the dynamic language code. In the embodiment of the present invention, when the dynamic language code is executed again, the cache code of the dynamic language code may be acquired and executed on the basis of the cache code of the dynamic language code. Specifically, the byte code buffered by the dynamic language code when executed previously may be obtained, and the dynamic language code is executed on the basis of the byte code code, and the native code cached by the dynamic language code when executed previously may also be obtained. Executing the dynamic language code based on the native code, and also obtaining the bytecode and the native code cached by the dynamic language code when executed, and executing the dynamic on the basis of the bytecode and the native code Language code. For example, when the JS scripting language code is executed again, the bytecode cached by the JS scripting language code at the time of execution may be obtained, and the bytecode is converted into native code, and the JS scripting language code is executed by executing the native code; Can get the native code cached by the JS scripting language code before execution, and will be JS scripting language The code generates a bytecode, and executes the JS scripting language code by executing the cached native code corresponding to the bytecode; and can also obtain the bytecode and the native code cached by the JS scripting language code before execution, by executing the cached native code. The code executes the JS scripting language code. In the embodiment of the present invention, the cache code of the dynamic language code may be obtained by using a bytecode keyword generated by the identifier of the dynamic language code to obtain a cached bytecode corresponding to the dynamic language code; and the cache code for obtaining the dynamic language code may also be used. The cached code corresponding to the dynamic language code is obtained by the native code keyword generated by the identifier of the dynamic language code, and the cache code of the dynamic language code may further include the dynamic language obtained by using the bytecode keyword generated by the identifier of the dynamic language code. The cached bytecode and the native code keyword corresponding to the code obtain the cached native code corresponding to the dynamic language code. Thus, by executing the bytecode and the native code to execute the dynamic language code, the execution overhead of the dynamic language code is reduced. In the embodiment of the present invention, before the execution of the dynamic language code, the dynamic language code execution method may further include determining whether there is a cache code of the dynamic language code. If it is determined that the cache code of the dynamic language code exists, the dynamic language code is executed on the basis of the cache code; if it is determined that the cache code of the dynamic language code does not exist, the cache code of the dynamic language code generated when the dynamic language code is executed is acquired , and add the generated cache code to the cache. Specifically, before the execution of the dynamic language code, the bytecode keyword generated by the identifier of the dynamic language code (such as a file name, etc.) may be used to determine whether there is a cached bytecode corresponding to the dynamic language code, if it is determined that a dynamic language exists The bytecode of the cache corresponding to the code can be converted into native code, and the dynamic language code is executed by executing the native code. Before the execution of the dynamic language code, the native code keyword generated by the identifier of the dynamic language code (such as a file name, etc.) may also be used to determine whether there is a cached native code corresponding to the dynamic language code, and if it is determined that there is a cache corresponding to the dynamic language code. The native code can execute dynamic language code by executing native code. If it is determined that there is no cached bytecode corresponding to the dynamic language code and the corresponding cached native code, the corresponding bytecode and the corresponding native code may be generated when the dynamic language code is executed, and the generated correspondence may be The bytecode and corresponding native code are added to the cache, for example, and can be added to the bytecode cache hash table and the native code cache hash table, respectively. Thus, when the dynamic language code is executed again, the execution overhead of the dynamic language code can be reduced by executing the cached bytecode or the cached native code. 4 is a flow chart of a method of executing a JS scripting language code in accordance with an embodiment of the present invention. JS of this embodiment The scripting language code execution method can be used as a preferred embodiment of the embodiment shown in Fig. 4, wherein the features can be combined with the features in the embodiment shown in Fig. 3. As shown in FIG. 4, the JS scripting language code execution method of this embodiment includes the following steps: Step S401: Acquire a JS scripting language code execution request. After receiving the JS scripting language code execution request, it is determined that the JS scripting language code needs to be executed. Step S402, initializing a bytecode buffer hash table. The bytecode buffer hash table may be a bytecode buffer hash table in the foregoing embodiment for buffering the bytecode generated during execution. For initializing the bytecode buffer hash table, the bytecode buffer hash table may be given a certain value, so that the bytecode buffer hash table may further store the bytecode based on the storage space corresponding to the given value, for initializing , you can also clear the bytecode stored in the bytecode cache hash table before. Step S403, initializing a native code cache hash table. The native code cache hash table may cache the hash table for the native code in the previous embodiment for caching the native code generated during execution. For initializing the native code cache hash table, it is possible to assign a certain value to the native code cache hash table, so that the native code cache hash table can further store the native code based on the storage space corresponding to the given value. For initialization, it can also be Clear the previously stored bytecode in the native code cache hash table. Step S404, determining whether the bytecode buffer can be used.
JS脚本语言代码的文件名可以是 document.url + index, 以 document.url + index 作为该 JS脚本语言代码的标识。 Hash Keyl是可以是根据 JS脚本语言代码的文件名 document.url + index生成的字节码关键字, Hash Keyl可以标识该 JS脚本语言代码。 Hash Value 1可以标识该 JS脚本语言代码编译后生成的对应的字节码。 对于判断是否可使用字节码缓存,可以根据该 Hash Keyl在字节码缓存哈希表中 查找是否存在 Hash Keyl对应的 Hash Value 1字节码,如果存在 Hash Keyl对应的 Hash Value 1 字节码, 则说明可以使用字节码缓存, 如果不存在 Hash Keyl 对应的 Hash Valuel字节码, 则说明不可以使用字节码缓存。经过判断, 如果确定不可使用字节码 缓存, 则执行步骤 S405A1 ; 如果确定可使用字节码缓存, 则执行步骤 S405B。 步骤 S405A1, 加载 JS脚本语言代码。 步骤 S405A2, 编译 JS脚本语言代码为字节码。 在编译 JS脚本语言代码为字节码之前,可以先对编译 JS脚本语言代码进行分析 处理, 生成相应的语法分析树, 再进一步生成相应的字节码。 步骤 S405A3, 缓存字节码。 需要说明的是, 在本发明实施例中, JS 脚本语言代码可以使用字节码缓存的条 件可以包括 JS脚本语言代码可以使用 HTTP缓存和 JS脚本语言代码对应的字节码在 字节码缓存哈希表中没有对应的记录。 在本发明实施例中,可以通过建立字节码缓存哈希表的方式缓存字节码。缓存在 字节码缓存哈希表中的字节码可以通过 JS脚本语言代码的标识进行标记, 例如, 可 以通过 Hash Value 1进行标记。 在本发明实施例中, 缓存字节码可以对当前应用固定的内部 JS脚本语言代码和 外部 JS脚本语言代码进行缓存。缓存字节码也可以对一些常用的 JS脚本语言框架代 码进行缓存, 这样, 可以达到跨应用缓存的目的。 步骤 S405A4, 更新字节码缓存哈希表中对应的记录。 在本发明实施例中, 可以将该 JS脚本语言代码的字节码缓存到字节码缓存哈希 表中以更新该字节码缓存哈希表中缓存的字节码记录。 在该 JS脚本语言代码再次执 行时, 可以不经过分析和编译过程, 直接通过该 JS脚本语言代码的标识从该字节码 缓存哈希表中获取该 JS脚本语言代码对应的字节码,并将该字节码转化成原生代码, 通过执行原生代码以执行该 JS脚本语言代码, 从而可以提高执行效率, 进而可以降 低 JS脚本语言代码的执行开销。 步骤 S405B, 从字节码缓存哈希表中获取 JS脚本语言代码对应的字节码缓存。 如果根据该 JS脚本语言代码的标识可以在字节码缓存哈希表中查找到该 JS脚本 语言代码对应的缓存的字节码, 则可以直接从字节码缓存哈希表中获取该 JS脚本语 言代码对应的字节码。 步骤 S406, 判断是否可使用原生代码缓存。 在 JIT调用时, 字节码在被转换成原生代码之前, 先在原生代码缓存哈希表中查 找是否存在该字节码对应的缓存的原生代码。 The file name of the JS scripting language code can be document.url + index, with document.url + index as the identifier of the JS scripting language code. Hash Keyl is a bytecode keyword that can be generated according to the file name document.url + index of the JS scripting language code, and Hash Keyl can identify the JS scripting language code. Hash Value 1 can identify the corresponding bytecode generated after the JS scripting language code is compiled. For determining whether the bytecode buffer can be used, the Hash Keyl may be used to find the Hash Value 1 bytecode corresponding to the Hash Key1 according to the Hash Keyl, if there is a Hash Value 1 bytecode corresponding to the Hash Key1. , then you can use the bytecode cache, if there is no Hash corresponding to Hash Keyl The Valuel bytecode indicates that the bytecode cache cannot be used. It is judged that if it is determined that the bytecode buffer is not available, step S405A1 is performed; if it is determined that the bytecode buffer can be used, step S405B is performed. Step S405A1, loading the JS scripting language code. In step S405A2, the JS script language code is compiled into a bytecode. Before compiling the JS scripting language code to bytecode, the compiled JS scripting language code can be analyzed and processed, a corresponding parse tree is generated, and the corresponding bytecode is further generated. Step S405A3, buffering the bytecode. It should be noted that, in the embodiment of the present invention, the condition that the JS script language code can use the bytecode cache may include the JS scripting language code that can use the bytecode corresponding to the HTTP cache and the JS scripting language code in the bytecode cache. There is no corresponding record in the table. In the embodiment of the present invention, the bytecode can be cached by establishing a bytecode buffer hash table. The bytecode buffered in the bytecode buffer hash table can be marked by the identifier of the JS scripting language code, for example, by Hash Value 1. In the embodiment of the present invention, the cache bytecode can cache the internal JS scripting language code and the external JS scripting language code that are currently applied. Cache bytecode can also cache some common JS scripting language framework code, so that cross-application caching can be achieved. Step S405A4, updating the corresponding record in the bytecode buffer hash table. In an embodiment of the present invention, the bytecode of the JS scripting language code may be cached into a bytecode buffer hash table to update the bytecode record cached in the bytecode buffer hash table. When the JS scripting language code is executed again, the bytecode corresponding to the JS scripting language code may be obtained from the bytecode cache hash table directly through the identifier of the JS scripting language code without analyzing and compiling the process. Converting the bytecode into native code, by executing the native code to execute the JS scripting language code, can improve execution efficiency, thereby reducing the execution overhead of the JS scripting language code. Step S405B: Obtain a bytecode cache corresponding to the JS script language code from the bytecode cache hash table. If the JS script can be found in the bytecode cache hash table according to the identifier of the JS script language code The cached bytecode corresponding to the language code can directly obtain the bytecode corresponding to the JS script language code from the bytecode cache hash table. In step S406, it is determined whether the native code cache can be used. When the JIT is called, the bytecode is first searched in the native code cache hash table for the cached native code corresponding to the bytecode before being converted into the native code.
JS脚本语言代码的文件名可以是 document.url + index, 以 document.url + index 作为该 JS脚本语言代码的标识。 根据上述步骤的描述, Hash Key2可以是根据字节 码的地址生成的原生代码关键字, 可以标识字节码, 此处的 Hash Key2可以为步骤 S404中的 Hash Valuel。 Hash Value2可以标识该字节码转换后对应的原生代码。 对于判断是否可使用原生代码缓存,可以根据该 Hash Key2在原生代码缓存哈希 表中查找是否存在 Hash Value2对应的缓存的原生代码, 如果原生代码缓存哈希表中 存在 Hash Valu 对应的缓存的原生代码, 则说明可以使用原生代码缓存, 如果原生 代码缓存哈希表中不存在 Hash Value2对应的缓存的原生代码, 则说明不可以使用原 生代码缓存。 经过判断, 如果确定不可使用原生代码缓存, 则执行步骤 S407A1 ; 如 果确定可使用原生代码缓存, 则执行步骤 S407B。 步骤 S407A1 , 转换字节码为原生代码。 步骤 S407 A2, 缓存原生代码。 可以通过建立原生代码缓存哈希表的方式缓存原生代码。缓存在原生代码缓存哈 希表中的原生代码可以通过 JS脚本语言代码的标识进行标记。 例如, 可以通过 Hash Value2进行标记。 在本发明实施例中, 可以对当前应用的所有热点代码的原生代码进行缓存。 步骤 S407A3 , 更新原生代码缓存哈希表中对应的记录。 在本发明实施例中, 可以将该 JS脚本语言代码的原生代码缓存到原生代码缓存 哈希表中以更新该原生代码缓存哈希表中缓存的原生代码记录。 这样, 在该 JS脚本 语言代码再次执行时, 可以通过该 JS脚本语言代码的标识从该原生代码缓存哈希表 中获取该 JS脚本语言代码对应的原生代码,通过执行该原生代码以执行该 JS脚本语 言代码, 从而可以提高执行效率, 进而可以降低 JS脚本语言代码的执行开销。 步骤 S407B , 从原生代码缓存哈希表中获取字节码对应的原生代码缓存。 如果根据 JS脚本语言代码的标识可以在原生代码缓存哈希表中查找到该 JS脚本 语言代码对应的原生代码, 则可以从原生代码缓存哈希表中获取该原生代码。 步骤 S408, 执行原生代码。 在本发明实施例中, 可以通过执行原生代码以执行 JS脚本语言代码。 在本发明实施例中, 达到了降低 JS脚本语言代码的执行开销的效果。 在本发明实施例中,该 JS脚本语言代码执行方法可以在 firefox 23浏览器上实现。 在 firefox 23浏览器上加载和执行大型 HTML5游戏时,尤其是首次执行大型 HTML5 游戏时, 采用本发明实施例的 JS脚本语言代码执行方法, 可以降低客户端加载和执 行游戏的开销, 提高加载效率。例如, 在 firefox 23浏览器上首次加载由 mozilla提供 的 HTML5大型游戏 BananaBread时, 采用本发明实施例的 JS脚本语言代码执行方 法来执行该游戏的 JS函数时的开销, 显然, 该开销降低了。 为了实现缓存的字节码和缓存的原生代码等缓存代码的重用, 在退出 firefOX23 浏览器时,可以将所有缓存的字节码和所有缓存的原生代码等缓存代码都写入本次磁 盘文件中, 例如, jscache.cfg中, 这样, 在重启 firefox 23浏览器时, 可以从该本次 磁盘文件中读入所有缓存的字节码和所有缓存的原生代码等缓存代码。 需要说明的是,为了降低动态语言代码的执行开销, 也可以通过直接缓存并执行 由 WebAPP发布方下发给浏览器的动态语言对应的原生代码; 为了降低动态语言代 码的执行开销, 还可以通过直接缓存并执行由 Web Server 下发给浏览器的通过该 Web Server提供工具将 JS脚本语言代码转化成的对应的原生代码。 从以上的描述中,可以看出,本发明实施例实现了降低动态语言代码执行开销的 效果。 显然,本领域的技术人员应该明白, 上述的本发明的各模块或各步骤可以用通用 的计算装置来实现, 它们可以集中在单个的计算装置上, 或者分布在多个计算装置所 组成的网络上, 可选地, 它们可以用计算装置可执行的程序代码来实现, 从而, 可以 将它们存储在存储装置中由计算装置来执行,或者将它们分别制作成各个集成电路模 块, 或者将它们中的多个模块或步骤制作成单个集成电路模块来实现。这样, 本发明 不限制于任何特定的硬件和软件结合。 The file name of the JS scripting language code can be document.url + index, with document.url + index as the identifier of the JS scripting language code. According to the description of the foregoing steps, the Hash Key2 may be a native code keyword generated according to the address of the bytecode, and may identify the bytecode, where the Hash Key2 may be the Hash Valuel in step S404. Hash Value2 can identify the corresponding native code after the bytecode conversion. For judging whether the native code cache can be used, the hash code may be used in the native code cache hash table to find whether there is a cached native code corresponding to Hash Value2, if there is a hash of the hash corresponding to the hash code in the native code cache hash table. The code indicates that the native code cache can be used. If the native code of the cache corresponding to Hash Value2 does not exist in the native code cache hash table, the native code cache cannot be used. After judging, if it is determined that the native code buffer is not available, step S407A1 is performed; if it is determined that the native code buffer can be used, step S407B is performed. Step S407A1, converting the bytecode to a native code. Step S407 A2, the native code is cached. Native code can be cached by creating a native code cache hash table. Native code cached in the native code cache hash table can be tagged with the identity of the JS scripting language code. For example, you can mark it with Hash Value2. In the embodiment of the present invention, the native code of all hotspot codes of the current application may be cached. Step S407A3, updating the corresponding record in the native code cache hash table. In an embodiment of the present invention, the native code of the JS scripting language code may be cached into a native code cache hash table to update the native code record cached in the native code cache hash table. In this way, when the JS scripting language code is executed again, the native code corresponding to the JS scripting language code can be obtained from the native code cache hash table by using the identifier of the JS scripting language code, and the native code is executed to execute the JS. Script language Word code, which can improve the execution efficiency, which can reduce the execution cost of the JS scripting language code. Step S407B: Obtain a native code cache corresponding to the bytecode from the native code cache hash table. If the native code corresponding to the JS scripting language code can be found in the native code cache hash table according to the identifier of the JS scripting language code, the native code can be obtained from the native code cache hash table. Step S408, executing a native code. In an embodiment of the invention, the JS scripting language code can be executed by executing native code. In the embodiment of the present invention, the effect of reducing the execution overhead of the JS scripting language code is achieved. In the embodiment of the present invention, the JS scripting language code execution method can be implemented on a Firefox 23 browser. When the large HTML5 game is loaded and executed on the Firefox 23 browser, especially when the large HTML5 game is executed for the first time, the JS script language code execution method of the embodiment of the present invention can reduce the overhead of loading and executing the game by the client, and improve the loading efficiency. . For example, when the HTML5 large game BananaBread provided by mozilla is loaded for the first time on the Firefox 23 browser, the overhead of executing the JS function of the game using the JS script language code execution method of the embodiment of the present invention is obviously reduced. In order to reuse the cached byte code cache and native code cache code, etc., at the exit fir e f OX 23 browsers can cache all bytecode and all other cached native code cache write this code In the secondary disk file, for example, jscache.cfg, when the Firefox 23 browser is restarted, all cached bytecodes and cached code such as all cached native code can be read from the current disk file. It should be noted that, in order to reduce the execution overhead of the dynamic language code, the native code corresponding to the dynamic language sent by the WebAPP publisher to the browser may be directly cached and executed; in order to reduce the execution overhead of the dynamic language code, The corresponding native code that converts the JS scripting language code into the browser through the Web Server providing tool is directly cached and executed by the Web Server. From the above description, it can be seen that the embodiment of the present invention achieves the effect of reducing the overhead of dynamic language code execution. Obviously, those skilled in the art should understand that the above modules or steps of the present invention can be implemented by a general-purpose computing device, which can be concentrated on a single computing device or distributed over a network composed of multiple computing devices. Alternatively, they may be implemented by program code executable by the computing device, thereby Storing them in a storage device is performed by a computing device, or they are separately fabricated into individual integrated circuit modules, or a plurality of modules or steps thereof are fabricated into a single integrated circuit module. Thus, the invention is not limited to any specific combination of hardware and software.
以上所述仅为本发明的优选实施例而已, 并不用于限制本发明, 对于本领域的技 术人员来说, 本发明可以有各种更改和变化。 凡在本发明的精神和原则之内, 所作的 任何修改、 等同替换、 改进等, 均应包含在本发明的保护范围之内。  The above description is only a preferred embodiment of the present invention, and is not intended to limit the present invention, and various modifications and changes can be made to the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and scope of the present invention are intended to be included within the scope of the present invention.

Claims

权 利 要 求 Rights request
1、 一种动态语言代码执行方法, 其特征在于, 包括: 获取动态语言代码的执行请求; 判断是否存在所述动态语言代码的缓存代码,所述缓存代码为执行所述动态 语言代码时产生的代码; 如果存在所述动态语言代码的缓存代码,在所述缓存代码的基础上执行所述 动态语言代码。 1. A dynamic language code execution method, characterized in that it includes: Obtaining an execution request of the dynamic language code; Determining whether there is a cache code of the dynamic language code, the cache code being generated when the dynamic language code is executed Code; if there is a cache code of the dynamic language code, execute the dynamic language code based on the cache code.
2、 根据权利要求 1所述的方法, 其特征在于, 在所述缓存代码的基础上执 行所述动态语言代码, 包括: 判断所述缓存代码的类型,所述缓存代码包括所述动态语言代码的字节码和 原生代码; 如果所述缓存代码是所述动态语言代码的原生代码,则执行所述原生代码以 实现执行所述动态语言代码; 如果所述缓存代码是所述动态语言代码的字节码,则将所述字节码转换为原 生代码, 并执行所述原生代码以实现执行所述动态语言代码。 2. The method according to claim 1, characterized in that, executing the dynamic language code based on the cache code includes: determining the type of the cache code, and the cache code includes the dynamic language code bytecode and native code; if the cache code is the native code of the dynamic language code, execute the native code to implement the execution of the dynamic language code; if the cache code is the dynamic language code bytecode, convert the bytecode into native code, and execute the native code to execute the dynamic language code.
3、 根据权利要求 1所述的方法, 其特征在于, 所述方法还包括: 如果不存 在所述动态语言代码的缓存代码, 存储所述动态语言代码执行时产生的缓存代 码。 3. The method according to claim 1, characterized in that the method further includes: if there is no cache code of the dynamic language code, storing the cache code generated when the dynamic language code is executed.
4、 根据权利要求 3所述的方法, 其特征在于, 存储所述动态语言代码对应 的缓存代码, 包括: 存储所述动态语言代码执行时生成的字节码,并将所述字节码作为所述动态 语言代码的缓存代码; 或者, 存储所述动态语言代码执行时生成的原生代码,并将所述原生代码作为所述 动态语言代码的缓存代码; 或者, 存储 WebApp发布方或 Web Server下发的动态语言代码对应的原生代码。 4. The method according to claim 3, characterized in that, storing the cache code corresponding to the dynamic language code includes: storing the bytecode generated when the dynamic language code is executed, and using the bytecode as The cache code of the dynamic language code; or, store the native code generated when the dynamic language code is executed, and use the native code as the cache code of the dynamic language code; Or, store the native code corresponding to the dynamic language code issued by the WebApp publisher or Web Server.
5、 根据权利要求 4所述的方法, 其特征在于, 存储执行所述动态语言代码 时生成的字节码, 包括: 在预先建立的字节码哈希表中存储所述字节码,并根据所述动态语言代码的 标识对所述字节码进行标识。 5. The method of claim 4, wherein storing the bytecode generated when executing the dynamic language code includes: storing the bytecode in a pre-established bytecode hash table, and The bytecode is identified according to the identification of the dynamic language code.
6、 根据权利要求 4所述的方法, 其特征在于, 存储所述动态语言代码执行 时生成的原生代码, 包括: 在预先建立的原生代码哈希表中存储所述原生代码,并根据所述动态语言代 码的标识对所述原生代码进行标识。 6. The method according to claim 4, characterized in that, storing the native code generated when the dynamic language code is executed includes: storing the native code in a pre-established native code hash table, and storing the native code according to the The identification of dynamic language code identifies the native code.
7、 一种动态语言代码执行方法, 其特征在于, 包括: 在动态语言代码执行时, 缓存所述动态语言代码执行时生成的代码, 得到所 述动态语言代码的缓存代码; 以及, 在所述动态语言代码再次执行时,获取所述动态语言代码的缓存代码并在所 述动态语言代码的缓存代码的基础上执行所述动态语言代码。 7. A dynamic language code execution method, characterized in that it includes: when the dynamic language code is executed, caching the code generated when the dynamic language code is executed, and obtaining the cache code of the dynamic language code; and, in the When the dynamic language code is executed again, the cache code of the dynamic language code is obtained and the dynamic language code is executed based on the cache code of the dynamic language code.
8、 根据权利要求 7所述的动态语言代码执行方法, 其特征在于, 所述在动态语言代码执行时, 缓存所述动态语言代码执行时生成的代码, 得 到所述动态语言代码的缓存代码的步骤包括: 在所述动态语言代码执行时, 缓存 所述动态语言代码执行时生成的字节码,并将所述字节码作为所述动态语言代码 的缓存代码; 所述在动态语言代码再次执行时,获取所述动态语言代码的缓存代码并在所 述动态语言代码的缓存代码的基础上执行所述动态语言代码的步骤包括:在动态 语言代码再次执行时, 获取所述字节码, 并将所述字节码转换为原生代码; 通过 执行所述原生代码执行所述动态语言代码。 8. The dynamic language code execution method according to claim 7, characterized in that, when the dynamic language code is executed, the code generated when the dynamic language code is executed is cached, and the cached code of the dynamic language code is obtained. The steps include: when the dynamic language code is executed, cache the bytecode generated when the dynamic language code is executed, and use the bytecode as the cache code of the dynamic language code; During execution, the step of obtaining the cache code of the dynamic language code and executing the dynamic language code on the basis of the cache code of the dynamic language code includes: obtaining the bytecode when the dynamic language code is executed again, and convert the bytecode into native code; execute the dynamic language code by executing the native code.
9、 根据权利要求 8所述的动态语言代码执行方法, 其特征在于, 所述缓存动态语言代码执行时生成的字节码的步骤包括:建立字节码缓存哈 希表; 将所述动态语言代码执行时生成的字节码缓存到所述字节码缓存哈希表 中, 其中, 缓存所述字节码时, 将所述动态语言代码的标识对缓存的所述字节码 进行标识; 所述获取所述字节码的步骤包括:通过所述动态语言代码的标识获取所述动 态语言代码对应的所述字节码。 9. The dynamic language code execution method according to claim 8, characterized in that the step of caching the bytecode generated when the dynamic language code is executed includes: establishing a bytecode cache Hash table; cache the bytecode generated when the dynamic language code is executed into the bytecode cache hash table, where, when caching the bytecode, compare the identifier of the dynamic language code to the cached The bytecode is identified; the step of obtaining the bytecode includes: obtaining the bytecode corresponding to the dynamic language code through the identification of the dynamic language code.
10、 根据权利要求 7所述的动态语言代码执行方法, 其特征在于, 所述在动态语言代码执行时, 缓存所述动态语言代码执行时生成的代码, 得 到所述动态语言代码的缓存代码的步骤包括: 在所述动态语言代码执行时, 缓存 所述动态语言代码执行时生成的原生代码, 并将所述原生代码作为所述缓存代 码; 所述在动态语言代码再次执行时,获取所述动态语言代码的缓存代码并在所 述动态语言代码的缓存代码的基础上执行所述动态语言代码的步骤包括:在动态 语言代码再次执行时, 获取所述原生代码, 通过执行所述原生代码执行所述动态 语言代码。 10. The dynamic language code execution method according to claim 7, characterized in that, when the dynamic language code is executed, the code generated when the dynamic language code is executed is cached, and the cached code of the dynamic language code is obtained. The steps include: when the dynamic language code is executed, cache the native code generated when the dynamic language code is executed, and use the native code as the cache code; when the dynamic language code is executed again, obtain the The step of caching the dynamic language code and executing the dynamic language code based on the cached code includes: when the dynamic language code is executed again, obtain the native code and execute by executing the native code. The dynamic language code.
11、 根据权利要求 10所述的动态语言代码执行方法, 其特征在于, 所述缓存动态语言代码执行时生成的原生代码的步骤包括:建立原生代码缓 存哈希表;将所述动态语言代码执行时生成的原生代码缓存到所述原生代码缓存 哈希表中, 其中, 缓存所述原生代码时, 将所述动态语言代码的标识对缓存的所 述原生代码进行标识; 所述获取所述原生代码的步骤包括:通过所述动态语言代码的标识获取所述 动态语言代码对应的所述原生代码。 11. The dynamic language code execution method according to claim 10, characterized in that the step of caching the native code generated when the dynamic language code is executed includes: establishing a native code cache hash table; executing the dynamic language code The native code generated when is cached in the native code cache hash table, wherein when the native code is cached, the cached native code is identified with the identifier of the dynamic language code; the obtaining of the native code The step of coding includes: obtaining the native code corresponding to the dynamic language code through the identification of the dynamic language code.
12、 一种动态语言代码执行装置, 其特征在于, 包括: 获取单元, 用于获取动态语言代码的执行请求; 判断单元,用于判断是否存在所述动态语言代码的缓存代码, 所述缓存代码 为执行所述动态语言代码时产生的代码; 执行单元,用于当存在所述动态语言代码的缓存代码时, 在所述缓存代码的 基础上执行所述动态语言代码。 12. A dynamic language code execution device, characterized in that it includes: an acquisition unit, used to obtain an execution request of the dynamic language code; a judgment unit, used to judge whether there is a cache code of the dynamic language code, the cache code is the code generated when the dynamic language code is executed; an execution unit is used to, when there is a cache code of the dynamic language code, in the cache code based on executing the dynamic language code.
13、 根据权利要求 12所述的装置, 其特征在于, 所述执行单元包括: 第一判断子单元,用于判断所述缓存代码的类型, 所述缓存代码包括所述动 态语言代码的字节码和原生代码; 第一执行子单元, 用于当所述缓存代码是所述动态语言代码的原生代码时, 执行所述原生代码以实现执行所述动态语言代码; 转换子单元,用于当所述缓存代码是所述动态语言代码的字节码时, 将所述 字节码转换为原生代码。 13. The device according to claim 12, characterized in that, the execution unit includes: a first judgment sub-unit, used to judge the type of the cache code, the cache code includes bytes of the dynamic language code code and native code; the first execution subunit is used to execute the native code to execute the dynamic language code when the cache code is the native code of the dynamic language code; the conversion subunit is used to execute the dynamic language code when the cache code is the native code of the dynamic language code. When the cache code is the bytecode of the dynamic language code, the bytecode is converted into native code.
14、 根据权利要求 12所述的装置, 其特征在于, 所述装置还包括: 缓存单元,用于当不存在所述动态语言代码的缓存代码时, 存储所述动态语 言代码执行时产生的缓存代码。 14. The device according to claim 12, characterized in that, the device further includes: a cache unit, configured to store the cache generated when the dynamic language code is executed when there is no cache code of the dynamic language code. code.
15、 一种动态语言代码执行装置, 其特征在于, 包括: 缓存单元,用于在动态语言代码执行时, 缓存所述动态语言代码执行时生成 的代码, 得到所述动态语言代码的缓存代码; 以及, 执行单元,用于在所述动态语言代码再次执行时, 获取所述动态语言代码的 缓存代码并在所述动态语言代码的缓存代码的基础上执行所述动态语言代码。 15. A dynamic language code execution device, characterized in that it includes: a cache unit, used to cache the code generated when the dynamic language code is executed when the dynamic language code is executed, and obtain the cache code of the dynamic language code; And, an execution unit, configured to obtain the cache code of the dynamic language code and execute the dynamic language code based on the cache code of the dynamic language code when the dynamic language code is executed again.
16、 根据权利要求 15所述的动态语言代码执行装置, 其特征在于, 所述缓存单元用于在所述动态语言代码执行时,缓存所述动态语言代码执行 时生成的字节码, 并将所述字节码作为所述动态语言代码的缓存代码; 所述执行单元用于将所述字节码转换为原生代码;通过执行所述原生代码执 行所述动态语言代码。 16. The dynamic language code execution device according to claim 15, wherein the caching unit is used to cache the bytecode generated when the dynamic language code is executed, and store the bytecode generated when the dynamic language code is executed. The bytecode serves as the cache code of the dynamic language code; the execution unit is used to convert the bytecode into native code; and executes the dynamic language code by executing the native code.
17、 根据权利要求 16所述的动态语言代码执行装置, 其特征在于, 所述缓存单元用于采用以下方式缓存所述动态语言代码执行时生成的字节 码: 建立字节码缓存哈希表, 将所述动态语言代码执行时生成的字节码缓存到所 述字节码缓存哈希表中, 其中, 缓存所述字节码时, 将所述动态语言代码的标识 对缓存的所述字节码进行标识, 所述执行单元用于采用以下方式获取所述字节码:通过所述动态语言代码的 标识获取所述动态语言代码对应的所述字节码。 17. The dynamic language code execution device according to claim 16, wherein the caching unit is used to cache the bytecode generated when the dynamic language code is executed in the following manner: establishing a bytecode cache hash table , cache the bytecode generated when the dynamic language code is executed into the bytecode cache hash table, where, when caching the bytecode, the identifier of the dynamic language code The cached bytecode is identified, and the execution unit is configured to obtain the bytecode in the following manner: obtain the bytecode corresponding to the dynamic language code through the identification of the dynamic language code.
18、 根据权利要求 15所述的动态语言代码执行装置, 其特征在于, 所述缓存单元用于在所述动态语言代码执行时,缓存所述动态语言代码执行 时生成的原生代码, 并将所述原生代码作为所述缓存代码, 所述执行单元用于通过执行所述原生代码执行所述动态语言代码。 18. The dynamic language code execution device according to claim 15, wherein the caching unit is used to cache the native code generated when the dynamic language code is executed, and store the generated code. The native code is used as the cache code, and the execution unit is configured to execute the dynamic language code by executing the native code.
19、 根据权利要求 18所述的动态语言代码执行装置, 其特征在于, 所述缓存单元用于采用以下方式缓存所述动态语言代码执行时生成的原生 代码: 建立原生代码缓存哈希表, 将所述动态语言代码执行时生成的原生代码缓 存到所述原生代码缓存哈希表中, 其中, 缓存所述原生代码时, 将所述动态语言 代码的标识对缓存的所述原生代码进行标识, 所述执行单元用于采用以下方式获取所述原生代码:通过所述动态语言代码 的标识获取所述动态语言代码对应的所述原生代码。 19. The dynamic language code execution device according to claim 18, characterized in that the caching unit is used to cache the native code generated when the dynamic language code is executed in the following manner: establishing a native code cache hash table, and The native code generated when the dynamic language code is executed is cached in the native code cache hash table, where, when the native code is cached, the identifier of the dynamic language code is used to identify the cached native code, The execution unit is configured to obtain the native code in the following manner: obtain the native code corresponding to the dynamic language code through the identification of the dynamic language code.
20、 一种具有处理器可执行的程序代码的计算机可读介质, 其特征在于, 所 述程序代码使处理器执行下述步骤: 获取动态语言代码的执行请求; 判断是否存在所述动态语言代码的缓存代码,所述缓存代码为执行所述动态 语言代码时产生的代码; 如果存在所述动态语言代码的缓存代码,在所述缓存代码的基础上执行所述 20. A computer-readable medium having a program code executable by a processor, characterized in that the program code causes the processor to perform the following steps: Obtain an execution request for a dynamic language code; Determine whether the dynamic language code exists The cache code is the code generated when the dynamic language code is executed; if there is a cache code of the dynamic language code, the cache code is executed on the basis of the cache code
PCT/CN2014/078956 2013-08-15 2014-05-30 Dynamic language code execution method and apparatus WO2015021809A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201310357191.2 2013-08-15
CN2013103571912A CN103412754A (en) 2013-08-15 2013-08-15 Dynamic language code execution method and device

Publications (1)

Publication Number Publication Date
WO2015021809A1 true WO2015021809A1 (en) 2015-02-19

Family

ID=49605767

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2014/078956 WO2015021809A1 (en) 2013-08-15 2014-05-30 Dynamic language code execution method and apparatus

Country Status (2)

Country Link
CN (1) CN103412754A (en)
WO (1) WO2015021809A1 (en)

Families Citing this family (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103412754A (en) * 2013-08-15 2013-11-27 优视科技有限公司 Dynamic language code execution method and device
US9558096B2 (en) * 2014-03-21 2017-01-31 Marvell World Trade Ltd. Method and apparatus for supporting performance analysis
CN105786465A (en) * 2014-12-23 2016-07-20 远光软件股份有限公司 Scripting language execution method and device
CN104598227A (en) * 2014-12-31 2015-05-06 国家电网公司 Method for modifying content of system presentation page
CN106557350B (en) * 2015-09-30 2019-12-13 北京金山安全软件有限公司 JAVA byte code conversion method, device and equipment in application program installation package
CN106445505A (en) * 2016-08-31 2017-02-22 恒生电子股份有限公司 Code processing method and device
CN107015839B (en) * 2016-09-27 2020-07-17 阿里巴巴集团控股有限公司 Method and device for realizing front-end event agent
CN109144601A (en) * 2018-06-22 2019-01-04 北京奇艺世纪科技有限公司 In IOS using the interior method and system for calling function
CN110941433B (en) * 2019-11-13 2022-03-22 佛山职业技术学院 Method and system for edge-assisted deployment of third party application to microcontroller
CN116450250B (en) * 2023-06-16 2023-09-19 天津金城银行股份有限公司 Dynamic scenario execution method, system and storage medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1729453A (en) * 2002-12-23 2006-02-01 英特尔公司 Persistent cache apparatus and methods
CN103412754A (en) * 2013-08-15 2013-11-27 优视科技有限公司 Dynamic language code execution method and device

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20010042241A1 (en) * 2000-01-21 2001-11-15 Fujitsu Limited Apparatus and method for executing program using just-in time-compiler system
JP2007179153A (en) * 2005-12-27 2007-07-12 Toshiba Corp Script program execution device, script program execution method and optical disk device
US9250938B2 (en) * 2008-10-15 2016-02-02 Microsoft Technology Licensing, Llc Caching runtime generated code

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1729453A (en) * 2002-12-23 2006-02-01 英特尔公司 Persistent cache apparatus and methods
CN103412754A (en) * 2013-08-15 2013-11-27 优视科技有限公司 Dynamic language code execution method and device

Also Published As

Publication number Publication date
CN103412754A (en) 2013-11-27

Similar Documents

Publication Publication Date Title
WO2015021809A1 (en) Dynamic language code execution method and apparatus
WO2016192556A1 (en) Interface invoking method, device and terminal
US8752016B2 (en) Converting JavaScript into a device-independent representation
US8627298B2 (en) Using appropriate level of code to be executed in runtime environment using metadata describing versions of resources being used by code
US8984497B2 (en) Source code converting, method program, and systems for first programming language to a code in a second programming language
US9811321B1 (en) Script compilation
US9182953B2 (en) Hybrid dynamic code compiling device, method, and service system thereof
US10678994B2 (en) Method and system for reusing HTML content
WO2016177341A1 (en) Interface calling method and device, and terminal
US10671384B1 (en) Proactive seeding of build Artifacts
US9876880B2 (en) Creation of a binding based on a description associated with a server
KR101689745B1 (en) Web browsing system and method for rendering dynamic resource URI of script
US9880943B2 (en) Cache management in a multi-threaded environment
JP6379654B2 (en) Process execution program, process execution method, and information processing apparatus
CN111723314B (en) Webpage display method and device, electronic equipment and computer readable storage medium
US11500652B2 (en) Method and system for application loading
CN103544276B (en) Method and device for displaying script files by virtual machine
JP5535184B2 (en) Browser execution script conversion system and browser execution script conversion program
US20160274996A1 (en) Method to efficiently implement synchronization using software managed address translation
CN106293746B (en) Method and system for updating browser script
US20140052772A1 (en) Http performance enhancement based on delta transfer
CN107643892B (en) Interface processing method, device, storage medium and processor
US11689630B2 (en) Request processing method and apparatus, electronic device, and computer storage medium
CN112650502A (en) Batch processing task processing method and device, computer equipment and storage medium
CN104965909A (en) Dynamic web content request handling method

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 14836484

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 06.07.2016)

122 Ep: pct application non-entry in european phase

Ref document number: 14836484

Country of ref document: EP

Kind code of ref document: A1