Optimized storage of function variables
OwnerVictor Leonel Hernandez Porras, Roger Scott Hooverinventors
Life of this patent
Estimating the term…
Abstract
Optimized storage of function variables in compiled code is disclosed. It is determined that a variable of a first function is required to be available for use by a second function subsequent to return of the first function. Machine code is generated to escape the variable from a storage location in a stack memory to a storage location in a heap memory, prior to the variable being removed from the stack memory, in connection with return of the first function.
Claims21
A method for processing software code, comprising:
- while analyzing a high-level code, determining programmatically that:
- variables of a first function are required to be available for use by a second function subsequent to a return of the first function, and
- variables of a third function are not required to be available for use by the second function subsequent to a return of the third function,
- wherein the determining comprises identifying that the second function continues to reference the variables of the first function, but not the variables of the third function, subsequent to the return of the first function;
- and
- when compiling the high-level code into machine code:
- generating automatically for the first function a first segment of machine code that, when executed, is configured to:
- copy values of the variables of the first function from a storage location in a stack memory to temporary objects stored in a heap memory prior to the values of the variables of the first function being removed from the stack memory in response to the return of the first function, wherein:
- during execution of the first function, the temporary objects store pointers to the storage location in the stack memory, and,
- subsequent to the return of the first function, and during execution of the second function, the temporary objects store the copied values instead of the pointers;
- and
- generating automatically for the third function a second segment of machine code that, when executed, is configured to cause values of the variables of the third function to be removed from the stack memory when the third function returns.
A system for processing software code, comprising:
- a memory;
- and
- a processor coupled to the memory and configured to:
- while analyzing a high-level code, determining programmatically that:
- variables of a first function are required to be available for use by a second function subsequent to a return of the first function, and
- variables of a third function are not required to be available for use by the second function subsequent to a return of the third function,
- wherein the determining comprises identifying that the second function continues to reference the variables of the first function, but not the variables of the third function, subsequent to the return of the first function;
- and
- when compiling the high-level code into machine code:
- generating automatically for the first function a first segment of machine code that, when executed, is configured to:
- copy values of the variables of the first function from a storage location in a stack memory to temporary objects stored in a heap memory prior to the values of the variables of the first function being removed from the stack memory in response to the return of the first function, wherein:
- during execution of the first function, the temporary objects store pointers to the storage location in the stack memory, and,
- subsequent to the return of the first function, and during execution of the second function, the temporary objects store the copied value instead of the pointers;
- and
- generating automatically for the third function a second segment of machine code that, when executed, is configured to cause values of the variables of the third function to be removed from the stack memory when the third function returns.
A computer program product for processing software code, the computer program product being embodied in a non-transitory computer readable storage medium and comprising computer instructions that, when executed by a processor, cause the processor to implement a method, the method comprising:
- while analyzing a high-level code, determining programmatically that:
- variables of a first function are required to be available for use by a second function subsequent to a return of the first function, and
- variables of a third function are not required to be available for use by the second function subsequent to a return of the third function,
- wherein the determining comprises identifying that the second function continues to reference the variables of the first function, but not the variables of the third function, subsequent to the return of the first function;
- and
- when compiling the high-level code into machine code:
- generating automatically for the first function a first segment of machine code that, when executed, is configured to:
- copy values of the variables of the first function from a storage location in a stack memory to temporary objects stored in a heap memory prior to the values of the variables of the first function being removed from the stack memory in response to the return of the first function, wherein:
- during execution of the first function, the temporary objects store pointers to the storage location in the stack memory, and,
- subsequent to the return of the first function, and during execution of the second function, the temporary objects store the copied values instead of the pointers;
- and
- generating automatically for the third function a second segment of machine code that, when executed, is configured to cause values of the variables of the third function to be removed from the stack memory when the third function returns.
A system for processing software code, comprising:
- a memory;
- a processor coupled to the memory;
- means for determining, while analyzing a high-level code, that:
- variables of a first function are required to be available for use by a second function subsequent to a return of the first function, and
- variables of a third function are not required to be available for use by the second function subsequent to a return of the third function,
- wherein the determining comprises identifying that the second function continues to reference the variables of the first function, but not the variables of the third function, subsequent to the return of the first function;
- and
- when compiling the high-level code into machine code:
- means for generating automatically for the first function a first segment of machine code that, when executed, is configured to:
- copy values of the variables of the first function from a storage location in a stack memory to temporary objects stored in a heap memory prior to the values of the variables of the first function being removed from the stack memory in response to the return of the first function, wherein:
- during execution of the first function, the temporary objects store pointers to the storage location in the stack memory, and,
- subsequent to the return of the first function, and during execution of the second function, the temporary objects store the copied values instead of the pointers;
- and
- means for generating automatically for the third function a second segment of machine code that, when executed, is configured to cause values of the variables of the third function to be removed from the stack memory when the third function returns.
Dependencies are inferred from the claim text.