List of usage examples for org.objectweb.asm Opcodes ACC_FINAL
int ACC_FINAL
To view the source code for org.objectweb.asm Opcodes ACC_FINAL.
Click Source Link
From source file:com.yahoo.yqlplus.engine.internal.source.ExportUnitGenerator.java
public ObjectBuilder createModuleAdapter(String moduleName, Class<?> sourceClass, TypeWidget moduleType, TypeWidget contextType, BytecodeExpression sourceProvider) { gambitScope.addClass(sourceClass);//from www . ja va 2 s. com ObjectBuilder adapter = gambitScope.createObject(); ObjectBuilder.ConstructorBuilder cb = adapter.getConstructor(); ObjectBuilder.FieldBuilder fld = adapter.field("$module", moduleType); fld.addModifiers(Opcodes.ACC_FINAL); cb.exec(fld.get(cb.local("this")).write(cb.cast(moduleType, cb.invokeExact(Location.NONE, "get", Provider.class, AnyTypeWidget.getInstance(), sourceProvider)))); adapter.addParameterField(fld); ObjectBuilder.FieldBuilder programName = adapter.field("$programName", BaseTypeAdapter.STRING); programName.annotate(Inject.class); programName.annotate(Named.class).put("value", "programName"); adapter.addParameterField(programName); BytecodeExpression metric = gambitScope.constant(PhysicalExprOperatorCompiler.EMPTY_DIMENSION); metric = metricWith(cb, metric, "source", moduleName); return adapter; }
From source file:com.yahoo.yqlplus.engine.internal.source.SourceUnitGenerator.java
public ObjectBuilder createSourceAdapter(String sourceName, Class<?> sourceClass, TypeWidget sourceType, TypeWidget contextType, BytecodeExpression sourceProvider) { gambitScope.addClass(sourceClass);/*from www. j av a 2 s .c om*/ ObjectBuilder adapter = gambitScope.createObject(); ObjectBuilder.ConstructorBuilder cb = adapter.getConstructor(); ObjectBuilder.FieldBuilder fld = adapter.field("$source", sourceType); fld.addModifiers(Opcodes.ACC_FINAL); cb.exec(fld.get(cb.local("this")).write(cb.cast(sourceType, cb.invokeExact(Location.NONE, "get", Provider.class, AnyTypeWidget.getInstance(), sourceProvider)))); adapter.addParameterField(fld); ObjectBuilder.FieldBuilder programName = adapter.field("$programName", BaseTypeAdapter.STRING); programName.annotate(Inject.class); programName.annotate(Named.class).put("value", "programName"); adapter.addParameterField(programName); BytecodeExpression metric = gambitScope.constant(PhysicalExprOperatorCompiler.EMPTY_DIMENSION); metric = metricWith(cb, metric, "source", sourceName); for (String operation : OPERATIONS) { // adapter.addParameterField(adapter.finalField("$metricDimension$" + operation, metricWith(cb, metric, "operation", operation))); // current code breaks if we add operation dimension; don't for now TODO: modify that code to ignore new dimensions adapter.addParameterField(adapter.finalField("$metricDimension$" + operation, metric)); } return adapter; }
From source file:cz.vutbr.fit.xhriba01.bc.lib.Utils.java
License:Open Source License
/** * Creates text representation of asm method access flag. * // w ww. j a v a 2 s.co m * @param flag asm method access flag * @return formatted string representing the access flag */ public static String formatMethodAccessFlags(int flag) { List<String> accesses = new ArrayList<>(); if ((flag & Opcodes.ACC_PUBLIC) != 0) { accesses.add("public"); } if ((flag & Opcodes.ACC_PROTECTED) != 0) { accesses.add("protected"); } if ((flag & Opcodes.ACC_PRIVATE) != 0) { accesses.add("private"); } if ((flag & Opcodes.ACC_STATIC) != 0) { accesses.add("static"); } if ((flag & Opcodes.ACC_ABSTRACT) != 0) { accesses.add("abstract"); } if ((flag & Opcodes.ACC_FINAL) != 0) { accesses.add("final"); } return join(accesses.toArray(new String[accesses.size()]), " "); }
From source file:cz.vutbr.fit.xhriba01.bc.lib.Utils.java
License:Open Source License
/** * Creates text representation of asm class access flag. * //from w w w. j a va 2 s . c o m * @param flag asm class access flag * @return formatted string representing the access flag */ public static String formatClassAccessFlags(int flag) { List<String> accesses = new ArrayList<>(); if ((flag & Opcodes.ACC_PUBLIC) != 0) { accesses.add("public"); } if ((flag & Opcodes.ACC_PROTECTED) != 0) { accesses.add("protected"); } if ((flag & Opcodes.ACC_PRIVATE) != 0) { accesses.add("private"); } if ((flag & Opcodes.ACC_STATIC) != 0) { accesses.add("static"); } if ((flag & Opcodes.ACC_ABSTRACT) != 0) { accesses.add("abstract"); } if ((flag & Opcodes.ACC_FINAL) != 0) { accesses.add("final"); } if ((flag & Opcodes.ACC_ENUM) != 0) { accesses.add("enum"); } else if ((flag & Opcodes.ACC_INTERFACE) != 0) { accesses.add("interface"); } else { accesses.add("class"); } return join(accesses.toArray(new String[accesses.size()]), " "); }
From source file:de.scoopgmbh.copper.instrument.MethodInfo.java
License:Apache License
public String getDeclaration() { StringBuilder sb = new StringBuilder(); if ((access & Opcodes.ACC_PRIVATE) != 0) sb.append("private "); if ((access & Opcodes.ACC_PROTECTED) != 0) sb.append("protected "); if ((access & Opcodes.ACC_PUBLIC) != 0) sb.append("public "); if ((access & Opcodes.ACC_STATIC) != 0) sb.append("static "); if ((access & Opcodes.ACC_FINAL) != 0) sb.append("final "); sb.append(Type.getReturnType(descriptor).getClassName()).append(' ').append(methodName).append('('); boolean first = true; for (Type t : Type.getArgumentTypes(descriptor)) { if (!first) sb.append(", "); first = false;/*from w w w . j av a 2 s.c o m*/ sb.append(t.getClassName()); } sb.append(')'); return sb.toString(); }
From source file:de.tuberlin.uebb.jbop.optimizer.array.LocalArrayLengthInlinerTest.java
License:Open Source License
/** * Tests that LocalArrayLengthInliner is working correctly. * //from w w w . jav a2 s . c o m * @throws Exception * the exception */ @Test public void test_newarrayAndSubarray() throws Exception { // INIT final String owner = "de.tuberlin.uebb.jbop.optimizer.array.LocalArrayLengthTestClass"; final ClassNodeBuilder builder = ClassNodeBuilder.createClass(owner).// addField("doubleArray", "[[D").initArray(15, 42) .withModifiers(Opcodes.ACC_PRIVATE, Opcodes.ACC_FINAL).// addMethod("getArrayLength", "()I").withAnnotation(Optimizable.class).// addArray("[D", 15).// 3 -> 3 addInsn(new VarInsnNode(Opcodes.ALOAD, 1)).// 1 -> 0| addInsn(new InsnNode(Opcodes.ARRAYLENGTH)).// 1 -> 0|1 addGetClassField("doubleArray").// 2 -> 2 addInsn(new InsnNode(Opcodes.ICONST_0)).// 1 -> 1 addInsn(new InsnNode(Opcodes.AALOAD)).// 1 -> 1 addInsn(new VarInsnNode(Opcodes.ASTORE, 2)).// 1 -> 1 addInsn(new VarInsnNode(Opcodes.ALOAD, 2)).// 1 -> 0| addInsn(new InsnNode(Opcodes.ARRAYLENGTH)).// 1 -> 0|1 addInsn(new InsnNode(Opcodes.IADD)).// 1 -> 1 addInsn(new InsnNode(Opcodes.IRETURN));// 1 -> 1 // 14 -> 12 final LocalArrayLengthInliner inliner = new LocalArrayLengthInliner(); inliner.setInputObject(builder.toClass().instance()); // RUN STEP 1 final MethodNode method = builder.getMethod("getArrayLength"); assertEquals(14, method.instructions.size()); final InsnList optimized = inliner.optimize(method.instructions, method); method.instructions = optimized; // ASSERT STEP 1 assertEquals(12, optimized.size()); assertEquals(15, NodeHelper.getNumberValue(optimized.get(3)).intValue()); assertEquals(42, NodeHelper.getNumberValue(optimized.get(9)).intValue()); // RUN STEP 2 final InsnList optimized2 = inliner.optimize(method.instructions, method); // ASSERT STEP 2 assertEquals(12, optimized2.size()); }
From source file:de.tuberlin.uebb.jbop.optimizer.array.LocalArrayValueInlinerTest.java
License:Open Source License
/** * Tests that LocalArrayValueInliner is working correctly. * //from ww w. ja va 2 s. c om * @throws Exception * the exception */ @Test public void testLocalArrayValueInliner() throws Exception { // INIT final String owner = "de.tuberlin.uebb.jbop.optimizer.array.LocalArrayValueTestClass"; final ClassNodeBuilder builder = ClassNodeBuilder.createClass(owner).// addField("doubleArray", "[[D").// withAnnotation(ImmutableArray.class).// withModifiers(Opcodes.ACC_PRIVATE, Opcodes.ACC_FINAL).// initArray(2, 2).// initMultiArrayWith(1.0, 0, 0).// initMultiArrayWith(2.0, 0, 1).// initMultiArrayWith(3.0, 1, 0).// initMultiArrayWith(4.0, 1, 1).// addMethod("getArrayValue", "()D").withAnnotation(Optimizable.class).// addGetClassField("doubleArray").// 2 -> 2 addInsn(new InsnNode(Opcodes.ICONST_0)).// 1 -> 1 addInsn(new InsnNode(Opcodes.AALOAD)).// 1 -> 1 addInsn(new VarInsnNode(Opcodes.ASTORE, 2)).// 1 -> 1 addInsn(new VarInsnNode(Opcodes.ALOAD, 2)).// 1 -> 0| addInsn(new InsnNode(Opcodes.ICONST_1)).// 1 -> 0| addInsn(new InsnNode(Opcodes.DALOAD)).// 1 -> 0| 1 addInsn(new InsnNode(Opcodes.DRETURN));// 1 -> 1 // 14 -> 12 final LocalArrayValueInliner inliner = new LocalArrayValueInliner(); inliner.setInputObject(builder.toClass().instance()); // RUN STEP 1 final MethodNode method = builder.getMethod("getArrayValue"); assertEquals(9, method.instructions.size()); final InsnList optimized = inliner.optimize(method.instructions, method); // ASSERT STEP 1 assertEquals(7, optimized.size()); assertEquals(2.0, NodeHelper.getNumberValue(optimized.get(5)).doubleValue(), .0001); // RUN STEP 2 final InsnList optimized2 = inliner.optimize(method.instructions, method); // ASSERT STEP 2 assertEquals(7, optimized2.size()); }
From source file:de.zib.sfs.instrument.AbstractSfsAdapter.java
License:BSD License
@Override public void visitSource(String source, String debug) { if (this.callbackTypeDescriptor != null) { // private final <CallbackType> callback; FieldVisitor callbackFV = this.cv.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL, "callback", this.callbackTypeDescriptor, null, null); callbackFV.visitEnd();/*from w w w. jav a2 s .c om*/ } // private final InstrumentationActive instrumentationActive; FieldVisitor instrumentationActiveFV = this.cv.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL, "instrumentationActive", Type.getDescriptor(InstrumentationActive.class), null, null); instrumentationActiveFV.visitEnd(); appendFields(this.cv); this.cv.visitSource(source, debug); }
From source file:de.zib.sfs.instrument.RandomAccessFileAdapter.java
License:BSD License
@Override protected void appendWrappedMethods(ClassVisitor visitor) { ResultPasser resultDiscarder = new DiscardResultPasser(); wrapMethod(Opcodes.ACC_PRIVATE, "open", Type.VOID_TYPE, new Type[] { Type.getType(String.class), Type.INT_TYPE }, null, new String[] { Type.getInternalName(FileNotFoundException.class) }, "openCallback", Type.getType(String.class), new ParameterResultPasser(1)); // for all read methods pass the read result to the callback ReturnResultPasser resultPasser = new ReturnResultPasser(); // invokes .length on an array ResultPasser arrayLengthPasser = new ParameterResultPasser(1) { @Override//from ww w . j av a 2 s . c om public void passResult(MethodVisitor mv) { mv.visitInsn(Opcodes.ARRAYLENGTH); } }; // invokes .length(); on the current local variable ResultPasser stringLengthPasser = new ReturnResultPasser() { @Override public void passResult(MethodVisitor mv) { mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(String.class), "length", Type.getMethodDescriptor(Type.INT_TYPE), false); } }; if (!skipReads()) { wrapMethod(Opcodes.ACC_PUBLIC, "read", Type.INT_TYPE, null, null, new String[] { Type.getInternalName(IOException.class) }, "readCallback", Type.INT_TYPE, resultPasser); wrapMethod(Opcodes.ACC_PUBLIC, "read", Type.INT_TYPE, new Type[] { Type.getType(byte[].class) }, null, new String[] { Type.getInternalName(IOException.class) }, "readBytesCallback", Type.INT_TYPE, resultPasser); wrapMethod(Opcodes.ACC_PUBLIC, "read", Type.INT_TYPE, new Type[] { Type.getType(byte[].class), Type.INT_TYPE, Type.INT_TYPE }, null, new String[] { Type.getInternalName(IOException.class) }, "readBytesCallback", Type.INT_TYPE, resultPasser); wrapMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "readFully", Type.VOID_TYPE, new Type[] { Type.getType(byte[].class) }, null, new String[] { Type.getInternalName(IOException.class) }, "readBytesCallback", Type.INT_TYPE, arrayLengthPasser); wrapMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "readFully", Type.VOID_TYPE, new Type[] { Type.getType(byte[].class), Type.INT_TYPE, Type.INT_TYPE }, null, new String[] { Type.getInternalName(IOException.class) }, "readBytesCallback", Type.INT_TYPE, new ParameterResultPasser(3)); // record length of read string wrapMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "readLine", Type.getType(String.class), null, null, new String[] { Type.getInternalName(IOException.class) }, "readBytesCallback", Type.INT_TYPE, stringLengthPasser); wrapMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "readUTF", Type.getType(String.class), null, null, new String[] { Type.getInternalName(IOException.class) }, "readBytesCallback", Type.INT_TYPE, stringLengthPasser); } // take length of parameter string instead of return value stringLengthPasser = new ParameterResultPasser(1) { @Override public void passResult(MethodVisitor mv) { mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(String.class), "length", Type.getMethodDescriptor(Type.INT_TYPE), false); } }; if (!skipWrites()) { // 1 byte write, no result needed wrapMethod(Opcodes.ACC_PUBLIC, "write", Type.VOID_TYPE, new Type[] { Type.INT_TYPE }, null, new String[] { Type.getInternalName(IOException.class) }, "writeCallback", null, resultDiscarder); // have the byte array put on top of the stack, then pass its length // to // the callback wrapMethod(Opcodes.ACC_PUBLIC, "write", Type.VOID_TYPE, new Type[] { Type.getType(byte[].class) }, null, new String[] { Type.getInternalName(IOException.class) }, "writeBytesCallback", Type.INT_TYPE, arrayLengthPasser); // have the len parameter put on top of the stack wrapMethod(Opcodes.ACC_PUBLIC, "write", Type.VOID_TYPE, new Type[] { Type.getType(byte[].class), Type.INT_TYPE, Type.INT_TYPE }, null, new String[] { Type.getInternalName(IOException.class) }, "writeBytesCallback", Type.INT_TYPE, new ParameterResultPasser(3)); wrapMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "writeBytes", Type.VOID_TYPE, new Type[] { Type.getType(String.class) }, null, new String[] { Type.getInternalName(IOException.class) }, "writeBytesCallback", Type.INT_TYPE, stringLengthPasser); // twice the data if written as characters wrapMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "writeChars", Type.VOID_TYPE, new Type[] { Type.getType(String.class) }, null, new String[] { Type.getInternalName(IOException.class) }, "writeBytesCallback", Type.INT_TYPE, new ParameterResultPasser(1) { @Override public void passResult(MethodVisitor mv) { mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(String.class), "length", Type.getMethodDescriptor(Type.INT_TYPE), false); mv.visitInsn(Opcodes.ICONST_2); mv.visitInsn(Opcodes.IMUL); } }); wrapMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "writeUTF", Type.VOID_TYPE, new Type[] { Type.getType(String.class) }, null, new String[] { Type.getInternalName(IOException.class) }, "writeBytesCallback", Type.INT_TYPE, stringLengthPasser); } }
From source file:de.zib.sfs.instrument.RandomAccessFileAdapter.java
License:BSD License
private boolean isReadFullyMethod(int access, String name, String desc, String signature, String[] exceptions) { return access == (Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL) && "readFully".equals(name) && (Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(byte[].class)).equals(desc) || Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(byte[].class), Type.INT_TYPE, Type.INT_TYPE).equals(desc)) && null == signature && exceptions != null && exceptions.length == 1 && Type.getInternalName(IOException.class).equals(exceptions[0]) && !skipReads(); }