IP Library › Patent Application 13593417
Patent Application
App. No. 13/593,417

Runtime State Based Code Re-Optimization

Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US None
App. No.
13/593,417
Abstract

A method and an apparatus to execute a code compiled from a source code to access an untyped variable are described. An optimized access code may be compiled in the code with speculative optimization via a type prediction of runtime value of the untyped variable. Invalidity of the type prediction may be dynamically detected for future runtime values of the untyped variable. The code may be updated with an access code compiled for the access without the speculative optimization based on the invalidity detection. The updated code can be executed for the access to the untyped variable without executing the optimized access code.

Claims (50)

1 . A machine-readable non-transitory storage medium having instructions therein, which when executed by a machine, cause the machine to perform a method, the method comprising:

executing a code compiled from a source code, the source code including an access of an untyped variable, the access being compiled with speculative optimization as an optimized access code in the code via a type prediction of runtime values of the untyped variable;

detecting dynamically invalidity of the type prediction for future runtime values of the untyped variable;

updating the code with an access code compiled for the access without the speculative optimization; and

executing the updated code without executing the optimized access code for the future runtime values of the untyped variable.

2 . The medium of claim 1 , wherein the type prediction specifies one or more expected types for the runtime values, wherein the execution of the code is based on at least one memory heap, wherein existing runtime values are allocated in the memory heap via the execution of the code, and wherein the detection comprises:

identifying types of the existing runtime values, wherein the type prediction is valid if at least one of the identified types belongs to the expected types.

3 . The medium of claim 2 , wherein an access code compiled without the speculative optimization is based on a collection of possible types of values for the untyped variable and wherein the collection of possible types include the expected types.

4 . The medium of claim 2 , wherein the source code specifies one or more functions, each function having zero or more input variables to update one or more variables, wherein the function represents a structure transition from a source collection of types to a target collection of types, wherein each target type corresponds one of the updated variables based on the input variables belonging to the source collection of types, the detection further comprising:

identifying a sequence of one or more of the functions, wherein the types of the existing runtime values are transitively transitioned to a resulting collection of types via structure transitions in order corresponding to the sequence of functions, and wherein the type prediction is valid if at least one of the resulting collection of types belongs to the expected types.

5 . The medium of claim 4 , wherein the sequence of functions includes a first function and a second function next to the first function according to the sequence, the first function corresponding to a first structure transition, the second function corresponding to a second structure transition, wherein a first collection of types are transitively transitioned to a second collection of types via the first structure transition and the second structure transition in order if the first collection of types is transitioned to an intermediate collection of types via the first structure transition and the intermediate collection of types is transitioned to the second collection of types via the second structure transition.

6 . The medium of claim 4 , wherein each existing runtime value corresponds to a runtime object, wherein the identification of the sequence of functions comprises:

determining if the one or more functions are invokable based on the existing runtime values, wherein a particular one of the functions is invokable if a particular one of the existing runtime values corresponds to a particular runtime object including a pointer pointing to the particular function, wherein the particular function is invokable if an invokable one of the functions specifies a call to the particular function, and wherein each of the sequence of functions is invokable.

7 . The medium of claim 4 , wherein the invalidity is detected if none of the identified types belongs to the expected types and no sequence of the functions is identified for a corresponding resulting collection of types with at least one of the corresponding resulting collection of types belonging to the expected types.

8 . The medium of claim 4 , further comprising:

performing garbage collection operations to maintain the heap memory, wherein the detection of the invalidity of the type prediction is initiated via the garbage collection operations.

9 . The medium of claim 1 , further comprising:

profiling the execution of the code to collect one or more types of values assigned to the untyped variable during runtime, and wherein the type prediction is based on previously collected types of values.

10 . The medium of claim 9 , wherein the access of the untyped variable is specified in one of the functions, the one function having at least one input variable, and wherein the untyped variable belongs to the at least one input variable of the one function.

11 . The medium of claim 10 , wherein the code includes an optimally compiled function code for the one function optimized based on the type prediction, and wherein the optimally compiled function code includes the access to the untyped variable.

12 . The medium of claim 11 , wherein the updated code includes a non-optimized compiled function code for the one function without the optimally compiled function code.

13 . The medium of claim 11 , wherein the update comprises:

recompiling the code dynamically during the runtime to remove the optimally compiled function code for the one function.

14 . The medium of claim 11 , wherein a non-optimally compiled function code for the one function includes the access code, and wherein the recompilation replaces the optimally compiled function code with the non-optimally compiled function code for the one function.

15 . The medium of claim 11 , wherein the collected types of values correspond to an updated type prediction for the future runtime values of the untyped variable and wherein the recompilation replaces the optimally compiled function code with an updated compiled function code for the one function optimized based on the updated type prediction.

16 . A machine-readable non-transitory storage medium having instructions therein, which when executed by a machine, cause the machine to perform a method, the method comprising:

executing a code compiled from a source code specifying at least one function having one or more untyped input variables, the code including a first function code optimally compiled for the function based on a type prediction for future runtime values of the untyped input variables;

detecting dynamically invalidity of the type prediction for the future runtime values of the untyped variable;

updating the code with a second function code compiled for the function; and

executing the updated code without executing the first function code for the future runtime values of the untyped input variables.

17 . The medium of claim 16 , wherein the execution of the code is based on a heap memory allocated with objects corresponding to existing runtime values for the execution of the code, the method further comprising:

performing garbage collection operations to maintain the heap memory, wherein the garbage collection operations identify which of the objects are no longer needed for the execution of the code and wherein the garbage collection operations include a callback to initiate the detection of the invalidity.

18 . The medium of claim 16 , wherein the type prediction corresponds to one or more expected types for the input variables and wherein the detection comprises:

determining whether types of the future runtime values include the expected types, wherein the invalidity is detected if the types of the future runtime values do not overlap with the expected types.

19 . The medium of claim 18 , further comprising:

identifying types of the existing runtime values in the heap memory, wherein the types of the future runtime values include the types of the existing runtime values.

20 . The medium of claim 18 , wherein the code includes a plurality of function codes for a plurality of functions specified in the source code, wherein at least one of the function codes represents a structure transition indicating a destination type of the future runtime values based on a source type of the future runtime values, and wherein the types of the future runtime values include the destination type if the types of the future runtime values include the source type.

21 . The medium of claim 20 , wherein the objects in the heap memory include a pointer pointing to the at least one function code.

22 . A computer implemented method comprising:

executing a code compiled from a source code, the source code including an access of an untyped variable, the access being compiled with speculative optimization as an optimized access code in the code via a type prediction of runtime values of the untyped variable;

detecting dynamically invalidity of the type prediction for future runtime values of the untyped variable;

updating the code with an access code compiled for the access without the speculative optimization; and

executing the updated code without executing the optimized access code for the future runtime values of the untyped variable.

23 . A computer system comprising:

a memory storing instructions and a source code, the source code including an access of an untyped variable for a data processing task;

a processor coupled to the memory and the user interface to execute the instructions from the memory, the processor being configured to

execute a code compiled from a source code including an access of an untyped variable, the access being compiled with speculative optimization as an optimized access code in the code via a type prediction of runtime values of the untyped variable,

detect dynamically invalidity of the type prediction for future runtime values of the untyped variable,

update the code with an access code compiled for the access without the speculative optimization, and

execute the updated code without executing the optimized access code for the future runtime values of the untyped variable.

Assignments (1)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Aug 24, 2012
From: PIZLO, FILIP J.; BARRACLOUGH, GAVIN
To: APPLE INC.
Reel/Frame 028847/0756 →