Memory Fence Insertion for Thread Safety in Java Compilation

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Statically compiling programs, such as JAVA programs, can be time-consuming due to incorrect variable value observations across threads caused by hardware implementations reordering instructions for performance benefits, leading to misreads and increased compilation time.

Innovation Solution

Determine the existence of predetermined write and read patterns in a program and insert a memory fence before or after variables accordingly to prevent misreads, using weaker memory fences like acquire fences to reduce execution time without compromising performance.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Reliability

If memory fences are inserted to prevent incorrect variable value observations across threads, then reliability is improved, but device complexity increases

Engineering Contradiction:
Improvevariable value observation correctnessVSAvoidprogram structure complexity
Core Design Contradiction:
ReliabilityVSDevice complexity

Solution Approach 1:

The patent applies local quality by selectively inserting memory fences only at specific locations where thread interference patterns are detected, rather than uniformly throughout the program. This targeted approach maintains reliability where needed while minimizing the overall increase in program complexity.

Inventive Principle:
Principle #3Local quality

Solution Approach 2:

Memory fences act as intermediary elements inserted into the program code to mediate between competing thread operations. These fences prevent harmful reordering effects without requiring fundamental changes to the program structure or threading model.

Inventive Principle:
Principle #24Intermediary (Mediator)

2Reliability

If memory fences are inserted to prevent misreads, then reliability is improved, but execution time increases

Engineering Contradiction:
Improvevariable read correctnessVSAvoidprogram execution time
Core Design Contradiction:
ReliabilityVSLoss of time

Solution Approach 1:

The patent reduces execution time overhead by applying memory fences locally only where thread interference patterns are detected, rather than throughout the entire program. This selective application minimizes the time penalty while maintaining reliability where thread safety is actually needed.

Inventive Principle:
Principle #3Local quality

Solution Approach 2:

The patent applies partial action by inserting memory fences only in the minimal necessary locations to prevent incorrect variable observations, avoiding excessive fence insertion that would unnecessarily increase execution time.

Inventive Principle:
Principle #16Partial or excessive action

3Productivity

If static compilation is used to reduce runtime overhead, then productivity is improved, but compilation time increases

Engineering Contradiction:
Improveruntime execution efficiencyVSAvoidcompilation time
Core Design Contradiction:
ProductivityVSLoss of time

Solution Approach 1:

The patent performs preliminary static analysis during compilation to detect thread interference patterns and determine optimal memory fence insertion points. This advance preparation enables efficient runtime execution without requiring complex runtime analysis or interpretation overhead.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent changes the compilation approach by integrating pattern detection and fence insertion decisions into the static compilation process, transforming the compilation task to produce optimized code that executes efficiently without requiring lengthy runtime setup.

Inventive Principle:
Principle #35Parameter changes

Data Source

PatentUS20230393821A1Inserting a memory fence in a program in response to a determination that predetermined pattern(s) do not exist in the program
Publication Date: 2023.12.07 INTERNATIONAL BUSINESS MACHINE CORPORATION
  • US20230393821A1 patent drawing
  • US20230393821A1 patent drawing
  • US20230393821A1 patent drawing

AI summary

A computer-implemented method according to one embodiment includes determining whether a predetermined write pattern and a predetermined read pattern exist in a program of an application. In response to a determination that the predetermined write pattern and the predetermined read pattern do not exist in the program, a memory fence is inserted before a variable in the program. A computer-implemented method according to another embodiment includes determining whether a predetermined write pattern exists in a program of an application. In response to a determination that the predetermined write pattern does not exist in the program, a memory fence is inserted after a variable in the program.