Non-Overwritable Variable for Thread Visibility
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Concurrent threads or processes may not have visibility to the latest value assigned to a shared field due to instruction reordering by compilers and CPUs adhering to the Java Language Specification, leading to penalties in garbage collection and memory latency when using 'final' or 'volatile' attributes.
Innovation Solution
Inserting a declaration of a non-overwritable variable pointing to a current object in the source code and storing a value referencing the current object to ensure visibility without creating new objects, thereby avoiding reordering issues and associated overhead.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Reliability
If a 'final' attribute is associated with a shared field to ensure visibility, then thread visibility is improved, but garbage collection overhead increases due to creation of new objects to replace the final field
Solution Approach 1:
The patent extracts the visibility guarantee mechanism from the object replacement approach. Instead of creating new objects to replace final fields, the invention uses a separate non-overwritable variable that holds a reference to the current object, allowing visibility without object creation overhead.
Solution Approach 2:
The patent introduces a non-overwritable variable as an intermediary between the shared field and the object reference. This intermediary variable ensures visibility of the current object reference to threads without requiring the actual object to be recreated, thus eliminating garbage collection overhead while maintaining reliability.
2Reliability
If a 'volatile' attribute is associated with a shared field to ensure visibility, then thread visibility is improved, but memory latency increases due to required reading of the volatile field
Solution Approach 1:
The patent extracts the visibility guarantee from the volatile field reading requirement. By using a non-overwritable variable to store the object reference, the invention eliminates the need for repeated volatile reads while maintaining thread visibility, thus improving memory access speed.
Solution Approach 2:
The patent applies preliminary action by storing the object reference in the non-overwritable variable during object creation. This preliminary storage ensures that the reference is available to threads without requiring subsequent volatile reads, reducing memory latency while maintaining visibility guarantees.
3Speed
If instruction reordering is allowed by compiler and CPU to optimize performance, then execution speed is improved, but visibility of latest field values is compromised
Solution Approach 1:
The patent uses the non-overwritable variable as an intermediary that prevents instruction reordering from compromising visibility. The special properties of this variable ensure that assignments to it maintain ordering guarantees, allowing the compiler and CPU to optimize other instructions while preserving visibility of the latest object reference.
Data Source
AI summary
Embodiments of the disclosure are directed to inserting a declaration of a non-overwritable variable pointing to a current object in a source code, and inserting a code of storing a value referencing the current object to the non-overwritable variable. Embodiments of the disclosure are directed to converting a source code to generate a shared object in a lock-free mode by inserting a declaration of a non-overwritable variable pointing to a current object in the source code, and inserting a code of storing a value referencing the current object to the non-overwritable variable.


