Module java.base
Package java.dyn

Class CoroutineSupport


  • public class CoroutineSupport
    extends Object
    Jvm entry of coroutine APIs.
    • Constructor Detail

      • CoroutineSupport

        public CoroutineSupport​(Thread thread)
        Allocates a new CoroutineSupport 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 a Coroutine from other threads 2. we won't switch to a Coroutine that's being stolen 3. we won't steal a running Coroutine this function should only be called in com.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