use of co.paralleluniverse.common.util.ExtendedStackTraceElement in project quasar by puniverse.
the class Fiber method initTrace.
private static StringBuilder initTrace(int i, ExtendedStackTraceElement[] stes) {
final StringBuilder stackTrace = new StringBuilder();
for (int j = 0; j <= i; j++) {
final ExtendedStackTraceElement ste2 = stes[j];
if (ste2.getClassName().equals(Thread.class.getName()) && ste2.getMethodName().equals("getStackTrace"))
continue;
printTraceLine(stackTrace, ste2);
}
return stackTrace;
}
use of co.paralleluniverse.common.util.ExtendedStackTraceElement in project quasar by puniverse.
the class Fiber method checkInstrumentation.
@SuppressWarnings("null")
private static boolean checkInstrumentation(ExtendedStackTrace st, boolean fromUncaughtExc) {
if (fromUncaughtExc && st.get().length > 0 && st.get()[0] != null) {
final ExtendedStackTraceElement first = st.get()[0];
if (!first.getDeclaringClass().equals(ClassCastException.class) && !(first.getDeclaringClass().equals(NullPointerException.class) && first.getDeclaringClass().getName().startsWith("co.paralleluniverse.fibers")))
return true;
}
boolean ok = true;
StringBuilder stackTrace = null;
final ExtendedStackTraceElement[] stes = st.get();
for (int i = 0; i < stes.length; i++) {
final ExtendedStackTraceElement ste = stes[i];
if (ste.getClassName().equals(Thread.class.getName()) && ste.getMethodName().equals("getStackTrace"))
continue;
if (ste.getClassName().equals(ExtendedStackTrace.class.getName()))
continue;
if (!ok)
printTraceLine(stackTrace, ste);
if (ste.getClassName().contains("$$Lambda$"))
continue;
if (!ste.getClassName().equals(Fiber.class.getName()) && !ste.getClassName().startsWith(Fiber.class.getName() + '$') && !ste.getClassName().equals(Stack.class.getName()) && !SuspendableHelper.isWaiver(ste.getClassName(), ste.getMethodName())) {
final Class<?> clazz = ste.getDeclaringClass();
final boolean classInstrumented = SuspendableHelper.isInstrumented(clazz);
final Member /*Executable*/
m = SuspendableHelper.lookupMethod(ste);
if (m != null) {
final boolean methodInstrumented = SuspendableHelper.isInstrumented(m);
final Pair<Boolean, Instrumented> callSiteInstrumented = SuspendableHelper.isCallSiteInstrumented(m, ste.getLineNumber(), ste.getBytecodeIndex(), stes, i);
if (!classInstrumented || !methodInstrumented || !callSiteInstrumented.getFirst()) {
if (ok)
stackTrace = initTrace(i, stes);
if (!classInstrumented || !methodInstrumented)
stackTrace.append(" **");
else if (!callSiteInstrumented.getFirst())
stackTrace.append(" !! (instrumented suspendable calls at: ").append(callSitesString(callSiteInstrumented.getSecond())).append(")");
ok = false;
}
} else {
if (ok)
stackTrace = initTrace(i, stes);
// Methods can only be found via source lines in @Instrumented annotations
stackTrace.append(" **");
ok = false;
}
} else if (ste.getClassName().equals(Fiber.class.getName()) && ste.getMethodName().equals("run1")) {
if (!ok) {
final String str = "Uninstrumented whole methods ('**') or single calls ('!!') detected: " + stackTrace;
if (Debug.isUnitTest())
throw new VerifyInstrumentationException(str);
System.err.println("WARNING: " + str);
}
return ok;
}
}
throw new IllegalStateException("Not run through Fiber.exec(). (trace: " + Arrays.toString(stes) + ")");
}
use of co.paralleluniverse.common.util.ExtendedStackTraceElement in project quasar by puniverse.
the class SuspendableHelper method isCallSiteInstrumented.
public static Pair<Boolean, Instrumented> isCallSiteInstrumented(/*Executable*/
Member m, int sourceLine, int bci, ExtendedStackTraceElement[] stes, int currentSteIdx) {
if (m == null)
return new Pair<>(false, null);
if (isSyntheticAndNotLambda(m))
return new Pair<>(true, null);
final ExtendedStackTraceElement calleeSte = currentSteIdx - 1 >= 0 ? stes[currentSteIdx - 1] : null;
if (calleeSte != null && // `verifySuspend` and `popMethod` calls are not suspendable call sites, not verifying them.
((calleeSte.getClassName().equals(Fiber.class.getName()) && calleeSte.getMethodName().equals("verifySuspend")) || (calleeSte.getClassName().equals(Stack.class.getName()) && calleeSte.getMethodName().equals("popMethod")))) {
return new Pair<>(true, null);
} else {
final Instrumented i = getAnnotation(m, Instrumented.class);
if (i == null)
return new Pair<>(false, i);
if (calleeSte != null && i.suspendableCallSiteNames() != null) {
// check by callsite name (fails for bootstrapped lambdas)
final Member callee = calleeSte.getMethod();
if (callee == null) {
final String methodName = "." + calleeSte.getMethodName() + "(";
for (String callsite : i.suspendableCallSiteNames()) {
if (callsite.contains(methodName)) {
return new Pair(true, i);
}
}
} else {
final String nameAndDescSuffix = "." + callee.getName() + ASMUtil.getDescriptor(callee);
final String[] callsites = i.suspendableCallSiteNames();
for (String callsite : callsites) {
if (callsite.endsWith(nameAndDescSuffix)) {
Class<?> callsiteOwner = null;
try {
callsiteOwner = Class.forName(getCallsiteOwner(callsite));
} catch (ClassNotFoundException e) {
}
if (callsiteOwner != null) {
final Class<?> owner = callee.getDeclaringClass();
if (declareInCommonAncestor(nameAndDescSuffix, owner, callsiteOwner)) {
return new Pair(true, i);
}
}
}
}
}
}
if (bci >= 0) {
// check by bci; may be brittle
final int[] scs = i.suspendableCallSitesOffsetsAfterInstr();
for (int j : scs) {
if (j == bci)
return new Pair<>(true, i);
}
} else if (sourceLine >= 0) {
// check by source line
final int[] scs = i.suspendableCallSites();
for (int j : scs) {
if (j == sourceLine)
return new Pair<>(true, i);
}
}
return new Pair<>(false, i);
}
}
Aggregations