Skip to content

Commit

Permalink
🐛 Fix #255
Browse files Browse the repository at this point in the history
  • Loading branch information
circlespainter committed Apr 3, 2017
1 parent cf96710 commit a3a3702
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static Pair<Boolean, Instrumented> isCallSiteInstrumented(/*Executable*/
}
if (callsiteOwner != null) {
final Class<?> owner = callee.getDeclaringClass();
if (callsiteOwner.isAssignableFrom(owner)) {
if (declareInCommonAncestor(nameAndDescSuffix, owner, callsiteOwner)) {
ok = true;
break;
}
Expand Down Expand Up @@ -138,6 +138,54 @@ else if (sourceLine >= 0){
}
}

private static boolean declareInCommonAncestor(String nameAndDescSuffix, Class<?> c1, Class<?> c2) {
if (nameAndDescSuffix == null || c1 == null || c2 == null)
return false;

if (c1.isAssignableFrom(c2))
return hasMethodWithDescriptor(nameAndDescSuffix, c1);

if (c2.isAssignableFrom(c1))
return hasMethodWithDescriptor(nameAndDescSuffix, c2);

return
declareInCommonAncestor(nameAndDescSuffix, c1.getSuperclass(), c2) ||
declareInCommonAncestor(nameAndDescSuffix, c1.getInterfaces(), c2);
}

private static boolean hasMethodWithDescriptor(String nameAndDescSuffix, Class<?> c) {
if (nameAndDescSuffix == null || c == null)
return false;

for (final Method m : c.getDeclaredMethods()) {
final String n = "." + m.getName() + ASMUtil.getDescriptor(m);
if (nameAndDescSuffix.equals(n))
return true;
}

if (hasMethodWithDescriptor(nameAndDescSuffix, c.getSuperclass()))
return true;

for (final Class<?> i : c.getInterfaces()) {
if (hasMethodWithDescriptor(nameAndDescSuffix, i))
return true;
}

return false;
}

private static boolean declareInCommonAncestor(String nameAndDescSuffix, Class<?>[] c1s, Class<?> c2) {
if (nameAndDescSuffix == null || c1s == null || c2 == null)
return false;

for (final Class<?> c1 : c1s) {
if (declareInCommonAncestor(nameAndDescSuffix, c1, c2))
return true;
}

return false;
}

public static String getCallsiteOwner(String callsiteName) {
return callsiteName.substring(0, callsiteName.indexOf('.')).replace('/', '.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@
import co.paralleluniverse.strands.SuspendableCallable;
import co.paralleluniverse.strands.SuspendableRunnable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import static org.junit.Assert.*;
import static org.junit.Assume.*;

import co.paralleluniverse.strands.channels.Channels;
import co.paralleluniverse.strands.channels.IntChannel;
import org.junit.Test;

/**
Expand Down Expand Up @@ -238,4 +244,22 @@ public final void testVerificationOK() throws ExecutionException, InterruptedExc
}}).start();
assertEquals(fOk.get(), new Integer(4));
}

@Test
public final void testVerifyUninstrumentedCallSiteDeclaringAndOwnerOK() throws ExecutionException, InterruptedException, SuspendExecution {
assumeTrue(SystemProperties.isEmptyOrTrue("co.paralleluniverse.fibers.verifyInstrumentation"));

// From https://github.com/puniverse/quasar/issues/255
final IntChannel intChannel = Channels.newIntChannel(1);
try {
new Fiber<>(new SuspendableCallable<Integer>() {
@Override
public Integer run() throws SuspendExecution, InterruptedException {
return intChannel.receive();
}
}).start().join(100, TimeUnit.MILLISECONDS);
} catch (final TimeoutException ignored) {
}
// Should complete without verification exceptions
}
}

0 comments on commit a3a3702

Please sign in to comment.