当前位置: 首页>>代码示例>>Java>>正文


Java MethodVisitor.visitLabel方法代码示例

本文整理汇总了Java中org.objectweb.asm.MethodVisitor.visitLabel方法的典型用法代码示例。如果您正苦于以下问题:Java MethodVisitor.visitLabel方法的具体用法?Java MethodVisitor.visitLabel怎么用?Java MethodVisitor.visitLabel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.objectweb.asm.MethodVisitor的用法示例。


在下文中一共展示了MethodVisitor.visitLabel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: insertCollectionStart

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void insertCollectionStart(MethodVisitor mv) {
    // collection.iterator()
    mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Collection", "iterator", "()Ljava/util/Iterator;", true);
    mv.visitVarInsn(ASTORE, varArray);

    mv.visitLabel(loopStart);

    // Append a new frame preserving the same locals from the last one
    mv.visitFrame(F_APPEND, 2, new Object[]{BUILDER.getInternalName(), "java/util/Iterator"}, 0, null);

    // if(iterator.hasNext()) break;
    mv.visitVarInsn(ALOAD, varArray);
    mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Iterator", "hasNext", "()Z", true);
    mv.visitJumpInsn(IFEQ, loopEnd);

    // (String)iterator.next()
    mv.visitVarInsn(ALOAD, varArray);
    mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Iterator", "next", "()Ljava/lang/Object;", true);
    mv.visitTypeInsn(CHECKCAST, Type.getInternalName(member.component));
    mv.visitVarInsn(ASTORE, varObject);
}
 
开发者ID:Guichaguri,项目名称:FastMustache,代码行数:22,代码来源:LoopSection.java

示例2: visit

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public Object visit(ASTMatchCaseHeadExpr node, Object data) throws CompileException {

  Label match_case_label = node.getMatchCaseLabel();
  Debug.assertion(match_case_label != null, "match_case_label should not be invalid");

  MethodVisitor mv = getClosestFunContext().getMethodVisitor();

  mv.visitLabel(match_case_label);

  Token t = node.getAstToken();

  switch (t.kind) {
  case ParserConstants.CASE: {
    Reduction reduce = popReduction();
    Debug.assertion(reduce != null, "Match Condition Reduction should not be invalid");
  }
    break;
  default:
    // do nothing
  }

  return null;
}
 
开发者ID:Samsung,项目名称:MeziLang,代码行数:25,代码来源:ASTCompileVisitor.java

示例3: generateUpdateMethod

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void generateUpdateMethod(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor,
        String argsClassInternalName,
        String constDesc, Parameter[] parameters) {
    MethodVisitor mv;
    mv = cw.visitMethod(ACC_PUBLIC, "update", "()Lio/primeval/reflex/arguments/Arguments;", null, null);
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitTypeInsn(NEW, argsClassInternalName);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, selfClassInternalName, "parameters", "Ljava/util/List;");
    for (int i = 0; i < parameters.length; i++) {
        Parameter parameter = parameters[i];
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, selfClassInternalName, parameter.getName(), Type.getDescriptor(parameter.getType()));
    }
    mv.visitMethodInsn(INVOKESPECIAL, argsClassInternalName, "<init>", constDesc, false);
    mv.visitInsn(ARETURN);
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitLocalVariable("this", selfClassDescriptor, null, l0, l1, 0);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}
 
开发者ID:primeval-io,项目名称:primeval-reflex,代码行数:26,代码来源:MethodArgumentssUpdaterGenerator.java

示例4: writeSetter

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void writeSetter(ClassVisitor visitor, Type generatedType, String propertyName, Class<?> propertyClass, WeaklyTypeReferencingMethod<?, ?> weakSetter) {
    Type propertyType = Type.getType(propertyClass);
    Label calledOutsideOfConstructor = new Label();

    Method setter = weakSetter.getMethod();

    // the regular typed setter
    String methodDescriptor = Type.getMethodDescriptor(Type.VOID_TYPE, propertyType);
    MethodVisitor methodVisitor = declareMethod(visitor, setter.getName(), methodDescriptor, AsmClassGeneratorUtils.signature(setter));

    putCanCallSettersFieldValueOnStack(methodVisitor, generatedType);
    jumpToLabelIfStackEvaluatesToTrue(methodVisitor, calledOutsideOfConstructor);
    throwExceptionBecauseCalledOnItself(methodVisitor);

    methodVisitor.visitLabel(calledOutsideOfConstructor);
    putStateFieldValueOnStack(methodVisitor, generatedType);
    putConstantOnStack(methodVisitor, propertyName);
    putFirstMethodArgumentOnStack(methodVisitor, propertyType);
    if (propertyClass.isPrimitive()) {
        boxType(methodVisitor, propertyClass);
    }
    invokeStateSetMethod(methodVisitor);

    finishVisitingMethod(methodVisitor);
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:26,代码来源:ManagedProxyClassGenerator.java

示例5: generateUpdaterMethod

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void generateUpdaterMethod(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor,
        String updaterClassInternalName,
        String constDesc, Parameter[] parameters) {
    MethodVisitor mv;

    mv = cw.visitMethod(ACC_PUBLIC, "updater", "()Lio/primeval/reflex/arguments/ArgumentsUpdater;", null, null);
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitTypeInsn(NEW, updaterClassInternalName);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, selfClassInternalName, "parameters", "Ljava/util/List;");
    for (int i = 0; i < parameters.length; i++) {
        Parameter parameter = parameters[i];
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, selfClassInternalName, parameter.getName(), Type.getDescriptor(parameter.getType()));
    }
    mv.visitMethodInsn(INVOKESPECIAL, updaterClassInternalName, "<init>", constDesc, false);
    mv.visitInsn(ARETURN);
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitLocalVariable("this", selfClassDescriptor, null, l0, l1, 0);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}
 
开发者ID:primeval-io,项目名称:primeval-reflex,代码行数:27,代码来源:MethodArgumentsGenerator.java

示例6: writeNonAbstractMethodWrapper

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void writeNonAbstractMethodWrapper(ClassVisitor visitor, Type generatedType, Class<?> managedTypeClass, Method method) {
    Label start = new Label();
    Label end = new Label();
    Label handler = new Label();

    MethodVisitor methodVisitor = declareMethod(visitor, method);

    methodVisitor.visitTryCatchBlock(start, end, handler, null);

    setCanCallSettersField(methodVisitor, generatedType, false);

    methodVisitor.visitLabel(start);
    invokeSuperMethod(methodVisitor, managedTypeClass, method);
    methodVisitor.visitLabel(end);

    setCanCallSettersField(methodVisitor, generatedType, true);
    methodVisitor.visitInsn(ARETURN);

    methodVisitor.visitLabel(handler);
    setCanCallSettersField(methodVisitor, generatedType, true);
    methodVisitor.visitInsn(ATHROW);

    methodVisitor.visitMaxs(0, 0);
    methodVisitor.visitEnd();
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:26,代码来源:ManagedProxyClassGenerator.java

示例7: createConstructor

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void createConstructor(ClassWriter cw, String classDesc) {
    Label start = new Label();
    Label end = new Label();

    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    mv.visitCode();
    mv.visitLabel(start);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKESPECIAL, BytecodeGenerator.OBJECT.getInternalName(), "<init>", "()V", false);
    mv.visitInsn(RETURN);
    mv.visitLabel(end);
    mv.visitLocalVariable("this", classDesc, null, start, end, 0);
    mv.visitMaxs(1, 1);
    mv.visitEnd();
}
 
开发者ID:Guichaguri,项目名称:FastMustache,代码行数:16,代码来源:MustacheCompiler.java

示例8: generateParametersGetter

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void generateParametersGetter(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor) {
    MethodVisitor mv;
    mv = cw.visitMethod(ACC_PUBLIC, "parameters", "()Ljava/util/List;", "()Ljava/util/List<Ljava/lang/reflect/Parameter;>;", null);
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, selfClassInternalName, "parameters", "Ljava/util/List;");
    mv.visitInsn(ARETURN);
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitLocalVariable("this", selfClassDescriptor, null, l0, l1, 0);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}
 
开发者ID:primeval-io,项目名称:primeval-reflex,代码行数:16,代码来源:MethodArgumentsGenerator.java

示例9: addGetMetaClass

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private void addGetMetaClass() {
    Label lookup = new Label();

    MethodVisitor methodVisitor = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, "getMetaClass", RETURN_META_CLASS, null, null);
    methodVisitor.visitCode();

    // if (this.metaClass != null) { return this.metaClass; }
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    methodVisitor.visitFieldInsn(Opcodes.GETFIELD, className, META_CLASS_FIELD, META_CLASS_TYPE.getDescriptor());
    methodVisitor.visitInsn(Opcodes.DUP);
    methodVisitor.visitJumpInsn(Opcodes.IFNULL, lookup);
    methodVisitor.visitInsn(Opcodes.ARETURN);

    methodVisitor.visitLabel(lookup);
    methodVisitor.visitFrame(Opcodes.F_NEW, 1, new Object[]{className}, 1, new Object[]{META_CLASS_TYPE.getInternalName()});
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); // for storing to field

    // GroovySystem.getMetaClassRegistry()
    methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, GROOVY_SYSTEM_TYPE.getInternalName(), "getMetaClassRegistry", RETURN_META_CLASS_REGISTRY, false);

    // this.getClass()
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, OBJECT_TYPE.getInternalName(), "getClass", RETURN_CLASS, false);

    // getMetaClass(..)
    methodVisitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, META_CLASS_REGISTRY_TYPE.getInternalName(), "getMetaClass", RETURN_META_CLASS_FROM_CLASS, true);

    // this.metaClass = <value>
    methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, className, META_CLASS_FIELD, META_CLASS_TYPE.getDescriptor());

    // return this.metaClass
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    methodVisitor.visitFieldInsn(Opcodes.GETFIELD, className, META_CLASS_FIELD, META_CLASS_TYPE.getDescriptor());

    methodVisitor.visitInsn(Opcodes.ARETURN);
    methodVisitor.visitMaxs(4, 1);
    methodVisitor.visitEnd();
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:39,代码来源:MixInLegacyTypesClassLoader.java

示例10: insertGetString

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
static private void insertGetString(ClassWriter cw, String classNameInternal, ArrayList<Field> fields) {
	int maxStack = 6;
	MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "getString", "(Ljava/lang/Object;I)Ljava/lang/String;", null,
			null);
	mv.visitCode();
	mv.visitVarInsn(ILOAD, 2);

	if (!fields.isEmpty()) {
		maxStack--;
		Label[] labels = new Label[fields.size()];
		Label labelForInvalidTypes = new Label();
		boolean hasAnyBadTypeLabel = false;
		for (int i = 0, n = labels.length; i < n; i++) {
			if (fields.get(i).getType().equals(String.class))
				labels[i] = new Label();
			else {
				labels[i] = labelForInvalidTypes;
				hasAnyBadTypeLabel = true;
			}
		}
		Label defaultLabel = new Label();
		mv.visitTableSwitchInsn(0, labels.length - 1, defaultLabel, labels);

		for (int i = 0, n = labels.length; i < n; i++) {
			if (!labels[i].equals(labelForInvalidTypes)) {
				mv.visitLabel(labels[i]);
				mv.visitFrame(F_SAME, 0, null, 0, null);
				mv.visitVarInsn(ALOAD, 1);
				mv.visitTypeInsn(CHECKCAST, classNameInternal);
				mv.visitFieldInsn(GETFIELD, classNameInternal, fields.get(i).getName(), "Ljava/lang/String;");
				mv.visitInsn(ARETURN);
			}
		}
		// Rest of fields: different type
		if (hasAnyBadTypeLabel) {
			mv.visitLabel(labelForInvalidTypes);
			mv.visitFrame(F_SAME, 0, null, 0, null);
			insertThrowExceptionForFieldType(mv, "String");
		}
		// Default: field not found
		mv.visitLabel(defaultLabel);
		mv.visitFrame(F_SAME, 0, null, 0, null);
	}
	insertThrowExceptionForFieldNotFound(mv);
	mv.visitMaxs(maxStack, 3);
	mv.visitEnd();
}
 
开发者ID:HankXV,项目名称:Limitart,代码行数:48,代码来源:FieldAccess.java

示例11: accept

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@Override
public void accept(final MethodVisitor cv) {
    cv.visitLabel(getLabel());
}
 
开发者ID:ItzSomebody,项目名称:Simple-JAR-Watermark,代码行数:5,代码来源:LabelNode.java

示例12: insertGetObject

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
static private void insertGetObject(ClassWriter cw, String classNameInternal, ArrayList<Field> fields) {
	int maxStack = 6;
	MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "get", "(Ljava/lang/Object;I)Ljava/lang/Object;", null, null);
	mv.visitCode();
	mv.visitVarInsn(ILOAD, 2);

	if (!fields.isEmpty()) {
		maxStack--;
		Label[] labels = new Label[fields.size()];
		for (int i = 0, n = labels.length; i < n; i++)
			labels[i] = new Label();
		Label defaultLabel = new Label();
		mv.visitTableSwitchInsn(0, labels.length - 1, defaultLabel, labels);

		for (int i = 0, n = labels.length; i < n; i++) {
			Field field = fields.get(i);

			mv.visitLabel(labels[i]);
			mv.visitFrame(F_SAME, 0, null, 0, null);
			mv.visitVarInsn(ALOAD, 1);
			mv.visitTypeInsn(CHECKCAST, classNameInternal);
			mv.visitFieldInsn(GETFIELD, classNameInternal, field.getName(), Type.getDescriptor(field.getType()));

			Type fieldType = Type.getType(field.getType());
			switch (fieldType.getSort()) {
			case Type.BOOLEAN:
				mv.visitMethodInsn(INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;");
				break;
			case Type.BYTE:
				mv.visitMethodInsn(INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;");
				break;
			case Type.CHAR:
				mv.visitMethodInsn(INVOKESTATIC, "java/lang/Character", "valueOf", "(C)Ljava/lang/Character;");
				break;
			case Type.SHORT:
				mv.visitMethodInsn(INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;");
				break;
			case Type.INT:
				mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;");
				break;
			case Type.FLOAT:
				mv.visitMethodInsn(INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;");
				break;
			case Type.LONG:
				mv.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;");
				break;
			case Type.DOUBLE:
				mv.visitMethodInsn(INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;");
				break;
			}

			mv.visitInsn(ARETURN);
		}

		mv.visitLabel(defaultLabel);
		mv.visitFrame(F_SAME, 0, null, 0, null);
	}
	insertThrowExceptionForFieldNotFound(mv);
	mv.visitMaxs(maxStack, 3);
	mv.visitEnd();
}
 
开发者ID:HankXV,项目名称:Limitart,代码行数:63,代码来源:FieldAccess.java

示例13: applyServiceInjectionToGetter

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
public void applyServiceInjectionToGetter(PropertyMetaData property, Method getter) throws Exception {
    // GENERATE public <type> <getter>() { if (<field> == null) { <field> = getServices().get(getClass().getDeclaredMethod(<getter-name>).getGenericReturnType()); } return <field> }
    String getterName = getter.getName();
    Type returnType = Type.getType(getter.getReturnType());
    String methodDescriptor = Type.getMethodDescriptor(returnType);
    Type serviceType = Type.getType(property.getType());
    String propFieldName = propFieldName(property);

    MethodVisitor methodVisitor = visitor.visitMethod(Opcodes.ACC_PUBLIC, getterName, methodDescriptor, signature(getter), EMPTY_STRINGS);
    methodVisitor.visitCode();

    // if (this.<field> == null) { ...  }

    // this.field
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    methodVisitor.visitFieldInsn(Opcodes.GETFIELD, generatedType.getInternalName(), propFieldName, serviceType.getDescriptor());

    Label alreadyLoaded = new Label();
    methodVisitor.visitJumpInsn(Opcodes.IFNONNULL, alreadyLoaded);

    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);

    // this.getServices()
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, generatedType.getInternalName(), "getServices", Type.getMethodDescriptor(SERVICE_REGISTRY_TYPE), false);

    java.lang.reflect.Type genericReturnType = getter.getGenericReturnType();
    if (genericReturnType instanceof Class) {
        // if the return type doesn't use generics, then it's faster to just rely on the type name directly
        methodVisitor.visitLdcInsn(Type.getType((Class) genericReturnType));
    } else {
        // load the static type descriptor from class constants
        String constantFieldName = getConstantNameForGenericReturnType(genericReturnType, getterName);
        methodVisitor.visitFieldInsn(GETSTATIC, generatedType.getInternalName(), constantFieldName, JAVA_REFLECT_TYPE_DESCRIPTOR);
    }

    // get(<type>)
    methodVisitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, SERVICE_REGISTRY_TYPE.getInternalName(), "get", GET_METHOD_DESCRIPTOR, true);

    // this.field = (<type>)<service>
    methodVisitor.visitTypeInsn(Opcodes.CHECKCAST, serviceType.getInternalName());
    methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, generatedType.getInternalName(), propFieldName, serviceType.getDescriptor());

    // this.field
    methodVisitor.visitLabel(alreadyLoaded);
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    methodVisitor.visitFieldInsn(Opcodes.GETFIELD, generatedType.getInternalName(), propFieldName, serviceType.getDescriptor());

    // return
    methodVisitor.visitInsn(returnType.getOpcode(Opcodes.IRETURN));
    methodVisitor.visitMaxs(0, 0);
    methodVisitor.visitEnd();
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:54,代码来源:AsmBackedClassGenerator.java

示例14: makeClazz

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static byte[] makeClazz() {
    // Code generated the class below using asm.
    String clazzName = DeoptimizeOnExceptionTest.class.getName().replace('.', '/');
    final ClassWriter w = new ClassWriter(0);
    w.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC,
                    "t/TestJSR", null, "java/lang/Object",
                    new String[]{"java/lang/Runnable"});
    MethodVisitor mv = w.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, new String[]{});
    mv.visitCode();
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
    mv.visitInsn(Opcodes.RETURN);
    mv.visitMaxs(10, 10);
    mv.visitEnd();

    mv = w.visitMethod(Opcodes.ACC_PUBLIC, "run", "()V", null, null);
    mv.visitCode();
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "getM", "()Ljava/lang/Object;", false);
    Label l1 = new Label();
    mv.visitJumpInsn(Opcodes.JSR, l1);
    mv.visitInsn(Opcodes.RETURN);

    mv.visitLabel(l1);
    mv.visitVarInsn(Opcodes.ASTORE, 1);

    Label lElse = new Label();
    Label lEnd = new Label();
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J", false);
    mv.visitInsn(Opcodes.POP2);
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "getM", "()Ljava/lang/Object;", false);
    mv.visitInsn(Opcodes.DUP);
    mv.visitJumpInsn(Opcodes.IFNULL, lElse);
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "methodA", "()V", false);
    mv.visitJumpInsn(Opcodes.GOTO, lEnd);
    mv.visitLabel(lElse);
    mv.visitMethodInsn(Opcodes.INVOKESTATIC, clazzName, "methodB", "()V", false);
    mv.visitLabel(lEnd);

    mv.visitVarInsn(Opcodes.RET, 1);
    mv.visitMaxs(10, 10);
    mv.visitEnd();
    return w.toByteArray();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:44,代码来源:DeoptimizeOnExceptionTest.java

示例15: generateHashCodeMethod

import org.objectweb.asm.MethodVisitor; //导入方法依赖的package包/类
private static void generateHashCodeMethod(ClassWriter cw, String selfClassInternalName, String selfClassDescriptor,
        Parameter[] parameters) {
    MethodVisitor mv;
    mv = cw.visitMethod(ACC_PUBLIC, "hashCode", "()I", null, null);
    mv.visitCode();

    // int result = 1;

    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitInsn(ICONST_1);
    mv.visitVarInsn(ISTORE, 1);

    for (Parameter param : parameters) {
        Class<?> type = param.getType();
        mv.visitIntInsn(BIPUSH, 31);
        mv.visitVarInsn(ILOAD, 1);
        mv.visitInsn(IMUL);
        mv.visitVarInsn(ALOAD, 0);
        Type typeType = Type.getType(type);
        mv.visitFieldInsn(GETFIELD, selfClassInternalName, param.getName(), typeType.getDescriptor());
        if (type.isPrimitive()) {
            Class<?> boxed = BytecodeGenUtils.getBoxed(type);
            mv.visitMethodInsn(INVOKESTATIC, Type.getInternalName(boxed), "hashCode",
                    Type.getMethodDescriptor(Type.INT_TYPE, typeType), false);

        } else {
            mv.visitMethodInsn(INVOKESTATIC, "java/util/Objects", "hashCode", "(Ljava/lang/Object;)I", false);
        }
        mv.visitInsn(IADD);
        mv.visitVarInsn(ISTORE, 1);
    }

    mv.visitVarInsn(ILOAD, 1);
    mv.visitInsn(IRETURN);
    Label l7 = new Label();
    mv.visitLabel(l7);
    mv.visitLocalVariable("this", selfClassDescriptor, null, l0, l7, 0);
    mv.visitLocalVariable("result", "I", null, l0, l7, 1);
    mv.visitMaxs(-1, -1);
    mv.visitEnd();
}
 
开发者ID:primeval-io,项目名称:primeval-reflex,代码行数:43,代码来源:MethodArgumentssUpdaterGenerator.java


注:本文中的org.objectweb.asm.MethodVisitor.visitLabel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。