本文整理汇总了Java中org.springframework.asm.MethodVisitor.visitInsn方法的典型用法代码示例。如果您正苦于以下问题:Java MethodVisitor.visitInsn方法的具体用法?Java MethodVisitor.visitInsn怎么用?Java MethodVisitor.visitInsn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.asm.MethodVisitor
的用法示例。
在下文中一共展示了MethodVisitor.visitInsn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateCode
import org.springframework.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
// exit type descriptor can be null if both components are literal expressions
computeExitTypeDescriptor();
this.children[0].generateCode(mv, cf);
Label elseTarget = new Label();
Label endOfIf = new Label();
mv.visitInsn(DUP);
mv.visitJumpInsn(IFNULL, elseTarget);
mv.visitJumpInsn(GOTO, endOfIf);
mv.visitLabel(elseTarget);
mv.visitInsn(POP);
this.children[1].generateCode(mv, cf);
if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) {
CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor().charAt(0));
}
mv.visitLabel(endOfIf);
cf.pushDescriptor(this.exitTypeDescriptor);
}
示例2: insertArrayStore
import org.springframework.asm.MethodVisitor; //导入方法依赖的package包/类
/**
* Produce appropriate bytecode to store a stack item in an array. The
* instruction to use varies depending on whether the type
* is a primitive or reference type.
* @param mv where to insert the bytecode
* @param arrayElementType the type of the array elements
*/
public static void insertArrayStore(MethodVisitor mv, String arrayElementType) {
if (arrayElementType.length()==1) {
switch (arrayElementType.charAt(0)) {
case 'I': mv.visitInsn(IASTORE); break;
case 'J': mv.visitInsn(LASTORE); break;
case 'F': mv.visitInsn(FASTORE); break;
case 'D': mv.visitInsn(DASTORE); break;
case 'B': mv.visitInsn(BASTORE); break;
case 'C': mv.visitInsn(CASTORE); break;
case 'S': mv.visitInsn(SASTORE); break;
case 'Z': mv.visitInsn(BASTORE); break;
default:
throw new IllegalArgumentException("Unexpected arraytype "+arrayElementType.charAt(0));
}
}
else {
mv.visitInsn(AASTORE);
}
}
示例3: insertOptimalLoad
import org.springframework.asm.MethodVisitor; //导入方法依赖的package包/类
/**
* Create the optimal instruction for loading a number on the stack.
* @param mv where to insert the bytecode
* @param value the value to be loaded
*/
public static void insertOptimalLoad(MethodVisitor mv, int value) {
if (value < 6) {
mv.visitInsn(ICONST_0+value);
}
else if (value < Byte.MAX_VALUE) {
mv.visitIntInsn(BIPUSH, value);
}
else if (value < Short.MAX_VALUE) {
mv.visitIntInsn(SIPUSH, value);
}
else {
mv.visitLdcInsn(value);
}
}
示例4: generateCode
import org.springframework.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
int intValue = (Integer) this.value.getValue();
if (intValue == -1) {
// Not sure we can get here because -1 is OpMinus
mv.visitInsn(ICONST_M1);
}
else if (intValue >= 0 && intValue < 6) {
mv.visitInsn(ICONST_0 + intValue);
}
else {
mv.visitLdcInsn(intValue);
}
cf.pushDescriptor(this.exitTypeDescriptor);
}
示例5: generateCode
import org.springframework.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
ReflectiveConstructorExecutor executor = ((ReflectiveConstructorExecutor) this.cachedExecutor);
Constructor<?> constructor = executor.getConstructor();
String classDesc = constructor.getDeclaringClass().getName().replace('.', '/');
mv.visitTypeInsn(NEW, classDesc);
mv.visitInsn(DUP);
// children[0] is the type of the constructor, don't want to include that in argument processing
SpelNodeImpl[] arguments = new SpelNodeImpl[children.length - 1];
System.arraycopy(children, 1, arguments, 0, children.length - 1);
generateCodeForArguments(mv, cf, constructor, arguments);
mv.visitMethodInsn(INVOKESPECIAL, classDesc, "<init>", CodeFlow.createSignatureDescriptor(constructor), false);
cf.pushDescriptor(this.exitTypeDescriptor);
}
示例6: generateCode
import org.springframework.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void generateCode(String propertyName, MethodVisitor mv, CodeFlow cf) {
boolean isStatic = Modifier.isStatic(this.member.getModifiers());
String descriptor = cf.lastDescriptor();
String classDesc = this.member.getDeclaringClass().getName().replace('.', '/');
if (!isStatic) {
if (descriptor == null) {
cf.loadTarget(mv);
}
if (descriptor == null || !classDesc.equals(descriptor.substring(1))) {
mv.visitTypeInsn(CHECKCAST, classDesc);
}
}
else {
if (descriptor != null) {
// A static field/method call will not consume what is on the stack,
// it needs to be popped off.
mv.visitInsn(POP);
}
}
if (this.member instanceof Method) {
mv.visitMethodInsn((isStatic ? INVOKESTATIC : INVOKEVIRTUAL), classDesc, this.member.getName(),
CodeFlow.createSignatureDescriptor((Method) this.member), false);
}
else {
mv.visitFieldInsn((isStatic ? GETSTATIC : GETFIELD), classDesc, this.member.getName(),
CodeFlow.toJvmDescriptor(((Field) this.member).getType()));
}
}
示例7: generateCode
import org.springframework.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
getLeftOperand().generateCode(mv, cf);
String leftDesc = getLeftOperand().exitTypeDescriptor;
CodeFlow.insertNumericUnboxOrPrimitiveTypeCoercion(mv, leftDesc, this.exitTypeDescriptor.charAt(0));
if (this.children.length > 1) {
cf.enterCompilationScope();
getRightOperand().generateCode(mv, cf);
String rightDesc = getRightOperand().exitTypeDescriptor;
cf.exitCompilationScope();
CodeFlow.insertNumericUnboxOrPrimitiveTypeCoercion(mv, rightDesc, this.exitTypeDescriptor.charAt(0));
switch (this.exitTypeDescriptor.charAt(0)) {
case 'I':
mv.visitInsn(IDIV);
break;
case 'J':
mv.visitInsn(LDIV);
break;
case 'F':
mv.visitInsn(FDIV);
break;
case 'D':
mv.visitInsn(DDIV);
break;
default:
throw new IllegalStateException(
"Unrecognized exit type descriptor: '" + this.exitTypeDescriptor + "'");
}
}
cf.pushDescriptor(this.exitTypeDescriptor);
}
示例8: generateCode
import org.springframework.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
getLeftOperand().generateCode(mv, cf);
String leftDesc = getLeftOperand().exitTypeDescriptor;
CodeFlow.insertNumericUnboxOrPrimitiveTypeCoercion(mv, leftDesc, this.exitTypeDescriptor.charAt(0));
if (this.children.length > 1) {
cf.enterCompilationScope();
getRightOperand().generateCode(mv, cf);
String rightDesc = getRightOperand().exitTypeDescriptor;
cf.exitCompilationScope();
CodeFlow.insertNumericUnboxOrPrimitiveTypeCoercion(mv, rightDesc, this.exitTypeDescriptor.charAt(0));
switch (this.exitTypeDescriptor.charAt(0)) {
case 'I':
mv.visitInsn(IMUL);
break;
case 'J':
mv.visitInsn(LMUL);
break;
case 'F':
mv.visitInsn(FMUL);
break;
case 'D':
mv.visitInsn(DMUL);
break;
default:
throw new IllegalStateException(
"Unrecognized exit type descriptor: '" + this.exitTypeDescriptor + "'");
}
}
cf.pushDescriptor(this.exitTypeDescriptor);
}
示例9: generateClinitCode
import org.springframework.asm.MethodVisitor; //导入方法依赖的package包/类
void generateClinitCode(String clazzname, String constantFieldName, MethodVisitor mv, CodeFlow codeflow, boolean nested) {
mv.visitTypeInsn(NEW, "java/util/ArrayList");
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V", false);
if (!nested) {
mv.visitFieldInsn(PUTSTATIC, clazzname, constantFieldName, "Ljava/util/List;");
}
int childcount = getChildCount();
for (int c=0; c < childcount; c++) {
if (!nested) {
mv.visitFieldInsn(GETSTATIC, clazzname, constantFieldName, "Ljava/util/List;");
}
else {
mv.visitInsn(DUP);
}
// The children might be further lists if they are not constants. In this
// situation do not call back into generateCode() because it will register another clinit adder.
// Instead, directly build the list here:
if (children[c] instanceof InlineList) {
((InlineList)children[c]).generateClinitCode(clazzname, constantFieldName, mv, codeflow, true);
}
else {
children[c].generateCode(mv, codeflow);
if (CodeFlow.isPrimitive(codeflow.lastDescriptor())) {
CodeFlow.insertBoxIfNecessary(mv, codeflow.lastDescriptor().charAt(0));
}
}
mv.visitMethodInsn(INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", true);
mv.visitInsn(POP);
}
}
示例10: generateCode
import org.springframework.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
getLeftOperand().generateCode(mv, cf);
String leftDesc = getLeftOperand().exitTypeDescriptor;
CodeFlow.insertNumericUnboxOrPrimitiveTypeCoercion(mv, leftDesc, this.exitTypeDescriptor.charAt(0));
if (this.children.length > 1) {
cf.enterCompilationScope();
getRightOperand().generateCode(mv, cf);
String rightDesc = getRightOperand().exitTypeDescriptor;
cf.exitCompilationScope();
CodeFlow.insertNumericUnboxOrPrimitiveTypeCoercion(mv, rightDesc, this.exitTypeDescriptor.charAt(0));
switch (this.exitTypeDescriptor.charAt(0)) {
case 'I':
mv.visitInsn(IREM);
break;
case 'J':
mv.visitInsn(LREM);
break;
case 'F':
mv.visitInsn(FREM);
break;
case 'D':
mv.visitInsn(DREM);
break;
default:
throw new IllegalStateException(
"Unrecognized exit type descriptor: '" + this.exitTypeDescriptor + "'");
}
}
cf.pushDescriptor(this.exitTypeDescriptor);
}
示例11: insertAnyNecessaryTypeConversionBytecodes
import org.springframework.asm.MethodVisitor; //导入方法依赖的package包/类
/**
* Insert any necessary numeric conversion bytecodes based upon what is on the stack and the desired target type.
* @param mv the method visitor into which instructions should be placed
* @param targetDescriptor the (primitive) descriptor of the target type
* @param stackDescriptor the descriptor of the operand on top of the stack
*/
public static void insertAnyNecessaryTypeConversionBytecodes(MethodVisitor mv, char targetDescriptor, String stackDescriptor) {
if (CodeFlow.isPrimitive(stackDescriptor)) {
char stackTop = stackDescriptor.charAt(0);
if (stackTop=='I' || stackTop=='B' || stackTop=='S' || stackTop=='C') {
if (targetDescriptor=='D') {
mv.visitInsn(I2D);
}
else if (targetDescriptor=='F') {
mv.visitInsn(I2F);
}
else if (targetDescriptor=='J') {
mv.visitInsn(I2L);
}
else if (targetDescriptor=='I') {
// nop
}
else {
throw new IllegalStateException("cannot get from "+stackTop+" to "+targetDescriptor);
}
}
else if (stackTop=='J') {
if (targetDescriptor=='D') {
mv.visitInsn(L2D);
}
else if (targetDescriptor=='F') {
mv.visitInsn(L2F);
}
else if (targetDescriptor=='J') {
// nop
}
else if (targetDescriptor=='I') {
mv.visitInsn(L2I);
}
else {
throw new IllegalStateException("cannot get from "+stackTop+" to "+targetDescriptor);
}
}
else if (stackTop=='F') {
if (targetDescriptor=='D') {
mv.visitInsn(F2D);
}
else if (targetDescriptor=='F') {
// nop
}
else if (targetDescriptor=='J') {
mv.visitInsn(F2L);
}
else if (targetDescriptor=='I') {
mv.visitInsn(F2I);
}
else {
throw new IllegalStateException("cannot get from "+stackTop+" to "+targetDescriptor);
}
}
else if (stackTop=='D') {
if (targetDescriptor=='D') {
// nop
}
else if (targetDescriptor=='F') {
mv.visitInsn(D2F);
}
else if (targetDescriptor=='J') {
mv.visitInsn(D2L);
}
else if (targetDescriptor=='I') {
mv.visitInsn(D2I);
}
else {
throw new IllegalStateException("cannot get from "+stackDescriptor+" to "+targetDescriptor);
}
}
}
}
示例12: generateCode
import org.springframework.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
getLeftOperand().generateCode(mv, cf);
String leftDesc = getLeftOperand().exitTypeDescriptor;
CodeFlow.insertNumericUnboxOrPrimitiveTypeCoercion(mv, leftDesc, this.exitTypeDescriptor.charAt(0));
if (this.children.length > 1) {
cf.enterCompilationScope();
getRightOperand().generateCode(mv, cf);
String rightDesc = getRightOperand().exitTypeDescriptor;
cf.exitCompilationScope();
CodeFlow.insertNumericUnboxOrPrimitiveTypeCoercion(mv, rightDesc, this.exitTypeDescriptor.charAt(0));
switch (this.exitTypeDescriptor.charAt(0)) {
case 'I':
mv.visitInsn(ISUB);
break;
case 'J':
mv.visitInsn(LSUB);
break;
case 'F':
mv.visitInsn(FSUB);
break;
case 'D':
mv.visitInsn(DSUB);
break;
default:
throw new IllegalStateException(
"Unrecognized exit type descriptor: '" + this.exitTypeDescriptor + "'");
}
}
else {
switch (this.exitTypeDescriptor.charAt(0)) {
case 'I':
mv.visitInsn(INEG);
break;
case 'J':
mv.visitInsn(LNEG);
break;
case 'F':
mv.visitInsn(FNEG);
break;
case 'D':
mv.visitInsn(DNEG);
break;
default:
throw new IllegalStateException(
"Unrecognized exit type descriptor: '" + this.exitTypeDescriptor + "'");
}
}
cf.pushDescriptor(this.exitTypeDescriptor);
}
示例13: generateCode
import org.springframework.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
if (this.exitTypeDescriptor == "Ljava/lang/String") {
mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V", false);
walk(mv,cf,getLeftOperand());
walk(mv,cf,getRightOperand());
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false);
}
else {
getLeftOperand().generateCode(mv, cf);
String leftDesc = getLeftOperand().exitTypeDescriptor;
CodeFlow.insertNumericUnboxOrPrimitiveTypeCoercion(mv, leftDesc, this.exitTypeDescriptor.charAt(0));
if (this.children.length > 1) {
cf.enterCompilationScope();
getRightOperand().generateCode(mv, cf);
String rightDesc = getRightOperand().exitTypeDescriptor;
cf.exitCompilationScope();
CodeFlow.insertNumericUnboxOrPrimitiveTypeCoercion(mv, rightDesc, this.exitTypeDescriptor.charAt(0));
switch (this.exitTypeDescriptor.charAt(0)) {
case 'I':
mv.visitInsn(IADD);
break;
case 'J':
mv.visitInsn(LADD);
break;
case 'F':
mv.visitInsn(FADD);
break;
case 'D':
mv.visitInsn(DADD);
break;
default:
throw new IllegalStateException(
"Unrecognized exit type descriptor: '" + this.exitTypeDescriptor + "'");
}
}
}
cf.pushDescriptor(this.exitTypeDescriptor);
}
示例14: generateCode
import org.springframework.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
String leftDesc = getLeftOperand().exitTypeDescriptor;
String rightDesc = getRightOperand().exitTypeDescriptor;
Label elseTarget = new Label();
Label endOfIf = new Label();
boolean leftPrim = CodeFlow.isPrimitive(leftDesc);
boolean rightPrim = CodeFlow.isPrimitive(rightDesc);
DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility(leftDesc, rightDesc, leftActualDescriptor, rightActualDescriptor);
if (dc.areNumbers && dc.areCompatible) {
char targetType = dc.compatibleType;
getLeftOperand().generateCode(mv, cf);
if (!leftPrim) {
CodeFlow.insertUnboxInsns(mv, targetType, leftDesc);
}
cf.enterCompilationScope();
getRightOperand().generateCode(mv, cf);
cf.exitCompilationScope();
if (!rightPrim) {
CodeFlow.insertUnboxInsns(mv, targetType, rightDesc);
}
// assert: SpelCompiler.boxingCompatible(leftDesc, rightDesc)
if (targetType == 'D') {
mv.visitInsn(DCMPL);
mv.visitJumpInsn(IFEQ, elseTarget);
}
else if (targetType == 'F') {
mv.visitInsn(FCMPL);
mv.visitJumpInsn(IFEQ, elseTarget);
}
else if (targetType == 'J') {
mv.visitInsn(LCMP);
mv.visitJumpInsn(IFEQ, elseTarget);
}
else if (targetType == 'I' || targetType == 'Z') {
mv.visitJumpInsn(IF_ICMPEQ, elseTarget);
}
else {
throw new IllegalStateException("Unexpected descriptor "+leftDesc);
}
}
else {
getLeftOperand().generateCode(mv, cf);
getRightOperand().generateCode(mv, cf);
mv.visitJumpInsn(IF_ACMPEQ, elseTarget);
}
mv.visitInsn(ICONST_1);
mv.visitJumpInsn(GOTO,endOfIf);
mv.visitLabel(elseTarget);
mv.visitInsn(ICONST_0);
mv.visitLabel(endOfIf);
cf.pushDescriptor("Z");
}
示例15: generateComparisonCode
import org.springframework.asm.MethodVisitor; //导入方法依赖的package包/类
/**
* Numeric comparison operators share very similar generated code, only differing in
* two comparison instructions.
*/
protected void generateComparisonCode(MethodVisitor mv, CodeFlow cf, int compInstruction1, int compInstruction2) {
String leftDesc = getLeftOperand().exitTypeDescriptor;
String rightDesc = getRightOperand().exitTypeDescriptor;
boolean unboxLeft = !CodeFlow.isPrimitive(leftDesc);
boolean unboxRight = !CodeFlow.isPrimitive(rightDesc);
DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility(leftDesc, rightDesc,
this.leftActualDescriptor, this.rightActualDescriptor);
char targetType = dc.compatibleType;//CodeFlow.toPrimitiveTargetDesc(leftDesc);
getLeftOperand().generateCode(mv, cf);
if (unboxLeft) {
CodeFlow.insertUnboxInsns(mv, targetType, leftDesc);
}
cf.enterCompilationScope();
getRightOperand().generateCode(mv, cf);
cf.exitCompilationScope();
if (unboxRight) {
CodeFlow.insertUnboxInsns(mv, targetType, rightDesc);
}
// assert: SpelCompiler.boxingCompatible(leftDesc, rightDesc)
Label elseTarget = new Label();
Label endOfIf = new Label();
if (targetType=='D') {
mv.visitInsn(DCMPG);
mv.visitJumpInsn(compInstruction1, elseTarget);
}
else if (targetType=='F') {
mv.visitInsn(FCMPG);
mv.visitJumpInsn(compInstruction1, elseTarget);
}
else if (targetType=='J') {
mv.visitInsn(LCMP);
mv.visitJumpInsn(compInstruction1, elseTarget);
}
else if (targetType=='I') {
mv.visitJumpInsn(compInstruction2, elseTarget);
}
else {
throw new IllegalStateException("Unexpected descriptor "+leftDesc);
}
// Other numbers are not yet supported (isCompilable will not have returned true)
mv.visitInsn(ICONST_1);
mv.visitJumpInsn(GOTO,endOfIf);
mv.visitLabel(elseTarget);
mv.visitInsn(ICONST_0);
mv.visitLabel(endOfIf);
cf.pushDescriptor("Z");
}