Package org.jnode.assembler

Examples of org.jnode.assembler.Label


    /**
     * Insert a yieldpoint into the code
     */
    public final void writeYieldPoint(Object curInstrLabel) {
        if (!method.isUninterruptible()) {
            final Label doneLabel = new Label(curInstrLabel + "noYP");
            final Label ypLabel = new Label(curInstrLabel + "$$yp");
            final int offset = entryPoints.getVmThreadSwitchIndicatorOffset();
            final int flag = VmProcessor.TSI_SWITCH_REQUESTED;
            if (os.isCode32()) {
                os.writePrefix(X86Constants.FS_PREFIX);
                os.writeCMP_MEM(BITS32, offset, flag);
View Full Code Here


        if (method.isStatic() && !method.isInitializer()) {
            // Only when class is not initialize
            final VmType<?> cls = method.getDeclaringClass();
            if (!cls.isAlwaysInitialized()) {
                final GPR aax = this.AAX;
                final Label label = genLabel("$$class-init");

                // Save eax
                os.writePUSH(aax);
                // Get class into aax
                if (os.isCode32()) {
View Full Code Here

     */
    public final void writeClassInitialize(Label curInstrLabel, GPR classReg,
                                           GPR tmpReg, VmType<?> cls) {
        if (!cls.isAlwaysInitialized()) {
            // Create jump labels
            final Label testIsolated = new Label(curInstrLabel + "$$testiso-cinit");
            final Label doInit = new Label(curInstrLabel + "$$do-cinit-ex");
            final Label done = new Label(curInstrLabel + "$$done-cinit-ex");

            // Test declaringClass.modifiers (mostly true)
            os.writeTEST(BITS32, classReg, entryPoints.getVmTypeState()
                .getOffset(), VmTypeState.ST_ALWAYS_INITIALIZED);
            if (!cls.isSharedStatics()) {
                // Jump when not initialized to isolated state test
                // Branch predication expects this forward jump NOT
                // to be taken.
                os.writeJCC(testIsolated, X86Constants.JZ);
                // We don't have to initialize, so jump over the init-code.
                os.writeJMP(done);

                // Test isolated class state
                os.setObjectRef(testIsolated);
                writeLoadIsolatedStatics(curInstrLabel, "$$ld-is-stat", tmpReg);
                final int offset = getIsolatedStaticsOffset(cls);
                os.writeTEST(BITS32, tmpReg, offset, VmTypeState.IST_INITIALIZED);
            }
            // Jump when not initialized to doInit.
            // Branch predication expects this forward jump NOT
            // to be taken.
            os.writeJCC(doInit, X86Constants.JZ);

            // We don't have to initialize, so jump over the init-code.
            os.writeJMP(done);

            // Start initialize code
            os.setObjectRef(doInit);

            // Get label for class initialize code
            Label initializer = classInitLabels.get(cls);
            if (initializer == null) {
                // create one
                initializer = genLabel("$$init-" + cls.getName());
                classInitLabels.put(cls, initializer);
            }
View Full Code Here

    /**
     * Write the class initializer code.
     */
    public final void writeClassInitializers() {
        for (Map.Entry<VmType<?>, Label> entry : classInitLabels.entrySet()) {
            final Label label = entry.getValue();
            // Set label
            os.setObjectRef(label);
            // Save registers
            if (os.isCode32()) {
                os.writePUSHA();
View Full Code Here

        // jg vm_invoke_testStackOverflowDone
        // vm_invoke_testStackOverflow:
        // int 0x31
        // vm_invoke_testStackOverflowDone:
        final int offset = entryPoints.getVmProcessorStackEnd().getOffset();
        final Label doneLabel = new Label(labelPrefix + "$$stackof-done");
        final Label intLabel = new Label(labelPrefix + "$$stovf");
        if (os.isCode32()) {
            os.writePrefix(X86Constants.FS_PREFIX);
            os.writeCMP_MEM(X86Register.ESP, offset);
        } else {
            os.writeCMP(X86Register.RSP, PROCESSOR64, offset);
View Full Code Here

                                       boolean isTestOnly) {
        final int offset = entryPoints.getVmProcessorSharedStaticsTable()
            .getOffset();
        if (isTestOnly) {
            if (debug) {
                final Label ok = new Label(curInstrLabel + labelPrefix
                    + "$$ediok");
                if (os.isCode32()) {
                    os.writePrefix(X86Constants.FS_PREFIX);
                    os.writeCMP_MEM(this.STATICS, offset);
                } else {
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

     * @param curInstrLabel
     */
    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

     * @param typeSizeInfo
     * @param maxLocals
     */
    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

        this.stackFrame = stackFrame;
        this.currentMethod = method;
    }

    public final Label getInstrLabel(int address) {
        Label l = addressLabels[address];
        if (l == null) {
            l = new Label(instrLabelPrefix + address);
            addressLabels[address] = l;
        }
        return l;
    }
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.