Method and apparatus for determining frequency of execution for compiled methods within a virtual machine
Abstract
One embodiment of the present invention provides a system that facilitates determining a frequency of execution of compiled methods within a virtual machine. The system starts by determining if a compiled method is executing. If so, the system sets a flag corresponding to the compiled method to indicate that the compiled method is executing. Periodically, the system scans the flag and increments the value of a corresponding counter if the flag is set, and then resets the flag. Finally, the system analyzes the value of the counter to determine a frequency of execution of the compiled method.

Term
Term ended
Projected expiry passed 28 February 2025, 1.6 years ago.
- Priority
- Filed
- Published
- Projected expiry
- Today
17 claims: 12 independent, 5 dependent
- 1A method for determining a frequency of execution of compiled methods within a virtual machine, the method comprising:when a compiled method is executed, setting a flag corresponding to the compiled method to indicate that the compiled method is executing;periodically, scanning the flag and incrementing the value of a corresponding counter if the flag is set, and then resetting the flag;and analyzing the value of the counter to determine a frequency of execution of the compiled method.
- 4The method of any preceding claim, wherein determining when the compiled method is executed further involves executing an instruction when the compiled method is called by a second compiled method, wherein the instruction sets the flag corresponding to the compiled method.
- 5The method of any preceding claim, wherein determining when the compiled method is executed further involves executing an instruction when returning to a second compiled method from the compiled method, wherein the instruction sets the flag corresponding to the compiled method.
- 6The method of any preceding claim, wherein determining when the compiled method is executed further involves executing an instruction when returning to the compiled method from a second compiled method, wherein the instruction sets the flag corresponding to the compiled method.
- 7The method of any preceding claim, wherein determining when the compiled method is executed further involves executing an instruction when initiating a backward branch within the compiled method, wherein the instruction sets the flag corresponding to the compiled method.
- 8The method of any preceding claim, wherein determining when the compiled method is executed further involves executing an instruction at a target for a backward branch within the compiled method, wherein the instruction sets the flag corresponding to the compiled method.
- 9The method of any preceding claim, further comprising evicting the compiled method if the frequency of execution of the compiled method is below a predetermined threshold, so that the method must be subsequently recompiled or interpreted if the compiled method is executed again.
- 11The method of any preceding claim, further comprising periodically decreasing the counter to introduce decay, thereby fading the relevance of historical execution of the compiled method over time.
- 13The method of any preceding claim, further comprising periodically increasing a weight value assigned to the flag so that subsequent executions of the compiled method count more than prior executions of the compiled method.
- 14A computer program for implementing the method of any preceding claim.
- 15A computer-readable storage medium storing instructions that when executed by a computer cause the computer to perform a method for determining a frequency of execution of compiled methods within a virtual machine, the method comprising:when a compiled method is executed, setting a flag corresponding to the compiled method to indicate that the compiled method is executing;periodically, scanning the flag and incrementing the value of a corresponding counter if the flag is set, and then resetting the flag;and analyzing the value of the counter to determine a frequency of execution of the compiled method.
- 16Apparatus for determining a frequency of execution of compiled methods within a virtual machine, comprising:a determination mechanism configured to determine when a compiled method is executed;a flag setting mechanism configured to set a flag corresponding to the compiled method to indicate that the compiled method is executing, if the compiled method is executing;a scanning mechanism configured to periodically scan the flag and increment the value of a corresponding counter if the flag is set, and to reset the flag;and an analysis mechanism configured to analyze the value of the counter to determine a frequency of execution of the compiled method.
Independent claims13
48 paragraphs, as filed
<b>Field of the Invention</b>
0001The present invention relates to virtual machines within computer systems. More specifically, the present invention relates to a method and an apparatus for determining the frequency of execution of compiled methods within a virtual machine.
<b>Background of the Invention</b>
0002The Java 2 Platform, Micro Edition (J2ME<sup>TM</sup>), has become very popular in the wireless device space. Motorola, Nokia, NTT DoCoMo, RIM, Siemens, and many other key players in the wireless device industry have recently started shipping J2ME-enabled devices in very high volume. It has been estimated that over 200 million J2ME-enabled mobile phones were shipped in 2003 alone.
0003One major limitation of these wireless devices is the relatively small amount of memory available for executing programs. Many methods have been developed to optimize memory usage in these memory-constrained devices. Once such method involves using a dynamic compiler that supports both the execution of interpreted code and compiled code. Code that is executed more often is compiled and executed in compiled mode, while code that is executed less often is executed in interpreted mode. Note that the compiled code executes much faster than the interpreted code; however, the compiled code takes up a lot more space than the executed code.
0004Whether this dynamically generated compiled code resides on the object heap or in a separate code cache region of memory, this compiled code is typically evicted from memory when it is no longer frequently accessed, and this eviction typically takes place through a garbage collection (GC) process. Note that the compiled code may contain pointers to objects which are handled by the GC process.
0005Although the actual eviction of the compiled code happens during GC, the victim selection portion of the eviction process is ideally based on information gathered during mutator execution, wherein the system can gather information to rank compiled methods according to how frequently they are used.
0006As memory constraints become tighter, the quality of this ranking process becomes increasingly important for sustaining high overall execution speed. On the other hand, if the ranking mechanism becomes too complicated, obtaining ranking data may create a significant additional burden on the mutator.
0007In order to determine when a method is in use, it is a common practice to insert software hooks into specific locations in a method. These hooks can gather data and perform various computations when they are encountered during program execution.
0008Current victim selection schemes that use hooks fall into two categories, heavyweight hooks and lightweight hooks. With heavyweight hooks, the system performs some weighting calculation concerning a routine directly in the above hooks. For example, the hook can increment a counter in a Java method. In contrast, lightweight hooks produce a minimal amount of mutator slowdown by computing as little as possible in the hooks. For example, there is a self-modifying code scheme in the Connected Limited Device Configuration HotSpot Implementation (CLDC HI) within J2ME<sup>TM</sup> that patches the Java method callee prolog only the first time a hook is executed during a given GC cycle. In subsequent uses of the same routine, there is no mutator overhead.
0009Another way to determine method usage is to use statistical sampling. Statistical sampling operates by periodically analyzing the current stack to determine when routines are executing. (The statistical sampling method also counts as lightweight, since it typically executes relatively infrequently.)
0010However, all of the above-described techniques have drawbacks. They either slow down the mutator significantly, or they do not gather enough information for good victim selection. Furthermore, the interval between GCs is generally too large to establish a useful ranking among large numbers of methods. (Reflecting multiple GC intervals in multiple bits as in CLDC HI does not fully solve this problem, since one GC interval is generally already too long.)
<b>Summary of the Invention</b>
0011One embodiment of the present invention provides a system that facilitates determining a frequency of execution of compiled methods within a virtual machine. The system starts by determining if a compiled method is executing. If so, the system sets a flag corresponding to the compiled method to indicate that the compiled method is executing. Periodically, the system scans the flag and increments the value of a corresponding counter if the flag is set, and then resets the flag. Finally, the system analyzes the value of the counter to determine a frequency of execution of the compiled method.
0012In one embodiment, the system adjusts a time interval between incrementations of the counter.
0013In one embodiment, the system determines when the compiled method is executed by executing an instruction when the compiled method calls a second compiled method, wherein the instruction sets the flag corresponding to the compiled method.
0014In one embodiment, the system determines when the compiled method is executed by executing an instruction when the compiled method is called by a second compiled method, wherein the instruction sets the flag corresponding to the compiled method.
0015In one embodiment, the system determines when the compiled method is executed by executing an instruction when returning to a second compiled method from the compiled method, wherein the instruction sets the flag corresponding to the compiled method.
0016In one embodiment, the system determines when the compiled method is executed by executing an instruction when returning to the compiled method from a second compiled method, wherein the instruction sets the flag corresponding to the compiled method.
0017In one embodiment, the system determines when the compiled method is executed by executing an instruction when initiating a backward branch within the compiled method, wherein the instruction sets the flag corresponding to the compiled method.
0018In one embodiment, the system determines when the compiled method is executed by executing an instruction at a target for a backward branch within the compiled method, wherein the instruction sets the flag corresponding to the compiled method.
0019In one embodiment, the system evicts the compiled method if the frequency of execution of the compiled method is below a predetermined threshold, so that the method must be subsequently recompiled or interpreted if the compiled method is executed again. The system may adjust the predetermined threshold to regulate the number of compiled methods.
0020In one embodiment, the system periodically decreases the counter to introduce decay, thereby fading the relevance of historical execution of the compiled method over time. The system may periodically decrease the counter when any counter associated with any method reaches a predetermined threshold.
0021In one embodiment, the system periodically increases a weight value assigned to the flag so that subsequent executions of the compiled method count more than prior executions of the compiled method.
<b>Brief Description of the Figures</b>
0022Various embodiments of the invention will now be described in detail by way of example only with reference to the following drawings: <ul id="ul0001" list-style="none" compact="compact"><li>FIG. 1 illustrates a memory-constrained computing device in accordance with one embodiment of the present invention.</li><li>FIG. 2 illustrates a flag array in accordance with one embodiment of the present invention.</li><li>FIG. 3 illustrates a reference array in accordance with one embodiment of the present invention.</li><li>FIG. 4 presents a flowchart illustrating the process of setting flag bits in accordance with one embodiment of the present invention.</li><li>FIG. 5 presents a flowchart illustrating the process of accumulating the set flag bits in accordance with an embodiment of the present invention.</li></ul>
<b>Detailed Description</b>
<b>Memory-Constrained Computing Device</b>
0023FIG. 1 illustrates a memory-constrained computing device 100 in accordance with one embodiment of the present invention. Memory-constrained computing device 100 may include any type of computing device, including, but not limited to, a cell phone, a computer system based on a microprocessor, a digital signal processor, a portable computing device, a personal organizer, a device controller, and a computational engine within an appliance. Memory-constrained computing device 100 contains Java Virtual Machine (JVM) 102, which in turn supports execution of both compiled and interpreted methods. (The terms JAVA, JVM and JAVA VIRTUAL MACHINE are trademarks of SUN Microsystems, Inc. of Santa Clara, California.) Note that JVM 102 could be any type of platform-independent virtual machine, and is not meant to be limited to a Java Virtual Machine.
0024JVM 102 contains compiled method store 110. In order to improve performance within JVM 102, some methods are compiled and added to compiled method store 110, which enables these methods to execute faster than the interpreted methods. However, the compiled methods generally take up more space than the interpreted methods, depending on the quality of the compiled code. Furthermore, in many systems, interpreted code cannot be discarded after compilation. Hence, JVM 102 dynamically compiles only the more frequently used methods and places them in compiled store 110. Additionally, JVM 102 regularly evicts less frequently used compiled methods from compiled method store 110 to save space so that subsequent executions of the method take place in interpreted mode. Such evictions may take place during a garbage-collection operation, as well as during some other eviction operation that occurs outside of a garbage-collection operation.
<b>Flag Array</b>
0025FIG. 2 illustrates a flag array 200 in accordance with one embodiment of the present invention. Flag array 200 is used to facilitate victim selection in a manner that achieves nearly the victim selection quality of heavyweight hooks and the overall cost of lightweight hooks as described previously. In one embodiment of the present invention, the dynamic compiler in JVM 102 generates extra code in (1) the prologue of a callee, (2) directly after a call, and (3) directly before a backwards branch. Using the above three locations, one can catch most relevant method access (except for long loop-free code stretches, which are better executed by the interpreter anyway). Other hook placements (or a subset of the above placements) might also work, though probably with less accuracy and thus reduced method ranking quality.
0026The present approach restricts the hook to a very brief inline action; namely, setting a flag in flag array 200 that corresponds to the routine (method, function) being executed. In the example illustrated in FIG. 2, a bit is set in flag array 200 representing the execution of a compiled method in compiled methods 202. The actual machine instruction to set the flag is chosen to address the smallest addressible memory unit (word, byte, bit) without compromising performance. Typically, it sets one byte, although in some architectures, it may set an entire word or a single bit. These flags are contained within flag array 200 which is located at an offset specified by a global variable. Each compiled method has its own index (within compiled methods 202) into flag array 200. Note that indices of evicted routines can be reused.
0027Theoretically, the fact that a method in question has been used at a given point in time will decay in usefulness as mutator execution progresses. As explained above, waiting until a GC happens to harvest the bit and use it for ranking purposes typically takes too long. Gathering more than one bit, on the other hand, increases the mutator burden. The present approach resolves this tension by introducing a third phase in which gathered bits are adjusted to represent the fading of their relevance over time.
<b>Reference Array</b>
0028FIG. 3 illustrates a reference array 300 in accordance with one embodiment of the present invention. Reference array 300 maps the flag indices back to their respective compiled methods, such as compiled method 112, compiled method 302, and compiled method 304. Furthermore, an extra "count" field is associated with each method. This association can either be provided by a third array, count array 310, or by placing an extra field into each method instance. Using the above data structures, the system can iterate over all compiled routines and update their "count" fields according to which flags have been set. After the count fields are updated, all flags are then reset.
0029In one embodiment of the present invention, the process of updating the count fields involves two phases. In the first phase, all counts are lowered to fade the relevance of method usage over time. Then, in the second phase, the flag (with possibly some weight factor) is added only to those routines which have a flag set in the given interval.
0030In another embodiment of the present invention, there is only a single phase in which all counts for methods with set flags are updated, but the weight factor for a set flag is increased at every interval. The count lowering can thus be delayed until GC time, after which the flag weight is reset. Note that this scheme further reduces impact on the mutator.
0031In a third embodiment of the present invention, count decay is triggered by reaching a certain count threshold for any of the compiled methods. This decay process helps to model typical program execution, which typically involves frequent access to a small compiled working set of methods, wherein the working set evolves over time. During normal program execution, certain methods are executed much more frequently than other methods during a specific time period. Over time, the set of methods that are executed most frequently (the working set) changes as the program executes. In this embodiment, the count decay process is important because it reduces the importance of methods that have executed less recently, which helps to result in stronger count values for methods in the working set.
0032It is also important to consider when more methods are being interpreted rather then executed. In order to increase overall performance, in one embodiment of the present invention, a shift in the workload to the interpreter triggers a decay round. For example, this can be approximated by observing the ratio of interpreted execution to compiled execution during a specific time interval. In effect, this embodiment of the present invention makes the choice of interval length virtually irrelevant for the decay processing, in that decay "time flow" is decoupled from wall clock time.
0033Furthermore, at GC time, all methods can be ranked by their accumulated count. The system can either first sort them by count, or can repeatedly search for victims below a certain count threshold, and keep increasing the threshold until a given eviction target is met. Note that the summarization interval needs to be short enough to maintain the relevance of set flags in flag array 200. It also needs to be long enough to spread out mutator burden. In balancing these demands, the system must consider mutator speed, i.e. the rate at which flag setting hooks are hit.
0034The system also needs to handle index overflow. Each index is assigned to a method before it gets compiled. In cases where there is no available index, the system can either prevent compilation until an index will be freed, or can attempt to usurp the index of a routine with a low current ranking. In the rare case that the original index owner sets a flag, an inaccuracy occurs. However, this is likely to be a rare event, which is best ensured against by choosing a large enough array so that index overflow is unlikely to occur. To accomplish this, the array size can be proportional to the heap size. (For example, for a 1 MB heap, an array with 500 elements could be used).
<b>Setting Flag Bits</b>
0035FIG. 4 presents a flowchart illustrating the process of setting flag bits in flag array 200 in accordance with one embodiment of the present invention. The system starts by determining when a compiled method, such as compiled method 112, is executed (step 402). This can be accomplished by the use of the execution hooks described previously. Finally, the system sets a flag bit in flag array 200 indicating that the compiled method has executed (step 406).
<b>Accumulating Set Flag Bits</b>
0036FIG. 5 presents a flowchart illustrating the process of accumulating the set flag bits from flag array 200 into count array 310 in accordance with one embodiment of the present invention. At some periodic interval, the system scans flag array 200 for set flag bits (step 502). For each set flag bit, the system increments a count in count array 310 that corresponds to the flag bit in flag array 200 (step 504). Once all of the appropriate counts in count array 310 have been incremented, the system clears all of the flag bits in flag array 200 for the next periodic interval (step 506). Note that while incrementing count array 310, if the system detects an overflow in one of the counts, the system may shift the bits of count array 310 to introduce a decay as described above.
0037The data structures and code described in this detailed description are typically stored on a computer-readable storage medium, which may be any device or medium that can store code and/or data for use by a computer system. This includes, but is not limited to, magnetic, semiconductor, and optical storage devices such as disk drives, magnetic tape, flash memory, CDs (compact discs) and DVDs (digital versatile discs or digital video discs), and computer instruction signals embodied in a transmission medium (with or without a carrier wave upon which the signals are modulated). For example, the transmission medium may include a communications network, such as the Internet.
0038The foregoing descriptions of embodiments of the present invention have been presented for purposes of illustration in order to enable a person skilled in the art to appreciate and implement the invention. They are provided in the context of particular applications and their requirements, but are not intended to be exhaustive or to limit the present invention to the forms disclosed. Accordingly, many modifications and variations will be apparent to practitioners skilled in the art, and the scope of the present invention is defined by the appended claims and their equivalents.
4 sheets
Sheet 1 Sheet 2 Sheet 3 Sheet 4
Every citation, both ways
| Document | Relation | Office | Cited during |
|---|---|---|---|
| EP0905619A2 | Cites | European Patent Office (EPO) | Applicant |
| EP0908819A2 | Cites | European Patent Office (EPO) | Search report |
| US2002144240A1 | Cites | United States of America | Applicant |
| US2003110357A1 | Cites | United States of America | Search report |
| US6126329A | Cites | United States of America | Search report |
| US6249912B1 | Cites | United States of America | Search report |
9 members in 3 offices
Priority claims4
| Document | Office | Kind | Date |
|---|---|---|---|
| 550802P | United States of America | – | |
| 55080204 | United States of America | P | |
| 966086 | United States of America | – | |
| 96608604 | United States of America | A |
Members9
| Document | Office | Kind | |
|---|---|---|---|
| US2005198620A1 | United States of America | A1 | |
| JP2005251208A | Japan | A | |
| EP1589425A2This record | European Patent Office (EPO) | A2 | |
| EP1589425A3 | European Patent Office (EPO) | A3 | |
| US7412693B2 | United States of America | B2 | |
| JP2012038359A | Japan | A | |
| EP1589425B1 | European Patent Office (EPO) | B1 | |
| JP2013257916A | Japan | A | |
| JP5422635B2 | Japan | B2 |
32 legal events, as 4 offices reported them to INPADOC
Over the term
Point at a mark for the eventEvents
| Event | Code | Office | |
|---|---|---|---|
| Lapsed in a contracting state [announced via postgrant information from national office to epo]LapsedPG25 | PG25 | EP | |
| Patent expired after termination of 20 yearsExpiredPE20 | PE20 | GB | |
| Expiry of rightR071 | R071 | DE | |
| Annual fee paid to national office [announced via postgrant information from national office to epo]GrantedPGFP | PGFP | EP | |
| Annual fee paid to national office [announced via postgrant information from national office to epo]GrantedPGFP | PGFP | EP | |
| Opt-out of the competence of the unified patent court (upc) registeredP01 | P01 | EP | |
| Change of representativeR082 | R082 | DE | |
| Lapsed in a contracting state [announced via postgrant information from national office to epo]LapsedPG25 | PG25 | EP | |
| Notification of lapseLapsedST | ST | FR | |
| No opposition filed against granted patent, or epo opposition proceedings concluded without decisionGrantedR097 | R097 | DE | |
| No opposition filedOpposition26N | 26N | EP | |
| No opposition filed within time limitOppositionORIGINAL CODE: 0009261PLBE | PLBE | EP | |
| Information on the status of an ep patent application or granted ep patentGrantedSTATUS: NO OPPOSITION FILED WITHIN TIME LIMITSTAA | STAA | EP | |
| Dpma publication of mentioned ep patent grantGrantedR096 | R096 | DE | |
| Designated contracting statesAK | AK | EP | |
| European patent grantedGrantedFG4D | FG4D | GB | |
| (expected) grantORIGINAL CODE: 0009210GRAA | GRAA | EP | |
| Grant fee paidORIGINAL CODE: EPIDOSNIGR3GRAS | GRAS | EP | |
| Information provided on ipc code assigned before grantRIC1 | RIC1 | EP | |
| Information provided on ipc code assigned before grantRIC1 | RIC1 | EP | |
| Despatch of communication of intention to grant a patentORIGINAL CODE: EPIDOSNIGR1GRAP | GRAP | EP | |
| Party data changed (applicant data changed or rights of an application transferred)RAP1 | RAP1 | EP | |
| First examination report despatched (corrected)R17C | R17C | EP | |
| First examination report despatched17Q | 17Q | EP | |
| Designation fees paidAKX | AKX | EP | |
| Request for examination filed17P | 17P | EP | |
| Designated contracting statesAK | AK | EP | |
| Request for extension of the european patentAX | AX | EP | |
| Search report despatchedORIGINAL CODE: 0009013PUAL | PUAL | EP | |
| Designated contracting statesAK | AK | EP | |
| Request for extension of the european patentAX | AX | EP | |
| Public reference made under article 153(3) epc to a published international application that has entered the european phaseORIGINAL CODE: 0009012PUAI | PUAI | EP |
Numbers
- Publication
- 1589425
- Application
- 52511573
Titles3
- German
- Verfahren und Vorrichtung zur Feststellung der Ausführungsfrequenz von übersetzten Methoden in einer virtuellen Maschine
- English
- Method and apparatus for determining frequency of execution for compiled methods within a virtual machine
- French
- Méthode et appareil pour déterminer la fréquence d'exécution de méthodes compilées dans une machine virtuelle
Classification
- CPC, 5
- G06F9/5016
- G06F9/4552
- G06F11/3466
- G06F2201/865
- G06F2201/88
- IPC, 3
- G06F9 50
- G06F11 34
- G06F9 44
Designated states36
- Contracting states, 30
- Austria
- Belgium
- Bulgaria
- Switzerland
- Cyprus
- Czechia
- Germany
- Denmark
- Estonia
- Spain
- Finland
- France
- United Kingdom
- Greece
- Hungary
- Ireland
- Iceland
- Italy
- Liechtenstein
- Lithuania
- Luxembourg
- Monaco
- Netherlands (Kingdom of the)
- Poland
and 6 moreShow fewer
- Portugal
- Romania
- Sweden
- Slovenia
- Slovakia
- Türkiye
- Extension states, 6
- Albania
- Bosnia and Herzegovina
- Croatia
- Latvia
- North Macedonia
- Yugoslavia, later Serbia and Montenegro (until 2006)