Skip to content

Commit

Permalink
[GR-8804] Better error reporting for NoAllocationVerifier.
Browse files Browse the repository at this point in the history
PullRequest: graal/1173
  • Loading branch information
Christian Wimmer committed Mar 26, 2018
2 parents ac78c6f + 5437eee commit 4d4082d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ public boolean isAllocationDisallowed() {

/** A guard to place before an allocation, giving the call site and the allocation type. */
static void exitIfAllocationDisallowed(final String callSite, final String typeName) {
NoAllocationVerifier.DisallowedAllocationError.exitIf(HeapImpl.getHeapImpl().isAllocationDisallowed(), callSite, typeName);
if (HeapImpl.getHeapImpl().isAllocationDisallowed()) {
NoAllocationVerifier.exit(callSite, typeName);
}
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import com.oracle.svm.core.annotate.NeverInline;
import com.oracle.svm.core.log.Log;
import com.oracle.svm.core.stack.ThreadStackPrinter;
import com.oracle.svm.core.threadlocal.FastThreadLocalFactory;
import com.oracle.svm.core.threadlocal.FastThreadLocalObject;
import com.oracle.svm.core.util.VMError;
Expand All @@ -42,36 +41,21 @@
*/
public class NoAllocationVerifier implements AutoCloseable {

/**
* Throw one of these to signal that allocation is disallowed. Since we cannot allocate the
* error (remember that allocation is disallowed) region), we have a pre-allocated singleton
* available.
*/
public static final class DisallowedAllocationError extends Error {

/** A guard to place before an allocation, giving the call site and the allocation type. */
public static void exitIf(final boolean state, final String callSite, final String typeName) {
if (state) {
// Throw an error to capture the stack backtrace.
Log.log().string("[NoAllocationVerifier.DisallowedAllocationError: ").string(callSite).string(": ").string(typeName).newline();
ThreadStackPrinter.printBacktrace();
Log.log().string("]").newline();
NoAllocationVerifier.logReasons(Log.log());
throw DisallowedAllocationError.SINGLETON;
}
return;
}
public static final String ERROR_MSG = "Attempt to allocate while allocation was explicitly disabled using a NoAllocationVerifier";

/** A singleton instance. */
private static final DisallowedAllocationError SINGLETON = new DisallowedAllocationError();

/** A private constructor because there is only the singleton instance. */
private DisallowedAllocationError() {
super();
/** A guard to place before an allocation, giving the call site and the allocation type. */
public static void exit(final String callSite, final String typeName) {
Log.log().string("[NoAllocationVerifier detected disallowed allocation: ").string(callSite).string(": ").string(typeName).newline();
if (openVerifiers.get() != null) {
Log.log().string("[NoAllocationVerifier stack: ");
for (NoAllocationVerifier rest = openVerifiers.get(); rest != null; rest = rest.next) {
Log.log().newline().string(" ").string(" reason: ").string(rest.reason).newline();
}
Log.log().string("]").newline();
}
Log.log().string("]").newline();

/** Every error needs one of these. */
private static final long serialVersionUID = -4649183827933685657L;
throw VMError.shouldNotReachHere(ERROR_MSG);
}

private static final FastThreadLocalObject<NoAllocationVerifier> openVerifiers = FastThreadLocalFactory.createObject(NoAllocationVerifier.class);
Expand Down Expand Up @@ -161,14 +145,4 @@ public void close() {
Heap.getHeap().resumeAllocation();
}
}

protected static void logReasons(Log log) {
if (openVerifiers.get() != null) {
log.string("[NoAllocationVerifier stack: ");
for (NoAllocationVerifier rest = openVerifiers.get(); rest != null; rest = rest.next) {
log.newline().string(" ").string(" reason: ").string(rest.reason);
}
log.string("]").newline();
}
}
}

0 comments on commit 4d4082d

Please sign in to comment.