List of usage examples for org.objectweb.asm Opcodes PUTSTATIC
int PUTSTATIC
To view the source code for org.objectweb.asm Opcodes PUTSTATIC.
Click Source Link
From source file:com.yahoo.yqlplus.engine.internal.bytecode.DynamicBootstrapUnit.java
public void init() { ProgramValueTypeAdapter types = environment.getValueTypeAdapter(); BytecodeExpression classSource = types.constant(getEnvironment()); TypeWidget dynamicLinker = types.adaptInternal(DynamicLinker.class); FieldDefinition field = createField(dynamicLinker, "bootstrap"); field.addModifier(Opcodes.ACC_STATIC | Opcodes.ACC_FINAL); MethodGenerator sl = createMethod("<clinit>"); sl.setModifier(Opcodes.ACC_STATIC);//from www.ja v a2 s .c o m sl.add(classSource); sl.add(new BytecodeSequence() { @Override public void generate(CodeEmitter code) { final MethodVisitor mv = code.getMethodVisitor(); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Dynamic.class), "createDynamicLinker", MethodType.methodType(DynamicLinker.class, ASMClassSource.class).toMethodDescriptorString(), false); mv.visitFieldInsn(Opcodes.PUTSTATIC, Dynamic.DYNAMIC_INTERNAL_NAME, "bootstrap", Type.getDescriptor(DynamicLinker.class)); mv.visitInsn(Opcodes.RETURN); } }); MethodGenerator mgen = createStaticMethod(Dynamic.DYNAMIC_BOOTSTRAP_METHOD); TypeWidget callSite = types.adaptInternal(CallSite.class); TypeWidget lookup = types.adaptInternal(MethodHandles.Lookup.class); TypeWidget methodType = types.adaptInternal(MethodType.class); mgen.setReturnType(callSite); AssignableValue lu = mgen.addArgument("lookup", lookup); AssignableValue name = mgen.addArgument("name", BaseTypeAdapter.STRING); AssignableValue sig = mgen.addArgument("sig", methodType); final String desc = MethodType.methodType(CallSite.class, // ...that will return a CallSite object, ... MethodHandles.Lookup.class, // ... when given a lookup object, ... String.class, // ... the operation name, ... MethodType.class, // ... and the signature at the call site. DynamicLinker.class).toMethodDescriptorString(); mgen.add(lu.read()); mgen.add(name.read()); mgen.add(sig.read()); mgen.add(new BytecodeSequence() { @Override public void generate(CodeEmitter code) { final MethodVisitor mv = code.getMethodVisitor(); mv.visitFieldInsn(Opcodes.GETSTATIC, Dynamic.DYNAMIC_INTERNAL_NAME, "bootstrap", Type.getDescriptor(DynamicLinker.class)); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Dynamic.class), "link", desc, false); mv.visitInsn(Opcodes.ARETURN); } }); }
From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.FieldInstruction.java
License:Open Source License
@Override public String toString() { String type;/*w w w .j a va 2s .co m*/ switch (getOpcode()) { case Opcodes.PUTSTATIC: type = "PUTSTATIC"; break; case Opcodes.GETSTATIC: type = "GETSTATIC"; break; case Opcodes.GETFIELD: type = "GETFIELD"; break; case Opcodes.PUTFIELD: type = "PUTFIELD"; break; default: assert false; type = "--ERROR--"; break; } StringBuilder sb = new StringBuilder(type.length() + this.ownerInternalClassName.length() + this.fieldName.length() + this.fieldDesc.length() + 3); sb.append(type).append(' ').append(this.ownerInternalClassName).append('.').append(this.fieldName) .append(' ').append(this.fieldDesc); return sb.toString(); }
From source file:de.unisb.cs.st.javaslicer.common.classRepresentation.instructions.FieldInstruction2.java
License:Open Source License
@Override public String toString() { String type;//from ww w . j a va 2s .c om switch (getOpcode()) { case Opcodes.PUTSTATIC: type = "PUTSTATIC"; break; case Opcodes.GETSTATIC: type = "GETSTATIC"; break; case Opcodes.GETFIELD: type = "GETFIELD"; break; case Opcodes.PUTFIELD: type = "PUTFIELD"; break; default: assert false; type = "--ERROR--"; break; } StringBuilder sb = new StringBuilder(type.length() + this.ownerInternalClassName.length() + this.fieldName.length() + this.fieldDesc.length() + 3); sb.append(type).append(' ').append(this.ownerInternalClassName).append(".&&").append(this.fieldName) .append(' ').append(this.fieldDesc); return sb.toString(); }
From source file:dyco4j.instrumentation.internals.InitTracingMethodVisitor.java
License:BSD License
@Override public void visitFieldInsn(final int opcode, final String owner, final String name, final String desc) { this.mv.visitFieldInsn(opcode, owner, name, desc); final char _c = desc.charAt(0); final boolean _longOrDouble = _c == 'J' || _c == 'D'; switch (opcode) { case Opcodes.GETSTATIC: // add 1 or 2 this.stackFrame.push(OTHER); if (_longOrDouble) this.stackFrame.push(OTHER); break;//w w w. java 2s . c o m case Opcodes.PUTSTATIC: // remove 1 or 2 this.stackFrame.pop(); if (_longOrDouble) this.stackFrame.pop(); break; case Opcodes.PUTFIELD: // remove 2 or 3 this.stackFrame.pop(); this.stackFrame.pop(); if (_longOrDouble) this.stackFrame.pop(); break; case Opcodes.GETFIELD: // remove 1 add 1 or 2 if (_longOrDouble) this.stackFrame.push(OTHER); } }
From source file:dyco4j.instrumentation.internals.TracingMethodVisitor.java
License:BSD License
@Override public final void visitFieldInsn(final int opcode, final String owner, final String name, final String desc) { if (this.cv.cmdLineOptions.traceFieldAccess) { final Type _fieldType = Type.getType(desc); final String _fieldId = this.cv.getFieldId(name, owner, desc); final boolean _isFieldStatic = opcode == Opcodes.GETSTATIC || opcode == Opcodes.PUTSTATIC; if (opcode == Opcodes.GETSTATIC || opcode == Opcodes.GETFIELD) { if (_isFieldStatic) super.visitInsn(Opcodes.ACONST_NULL); else if (this.thisInitialized) super.visitInsn(Opcodes.DUP); else { super.visitLdcInsn(LoggingHelper.UNINITIALIZED_THIS); super.visitInsn(Opcodes.SWAP); }//w w w. ja v a 2 s . c o m super.visitFieldInsn(opcode, owner, name, desc); LoggingHelper.emitLogField(this.mv, _fieldId, _fieldType, Logger.FieldAction.GETF); } else if (opcode == Opcodes.PUTSTATIC || opcode == Opcodes.PUTFIELD) { if (_isFieldStatic) { super.visitInsn(Opcodes.ACONST_NULL); } else if (this.thisInitialized) { LoggingHelper.emitSwapTwoWordsAndOneWord(this.mv, _fieldType); final int _fieldSort = _fieldType.getSort(); if (_fieldSort == Type.LONG || _fieldSort == Type.DOUBLE) super.visitInsn(Opcodes.DUP_X2); else super.visitInsn(Opcodes.DUP_X1); } else { super.visitLdcInsn(LoggingHelper.UNINITIALIZED_THIS); } LoggingHelper.emitSwapOneWordAndTwoWords(this.mv, _fieldType); LoggingHelper.emitLogField(this.mv, _fieldId, _fieldType, Logger.FieldAction.PUTF); super.visitFieldInsn(opcode, owner, name, desc); } } else super.visitFieldInsn(opcode, owner, name, desc); }
From source file:edu.mit.streamjit.util.bytecode.MethodResolver.java
License:Open Source License
private void interpret(FieldInsnNode insn, FrameState frame, BBInfo block) { Klass k = getKlassByInternalName(insn.owner); Field f = k.getField(insn.name); switch (insn.getOpcode()) { case Opcodes.GETSTATIC: LoadInst li = new LoadInst(f); block.block.instructions().add(li); frame.stack.push(li);// ww w . java 2 s .c o m break; case Opcodes.GETFIELD: LoadInst li2 = new LoadInst(f, frame.stack.pop()); block.block.instructions().add(li2); frame.stack.push(li2); break; case Opcodes.PUTSTATIC: StoreInst si = new StoreInst(f, frame.stack.pop()); block.block.instructions().add(si); break; case Opcodes.PUTFIELD: StoreInst si2 = new StoreInst(f, frame.stack.pop(), frame.stack.pop()); block.block.instructions().add(si2); break; default: throw new UnsupportedOperationException("" + insn.getOpcode()); } }
From source file:edu.mit.streamjit.util.bytecode.MethodUnresolver.java
License:Open Source License
private void emit(StoreInst i, InsnList insns) { Value location = i.getLocation();// ww w .j a va 2 s .co m if (location instanceof LocalVariable) { load(i.getData(), insns); store(location, insns); } else { Field f = (Field) location; if (!f.isStatic()) load(i.getInstance(), insns); load(i.getData(), insns); insns.add(new FieldInsnNode(f.isStatic() ? Opcodes.PUTSTATIC : Opcodes.PUTFIELD, internalName(f.getParent()), f.getName(), f.getType().getFieldType().getDescriptor())); } }
From source file:edu.ubc.mirrors.holograms.HologramMethodGenerator.java
License:Open Source License
@Override public void visitFieldInsn(int opcode, String owner, String name, String desc) { boolean isSet = (opcode == Opcodes.PUTFIELD || opcode == Opcodes.PUTSTATIC); boolean isStatic = (opcode == Opcodes.GETSTATIC || opcode == Opcodes.PUTSTATIC); Type fieldType = Type.getType(desc); int setValueLocal = -1; if (isStatic) { // For a static field the instance is null if (isSet) { setValueLocal = lvs.newLocal(fieldType); store(setValueLocal, fieldType); }//from w w w .j a va 2 s. com aconst(null); if (isSet) { load(setValueLocal, fieldType); } } else { // If this is an "uninitialized this", the mirror is the nth argument instead // of the mirror field on ObjectHologram. Object stackType = stackType(isSet ? 1 : 0); if (stackType == Opcodes.UNINITIALIZED_THIS) { // Pop the original argument if (isSet) { setValueLocal = lvs.newLocal(fieldType); store(setValueLocal, fieldType); } pop(); load((methodType.getArgumentsAndReturnSizes() >> 2) - 1, instanceMirrorType); MethodHandle.OBJECT_HOLOGRAM_MAKE.invoke(this); if (isSet) { load(setValueLocal, fieldType); } } } getClassMirror(Type.getObjectType(owner)); aconst(name); Type fieldTypeForMirrorCall = fieldType; int fieldSort = fieldType.getSort(); String suffix = ""; if (fieldSort == Type.ARRAY || fieldSort == Type.OBJECT) { fieldTypeForMirrorCall = hologramType; } else { suffix = HologramClassGenerator.getSortName(fieldSort); } // Call the appropriate getter/setter method on the mirror String methodDesc; if (isSet) { methodDesc = Type.getMethodDescriptor(Type.VOID_TYPE, hologramType, fieldTypeForMirrorCall, classMirrorType, stringType); } else { methodDesc = Type.getMethodDescriptor(fieldTypeForMirrorCall, hologramType, classMirrorType, stringType); } invokestatic(instanceHologramType.getInternalName(), (isSet ? "set" : "get") + suffix + "Field", methodDesc); if (!isSet && fieldTypeForMirrorCall.equals(hologramType)) { checkcast(fieldType); } }
From source file:edu.umd.cs.findbugs.ba.XFactory.java
License:Open Source License
public static XField createReferencedXField(DismantleBytecode visitor) { int seen = visitor.getOpcode(); if (seen != Opcodes.GETFIELD && seen != Opcodes.GETSTATIC && seen != Opcodes.PUTFIELD && seen != Opcodes.PUTSTATIC) { throw new IllegalArgumentException("Not at a field reference"); }/*from ww w .j a v a2 s . c om*/ return createXFieldUsingSlashedClassName(visitor.getClassConstantOperand(), visitor.getNameConstantOperand(), visitor.getSigConstantOperand(), visitor.getRefFieldIsStatic()); }
From source file:edu.umd.cs.guitar.testcase.plugin.edg.ClassDBVisitor.java
License:Open Source License
@Override public void visitFieldInsn(int opcode, String owner, String name, String desc) { currentMethod.setEmpty(false);//from www . j a v a 2 s. co m Class c; Field f; switch (opcode) { case Opcodes.GETFIELD: case Opcodes.GETSTATIC: c = getClass(owner); f = getField(c, name); f.setDesc(desc); // read after write is not a real read // if (!currentMethod.hasWrite(f)){ currentMethod.addRead(f); labelReads.add(f); // } break; case Opcodes.PUTFIELD: case Opcodes.PUTSTATIC: c = getClass(owner); f = getField(c, name); f.setDesc(desc); currentMethod.addWrite(f); labelWrites.add(f); break; } }