Compiler Function Variable Escaping Stack to Heap

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing methods for compiling JavaScript and similar programming languages that store function variables in stack memory face errors when a second function relies on variables of a first function after the first function has returned, as the variables are no longer available in the stack.

Innovation Solution

Generating machine code that conditionally escapes function variables from the stack to heap memory if they need to be available to another function after the first function has returned, using a temporary object to store pointers to these variables during execution and copying their values to the heap upon return.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Speed

If function variables are stored in stack memory, then access time is reduced and execution speed is improved, but variables become unavailable to subsequent functions after the first function returns

Engineering Contradiction:
Improveexecution speedVSAvoidvariable availability
Core Design Contradiction:
SpeedVSReliability

Solution Approach 1:

The patent applies dynamics by making the storage location of function variables changeable rather than fixed. Variables dynamically switch between stack storage (during function execution for speed) and heap storage (after function return for availability). The compiler analyzes control flow to determine when variables need to escape the stack and generates appropriate code to transfer them to heap memory, enabling the system to adapt storage location based on execution state.

Inventive Principle:
Principle #15Dynamics

Solution Approach 2:

The patent uses heap memory as an intermediary storage location between the stack and the requirements of subsequent functions. When a function variable needs to remain available after the function returns, the system transfers the variable from the stack to the heap as an intermediary step, allowing the variable to persist across function boundaries while maintaining fast access during execution.

Inventive Principle:
Principle #24Intermediary (Mediator)

2Reliability

If function variables are stored in heap memory, then variables remain available to subsequent functions, but access time increases and execution speed decreases

Engineering Contradiction:
Improvevariable availabilityVSAvoidexecution speed
Core Design Contradiction:
ReliabilityVSSpeed

Solution Approach 1:

The system dynamically selects the optimal storage location based on execution context. During function execution, variables are stored in the stack for fast access. The compiler analyzes control flow graphs to identify variables that need to escape to subsequent functions and generates code to transfer them to the heap at appropriate times, achieving both speed and availability.

Inventive Principle:
Principle #15Dynamics

Solution Approach 2:

The patent segments the storage strategy into two distinct phases: stack storage during execution for performance, and heap storage after return for availability. The compiler divides the variable lifecycle into segments and applies different storage mechanisms to each segment, optimizing for the appropriate metric at each phase.

Inventive Principle:
Principle #1Segmentation

3Reliability

If the compiler transfers variables from stack to heap, then variable availability is maintained, but additional memory operations are required increasing complexity

Engineering Contradiction:
Improvevariable availabilityVSAvoidmemory operation complexity
Core Design Contradiction:
ReliabilityVSDevice complexity

Solution Approach 1:

The compiler performs preliminary analysis of the control flow graph to identify which variables need to escape to subsequent functions before generating code. This static analysis allows the compiler to pre-determine the escapement requirements and generate optimized code that transfers variables at the correct moments, avoiding unnecessary runtime operations and reducing overall complexity.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent changes the parameter of storage location from fixed (either stack or heap) to variable based on function execution state. The compiler modifies the storage parameter dynamically by transferring variables between stack and heap at appropriate points in execution, enabling the system to adapt to different control flow scenarios without requiring complex runtime decision-making.

Inventive Principle:
Principle #35Parameter changes

Data Source

PatentUS8898625B2Optimized storage of function variables
Publication Date: 2014.11.25 APPLE INC
  • US8898625B2 patent drawing
  • US8898625B2 patent drawing
  • US8898625B2 patent drawing

AI summary

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.