List of usage examples for org.objectweb.asm Opcodes DUP2_X2
int DUP2_X2
To view the source code for org.objectweb.asm Opcodes DUP2_X2.
Click Source Link
From source file:dyco4j.instrumentation.internals.TracingMethodVisitor.java
License:BSD License
private void visitArrayLoadInsn(final int opcode) { super.visitInsn(Opcodes.DUP2); super.visitInsn(opcode); if (opcode == Opcodes.LALOAD || opcode == Opcodes.DALOAD) super.visitInsn(Opcodes.DUP2_X2); else/*from w w w . ja va2 s.c o m*/ super.visitInsn(Opcodes.DUP_X2); switch (opcode) { case Opcodes.AALOAD: LoggingHelper.emitConvertToString(this.mv, Type.getObjectType("java/lang/Object")); break; case Opcodes.BALOAD: LoggingHelper.emitConvertToString(this.mv, Type.BYTE_TYPE); break; case Opcodes.CALOAD: LoggingHelper.emitConvertToString(this.mv, Type.CHAR_TYPE); break; case Opcodes.FALOAD: LoggingHelper.emitConvertToString(this.mv, Type.FLOAT_TYPE); break; case Opcodes.IALOAD: LoggingHelper.emitConvertToString(this.mv, Type.INT_TYPE); break; case Opcodes.SALOAD: LoggingHelper.emitConvertToString(this.mv, Type.SHORT_TYPE); break; case Opcodes.DALOAD: LoggingHelper.emitConvertToString(this.mv, Type.DOUBLE_TYPE); break; case Opcodes.LALOAD: LoggingHelper.emitConvertToString(this.mv, Type.LONG_TYPE); break; } LoggingHelper.emitLogArray(this.mv, Logger.ArrayAction.GETA); }
From source file:edu.mit.streamjit.util.bytecode.MethodResolver.java
License:Open Source License
private void interpret(InsnNode insn, FrameState frame, BBInfo block) { ReturnType returnType = block.block.getParent().getType().getReturnType(); switch (insn.getOpcode()) { case Opcodes.NOP: break;/*w w w. jav a 2s . co m*/ //<editor-fold defaultstate="collapsed" desc="Stack manipulation opcodes (pop, dup, swap)"> case Opcodes.POP: assert frame.stack.peek().getType().getCategory() == 1; frame.stack.pop(); break; case Opcodes.POP2: final int[][][] pop2Permutations = { { { 1, 1 }, {} }, { { 2 }, {} } }; conditionallyPermute(frame, pop2Permutations); break; case Opcodes.DUP: final int[][][] dupPermutations = { { { 1 }, { 1, 1 } } }; conditionallyPermute(frame, dupPermutations); break; case Opcodes.DUP_X1: final int[][][] dup_x1Permutations = { { { 1, 1 }, { 1, 2, 1 } } }; conditionallyPermute(frame, dup_x1Permutations); break; case Opcodes.DUP_X2: final int[][][] dup_x2Permutations = { { { 1, 1, 1 }, { 1, 3, 2, 1 } }, { { 1, 2 }, { 1, 2, 1 } } }; conditionallyPermute(frame, dup_x2Permutations); break; case Opcodes.DUP2: final int[][][] dup2Permutations = { { { 1, 1 }, { 2, 1, 2, 1 } }, { { 2 }, { 1, 1 } } }; conditionallyPermute(frame, dup2Permutations); break; case Opcodes.DUP2_X1: final int[][][] dup2_x1Permutations = { { { 1, 1, 1 }, { 2, 1, 3, 2, 1 } }, { { 2, 1 }, { 1, 2, 1 } } }; conditionallyPermute(frame, dup2_x1Permutations); break; case Opcodes.DUP2_X2: final int[][][] dup2_x2Permutations = { { { 1, 1, 1, 1 }, { 2, 1, 4, 3, 2, 1 } }, { { 2, 1, 1 }, { 1, 3, 2, 1 } }, { { 3, 2, 1 }, { 2, 1, 3, 2, 1 } }, { { 2, 2 }, { 1, 2, 1 } } }; conditionallyPermute(frame, dup2_x2Permutations); break; case Opcodes.SWAP: final int[][][] swapPermutations = { { { 1, 1 }, { 1, 2 } } }; conditionallyPermute(frame, swapPermutations); break; //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Constant-stacking opcodes (iconst_0, etc.; see also bipush, sipush)"> case Opcodes.ACONST_NULL: frame.stack.push(module.constants().getNullConstant()); break; case Opcodes.ICONST_M1: frame.stack.push(module.constants().getSmallestIntConstant(-1)); break; case Opcodes.ICONST_0: frame.stack.push(module.constants().getSmallestIntConstant(0)); break; case Opcodes.ICONST_1: frame.stack.push(module.constants().getSmallestIntConstant(1)); break; case Opcodes.ICONST_2: frame.stack.push(module.constants().getSmallestIntConstant(2)); break; case Opcodes.ICONST_3: frame.stack.push(module.constants().getSmallestIntConstant(3)); break; case Opcodes.ICONST_4: frame.stack.push(module.constants().getSmallestIntConstant(4)); break; case Opcodes.ICONST_5: frame.stack.push(module.constants().getSmallestIntConstant(5)); break; case Opcodes.LCONST_0: frame.stack.push(module.constants().getConstant(0L)); break; case Opcodes.LCONST_1: frame.stack.push(module.constants().getConstant(1L)); break; case Opcodes.FCONST_0: frame.stack.push(module.constants().getConstant(0f)); break; case Opcodes.FCONST_1: frame.stack.push(module.constants().getConstant(1f)); break; case Opcodes.FCONST_2: frame.stack.push(module.constants().getConstant(2f)); break; case Opcodes.DCONST_0: frame.stack.push(module.constants().getConstant(0d)); break; case Opcodes.DCONST_1: frame.stack.push(module.constants().getConstant(1d)); break; //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Return opcodes"> case Opcodes.IRETURN: assert returnType.isSubtypeOf(typeFactory.getType(int.class)); assert frame.stack.peek().getType().isSubtypeOf(returnType); block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop())); break; case Opcodes.LRETURN: assert returnType.isSubtypeOf(typeFactory.getType(long.class)); assert frame.stack.peek().getType().isSubtypeOf(returnType); block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop())); break; case Opcodes.FRETURN: assert returnType.isSubtypeOf(typeFactory.getType(float.class)); assert frame.stack.peek().getType().isSubtypeOf(returnType); block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop())); break; case Opcodes.DRETURN: assert returnType.isSubtypeOf(typeFactory.getType(double.class)); assert frame.stack.peek().getType().isSubtypeOf(returnType); block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop())); break; case Opcodes.ARETURN: assert returnType.isSubtypeOf(typeFactory.getType(Object.class)); assert frame.stack.peek().getType().isSubtypeOf(returnType); block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop())); break; case Opcodes.RETURN: assert returnType instanceof VoidType || method.isConstructor(); block.block.instructions().add(new ReturnInst(typeFactory.getVoidType())); break; //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Unary math opcodes (negation)"> //Unary minus is rendered as a multiplication by -1. (The obvious //other choice, subtraction from 0, is not equivalent for floats and //doubles due to negative zero.) case Opcodes.INEG: frame.stack.push(module.constants().getSmallestIntConstant(-1)); binary(BinaryInst.Operation.MUL, frame, block); break; case Opcodes.LNEG: frame.stack.push(module.constants().getConstant(-1L)); binary(BinaryInst.Operation.MUL, frame, block); break; case Opcodes.FNEG: frame.stack.push(module.constants().getConstant(-1f)); binary(BinaryInst.Operation.MUL, frame, block); break; case Opcodes.DNEG: frame.stack.push(module.constants().getConstant(-1d)); binary(BinaryInst.Operation.MUL, frame, block); break; //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Binary math opcodes"> case Opcodes.IADD: case Opcodes.LADD: case Opcodes.FADD: case Opcodes.DADD: binary(BinaryInst.Operation.ADD, frame, block); break; case Opcodes.ISUB: case Opcodes.LSUB: case Opcodes.FSUB: case Opcodes.DSUB: binary(BinaryInst.Operation.SUB, frame, block); break; case Opcodes.IMUL: case Opcodes.LMUL: case Opcodes.FMUL: case Opcodes.DMUL: binary(BinaryInst.Operation.MUL, frame, block); break; case Opcodes.IDIV: case Opcodes.LDIV: case Opcodes.FDIV: case Opcodes.DDIV: binary(BinaryInst.Operation.DIV, frame, block); break; case Opcodes.IREM: case Opcodes.LREM: case Opcodes.FREM: case Opcodes.DREM: binary(BinaryInst.Operation.REM, frame, block); break; case Opcodes.ISHL: case Opcodes.LSHL: binary(BinaryInst.Operation.SHL, frame, block); break; case Opcodes.ISHR: case Opcodes.LSHR: binary(BinaryInst.Operation.SHR, frame, block); break; case Opcodes.IUSHR: case Opcodes.LUSHR: binary(BinaryInst.Operation.USHR, frame, block); break; case Opcodes.IAND: case Opcodes.LAND: binary(BinaryInst.Operation.AND, frame, block); break; case Opcodes.IOR: case Opcodes.LOR: binary(BinaryInst.Operation.OR, frame, block); break; case Opcodes.IXOR: case Opcodes.LXOR: binary(BinaryInst.Operation.XOR, frame, block); break; case Opcodes.LCMP: case Opcodes.FCMPL: case Opcodes.DCMPL: binary(BinaryInst.Operation.CMP, frame, block); break; case Opcodes.FCMPG: case Opcodes.DCMPG: binary(BinaryInst.Operation.CMPG, frame, block); break; //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Primitive casts"> case Opcodes.I2L: cast(int.class, long.class, frame, block); break; case Opcodes.I2F: cast(int.class, float.class, frame, block); break; case Opcodes.I2D: cast(int.class, double.class, frame, block); break; case Opcodes.L2I: cast(long.class, int.class, frame, block); break; case Opcodes.L2F: cast(long.class, float.class, frame, block); break; case Opcodes.L2D: cast(long.class, double.class, frame, block); break; case Opcodes.F2I: cast(float.class, int.class, frame, block); break; case Opcodes.F2L: cast(float.class, long.class, frame, block); break; case Opcodes.F2D: cast(float.class, double.class, frame, block); break; case Opcodes.D2I: cast(double.class, int.class, frame, block); break; case Opcodes.D2L: cast(double.class, long.class, frame, block); break; case Opcodes.D2F: cast(double.class, float.class, frame, block); break; case Opcodes.I2B: cast(int.class, byte.class, frame, block); break; case Opcodes.I2C: cast(int.class, char.class, frame, block); break; case Opcodes.I2S: cast(int.class, short.class, frame, block); break; //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Array store opcodes"> case Opcodes.IASTORE: case Opcodes.LASTORE: case Opcodes.FASTORE: case Opcodes.DASTORE: case Opcodes.AASTORE: case Opcodes.BASTORE: case Opcodes.CASTORE: case Opcodes.SASTORE: Value data = frame.stack.pop(); Value index = frame.stack.pop(); Value array = frame.stack.pop(); ArrayStoreInst asi = new ArrayStoreInst(array, index, data); block.block.instructions().add(asi); break; //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Array load opcodes"> case Opcodes.IALOAD: case Opcodes.LALOAD: case Opcodes.FALOAD: case Opcodes.DALOAD: case Opcodes.AALOAD: case Opcodes.BALOAD: case Opcodes.CALOAD: case Opcodes.SALOAD: Value index2 = frame.stack.pop(); Value array2 = frame.stack.pop(); ArrayLoadInst ali = new ArrayLoadInst(array2, index2); block.block.instructions().add(ali); frame.stack.push(ali); break; //</editor-fold> case Opcodes.ARRAYLENGTH: ArrayLengthInst lengthInst = new ArrayLengthInst(frame.stack.pop()); block.block.instructions().add(lengthInst); frame.stack.push(lengthInst); break; case Opcodes.ATHROW: block.block.instructions().add(new ThrowInst(frame.stack.pop())); break; default: throw new UnsupportedOperationException("" + insn.getOpcode()); } }
From source file:jpcsp.Allegrex.compiler.CompilerContext.java
License:Open Source License
private void logSyscall(HLEModuleFunction func, String logPrefix, String logCheckFunction, String logFunction) { // Modules.getLogger(func.getModuleName()).warn("Unimplemented..."); loadModuleLoggger(func);//from www . j av a 2s. c om mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), logCheckFunction, "()Z"); Label loggingDisabled = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, loggingDisabled); loadModuleLoggger(func); StringBuilder formatString = new StringBuilder(); if (logPrefix != null) { formatString.append(logPrefix); } formatString.append(func.getFunctionName()); ParameterInfo[] parameters = new ClassAnalyzer().getParameters(func.getFunctionName(), func.getHLEModuleMethod().getDeclaringClass()); if (parameters != null) { // Log message: // String.format( // "Unimplemented <function name> // <parameterIntegerName>=0x%X, // <parameterBooleanName>=%b, // <parameterLongName>=0x%X, // <parameterFloatName>=%f, // <parameterOtherTypeName>=%s", // new Object[] { // new Integer(parameterValueInteger), // new Boolean(parameterValueBoolean), // new Long(parameterValueLong), // new Float(parameterValueFloat), // parameterValueOtherTypes // }) loadImm(parameters.length); mv.visitTypeInsn(Opcodes.ANEWARRAY, Type.getInternalName(Object.class)); CompilerParameterReader parameterReader = new CompilerParameterReader(this); Annotation[][] paramsAnotations = func.getHLEModuleMethod().getParameterAnnotations(); int objectArrayIndex = 0; for (int paramIndex = 0; paramIndex < parameters.length; paramIndex++) { ParameterInfo parameter = parameters[paramIndex]; Class<?> parameterType = parameter.type; CompilerTypeInformation typeInformation = compilerTypeManager .getCompilerTypeInformation(parameterType); mv.visitInsn(Opcodes.DUP); loadImm(objectArrayIndex); formatString.append(paramIndex > 0 ? ", " : " "); formatString.append(parameter.name); formatString.append("="); formatString.append(typeInformation.formatString); if (typeInformation.boxingTypeInternalName != null) { mv.visitTypeInsn(Opcodes.NEW, typeInformation.boxingTypeInternalName); mv.visitInsn(Opcodes.DUP); } loadParameter(parameterReader, func, parameterType, paramsAnotations[paramIndex], null, null); if (typeInformation.boxingTypeInternalName != null) { mv.visitMethodInsn(Opcodes.INVOKESPECIAL, typeInformation.boxingTypeInternalName, "<init>", typeInformation.boxingMethodDescriptor); } mv.visitInsn(Opcodes.AASTORE); objectArrayIndex++; } mv.visitLdcInsn(formatString.toString()); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(String.class), "format", "(" + Type.getDescriptor(String.class) + "[" + Type.getDescriptor(Object.class) + ")" + Type.getDescriptor(String.class)); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), logFunction, "(" + Type.getDescriptor(Object.class) + ")V"); parameterReader = new CompilerParameterReader(this); for (int paramIndex = 0; paramIndex < parameters.length; paramIndex++) { ParameterInfo parameter = parameters[paramIndex]; Class<?> parameterType = parameter.type; LengthInfo lengthInfo = BufferInfo.defaultLengthInfo; int length = BufferInfo.defaultLength; Usage usage = BufferInfo.defaultUsage; for (Annotation parameterAnnotation : paramsAnotations[paramIndex]) { if (parameterAnnotation instanceof BufferInfo) { BufferInfo bufferInfo = (BufferInfo) parameterAnnotation; lengthInfo = bufferInfo.lengthInfo(); length = bufferInfo.length(); usage = bufferInfo.usage(); } } boolean parameterRead = false; if ((usage == Usage.in || usage == Usage.inout) && (lengthInfo != LengthInfo.unknown || parameterType == TPointer16.class || parameterType == TPointer32.class || parameterType == TPointer64.class)) { loadModuleLoggger(func); loadImm(1); mv.visitTypeInsn(Opcodes.ANEWARRAY, Type.getInternalName(Object.class)); mv.visitInsn(Opcodes.DUP); loadImm(0); Label done = new Label(); Label addressNull = new Label(); parameterReader.loadNextInt(); parameterRead = true; mv.visitInsn(Opcodes.DUP); mv.visitJumpInsn(Opcodes.IFEQ, addressNull); String format = String.format("%s[%s]:%%s", parameter.name, usage); boolean useMemoryDump = true; switch (lengthInfo) { case fixedLength: loadImm(length); break; case nextNextParameter: parameterReader.skipNextInt(); paramIndex++; parameterReader.loadNextInt(); paramIndex++; break; case nextParameter: parameterReader.loadNextInt(); paramIndex++; break; case previousParameter: // Go back to the address parameter parameterReader.rewindPreviousInt(); // Go back to the previous parameter parameterReader.rewindPreviousInt(); // Load the length from the previous parameter parameterReader.loadNextInt(); // Skip again the address parameter // to come back to the above situation parameterReader.skipNextInt(); break; case variableLength: mv.visitInsn(Opcodes.DUP); loadMemory(); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "read32", "(I)I"); break; case unknown: useMemoryDump = false; format = String.format("%s[%s]: 0x%%X", parameter.name, usage); loadMemory(); mv.visitInsn(Opcodes.SWAP); if (parameterType == TPointer64.class) { mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "read64", "(I)J"); mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Long.class)); mv.visitInsn(Opcodes.DUP); mv.visitInsn(Opcodes.DUP2_X2); mv.visitInsn(Opcodes.POP2); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Long.class), "<init>", "(J)V"); } else if (parameterType == TPointer16.class) { mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "read16", "(I)I"); mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Integer.class)); mv.visitInsn(Opcodes.DUP_X1); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Integer.class), "<init>", "(I)V"); } else { mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "read32", "(I)I"); mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Integer.class)); mv.visitInsn(Opcodes.DUP_X1); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Integer.class), "<init>", "(I)V"); } break; default: log.error(String.format("Unimplemented lengthInfo=%s", lengthInfo)); break; } if (useMemoryDump) { mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Utilities.class), "getMemoryDump", "(II)" + Type.getDescriptor(String.class)); } mv.visitInsn(Opcodes.AASTORE); mv.visitLdcInsn(format); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(String.class), "format", "(" + Type.getDescriptor(String.class) + "[" + Type.getDescriptor(Object.class) + ")" + Type.getDescriptor(String.class)); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), logFunction, "(" + Type.getDescriptor(Object.class) + ")V"); mv.visitJumpInsn(Opcodes.GOTO, done); mv.visitLabel(addressNull); mv.visitInsn(Opcodes.POP); mv.visitInsn(Opcodes.POP2); mv.visitInsn(Opcodes.POP2); mv.visitLabel(done); } if (!parameterRead) { if (parameterType == long.class) { parameterReader.skipNextLong(); } else if (parameterType == float.class) { parameterReader.skipNextFloat(); } else { parameterReader.skipNextInt(); } } } } else { mv.visitLdcInsn(formatString.toString()); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), logFunction, "(" + Type.getDescriptor(Object.class) + ")V"); } mv.visitLabel(loggingDisabled); }
From source file:jpcsp.Allegrex.compiler.CompilerContext.java
License:Open Source License
private void logSyscallEnd(HLEModuleFunction func, boolean isErrorCode) { String loggingLevel = getLoggingLevel(func); if (loggingLevel == null) { return;/*from ww w . j av a 2s. c o m*/ } String logCheckFunction = getLogCheckFunction(loggingLevel); // if (Modules.getLogger(func.getModuleName()).isDebugEnabled()) { // Modules.getLogger(func.getModuleName()).debug(String.format("<function name> returning 0x%X", new Object[1] { new Integer(returnValue) })); // } loadModuleLoggger(func); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), logCheckFunction, "()Z"); Label notDebug = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, notDebug); boolean isReturningVoid = func.getHLEModuleMethod().getReturnType() == void.class; mv.visitInsn(Opcodes.DUP); mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Integer.class)); mv.visitInsn(Opcodes.DUP_X1); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Integer.class), "<init>", "(I)V"); loadImm(1); mv.visitTypeInsn(Opcodes.ANEWARRAY, Type.getInternalName(Object.class)); mv.visitInsn(Opcodes.DUP_X1); mv.visitInsn(Opcodes.SWAP); loadImm(0); mv.visitInsn(Opcodes.SWAP); mv.visitInsn(Opcodes.AASTORE); String prefix = func.isUnimplemented() && !codeBlock.isHLEFunction() ? "Unimplemented " : ""; mv.visitLdcInsn(String.format("%s%s returning %s%s", prefix, func.getFunctionName(), isErrorCode ? "errorCode " : "", isReturningVoid ? "void" : "0x%X")); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(String.class), "format", "(" + Type.getDescriptor(String.class) + "[" + Type.getDescriptor(Object.class) + ")" + Type.getDescriptor(String.class)); loadModuleLoggger(func); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), loggingLevel, "(" + Type.getDescriptor(Object.class) + ")V"); if (!isErrorCode) { ParameterInfo[] parameters = new ClassAnalyzer().getParameters(func.getFunctionName(), func.getHLEModuleMethod().getDeclaringClass()); if (parameters != null) { CompilerParameterReader parameterReader; if (parametersSavedToLocals) { parameterReader = new CompilerLocalVarParameterReader(this, LOCAL_FIRST_SAVED_PARAMETER); } else { parameterReader = new CompilerParameterReader(this); } Annotation[][] paramsAnotations = func.getHLEModuleMethod().getParameterAnnotations(); for (int paramIndex = 0; paramIndex < parameters.length; paramIndex++) { ParameterInfo parameter = parameters[paramIndex]; Class<?> parameterType = parameter.type; LengthInfo lengthInfo = BufferInfo.defaultLengthInfo; int length = BufferInfo.defaultLength; Usage usage = BufferInfo.defaultUsage; boolean debugMemory = false; for (Annotation parameterAnnotation : paramsAnotations[paramIndex]) { if (parameterAnnotation instanceof BufferInfo) { BufferInfo bufferInfo = (BufferInfo) parameterAnnotation; lengthInfo = bufferInfo.lengthInfo(); length = bufferInfo.length(); usage = bufferInfo.usage(); } else if (parameterAnnotation instanceof DebugMemory) { debugMemory = true; } } boolean parameterRead = false; if ((usage == Usage.out || usage == Usage.inout) && (lengthInfo != LengthInfo.unknown || parameterType == TPointer16.class || parameterType == TPointer32.class || parameterType == TPointer64.class)) { loadModuleLoggger(func); loadImm(1); mv.visitTypeInsn(Opcodes.ANEWARRAY, Type.getInternalName(Object.class)); mv.visitInsn(Opcodes.DUP); loadImm(0); Label done = new Label(); Label addressNull = new Label(); parameterReader.loadNextInt(); parameterRead = true; mv.visitInsn(Opcodes.DUP); mv.visitJumpInsn(Opcodes.IFEQ, addressNull); String format = String.format("%s[%s]:%%s", parameter.name, usage); boolean useMemoryDump = true; switch (lengthInfo) { case fixedLength: loadImm(length); break; case nextNextParameter: parameterReader.skipNextInt(); paramIndex++; parameterReader.loadNextInt(); paramIndex++; break; case nextParameter: parameterReader.loadNextInt(); paramIndex++; break; case previousParameter: // Go back to the address parameter parameterReader.rewindPreviousInt(); // Go back to the previous parameter parameterReader.rewindPreviousInt(); // Load the length from the previous parameter parameterReader.loadNextInt(); // Skip again the address parameter // to come back to the above situation parameterReader.skipNextInt(); break; case variableLength: mv.visitInsn(Opcodes.DUP); loadMemory(); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "read32", "(I)I"); break; case returnValue: loadRegister(_v0); break; case unknown: useMemoryDump = false; format = String.format("%s[%s]: 0x%%X", parameter.name, usage); loadMemory(); mv.visitInsn(Opcodes.SWAP); if (parameterType == TPointer64.class) { if (debugMemory) { mv.visitInsn(Opcodes.DUP); loadImm(8); mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "debugMemory", "(II)V"); } mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "read64", "(I)J"); mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Long.class)); mv.visitInsn(Opcodes.DUP); mv.visitInsn(Opcodes.DUP2_X2); mv.visitInsn(Opcodes.POP2); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Long.class), "<init>", "(J)V"); } else if (parameterType == TPointer16.class) { if (debugMemory) { mv.visitInsn(Opcodes.DUP); loadImm(2); mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "debugMemory", "(II)V"); } mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "read16", "(I)I"); mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Integer.class)); mv.visitInsn(Opcodes.DUP_X1); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Integer.class), "<init>", "(I)V"); } else { if (debugMemory) { mv.visitInsn(Opcodes.DUP); loadImm(4); mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "debugMemory", "(II)V"); } mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "read32", "(I)I"); mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Integer.class)); mv.visitInsn(Opcodes.DUP_X1); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Integer.class), "<init>", "(I)V"); } break; default: log.error(String.format("Unimplemented lengthInfo=%s", lengthInfo)); break; } if (useMemoryDump) { if (debugMemory) { mv.visitInsn(Opcodes.DUP2); mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "debugMemory", "(II)V"); } mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Utilities.class), "getMemoryDump", "(II)" + Type.getDescriptor(String.class)); } mv.visitInsn(Opcodes.AASTORE); mv.visitLdcInsn(format); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(String.class), "format", "(" + Type.getDescriptor(String.class) + "[" + Type.getDescriptor(Object.class) + ")" + Type.getDescriptor(String.class)); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), loggingLevel, "(" + Type.getDescriptor(Object.class) + ")V"); mv.visitJumpInsn(Opcodes.GOTO, done); mv.visitLabel(addressNull); mv.visitInsn(Opcodes.POP); mv.visitInsn(Opcodes.POP2); mv.visitInsn(Opcodes.POP2); mv.visitLabel(done); } if (!parameterRead) { if (parameterType == long.class) { parameterReader.skipNextLong(); } else if (parameterType == float.class) { parameterReader.skipNextFloat(); } else { parameterReader.skipNextInt(); } } } } } mv.visitLabel(notDebug); }
From source file:jpcsp.Allegrex.compiler.CompilerContext.java
License:Open Source License
@Override public void compileVFPUInstr(Object cstBefore, int opcode, String mathFunction) { int vsize = getVsize(); boolean useVt = getCodeInstruction().hasFlags(Instruction.FLAG_USES_VFPU_PFXT); if (mathFunction == null && opcode == Opcodes.NOP && !useVt && cstBefore == null && canUseVFPUInt(vsize)) { // VMOV should use int instead of float startPfxCompiled(false);/*from w w w . j a v a 2s .co m*/ for (int n = 0; n < vsize; n++) { prepareVdForStoreInt(n); loadVsInt(n); storeVdInt(n); } endPfxCompiled(vsize, false); } else { startPfxCompiled(true); for (int n = 0; n < vsize; n++) { prepareVdForStore(n); if (cstBefore != null) { mv.visitLdcInsn(cstBefore); } loadVs(n); if (useVt) { loadVt(n); } if (mathFunction != null) { if ("abs".equals(mathFunction)) { mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Math.class), mathFunction, "(F)F"); } else if ("max".equals(mathFunction) || "min".equals(mathFunction)) { mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Math.class), mathFunction, "(FF)F"); } else { mv.visitInsn(Opcodes.F2D); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Math.class), mathFunction, "(D)D"); mv.visitInsn(Opcodes.D2F); } } Label doneStore = null; if (opcode != Opcodes.NOP) { Label doneOpcode = null; if (opcode == Opcodes.FDIV && cstBefore == null) { // if (value1 == 0f && value2 == 0f) { // result = PSP-NaN | (sign(value1) ^ sign(value2)); // } else { // result = value1 / value2; // } doneOpcode = new Label(); doneStore = new Label(); Label notZeroByZero = new Label(); Label notZeroByZeroPop = new Label(); mv.visitInsn(Opcodes.DUP2); mv.visitInsn(Opcodes.FCONST_0); mv.visitInsn(Opcodes.FCMPG); mv.visitJumpInsn(Opcodes.IFNE, notZeroByZeroPop); mv.visitInsn(Opcodes.FCONST_0); mv.visitInsn(Opcodes.FCMPG); mv.visitJumpInsn(Opcodes.IFNE, notZeroByZero); convertVFloatToInt(); loadImm(0x80000000); mv.visitInsn(Opcodes.IAND); mv.visitInsn(Opcodes.SWAP); convertVFloatToInt(); loadImm(0x80000000); mv.visitInsn(Opcodes.IAND); mv.visitInsn(Opcodes.IXOR); storeTmp1(); // Store the NaN value as an "int" to not loose any bit. // Storing as float results in 0x7FC00001 instead of 0x7F800001. mv.visitInsn(Opcodes.DUP2_X2); mv.visitInsn(Opcodes.POP2); loadPspNaNInt(); loadTmp1(); mv.visitInsn(Opcodes.IOR); int preparedRegister = preparedRegisterForStore; storeVdInt(n); preparedRegisterForStore = preparedRegister; mv.visitJumpInsn(Opcodes.GOTO, doneStore); mv.visitLabel(notZeroByZeroPop); mv.visitInsn(Opcodes.POP); mv.visitLabel(notZeroByZero); } mv.visitInsn(opcode); if (doneOpcode != null) { mv.visitLabel(doneOpcode); } } storeVd(n); if (doneStore != null) { mv.visitLabel(doneStore); } } endPfxCompiled(vsize, true); } }
From source file:org.adjective.stout.tools.StackVisualiserMethodVisitor.java
License:Apache License
public void visitInsn(int opcode) { switch (opcode) { case Opcodes.NOP: break;// ww w. j a va 2 s . c om case Opcodes.ACONST_NULL: push("null", Object.class); break; case Opcodes.ICONST_M1: case Opcodes.ICONST_0: case Opcodes.ICONST_1: case Opcodes.ICONST_2: case Opcodes.ICONST_3: case Opcodes.ICONST_4: case Opcodes.ICONST_5: push(Integer.toString(opcode - Opcodes.ICONST_0), Type.INT_TYPE); break; case Opcodes.LCONST_0: case Opcodes.LCONST_1: push(Integer.toString(opcode - Opcodes.LCONST_0), Type.LONG_TYPE); break; case Opcodes.FCONST_0: case Opcodes.FCONST_1: case Opcodes.FCONST_2: push(Integer.toString(opcode - Opcodes.FCONST_0), Type.FLOAT_TYPE); break; case Opcodes.DCONST_0: case Opcodes.DCONST_1: push(Integer.toString(opcode - Opcodes.DCONST_0), Type.DOUBLE_TYPE); break; case Opcodes.IALOAD: case Opcodes.LALOAD: case Opcodes.FALOAD: case Opcodes.DALOAD: case Opcodes.AALOAD: case Opcodes.BALOAD: case Opcodes.CALOAD: case Opcodes.SALOAD: { Type opType = getType(Opcodes.IALOAD, opcode); StackValue idx = pop(Type.INT_TYPE); StackValue arr = popArray(opType); push(arr.description + "[" + idx.description + "]", opType); } break; case Opcodes.IASTORE: case Opcodes.LASTORE: case Opcodes.FASTORE: case Opcodes.DASTORE: case Opcodes.AASTORE: case Opcodes.BASTORE: case Opcodes.CASTORE: case Opcodes.SASTORE: { Type opType = getType(Opcodes.IASTORE, opcode); pop(opType); pop(Type.INT_TYPE); popArray(opType); } break; case Opcodes.POP: pop(); break; case Opcodes.POP2: pop(2); break; case Opcodes.DUP: push(peek()); break; case Opcodes.DUP2: push(peek(2)); push(peek(1)); break; case Opcodes.DUP_X1: { StackValue a = pop(); StackValue b = pop(); push(a); push(b); push(a); } break; case Opcodes.DUP_X2: { StackValue a = pop(); StackValue b = pop(); StackValue c = pop(); push(a); push(c); push(b); push(a); } break; case Opcodes.DUP2_X1: { StackValue a = popValue(false); StackValue b = pop(); StackValue c = pop(); push(b); push(a); push(c); push(b); push(a); } case Opcodes.DUP2_X2: { StackValue a = popValue(false); StackValue b = pop(); StackValue c = popValue(false); StackValue d = pop(); push(b); push(a); push(d); push(c); push(b); push(a); } break; case Opcodes.SWAP: { StackValue a = pop(); StackValue b = pop(); push(a); push(b); } break; case Opcodes.IADD: case Opcodes.LADD: case Opcodes.FADD: case Opcodes.DADD: math(Opcodes.IADD, opcode, "+"); break; case Opcodes.ISUB: case Opcodes.LSUB: case Opcodes.FSUB: case Opcodes.DSUB: math(Opcodes.ISUB, opcode, "-"); break; case Opcodes.IMUL: case Opcodes.LMUL: case Opcodes.FMUL: case Opcodes.DMUL: math(Opcodes.IMUL, opcode, "*"); break; case Opcodes.IDIV: case Opcodes.LDIV: case Opcodes.FDIV: case Opcodes.DDIV: math(Opcodes.IDIV, opcode, "/"); break; case Opcodes.IREM: case Opcodes.LREM: case Opcodes.FREM: case Opcodes.DREM: math(Opcodes.IREM, opcode, "%"); break; case Opcodes.IAND: case Opcodes.LAND: math(Opcodes.IAND, opcode, "&"); break; case Opcodes.IOR: case Opcodes.LOR: math(Opcodes.IOR, opcode, "|"); break; case Opcodes.IXOR: case Opcodes.LXOR: math(Opcodes.IXOR, opcode, "^"); break; case Opcodes.INEG: case Opcodes.LNEG: case Opcodes.FNEG: case Opcodes.DNEG: { Type type = getType(Opcodes.INEG, opcode); StackValue a = pop(type); push("-" + a.description, type); } break; case Opcodes.ISHL: case Opcodes.LSHL: { Type type = getType(Opcodes.ISHL, opcode); StackValue n = pop(Type.INT_TYPE); StackValue a = pop(type); push(a.description + "<<" + n.description, type); } break; case Opcodes.ISHR: case Opcodes.LSHR: { Type type = getType(Opcodes.ISHR, opcode); StackValue n = pop(Type.INT_TYPE); StackValue a = pop(type); push(a.description + ">>" + n.description, type); } break; case Opcodes.IUSHR: case Opcodes.LUSHR: { Type type = getType(Opcodes.IUSHR, opcode); StackValue n = pop(Type.INT_TYPE); StackValue a = pop(type); push(a.description + ">>>" + n.description, type); } case Opcodes.LCMP: { StackValue a = pop(Type.LONG_TYPE); StackValue b = pop(Type.LONG_TYPE); push(a.description + " cmp " + b.description + " {-1|0|1}", Type.LONG_TYPE); } break; case Opcodes.I2L: case Opcodes.I2F: case Opcodes.I2D: case Opcodes.L2I: case Opcodes.L2F: case Opcodes.L2D: case Opcodes.F2I: case Opcodes.F2L: case Opcodes.F2D: case Opcodes.D2I: case Opcodes.D2L: case Opcodes.D2F: case Opcodes.I2B: case Opcodes.I2C: case Opcodes.I2S: cast(opcode); break; case Opcodes.ARETURN: case Opcodes.ATHROW: popObject(); break; case Opcodes.RETURN: break; default: throw new IllegalArgumentException("Unsupported opcode " + opcode + " - " + OPCODES[opcode]); } print(opcode, ""); /* * FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN, * FRETURN, DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW, * MONITORENTER, or MONITOREXIT */ }
From source file:org.decojer.cavaj.readers.asm.ReadMethodVisitor.java
License:Open Source License
@Override public void visitInsn(final int opcode) { T t = null;/*from ww w . jav a 2s . c o m*/ int iValue = Integer.MIN_VALUE; Object oValue = null; switch (opcode) { case Opcodes.NOP: // nothing to do, ignore break; /******* * ADD * *******/ case Opcodes.DADD: t = T.DOUBLE; // fall through case Opcodes.FADD: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IADD: if (t == null) { t = T.INT; } // fall through case Opcodes.LADD: if (t == null) { t = T.LONG; } add(new ADD(this.ops.size(), opcode, this.line, t)); break; /********* * ALOAD * *********/ case Opcodes.AALOAD: t = T.REF; // fall through case Opcodes.BALOAD: if (t == null) { t = T.SMALL; } // fall through case Opcodes.CALOAD: if (t == null) { t = T.CHAR; } // fall through case Opcodes.DALOAD: if (t == null) { t = T.DOUBLE; } // fall through case Opcodes.FALOAD: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IALOAD: if (t == null) { t = T.INT; } // fall through case Opcodes.LALOAD: if (t == null) { t = T.LONG; } // fall through case Opcodes.SALOAD: if (t == null) { t = T.SHORT; } add(new ALOAD(this.ops.size(), opcode, this.line, t)); break; /******* * AND * *******/ case Opcodes.IAND: t = T.AINT; // fall through case Opcodes.LAND: if (t == null) { t = T.LONG; } add(new AND(this.ops.size(), opcode, this.line, t)); break; /*************** * ARRAYLENGTH * ***************/ case Opcodes.ARRAYLENGTH: add(new ARRAYLENGTH(this.ops.size(), opcode, this.line)); break; /********** * ASTORE * **********/ case Opcodes.AASTORE: t = T.REF; // fall through case Opcodes.BASTORE: if (t == null) { t = T.SMALL; } // fall through case Opcodes.CASTORE: if (t == null) { t = T.CHAR; } // fall through case Opcodes.DASTORE: if (t == null) { t = T.DOUBLE; } // fall through case Opcodes.FASTORE: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IASTORE: if (t == null) { t = T.INT; } // fall through case Opcodes.LASTORE: if (t == null) { t = T.LONG; } // fall through case Opcodes.SASTORE: if (t == null) { t = T.SHORT; } add(new ASTORE(this.ops.size(), opcode, this.line, t)); break; /******** * CAST * ********/ case Opcodes.D2F: t = T.DOUBLE; oValue = T.FLOAT; // fall through case Opcodes.D2I: if (t == null) { t = T.DOUBLE; oValue = T.INT; } // fall through case Opcodes.D2L: if (t == null) { t = T.DOUBLE; oValue = T.LONG; } // fall through case Opcodes.F2D: if (t == null) { t = T.FLOAT; oValue = T.DOUBLE; } // fall through case Opcodes.F2I: if (t == null) { t = T.FLOAT; oValue = T.INT; } // fall through case Opcodes.F2L: if (t == null) { t = T.FLOAT; oValue = T.LONG; } // fall through case Opcodes.I2B: if (t == null) { t = T.INT; oValue = T.BYTE; } // fall through case Opcodes.I2C: if (t == null) { t = T.INT; oValue = T.CHAR; } // fall through case Opcodes.I2D: if (t == null) { t = T.INT; oValue = T.DOUBLE; } // fall through case Opcodes.I2F: if (t == null) { t = T.INT; oValue = T.FLOAT; } // fall through case Opcodes.I2L: if (t == null) { t = T.INT; oValue = T.LONG; } // fall through case Opcodes.I2S: if (t == null) { t = T.INT; oValue = T.SHORT; } // fall through case Opcodes.L2D: if (t == null) { t = T.LONG; oValue = T.DOUBLE; } // fall through case Opcodes.L2F: if (t == null) { t = T.LONG; oValue = T.FLOAT; } // fall through case Opcodes.L2I: if (t == null) { t = T.LONG; oValue = T.INT; } assert oValue instanceof T; add(new CAST(this.ops.size(), opcode, this.line, t, (T) oValue)); break; /******* * CMP * *******/ case Opcodes.DCMPG: t = T.DOUBLE; iValue = CMP.T_G; // fall through case Opcodes.DCMPL: if (t == null) { t = T.DOUBLE; iValue = CMP.T_L; } // fall through case Opcodes.FCMPG: if (t == null) { t = T.FLOAT; iValue = CMP.T_G; } // fall through case Opcodes.FCMPL: if (t == null) { t = T.FLOAT; iValue = CMP.T_L; } // fall through case Opcodes.LCMP: if (t == null) { t = T.LONG; iValue = CMP.T_0; } add(new CMP(this.ops.size(), opcode, this.line, t, iValue)); break; /******* * DIV * *******/ case Opcodes.DDIV: t = T.DOUBLE; // fall through case Opcodes.FDIV: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IDIV: if (t == null) { t = T.INT; } // fall through case Opcodes.LDIV: if (t == null) { t = T.LONG; } add(new DIV(this.ops.size(), opcode, this.line, t)); break; /******* * DUP * *******/ case Opcodes.DUP: oValue = DUP.Kind.DUP; // fall through case Opcodes.DUP_X1: if (oValue == null) { oValue = DUP.Kind.DUP_X1; } // fall through case Opcodes.DUP_X2: if (oValue == null) { oValue = DUP.Kind.DUP_X2; } // fall through case Opcodes.DUP2: if (oValue == null) { oValue = DUP.Kind.DUP2; } // fall through case Opcodes.DUP2_X1: if (oValue == null) { oValue = DUP.Kind.DUP2_X1; } // fall through case Opcodes.DUP2_X2: if (oValue == null) { oValue = DUP.Kind.DUP2_X2; } add(new DUP(this.ops.size(), opcode, this.line, (DUP.Kind) oValue)); break; /*********** * MONITOR * ***********/ case Opcodes.MONITORENTER: oValue = MONITOR.Kind.ENTER; // fall through case Opcodes.MONITOREXIT: if (oValue == null) { oValue = MONITOR.Kind.EXIT; } add(new MONITOR(this.ops.size(), opcode, this.line, (MONITOR.Kind) oValue)); break; /******* * MUL * *******/ case Opcodes.DMUL: t = T.DOUBLE; // fall through case Opcodes.FMUL: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IMUL: if (t == null) { t = T.INT; } // fall through case Opcodes.LMUL: if (t == null) { t = T.LONG; } add(new MUL(this.ops.size(), opcode, this.line, t)); break; /******* * NEG * *******/ case Opcodes.DNEG: t = T.DOUBLE; // fall through case Opcodes.FNEG: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.INEG: if (t == null) { t = T.INT; } // fall through case Opcodes.LNEG: if (t == null) { t = T.LONG; } add(new NEG(this.ops.size(), opcode, this.line, t)); break; /****** * OR * ******/ case Opcodes.IOR: t = T.AINT; // fall through case Opcodes.LOR: if (t == null) { t = T.LONG; } add(new OR(this.ops.size(), opcode, this.line, t)); break; /******* * POP * *******/ case Opcodes.POP: oValue = POP.Kind.POP; // fall through case Opcodes.POP2: if (oValue == null) { oValue = POP.Kind.POP2; } add(new POP(this.ops.size(), opcode, this.line, (POP.Kind) oValue)); break; /******** * PUSH * ********/ case Opcodes.ACONST_NULL: t = T.REF; // fall through case Opcodes.DCONST_0: if (t == null) { oValue = 0D; t = T.DOUBLE; } // fall through case Opcodes.FCONST_0: if (t == null) { oValue = 0F; t = T.FLOAT; } // fall through case Opcodes.ICONST_0: if (t == null) { oValue = 0; t = T.getJvmIntT(0); } // fall through case Opcodes.LCONST_0: if (t == null) { oValue = 0L; t = T.LONG; } // fall through case Opcodes.DCONST_1: if (t == null) { oValue = 1D; t = T.DOUBLE; } // fall through case Opcodes.FCONST_1: if (t == null) { oValue = 1F; t = T.FLOAT; } // fall through case Opcodes.ICONST_1: if (t == null) { oValue = 1; t = T.getJvmIntT(1); } // fall through case Opcodes.LCONST_1: if (t == null) { oValue = 1L; t = T.LONG; } // fall through case Opcodes.FCONST_2: if (t == null) { oValue = 2F; t = T.FLOAT; } // fall through case Opcodes.ICONST_2: if (t == null) { oValue = 2; t = T.getJvmIntT(2); } // fall through case Opcodes.ICONST_3: if (t == null) { oValue = 3; t = T.getJvmIntT(3); } // fall through case Opcodes.ICONST_4: if (t == null) { oValue = 4; t = T.getJvmIntT(4); } // fall through case Opcodes.ICONST_5: if (t == null) { oValue = 5; t = T.getJvmIntT(5); } // fall through case Opcodes.ICONST_M1: if (t == null) { oValue = -1; t = T.getJvmIntT(-1); } add(new PUSH(this.ops.size(), opcode, this.line, t, oValue)); break; /******* * REM * *******/ case Opcodes.DREM: t = T.DOUBLE; // fall through case Opcodes.FREM: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IREM: if (t == null) { t = T.INT; } // fall through case Opcodes.LREM: if (t == null) { t = T.LONG; } add(new REM(this.ops.size(), opcode, this.line, t)); break; /********** * RETURN * **********/ case Opcodes.ARETURN: t = T.REF; // fall through case Opcodes.DRETURN: if (t == null) { t = T.DOUBLE; } // fall through case Opcodes.FRETURN: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IRETURN: if (t == null) { t = T.AINT; } // fall through case Opcodes.LRETURN: if (t == null) { t = T.LONG; } // fall through case Opcodes.RETURN: if (t == null) { t = T.VOID; } add(new RETURN(this.ops.size(), opcode, this.line, t)); break; /******* * SHL * *******/ case Opcodes.ISHL: t = T.INT; // fall through case Opcodes.LSHL: if (t == null) { t = T.LONG; } add(new SHL(this.ops.size(), opcode, this.line, t, T.INT)); break; /******* * SHR * *******/ case Opcodes.ISHR: case Opcodes.IUSHR: t = T.INT; // fall through case Opcodes.LSHR: case Opcodes.LUSHR: if (t == null) { t = T.LONG; } add(new SHR(this.ops.size(), opcode, this.line, t, T.INT, opcode == Opcodes.IUSHR || opcode == Opcodes.LUSHR)); break; /******* * SUB * *******/ case Opcodes.DSUB: t = T.DOUBLE; // fall through case Opcodes.FSUB: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.ISUB: if (t == null) { t = T.INT; } // fall through case Opcodes.LSUB: if (t == null) { t = T.LONG; } add(new SUB(this.ops.size(), opcode, this.line, t)); break; /******** * SWAP * ********/ case Opcodes.SWAP: add(new SWAP(this.ops.size(), opcode, this.line)); break; /********* * THROW * *********/ case Opcodes.ATHROW: add(new THROW(this.ops.size(), opcode, this.line)); break; /******* * XOR * *******/ case Opcodes.IXOR: t = T.AINT; // fall through case Opcodes.LXOR: { if (t == null) { t = T.LONG; } add(new XOR(this.ops.size(), opcode, this.line, t)); break; } default: log.warn(getM() + ": Unknown insn opcode '" + opcode + "'!"); } }
From source file:org.elasticsearch.plan.a.External.java
License:Apache License
private void array(final ParserRuleContext source, final ExpressionContext exprctx, final boolean last) { if (current.dimensions == 0) { throw new IllegalArgumentException( error(source) + "Attempting to address a non-array type [" + current.name + "] as an array."); }/*from www.jav a2 s. co m*/ final ExpressionMetadata expremd = adapter.createExpressionMetadata(exprctx); expremd.to = standard.intType; analyzer.visit(exprctx); segments.add(new NodeSegment(exprctx)); final Type type = getTypeWithArrayDimensions(current.struct, current.dimensions - 1); if (last && write != null) { final ExpressionMetadata writeemd = adapter.createExpressionMetadata(write); if (token == CAT) { writeemd.promotion = caster.concat; analyzer.visit(write); writeemd.to = writeemd.from; caster.markCast(writeemd); final Cast cast = caster.getLegalCast(source, standard.stringType, type, false); segments.add(new InstructionSegment(source, Opcodes.DUP2_X1)); segments.add(new ArraySegment(source, type, false)); segments.add(new AppendStringsSegment(source, type, true)); segments.add(new NodeSegment(write)); segments.add(new AppendStringsSegment(write, writeemd.to, false)); segments.add(new ToStringsSegment(source)); segments.add(new CastSegment(source, cast)); if (read) { if (type.metadata.size == 1) { segments.add(new InstructionSegment(source, Opcodes.DUP_X2)); } else if (type.metadata.size == 2) { segments.add(new InstructionSegment(source, Opcodes.DUP2_X2)); } else { throw new IllegalStateException(error(source) + "Unexpected type size."); } } segments.add(new ArraySegment(source, type, true)); } else if (token > 0) { current = type; final Cast[] casts = toNumericCasts(source); writeemd.to = current; analyzer.visit(write); segments.add(new InstructionSegment(source, Opcodes.DUP2)); segments.add(new ArraySegment(source, type, false)); if (read && post) { if (type.metadata.size == 1) { segments.add(new InstructionSegment(source, Opcodes.DUP_X2)); } else if (type.metadata.size == 2) { segments.add(new InstructionSegment(source, Opcodes.DUP2_X2)); } else { throw new IllegalStateException(error(source) + "Unexpected type size."); } } segments.add(new CastSegment(source, casts[0])); segments.add(new NodeSegment(write)); segments.add(new TokenSegment(source, current, token)); segments.add(new CastSegment(source, casts[1])); if (read && !post) { if (type.metadata.size == 1) { segments.add(new InstructionSegment(source, Opcodes.DUP_X2)); } else if (type.metadata.size == 2) { segments.add(new InstructionSegment(source, Opcodes.DUP2_X2)); } else { throw new IllegalStateException(error(source) + "Unexpected type size."); } } segments.add(new ArraySegment(source, type, true)); } else { writeemd.to = type; analyzer.visit(write); segments.add(new NodeSegment(write)); if (read && !post) { if (type.metadata.size == 1) { segments.add(new InstructionSegment(source, Opcodes.DUP_X2)); } else if (type.metadata.size == 2) { segments.add(new InstructionSegment(source, Opcodes.DUP2_X2)); } else { throw new IllegalStateException(error(source) + "Unexpected type size."); } } segments.add(new ArraySegment(source, type, true)); } current = read ? type : standard.voidType; } else { segments.add(new ArraySegment(source, type, false)); current = type; } }
From source file:org.evosuite.instrumentation.error.OverflowInstrumentation.java
License:Open Source License
@Override public void visitInsn(int opcode) { // Overflow checks switch (opcode) { case Opcodes.IADD: case Opcodes.ISUB: case Opcodes.IMUL: mv.visitInsn(Opcodes.DUP2);/*from www.j a v a2 s. c o m*/ mv.visitLdcInsn(opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "underflowDistance", "(III)I", false); insertBranchWithoutException(Opcodes.IFGT); case Opcodes.IDIV: mv.visitInsn(Opcodes.DUP2); mv.visitLdcInsn(opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "overflowDistance", "(III)I", false); insertBranchWithoutException(Opcodes.IFGT); break; case Opcodes.FADD: case Opcodes.FSUB: case Opcodes.FMUL: mv.visitInsn(Opcodes.DUP2); mv.visitLdcInsn(opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "underflowDistance", "(FFI)I", false); insertBranchWithoutException(Opcodes.IFGE); case Opcodes.FDIV: mv.visitInsn(Opcodes.DUP2); mv.visitLdcInsn(opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "overflowDistance", "(FFI)I", false); insertBranchWithoutException(Opcodes.IFGE); break; case Opcodes.DADD: case Opcodes.DSUB: case Opcodes.DMUL: int loc = mv.newLocal(Type.DOUBLE_TYPE); mv.storeLocal(loc); mv.visitInsn(Opcodes.DUP2); mv.loadLocal(loc); mv.visitInsn(Opcodes.DUP2_X2); mv.visitLdcInsn(opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "underflowDistance", "(DDI)I", false); insertBranchWithoutException(Opcodes.IFGE); case Opcodes.DDIV: loc = mv.newLocal(Type.DOUBLE_TYPE); mv.storeLocal(loc); mv.visitInsn(Opcodes.DUP2); mv.loadLocal(loc); mv.visitInsn(Opcodes.DUP2_X2); mv.visitLdcInsn(opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "overflowDistance", "(DDI)I", false); insertBranchWithoutException(Opcodes.IFGE); break; case Opcodes.LADD: case Opcodes.LSUB: case Opcodes.LMUL: int loc2 = mv.newLocal(Type.LONG_TYPE); mv.storeLocal(loc2); mv.visitInsn(Opcodes.DUP2); mv.loadLocal(loc2); mv.visitInsn(Opcodes.DUP2_X2); mv.visitLdcInsn(opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "underflowDistance", "(JJI)I", false); insertBranchWithoutException(Opcodes.IFGE); case Opcodes.LDIV: loc2 = mv.newLocal(Type.LONG_TYPE); mv.storeLocal(loc2); mv.visitInsn(Opcodes.DUP2); mv.loadLocal(loc2); mv.visitInsn(Opcodes.DUP2_X2); mv.visitLdcInsn(opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "overflowDistance", "(JJI)I", false); insertBranchWithoutException(Opcodes.IFGE); break; } }
From source file:org.evosuite.instrumentation.mutation.ReplaceArithmeticOperator.java
License:Open Source License
/** * <p>getInfectionDistance</p> * * @param opcodeOrig a int./*from www.j a v a 2 s.c o m*/ * @param opcodeNew a int. * @return a {@link org.objectweb.asm.tree.InsnList} object. */ public InsnList getInfectionDistance(int opcodeOrig, int opcodeNew) { InsnList distance = new InsnList(); if (opcodesInt.contains(opcodeOrig)) { distance.add(new InsnNode(Opcodes.DUP2)); distance.add(new LdcInsnNode(opcodeOrig)); distance.add(new LdcInsnNode(opcodeNew)); distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ReplaceArithmeticOperator.class), "getInfectionDistanceInt", "(IIII)D", false)); } else if (opcodesLong.contains(opcodeOrig)) { distance.add(new VarInsnNode(Opcodes.LSTORE, numVariable)); distance.add(new InsnNode(Opcodes.DUP2)); distance.add(new VarInsnNode(Opcodes.LLOAD, numVariable)); distance.add(new InsnNode(Opcodes.DUP2_X2)); distance.add(new LdcInsnNode(opcodeOrig)); distance.add(new LdcInsnNode(opcodeNew)); distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ReplaceArithmeticOperator.class), "getInfectionDistanceLong", "(JJII)D", false)); numVariable += 2; } else if (opcodesFloat.contains(opcodeOrig)) { distance.add(new InsnNode(Opcodes.DUP2)); distance.add(new LdcInsnNode(opcodeOrig)); distance.add(new LdcInsnNode(opcodeNew)); distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ReplaceArithmeticOperator.class), "getInfectionDistanceFloat", "(FFII)D", false)); } else if (opcodesDouble.contains(opcodeOrig)) { distance.add(new VarInsnNode(Opcodes.DSTORE, numVariable)); distance.add(new InsnNode(Opcodes.DUP2)); distance.add(new VarInsnNode(Opcodes.DLOAD, numVariable)); distance.add(new InsnNode(Opcodes.DUP2_X2)); distance.add(new LdcInsnNode(opcodeOrig)); distance.add(new LdcInsnNode(opcodeNew)); distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ReplaceArithmeticOperator.class), "getInfectionDistanceDouble", "(DDII)D", false)); numVariable += 2; } return distance; }