List of usage examples for org.objectweb.asm Opcodes GETSTATIC
int GETSTATIC
To view the source code for org.objectweb.asm Opcodes GETSTATIC.
Click Source Link
From source file:org.jacoco.core.internal.instr.ClassFieldProbeArrayStrategy.java
License:Open Source License
private void createInitMethod(final ClassVisitor cv, final int probeCount) { final MethodVisitor mv = cv.visitMethod(InstrSupport.INITMETHOD_ACC, InstrSupport.INITMETHOD_NAME, InstrSupport.INITMETHOD_DESC, null, null); mv.visitCode();// w ww . ja va2 s. c om // Load the value of the static data field: mv.visitFieldInsn(Opcodes.GETSTATIC, className, InstrSupport.DATAFIELD_NAME, InstrSupport.DATAFIELD_DESC); mv.visitInsn(Opcodes.DUP); // Stack[1]: [Z // Stack[0]: [Z // Skip initialization when we already have a data array: final Label alreadyInitialized = new Label(); mv.visitJumpInsn(Opcodes.IFNONNULL, alreadyInitialized); // Stack[0]: [Z mv.visitInsn(Opcodes.POP); final int size = genInitializeDataField(mv, probeCount); // Stack[0]: [Z // Return the class' probe array: if (withFrames) { mv.visitFrame(Opcodes.F_NEW, 0, FRAME_LOCALS_EMPTY, 1, FRAME_STACK_ARRZ); } mv.visitLabel(alreadyInitialized); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(Math.max(size, 2), 0); // Maximum local stack size is 2 mv.visitEnd(); }
From source file:org.jacoco.core.internal.instr.FrameTracker.java
License:Open Source License
@Override public void visitFieldInsn(final int opcode, final String owner, final String name, final String desc) { final Type t = Type.getType(desc); switch (opcode) { case Opcodes.PUTSTATIC: pop(t);// www . j ava 2s .co m break; case Opcodes.PUTFIELD: pop(t); pop(1); break; case Opcodes.GETSTATIC: push(t); break; case Opcodes.GETFIELD: pop(1); push(t); break; default: throw new IllegalArgumentException(); } mv.visitFieldInsn(opcode, owner, name, desc); }
From source file:org.jacoco.core.internal.instr.InterfaceFieldProbeArrayStrategy.java
License:Open Source License
private void createInitMethod(final ClassVisitor cv, final int probeCount) { final MethodVisitor mv = cv.visitMethod(InstrSupport.INITMETHOD_ACC, InstrSupport.INITMETHOD_NAME, InstrSupport.INITMETHOD_DESC, null, null); mv.visitCode();//from w w w. j av a2s . com // Load the value of the static data field: mv.visitFieldInsn(Opcodes.GETSTATIC, className, InstrSupport.DATAFIELD_NAME, InstrSupport.DATAFIELD_DESC); mv.visitInsn(Opcodes.DUP); // Stack[1]: [Z // Stack[0]: [Z // Skip initialization when we already have a data array: final Label alreadyInitialized = new Label(); mv.visitJumpInsn(Opcodes.IFNONNULL, alreadyInitialized); // Stack[0]: [Z mv.visitInsn(Opcodes.POP); final int size = accessorGenerator.generateDataAccessor(classId, className, probeCount, mv); // Stack[0]: [Z // Return the class' probe array: mv.visitFrame(Opcodes.F_NEW, 0, FRAME_LOCALS_EMPTY, 1, FRAME_STACK_ARRZ); mv.visitLabel(alreadyInitialized); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(Math.max(size, 2), 0); // Maximum local stack size is 2 mv.visitEnd(); }
From source file:org.jacoco.core.runtime.InjectedClassRuntime.java
License:Open Source License
public int generateDataAccessor(final long classid, final String classname, final int probecount, final MethodVisitor mv) { mv.visitFieldInsn(Opcodes.GETSTATIC, injectedClassName, FIELD_NAME, FIELD_TYPE); RuntimeData.generateAccessCall(classid, classname, probecount, mv); return 6;/*from w w w. j a v a2s. c om*/ }
From source file:org.jacoco.core.runtime.LoggerRuntime.java
License:Open Source License
public int generateDataAccessor(final long classid, final String classname, final int probecount, final MethodVisitor mv) { // The data accessor performs the following steps: //// www.ja v a2s . c om // final Object[] args = new Object[3]; // args[0] = Long.valueOf(classid); // args[1] = classname; // args[2] = Integer.valueOf(probecount); // Logger.getLogger(CHANNEL).log(Level.INFO, key, args); // final byte[] probedata = (byte[]) args[0]; // // Note that local variable 'args' is used at two places. As were not // allowed to allocate local variables we have to keep this value with // DUP and SWAP operations on the operand stack. // 1. Create parameter array: RuntimeData.generateArgumentArray(classid, classname, probecount, mv); // Stack[0]: [Ljava/lang/Object; mv.visitInsn(Opcodes.DUP); // Stack[1]: [Ljava/lang/Object; // Stack[0]: [Ljava/lang/Object; // 2. Call Logger: mv.visitLdcInsn(CHANNEL); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/util/logging/Logger", "getLogger", "(Ljava/lang/String;)Ljava/util/logging/Logger;"); // Stack[2]: Ljava/util/logging/Logger; // Stack[1]: [Ljava/lang/Object; // Stack[0]: [Ljava/lang/Object; mv.visitInsn(Opcodes.SWAP); // Stack[2]: [Ljava/lang/Object; // Stack[1]: Ljava/util/logging/Logger; // Stack[0]: [Ljava/lang/Object; mv.visitFieldInsn(Opcodes.GETSTATIC, "java/util/logging/Level", "INFO", "Ljava/util/logging/Level;"); // Stack[3]: Ljava/util/logging/Level; // Stack[2]: [Ljava/lang/Object; // Stack[1]: Ljava/util/logging/Logger; // Stack[0]: [Ljava/lang/Object; mv.visitInsn(Opcodes.SWAP); // Stack[3]: [Ljava/lang/Object; // Stack[2]: Ljava/util/logging/Level; // Stack[1]: Ljava/util/logging/Logger; // Stack[0]: [Ljava/lang/Object; mv.visitLdcInsn(key); // Stack[4]: Ljava/lang/String; // Stack[3]: [Ljava/lang/Object; // Stack[2]: Ljava/util/logging/Level; // Stack[1]: Ljava/util/logging/Logger; // Stack[0]: [Ljava/lang/Object; mv.visitInsn(Opcodes.SWAP); // Stack[4]: [Ljava/lang/Object; // Stack[3]: Ljava/lang/String; // Stack[2]: Ljava/util/logging/Level; // Stack[1]: Ljava/util/logging/Logger; // Stack[0]: [Ljava/lang/Object; mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/logging/Logger", "log", "(Ljava/util/logging/Level;Ljava/lang/String;[Ljava/lang/Object;)V"); // Stack[0]: [Ljava/lang/Object; // 3. Load data structure from parameter array: mv.visitInsn(Opcodes.ICONST_0); mv.visitInsn(Opcodes.AALOAD); mv.visitTypeInsn(Opcodes.CHECKCAST, InstrSupport.DATAFIELD_DESC); // Stack[0]: [Z return 5; // Maximum local stack size is 5 }
From source file:org.jacoco.core.runtime.ModifiedSystemClassRuntime.java
License:Open Source License
public int generateDataAccessor(final long classid, final String classname, final int probecount, final MethodVisitor mv) { mv.visitFieldInsn(Opcodes.GETSTATIC, systemClassName, accessFieldName, ACCESS_FIELD_TYPE); RuntimeData.generateAccessCall(classid, classname, probecount, mv); return 6;//from ww w . j a v a2 s . co m }
From source file:org.jboss.as.hibernate.MethodAdapter.java
License:Open Source License
@Override public void visitFieldInsn(int opcode, String owner, String name, String desc) { // App References to Enum org.hibernate.FlushMode.NEVER (0) should be transformed to reference FlushMode.MANUAL (0) instead. if (opcode == Opcodes.GETSTATIC && owner.equals("org/hibernate/FlushMode") && name.equals("NEVER") && desc.equals("Lorg/hibernate/FlushMode;")) { logger.debugf("Deprecated Hibernate51CompatibilityTransformer transformed application classes in '%s', " + "class '%s' is using org.hibernate.FlushMode.NEVER, change to org.hibernate.FlushMode.MANUAL.", moduleName, className);//from w w w. j a v a 2 s . c o m mv.visitFieldInsn(opcode, owner, "MANUAL", desc); transformedState.setClassTransformed(true); } else { mv.visitFieldInsn(opcode, owner, name, desc); } }
From source file:org.jboss.byteman.agent.adapter.RuleGeneratorAdapter.java
License:Open Source License
/** * Generates the instruction to push the value of a static field on the * stack./*from w ww. j a v a 2s. c o m*/ * * @param owner the class in which the field is defined. * @param name the name of the field. * @param type the type of the field. */ public void getStatic(final Type owner, final String name, final Type type) { fieldInsn(Opcodes.GETSTATIC, owner, name, type); }
From source file:org.jboss.byteman.rule.expression.StaticExpression.java
License:Open Source License
public void compile(MethodVisitor mv, CompileContext compileContext) throws CompileException { // make sure we are at the right source line compileContext.notifySourceLine(line); int currentStack = compileContext.getStackCount(); int expected; // compile a field access if (isPublicField) { String ownerType = Type.internalName(field.getDeclaringClass()); String fieldName = field.getName(); String fieldType = Type.internalName(field.getType(), true); mv.visitFieldInsn(Opcodes.GETSTATIC, ownerType, fieldName, fieldType); expected = (type.getNBytes() > 4 ? 2 : 1); compileContext.addStackCount(expected); } else {// w w w .j a v a 2s . c om // since this is a private field we need to do the access using reflection // stack the helper, a null owner and the field index mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitLdcInsn(fieldIndex); compileContext.addStackCount(3); // use the HelperAdapter method getAccessibleField to get the field value mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.internalName(HelperAdapter.class), "getAccessibleField", "(Ljava/lang/Object;I)Ljava/lang/Object;"); // we popped three words and added one object as result compileContext.addStackCount(-2); // convert Object to primitive or cast to subtype if required compileTypeConversion(Type.OBJECT, type, mv, compileContext); } }
From source file:org.kantega.notsoserial.CreateBytesIT.java
License:Apache License
private byte[] createTransletBytes() { ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, "com/example/InvokingTranslet", null, Type.getType(AbstractTranslet.class).getInternalName(), new String[] { Type.getType(Serializable.class).getInternalName() }); MethodVisitor init = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); init.visitCode();//ww w. ja va2s .c om init.visitVarInsn(Opcodes.ALOAD, 0); init.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getType(AbstractTranslet.class).getInternalName(), "<init>", "()V"); init.visitVarInsn(Opcodes.ALOAD, 0); init.visitIntInsn(Opcodes.BIPUSH, 101); init.visitFieldInsn(Opcodes.PUTFIELD, Type.getType(AbstractTranslet.class).getInternalName(), "transletVersion", "I"); init.visitInsn(Opcodes.RETURN); init.visitMaxs(2, 2); init.visitEnd(); MethodVisitor transformMethod = cw.visitMethod(Opcodes.ACC_PUBLIC, "transform", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.getType(DOM.class), Type.getType(DTMAxisIterator.class) }), null, new String[] { Type.getType(TransletException.class).getInternalName() }); transformMethod.visitCode(); transformMethod.visitInsn(Opcodes.RETURN); transformMethod.visitEnd(); MethodVisitor mv = cw.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null); mv.visitCode(); mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); mv.visitLdcInsn("HMM.."); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V"); mv.visitLdcInsn("pwned"); mv.visitLdcInsn("true"); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/System", "setProperty", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;"); mv.visitInsn(Opcodes.POP); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(2, 0); mv.visitEnd(); cw.visitEnd(); return cw.toByteArray(); }