- java.lang.Object
-
- java.dyn.CoroutineSupport
-
public class CoroutineSupport extends Object
Jvm entry of coroutine APIs.
-
-
Constructor Summary
Constructors Constructor Description CoroutineSupport(Thread thread)
Allocates a newCoroutineSupport
object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static boolean
checkAndThrowException(Coroutine coroutine)
check if we should throw a TenantDeath or ThreqadDeathExceptionvoid
drain()
drain all alive coroutines.static StackTraceElement[]
getCoroutineStack(long coroPtr)
this will turn on a safepoint to stop all threads.CoroutineBase
getCurrent()
boolean
isCurrent(CoroutineBase coroutine)
static boolean
isInClinit(Coroutine coroutine)
Telling if current coroutine is executing clinitstatic void
setWispBooted()
Telling jvm that wisp is ready to be used.void
symmetricStopCoroutine(Coroutine target)
yield to coroutine with lock and stop the current coroutinevoid
symmetricYieldTo(Coroutine target)
yield to coroutine with lockvoid
terminateCoroutine(Coroutine target)
terminate current coroutine and yield forwardCoroutine
threadCoroutine()
return the threadCoroutinevoid
unsafeSymmetricYieldTo(Coroutine target)
optimized version of symmetricYieldTo based on assumptions: 1. we won't simultaneously steal aCoroutine
from other threads 2. we won't switch to aCoroutine
that's being stolen 3. we won't steal a runningCoroutine
this function should only be called incom.alibaba.wisp.engine.WispTask#switchTo(WispTask, WispTask)
, we skipped unnecessary lock to improve performance.
-
-
-
Constructor Detail
-
CoroutineSupport
public CoroutineSupport(Thread thread)
Allocates a newCoroutineSupport
object.- Parameters:
thread
- the Thread
-
-
Method Detail
-
threadCoroutine
public Coroutine threadCoroutine()
return the threadCoroutine- Returns:
- threadCoroutine
-
checkAndThrowException
public static boolean checkAndThrowException(Coroutine coroutine)
check if we should throw a TenantDeath or ThreqadDeathException- Parameters:
coroutine
- the coroutine- Returns:
- if coroutine should throw exception
-
isInClinit
public static boolean isInClinit(Coroutine coroutine)
Telling if current coroutine is executing clinit- Parameters:
coroutine
- the coroutine- Returns:
- if current coroutine is executing clinit
-
drain
public void drain()
drain all alive coroutines.
-
unsafeSymmetricYieldTo
public void unsafeSymmetricYieldTo(Coroutine target)
optimized version of symmetricYieldTo based on assumptions: 1. we won't simultaneously steal aCoroutine
from other threads 2. we won't switch to aCoroutine
that's being stolen 3. we won't steal a runningCoroutine
this function should only be called incom.alibaba.wisp.engine.WispTask#switchTo(WispTask, WispTask)
, we skipped unnecessary lock to improve performance.- Parameters:
target
- coroutine
-
symmetricYieldTo
public void symmetricYieldTo(Coroutine target)
yield to coroutine with lock- Parameters:
target
- coroutine
-
symmetricStopCoroutine
public void symmetricStopCoroutine(Coroutine target)
yield to coroutine with lock and stop the current coroutine- Parameters:
target
- coroutine
-
terminateCoroutine
public void terminateCoroutine(Coroutine target)
terminate current coroutine and yield forward- Parameters:
target
- target
-
isCurrent
public boolean isCurrent(CoroutineBase coroutine)
- Parameters:
coroutine
- the coroutine- Returns:
- whether the coroutine is current coroutine
-
getCurrent
public CoroutineBase getCurrent()
- Returns:
- current running coroutine
-
setWispBooted
public static void setWispBooted()
Telling jvm that wisp is ready to be used.
-
getCoroutineStack
public static StackTraceElement[] getCoroutineStack(long coroPtr)
this will turn on a safepoint to stop all threads.- Parameters:
coroPtr
- coroutine- Returns:
- target coroutine's stack
-
-