本文整理匯總了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);
}
示例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;
}
示例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();
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例11: accept
import org.objectweb.asm.MethodVisitor; //導入方法依賴的package包/類
@Override
public void accept(final MethodVisitor cv) {
cv.visitLabel(getLabel());
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}