APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.vm

public Class Continuation

extends Object
Class Inheritance
Known Direct Subclasses
java.lang.VirtualThread.VThreadContinuation
Imports
jdk.internal.misc.Unsafe, jdk.internal.vm.annotation.DontInline, .IntrinsicCandidate, .Hidden, .JvmtiHideEvents, java.util.EnumSet, .Set, java.util.function.Supplier, jdk.internal.access.JavaLangAccess, .SharedSecrets

A one-shot delimited continuation.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
Continuation.Pinned

Reason for pinning

public static enum
Continuation.PreemptStatus

Preemption attempt result

Field Summary

Modifier and TypeField and Description
private Continuation
private boolean
private static final JavaLangAccess
private volatile boolean
private static final long
private Continuation
private boolean
private static final boolean
private final ContinuationScope
private Object[]
private StackChunk
private final Runnable
private static final Unsafe
U

private Object

Constructor Summary

AccessConstructor and Description
public
Continuation(ContinuationScope
the continuation's scope, used in yield
scope
,
Runnable
the continuation's body
target
)

Constructs a continuation

Method Summary

Modifier and TypeMethod and Description
private boolean
compareAndSetMounted(boolean expectedValue, boolean newValue)

private static Thread
private static native int
private void
dump()

private static void
enter(Continuation c, boolean isContinue)

private void
private static native void
enterSpecial(Continuation c, boolean isContinue, boolean isVirtualThread)

private boolean
private void
public static Continuation

Returns:

the continuation
getCurrentContinuation
(ContinuationScope
the scope
scope
)

Returns the current innermost continuation with the given scope

public Continuation
public ContinuationScope
public StackTraceElement[]

Returns:

the stack trace
getStackTrace
()

Obtains a stack trace for this unmounted continuation

private String
id()

private Continuation
public boolean

Returns:

whether this continuation is completed
isDone
()

Tests whether this continuation is completed

private boolean
private static boolean
public static boolean

Returns:

true if we're in the give scope and are pinned; false otherwise
isPinned
(ContinuationScope
the continuation scope
scope
)

Tests whether the given scope is pinned.

private static native int
public boolean

Returns:

whether this unmounted continuation was unmounted by forceful preemption
isPreempted
()

Tests whether this unmounted continuation was unmounted by forceful preemption (a successful tryPreempt)

private boolean
private void
protected void
onContinue()

Called when the continuation continues

protected void
onPinned(Continuation.Pinned
the reason for pinning
reason
)

Called when suspending if the continuation is pinned

private void
onPinned0(int reason)

public static native void
pin()

Pins the current continuation (enters a critical section).

private static Continuation.Pinned
pinnedReason(int reason)

private void
private static native void
public final void
run()

Mounts and runs the continuation body.

private void
setMounted(boolean newValue)

public StackWalker

Returns:

a new StackWalker
stackWalker
()

Creates a StackWalker for this continuation

public StackWalker

Returns:

a new StackWalker
stackWalker
(Set<StackWalker.Option>
the StackWalker's configuration options
options
)

Creates a StackWalker for this continuation

public StackWalker

Returns:

a new StackWalker
stackWalker
(Set<StackWalker.Option>
the StackWalker's configuration options
options
,
ContinuationScope
the delimiting continuation scope for the stack
scope
)

Creates a StackWalker for this continuation and enclosing ones up to the given scope

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public Continuation.PreemptStatus

Returns:

the result of the attempt
tryPreempt
(Thread
the thread on which to forcefully preempt this continuation
thread
)

Tries to forcefully preempt this continuation if it is currently mounted on the given thread Subclasses may throw an UnsupportedOperationException, but this does not prevent the continuation from being preempted on a parent scope.

private void
public static native void
unpin()

Unpins the current continuation (exits a critical section).

public static <R> R
public static boolean

Returns:

true for success; false for failure
yield
(ContinuationScope
The ContinuationScope to suspend
scope
)

Suspends the current continuations up to the given scope

private boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

childback to summary
private Continuation child
doneback to summary
private boolean done
JLAback to summary
private static final JavaLangAccess JLA
mountedback to summary
private volatile boolean mounted
MOUNTED_OFFSETback to summary
private static final long MOUNTED_OFFSET
parentback to summary
private Continuation parent
preemptedback to summary
private boolean preempted
PRESERVE_SCOPED_VALUE_CACHEback to summary
private static final boolean PRESERVE_SCOPED_VALUE_CACHE
scopeback to summary
private final ContinuationScope scope
scopedValueCacheback to summary
private Object[] scopedValueCache
tailback to summary
private StackChunk tail
targetback to summary
private final Runnable target
Uback to summary
private static final Unsafe U
yieldInfoback to summary
private Object yieldInfo

Constructor Detail

Continuationback to summary
public Continuation(ContinuationScope scope, Runnable target)

Constructs a continuation

Parameters
scope:ContinuationScope

the continuation's scope, used in yield

target:Runnable

the continuation's body

Method Detail

compareAndSetMountedback to summary
private boolean compareAndSetMounted(boolean expectedValue, boolean newValue)
currentCarrierThreadback to summary
private static Thread currentCarrierThread()
doYieldback to summary
private static native int doYield()
Annotations
@IntrinsicCandidate
dumpback to summary
private void dump()
enterback to summary
private static void enter(Continuation c, boolean isContinue)
Annotations
@Hidden
@DontInline
@IntrinsicCandidate
@JvmtiHideEvents
enter0back to summary
private void enter0()
Annotations
@Hidden
@JvmtiHideEvents
enterSpecialback to summary
private static native void enterSpecial(Continuation c, boolean isContinue, boolean isVirtualThread)
Annotations
@IntrinsicCandidate
fenceback to summary
private boolean fence()
finishback to summary
private void finish()
getCurrentContinuationback to summary
public static Continuation getCurrentContinuation(ContinuationScope scope)

Returns the current innermost continuation with the given scope

Parameters
scope:ContinuationScope

the scope

Returns:Continuation

the continuation

getParentback to summary
public Continuation getParent()
getScopeback to summary
public ContinuationScope getScope()
getStackTraceback to summary
public StackTraceElement[] getStackTrace()

Obtains a stack trace for this unmounted continuation

Returns:StackTraceElement[]

the stack trace

Exceptions
IllegalStateException:
if the continuation is mounted
idback to summary
private String id()
innermostback to summary
private Continuation innermost()
isDoneback to summary
public boolean isDone()

Tests whether this continuation is completed

Returns:boolean

whether this continuation is completed

isEmptyback to summary
private boolean isEmpty()
isEmptyOrTrueback to summary
private static boolean isEmptyOrTrue(String property)
isPinnedback to summary
public static boolean isPinned(ContinuationScope scope)

Tests whether the given scope is pinned. This method is slow.

Parameters
scope:ContinuationScope

the continuation scope

Returns:boolean

true if we're in the give scope and are pinned; false otherwise

isPinned0back to summary
private static native int isPinned0(ContinuationScope scope)
isPreemptedback to summary
public boolean isPreempted()

Tests whether this unmounted continuation was unmounted by forceful preemption (a successful tryPreempt)

Returns:boolean

whether this unmounted continuation was unmounted by forceful preemption

isStartedback to summary
private boolean isStarted()
mountback to summary
private void mount()
onContinueback to summary
protected void onContinue()

Called when the continuation continues

onPinnedback to summary
protected void onPinned(Continuation.Pinned reason)

Called when suspending if the continuation is pinned

Parameters
reason:Continuation.Pinned

the reason for pinning

onPinned0back to summary
private void onPinned0(int reason)
pinback to summary
public static native void pin()

Pins the current continuation (enters a critical section). This increments an internal semaphore that, when greater than 0, pins the continuation.

Annotations
@IntrinsicCandidate
pinnedReasonback to summary
private static Continuation.Pinned pinnedReason(int reason)
postYieldCleanupback to summary
private void postYieldCleanup()
registerNativesback to summary
private static native void registerNatives()
runback to summary
public final void run()

Mounts and runs the continuation body. If suspended, continues it from the last suspend point.

setMountedback to summary
private void setMounted(boolean newValue)
stackWalkerback to summary
public StackWalker stackWalker()

Creates a StackWalker for this continuation

Returns:StackWalker

a new StackWalker

stackWalkerback to summary
public StackWalker stackWalker(Set<StackWalker.Option> options)

Creates a StackWalker for this continuation

Parameters
options:Set<StackWalker.Option>

the StackWalker's configuration options

Returns:StackWalker

a new StackWalker

stackWalkerback to summary
public StackWalker stackWalker(Set<StackWalker.Option> options, ContinuationScope scope)

Creates a StackWalker for this continuation and enclosing ones up to the given scope

Parameters
options:Set<StackWalker.Option>

the StackWalker's configuration options

scope:ContinuationScope

the delimiting continuation scope for the stack

Returns:StackWalker

a new StackWalker

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
tryPreemptback to summary
public Continuation.PreemptStatus tryPreempt(Thread thread)

Tries to forcefully preempt this continuation if it is currently mounted on the given thread Subclasses may throw an UnsupportedOperationException, but this does not prevent the continuation from being preempted on a parent scope.

Parameters
thread:Thread

the thread on which to forcefully preempt this continuation

Returns:Continuation.PreemptStatus

the result of the attempt

Exceptions
UnsupportedOperationException:
if this continuation does not support preemption
unmountback to summary
private void unmount()
unpinback to summary
public static native void unpin()

Unpins the current continuation (exits a critical section). This decrements an internal semaphore that, when equal 0, unpins the current continuation if pinned with pin().

Annotations
@IntrinsicCandidate
wrapWalkback to summary
public static <R> R wrapWalk(Continuation inner, ContinuationScope scope, Supplier<R> walk)
yieldback to summary
public static boolean yield(ContinuationScope scope)

Suspends the current continuations up to the given scope

Parameters
scope:ContinuationScope

The ContinuationScope to suspend

Returns:boolean

true for success; false for failure

Annotations
@Hidden
@JvmtiHideEvents
Exceptions
IllegalStateException:
if not currently in the given scope,
yield0back to summary
private boolean yield0(ContinuationScope scope, Continuation child)
Annotations
@Hidden
@JvmtiHideEvents
jdk.internal.vm back to summary

public final Enum Continuation.Pinned

extends Enum<Continuation.Pinned>
Class Inheritance

Reason for pinning

Field Summary

Modifier and TypeField and Description
public static final Continuation.Pinned
CRITICAL_SECTION

In critical section

public static final Continuation.Pinned
EXCEPTION

Exception (OOME/SOE)

public static final Continuation.Pinned
NATIVE

Native frame on stack

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Continuation.Pinned
public static Continuation.Pinned[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CRITICAL_SECTIONback to summary
public static final Continuation.Pinned CRITICAL_SECTION

In critical section

EXCEPTIONback to summary
public static final Continuation.Pinned EXCEPTION

Exception (OOME/SOE)

NATIVEback to summary
public static final Continuation.Pinned NATIVE

Native frame on stack

Constructor Detail

Pinnedback to summary
private Pinned()

Method Detail

valueOfback to summary
public static Continuation.Pinned valueOf(String name)
valuesback to summary
public static Continuation.Pinned[] values()
jdk.internal.vm back to summary

public final Enum Continuation.PreemptStatus

extends Enum<Continuation.PreemptStatus>
Class Inheritance

Preemption attempt result

Field Summary

Modifier and TypeField and Description
public static final Continuation.PreemptStatus
PERM_FAIL_NOT_MOUNTED

Permanent failure: continuation not mounted on the thread

public static final Continuation.PreemptStatus
PERM_FAIL_UNSUPPORTED

Permanent failure

public static final Continuation.PreemptStatus
PERM_FAIL_YIELDING

Permanent failure: continuation already yielding

pack-priv final Continuation.Pinned
public static final Continuation.PreemptStatus
SUCCESS

Success

public static final Continuation.PreemptStatus
TRANSIENT_FAIL_PINNED_CRITICAL_SECTION

Transient failure: continuation pinned due to a held CS

public static final Continuation.PreemptStatus
TRANSIENT_FAIL_PINNED_NATIVE

Transient failure: continuation pinned due to native frame

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Continuation.Pinned

Returns:

whether or not the continuation is pinned
pinned
()

Whether or not the continuation is pinned.

public static Continuation.PreemptStatus
public static Continuation.PreemptStatus[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

PERM_FAIL_NOT_MOUNTEDback to summary
public static final Continuation.PreemptStatus PERM_FAIL_NOT_MOUNTED

Permanent failure: continuation not mounted on the thread

PERM_FAIL_UNSUPPORTEDback to summary
public static final Continuation.PreemptStatus PERM_FAIL_UNSUPPORTED

Permanent failure

PERM_FAIL_YIELDINGback to summary
public static final Continuation.PreemptStatus PERM_FAIL_YIELDING

Permanent failure: continuation already yielding

pinnedback to summary
pack-priv final Continuation.Pinned pinned
SUCCESSback to summary
public static final Continuation.PreemptStatus SUCCESS

Success

TRANSIENT_FAIL_PINNED_CRITICAL_SECTIONback to summary
public static final Continuation.PreemptStatus TRANSIENT_FAIL_PINNED_CRITICAL_SECTION

Transient failure: continuation pinned due to a held CS

TRANSIENT_FAIL_PINNED_NATIVEback to summary
public static final Continuation.PreemptStatus TRANSIENT_FAIL_PINNED_NATIVE

Transient failure: continuation pinned due to native frame

Constructor Detail

PreemptStatusback to summary
private PreemptStatus(Continuation.Pinned reason)

Method Detail

pinnedback to summary
public Continuation.Pinned pinned()

Whether or not the continuation is pinned.

Returns:Continuation.Pinned

whether or not the continuation is pinned

valueOfback to summary
public static Continuation.PreemptStatus valueOf(String name)
valuesback to summary
public static Continuation.PreemptStatus[] values()