Package org.jnode.assembler

Examples of org.jnode.assembler.Label


            // Push const not supported in 64-bit mode,
            // but PUSH imm32 will sign-extend to 64-bit
            os.writePUSH(0);
        } else {
            X86CompilerHelper helper = ec.getHelper();
            Label l = new Label(Long.toString(labelCounter++));
            helper.writePushStaticsEntry(l, value);
        }
    }
View Full Code Here


     * @return The length of os at the start of the method code.
     */
    public int emitHeader() {

        final VmMethodCode code = new VmMethodCode();
        final Label startLabel = helper.genLabel("$$start");
        codeObject = os.startObject(entryPoints.getVmMethodCodeClass());
        os.setObjectRef(code);
        cm.setCodeStart(os.setObjectRef(startLabel));
        final int rc = os.getLength();

View Full Code Here

     * Write code to test the alignment of the stack pointer.
     */
    public void writeStackAlignmentTest(Label curInstrLabel) {
        if (false && os.isCode64()) {
            final int idx = os.getLength();
            final Label test = new Label(curInstrLabel + "$$stackAlignTest" + idx);
            final Label failed = new Label(curInstrLabel + "$$stackAlign" + idx);
            os.writeJMP(test);
            os.setObjectRef(failed);
            os.writeINT(0x41);
            os.setObjectRef(test);
            os.writeTEST(X86Register.RSP, 7);
View Full Code Here

    /**
     * Emit code to end the stack frame
     */
    public void emitTrailer(TypeSizeInfo typeSizeInfo, int maxLocals) {
        final int argSlotCount = method.getArgSlotCount();
        final Label stackOverflowLabel = helper.genLabel("$$stack-overflow");
        final GPR asp = helper.SP;
        final GPR abp = helper.BP;
        final GPR aax = helper.AAX;
        final int size = helper.ADDRSIZE;

        // Begin footer
        // Now start the actual footer
        os.setObjectRef(footerLabel);

        /* Go restore the previous current frame */
        emitSynchronizationCode(typeSizeInfo, entryPoints.getMonitorExitMethod());
        os.writeLEA(asp, abp, EbpFrameRefOffset);
        os.writePOP(abp);
        restoreRegisters();
        // Return
        if (argSlotCount > 0) {
            os.writeRET(argSlotCount * slotSize);
        } else {
            os.writeRET();
        }
        // End footer

        // Begin header
        // Init starts here
        os.setObjectRef(initLabel);

        // Test stack overflow       
        final int stackEndOffset = entryPoints.getVmProcessorStackEnd().getOffset();
        if (os.isCode32()) {
            os.writePrefix(X86Constants.FS_PREFIX);
            os.writeCMP_MEM(X86Register.ESP, stackEndOffset);
        } else {
            os.writeCMP(X86Register.RSP, PROCESSOR64, stackEndOffset);
        }
        // This forward jump is not predicted by branch prediction.
        // Which is good, because we do not predict a stack overflow
        os.writeJCC(stackOverflowLabel, X86Constants.JLE);

        // Load the statics table reference
        if (method.hasLoadStaticsPragma()) {
            helper.writeLoadSTATICS(helper.genLabel("$$edi"), "init", false);
        }

        // Test stack alignment
        writeStackAlignmentTest(helper.genLabel("$$stackAlignment"));

        // Create class initialization code (if needed)
        helper.writeClassInitialize(method);

        // Increment the invocation count
        //helper.writeIncInvocationCount(aax); (NOT USED for now, aax is also invalid now)

        // Fixed framelayout
        saveRegisters();
        os.writePUSH(abp);
        os.writePUSH(cm.getCompiledCodeId());
        os.writeMOV(size, abp, asp);

        // Emit the code to create the locals
        final int noLocalVars = maxLocals - argSlotCount;
        // Create and clear all local variables
        if (noLocalVars > 0) {
            os.writeXOR(aax, aax);
            for (int i = 0; i < noLocalVars; i++) {
                os.writePUSH(aax);
            }
        }

        // Create the synchronization enter code
        emitSynchronizationCode(typeSizeInfo, entryPoints.getMonitorEnterMethod());

        // And jump back to the actual code start
        os.writeJMP(startCodeLabel);

        // Write stack overflow code
        os.setObjectRef(stackOverflowLabel);
        os.writeINT(0x31);

        // Write class initializers
        helper.writeClassInitializers();

        // End header      

        // No set the exception start&endPtr's
        //final int noLocals = bc.getNoLocals();
        //final int noLocalVars = noLocals - noArgs;
        final int count = bc.getNoExceptionHandlers();
        CompiledExceptionHandler[] ceh = new CompiledExceptionHandler[count];
        for (int i = 0; i < count; i++) {
            final VmInterpretedExceptionHandler eh = bc.getExceptionHandler(i);
            final Label handlerLabel = helper.genLabel("$$ex-handler" + i);

            final ObjectRef handlerRef = os.setObjectRef(handlerLabel);

            /** Clear the calculation stack (only locals are left) */
            if (noLocalVars < 0) {
                System.out.println("@#@#@#@# noLocalVars = " + noLocalVars);
            }
            final int ofs = Math.max(0, noLocalVars) * slotSize;
            os.writeLEA(asp, abp, -ofs);
            /** Push the exception in EAX */
            os.writePUSH(aax);
            /** Goto the real handler */
            os.writeJMP(helper.getInstrLabel(eh.getHandlerPC()));

            ceh[i] = new CompiledExceptionHandler();
            ceh[i].setStartPc(os.getObjectRef(helper.getInstrLabel(eh
                .getStartPC())));
            ceh[i].setEndPc(os
                .getObjectRef(helper.getInstrLabel(eh.getEndPC())));
            ceh[i].setHandler(handlerRef);

        }
        cm.setExceptionHandlers(ceh);

        // Now create the default exception handler
        Label handlerLabel = helper.genLabel("$$def-ex-handler");
        cm.setDefExceptionHandler(os.setObjectRef(handlerLabel));
        emitSynchronizationCode(typeSizeInfo, entryPoints.getMonitorExitMethod());
        os.writeLEA(asp, abp, EbpFrameRefOffset);
        os.writePOP(abp);
        restoreRegisters();
View Full Code Here

    @Override
    protected CompiledMethod doCompile(VmMethod method, NativeStream os, int level, boolean isBootstrap) {
        final CompiledMethod cm = new CompiledMethod(level);
        try {
            if (method.isNative()) {
                Object label = new Label(method.getMangledName());
                cm.setCodeStart(os.getObjectRef(label));
            } else {
                EntryPoints entryPoints = getEntryPoints();
                X86CompilerHelper helper = new X86CompilerHelper((X86Assembler) os, null, entryPoints, isBootstrap);
                helper.setMethod(method);
View Full Code Here

        // Pop fpu stack twice (FUCOMPP)
        fpuStack.pop(ec);
        fpuStack.pop(ec);

        final Label gtLabel = new Label(curInstrLabel + "gt");
        final Label ltLabel = new Label(curInstrLabel + "lt");
        final Label endLabel = new Label(curInstrLabel + "end");
        if (os.isCode32()) {
            os.writeJCC(gtLabel, X86Constants.JA);
            os.writeJCC(ltLabel, X86Constants.JB);
        } else {
            // Emulate JA
View Full Code Here

     * @return The compiled method
     */
    protected CompiledMethod doCompile(VmMethod method, NativeStream nos, int level, boolean isBootstrap) {
        final CompiledMethod cm = new CompiledMethod(level);
        if (method.isNative()) {
            Object label = new Label(method.getMangledName());
            cm.setCodeStart(nos.getObjectRef(label));
        } else {
            final X86Assembler os = (X86Assembler) nos;
            final EntryPoints context = getEntryPoints();
            // Create the helper
            final X86CompilerHelper ih = new X86CompilerHelper(os, null, context, isBootstrap);
            // Start an "object"
            final NativeStream.ObjectInfo objectInfo = os.startObject(context.getVmMethodCodeClass());
            // Start the code creation
            cm.setCodeStart(os.setObjectRef(new Label(method.getMangledName() + "$$start")));

            // Setup call to {@link VmMethod#recompileMethod(int, int)}
            final VmType<?> declClass = method.getDeclaringClass();
            os.writePUSH(declClass.getSharedStaticsIndex());
            os.writePUSH(declClass.indexOf(method));
            final int recompileStatOfs = ih.getSharedStaticsOffset(context.getRecompileMethod());
            os.writeCALL(ih.STATICS, recompileStatOfs);

            // Emit jump to the newly compiled code.
            final int methodStatOfs = ih.getSharedStaticsOffset(method);
            os.writeJMP(ih.STATICS, methodStatOfs);

            // Close the "object"
            objectInfo.markEnd();
            // The end
            cm.setCodeEnd(os.setObjectRef(new Label(method.getMangledName() + "$$end")));

            // Test for unresolved objectrefs
            if (!isBootstrap && os.hasUnresolvedObjectRefs()) {
                throw new Error("There are unresolved objectrefs " + os.getUnresolvedObjectRefs());
            }
View Full Code Here

                context, isBootstrap);
            // Start an "object"
            final NativeStream.ObjectInfo objectInfo = os.startObject(context
                .getVmMethodCodeClass());
            // Start the code creation
            cm.setCodeStart(os.setObjectRef(new Label(method.getMangledName()
                + "$$abstract-start")));
            // Call abstract method error method
            helper.writeJumpTableJMP(X86JumpTable.VM_INVOKE_ABSTRACT_IDX);
            // Close the "object"
            objectInfo.markEnd();
            // The end
            cm.setCodeEnd(os.setObjectRef(new Label(method.getMangledName()
                + "$$abstract-end")));

            return cm;
        } else {
            // Set the address of the abstract method code
View Full Code Here

     *
     * @param address
     * @return The created label
     */
    public final Label getInstrLabel(int address) {
        Label l = addressLabels.get(address);
        if (l == null) {
            l = new Label(instrLabelPrefix + address);
            addressLabels.put(address, l);
        }
        return l;
    }
View Full Code Here

     *
     * @param postFix
     * @return The created label
     */
    public final Label genLabel(String postFix) {
        return new Label(labelPrefix + postFix);
    }
View Full Code Here

TOP

Related Classes of org.jnode.assembler.Label

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.