Search in sources :

Example 26 with GraalError

use of org.graalvm.compiler.debug.GraalError in project graal by oracle.

the class GraalOSRTestBase method compile.

protected static void compile(DebugContext debug, ResolvedJavaMethod method, int bci) {
    HotSpotJVMCIRuntimeProvider runtime = HotSpotJVMCIRuntime.runtime();
    long jvmciEnv = 0L;
    HotSpotCompilationRequest request = new HotSpotCompilationRequest((HotSpotResolvedJavaMethod) method, bci, jvmciEnv);
    HotSpotGraalCompiler compiler = (HotSpotGraalCompiler) runtime.getCompiler();
    CompilationTask task = new CompilationTask(runtime, compiler, request, true, true, debug.getOptions());
    if (method instanceof HotSpotResolvedJavaMethod) {
        HotSpotGraalRuntimeProvider graalRuntime = compiler.getGraalRuntime();
        GraalHotSpotVMConfig config = graalRuntime.getVMConfig();
        if (((HotSpotResolvedJavaMethod) method).hasCodeAtLevel(bci, config.compilationLevelFullOptimization)) {
            return;
        }
    }
    HotSpotCompilationRequestResult result = task.runCompilation(debug);
    if (result.getFailure() != null) {
        throw new GraalError(result.getFailureMessage());
    }
}
Also used : HotSpotGraalCompiler(org.graalvm.compiler.hotspot.HotSpotGraalCompiler) HotSpotResolvedJavaMethod(jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod) GraalError(org.graalvm.compiler.debug.GraalError) HotSpotCompilationRequestResult(jdk.vm.ci.hotspot.HotSpotCompilationRequestResult) HotSpotGraalRuntimeProvider(org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider) HotSpotCompilationRequest(jdk.vm.ci.hotspot.HotSpotCompilationRequest) CompilationTask(org.graalvm.compiler.hotspot.CompilationTask) GraalHotSpotVMConfig(org.graalvm.compiler.hotspot.GraalHotSpotVMConfig) HotSpotJVMCIRuntimeProvider(jdk.vm.ci.hotspot.HotSpotJVMCIRuntimeProvider)

Example 27 with GraalError

use of org.graalvm.compiler.debug.GraalError in project graal by oracle.

the class ClassfileBytecode method getExceptionHandlers.

@Override
public ExceptionHandler[] getExceptionHandlers() {
    if (exceptionTableBytes == null) {
        return new ExceptionHandler[0];
    }
    final int exceptionTableLength = exceptionTableBytes.length / EXCEPTION_HANDLER_TABLE_SIZE_IN_BYTES;
    ExceptionHandler[] handlers = new ExceptionHandler[exceptionTableLength];
    DataInputStream stream = new DataInputStream(new ByteArrayInputStream(exceptionTableBytes));
    for (int i = 0; i < exceptionTableLength; i++) {
        try {
            final int startPc = stream.readUnsignedShort();
            final int endPc = stream.readUnsignedShort();
            final int handlerPc = stream.readUnsignedShort();
            int catchTypeIndex = stream.readUnsignedShort();
            JavaType catchType;
            if (catchTypeIndex == 0) {
                catchType = null;
            } else {
                // opcode is not used
                final int opcode = -1;
                catchType = constantPool.lookupType(catchTypeIndex, opcode);
                // Check for Throwable which catches everything.
                if (catchType.toJavaName().equals("java.lang.Throwable")) {
                    catchTypeIndex = 0;
                    catchType = null;
                }
            }
            handlers[i] = new ExceptionHandler(startPc, endPc, handlerPc, catchTypeIndex, catchType);
        } catch (IOException e) {
            throw new GraalError(e);
        }
    }
    return handlers;
}
Also used : ExceptionHandler(jdk.vm.ci.meta.ExceptionHandler) JavaType(jdk.vm.ci.meta.JavaType) GraalError(org.graalvm.compiler.debug.GraalError) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 28 with GraalError

use of org.graalvm.compiler.debug.GraalError in project graal by oracle.

the class ClassfileBytecode method getLineNumberTable.

@Override
public LineNumberTable getLineNumberTable() {
    if (lineNumberTableBytes == null) {
        return null;
    }
    final int lineNumberTableLength = lineNumberTableBytes.length / LINE_NUMBER_TABLE_ENTRY_SIZE_IN_BYTES;
    DataInputStream stream = new DataInputStream(new ByteArrayInputStream(lineNumberTableBytes));
    int[] bci = new int[lineNumberTableLength];
    int[] line = new int[lineNumberTableLength];
    for (int i = 0; i < lineNumberTableLength; i++) {
        try {
            bci[i] = stream.readUnsignedShort();
            line[i] = stream.readUnsignedShort();
        } catch (IOException e) {
            throw new GraalError(e);
        }
    }
    return new LineNumberTable(line, bci);
}
Also used : GraalError(org.graalvm.compiler.debug.GraalError) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) LineNumberTable(jdk.vm.ci.meta.LineNumberTable)

Example 29 with GraalError

use of org.graalvm.compiler.debug.GraalError in project graal by oracle.

the class ClassfileBytecode method getLocalVariableTable.

@Override
public LocalVariableTable getLocalVariableTable() {
    if (localVariableTableBytes == null) {
        return null;
    }
    final int localVariableTableLength = localVariableTableBytes.length / LOCAL_VARIABLE_TABLE_SIZE_IN_BYTES;
    DataInputStream stream = new DataInputStream(new ByteArrayInputStream(localVariableTableBytes));
    Local[] locals = new Local[localVariableTableLength];
    for (int i = 0; i < localVariableTableLength; i++) {
        try {
            final int startBci = stream.readUnsignedShort();
            final int endBci = startBci + stream.readUnsignedShort();
            final int nameCpIndex = stream.readUnsignedShort();
            final int typeCpIndex = stream.readUnsignedShort();
            final int slot = stream.readUnsignedShort();
            String localName = constantPool.lookupUtf8(nameCpIndex);
            String localType = constantPool.lookupUtf8(typeCpIndex);
            ClassfileBytecodeProvider context = constantPool.context;
            Class<?> c = context.resolveToClass(localType);
            locals[i] = new Local(localName, context.metaAccess.lookupJavaType(c), startBci, endBci, slot);
        } catch (IOException e) {
            throw new GraalError(e);
        }
    }
    return new LocalVariableTable(locals);
}
Also used : LocalVariableTable(jdk.vm.ci.meta.LocalVariableTable) GraalError(org.graalvm.compiler.debug.GraalError) ByteArrayInputStream(java.io.ByteArrayInputStream) Local(jdk.vm.ci.meta.Local) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 30 with GraalError

use of org.graalvm.compiler.debug.GraalError in project graal by oracle.

the class AbstractKnownTruffleTypes method findField.

protected ResolvedJavaField findField(ResolvedJavaType declaringClass, String name) {
    FieldsCache fc = fieldsCache;
    if (fc == null || !fc.declaringClass.equals(declaringClass)) {
        fc = new FieldsCache(declaringClass, declaringClass.getInstanceFields(false));
        fieldsCache = fc;
    }
    for (ResolvedJavaField f : fc.fields) {
        if (f.getName().equals(name)) {
            return f;
        }
    }
    throw new GraalError("Could not find required field %s.%s", declaringClass.getName(), name);
}
Also used : GraalError(org.graalvm.compiler.debug.GraalError) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Aggregations

GraalError (org.graalvm.compiler.debug.GraalError)42 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)9 ValueNode (org.graalvm.compiler.nodes.ValueNode)8 DebugContext (org.graalvm.compiler.debug.DebugContext)7 Indent (org.graalvm.compiler.debug.Indent)5 IOException (java.io.IOException)4 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)4 Node (org.graalvm.compiler.graph.Node)4 OptionValues (org.graalvm.compiler.options.OptionValues)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 DataInputStream (java.io.DataInputStream)3 ArrayList (java.util.ArrayList)3 CompilationResult (org.graalvm.compiler.code.CompilationResult)3 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)3 Invoke (org.graalvm.compiler.nodes.Invoke)3 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)3 VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)3 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)2 HostedMethod (com.oracle.svm.hosted.meta.HostedMethod)2 InstalledCode (jdk.vm.ci.code.InstalledCode)2