puniverse / quasar

Fibers, Channels and Actors for the JVM
http://docs.paralleluniverse.co/quasar/
Other
4.56k stars 574 forks source link

If Fiber.park immediately precedes a catch statement, instrumentation fails #211

Closed mikehearn closed 7 years ago

mikehearn commented 8 years ago

Bug reported by Matthew Nesbit. To reproduce, delete any results.add statement before the catch and it breaks the instrumentation:

Failed test initializationError [co.paralleluniverse.fibers.instrument.SuspendableAnnotationTest] with exception: java.lang.ClassFormatError: Illegal exception table range in class file co/paralleluniverse/fibers/instrument/SuspendableAnnotationTest java.lang.ClassFormatError: Illegal exception table range in class file co/paralleluniverse/fibers/instrument/SuspendableAnnotationTest at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:760) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)

thelastender commented 7 years ago

Yes, I have encountered this bug too. Here is a simple example:

public class B
{
    @Suspendable
    public void f()
    {
        System.out.println("f in B");
        try
        {
             Fiber.park();
        }
        catch(SuspendExecution s)
        {
             throw new AssertionError(s);
        }
    }
}

This get a exception ···java.lang.IllegalStateException: Emty try catch block handler range`` when I use java agent. Note it is a wrong spellEmty`.

When I use Ant Task to instrument, I got the same error.

If I add a line after Fiber.park(). There is no problem. Like this:

public class B
{
    @Suspendable
    public void f()
    {
        System.out.println("f in B");
        try
        {
             Fiber.park();
             System.out.println("after park...");
        }
        catch(SuspendExecution s)
        {
             throw new AssertionError(s);
        }
    }
}
circlespainter commented 7 years ago

This one seems to be triggered by exception handlers splitting around suspendable calls; this may leave some handlers empty and the verifier will complain about that (see exception_table's start_pc/end_pc here: https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.3).