List of usage examples for org.objectweb.asm Opcodes POP
int POP
To view the source code for org.objectweb.asm Opcodes POP.
Click Source Link
From source file:co.paralleluniverse.fibers.instrument.InstrumentMethod.java
License:Open Source License
private void emitStoreState(MethodVisitor mv, int idx, FrameInfo fi, int numArgsToPreserve) { Frame f = frames[fi.endInstruction]; if (fi.lBefore != null) fi.lBefore.accept(mv);/*from w ww . java 2 s .c o m*/ mv.visitVarInsn(Opcodes.ALOAD, lvarStack); emitConst(mv, idx); emitConst(mv, fi.numSlots); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STACK_NAME, "pushMethod", "(II)V"); // store operand stack for (int i = f.getStackSize(); i-- > 0;) { BasicValue v = (BasicValue) f.getStack(i); if (!isOmitted(v)) { if (!isNullType(v)) { int slotIdx = fi.stackSlotIndices[i]; assert slotIdx >= 0 && slotIdx < fi.numSlots; emitStoreValue(mv, v, lvarStack, slotIdx, -1); } else { db.log(LogLevel.DEBUG, "NULL stack entry: type=%s size=%d", v.getType(), v.getSize()); mv.visitInsn(Opcodes.POP); } } } // store local vars for (int i = firstLocal; i < f.getLocals(); i++) { BasicValue v = (BasicValue) f.getLocal(i); if (!isNullType(v)) { mv.visitVarInsn(v.getType().getOpcode(Opcodes.ILOAD), i); int slotIdx = fi.localSlotIndices[i]; assert slotIdx >= 0 && slotIdx < fi.numSlots; emitStoreValue(mv, v, lvarStack, slotIdx, i); } } // restore last numArgsToPreserve operands for (int i = f.getStackSize() - numArgsToPreserve; i < f.getStackSize(); i++) { BasicValue v = (BasicValue) f.getStack(i); if (!isOmitted(v)) { if (!isNullType(v)) { int slotIdx = fi.stackSlotIndices[i]; assert slotIdx >= 0 && slotIdx < fi.numSlots; emitRestoreValue(mv, v, lvarStack, slotIdx, -1); } else { mv.visitInsn(Opcodes.ACONST_NULL); } } } }
From source file:com.alibaba.hotswap.processor.field.access.FieldAccessModifier.java
License:Open Source License
@Override public void visitFieldInsn(int opcode, String owner, String name, String desc) { if (HotswapRuntime.getClassInitialized(className) && !name.equals(HotswapConstants.STATIC_FIELD_HOLDER) && !name.equals(HotswapConstants.FIELD_HOLDER)) { Queue<String> owners = new LinkedList<String>(); owners.offer(owner);/*from w w w . j av a 2s . c o m*/ String tmpOwner = owners.poll(); while (tmpOwner != null) { if (HotswapRuntime.hasClassMeta(tmpOwner)) { // Try to reload owner. HotswapRuntime.try2Reload(tmpOwner); ClassMeta classMeta = HotswapRuntime.getClassMeta(tmpOwner); String fmKey = HotswapFieldUtil.getFieldKey(name, desc); FieldMeta fm = classMeta.getFieldMeta(fmKey); if (classMeta.isInterface) { if (fm != null && !fm.isDeleted(classMeta.loadedIndex) && (opcode == Opcodes.PUTSTATIC || opcode == Opcodes.GETSTATIC)) { super.visitFieldInsn(opcode, Type.getInternalName(classMeta.vClass), fm.name, fm.desc); return; } } if (fm != null && classMeta.primaryFieldKeyList.contains(fmKey) && !fm.isDeleted(classMeta.loadedIndex)) { break; } else if (fm != null && classMeta.primaryFieldKeyList.contains(fmKey) && fm.isDeleted(classMeta.loadedIndex)) { // If this accessed field is primary and deleted, it perhaps is a alias field fm = classMeta.getFieldMeta(HotswapFieldUtil .getFieldKey(HotswapConstants.PREFIX_FIELD_ALIAS + fm.name, fm.desc)); } if (fm != null && fm.isAdded() && !fm.isDeleted(classMeta.loadedIndex)) { if (opcode == Opcodes.PUTSTATIC) { // put static box(Type.getType(fm.desc)); mv.visitFieldInsn(Opcodes.GETSTATIC, tmpOwner, HotswapConstants.STATIC_FIELD_HOLDER, "Ljava/util/concurrent/ConcurrentHashMap;"); mv.visitLdcInsn(fm.name); mv.visitLdcInsn(fm.desc); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapFieldUtil.class), "setFieldValue", "(Ljava/lang/Object;Ljava/util/concurrent/ConcurrentHashMap;Ljava/lang/String;Ljava/lang/String;)V"); return; } else if (opcode == Opcodes.GETSTATIC) { // get static mv.visitFieldInsn(Opcodes.GETSTATIC, tmpOwner, HotswapConstants.STATIC_FIELD_HOLDER, "Ljava/util/concurrent/ConcurrentHashMap;"); mv.visitLdcInsn(fm.name); mv.visitLdcInsn(fm.desc); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapFieldUtil.class), "getFieldValue", "(Ljava/util/concurrent/ConcurrentHashMap;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;"); unbox(Type.getType(fm.desc)); return; } else if (opcode == Opcodes.PUTFIELD) { // put field // stack: obj fieldValue box(Type.getType(fm.desc)); mv.visitInsn(Opcodes.SWAP); mv.visitFieldInsn(Opcodes.GETFIELD, tmpOwner, HotswapConstants.FIELD_HOLDER, "Ljava/util/concurrent/ConcurrentHashMap;"); mv.visitLdcInsn(fm.name); mv.visitLdcInsn(fm.desc); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapFieldUtil.class), "setFieldValue", "(Ljava/lang/Object;Ljava/util/concurrent/ConcurrentHashMap;Ljava/lang/String;Ljava/lang/String;)V"); return; } else if (opcode == Opcodes.GETFIELD) { // get field // stack: obj mv.visitFieldInsn(Opcodes.GETFIELD, tmpOwner, HotswapConstants.FIELD_HOLDER, "Ljava/util/concurrent/ConcurrentHashMap;"); mv.visitLdcInsn(fm.name); mv.visitLdcInsn(fm.desc); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapFieldUtil.class), "getFieldValue", "(Ljava/util/concurrent/ConcurrentHashMap;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;"); Label notnull = newLabel(); Type type = Type.getType(fm.desc); mv.visitInsn(Opcodes.DUP); mv.visitJumpInsn(Opcodes.IFNONNULL, notnull); Label end = newLabel(); switch (type.getSort()) { case Type.BOOLEAN: mv.visitInsn(Opcodes.POP); mv.visitLdcInsn(new Boolean(false)); break; case Type.CHAR: mv.visitInsn(Opcodes.POP); mv.visitLdcInsn(new Character(' ')); break; case Type.BYTE: mv.visitInsn(Opcodes.POP); mv.visitLdcInsn(new Byte((byte) 0)); break; case Type.SHORT: mv.visitInsn(Opcodes.POP); mv.visitLdcInsn(new Short((short) 0)); break; case Type.INT: mv.visitInsn(Opcodes.POP); mv.visitLdcInsn(new Integer(0)); break; case Type.FLOAT: mv.visitInsn(Opcodes.POP); mv.visitLdcInsn(new Float(0)); break; case Type.LONG: mv.visitInsn(Opcodes.POP); mv.visitLdcInsn(new Long(0)); break; case Type.DOUBLE: mv.visitInsn(Opcodes.POP); mv.visitLdcInsn(new Double(0)); break; default: break; } mv.visitJumpInsn(Opcodes.GOTO, end); mark(notnull); unbox(type); mark(end); return; } } if (classMeta.clazz != null) { Class<?> superClass = classMeta.clazz.getSuperclass(); if (superClass != null) { owners.offer(HotswapUtil.getInternalClassName(superClass.getName())); } Class<?>[] superInterfaces = classMeta.clazz.getInterfaces(); if (superInterfaces != null) { for (Class<?> itf : superInterfaces) { owners.offer(HotswapUtil.getInternalClassName(itf.getName())); } } } } tmpOwner = owners.poll(); } } super.visitFieldInsn(opcode, owner, name, desc); }
From source file:com.alibaba.hotswap.processor.jdk.classloader.modifier.DefineClassMethodModifier.java
License:Open Source License
@Override public void visitCode() { super.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 1);//from ww w . j a v a2 s . c om mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapConfiguration.class), "getClassPathInWorkspace", "(Ljava/lang/String;)Ljava/lang/String;"); mv.visitInsn(Opcodes.DUP); Label old = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, old); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(HotswapRuntime.class), "updateClassMeta", "(Ljava/lang/String;Ljava/lang/ClassLoader;)V"); mv.visitVarInsn(Opcodes.ALOAD, 1); // className mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(CustomerLoadClassBytes.class), "loadBytesFromPath", "(Ljava/lang/String;Ljava/lang/String;)[B"); mv.visitVarInsn(Opcodes.ASTORE, 2);// store class bytes into 2 mv.visitVarInsn(Opcodes.ALOAD, 2);// load class bytes mv.visitInsn(Opcodes.ARRAYLENGTH); // length of the class bytes mv.visitVarInsn(Opcodes.ISTORE, 4);// store length into 4 Label end = new Label(); mv.visitJumpInsn(Opcodes.GOTO, end); mv.visitLabel(old); mv.visitInsn(Opcodes.POP); mv.visitLabel(end); }
From source file:com.alibaba.hotswap.processor.jdk.classloader.modifier.FindClassMethodModifier.java
License:Open Source License
@Override public void visitCode() { super.visitCode(); Label normal = new Label(); mv.visitVarInsn(Opcodes.ALOAD, 0);// www. jav a2 s . c o m mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(ClassLoaderHelper.class), "tryLoadVClass", "(Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/lang/Class;"); mv.visitInsn(Opcodes.DUP); mv.visitJumpInsn(Opcodes.IFNULL, normal); mv.visitInsn(Opcodes.ARETURN); mv.visitLabel(normal); mv.visitInsn(Opcodes.POP); }
From source file:com.android.tools.layoutlib.create.StubMethodAdapter.java
License:Apache License
private void generatePop() { /* Pops the stack, depending on the return type. *//*from w w w . j av a2 s . co m*/ switch (mReturnType != null ? mReturnType.getSort() : Type.VOID) { case Type.VOID: break; case Type.BOOLEAN: case Type.CHAR: case Type.BYTE: case Type.SHORT: case Type.INT: case Type.FLOAT: case Type.ARRAY: case Type.OBJECT: mParentVisitor.visitInsn(Opcodes.POP); break; case Type.LONG: case Type.DOUBLE: mParentVisitor.visitInsn(Opcodes.POP2); break; } }
From source file:com.asakusafw.dag.compiler.builtin.Util.java
License:Apache License
static void defineBuildKey(ClassGeneratorContext context, ClassWriter writer, TypeDescription dataType, Group group) {//from w ww.j a va 2 s. c o m DataModelReference type = context.getDataModelLoader().load(dataType); List<PropertyReference> props = group.getGrouping().stream() .map(p -> Invariants.requireNonNull(type.findProperty(p))).collect(Collectors.toList()); MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "buildKey", Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(KeyBuffer.class), typeOf(Object.class)), null, null); LocalVarRef key = new LocalVarRef(Opcodes.ALOAD, 1); LocalVarRef object = cast(v, 2, dataType); for (PropertyReference p : props) { key.load(v); object.load(v); getOption(v, p); v.visitMethodInsn(Opcodes.INVOKEINTERFACE, typeOf(KeyBuffer.class).getInternalName(), "append", Type.getMethodDescriptor(typeOf(KeyBuffer.class), typeOf(Object.class)), true); v.visitInsn(Opcodes.POP); } v.visitInsn(Opcodes.RETURN); v.visitMaxs(0, 0); v.visitEnd(); }
From source file:com.asakusafw.dag.compiler.codegen.CoGroupInputAdapterGenerator.java
License:Apache License
/** * Generates {@link ExtractInputAdapter} class. * @param context the current context/*from w ww. j a v a 2 s . c om*/ * @param inputs the target output ports * @param target the target class * @return the generated class data */ public ClassData generate(ClassGeneratorContext context, List<Spec> inputs, ClassDescription target) { ClassWriter writer = AsmUtil.newWriter(target, CoGroupInputAdapter.class); defineAdapterConstructor(writer, CoGroupInputAdapter.class, v -> { for (Spec spec : inputs) { ClassDescription supplier = SupplierGenerator.get(context, spec.dataType); v.visitVarInsn(Opcodes.ALOAD, 0); getConst(v, spec.id); getConst(v, typeOf(supplier)); getEnumConstant(v, spec.bufferType); v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "bind", //$NON-NLS-1$ Type.getMethodDescriptor(typeOf(CoGroupInputAdapter.class), typeOf(String.class), typeOf(Class.class), typeOf(CoGroupInputAdapter.BufferType.class)), false); v.visitInsn(Opcodes.POP); } }); return new ClassData(target, writer::toByteArray); }
From source file:com.asakusafw.dag.compiler.codegen.EdgeDataTableAdapterGenerator.java
License:Apache License
/** * Generates {@link EdgeDataTableAdapter} class. * @param context the current context//from www. j a v a 2 s. c o m * @param specs the target output ports * @param target the target class * @return the generated class data */ public ClassData generate(ClassGeneratorContext context, List<Spec> specs, ClassDescription target) { ClassWriter writer = AsmUtil.newWriter(target, EdgeDataTableAdapter.class); defineAdapterConstructor(writer, EdgeDataTableAdapter.class, v -> { LocalVarRef self = new LocalVarRef(Opcodes.ALOAD, 0); int index = 0; for (Spec spec : specs) { ClassDescription keyBuilder; if (spec.group.getGrouping().isEmpty()) { keyBuilder = null; } else { keyBuilder = generateKeyBuilder(context, spec, qualify(target, "k", index)); } ClassDescription copier = ObjectCopierGenerator.get(context, spec.dataType); ClassDescription comparator = toComparatorClass(context, spec); TypeDescription[] keyElementTypes = toKeyElementTypes(context, spec); self.load(v); getConst(v, spec.tableId); getConst(v, spec.inputId); getConst(v, keyBuilder); getConst(v, copier); getConst(v, comparator); getArray(v, typeOf(Class.class), keyElementTypes); v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "bind", Type.getMethodDescriptor(typeOf(EdgeDataTableAdapter.class), typeOf(String.class), typeOf(String.class), typeOf(Class.class), typeOf(Class.class), typeOf(Class.class), typeOf(Class[].class)), false); v.visitInsn(Opcodes.POP); index++; } }); return new ClassData(target, writer::toByteArray); }
From source file:com.asakusafw.dag.compiler.codegen.EdgeDataTableAdapterGenerator.java
License:Apache License
private static void defineBuildKey(ClassGeneratorContext context, ClassWriter writer, TypeDescription dataType, Group group) {//from w w w . j a va 2 s . c om DataModelReference type = context.getDataModelLoader().load(dataType); List<PropertyReference> props = group.getGrouping().stream() .map(p -> Invariants.requireNonNull(type.findProperty(p))).collect(Collectors.toList()); MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "buildKey", Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(KeyBuffer.class), typeOf(Object.class)), null, null); LocalVarRef key = new LocalVarRef(Opcodes.ALOAD, 1); LocalVarRef object = cast(v, 2, dataType); for (PropertyReference p : props) { key.load(v); object.load(v); getOption(v, p); v.visitMethodInsn(Opcodes.INVOKEINTERFACE, typeOf(KeyBuffer.class).getInternalName(), "append", Type.getMethodDescriptor(typeOf(KeyBuffer.class), typeOf(Object.class)), true); v.visitInsn(Opcodes.POP); } v.visitInsn(Opcodes.RETURN); v.visitMaxs(0, 0); v.visitEnd(); }
From source file:com.asakusafw.dag.compiler.codegen.EdgeOutputAdapterGenerator.java
License:Apache License
/** * Generates {@link EdgeOutputAdapter} class. * @param context the current context//from w w w. j ava2 s . c om * @param specs the target output ports * @param target the target class * @return the generated class data */ public ClassData generate(ClassGeneratorContext context, List<Spec> specs, ClassDescription target) { ClassWriter writer = AsmUtil.newWriter(target, EdgeOutputAdapter.class); defineAdapterConstructor(writer, EdgeOutputAdapter.class, v -> { for (Spec spec : specs) { v.visitVarInsn(Opcodes.ALOAD, 0); getConst(v, spec.id); getConst(v, spec.mapper); getConst(v, spec.copier); getConst(v, spec.combiner); v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "bind", Type.getMethodDescriptor(typeOf(EdgeOutputAdapter.class), typeOf(String.class), typeOf(Class.class), typeOf(Class.class), typeOf(Class.class)), false); v.visitInsn(Opcodes.POP); } }); return new ClassData(target, writer::toByteArray); }