Search in sources :

Example 1 with Infopoint

use of jdk.vm.ci.code.site.Infopoint in project graal by oracle.

the class InfopointReasonTest method lineInfopoints.

@Test
public void lineInfopoints() {
    final ResolvedJavaMethod method = getResolvedJavaMethod("testMethod");
    final StructuredGraph graph = parse(builder(method, AllowAssumptions.ifTrue(OptAssumptions.getValue(getInitialOptions()))), getDebugGraphBuilderSuite());
    int graphLineSPs = 0;
    for (FullInfopointNode ipn : graph.getNodes().filter(FullInfopointNode.class)) {
        if (ipn.getReason() == InfopointReason.BYTECODE_POSITION) {
            ++graphLineSPs;
        }
    }
    assertTrue(graphLineSPs > 0);
    PhaseSuite<HighTierContext> graphBuilderSuite = getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withFullInfopoints(true));
    final CompilationResult cr = compileGraph(graph, graph.method(), getProviders(), getBackend(), graphBuilderSuite, OptimisticOptimizations.ALL, graph.getProfilingInfo(), createSuites(graph.getOptions()), createLIRSuites(graph.getOptions()), new CompilationResult(graph.compilationId()), CompilationResultBuilderFactory.Default);
    int lineSPs = 0;
    for (Infopoint sp : cr.getInfopoints()) {
        assertNotNull(sp.reason);
        if (sp.reason == InfopointReason.BYTECODE_POSITION) {
            ++lineSPs;
        }
    }
    assertTrue(lineSPs > 0);
}
Also used : FullInfopointNode(org.graalvm.compiler.nodes.FullInfopointNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Infopoint(jdk.vm.ci.code.site.Infopoint) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) CompilationResult(org.graalvm.compiler.code.CompilationResult) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Infopoint(jdk.vm.ci.code.site.Infopoint) Test(org.junit.Test)

Example 2 with Infopoint

use of jdk.vm.ci.code.site.Infopoint in project graal by oracle.

the class Stub method checkStubInvariants.

/**
 * Checks the conditions a compilation must satisfy to be installed as a RuntimeStub.
 */
private boolean checkStubInvariants(CompilationResult compResult) {
    assert compResult.getExceptionHandlers().isEmpty() : this;
    // assumptions and there is no point in recording evol_method dependencies
    assert compResult.getAssumptions() == null : "stubs should not use assumptions: " + this;
    for (DataPatch data : compResult.getDataPatches()) {
        if (data.reference instanceof ConstantReference) {
            ConstantReference ref = (ConstantReference) data.reference;
            if (ref.getConstant() instanceof HotSpotMetaspaceConstant) {
                HotSpotMetaspaceConstant c = (HotSpotMetaspaceConstant) ref.getConstant();
                if (c.asResolvedJavaType() != null && c.asResolvedJavaType().getName().equals("[I")) {
                    // embedding the type '[I' is safe, since it is never unloaded
                    continue;
                }
            }
        }
        assert !(data.reference instanceof ConstantReference) : this + " cannot have embedded object or metadata constant: " + data.reference;
    }
    for (Infopoint infopoint : compResult.getInfopoints()) {
        assert infopoint instanceof Call : this + " cannot have non-call infopoint: " + infopoint;
        Call call = (Call) infopoint;
        assert call.target instanceof HotSpotForeignCallLinkage : this + " cannot have non runtime call: " + call.target;
        HotSpotForeignCallLinkage callLinkage = (HotSpotForeignCallLinkage) call.target;
        assert !callLinkage.isCompiledStub() || callLinkage.getDescriptor().equals(UNCOMMON_TRAP_HANDLER) : this + " cannot call compiled stub " + callLinkage;
    }
    return true;
}
Also used : Call(jdk.vm.ci.code.site.Call) ConstantReference(jdk.vm.ci.code.site.ConstantReference) DataPatch(jdk.vm.ci.code.site.DataPatch) HotSpotForeignCallLinkage(org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage) Infopoint(jdk.vm.ci.code.site.Infopoint) HotSpotMetaspaceConstant(jdk.vm.ci.hotspot.HotSpotMetaspaceConstant)

Example 3 with Infopoint

use of jdk.vm.ci.code.site.Infopoint in project graal by oracle.

the class InstalledCodeBuilder method patchCalls.

private int patchCalls(AMD64InstructionPatcher patcher) {
    /*
         * Patch the direct call instructions. TODO: This is highly x64 specific. Should be
         * rewritten to generic backends.
         */
    Map<Long, Integer> directTargets = new HashMap<>();
    int currentPos = codeSize;
    for (Infopoint infopoint : compilation.getInfopoints()) {
        if (infopoint instanceof Call && ((Call) infopoint).direct) {
            Call call = (Call) infopoint;
            long targetAddress = getTargetCodeAddress(call);
            long pcDisplacement = targetAddress - (code.rawValue() + call.pcOffset);
            if (pcDisplacement != (int) pcDisplacement || testTrampolineJumps) {
                /*
                     * In case a trampoline jump is need we just "call" the trampoline jump at the
                     * end of the code.
                     */
                Long destAddr = Long.valueOf(targetAddress);
                Integer trampolineOffset = directTargets.get(destAddr);
                if (trampolineOffset == null) {
                    trampolineOffset = currentPos;
                    directTargets.put(destAddr, trampolineOffset);
                    currentPos += TRAMPOLINE_JUMP_SIZE;
                }
                pcDisplacement = trampolineOffset - call.pcOffset;
            }
            assert pcDisplacement == (int) pcDisplacement;
            // Patch a PC-relative call.
            patcher.findPatchData(call.pcOffset, (int) pcDisplacement).apply(compiledBytes);
        }
    }
    if (directTargets.size() > 0) {
        /*
             * Insert trampoline jumps. Note that this is only a fail-safe, because usually the code
             * should be within a 32-bit address range.
             */
        currentPos = ObjectLayout.roundUp(currentPos, 8);
        ByteBuffer codeBuffer = ByteBuffer.wrap(compiledBytes).order(ConfigurationValues.getTarget().arch.getByteOrder());
        for (Entry<Long, Integer> entry : directTargets.entrySet()) {
            long targetAddress = entry.getKey();
            int trampolineOffset = entry.getValue();
            // Write the "jmp [rip+offset]" instruction
            codeBuffer.put(trampolineOffset + 0, (byte) 0xff);
            codeBuffer.put(trampolineOffset + 1, (byte) 0x25);
            codeBuffer.putInt(trampolineOffset + 2, currentPos - (trampolineOffset + TRAMPOLINE_JUMP_SIZE));
            // Write the target address
            codeBuffer.putLong(currentPos, targetAddress);
            currentPos += 8;
        }
    }
    return currentPos;
}
Also used : Call(jdk.vm.ci.code.site.Call) HashMap(java.util.HashMap) Infopoint(jdk.vm.ci.code.site.Infopoint) ByteBuffer(java.nio.ByteBuffer) Infopoint(jdk.vm.ci.code.site.Infopoint)

Example 4 with Infopoint

use of jdk.vm.ci.code.site.Infopoint in project graal by oracle.

the class HotSpotMonitorValueTest method addMethod.

@Override
protected InstalledCode addMethod(DebugContext debug, ResolvedJavaMethod method, CompilationResult compResult) {
    for (Infopoint i : compResult.getInfopoints()) {
        if (i instanceof Call) {
            Call call = (Call) i;
            if (call.target instanceof ResolvedJavaMethod) {
                ResolvedJavaMethod target = (ResolvedJavaMethod) call.target;
                if (target.equals(lookupObjectWait())) {
                    BytecodeFrame frame = call.debugInfo.frame();
                    BytecodeFrame caller = frame.caller();
                    assertNotNull(caller);
                    assertNull(caller.caller());
                    assertDeepEquals(2, frame.numLocks);
                    assertDeepEquals(2, caller.numLocks);
                    StackLockValue lock1 = (StackLockValue) frame.getLockValue(0);
                    StackLockValue lock2 = (StackLockValue) frame.getLockValue(1);
                    StackLockValue lock3 = (StackLockValue) caller.getLockValue(0);
                    StackLockValue lock4 = (StackLockValue) caller.getLockValue(1);
                    List<StackLockValue> locks = Arrays.asList(lock1, lock2, lock3, lock4);
                    for (StackLockValue lock : locks) {
                        for (StackLockValue other : locks) {
                            if (other != lock) {
                                // Every lock must have a different stack slot
                                assertThat(lock.getSlot(), not(other.getSlot()));
                            }
                        }
                    }
                    assertDeepEquals(lock3.getOwner(), lock4.getOwner());
                    assertThat(lock1.getOwner(), not(lock2.getOwner()));
                    return super.addMethod(debug, method, compResult);
                }
            }
        }
    }
    throw new AssertionError("Could not find debug info for call to Object.wait(long)");
}
Also used : Call(jdk.vm.ci.code.site.Call) BytecodeFrame(jdk.vm.ci.code.BytecodeFrame) StackLockValue(jdk.vm.ci.code.StackLockValue) Infopoint(jdk.vm.ci.code.site.Infopoint) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 5 with Infopoint

use of jdk.vm.ci.code.site.Infopoint in project graal by oracle.

the class CollectingObjectReferenceVisitor method addMethod.

public void addMethod(SharedMethod method, CompilationResult compilation, int compilationOffset) {
    int totalFrameSize = compilation.getTotalFrameSize();
    /* Mark the method start and register the frame size. */
    IPData startEntry = makeEntry(compilationOffset);
    startEntry.frameSizeEncoding = encodeFrameSize(totalFrameSize, true);
    /* Register the frame size for all entries that are starting points for the index. */
    long entryIP = CodeInfoDecoder.lookupEntryIP(CodeInfoDecoder.indexGranularity() + compilationOffset);
    while (entryIP <= CodeInfoDecoder.lookupEntryIP(compilation.getTargetCodeSize() + compilationOffset)) {
        IPData entry = makeEntry(entryIP);
        entry.frameSizeEncoding = encodeFrameSize(totalFrameSize, false);
        entryIP += CodeInfoDecoder.indexGranularity();
    }
    /* Make entries for all calls and deoptimization entry points of the method. */
    for (Infopoint infopoint : compilation.getInfopoints()) {
        final DebugInfo debugInfo = infopoint.debugInfo;
        if (debugInfo != null) {
            final int offset = getEntryOffset(infopoint);
            if (offset >= 0) {
                IPData entry = makeEntry(offset + compilationOffset);
                assert entry.referenceMap == null && entry.frameData == null;
                entry.referenceMap = (ReferenceMapEncoder.Input) debugInfo.getReferenceMap();
                entry.frameData = frameInfoEncoder.addDebugInfo(method, infopoint, totalFrameSize);
            }
        }
    }
    /* Make entries for all exception handlers. */
    for (ExceptionHandler handler : compilation.getExceptionHandlers()) {
        final IPData entry = makeEntry(handler.pcOffset + compilationOffset);
        assert entry.exceptionOffset == 0;
        entry.exceptionOffset = handler.handlerPos - handler.pcOffset;
    }
    ImageSingletons.lookup(Counters.class).methodCount.inc();
    ImageSingletons.lookup(Counters.class).codeSize.add(compilation.getTargetCodeSize());
}
Also used : ExceptionHandler(jdk.vm.ci.code.site.ExceptionHandler) ReferenceMapEncoder(com.oracle.svm.core.heap.ReferenceMapEncoder) Infopoint(jdk.vm.ci.code.site.Infopoint) DeoptEntryInfopoint(com.oracle.svm.core.deopt.DeoptEntryInfopoint) DebugInfo(jdk.vm.ci.code.DebugInfo) Infopoint(jdk.vm.ci.code.site.Infopoint) DeoptEntryInfopoint(com.oracle.svm.core.deopt.DeoptEntryInfopoint)

Aggregations

Infopoint (jdk.vm.ci.code.site.Infopoint)13 Call (jdk.vm.ci.code.site.Call)8 DeoptEntryInfopoint (com.oracle.svm.core.deopt.DeoptEntryInfopoint)6 CompilationResult (org.graalvm.compiler.code.CompilationResult)5 DebugInfo (jdk.vm.ci.code.DebugInfo)3 DataPatch (jdk.vm.ci.code.site.DataPatch)3 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)3 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)3 ReferenceMapEncoder (com.oracle.svm.core.heap.ReferenceMapEncoder)2 HostedMethod (com.oracle.svm.hosted.meta.HostedMethod)2 HashMap (java.util.HashMap)2 BytecodeFrame (jdk.vm.ci.code.BytecodeFrame)2 ExceptionHandler (jdk.vm.ci.code.site.ExceptionHandler)2 Test (org.junit.Test)2 AMD64InstructionPatcher (com.oracle.svm.core.graal.code.amd64.AMD64InstructionPatcher)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 DefaultRefMapFormatter (jdk.vm.ci.code.CodeUtil.DefaultRefMapFormatter)1