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.compiler.environments.TopLevelEnvGen.java
License:Open Source License
/** * Implementing "static reflection" for the method getFooRaw so the * interpreter uses a switch instruction for ***GetRaw * based on the hash values of String names in this namespace. *//* ww w . j a v a 2 s . co m*/ private static void writeMethodGetRaw(ClassWriter cw, String className, String methodName, EnvironmentClass environmentClass, EnvSymbolNames symbolNames) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, "(Ljava/lang/String;)" + environmentClass.descriptor(), null, null); mv.visitCode(); Label beginFunction = new Label(); mv.visitLabel(beginFunction); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I"); mv.visitVarInsn(Opcodes.ISTORE, 2); Label beginLoop = new Label(); mv.visitLabel(beginLoop); Relation<String, Integer> hashCodeRelation = symbolNames.makeHashCodeRelation(environmentClass); ArrayList<Integer> sortedCodes = new ArrayList<Integer>(hashCodeRelation.secondSet()); Collections.sort(sortedCodes); Label returnNull = new Label(); getRawHelper(mv, className, hashCodeRelation, environmentClass, sortedCodes, returnNull); mv.visitLabel(returnNull); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitInsn(Opcodes.ARETURN); Label endFunction = new Label(); mv.visitLabel(endFunction); mv.visitLocalVariable("this", Naming.internalToDesc(className), null, beginFunction, endFunction, 0); mv.visitLocalVariable("queryString", "Ljava/lang/String;", null, beginFunction, endFunction, 1); mv.visitLocalVariable("queryHashCode", "I", null, beginLoop, endFunction, 2); // See comment above on ClassWriter.COMPUTE_FRAMES mv.visitMaxs(2, 3); mv.visitEnd(); }
From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java
License:Open Source License
/** * Implementing "static reflection" for the method putRaw so the * interpreter uses a switch instruction for ***PutRaw * based on the hash values of String names in this namespace. *//*from www .j a v a 2 s. co m*/ private static void writeMethodPutRaw(ClassWriter cw, String className, String methodName, EnvironmentClass environmentClass, EnvSymbolNames symbolNames) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, "(" + STRING_DESCRIPTOR + environmentClass.descriptor() + ")V", null, null); mv.visitCode(); Label beginFunction = new Label(); mv.visitLabel(beginFunction); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, STRING_INTERNALNAME, "hashCode", "()I"); mv.visitVarInsn(Opcodes.ISTORE, 3); Label beginLoop = new Label(); mv.visitLabel(beginLoop); Relation<String, Integer> hashCodeRelation = symbolNames.makeHashCodeRelation(environmentClass); ArrayList<Integer> sortedCodes = new ArrayList<Integer>(hashCodeRelation.secondSet()); Collections.sort(sortedCodes); Label notFound = new Label(); putRawHelper(mv, className, environmentClass, hashCodeRelation, sortedCodes, notFound); mv.visitLabel(notFound); mv.visitInsn(Opcodes.RETURN); Label endFunction = new Label(); mv.visitLabel(endFunction); mv.visitLocalVariable("this", Naming.internalToDesc(className), null, beginFunction, endFunction, 0); mv.visitLocalVariable("queryString", STRING_DESCRIPTOR, null, beginFunction, endFunction, 1); mv.visitLocalVariable("value", environmentClass.descriptor(), null, beginFunction, endFunction, 2); mv.visitLocalVariable("queryHashCode", "I", null, beginLoop, endFunction, 3); // See comment above on ClassWriter.COMPUTE_FRAMES mv.visitMaxs(2, 4); mv.visitEnd(); }
From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java
License:Open Source License
private static void writeNullGetter(ClassWriter cw, String className, String methodName, String signature) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, signature, null, null); mv.visitCode();/*from w ww.j av a 2s . c o m*/ Label l0 = new Label(); mv.visitLabel(l0); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitInsn(Opcodes.ARETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", Naming.internalToDesc(className), null, l0, l1, 0); mv.visitLocalVariable("str", "Ljava/lang/String;", null, l0, l1, 1); // See comment above on ClassWriter.COMPUTE_FRAMES mv.visitMaxs(1, 2); mv.visitEnd(); }
From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java
License:Open Source License
private static void writeNullSetter(ClassWriter cw, String className, String methodName, String signature) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, signature, null, null); mv.visitCode();/*from ww w .j ava2 s.c o m*/ Label l0 = new Label(); mv.visitLabel(l0); mv.visitInsn(Opcodes.RETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", Naming.internalToDesc(className), null, l0, l1, 0); mv.visitLocalVariable("str", "Ljava/lang/String;", null, l0, l1, 1); mv.visitLocalVariable("f2", "Ljava/lang/Number;", null, l0, l1, 2); // See comment above on ClassWriter.COMPUTE_FRAMES mv.visitMaxs(0, 3); mv.visitEnd(); }
From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java
License:Open Source License
private static void writeRemoveMethod(ClassWriter cw, String className, String methodName, String invokeMethod, EnvironmentClass environmentClass) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, "(Ljava/lang/String;)V", null, null); mv.visitCode();/*from w ww . j av a 2 s.co m*/ Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, className, invokeMethod, "(Ljava/lang/String;" + environmentClass.descriptor() + ")V"); Label l1 = new Label(); mv.visitLabel(l1); mv.visitInsn(Opcodes.RETURN); Label l2 = new Label(); mv.visitLabel(l2); mv.visitLocalVariable("this", Naming.internalToDesc(className), null, l0, l2, 0); mv.visitLocalVariable("name", "Ljava/lang/String;", null, l0, l2, 1); // See comment above on ClassWriter.COMPUTE_FRAMES mv.visitMaxs(3, 2); mv.visitEnd(); }
From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java
License:Open Source License
private static void writeDumpMethod(ClassWriter cw, String className, EnvSymbolNames symbolNames) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "dump", "(Ljava/lang/Appendable;)Ljava/lang/Appendable;", null, new String[] { "java/io/IOException" }); mv.visitCode();/* w w w.j a va 2s .c om*/ Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, className, "within", Type.getType(HasAt.class).getDescriptor()); Label l1 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l1); Label l2 = new Label(); mv.visitLabel(l2); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, className, "within", Type.getType(HasAt.class).getDescriptor()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getType(HasAt.class).getInternalName(), "at", "()Ljava/lang/String;"); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/lang/Appendable", "append", "(Ljava/lang/CharSequence;)Ljava/lang/Appendable;"); mv.visitInsn(Opcodes.POP); Label l3 = new Label(); mv.visitLabel(l3); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitLdcInsn("\n"); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/lang/Appendable", "append", "(Ljava/lang/CharSequence;)Ljava/lang/Appendable;"); mv.visitInsn(Opcodes.POP); Label l4 = new Label(); mv.visitJumpInsn(Opcodes.GOTO, l4); mv.visitLabel(l1); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitLdcInsn("Not within anything.\n"); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/lang/Appendable", "append", "(Ljava/lang/CharSequence;)Ljava/lang/Appendable;"); mv.visitInsn(Opcodes.POP); mv.visitLabel(l4); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, className, "verboseDump", "Z"); Label l5 = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, l5); int linebreaks = dumpFields(mv, className, EnvironmentClass.FVALUE, symbolNames, 0); dumpFields(mv, className, EnvironmentClass.FTYPE, symbolNames, linebreaks); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitLdcInsn("\n"); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/lang/Appendable", "append", "(Ljava/lang/CharSequence;)Ljava/lang/Appendable;"); mv.visitInsn(Opcodes.POP); mv.visitLabel(l5); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitInsn(Opcodes.ARETURN); Label l9 = new Label(); mv.visitLabel(l9); mv.visitLocalVariable("this", Naming.internalToDesc(className), null, l0, l9, 0); mv.visitLocalVariable("a", "Ljava/lang/Appendable;", null, l0, l9, 1); // See comment above on ClassWriter.COMPUTE_FRAMES mv.visitMaxs(2, 2); mv.visitEnd(); }
From source file:com.sun.fortress.compiler.OverloadSet.java
License:Open Source License
protected void generateAnOverloadDefinitionInner(String _name, CodeGenClassWriter cv) { if (principalMember == null) return;/*from ww w.j a v a 2 s . co m*/ // "(" anOverloadedArg^N ")" returnType // Not sure what to do with return type. String signature = getSignature(); String[] exceptions = getExceptions(); // Right now we extract any necessary static arguments from // the principalMember. This may turn out to be wrong, but it // ought to be the case that principalMember is always set to // the statically most applicable method for the given set of // overloadings under consideration. [At present this does // not always appear to be the case in practice.] List<StaticParam> sargs = null; /* Some overloads have static args, but even if they are supplied, * runtime inference is still necessary (so I think) -- drc 2010-02-24 * * Not quite so -- if each static parameter is mentioned in any * invariant occurrence, then the supplied type is exact. * Runtime inference is only necessary when the occurrences are * ALL in variant context. Static analysis can also supply * no-more-precise-than information that it learns from context. * If no-less and no-more precise information are equal, then * again, dynamic inference is not needed. */ if (principalMember != null) { sargs = staticParametersOf(principalMember.tagF); } if (CodeGenerationPhase.debugOverloading >= 2) System.err.println("Emitting overload " + _name + signature); String PCNOuter = null; Naming.XlationData xldata = null; String overloaded_name = oMangle(_name); ArrayList<InitializedStaticField> isf_list = new ArrayList<InitializedStaticField>(); if (sargs != null) { // Map<String, String> xlation = new HashMap<String, String>(); xldata = CodeGen.xlationData(Naming.FUNCTION_GENERIC_TAG); String sparamsType = NamingCzar.genericDecoration(sargs, xldata, ifNone); // TODO: which signature is which? One needs to not have generics info in it. genericSchema = NamingCzar.makeArrowDescriptor(ifNone, overloadedDomain(), getRange()); /* Save this for later, to forestall collisions with * single functions that hit the generic type. * * Question: is this a problem with references to single * types within the overload itself? I think it might be, if we * do not use exactly the same handshake. */ // temporary fix to problems with type analysis. Check to make sure // that we don't generate a generic function class that was already // generated by our parent // A more complete fix would delve into the type checker // see bug PROJECTFORTRESS-19 (not_working_library_tests/MaybeTest2.fss) if (parent != null && parent.genericSchema.equals(genericSchema)) return; //prevent duplication String packageAndClassName = NamingCzar.javaPackageClassForApi(ifNone); // If we have static arguments, then our caller must be // invoking us by instantiating a closure class and then // calling its apply method. Thus we need to make sure // that we generate the expected closure class rather than // a top-level method. String PCN = Naming.genericFunctionPkgClass(packageAndClassName, _name, sparamsType, genericSchema); PCNOuter = Naming.genericFunctionPkgClass(packageAndClassName, _name, Naming.LEFT_OXFORD + Naming.RIGHT_OXFORD, genericSchema); // System.err.println("Looks generic.\n signature " + signature + // "\n gArrType " + genericArrowType + // "\n sparamsType " + sparamsType + // "\n PCN " + PCN + // "\n PCNOuter " + PCNOuter); cv = new CodeGenClassWriter(ClassWriter.COMPUTE_FRAMES, cv); overloaded_name = InstantiatingClassloader.closureClassPrefix(PCN, cv, PCN, signature, null, isf_list); } MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, // access, overloaded_name, // name, signature, // sp.getFortressifiedSignature(), null, // signature, // depends on generics, I think exceptions); // exceptions); generateBody(mv, 0); if (PCNOuter != null) { InstantiatingClassloader.optionalStaticsAndClassInitForTO(isf_list, cv); cv.dumpClass(PCNOuter, xldata); } }
From source file:com.sun.fortress.repository.ForeignJava.java
License:Open Source License
private boolean isPublic(int modifiers) { return 0 != (modifiers & Opcodes.ACC_PUBLIC); }
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); /*//ww w. j a v 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 static byte[] instantiateAnyTuple(String dename, List<String> parameters) { /*//w w w . j a va 2 s .c o m * Single parameter, N, which is the arity of the tuple. * * implements Ljava/util/List; * implements Lfortress/AnyType$Any; * abstract methods o1 ... oN (or 0 ... N-1, depending on tuple origin) */ int n = Integer.parseInt(parameters.get(0)); ManglingClassWriter cw = new ManglingClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); String[] superInterfaces = { // "java/util/List", "fortress/AnyType$Any" }; cw.visit(JVM_BYTECODE_VERSION, Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE, dename, null, "java/lang/Object", superInterfaces); for (int i = 0; i < n; i++) { String m = TUPLE_OBJECT_ELT_PFX + (i + Naming.TUPLE_ORIGIN); String sig = UNTYPED_GETTER_SIG; interfaceMethod(cw, m, sig); } cw.visitEnd(); return cw.toByteArray(); }