List of usage examples for org.objectweb.asm MethodVisitor visitJumpInsn
public void visitJumpInsn(final int opcode, final Label label)
From source file:com.sun.fortress.runtimeSystem.InstantiatingClassloader.java
License:Open Source License
private byte[] instantiateConcreteTuple(String dename, List<String> parameters) { /*/*ww w . j ava 2 s . co m*/ * 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.fortress.runtimeSystem.InstantiatingClassloader.java
License:Open Source License
/** * @param mv/*from ww w.j av a2 s . com*/ * @param cast_to */ public static void generalizedInstanceOf(MethodVisitor mv, String cast_to) { if (cast_to.startsWith(Naming.UNION_OX)) { List<String> cast_to_parameters = RTHelpers.extractStringParameters(cast_to); Label done = new Label(); for (int i = 0; i < cast_to_parameters.size(); i++) { mv.visitInsn(DUP); // object to test generalizedInstanceOf(mv, cast_to_parameters.get(i)); // replaces obj w/ 1/0 mv.visitInsn(DUP); // copy for branch test. leave one on TOS // eepI(mv,"union instanceof subtest " + cast_to_parameters.get(i)); mv.visitJumpInsn(IFNE, done); mv.visitInsn(POP); // discard unnecessary zero. } mv.visitLdcInsn(0); // failure mv.visitLabel(done); mv.visitInsn(SWAP); // put tested obj on TOS mv.visitInsn(POP); // discard } else if (cast_to.startsWith(Naming.TUPLE_OX)) { mv.visitMethodInsn(Opcodes.INVOKESTATIC, CONCRETE_ + cast_to, IS_A, "(Ljava/lang/Object;)Z"); } else if (cast_to.startsWith(Naming.ARROW_OX)) { mv.visitMethodInsn(Opcodes.INVOKESTATIC, ABSTRACT_ + cast_to, IS_A, "(Ljava/lang/Object;)Z"); } else { String type = cast_to.equals(Naming.INTERNAL_SNOWMAN) ? Naming.specialFortressTypes.get(Naming.INTERNAL_SNOWMAN) : cast_to; mv.visitTypeInsn(Opcodes.INSTANCEOF, type); } }
From source file:com.sun.fortress.runtimeSystem.InstantiatingClassloader.java
License:Open Source License
/** * @param rttiClassName//from w w w . j a va 2 s . c om * @param sparams_size */ static public void emitDictionaryAndFactoryForGenericRTTIclass(ManglingClassWriter cw, String rttiClassName, int sparams_size, final Naming.XlationData xldata) { // Push nulls for opr parameters in the factory call. List<Boolean> spks; int type_sparams_size = sparams_size; if (xldata != null) { spks = xldata.isOprKind(); sparams_size = spks.size(); } else { spks = new InfiniteList<Boolean>(false); } // FIELD // static, initialized to Map-like thing cw.visitField(ACC_PRIVATE + ACC_STATIC + ACC_FINAL, "DICTIONARY", Naming.RTTI_MAP_DESC, null, null); // CLINIT // factory, consulting map, optionally invoking constructor. MethodVisitor mv = cw.visitNoMangleMethod(ACC_STATIC, "<clinit>", "()V", null, null); mv.visitCode(); // new mv.visitTypeInsn(NEW, Naming.RTTI_MAP_TYPE); // init mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, Naming.RTTI_MAP_TYPE, "<init>", "()V"); // store mv.visitFieldInsn(PUTSTATIC, rttiClassName, "DICTIONARY", Naming.RTTI_MAP_DESC); mv.visitInsn(RETURN); mv.visitMaxs(Naming.ignoredMaxsParameter, Naming.ignoredMaxsParameter); mv.visitEnd(); // FACTORY boolean useSparamsArray = sparams_size > 6; int sparamsArrayIndex = sparams_size; String fact_sig = Naming.rttiFactorySig(type_sparams_size); String init_sig = InstantiatingClassloader.jvmSignatureForOnePlusNTypes("java/lang/Class", type_sparams_size, Naming.RTTI_CONTAINER_TYPE, "V"); String get_sig; String put_sig; String getClass_sig; if (useSparamsArray) { get_sig = Naming.makeMethodDesc(Naming.RTTI_CONTAINER_ARRAY_DESC, Naming.RTTI_CONTAINER_DESC); put_sig = Naming.makeMethodDesc(Naming.RTTI_CONTAINER_ARRAY_DESC + Naming.RTTI_CONTAINER_DESC, Naming.RTTI_CONTAINER_DESC); getClass_sig = Naming.makeMethodDesc(NamingCzar.descString + Naming.RTTI_CONTAINER_ARRAY_DESC, NamingCzar.descClass); } else { get_sig = InstantiatingClassloader.jvmSignatureForNTypes(sparams_size, Naming.RTTI_CONTAINER_TYPE, Naming.RTTI_CONTAINER_DESC); put_sig = InstantiatingClassloader.jvmSignatureForNTypes(sparams_size + 1, Naming.RTTI_CONTAINER_TYPE, Naming.RTTI_CONTAINER_DESC); getClass_sig = InstantiatingClassloader.jvmSignatureForOnePlusNTypes(NamingCzar.internalString, sparams_size, Naming.RTTI_CONTAINER_TYPE, NamingCzar.descClass); } mv = cw.visitNoMangleMethod(ACC_PUBLIC + ACC_STATIC, Naming.RTTI_FACTORY, fact_sig, null, null); mv.visitCode(); /* * First arg is java class, necessary for creation of type. * * rCN x = DICTIONARY.get(args) * if x == null then * x = new rCN(args) * x = DICTIONARY.put(args, x) * end * return x */ // object mv.visitFieldInsn(GETSTATIC, rttiClassName, "DICTIONARY", Naming.RTTI_MAP_DESC); // push args int l = sparams_size; if (useSparamsArray) { mv.visitLdcInsn(sparams_size); mv.visitTypeInsn(Opcodes.ANEWARRAY, Naming.RTTI_CONTAINER_TYPE); mv.visitVarInsn(Opcodes.ASTORE, sparamsArrayIndex); InstantiatingClassloader.pushArgsIntoArray(mv, 0, l, sparamsArrayIndex, spks); } else { InstantiatingClassloader.pushArgs(mv, 0, l, spks); } // invoke Dictionary.get mv.visitMethodInsn(INVOKEVIRTUAL, Naming.RTTI_MAP_TYPE, "get", get_sig); Label not_null = new Label(); mv.visitInsn(DUP); mv.visitJumpInsn(IFNONNULL, not_null); mv.visitInsn(POP); // discard dup'd null // doing it all on the stack -- (unless too many static params, then use an array for human coded stuff) // 1) first push the dictionary and args (array if used) // 2) create new RTTI object // 3) push args again (array if used) and create the class for this object // 4) push the args again (never array) to init RTTI object // 5) add to dictionary //1) mv.visitFieldInsn(GETSTATIC, rttiClassName, "DICTIONARY", Naming.RTTI_MAP_DESC); if (useSparamsArray) { mv.visitVarInsn(ALOAD, sparamsArrayIndex); } else { InstantiatingClassloader.pushArgs(mv, 0, l, spks); } // 2) invoke constructor mv.visitTypeInsn(NEW, rttiClassName); mv.visitInsn(DUP); // 3) create class for this object String stem = Naming.rttiClassToBaseClass(rttiClassName); if (true || xldata == null) { // NOT symbolic (and a problem if we pretend that it is) mv.visitLdcInsn(stem); } else { RTHelpers.symbolicLdc(mv, stem); } if (useSparamsArray) { mv.visitVarInsn(ALOAD, sparamsArrayIndex); } else { InstantiatingClassloader.pushArgs(mv, 0, l, spks); } //(mv, "before getRTTIclass"); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Naming.RT_HELPERS, "getRTTIclass", getClass_sig); //eep(mv, "after getRTTIclass"); // 4) init RTTI object (do not use array) // NOTE only pushing type_sparams here. InstantiatingClassloader.pushArgs(mv, 0, type_sparams_size); mv.visitMethodInsn(INVOKESPECIAL, rttiClassName, "<init>", init_sig); // 5) add to dictionary mv.visitMethodInsn(INVOKEVIRTUAL, Naming.RTTI_MAP_TYPE, "putIfNew", put_sig); mv.visitLabel(not_null); mv.visitInsn(ARETURN); mv.visitMaxs(Naming.ignoredMaxsParameter, Naming.ignoredMaxsParameter); mv.visitEnd(); }
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();/* w ww. j av a 2s . co m*/ 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.weibo.lodil.mmap.impl.GenerateHugeArrays.java
License:Apache License
private static void appendToStringHashCodeEqualsCopyOf(final TypeModel tm, final ClassWriter cw, final String name2, final boolean hasListField) { final String name = tm.bcType(); MethodVisitor mv; {// ww w .j a va 2 s .c o m mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null); mv.visitCode(); final Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(176, l0); mv.visitTypeInsn(NEW, "java/lang/StringBuilder"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V"); mv.visitLdcInsn(tm.type().getSimpleName() + "{"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;"); String sep = ""; for (final FieldModel fm : tm.fields()) { final boolean text = CharSequence.class.isAssignableFrom(tm.type()); mv.visitLdcInsn(sep + fm.fieldName() + "=" + (text ? "'" : "")); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;"); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, name2, "get" + fm.titleFieldName(), "()" + fm.bcLFieldType()); String appendType = "Ljava/lang/Object;"; final Class fmType = fm.type(); if (fmType.isPrimitive()) { if ((fmType == byte.class) || (fmType == short.class)) { appendType = "I"; } else { appendType = fm.bcLFieldType(); } } mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(" + appendType + ")Ljava/lang/StringBuilder;"); sep = text ? "', " : ", "; } if (sep.startsWith("'")) { mv.visitIntInsn(BIPUSH, 39); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(C)Ljava/lang/StringBuilder;"); } mv.visitIntInsn(BIPUSH, 125); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(C)Ljava/lang/StringBuilder;"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;"); mv.visitInsn(ARETURN); final Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", "L" + name2 + ";", null, l0, l1, 0); mv.visitMaxs(3, 1); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "equals", "(Ljava/lang/Object;)Z", null, null); mv.visitCode(); final Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(194, l0); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); final Label l1 = new Label(); mv.visitJumpInsn(IF_ACMPNE, l1); mv.visitInsn(ICONST_1); mv.visitInsn(IRETURN); mv.visitLabel(l1); mv.visitLineNumber(195, l1); mv.visitVarInsn(ALOAD, 1); final Label l2 = new Label(); mv.visitJumpInsn(IFNULL, l2); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;"); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;"); final Label l3 = new Label(); mv.visitJumpInsn(IF_ACMPEQ, l3); mv.visitLabel(l2); mv.visitInsn(ICONST_0); mv.visitInsn(IRETURN); mv.visitLabel(l3); mv.visitLineNumber(197, l3); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(CHECKCAST, name2); mv.visitVarInsn(ASTORE, 2); final Label l4 = new Label(); mv.visitLabel(l4); mv.visitLineNumber(199, l4); final FieldModel[] fieldModels = tm.fields().clone(); Arrays.sort(fieldModels, new Comparator<FieldModel>() { // reverse sort the preferences to optimise the public int compare(final FieldModel o1, final FieldModel o2) { return o2.equalsPreference() - o1.equalsPreference(); } }); for (final FieldModel fm : fieldModels) { // System.out.println(fm.fieldName()); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, name2, "get" + fm.titleFieldName(), "()" + fm.bcLFieldType()); mv.visitVarInsn(ALOAD, 2); mv.visitMethodInsn(INVOKEVIRTUAL, name2, "get" + fm.titleFieldName(), "()" + fm.bcLFieldType()); final Label l5 = new Label(); if (fm.isCallsNotEquals()) { mv.visitMethodInsn(INVOKESTATIC, fm.bcLModelType(), "notEquals", "(" + fm.bcLSetType() + fm.bcLSetType() + ")Z"); mv.visitJumpInsn(IFEQ, l5); } else { mv.visitJumpInsn(IF_ICMPEQ, l5); } mv.visitInsn(ICONST_0); mv.visitInsn(IRETURN); mv.visitLabel(l5); } mv.visitInsn(ICONST_1); mv.visitInsn(IRETURN); final Label l17 = new Label(); mv.visitLabel(l17); mv.visitLocalVariable("this", "L" + name2 + ";", null, l0, l17, 0); mv.visitLocalVariable("o", "Ljava/lang/Object;", null, l0, l17, 1); mv.visitLocalVariable("that", "L" + name2 + ";", null, l4, l17, 2); mv.visitMaxs(4, 3); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "hashCode", "()I", null, null); mv.visitCode(); final Label l0 = new Label(); mv.visitLabel(l0); int count = 0; for (final FieldModel fm : tm.fields()) { // if (count > 5) break; // System.out.println(fm.fieldName()); if (count > 0) { mv.visitIntInsn(BIPUSH, 31); mv.visitInsn(IMUL); } mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, name2, "get" + fm.titleFieldName(), "()" + fm.bcLFieldType()); if (fm.isCallsHashCode()) { mv.visitMethodInsn(INVOKESTATIC, fm.bcLModelType(), "hashCode", "(" + fm.bcLSetType() + ")I"); } if (count > 0) { mv.visitInsn(IADD); } count++; } mv.visitInsn(IRETURN); final Label l3 = new Label(); mv.visitLabel(l3); mv.visitLocalVariable("this", "L" + name2 + ";", null, l0, l3, 0); mv.visitMaxs(6, 1); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "copyOf", "(L" + name + ";)V", null, null); mv.visitCode(); final Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(240, l0); boolean copySimpleValues = false; for (final FieldModel fm : tm.fields()) { if (!fm.copySimpleValue() || !hasListField) { // if (true) { mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKEINTERFACE, name, "get" + fm.titleFieldName(), "()" + fm.bcLFieldType()); mv.visitMethodInsn(INVOKEVIRTUAL, name2, "set" + fm.titleFieldName(), "(" + fm.bcLFieldType() + ")V"); } else { copySimpleValues = true; } } final Label l4 = new Label(); final Label l6 = new Label(); if (copySimpleValues) { final Label l3 = new Label(); mv.visitLabel(l3); mv.visitLineNumber(243, l3); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(INSTANCEOF, name2); mv.visitJumpInsn(IFEQ, l4); final Label l5 = new Label(); mv.visitLabel(l5); mv.visitLineNumber(238, l5); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(CHECKCAST, name2); mv.visitVarInsn(ASTORE, 2); mv.visitLabel(l6); mv.visitLineNumber(239, l6); mv.visitVarInsn(ALOAD, 2); mv.visitFieldInsn(GETFIELD, name2, "container", "L" + collections + "impl/AbstractHugeContainer;"); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, name2, "container", "L" + collections + "impl/AbstractHugeContainer;"); mv.visitJumpInsn(IF_ACMPNE, l4); for (final FieldModel fm : tm.fields()) { if (fm.copySimpleValue()) { mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, name2, "allocation", "L" + name + "Allocation;"); mv.visitFieldInsn(GETFIELD, name + "Allocation", "m_" + fm.fieldName(), fm.bcLStoreType()); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, name2, "offset", "I"); mv.visitVarInsn(ALOAD, 2); mv.visitFieldInsn(GETFIELD, name2, "allocation", "L" + name + "Allocation;"); mv.visitFieldInsn(GETFIELD, name + "Allocation", "m_" + fm.fieldName(), fm.bcLStoreType()); mv.visitVarInsn(ALOAD, 2); mv.visitFieldInsn(GETFIELD, name2, "offset", "I"); mv.visitMethodInsn(INVOKEVIRTUAL, fm.bcStoreType(), "get", "(I)" + fm.bcLStoredType()); mv.visitMethodInsn(INVOKEVIRTUAL, fm.bcStoreType(), "put", "(I" + fm.bcLStoredType() + ")" + fm.bcLStoreType()); mv.visitInsn(POP); } } } final Label l16 = new Label(); mv.visitLabel(l16); mv.visitLineNumber(238, l16); final Label l17 = new Label(); mv.visitJumpInsn(GOTO, l17); mv.visitLabel(l4); mv.visitLineNumber(241, l4); for (final FieldModel fm : tm.fields()) { if (fm.copySimpleValue()) { mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKEINTERFACE, name, "get" + fm.titleFieldName(), "()" + fm.bcLFieldType()); mv.visitMethodInsn(INVOKEVIRTUAL, name2, "set" + fm.titleFieldName(), "(" + fm.bcLFieldType() + ")V"); } } mv.visitLabel(l17); mv.visitLineNumber(251, l17); mv.visitInsn(RETURN); final Label l27 = new Label(); mv.visitLabel(l27); mv.visitLocalVariable("this", "L" + name2 + ";", null, l0, l27, 0); mv.visitLocalVariable("t", "L" + name + ";", null, l0, l27, 1); if (copySimpleValues) { mv.visitLocalVariable("mte", "L" + name + "Element;", null, l6, l4, 2); } mv.visitMaxs(4, 3); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC + ACC_BRIDGE + ACC_SYNTHETIC, "copyOf", "(Ljava/lang/Object;)V", null, null); mv.visitCode(); final Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(275, l0); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(CHECKCAST, name); mv.visitMethodInsn(INVOKEVIRTUAL, name2, "copyOf", "(L" + name + ";)V"); mv.visitInsn(RETURN); final Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", "L" + name2 + ";", null, l0, l1, 0); mv.visitLocalVariable("x0", "Ljava/lang/Object;", null, l0, l1, 1); mv.visitMaxs(2, 2); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "writeExternal", "(Ljava/io/ObjectOutput;)V", null, new String[] { "java/io/IOException" }); mv.visitCode(); final Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(185, l0); for (final FieldModel fm : tm.fields()) { mv.visitVarInsn(ALOAD, 1); if (fm.bcLSetType().equals(fm.bcLFieldType())) { mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, name2, "get" + fm.titleFieldName(), "()" + fm.bcLFieldType()); mv.visitMethodInsn(INVOKESTATIC, fm.bcModelType(), "write", "(Ljava/io/ObjectOutput;" + fm.bcLSetType() + ")V"); } else { mv.visitLdcInsn(Type.getType(fm.bcLFieldType())); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, name2, "get" + fm.titleFieldName(), "()" + fm.bcLFieldType()); mv.visitMethodInsn(INVOKESTATIC, fm.bcModelType(), "write", "(Ljava/io/ObjectOutput;Ljava/lang/Class;" + fm.bcLSetType() + ")V"); } } final Label l13 = new Label(); mv.visitLabel(l13); mv.visitLineNumber(288, l13); mv.visitInsn(RETURN); final Label l14 = new Label(); mv.visitLabel(l14); mv.visitLocalVariable("this", "L" + name2 + ';', null, l0, l14, 0); mv.visitLocalVariable("out", "Ljava/io/ObjectOutput;", null, l0, l14, 1); mv.visitMaxs(4, 2); mv.visitEnd(); } { mv = cw.visitMethod(ACC_PUBLIC, "readExternal", "(Ljava/io/ObjectInput;)V", null, new String[] { "java/io/IOException", "java/lang/ClassNotFoundException" }); mv.visitCode(); final Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(287, l0); for (final FieldModel fm : tm.fields()) { mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); if (fm.bcLSetType().equals(fm.bcLFieldType())) { mv.visitMethodInsn(INVOKESTATIC, fm.bcModelType(), "read", "(Ljava/io/ObjectInput;)" + fm.bcLSetType()); } else { mv.visitLdcInsn(Type.getType(fm.bcLFieldType())); mv.visitMethodInsn(INVOKESTATIC, fm.bcModelType(), "read", "(Ljava/io/ObjectInput;Ljava/lang/Class;)" + fm.bcLSetType()); mv.visitTypeInsn(CHECKCAST, fm.bcFieldType()); } mv.visitMethodInsn(INVOKEVIRTUAL, name2, "set" + fm.titleFieldName(), "(" + fm.bcLFieldType() + ")V"); } final Label l13 = new Label(); mv.visitLabel(l13); mv.visitLineNumber(305, l13); mv.visitInsn(RETURN); final Label l14 = new Label(); mv.visitLabel(l14); mv.visitLocalVariable("this", "L" + name2 + ";", null, l0, l14, 0); mv.visitLocalVariable("in", "Ljava/io/ObjectInput;", null, l0, l14, 1); mv.visitMaxs(3, 2); mv.visitEnd(); } }
From source file:com.yahoo.yqlplus.engine.internal.bytecode.ClassAdapterGenerator.java
private void generateGetProperty(TypeWidget targetType, final PropertyAdapter propertyAdapter) { MethodGenerator method = createStaticMethod("getProperty"); method.setReturnType(AnyTypeWidget.getInstance()); final BytecodeExpression targetExpr = method.addArgument("target", targetType).read(); final BytecodeExpression propertyName = method.addArgument("property", BaseTypeAdapter.STRING).read(); method.add(new BytecodeSequence() { @Override//from w w w. j av a2s . c om public void generate(CodeEmitter code) { Map<String, Label> labelMap = Maps.newLinkedHashMap(); Label defaultCase = new Label(); Label done = new Label(); for (PropertyAdapter.Property property : propertyAdapter.getProperties()) { labelMap.put(property.name, new Label()); } propertyName.generate(code); code.emitStringSwitch(labelMap, defaultCase, true); MethodVisitor mv = code.getMethodVisitor(); for (PropertyAdapter.Property property : propertyAdapter.getProperties()) { mv.visitLabel(labelMap.get(property.name)); propertyAdapter.property(targetExpr, property.name).read().generate(code); code.box(property.type); mv.visitJumpInsn(Opcodes.GOTO, done); } mv.visitLabel(defaultCase); new NullExpr(AnyTypeWidget.getInstance()).generate(code); mv.visitLabel(done); mv.visitInsn(Opcodes.ARETURN); } }); }
From source file:com.yahoo.yqlplus.engine.internal.bytecode.ClassAdapterGenerator.java
private void generatePutProperty(TypeWidget targetType, final PropertyAdapter propertyAdapter) { MethodGenerator method = createStaticMethod("putProperty"); final BytecodeExpression targetExpr = method.addArgument("target", targetType).read(); final BytecodeExpression propertyName = method.addArgument("property", BaseTypeAdapter.STRING).read(); final BytecodeExpression valueExpr = method.addArgument("value", AnyTypeWidget.getInstance()).read(); method.add(new BytecodeSequence() { @Override//from w w w . j a va2 s . c o m public void generate(CodeEmitter code) { Map<String, Label> labelMap = Maps.newLinkedHashMap(); Label done = new Label(); for (PropertyAdapter.Property property : propertyAdapter.getProperties()) { labelMap.put(property.name, new Label()); } propertyName.generate(code); code.emitStringSwitch(labelMap, done, true); MethodVisitor mv = code.getMethodVisitor(); for (PropertyAdapter.Property property : propertyAdapter.getProperties()) { mv.visitLabel(labelMap.get(property.name)); AssignableValue av = propertyAdapter.property(targetExpr, property.name); try { code.exec(av.write(new BytecodeCastExpression(property.type, valueExpr))); } catch (UnsupportedOperationException ignored) { // can't write what isn't writable } mv.visitJumpInsn(Opcodes.GOTO, done); } mv.visitLabel(done); mv.visitInsn(Opcodes.RETURN); } }); }
From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.BlockAdapter.java
@Override public void jump(BytecodeExpression test, final BytecodeExpression result) { final BytecodeExpression testExpr = test; final TypeWidget type = testExpr.getType(); body.add(new BytecodeSequence() { @Override/*from w w w .j a v a 2 s. c o m*/ public void generate(CodeEmitter code) { code.exec(testExpr); Label isTrue = new Label(); Label isFalse = new Label(); type.getComparisionAdapter().coerceBoolean(code, isTrue, isFalse, isFalse); MethodVisitor mv = code.getMethodVisitor(); mv.visitLabel(isTrue); code.exec(result); mv.visitJumpInsn(Opcodes.GOTO, body.getEnd()); mv.visitLabel(isFalse); } }); }
From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.BytecodeCatchBuilder.java
@Override public BytecodeSequence build() { return new BytecodeSequence() { @Override//ww w .jav a2 s . co m public void generate(CodeEmitter code) { MethodVisitor mv = code.getMethodVisitor(); for (CatchClause catchClause : catchClauses) { if (catchClause.exceptionInternalNames.isEmpty()) { mv.visitTryCatchBlock(body.getStart(), body.getEnd(), catchClause.getStart(), null); } else { for (String name : catchClause.exceptionInternalNames) { mv.visitTryCatchBlock(body.getStart(), body.getEnd(), catchClause.getStart(), name); } } } Label done = new Label(); body.generate(code); mv.visitJumpInsn(Opcodes.GOTO, done); for (CatchClause catchClause : catchClauses.subList(0, catchClauses.size() - 1)) { catchClause.generate(code); mv.visitJumpInsn(Opcodes.GOTO, done); } catchClauses.get(catchClauses.size() - 1).generate(code); mv.visitLabel(done); } }; }
From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.CaseAdapter.java
@Override public void when(final BytecodeExpression test, final BytecodeExpression value) { final TypeWidget type = test.getType(); resultTypes.add(value.getType());//from w ww . j a v a 2s . c o m body.add(new BytecodeSequence() { @Override public void generate(CodeEmitter code) { code.exec(test); Label isTrue = new Label(); Label isFalse = new Label(); type.getComparisionAdapter().coerceBoolean(code, isTrue, isFalse, isFalse); MethodVisitor mv = code.getMethodVisitor(); mv.visitLabel(isTrue); code.exec(value); code.cast(unifiedOutputType, value.getType()); mv.visitJumpInsn(Opcodes.GOTO, end); mv.visitLabel(isFalse); } }); }