Virtual Thread Stack Switching Between Low and High Memory

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing context switching mechanisms for virtual threads in Java and similar programming languages are expensive and resource-intensive, particularly due to the need for stack copying and management, which limits the number of threads that can be allocated and complicates garbage collection.

Innovation Solution

Implement a hybrid virtual thread context switching mechanism that switches stacks between low and high memory based on availability, using a stack manager to copy unused stacks from low to high memory when low memory is scarce, allowing efficient scheduling and de-scheduling of virtual threads without hard limits on thread count.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Reliability

If traditional context switching mechanisms are used for virtual threads, then thread execution can be managed, but the cost of context switching becomes expensive and resource-intensive due to stack copying and management

Engineering Contradiction:
Improvethread execution managementVSAvoidcontext switching cost
Core Design Contradiction:
ReliabilityVSLoss of energy

Solution Approach 1:

The patent extracts the stack management overhead from the context switching operation itself. By maintaining thread stacks in a separate, efficiently managed heap area rather than copying them during context switches, the expensive stack copying operation is removed from the critical context switching path, leaving only lightweight register state switching.

Inventive Principle:
Principle #2Taking out (Extraction)

Solution Approach 2:

The patent uses selective copying only when necessary - specifically when threads need to be suspended or when the heap needs to be compacted. Instead of copying stacks on every context switch, copies occur only during garbage collection cycles or suspension events, dramatically reducing the frequency and cost of stack copying operations.

Inventive Principle:
Principle #26Copying

2Productivity

If more virtual threads are allocated to improve concurrency, then system throughput increases, but memory resources are consumed and stack management becomes more complex

Engineering Contradiction:
Improvesystem throughputVSAvoidstack management complexity
Core Design Contradiction:
ProductivityVSDevice complexity

Solution Approach 1:

The patent merges the management of thread stacks with the garbage collector's heap management. By having the garbage collector also responsible for stack heap management, compaction, and suspension, the system consolidates multiple functions into a single mechanism, reducing overall system complexity while supporting large numbers of threads.

Inventive Principle:
Principle #5Merging (Combining)

Solution Approach 2:

The garbage collector is given multiple functions: it manages the heap for thread stacks, performs stack compaction to free space, suspends threads when needed, and handles stack copying. This multi-functional approach eliminates the need for separate stack management infrastructure, simplifying the system while enabling support for many concurrent threads.

Inventive Principle:
Principle #6Universality (Multi-functionality)

3Ease of manufacture

If thread stacks are managed in traditional memory areas, then allocation is straightforward, but garbage collection becomes complicated and less efficient

Engineering Contradiction:
Improvestack allocationVSAvoidgarbage collection complexity
Core Design Contradiction:
Ease of manufactureVSDevice complexity

Solution Approach 1:

The patent combines stack memory management with the garbage collection process. Thread stacks are allocated from and returned to the same heap that the garbage collector manages, allowing the GC to handle both regular object memory and stack memory uniformly. This integration simplifies garbage collection by eliminating special cases for stack memory while maintaining ease of stack allocation.

Inventive Principle:
Principle #5Merging (Combining)

Data Source

PatentUS12481528B2Hybrid virtual thread context switching mechanism
Publication Date: 2025.11.25 INTERNATIONAL BUSINESS MACHINE CORPORATION
  • US12481528B2 patent drawing
  • US12481528B2 patent drawing
  • US12481528B2 patent drawing

AI summary

Hybrid virtual thread context switching in virtual machines is provided. For virtual threads scheduled to run on a VM, it is determined whether a virtual thread requires a stack. If a stack is required, it is determined whether low memory has space to allocate a stack. If there is space, a stack in low memory is allocated. If not, unused stacks are copied from low to high memory. If the virtual thread does not require a stack, it is determined whether the virtual thread stack is in low memory. If it is not, it is copied from high memory if there is enough space in low memory. If there is not enough space, unused stacks are copied from low memory to high memory. If the stack is in low memory, the method performs a stack switch and schedules the virtual on a carrier thread of the VM.