List of usage examples for org.objectweb.asm Opcodes ACC_STATIC
int ACC_STATIC
To view the source code for org.objectweb.asm Opcodes ACC_STATIC.
Click Source Link
From source file:com.sun.fortress.runtimeSystem.InstantiatingClassloader.java
License:Open Source License
private byte[] instantiateAbstractArrow(String name, List<String> parameters) { ManglingClassWriter cw = new ManglingClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); /*// w w w . jav a2 s . c o m * Special case extensions to plumb tuples * correctly in the face of generics instantiated * with tuple types. * * Except, recall that Arrow parameters are domain...;range * * if > 1 param then * unwrap = params * wrap = tuple params * else 1 param * if tuple * wrap = param * unwrap = untuple params * else * unwrap = param * wrap = null * * Use unwrapped parameters to generate the all-Objects case * for casting; check the generated signature against the input * to see if we are them. * */ Triple<List<String>, List<String>, String> stuff = normalizeArrowParameters(parameters); List<String> flat_params_and_ret = stuff.getA(); List<String> tupled_params_and_ret = stuff.getB(); String tupleType = stuff.getC(); List<String> flat_obj_params_and_ret = Useful.applyToAll(flat_params_and_ret, toJLO); List<String> norm_obj_params_and_ret = normalizeArrowParametersAndReturn(flat_obj_params_and_ret); List<String> norm_params_and_ret = normalizeArrowParametersAndReturn(flat_params_and_ret); String obj_sig = stringListToGeneric(ABSTRACT_ARROW, norm_obj_params_and_ret); String obj_intf_sig = stringListToGeneric(Naming.ARROW_TAG, norm_obj_params_and_ret); String wrapped_sig = stringListToGeneric(WRAPPED_ARROW, norm_params_and_ret); String typed_intf_sig = stringListToGeneric(Naming.ARROW_TAG, norm_params_and_ret); String unwrapped_apply_sig; if (parameters.size() == 2 && parameters.get(0).equals(Naming.INTERNAL_SNOWMAN)) unwrapped_apply_sig = arrowParamsToJVMsig(parameters.subList(1, 2)); else unwrapped_apply_sig = arrowParamsToJVMsig(flat_params_and_ret); String obj_apply_sig = arrowParamsToJVMsig(flat_obj_params_and_ret); String[] interfaces = new String[] { stringListToArrow(norm_params_and_ret) }; /* * Note that in the case of foo -> bar, * normalized = flattened, and tupled does not exist (is null). */ String typed_tupled_intf_sig = tupled_params_and_ret == null ? null : stringListToGeneric(Naming.ARROW_TAG, tupled_params_and_ret); String objectified_tupled_intf_sig = tupled_params_and_ret == null ? null : stringListToGeneric(Naming.ARROW_TAG, Useful.applyToAll(tupled_params_and_ret, toJLO)); boolean is_all_objects = norm_obj_params_and_ret.equals(norm_params_and_ret); String _super = is_all_objects ? "java/lang/Object" : obj_sig; cw.visit(JVM_BYTECODE_VERSION, ACC_PUBLIC + ACC_SUPER + ACC_ABSTRACT, name, null, _super, interfaces); simpleInitMethod(cw, _super); /* */ if (!is_all_objects) { // implement method for the object version. // cast parameters, invoke this.apply on cast parameters, ARETURN // note cut and paste from apply below, work in progress. MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, Naming.APPLY_METHOD, obj_apply_sig, null, null); mv.visitVarInsn(Opcodes.ALOAD, 0); // this int unwrapped_l = flat_params_and_ret.size(); for (int i = 0; i < unwrapped_l - 1; i++) { String t = flat_params_and_ret.get(i); if (!t.equals(Naming.INTERNAL_SNOWMAN) || unwrapped_l > 2) { mv.visitVarInsn(Opcodes.ALOAD, i + 1); // element // mv.visitTypeInsn(CHECKCAST, t); generalizedCastTo(mv, Naming.internalToType(t)); } } mv.visitMethodInsn(INVOKEVIRTUAL, name, Naming.APPLY_METHOD, unwrapped_apply_sig); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(Naming.ignoredMaxsParameter, Naming.ignoredMaxsParameter); mv.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, Naming.ANY_TYPE_CLASS); mv.visitJumpInsn(Opcodes.IFEQ, fail); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitTypeInsn(Opcodes.CHECKCAST, Naming.ANY_TYPE_CLASS); mv.visitMethodInsn(Opcodes.INVOKESTATIC, name, IS_A, "(" + Naming.internalToDesc(Naming.ANY_TYPE_CLASS) + ")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 Any { String sig = "(" + Naming.internalToDesc(Naming.ANY_TYPE_CLASS) + ")Z"; MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, IS_A, sig, null, null); Label fail = new Label(); //get RTTI to compare to mv.visitFieldInsn(GETSTATIC, name, Naming.RTTI_FIELD, Naming.RTTI_CONTAINER_DESC); //get RTTI of object mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(INVOKEINTERFACE, Naming.ANY_TYPE_CLASS, Naming.RTTI_GETTER, "()" + Naming.RTTI_CONTAINER_DESC); // mv.visitJumpInsn(IFNONNULL, fail); mv.visitMethodInsn(INVOKEVIRTUAL, Naming.RTTI_CONTAINER_TYPE, Naming.RTTI_SUBTYPE_METHOD_NAME, Naming.RTTI_SUBTYPE_METHOD_SIG); //mv.visitIntInsn(BIPUSH, 0); 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(); } // castTo { /* * If arg0 instanceof typed_intf_sig * return arg0 * arg0 = arg0.getWrappee() * if arg0 instanceof typed_intf_sig * return arg0 * new WrappedArrow * dup * push argo * init * return tos */ MethodVisitor mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, CAST_TO, "(" + // Naming.internalToDesc(obj_intf_sig) "Ljava/lang/Object;" + ")" + Naming.internalToDesc(typed_intf_sig), null, null); Label not_instance1 = new Label(); Label not_instance2 = new Label(); // try bare instanceof mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitTypeInsn(Opcodes.INSTANCEOF, typed_intf_sig); mv.visitJumpInsn(Opcodes.IFEQ, not_instance1); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitTypeInsn(Opcodes.CHECKCAST, typed_intf_sig); mv.visitInsn(Opcodes.ARETURN); // unwrap mv.visitLabel(not_instance1); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitTypeInsn(Opcodes.CHECKCAST, obj_intf_sig); mv.visitMethodInsn(INVOKEINTERFACE, obj_intf_sig, getWrappee, "()" + Naming.internalToDesc(obj_intf_sig)); mv.visitVarInsn(Opcodes.ASTORE, 0); // try instanceof on unwrapped mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitTypeInsn(Opcodes.INSTANCEOF, typed_intf_sig); mv.visitJumpInsn(Opcodes.IFEQ, not_instance2); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitTypeInsn(Opcodes.CHECKCAST, typed_intf_sig); mv.visitInsn(Opcodes.ARETURN); // wrap and return mv.visitLabel(not_instance2); mv.visitTypeInsn(NEW, wrapped_sig); mv.visitInsn(DUP); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, wrapped_sig, "<init>", "(" + Naming.internalToDesc(obj_intf_sig) + ")V"); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(Naming.ignoredMaxsParameter, Naming.ignoredMaxsParameter); mv.visitEnd(); } if (typed_tupled_intf_sig != null) { /* * If arg0 instanceof typed_intf_sig * return arg0 * arg0 = arg0.getWrappee() * if arg0 instanceof typed_intf_sig * return arg0 * new WrappedArrow * dup * push argo * init * return tos */ MethodVisitor mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, CAST_TO, "(" + Naming.internalToDesc(objectified_tupled_intf_sig) + ")" + Naming.internalToDesc(typed_intf_sig), null, null); Label not_instance1 = new Label(); Label not_instance2 = new Label(); // try bare instanceof mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitTypeInsn(Opcodes.INSTANCEOF, typed_intf_sig); mv.visitJumpInsn(Opcodes.IFEQ, not_instance1); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ARETURN); // unwrap mv.visitLabel(not_instance1); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(INVOKEINTERFACE, objectified_tupled_intf_sig, getWrappee, "()" + Naming.internalToDesc(objectified_tupled_intf_sig)); mv.visitVarInsn(Opcodes.ASTORE, 0); // try instanceof on unwrapped mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitTypeInsn(Opcodes.INSTANCEOF, typed_intf_sig); mv.visitJumpInsn(Opcodes.IFEQ, not_instance2); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ARETURN); // wrap and return - untupled should be okay here, since it subtypes mv.visitLabel(not_instance2); mv.visitTypeInsn(NEW, wrapped_sig); mv.visitInsn(DUP); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, wrapped_sig, "<init>", "(" + Naming.internalToDesc(obj_intf_sig) + ")V"); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(Naming.ignoredMaxsParameter, Naming.ignoredMaxsParameter); mv.visitEnd(); } // getWrappee { MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, getWrappee, "()" + Naming.internalToDesc(obj_intf_sig), null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(ARETURN); mv.visitMaxs(1, 1); mv.visitEnd(); // return this } if (tupled_params_and_ret == null) { /* Single abstract method */ if (LOG_LOADS) System.err.println(name + ".apply" + unwrapped_apply_sig + " abstract for abstract"); MethodVisitor mv = cw.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, Naming.APPLY_METHOD, unwrapped_apply_sig, null, null); mv.visitEnd(); } else { /* * Establish two circular forwarding methods; * the eventual implementer will break the cycle. * */ String tupled_apply_sig = arrowParamsToJVMsig(tupled_params_and_ret); { /* Given tupled args, extract, and invoke apply. */ if (LOG_LOADS) System.err.println(name + ".apply" + tupled_apply_sig + " abstract for abstract"); MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, Naming.APPLY_METHOD, tupled_apply_sig, null, null); mv.visitVarInsn(Opcodes.ALOAD, 0); // closure int unwrapped_l = flat_params_and_ret.size(); for (int i = 0; i < unwrapped_l - 1; i++) { String param = flat_params_and_ret.get(i); mv.visitVarInsn(Opcodes.ALOAD, 1); // tuple mv.visitMethodInsn(INVOKEINTERFACE, tupleType, TUPLE_TYPED_ELT_PFX + (Naming.TUPLE_ORIGIN + i), "()" + Naming.internalToDesc(param)); } mv.visitMethodInsn(INVOKEVIRTUAL, name, Naming.APPLY_METHOD, unwrapped_apply_sig); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(Naming.ignoredMaxsParameter, Naming.ignoredMaxsParameter); mv.visitEnd(); } { /* Given untupled args, load, make a tuple, invoke apply. */ if (LOG_LOADS) System.err.println(name + ".apply" + unwrapped_apply_sig + " abstract for abstract"); MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, Naming.APPLY_METHOD, unwrapped_apply_sig, null, null); mv.visitVarInsn(Opcodes.ALOAD, 0); // closure int unwrapped_l = flat_params_and_ret.size(); for (int i = 0; i < unwrapped_l - 1; i++) { mv.visitVarInsn(Opcodes.ALOAD, i + 1); // element } List<String> tuple_elements = flat_params_and_ret.subList(0, unwrapped_l - 1); String make_sig = toJvmSig(tuple_elements, Naming.javaDescForTaggedFortressType(tupleType)); mv.visitMethodInsn(INVOKESTATIC, stringListToGeneric(CONCRETE_TUPLE, tuple_elements), "make", make_sig); mv.visitMethodInsn(INVOKEVIRTUAL, name, Naming.APPLY_METHOD, tupled_apply_sig); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(Naming.ignoredMaxsParameter, Naming.ignoredMaxsParameter); mv.visitEnd(); } } //RTTI comparison field final String final_name = name; ArrayList<InitializedStaticField> isf_list = new ArrayList<InitializedStaticField>(); if (!parameters.contains("java/lang/Object")) { isf_list.add(new InitializedStaticField.StaticForUsualRttiField(final_name, this)); } else { isf_list.add(new InitializedStaticField.StaticForJLOParameterizedRttiField(final_name)); } cw.visitEnd(); // //RTTI getter { MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, Naming.RTTI_GETTER, "()" + Naming.RTTI_CONTAINER_DESC, null, null); mv.visitCode(); mv.visitFieldInsn(GETSTATIC, name, Naming.RTTI_FIELD, Naming.RTTI_CONTAINER_DESC); mv.visitInsn(ARETURN); mv.visitMaxs(1, 1); mv.visitEnd(); } optionalStaticsAndClassInitForTO(isf_list, cw); return cw.toByteArray(); }
From source file:com.sun.fortress.runtimeSystem.InstantiatingClassloader.java
License:Open Source License
private byte[] instantiateConcreteTuple(String dename, List<String> parameters) { /*/*from w ww. j ava2 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.tdk.jcov.instrument.DataClass.java
License:Open Source License
/** * Checks whether this class has 'static' modifier * * @return true if class is static//from w w w . j av a 2s .c o m */ public boolean hasStaticModifier() { return (access & Opcodes.ACC_STATIC) != 0; }
From source file:com.tencent.tinker.build.auxiliaryclass.AuxiliaryClassInjectAdapter.java
License:Open Source License
@Override public void visitEnd() { // If method <clinit> and <init> are not found, we should generate a <clinit>. if (!this.isClInitExists && !this.isInitExists) { MethodVisitor mv = super.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null); mv.visitCode();/*www . j av a2s . c om*/ mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/System", "lineSeparator", "()Ljava/lang/String;", false); Label lblSkipInvalidInsn = new Label(); mv.visitJumpInsn(Opcodes.IFNONNULL, lblSkipInvalidInsn); mv.visitLdcInsn(Type.getType(this.auxiliaryClassDesc)); mv.visitVarInsn(Opcodes.ASTORE, 0); mv.visitLabel(lblSkipInvalidInsn); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(1, 1); mv.visitEnd(); } super.visitEnd(); }
From source file:com.thomas15v.packetlib.codegenerator.asm.ASMHelper.java
License:MIT License
/** * Generate a forwarding method of the form * "static T name(S object) { return object.forward(); }". * * @param clazz Class to generate new method on * @param name Name of method to generate * @param forwardname Name of method to call * @param rettype Return type of method//from w w w. j a va 2 s .co m * @param argtype Argument type */ public static void generateStaticForwardingMethod(ClassNode clazz, String name, String forwardname, Type rettype, Type argtype) { MethodNode method = new MethodNode(Opcodes.ASM5, Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, name, "()" + rettype.getDescriptor(), null, null); ASMHelper.populateSelfForwardingMethod(method, forwardname, rettype, argtype); clazz.methods.add(method); }
From source file:com.thomas15v.packetlib.codegenerator.asm.ASMHelper.java
License:MIT License
public static boolean methodIsStatic(MethodNode method) { return (method.access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC; }
From source file:com.thomas15v.packetlib.codegenerator.asm.ASMHelper.java
License:MIT License
public static boolean fieldIsStatic(FieldNode field) { return (field.access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC; }
From source file:com.thomas15v.packetlib.codegenerator.asm.ASMHelper.java
License:MIT License
/** * Get the first variable index in the supplied method which is not an * argument or "this" reference, this corresponds to the size of the * arguments passed in to the method plus an extra spot for "this" if the * method is non-static//from www . j a va2 s. c o m * * @param method MethodNode to inspect * @return first available local index which is NOT used by a method * argument or "this" */ public static int getFirstNonArgLocalIndex(MethodNode method) { return ASMHelper.getFirstNonArgLocalIndex(Type.getArgumentTypes(method.desc), (method.access & Opcodes.ACC_STATIC) == 0); }
From source file:com.trigersoft.jaque.expression.ExpressionClassVisitor.java
License:Apache License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { // if ((access & Opcodes.ACC_SYNTHETIC) != 0) // return null; if (!_method.equals(name) || !_methodDesc.equals(desc)) return null; Type ret = Type.getReturnType(desc); if (ret.getSort() == Type.VOID) throw ExpressionMethodVisitor.notLambda(Opcodes.RETURN); _type = getClass(ret);/* ww w .ja va 2 s. co m*/ Type[] args = Type.getArgumentTypes(desc); Class<?>[] argTypes = new Class<?>[args.length]; for (int i = 0; i < args.length; i++) argTypes[i] = getClass(args[i]); _argTypes = argTypes; return new ExpressionMethodVisitor(this, (access & Opcodes.ACC_STATIC) == 0 ? _me : null, argTypes); }
From source file:com.xruby.compiler.codegen.ClassGeneratorForRubyProgram.java
License:BSD License
private void createStaticVoidMain(ClassVisitor cv) { MethodGenerator mg = new MethodGenerator(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, Method.getMethod("void main (String[])"), cv, null, null, false); mg.loadArg(0);// w w w . jav a 2s . c om mg.invokeStatic(Types.RUBY_RUNTIME_TYPE, Method.getMethod("void init(String[])")); Type program = Type.getType("L" + name_ + ";"); mg.newInstance(program); mg.dup(); mg.invokeConstructor(program, CgUtil.CONSTRUCTOR); mg.invokeVirtual(program, CgUtil.getMethod("invoke", Types.RUBY_VALUE_TYPE)); mg.pop(); mg.invokeStatic(Types.RUBY_RUNTIME_TYPE, CgUtil.getMethod("fini", Type.VOID_TYPE)); mg.returnValue(); mg.endMethod(); }