List of usage examples for org.objectweb.asm Opcodes ACC_PUBLIC
int ACC_PUBLIC
To view the source code for org.objectweb.asm Opcodes ACC_PUBLIC.
Click Source Link
From source file:com.sun.fortress.runtimeSystem.InstantiatingClassloader.java
License:Open Source License
private static byte[] instantiateAnyConcreteTuple(String dename, List<String> parameters) { /*//w w w . j av a 2 s . c o m * Single parameter, N, which is the arity of the tuple. * * extends Ljava/util/AbstractList; * implements LAnyTuple[\N\]; * int size() { return N; } * Object get(int n) { * if (n >= N || n < 0) { * throw new IndexOutOfBoundsException(); * } else { * // binary search tree returning o1 ... oN * } * } */ ManglingClassWriter cw = new ManglingClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); final String super_type = "java/lang/Object"; final int n = Integer.parseInt(parameters.get(0)); final String any_tuple_n = ANY_TUPLE + Naming.LEFT_OXFORD + n + Naming.RIGHT_OXFORD; String[] superInterfaces = { any_tuple_n }; cw.visit(JVM_BYTECODE_VERSION, Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, dename, null, super_type, superInterfaces); simpleInitMethod(cw, super_type); { // size method MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "size", "()I", null, null); mv.visitCode(); mv.visitIntInsn(BIPUSH, n); mv.visitInsn(IRETURN); mv.visitMaxs(1, 1); mv.visitEnd(); } { // get method final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "get", "(I)Ljava/lang/Object;", null, null); mv.visitCode(); mv.visitVarInsn(ILOAD, 1); mv.visitIntInsn(BIPUSH, n); Label l1 = new Label(); mv.visitJumpInsn(IF_ICMPGE, l1); mv.visitVarInsn(ILOAD, 1); Label l2 = new Label(); mv.visitJumpInsn(IFGE, l2); mv.visitLabel(l1); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitTypeInsn(NEW, "java/lang/IndexOutOfBoundsException"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/IndexOutOfBoundsException", "<init>", "()V"); mv.visitInsn(ATHROW); FnVoidVoid geti = new FnVoidVoid() { @Override public void apply() { mv.visitVarInsn(ILOAD, 1); } }; FnVoid<Integer> leaf = new FnVoid<Integer>() { @Override public void apply(Integer x) { mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEINTERFACE, any_tuple_n, TUPLE_OBJECT_ELT_PFX + (Naming.TUPLE_ORIGIN + x), UNTYPED_GETTER_SIG); mv.visitInsn(ARETURN); } }; visitBinaryTree(mv, 0, n - 1, l2, geti, leaf); mv.visitMaxs(2, 2); mv.visitEnd(); } cw.visitEnd(); return cw.toByteArray(); }
From source file:com.sun.fortress.runtimeSystem.InstantiatingClassloader.java
License:Open Source License
private byte[] instantiateConcreteTuple(String dename, List<String> parameters) { /*//ww w .j a va2 s . c om * extends AnyConcreteTuple[\ N \] * * implements Tuple[\ parameters \] * * defines f1 ... fN * defines e1 ... eN * defines o1 ... oN */ ManglingClassWriter cw = new ManglingClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); final int n = parameters.size(); final String any_tuple_n = ANY_TUPLE + Naming.LEFT_OXFORD + n + Naming.RIGHT_OXFORD; final String any_concrete_tuple_n = ANY_CONCRETE_TUPLE + Naming.LEFT_OXFORD + n + Naming.RIGHT_OXFORD; final String tuple_params = stringListToTuple(parameters); String[] superInterfaces = { tuple_params }; cw.visit(JVM_BYTECODE_VERSION, ACC_PUBLIC + ACC_SUPER, dename, null, any_concrete_tuple_n, superInterfaces); /* Outline of what must be generated: // fields // init method // factory method // getRTTI method // is instance method -- takes an Object // is instance method // cast method // typed getters // untyped getters */ // fields { for (int i = 0; i < n; i++) { String f = TUPLE_FIELD_PFX + (i + Naming.TUPLE_ORIGIN); String sig = Naming.internalToDesc(parameters.get(i)); cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, f, sig, null /* for non-generic */, null /* instance has no value */); } } // init method { String init_sig = tupleParamsToJvmInitSig(parameters); MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", init_sig, null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, any_concrete_tuple_n, "<init>", Naming.voidToVoid); for (int i = 0; i < n; i++) { String f = TUPLE_FIELD_PFX + (i + Naming.TUPLE_ORIGIN); String sig = Naming.internalToDesc(parameters.get(i)); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, i + 1); mv.visitFieldInsn(Opcodes.PUTFIELD, dename, f, sig); } mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(Naming.ignoredMaxsParameter, Naming.ignoredMaxsParameter); mv.visitEnd(); } // factory method -- same args as init, returns a new one. { String init_sig = tupleParamsToJvmInitSig(parameters); String make_sig = toJvmSig(parameters, Naming.javaDescForTaggedFortressType(tuple_params)); MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "make", make_sig, null, null); mv.visitCode(); // eep(mv, "before new"); mv.visitTypeInsn(NEW, dename); mv.visitInsn(DUP); // push params for init for (int i = 0; i < n; i++) { mv.visitVarInsn(Opcodes.ALOAD, i); } // eep(mv, "before init"); mv.visitMethodInsn(INVOKESPECIAL, dename, "<init>", init_sig); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(Naming.ignoredMaxsParameter, Naming.ignoredMaxsParameter); mv.visitEnd(); } // getRTTI method/field and static initialization { final String classname = dename; MethodVisitor mv = cw.visitNoMangleMethod(Opcodes.ACC_PUBLIC, // acccess Naming.RTTI_GETTER, // name Naming.STATIC_PARAMETER_GETTER_SIG, // sig null, // generics sig? null); // exceptions mv.visitCode(); mv.visitFieldInsn(GETSTATIC, classname, Naming.RTTI_FIELD, Naming.RTTI_CONTAINER_DESC); areturnEpilogue(mv); MethodVisitor imv = cw.visitMethod(ACC_STATIC, "<clinit>", Naming.voidToVoid, null, null); //taken from codegen.emitRttiField InitializedStaticField isf = new InitializedStaticField.StaticForRttiFieldOfTuple(classname, this); isf.forClinit(imv); cw.visitField(ACC_PUBLIC + ACC_STATIC + ACC_FINAL, isf.asmName(), isf.asmSignature(), null /* for non-generic */, null /* instance has no value */); imv.visitInsn(RETURN); imv.visitMaxs(Naming.ignoredMaxsParameter, Naming.ignoredMaxsParameter); imv.visitEnd(); } // is instance method -- takes an Object { String sig = "(Ljava/lang/Object;)Z"; MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, IS_A, sig, null, null); Label fail = new Label(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitTypeInsn(Opcodes.INSTANCEOF, any_tuple_n); mv.visitJumpInsn(Opcodes.IFEQ, fail); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitTypeInsn(Opcodes.CHECKCAST, any_tuple_n); mv.visitMethodInsn(Opcodes.INVOKESTATIC, dename, IS_A, "(" + Naming.internalToDesc(any_tuple_n) + ")Z"); mv.visitInsn(Opcodes.IRETURN); mv.visitLabel(fail); mv.visitIntInsn(BIPUSH, 0); mv.visitInsn(Opcodes.IRETURN); mv.visitMaxs(Naming.ignoredMaxsParameter, Naming.ignoredMaxsParameter); mv.visitEnd(); } // is instance method -- takes an AnyTuple[\N\] { String sig = "(" + Naming.internalToDesc(any_tuple_n) + ")Z"; MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, IS_A, sig, null, null); Label fail = new Label(); for (int i = 0; i < n; i++) { mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(INVOKEINTERFACE, any_tuple_n, TUPLE_OBJECT_ELT_PFX + (Naming.TUPLE_ORIGIN + i), UNTYPED_GETTER_SIG); String cast_to = parameters.get(i); generalizedInstanceOf(mv, cast_to); mv.visitJumpInsn(Opcodes.IFEQ, fail); } mv.visitIntInsn(BIPUSH, 1); mv.visitInsn(Opcodes.IRETURN); mv.visitLabel(fail); mv.visitIntInsn(BIPUSH, 0); mv.visitInsn(Opcodes.IRETURN); mv.visitMaxs(Naming.ignoredMaxsParameter, Naming.ignoredMaxsParameter); mv.visitEnd(); } // cast method { String sig = "(" + Naming.internalToDesc(any_tuple_n) + ")" + Naming.internalToDesc(tuple_params); String make_sig = toJvmSig(parameters, Naming.javaDescForTaggedFortressType(tuple_params)); MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, CAST_TO, sig, null, null); // Get the parameters to make, and cast them. for (int i = 0; i < n; i++) { mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(INVOKEINTERFACE, any_tuple_n, TUPLE_OBJECT_ELT_PFX + (Naming.TUPLE_ORIGIN + i), UNTYPED_GETTER_SIG); String cast_to = parameters.get(i); generalizedCastTo(mv, cast_to); } mv.visitMethodInsn(INVOKESTATIC, dename, "make", make_sig); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(Naming.ignoredMaxsParameter, Naming.ignoredMaxsParameter); mv.visitEnd(); } // typed getters // untyped getters for (int i = 0; i < n; i++) { String untyped = TUPLE_OBJECT_ELT_PFX + (Naming.TUPLE_ORIGIN + i); String typed = TUPLE_TYPED_ELT_PFX + (Naming.TUPLE_ORIGIN + i); String field = TUPLE_FIELD_PFX + (Naming.TUPLE_ORIGIN + i); String param_type = parameters.get(i); String param_desc = Naming.internalToDesc(param_type); { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, untyped, UNTYPED_GETTER_SIG, null, null); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(GETFIELD, dename, field, param_desc); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(Naming.ignoredMaxsParameter, Naming.ignoredMaxsParameter); mv.visitEnd(); } { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, typed, "()" + param_desc, null, null); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(GETFIELD, dename, field, param_desc); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(Naming.ignoredMaxsParameter, Naming.ignoredMaxsParameter); mv.visitEnd(); } } cw.visitEnd(); return cw.toByteArray(); }
From source file:com.sun.javatest.junit.JUnitAnnotationTestFinder.java
License:Open Source License
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if (access == Opcodes.ACC_PUBLIC) { currMethod = name;// ww w. j a v a2s . co m return this; } else return null; }
From source file:com.sun.javatest.junit.JUnitSuperTestFinder.java
License:Open Source License
/** * Looks for methods which are test methods by calling <tt>isTestMethodSignature</tt>. * You can override that method or this one. If overriding this one, * use foundTestMethod(String) to register any test methods which you * find./* ww w . ja va2s .c o m*/ */ public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if (access == Opcodes.ACC_PUBLIC) { //System.out.println("found method " + name); if (isTestMethodSignature(name)) foundTestMethod(name); } return null; }
From source file:com.sun.tdk.jcov.instrument.DataClass.java
License:Open Source License
/** * Check whether <b>access</b> field has ACC_PUBLIC or ACC_PROTECTED flag * * @see #getAccess()//w w w . jav a2 s . c o m * @see org.objectweb.asm.Opcodes * @return true if <b>access</b> field has ACC_PUBLIC or ACC_PROTECTED flag */ @Deprecated public boolean isPublic() { return (access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0; }
From source file:com.sun.tdk.jcov.instrument.DataClass.java
License:Open Source License
/** * Check whether <b>access</b> field has ACC_PUBLIC or ACC_PROTECTED flag * * @see #getAccess()// ww w .j av a 2 s . c om * @see org.objectweb.asm.Opcodes * @return true if <b>access</b> field has ACC_PUBLIC or ACC_PROTECTED flag */ public boolean isPublicAPI() { return (access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0; }
From source file:com.sun.tdk.jcov.instrument.DataClass.java
License:Open Source License
/** * Checks whether this class has 'public ' modifier * * @return true if class is public/*from w w w .j a v a2s . com*/ */ public boolean hasPublicModifier() { return (access & Opcodes.ACC_PUBLIC) != 0; }
From source file:com.sun.tdk.jcov.processing.CombinerDataProcessor.java
License:Open Source License
/** * Scans given modifiers in attempt to find "public". * * @param modifiers - array to scan//from ww w. j ava 2 s . co m * @return true if given array is not null and contains "public" */ private boolean isPublic(DataClass c, DataClass outClass) { if (isAnonymous(c.getName())) { return isPublicAnonymous(c, outClass); } return (c.getAccess() & Opcodes.ACC_PUBLIC) != 0; }
From source file:com.sun.tdk.jcov.processing.CombinerDataProcessor.java
License:Open Source License
/** * Removes "public" and "protected" modifiers from the given list * * @param modifiers array of modifiers// w ww . ja va 2s . com * @return modified array */ private int makePrivate(int modifiers) { return modifiers & ~Opcodes.ACC_PUBLIC & ~Opcodes.ACC_PROTECTED; }
From source file:com.sun.tdk.jcov.report.ClassCoverage.java
License:Open Source License
/** * <p> Use getAccess() method to check for more specific modifiers. * getAccess() method returns a bit-mask of org.objectweb.asm.Opcodes * constants. </p>//from w w w . j a v a 2 s . c o m * * @return true if class is <b>public</b> or <b>protected</b> * @see ClassCoverage#getAccess() */ public boolean isPublic() { return (access & Opcodes.ACC_PUBLIC) != 0; }