Search in sources :

Example 1 with AMD64MacroAssembler

use of org.graalvm.compiler.asm.amd64.AMD64MacroAssembler in project graal by oracle.

the class AMD64HotSpotBackend method emitCodePrefix.

/**
 * Emits the code prior to the verified entry point.
 *
 * @param installedCodeOwner see {@link Backend#emitCode}
 */
public void emitCodePrefix(ResolvedJavaMethod installedCodeOwner, CompilationResultBuilder crb, AMD64MacroAssembler asm, RegisterConfig regConfig, Label verifiedEntry) {
    HotSpotProviders providers = getProviders();
    if (installedCodeOwner != null && !installedCodeOwner.isStatic()) {
        crb.recordMark(config.MARKID_UNVERIFIED_ENTRY);
        CallingConvention cc = regConfig.getCallingConvention(HotSpotCallingConventionType.JavaCallee, null, new JavaType[] { providers.getMetaAccess().lookupJavaType(Object.class) }, this);
        // see definition of IC_Klass in
        Register inlineCacheKlass = rax;
        // c1_LIRAssembler_x86.cpp
        Register receiver = asRegister(cc.getArgument(0));
        AMD64Address src = new AMD64Address(receiver, config.hubOffset);
        if (config.useCompressedClassPointers) {
            Register register = r10;
            AMD64HotSpotMove.decodeKlassPointer(crb, asm, register, providers.getRegisters().getHeapBaseRegister(), src, config);
            if (GeneratePIC.getValue(crb.getOptions())) {
                asm.movq(providers.getRegisters().getHeapBaseRegister(), asm.getPlaceholder(-1));
                crb.recordMark(config.MARKID_NARROW_OOP_BASE_ADDRESS);
            } else {
                if (config.narrowKlassBase != 0) {
                    // The heap base register was destroyed above, so restore it
                    asm.movq(providers.getRegisters().getHeapBaseRegister(), config.narrowOopBase);
                }
            }
            asm.cmpq(inlineCacheKlass, register);
        } else {
            asm.cmpq(inlineCacheKlass, src);
        }
        AMD64Call.directConditionalJmp(crb, asm, getForeignCalls().lookupForeignCall(IC_MISS_HANDLER), ConditionFlag.NotEqual);
    }
    asm.align(config.codeEntryAlignment);
    crb.recordMark(config.MARKID_OSR_ENTRY);
    asm.bind(verifiedEntry);
    crb.recordMark(config.MARKID_VERIFIED_ENTRY);
    if (GeneratePIC.getValue(crb.getOptions())) {
        // Check for method state
        HotSpotFrameContext frameContext = (HotSpotFrameContext) crb.frameContext;
        if (!frameContext.isStub) {
            crb.recordInlineDataInCodeWithNote(new HotSpotSentinelConstant(LIRKind.value(AMD64Kind.QWORD), JavaKind.Long), HotSpotConstantLoadAction.MAKE_NOT_ENTRANT);
            asm.movq(AMD64.rax, asm.getPlaceholder(-1));
            asm.testq(AMD64.rax, AMD64.rax);
            AMD64Call.directConditionalJmp(crb, asm, getForeignCalls().lookupForeignCall(WRONG_METHOD_HANDLER), ConditionFlag.NotZero);
        }
    }
}
Also used : CallingConvention(jdk.vm.ci.code.CallingConvention) Register(jdk.vm.ci.code.Register) ValueUtil.asRegister(jdk.vm.ci.code.ValueUtil.asRegister) HotSpotProviders(org.graalvm.compiler.hotspot.meta.HotSpotProviders) HotSpotSentinelConstant(jdk.vm.ci.hotspot.HotSpotSentinelConstant) AMD64Address(org.graalvm.compiler.asm.amd64.AMD64Address)

Example 2 with AMD64MacroAssembler

use of org.graalvm.compiler.asm.amd64.AMD64MacroAssembler in project graal by oracle.

the class AMD64HotSpotCounterOp method emitCode.

@Override
public void emitCode(CompilationResultBuilder crb) {
    AMD64MacroAssembler masm = (AMD64MacroAssembler) crb.asm;
    TargetDescription target = crb.target;
    Register scratch;
    // want to spill it to the stack.
    if (!contains(increments, rax)) {
        scratch = rax;
    } else if (!contains(increments, rbx)) {
        scratch = rbx;
    } else {
        // emitIncrement().
        throw GraalError.unimplemented("RAX and RBX are increment registers at the same time, spilling over the scratch register is not supported right now");
    }
    // address for counters array
    AMD64Address countersArrayAddr = new AMD64Address(thread, config.jvmciCountersThreadOffset);
    Register countersArrayReg = scratch;
    // backup scratch register
    masm.movq((AMD64Address) crb.asAddress(backupSlot), scratch);
    // load counters array
    masm.movptr(countersArrayReg, countersArrayAddr);
    CounterProcedure emitProcedure = (counterIndex, increment, displacement) -> emitIncrement(masm, countersArrayReg, increment, displacement);
    forEachCounter(emitProcedure, target);
    // restore scratch register
    masm.movq(scratch, (AMD64Address) crb.asAddress(backupSlot));
}
Also used : HotSpotCounterOp(org.graalvm.compiler.hotspot.HotSpotCounterOp) AMD64.rax(jdk.vm.ci.amd64.AMD64.rax) AMD64.rbx(jdk.vm.ci.amd64.AMD64.rbx) LIRValueUtil.asJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant) CompilationResultBuilder(org.graalvm.compiler.lir.asm.CompilationResultBuilder) Register(jdk.vm.ci.code.Register) LIRValueUtil.isJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant) TargetDescription(jdk.vm.ci.code.TargetDescription) Value(jdk.vm.ci.meta.Value) AMD64Address(org.graalvm.compiler.asm.amd64.AMD64Address) HotSpotRegistersProvider(org.graalvm.compiler.hotspot.meta.HotSpotRegistersProvider) ValueUtil.isRegister(jdk.vm.ci.code.ValueUtil.isRegister) Opcode(org.graalvm.compiler.lir.Opcode) GraalError(org.graalvm.compiler.debug.GraalError) ValueUtil.asRegister(jdk.vm.ci.code.ValueUtil.asRegister) GraalHotSpotVMConfig(org.graalvm.compiler.hotspot.GraalHotSpotVMConfig) AMD64MacroAssembler(org.graalvm.compiler.asm.amd64.AMD64MacroAssembler) LIRInstructionClass(org.graalvm.compiler.lir.LIRInstructionClass) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) Register(jdk.vm.ci.code.Register) ValueUtil.isRegister(jdk.vm.ci.code.ValueUtil.isRegister) ValueUtil.asRegister(jdk.vm.ci.code.ValueUtil.asRegister) AMD64MacroAssembler(org.graalvm.compiler.asm.amd64.AMD64MacroAssembler) TargetDescription(jdk.vm.ci.code.TargetDescription) AMD64Address(org.graalvm.compiler.asm.amd64.AMD64Address)

Example 3 with AMD64MacroAssembler

use of org.graalvm.compiler.asm.amd64.AMD64MacroAssembler in project graal by oracle.

the class AMD64HotSpotJumpToExceptionHandlerInCallerOp method emitCode.

@Override
public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
    leaveFrameAndRestoreRbp(crb, masm);
    // Discard the return address, thus completing restoration of caller frame
    masm.incrementq(rsp, 8);
    if (System.getProperty("java.specification.version").compareTo("1.8") < 0) {
        // Restore rsp from rbp if the exception PC is a method handle call site.
        AMD64Address dst = new AMD64Address(thread, isMethodHandleReturnOffset);
        masm.cmpl(dst, 0);
        masm.cmovq(ConditionFlag.NotEqual, rsp, rbp);
    }
    masm.jmp(asRegister(handlerInCallerPc));
}
Also used : AMD64Address(org.graalvm.compiler.asm.amd64.AMD64Address)

Example 4 with AMD64MacroAssembler

use of org.graalvm.compiler.asm.amd64.AMD64MacroAssembler in project graal by oracle.

the class AMD64HotSpotLeaveCurrentStackFrameOp method emitCode.

@Override
public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
    FrameMap frameMap = crb.frameMap;
    RegisterConfig registerConfig = frameMap.getRegisterConfig();
    RegisterSaveLayout registerSaveLayout = saveRegisterOp.getMap(frameMap);
    Register stackPointer = registerConfig.getFrameRegister();
    // Restore integer result register.
    final int stackSlotSize = frameMap.getTarget().wordSize;
    Register integerResultRegister = registerConfig.getReturnRegister(JavaKind.Long);
    masm.movptr(integerResultRegister, new AMD64Address(stackPointer, registerSaveLayout.registerToSlot(integerResultRegister) * stackSlotSize));
    masm.movptr(rdx, new AMD64Address(stackPointer, registerSaveLayout.registerToSlot(rdx) * stackSlotSize));
    // Restore float result register.
    Register floatResultRegister = registerConfig.getReturnRegister(JavaKind.Double);
    masm.movdbl(floatResultRegister, new AMD64Address(stackPointer, registerSaveLayout.registerToSlot(floatResultRegister) * stackSlotSize));
    /*
         * All of the register save area will be popped of the stack. Only the return address
         * remains.
         */
    leaveFrameAndRestoreRbp(crb, masm);
    // Remove return address.
    masm.addq(stackPointer, crb.target.arch.getReturnAddressSize());
}
Also used : RegisterConfig(jdk.vm.ci.code.RegisterConfig) FrameMap(org.graalvm.compiler.lir.framemap.FrameMap) RegisterSaveLayout(jdk.vm.ci.code.RegisterSaveLayout) Register(jdk.vm.ci.code.Register) AMD64Address(org.graalvm.compiler.asm.amd64.AMD64Address)

Example 5 with AMD64MacroAssembler

use of org.graalvm.compiler.asm.amd64.AMD64MacroAssembler in project graal by oracle.

the class AMD64HotSpotLoadConfigValueOp method emitCode.

@Override
public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
    if (GeneratePIC.getValue(crb.getOptions())) {
        AMD64Kind kind = (AMD64Kind) result.getPlatformKind();
        Register reg = asRegister(result);
        AMD64Address placeholder = masm.getPlaceholder(-1);
        switch(kind) {
            case BYTE:
                masm.movsbl(reg, placeholder);
                break;
            case WORD:
                masm.movswl(reg, placeholder);
                break;
            case DWORD:
                masm.movl(reg, placeholder);
                break;
            case QWORD:
                masm.movq(reg, placeholder);
                break;
            default:
                throw GraalError.unimplemented();
        }
    } else {
        throw GraalError.unimplemented();
    }
    crb.recordMark(markId);
}
Also used : AMD64Kind(jdk.vm.ci.amd64.AMD64Kind) ValueUtil.asRegister(jdk.vm.ci.code.ValueUtil.asRegister) Register(jdk.vm.ci.code.Register) AMD64Address(org.graalvm.compiler.asm.amd64.AMD64Address)

Aggregations

AMD64Address (org.graalvm.compiler.asm.amd64.AMD64Address)32 Register (jdk.vm.ci.code.Register)23 ValueUtil.asRegister (jdk.vm.ci.code.ValueUtil.asRegister)19 Label (org.graalvm.compiler.asm.Label)16 ArrayDataPointerConstant (org.graalvm.compiler.lir.asm.ArrayDataPointerConstant)7 AMD64MacroAssembler (org.graalvm.compiler.asm.amd64.AMD64MacroAssembler)6 CallingConvention (jdk.vm.ci.code.CallingConvention)4 RegisterConfig (jdk.vm.ci.code.RegisterConfig)4 TargetDescription (jdk.vm.ci.code.TargetDescription)3 AMD64Kind (jdk.vm.ci.amd64.AMD64Kind)2 DataSectionReference (jdk.vm.ci.code.site.DataSectionReference)2 AssemblerTest (org.graalvm.compiler.asm.test.AssemblerTest)2 CompilationResult (org.graalvm.compiler.code.CompilationResult)2 Data (org.graalvm.compiler.code.DataSection.Data)2 RawData (org.graalvm.compiler.code.DataSection.RawData)2 SerializableData (org.graalvm.compiler.code.DataSection.SerializableData)2 FrameMap (org.graalvm.compiler.lir.framemap.FrameMap)2 Test (org.junit.Test)2 CGlobalDataReference (com.oracle.svm.core.graal.code.CGlobalDataReference)1 SubstrateRegisterConfig (com.oracle.svm.core.graal.meta.SubstrateRegisterConfig)1