use of org.graalvm.compiler.debug.GraalError in project graal by oracle.
the class CompileQueue method defaultCompileFunction.
@SuppressWarnings("try")
private CompilationResult defaultCompileFunction(DebugContext debug, HostedMethod method, CompilationIdentifier compilationIdentifier, CompileReason reason, RuntimeConfiguration config) {
if (NativeImageOptions.PrintAOTCompilation.getValue()) {
System.out.println("Compiling " + method.format("%r %H.%n(%p)") + " [" + reason + "]");
}
Backend backend = config.lookupBackend(method);
StructuredGraph graph = method.compilationInfo.graph;
assert graph != null : method;
/* Operate on a copy, to keep the original graph intact for later inlining. */
graph = graph.copyWithIdentifier(compilationIdentifier, debug);
/* Check that graph is in good shape before compilation. */
assert GraphOrder.assertSchedulableGraph(graph);
try (DebugContext.Scope s = debug.scope("Compiling", graph, method, this)) {
if (deoptimizeAll && method.compilationInfo.canDeoptForTesting) {
insertDeoptTests(method, graph);
}
method.compilationInfo.numNodesBeforeCompilation = graph.getNodeCount();
method.compilationInfo.numDeoptEntryPoints = graph.getNodes().filter(DeoptEntryNode.class).count();
method.compilationInfo.numDuringCallEntryPoints = graph.getNodes(MethodCallTargetNode.TYPE).snapshot().stream().map(MethodCallTargetNode::invoke).filter(invoke -> method.compilationInfo.isDeoptEntry(invoke.bci(), true, false)).count();
Suites suites = method.compilationInfo.isDeoptTarget() ? deoptTargetSuites : regularSuites;
LIRSuites lirSuites = method.compilationInfo.isDeoptTarget() ? deoptTargetLIRSuites : regularLIRSuites;
CompilationResult result = new CompilationResult(compilationIdentifier, method.format("%H.%n(%p)")) {
@Override
public void close() {
/*
* Do nothing, we do not want our CompilationResult to be closed because we
* aggregate all data items and machine code in the native image heap.
*/
}
};
try (Indent indent = debug.logAndIndent("compile %s", method)) {
GraalCompiler.compileGraph(graph, method, backend.getProviders(), backend, null, optimisticOpts, method.getProfilingInfo(), suites, lirSuites, result, new HostedCompilationResultBuilderFactory());
}
method.getProfilingInfo().setCompilerIRSize(StructuredGraph.class, method.compilationInfo.graph.getNodeCount());
method.compilationInfo.numNodesAfterCompilation = graph.getNodeCount();
if (method.compilationInfo.isDeoptTarget()) {
assert verifyDeoptTarget(method, result);
}
for (Infopoint infopoint : result.getInfopoints()) {
if (infopoint instanceof Call) {
Call call = (Call) infopoint;
HostedMethod callTarget = (HostedMethod) call.target;
if (call.direct) {
ensureCompiled(callTarget, new DirectCallReason(method, reason));
} else if (callTarget != null && callTarget.getImplementations() != null) {
for (HostedMethod impl : callTarget.getImplementations()) {
ensureCompiled(impl, new VirtualCallReason(method, callTarget, reason));
}
}
}
}
/* Shrink resulting code array to minimum size, to reduze memory footprint. */
if (result.getTargetCode().length > result.getTargetCodeSize()) {
result.setTargetCode(Arrays.copyOf(result.getTargetCode(), result.getTargetCodeSize()), result.getTargetCodeSize());
}
return result;
} catch (Throwable ex) {
GraalError error = ex instanceof GraalError ? (GraalError) ex : new GraalError(ex);
error.addContext("method: " + method.format("%r %H.%n(%p)") + " [" + reason + "]");
throw error;
}
}
use of org.graalvm.compiler.debug.GraalError in project graal by oracle.
the class CompileQueue method doInlineTrivial.
@SuppressWarnings("try")
private void doInlineTrivial(DebugContext debug, final HostedMethod method) {
/*
* Make a copy of the graph to avoid concurrency problems. Graph manipulations are not
* thread safe, and another thread can concurrently inline this method.
*/
final StructuredGraph graph = (StructuredGraph) method.compilationInfo.getGraph().copy(debug);
try (DebugContext.Scope s = debug.scope("InlineTrivial", graph, method, this)) {
try {
try (Indent in = debug.logAndIndent("do inline trivial in %s", method)) {
boolean inlined = false;
for (Invoke invoke : graph.getInvokes()) {
if (invoke.useForInlining()) {
inlined |= tryInlineTrivial(graph, invoke, !inlined);
}
}
if (inlined) {
Providers providers = runtimeConfig.lookupBackend(method).getProviders();
new CanonicalizerPhase().apply(graph, new PhaseContext(providers));
/*
* Publish the new graph, it can be picked up immediately by other threads
* trying to inline this method.
*/
method.compilationInfo.setGraph(graph);
checkTrivial(method);
inliningProgress = true;
}
}
} catch (Throwable ex) {
GraalError error = ex instanceof GraalError ? (GraalError) ex : new GraalError(ex);
error.addContext("method: " + method.format("%r %H.%n(%p)"));
throw error;
}
} catch (Throwable e) {
throw debug.handle(e);
}
}
use of org.graalvm.compiler.debug.GraalError in project graal by oracle.
the class SPARCBranchBailoutTest method testBailoutOnBranchOverflow.
@SuppressWarnings("try")
@Test
public void testBailoutOnBranchOverflow() throws Throwable {
Assume.assumeTrue(getBackend().getTarget().arch instanceof SPARC);
ResolvedJavaMethod m = getResolvedJavaMethod("testBranch");
DebugContext debug = getDebugContext();
try {
try (Scope s = debug.disable()) {
StructuredGraph graph = parseEager(m, AllowAssumptions.YES, debug);
compile(m, graph);
}
} catch (GraalError e) {
Assert.assertEquals(PermanentBailoutException.class, e.getCause().getClass());
}
}
use of org.graalvm.compiler.debug.GraalError in project graal by oracle.
the class MatchProcessor method processMatchableNode.
private void processMatchableNode(Element element, TypeElement topDeclaringType, MatchableNode matchable, AnnotationMirror mirror) throws GraalError {
logMessage("processMatchableNode %s %s %s\n", topDeclaringType, element, matchable);
String nodeClass;
String nodePackage;
TypeMirror nodeClassMirror = null;
try {
matchable.nodeClass();
} catch (MirroredTypeException e) {
nodeClassMirror = e.getTypeMirror();
}
if (nodeClassMirror == null) {
throw new GraalError("Can't get mirror for node class %s", element);
}
if (nodeClassMirror.toString().equals(MatchableNode.class.getName())) {
nodeClass = topDeclaringType.getQualifiedName().toString();
} else {
nodeClass = nodeClassMirror.toString();
}
TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(nodeClass);
if (typeElement == null) {
errorMessage(element, mirror, "Class \"%s\" cannot be resolved to a type", nodeClass);
return;
}
nodePackage = findPackage(typeElement);
assert nodeClass.startsWith(nodePackage);
nodeClass = nodeClass.substring(nodePackage.length() + 1);
assert nodeClass.endsWith("Node");
String shortName = nodeClass.substring(0, nodeClass.length() - 4);
Types typeUtils = processingEnv.getTypeUtils();
TypeElement nodeClassElement = (TypeElement) typeUtils.asElement(nodeClassMirror);
for (String input : matchable.inputs()) {
boolean ok = false;
TypeElement current = nodeClassElement;
while (!ok && current != null) {
for (Element fieldElement : ElementFilter.fieldsIn(current.getEnclosedElements())) {
if (fieldElement.getSimpleName().toString().equals(input)) {
ok = true;
break;
}
}
TypeMirror theSuper = current.getSuperclass();
current = (TypeElement) typeUtils.asElement(theSuper);
}
if (!ok) {
errorMessage(element, mirror, "Input named \"%s\" doesn't exist in %s", input, nodeClassElement.getSimpleName());
}
}
declareType(nodeClassMirror, shortName, nodeClass, nodePackage, matchable.inputs(), matchable.commutative(), matchable.shareable(), element);
}
use of org.graalvm.compiler.debug.GraalError in project graal by oracle.
the class HotSpotGraalConstantFieldProvider method isEmbeddableField.
protected boolean isEmbeddableField(ResolvedJavaField field) {
if (nonEmbeddableFields == null) {
synchronized (this) {
if (nonEmbeddableFields == null) {
List<ResolvedJavaField> fields = new ArrayList<>();
try {
fields.add(metaAccess.lookupJavaField(Boolean.class.getDeclaredField("TRUE")));
fields.add(metaAccess.lookupJavaField(Boolean.class.getDeclaredField("FALSE")));
Class<?> characterCacheClass = Character.class.getDeclaredClasses()[0];
assert "java.lang.Character$CharacterCache".equals(characterCacheClass.getName());
fields.add(metaAccess.lookupJavaField(characterCacheClass.getDeclaredField("cache")));
Class<?> byteCacheClass = Byte.class.getDeclaredClasses()[0];
assert "java.lang.Byte$ByteCache".equals(byteCacheClass.getName());
fields.add(metaAccess.lookupJavaField(byteCacheClass.getDeclaredField("cache")));
Class<?> shortCacheClass = Short.class.getDeclaredClasses()[0];
assert "java.lang.Short$ShortCache".equals(shortCacheClass.getName());
fields.add(metaAccess.lookupJavaField(shortCacheClass.getDeclaredField("cache")));
Class<?> integerCacheClass = Integer.class.getDeclaredClasses()[0];
assert "java.lang.Integer$IntegerCache".equals(integerCacheClass.getName());
fields.add(metaAccess.lookupJavaField(integerCacheClass.getDeclaredField("cache")));
Class<?> longCacheClass = Long.class.getDeclaredClasses()[0];
assert "java.lang.Long$LongCache".equals(longCacheClass.getName());
fields.add(metaAccess.lookupJavaField(longCacheClass.getDeclaredField("cache")));
fields.add(metaAccess.lookupJavaField(Throwable.class.getDeclaredField("UNASSIGNED_STACK")));
fields.add(metaAccess.lookupJavaField(Throwable.class.getDeclaredField("SUPPRESSED_SENTINEL")));
} catch (SecurityException | NoSuchFieldException e) {
throw new GraalError(e);
}
nonEmbeddableFields = fields;
}
}
}
return !nonEmbeddableFields.contains(field);
}
Aggregations