Preventing unsafe sharing through confinement of mutable captured variables
AssigneeOracle International Corporation
InventorsBrian Goetz, Alexander R. Buckley
Life of this patent
Estimating the term…
Abstract
The disclosed embodiments provide a system that facilitates the development and execution of a software program. During operation, the system provides a mechanism for restricting a variable to a runtime context in the software program. Next, the system identifies the runtime context during execution of the software program. Finally, the system uses the mechanism to prevent incorrect execution of the software program by ensuring that a closure capturing the variable executes within the identified runtime context.
Claims17
A computer-implemented method for facilitating the development and execution of a software program, comprising:
- during execution of the software program:
- receiving a first context identifier that identifies a creation runtime context and a creation thread that are used to create a closure that captures a variable;
- receiving a second context identifier that identifies a subsequent-execution runtime context and a subsequent-execution thread for a subsequent execution of the closure;
- and
- preventing unsafe sharing of variables captured by closures by ensuring that the subsequent-execution runtime context corresponds to the creation runtime context by:
- in response to determining that the first context identifier does not correspond to the second context identifier, preventing the unsafe sharing of variables captured by closures by modifying the closure to execute within the creation thread.
A system for facilitating the development and execution of a software program, comprising:
- a mechanism for restricting a variable to a runtime context in the software program;
- and
- a runtime system configured to, during execution of the program:
- receive a first context identifier that identifies a creation runtime context and a creation thread that are used to create a closure that captures the variable;
- receive a second context identifier that identifies a subsequent-execution runtime context and a subsequent-execution thread for a subsequent execution of the closure;
- and
- use the mechanism to prevent the software program from unsafely sharing variables captured by closures by ensuring that the subsequent-execution runtime context corresponds to the creation runtime context by:
- in response to determining that the first context identifier does not correspond to the second context identifier, prevent the software program from unsafely sharing variables captured by closures by modifying the closure to execute within the creation thread.
A non-transitory computer-readable storage medium storing instructions that when executed by a computer cause the computer to perform a method for facilitating the development and execution of a software program, the method comprising:
- providing a mechanism for restricting a variable to a runtime context in the software program;
- during execution of the software program:
- receiving a first context identifier that identifies a creation runtime context and a creation thread that are used to create a closure that captures the variable;
- receiving a second context identifier that identifies a subsequent-execution runtime context and a subsequent-execution thread for a subsequent execution of the closure;
- and
- preventing the software program from unsafe sharing of variables captured by closures by ensuring that the subsequent-execution runtime context corresponds to the creation runtime context by:
- in response to determining that the first context identifier does not correspond to the second context identifier, preventing the unsafe sharing of variables captured by closures within the subsequent-execution runtime context by modifying the closure to execute within the creation thread.
Dependencies are inferred from the claim text.