# US 7,412,693 B2 · Method and apparatus for determining frequency of execution for compiled methods within a virtual machine

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 7,412,693 B2
- Document ID: US7412693B2
- Status: Granted
- Kind: B2
- Application number: 10/966,086
- Filed: 2004-10-15
- Published: 2005-09-08
- Granted: 2008-08-12
- Earliest claimed: 2004-03-05
- Assignees: Sun Microsystems, Inc.
- Inventors: Bernd J. W. Mathiske; Oleg A. Pliss
- Web page: https://patentgrep.com/patent/US7412693B2

## CPC

- G06F 9/5016: {the resource being the memory}
- G06F 9/4552: {Involving translation to a different instruction set architecture, e.g. just-in-time translation in a JVM}
- G06F 11/3466: {Performance evaluation by tracing or monitoring}
- G06F 2201/865: Monitoring of software
- G06F 2201/88: Monitoring involving counting
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## 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.

## Claims

### Claim 1

A method for determining a relative frequency of execution of compiled methods within a virtual machine, the method comprising:
a flag array wherein each compiled method has a corresponding index into the flag array;
wherein each compiled method has a corresponding counter;
when a compiled method is executed, setting a flag in the flag array corresponding to the compiled method to indicate that the compiled method is executing;
periodically, scanning the flag array and for each compiled method, incrementing a value of the corresponding counter if the flag corresponding to the compiled method is set to indicate that the compiled method has executed at least once since the flag array was last reset, and then resetting the flag array for subsequent scanning; and
for each compiled method, analyzing the value of the corresponding counter to determine a relative frequency of execution of each of the compiled methods.

### Claim 2 (depends on 1)

The method of claim 1, further comprising adjusting a time interval between incrementations of the counter.

### Claim 3 (depends on 1)

The method of claim 1, wherein determining when the compiled method is executed further involves executing an instruction when the compiled method calls a second compiled method, wherein the instruction sets the flag corresponding to the compiled method.

### Claim 4 (depends on 1)

The method of claim 1, 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.

### Claim 5 (depends on 1)

The method of claim 1, 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.

### Claim 6 (depends on 1)

The method of claim 1, 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.

### Claim 7 (depends on 1)

The method of claim 1, 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.

### Claim 8 (depends on 1)

The method of claim 1, 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.

### Claim 9 (depends on 1)

The method of claim 1, further comprising evicting the compiled method if the frequency of execution of the compiled method is below a predetermined threshold, so that the compiled method must be subsequently recompiled or interpreted if the compiled method is executed again.

### Claim 10 (depends on 9)

The method of claim 9, further comprising adjusting the predetermined threshold to regulate a number of compiled methods.

### Claim 11 (depends on 1)

The method of claim 1, further comprising periodically decreasing the counter to introduce decay, thereby fading a relevance of historical execution of the compiled method over time.

### Claim 12 (depends on 11)

The method of claim 11, further comprising periodically decreasing the counter when any counter associated with any method reaches a predetermined threshold.

### Claim 13 (depends on 1)

The method of claim 1, 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.

### Claim 14

A computer-readable storage medium storing instructions that when executed by a computer cause the computer to perform a method for determining a relative frequency of execution of compiled methods within a virtual machine, the method comprising:
a flag array wherein each compiled method has a corresponding index into the flag array;
wherein each compiled method has a corresponding counter;
when a compiled method is executed, setting a flag in the flag array corresponding to the compiled method to indicate that the compiled method is executing;
periodically, scanning the flag array and for each compiled method, incrementing a value of the corresponding counter if the flag corresponding to the compiled method is set to indicate that the compiled method has executed at least once since the flag array was last reset, and then resetting the flag array for subsequent scanning; and
for each compiled method, analyzing the value of the corresponding counter to determine a relative frequency of execution of each of the compiled methods.

### Claim 15 (depends on 14)

The computer-readable storage medium of claim 14, wherein the method further comprises adjusting a time interval between incrementations of the counter.

### Claim 16 (depends on 14)

The computer-readable storage medium of claim 14, wherein determining when the compiled method is executed further involves executing an instruction when the compiled method calls a second compiled method, wherein the instruction sets the flag corresponding to the compiled method.

### Claim 17 (depends on 14)

The computer-readable storage medium of claim 14, 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.

### Claim 18 (depends on 14)

The computer-readable storage medium of claim 14, 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.

### Claim 19 (depends on 14)

The computer-readable storage medium of claim 14, 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.

### Claim 20 (depends on 14)

The computer-readable storage medium of claim 14, 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.

### Claim 21 (depends on 14)

The computer-readable storage medium of claim 14, 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.

### Claim 22 (depends on 14)

The computer-readable storage medium of claim 14, wherein the method further comprises evicting the compiled method if the frequency of execution of the compiled method is below a predetermined threshold, so that the compiled method must be subsequently recompiled or interpreted if the compiled method is executed again.

### Claim 23 (depends on 22)

The computer-readable storage medium of claim 22, wherein the method further comprises adjusting the predetermined threshold to regulate a number of compiled methods.

### Claim 24 (depends on 14)

The computer-readable storage medium of claim 14, wherein the method further comprises periodically decreasing the counter to introduce decay, thereby fading a relevance of historical execution of the compiled method over time.

### Claim 25 (depends on 24)

The computer-readable storage medium of claim 24, wherein the method further comprises periodically decreasing the counter when any counter associated with any method reaches a predetermined threshold.

### Claim 26 (depends on 14)

The computer-readable storage medium of claim 14, wherein the method further comprises 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.

### Claim 27

An apparatus for determining a relative frequency of execution of compiled methods within a virtual machine, comprising:
a processor;
a memory;
a flag array wherein each compiled method has a corresponding index into the flag array;
wherein each compiled method has a corresponding counter;
a determination mechanism configured to determine when a compiled method is executed;
a flag setting mechanism configured to set a flag in the flag array 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 array and for each compiled method, increment a value of the corresponding counter if the flag corresponding to the compiled method is set to indicate that the compiled method has executed at least once since the flag array was last reset, and to reset the flag array for subsequent scanning; and
an analysis mechanism configured to analyze the value of the corresponding counter for each compiled method to determine a relative frequency of execution of each of the compiled methods.

### Claim 28 (depends on 27)

The apparatus of claim 27, further comprising an adjustment mechanism configured to adjust a time interval between incrementations of the counter.

### Claim 29 (depends on 27)

The apparatus of claim 27, wherein the determination mechanism is further configured to determine 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.

### Claim 30 (depends on 27)

The apparatus of claim 27, wherein the determination mechanism is further configured to determine 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.

### Claim 31 (depends on 27)

The apparatus of claim 27, wherein the determination mechanism is further configured to determine 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.

### Claim 32 (depends on 27)

The apparatus of claim 27, wherein the determination mechanism is further configured to determine 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.

### Claim 33 (depends on 27)

The apparatus of claim 27, wherein the determination mechanism is further configured to determine 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.

### Claim 34 (depends on 27)

The apparatus of claim 27, wherein the determination mechanism is further configured to determine 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.

### Claim 35 (depends on 27)

The apparatus of claim 27, further comprising an eviction mechanism configured to evict the compiled method if the frequency of execution of the compiled method is below a predetermined threshold, so that the compiled method must be subsequently recompiled or interpreted if the compiled method is executed again.

### Claim 36 (depends on 35)

The apparatus of claim 35, further comprising an adjustment mechanism configured to adjust the predetermined threshold to regulate a number of compiled methods.

### Claim 37 (depends on 27)

The apparatus of claim 27, further comprising a decay mechanism configured to periodically decrease the counter to introduce decay, thereby fading a relevance of historical execution of the compiled method over time.

### Claim 38 (depends on 37)

The apparatus of claim 37, wherein the decay mechanism is further configured to periodically decrease the counter when any counter associated with any method reaches a predetermined threshold.

### Claim 39 (depends on 27)

The apparatus of claim 27, further comprising a weighting mechanism configured to periodically increase a weight value assigned to the flag so that subsequent executions of the compiled method count more than prior executions of the compiled method.
