Quasar fails to instrument java.util.concurrent.FutureTask

102 views
Skip to first unread message

wang jakie

unread,
Mar 13, 2020, 5:41:49 AM3/13/20
to quasar-pulsar-user
import co.paralleluniverse.fibers.Fiber;
import co.paralleluniverse.fibers.SuspendExecution;
import co.paralleluniverse.fibers.Suspendable;
import co.paralleluniverse.strands.SuspendableRunnable;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

public class QuasarCallableDemo {

    public static void main(String[] args) throws InterruptedException{
        final Callable callable = new Callable() {
            @Override
            @Suspendable
            public Object call() throws Exception {
                Fiber.sleep(100);
                Fiber.sleep(100);
                System.out.println("run");
                return null;
            }
        };

        final FutureTask futureTask = new FutureTask(callable);
        SuspendableRunnable suspendableRunnable = new SuspendableRunnable() {
            @Override
            public void run() throws SuspendExecution, InterruptedException {
                try {
                    System.out.println("i am in");
                  //  callable.call();
                   futureTask.run();
                } catch (Exception e) {
                }
            }
        };

        new Fiber<Void>(suspendableRunnable).start();
        Thread.sleep(1000);
        System.exit(0);
    }
}

META-INF/suspendables  java.util.concurrent.FutureTask.*
META-INF/suspendables-supers  java.util.concurrent.Callable.call

My development environment is JDK11, and the VM options are -javaagent:/Users/wangdong/.m2/repository/co/paralleluniverse/quasar-core/0.8.0/quasar-core-0.8.0.jar  -Dco.paralleluniverse.fibers.verifyInstrumentation=true

when I run this demo,this error ocurrs:

WARNING: Uninstrumented whole methods ('**') or single calls ('!!') detected: 
at co.paralleluniverse.common.util.ExtendedStackTrace.here() (ExtendedStackTrace.java:46)
at co.paralleluniverse.fibers.Fiber.checkInstrumentation() (Fiber.java:1696)
at co.paralleluniverse.fibers.Fiber.verifySuspend(co.paralleluniverse.fibers.Fiber) (Fiber.java:1669)
at co.paralleluniverse.fibers.Fiber.verifySuspend() (Fiber.java:1664)
at co.paralleluniverse.fibers.Fiber.sleep(long,java.util.concurrent.TimeUnit) (Fiber.java:695)
at co.paralleluniverse.fibers.Fiber.sleep(long) (Fiber.java:687)
at com.meituan.mtthrift.test.QuasarCallableDemo$1.call() (QuasarCallableDemo.java:19)
at java.util.concurrent.FutureTask.run() (FutureTask.java:264) **
at com.meituan.mtthrift.test.QuasarCallableDemo$2.run() (QuasarCallableDemo.java:33)
at co.paralleluniverse.strands.SuspendableUtils$VoidSuspendableCallable.run() (SuspendableUtils.java:42)
at co.paralleluniverse.strands.SuspendableUtils$VoidSuspendableCallable.run() (SuspendableUtils.java:30)
at co.paralleluniverse.fibers.Fiber.run() (Fiber.java:1099)
at co.paralleluniverse.fibers.Fiber.run1() (Fiber.java:1094)
did I miss something? Please help  me!

Syed Afzal

unread,
Mar 13, 2020, 8:30:59 AM3/13/20
to quasar-pulsar-user
Hi Wang,

You should not mix thread classes with fiber classes. 

Basically you have some task in  java.util.concurrent.Callable, which is essentially a task at the thread level. When you try to run it within a new fiber, it blocks the thread which is currently running the fiber. So, the moral of the story is to use the quasar version of classes that are meant for fibers. 

Fibers can run SuspendableRunnable and SuspendableCallable. So instead of creating a Callable then wrapping it in futureTask and again wrapping in SuspendableRunnable etc etc.. Just create a SuspendableCallable, which you can simply run in a fiber.

 final SuspendableCallable callable = new SuspendableCallable() {
             
@Suspendable
             
public Object run() throws SuspendExecution, InterruptedException {

                 
Fiber.sleep(100);
                 
Fiber.sleep(100);
                 
System.out.println("run");
                 
return null;
             
}
         
};

 
new Fiber<Void>(callable).start();

By the way are you using Gradle?
Classes in META-INF/suspendables are instrumented only in AOT instrumentation which runs as ant task.


Let me know if it helped.

Cheers,
Syed
Reply all
Reply to author
Forward
0 new messages