Search in sources :

Example 1 with Call

use of jdk.vm.ci.code.site.Call 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 2 with Call

use of jdk.vm.ci.code.site.Call 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 3 with Call

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

the class InstanceOfTest method test10.

@Test
public void test10() {
    Call callAt63 = new Call(null, 63, 5, true, null);
    Mark markAt63 = new Mark(63, "1");
    test("compareSites", callAt63, callAt63);
    test("compareSites", callAt63, markAt63);
    test("compareSites", markAt63, callAt63);
    test("compareSites", markAt63, markAt63);
}
Also used : Call(jdk.vm.ci.code.site.Call) Mark(jdk.vm.ci.code.site.Mark) Test(org.junit.Test)

Example 4 with Call

use of jdk.vm.ci.code.site.Call 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 Call

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

the class CompilationResult method recordCall.

/**
 * Records a call in the code array.
 *
 * @param codePos the position of the call in the code array
 * @param size the size of the call instruction
 * @param target the being called
 * @param debugInfo the debug info for the call
 * @param direct specifies if this is a {@linkplain Call#direct direct} call
 */
public void recordCall(int codePos, int size, InvokeTarget target, DebugInfo debugInfo, boolean direct) {
    checkOpen();
    final Call call = new Call(target, codePos, size, direct, debugInfo);
    addInfopoint(call);
}
Also used : Call(jdk.vm.ci.code.site.Call)

Aggregations

Call (jdk.vm.ci.code.site.Call)11 Infopoint (jdk.vm.ci.code.site.Infopoint)9 DeoptEntryInfopoint (com.oracle.svm.core.deopt.DeoptEntryInfopoint)4 CompilationResult (org.graalvm.compiler.code.CompilationResult)4 HostedMethod (com.oracle.svm.hosted.meta.HostedMethod)3 HashMap (java.util.HashMap)3 BytecodeFrame (jdk.vm.ci.code.BytecodeFrame)3 DataPatch (jdk.vm.ci.code.site.DataPatch)3 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 DebugInfo (jdk.vm.ci.code.DebugInfo)2 Backend (org.graalvm.compiler.core.target.Backend)2 DebugContext (org.graalvm.compiler.debug.DebugContext)2 GraalError (org.graalvm.compiler.debug.GraalError)2 Indent (org.graalvm.compiler.debug.Indent)2 LIRSuites (org.graalvm.compiler.lir.phases.LIRSuites)2 Suites (org.graalvm.compiler.phases.tiers.Suites)2 Purpose (com.oracle.graal.pointsto.infrastructure.GraphProvider.Purpose)1 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)1 SubstrateIntrinsicGraphBuilder (com.oracle.graal.pointsto.phases.SubstrateIntrinsicGraphBuilder)1