Example usage for org.objectweb.asm Opcodes INVOKESTATIC

List of usage examples for org.objectweb.asm Opcodes INVOKESTATIC

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes INVOKESTATIC.

Prototype

int INVOKESTATIC

To view the source code for org.objectweb.asm Opcodes INVOKESTATIC.

Click Source Link

Usage

From source file:jpcsp.Allegrex.compiler.CompilerContext.java

License:Open Source License

private void startInstructionLLE(CodeInstruction codeInstruction) {
    // Check for a pending interrupt only for instructions not being in a delay slot
    if (codeInstruction.isDelaySlot()) {
        return;//from   www.java  2 s.co  m
    }

    // TO avoid checking too often for a pending interrupt, check
    // only for instructions being the target of the branch or for those marked
    // as potentially modifying the interrupt state.
    if (!codeInstruction.isBranchTarget() && !previousInstructionModifiesInterruptState(codeInstruction)) {
        return;
    }

    Label noPendingInterrupt = new Label();
    mv.visitFieldInsn(Opcodes.GETSTATIC, runtimeContextLLEInternalName, "pendingInterruptIPbits", "I");
    mv.visitJumpInsn(Opcodes.IFEQ, noPendingInterrupt);
    int returnAddress = codeInstruction.getAddress();
    loadImm(returnAddress);
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextLLEInternalName, "checkPendingInterruptException",
            "(I)I");
    visitContinueToAddress(returnAddress, false);
    mv.visitLabel(noPendingInterrupt);
}

From source file:jpcsp.Allegrex.compiler.CompilerContext.java

License:Open Source License

@SuppressWarnings("unused")
public void startInstruction(CodeInstruction codeInstruction) {
    if (RuntimeContext.enableLineNumbers) {
        int lineNumber = codeInstruction.getAddress() - getCodeBlock().getLowestAddress();
        // Java line number is unsigned 16bits
        if (lineNumber >= 0 && lineNumber <= 0xFFFF) {
            mv.visitLineNumber(lineNumber, codeInstruction.getLabel());
        }/*w w w.  j  a v a  2s . co m*/
    }

    // The pc is used by the DebuggerMemory or the LLE/MMIO
    if (Memory.getInstance() instanceof DebuggerMemory || RuntimeContextLLE.isLLEActive()) {
        storePc();
    }

    if (RuntimeContextLLE.isLLEActive()) {
        startInstructionLLE(codeInstruction);
    }

    if (RuntimeContext.debugCodeInstruction) {
        loadImm(codeInstruction.getAddress());
        loadImm(codeInstruction.getOpcode());
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName,
                RuntimeContext.debugCodeInstructionName, "(II)V");
    }

    if (RuntimeContext.enableInstructionTypeCounting) {
        if (codeInstruction.getInsn() != null) {
            loadInstruction(codeInstruction.getInsn());
            loadImm(codeInstruction.getOpcode());
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName,
                    RuntimeContext.instructionTypeCount, "(" + instructionDescriptor + "I)V");
        }
    }

    if (RuntimeContext.enableDebugger) {
        loadImm(codeInstruction.getAddress());
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, RuntimeContext.debuggerName,
                "(I)V");
    }

    if (RuntimeContext.checkCodeModification && !(codeInstruction instanceof NativeCodeInstruction)) {
        // Generate the following sequence:
        //
        //     if (memory.read32(pc) != opcode) {
        //         RuntimeContext.onCodeModification(pc, opcode);
        //     }
        //
        loadMemory();
        loadImm(codeInstruction.getAddress());
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "read32", "(I)I");
        loadImm(codeInstruction.getOpcode());
        Label codeUnchanged = new Label();
        mv.visitJumpInsn(Opcodes.IF_ICMPEQ, codeUnchanged);

        loadImm(codeInstruction.getAddress());
        loadImm(codeInstruction.getOpcode());
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "onCodeModification", "(II)V");

        mv.visitLabel(codeUnchanged);
    }

    if (!isNonBranchingCodeSequence(codeInstruction)) {
        startNonBranchingCodeSequence();
    }

    // This instructions consumes the PFXT prefix but does not use it.
    if (codeInstruction.hasFlags(Instruction.FLAG_CONSUMES_VFPU_PFXT)) {
        disablePfxSrc(vfpuPfxtState);
    }
}

From source file:jpcsp.Allegrex.compiler.CompilerContext.java

License:Open Source License

public void visitJump(int opcode, CodeInstruction target) {
    // Back branch? i.e probably a loop
    if (target.getAddress() <= getCodeInstruction().getAddress()) {
        checkSync();//  w  w w.j a v  a 2  s . c o m

        if (Profiler.isProfilerEnabled()) {
            loadImm(getCodeInstruction().getAddress());
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, profilerInternalName, "addBackBranch", "(I)V");
        }
    }
    visitJump(opcode, target.getLabel());
}

From source file:jpcsp.Allegrex.compiler.CompilerContext.java

License:Open Source License

public void visitPauseEmuWithStatus(MethodVisitor mv, int status) {
    loadImm(status);/*from w ww  .  j  a v  a  2s  .c  om*/
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, RuntimeContext.pauseEmuWithStatus,
            "(I)V");
}

From source file:jpcsp.Allegrex.compiler.CompilerContext.java

License:Open Source License

public void visitLogInfo(MethodVisitor mv, String message) {
    mv.visitLdcInsn(message);//from w  w  w .j  ava 2 s. c o m
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, RuntimeContext.logInfo,
            "(" + stringDescriptor + ")V");
}

From source file:jpcsp.Allegrex.compiler.CompilerContext.java

License:Open Source License

@Override
public void memRead16(int registerIndex, int offset) {
    if (useMMIO()) {
        loadMMIO();/*w  ww.  j a v a 2s  . com*/
    } else if (!RuntimeContext.hasMemoryInt()) {
        loadMemory();
    } else {
        loadMemoryInt();
    }

    loadRegister(registerIndex);
    if (offset != 0) {
        loadImm(offset);
        mv.visitInsn(Opcodes.IADD);
    }

    if (RuntimeContext.debugMemoryRead) {
        mv.visitInsn(Opcodes.DUP);
        loadImm(0);
        loadImm(codeInstruction.getAddress());
        loadImm(1);
        loadImm(16);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "debugMemoryReadWrite",
                "(IIIZI)V");
    }

    if (useMMIO() || !RuntimeContext.hasMemoryInt()) {
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "read16", "(I)I");
    } else {
        if (checkMemoryAccess()) {
            loadImm(codeInstruction.getAddress());
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "checkMemoryRead16", "(II)I");
            loadImm(1);
            mv.visitInsn(Opcodes.IUSHR);
        } else {
            // memoryInt[(address & 0x1FFFFFFF) / 4] == memoryInt[(address << 3) >>> 5]
            loadImm(3);
            mv.visitInsn(Opcodes.ISHL);
            loadImm(4);
            mv.visitInsn(Opcodes.IUSHR);
        }
        mv.visitInsn(Opcodes.DUP);
        loadImm(1);
        mv.visitInsn(Opcodes.IAND);
        loadImm(4);
        mv.visitInsn(Opcodes.ISHL);
        storeTmp1();
        loadImm(1);
        mv.visitInsn(Opcodes.IUSHR);
        mv.visitInsn(Opcodes.IALOAD);
        loadTmp1();
        mv.visitInsn(Opcodes.IUSHR);
        loadImm(0xFFFF);
        mv.visitInsn(Opcodes.IAND);
    }
}

From source file:jpcsp.Allegrex.compiler.CompilerContext.java

License:Open Source License

@Override
public void memRead8(int registerIndex, int offset) {
    if (useMMIO()) {
        loadMMIO();//from w w w  .  j  a  v a 2  s.  co m
    } else if (!RuntimeContext.hasMemoryInt()) {
        loadMemory();
    } else {
        loadMemoryInt();
    }

    loadRegister(registerIndex);
    if (offset != 0) {
        loadImm(offset);
        mv.visitInsn(Opcodes.IADD);
    }

    if (RuntimeContext.debugMemoryRead) {
        mv.visitInsn(Opcodes.DUP);
        loadImm(0);
        loadImm(codeInstruction.getAddress());
        loadImm(1);
        loadImm(8);
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "debugMemoryReadWrite",
                "(IIIZI)V");
    }

    if (useMMIO() || !RuntimeContext.hasMemoryInt()) {
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "read8", "(I)I");
    } else {
        if (checkMemoryAccess()) {
            loadImm(codeInstruction.getAddress());
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "checkMemoryRead8", "(II)I");
        } else {
            // memoryInt[(address & 0x1FFFFFFF) / 4] == memoryInt[(address << 3) >>> 5]
            loadImm(3);
            mv.visitInsn(Opcodes.ISHL);
            loadImm(3);
            mv.visitInsn(Opcodes.IUSHR);
        }
        mv.visitInsn(Opcodes.DUP);
        loadImm(3);
        mv.visitInsn(Opcodes.IAND);
        loadImm(3);
        mv.visitInsn(Opcodes.ISHL);
        storeTmp1();
        loadImm(2);
        mv.visitInsn(Opcodes.IUSHR);
        mv.visitInsn(Opcodes.IALOAD);
        loadTmp1();
        mv.visitInsn(Opcodes.IUSHR);
        loadImm(0xFF);
        mv.visitInsn(Opcodes.IAND);
    }
}

From source file:jpcsp.Allegrex.compiler.CompilerContext.java

License:Open Source License

@SuppressWarnings("unused")
private void prepareMemIndex(int registerIndex, int offset, boolean isRead, int width) {
    loadRegister(registerIndex);//from  w  ww . j a v  a 2  s  .  c  om
    if (offset != 0) {
        loadImm(offset);
        mv.visitInsn(Opcodes.IADD);
    }

    if (RuntimeContext.debugMemoryRead && isRead) {
        if (!RuntimeContext.debugMemoryReadWriteNoSP || registerIndex != _sp) {
            mv.visitInsn(Opcodes.DUP);
            loadImm(0);
            loadImm(codeInstruction.getAddress());
            loadImm(isRead);
            loadImm(width);
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "debugMemoryReadWrite",
                    "(IIIZI)V");
        }
    }

    if (!useMMIO() && RuntimeContext.hasMemoryInt()) {
        if (registerIndex == _sp) {
            if (isCodeInstructionInKernelMemory()) {
                // In kernel memory, the $sp value can have the flag 0x80000000.
                // memoryInt[(address & 0x1FFFFFFF) / 4] == memoryInt[(address << 3) >>> 5]
                loadImm(3);
                mv.visitInsn(Opcodes.ISHL);
                loadImm(5);
                mv.visitInsn(Opcodes.IUSHR);
            } else {
                // No need to check for a valid memory access when referencing the $sp register
                loadImm(2);
                mv.visitInsn(Opcodes.IUSHR);
            }
        } else if (checkMemoryAccess()) {
            loadImm(codeInstruction.getAddress());
            String checkMethodName = String.format("checkMemory%s%d", isRead ? "Read" : "Write", width);
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, checkMethodName, "(II)I");
            loadImm(2);
            mv.visitInsn(Opcodes.IUSHR);
        } else {
            // memoryInt[(address & 0x1FFFFFFF) / 4] == memoryInt[(address << 3) >>> 5]
            loadImm(3);
            mv.visitInsn(Opcodes.ISHL);
            loadImm(5);
            mv.visitInsn(Opcodes.IUSHR);
        }
    }
}

From source file:jpcsp.Allegrex.compiler.CompilerContext.java

License:Open Source License

@Override
public void memWrite32(int registerIndex, int offset) {
    if (!memWritePrepared) {
        if (useMMIO()) {
            loadMMIO();/*www  . j  av a2s .  co  m*/
        } else if (!RuntimeContext.hasMemoryInt()) {
            loadMemory();
        } else {
            loadMemoryInt();
        }
        mv.visitInsn(Opcodes.SWAP);

        loadRegister(registerIndex);
        if (offset != 0) {
            loadImm(offset);
            mv.visitInsn(Opcodes.IADD);
        }
        if (checkMemoryAccess()) {
            loadImm(codeInstruction.getAddress());
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "checkMemoryWrite32", "(II)I");
        }
        mv.visitInsn(Opcodes.SWAP);
    }

    if (RuntimeContext.debugMemoryWrite) {
        if (!RuntimeContext.debugMemoryReadWriteNoSP || registerIndex != _sp) {
            mv.visitInsn(Opcodes.DUP2);
            mv.visitInsn(Opcodes.SWAP);
            loadImm(2);
            mv.visitInsn(Opcodes.ISHL);
            mv.visitInsn(Opcodes.SWAP);
            loadImm(codeInstruction.getAddress());
            loadImm(0);
            loadImm(32);
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "debugMemoryReadWrite",
                    "(IIIZI)V");
        }
    }

    if (useMMIO() || !RuntimeContext.hasMemoryInt()) {
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "write32", "(II)V");
    } else {
        mv.visitInsn(Opcodes.IASTORE);
    }

    memWritePrepared = false;
}

From source file:jpcsp.Allegrex.compiler.CompilerContext.java

License:Open Source License

@Override
public void prepareMemWrite16(int registerIndex, int offset) {
    if (useMMIO()) {
        loadMMIO();//from   ww  w . jav a  2 s . c o  m
    } else if (!RuntimeContext.hasMemoryInt()) {
        loadMemory();
    } else {
        loadMemoryInt();
    }

    loadRegister(registerIndex);
    if (offset != 0) {
        loadImm(offset);
        mv.visitInsn(Opcodes.IADD);
    }

    if (!useMMIO() && RuntimeContext.hasMemoryInt()) {
        if (checkMemoryAccess()) {
            loadImm(codeInstruction.getAddress());
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "checkMemoryWrite16", "(II)I");
        }
    }

    memWritePrepared = true;
}