- 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 newCoroutineSupportobject.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static booleancheckAndThrowException(Coroutine coroutine)check if we should throw a TenantDeath or ThreqadDeathExceptionvoiddrain()drain all alive coroutines.static StackTraceElement[]getCoroutineStack(long coroPtr)this will turn on a safepoint to stop all threads.CoroutineBasegetCurrent()booleanisCurrent(CoroutineBase coroutine)static booleanisInClinit(Coroutine coroutine)Telling if current coroutine is executing clinitstatic voidsetWispBooted()Telling jvm that wisp is ready to be used.voidsymmetricStopCoroutine(Coroutine target)yield to coroutine with lock and stop the current coroutinevoidsymmetricYieldTo(Coroutine target)yield to coroutine with lockvoidterminateCoroutine(Coroutine target)terminate current coroutine and yield forwardCoroutinethreadCoroutine()return the threadCoroutinevoidunsafeSymmetricYieldTo(Coroutine target)optimized version of symmetricYieldTo based on assumptions: 1. we won't simultaneously steal aCoroutinefrom other threads 2. we won't switch to aCoroutinethat's being stolen 3. we won't steal a runningCoroutinethis 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 newCoroutineSupportobject.- 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 aCoroutinefrom other threads 2. we won't switch to aCoroutinethat's being stolen 3. we won't steal a runningCoroutinethis 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
-
-