Example usage for org.objectweb.asm Label Label

List of usage examples for org.objectweb.asm Label Label

Introduction

In this page you can find the example usage for org.objectweb.asm Label Label.

Prototype

public Label() 

Source Link

Document

Constructs a new label.

Usage

From source file:com.sun.fortress.runtimeSystem.InstantiatingClassloader.java

License:Open Source License

/**
 * @param mv/*from w  w  w  . j  a va2  s. c o  m*/
 * @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//  w ww.j a  v  a 2s  . 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();/*from  w  ww  .  jav a  2 s  . c o  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.toolazydogs.maiden.agent.asm.BeginEndMethodVisitor.java

License:Apache License

public void visitInsn(int opcode) {
    LOGGER.entering(CLASS_NAME, "visitInsn", opcode);

    flush();/*from  www. jav a  2s  .c om*/

    switch (opcode) {
    case IRETURN:
    case LRETURN:
    case FRETURN:
    case DRETURN:
    case ARETURN:
    case RETURN:

        if (sawCode) {
            Label end = new Label();
            lvs.visitLabel(end);
            lvs.visitTryCatchBlock(start, end, l7, null);
        }

        for (BeginEndMethodListener listener : getReversed())
            listener.end(lvs);

        break;

    default:
        sawCode = true;
    }

    lvs.visitInsn(opcode);

    LOGGER.exiting(CLASS_NAME, "visitInsn");
}

From source file:com.toolazydogs.maiden.agent.asm.BeginEndMethodVisitor.java

License:Apache License

public void visitEnd() {
    LOGGER.entering(CLASS_NAME, "visitEnd");

    flush();//  w w w  . j av  a  2 s  .  co m

    if (sawCode) {
        LOGGER.finest("Saw code");

        final Label l13 = new Label();
        final int local = lvs.newLocal(Type.getType(Throwable.class));

        lvs.visitTryCatchBlock(l7, l13, l7, null);

        lvs.visitLabel(l7);
        lvs.visitVarInsn(ASTORE, local);
        lvs.visitLabel(l13);

        for (BeginEndMethodListener listener : getReversed())
            listener.end(lvs);

        lvs.visitVarInsn(ALOAD, local);
        lvs.visitInsn(ATHROW);
    }

    lvs.visitEnd();

    methodNode.accept(visitor);

    LOGGER.exiting(CLASS_NAME, "visitEnd");
}

From source file:com.toolazydogs.maiden.agent.asm.BeginEndMethodVisitor.java

License:Apache License

/**
 * Delay flushing out first label for our try/finally block until the first
 * bit of code is encountered.//from   w w w .j  a  va2 s  .co  m
 */
private void flush() {
    LOGGER.entering(CLASS_NAME, "flush");

    if (state == State.NEED_START_LABEL) {
        LOGGER.finest("Need start label");

        start = new Label();
        lvs.visitLabel(start);
        state = State.CLEARED;
    }

    LOGGER.exiting(CLASS_NAME, "flush");
}

From source file:com.weibo.lodil.mmap.impl.GenerateHugeArrays.java

License:Apache License

public static byte[] dumpArrayList(final TypeModel tm) {
    final ClassWriter cw = new ClassWriter(0);
    FieldVisitor fv;//from w  ww.jav a  2  s  .co  m
    MethodVisitor mv;

    final Class interfaceClass = tm.type();
    final String name = interfaceClass.getName().replace('.', '/');

    cw.visit(
            V1_5, ACC_PUBLIC + ACC_SUPER, name + "ArrayList", "L" + collections + "impl/AbstractHugeArrayList<L"
                    + name + ";L" + name + "Allocation;L" + name + "Element;>;",
            collections + "impl/AbstractHugeArrayList", null);

    cw.visitSource(tm.type().getSimpleName() + "ArrayList.java", null);

    for (final FieldModel fm : tm.fields()) {
        if (fm instanceof Enum8FieldModel) {
            fv = cw.visitField(ACC_FINAL, fm.fieldName() + "FieldModel",
                    "L" + collections + "model/Enum8FieldModel;",
                    "L" + collections + "model/Enum8FieldModel<Ljava/lang/annotation/ElementType;>;", null);
            fv.visitEnd();
        } else if (fm instanceof Enumerated16FieldModel) {
            fv = cw.visitField(ACC_FINAL, fm.fieldName() + "FieldModel",
                    "L" + collections + "model/Enumerated16FieldModel;",
                    "L" + collections + "model/Enumerated16FieldModel<Ljava/lang/String;>;", null);
            fv.visitEnd();
        }
    }
    final List<FieldModel> fields = new ArrayList<FieldModel>();
    {
        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "(L" + collections + "HugeArrayBuilder;)V", null, null);
        mv.visitCode();
        final Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(35, l0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitMethodInsn(INVOKESPECIAL, collections + "impl/AbstractHugeArrayList", "<init>",
                "(L" + collections + "HugeArrayBuilder;)V");
        final Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitLineNumber(29, l1);

        for (final FieldModel fm : tm.fields()) {
            if (fm instanceof Enum8FieldModel) {
                mv.visitVarInsn(ALOAD, 0);
                mv.visitTypeInsn(NEW, fm.bcModelType());
                mv.visitInsn(DUP);
                mv.visitLdcInsn(fm.fieldName());
                mv.visitIntInsn(BIPUSH, fm.fieldNumber());
                mv.visitLdcInsn(Type.getType(fm.bcLFieldType()));
                mv.visitMethodInsn(INVOKESTATIC, fm.bcFieldType(), "values", "()[" + fm.bcLFieldType());
                mv.visitMethodInsn(INVOKESPECIAL, fm.bcModelType(), "<init>",
                        "(Ljava/lang/String;ILjava/lang/Class;[Ljava/lang/Enum;)V");
                mv.visitFieldInsn(PUTFIELD, name + "ArrayList", fm.fieldName() + "FieldModel",
                        fm.bcLModelType());
                mv.visitVarInsn(ALOAD, 0);
                mv.visitFieldInsn(GETFIELD, name + "ArrayList", fm.fieldName() + "FieldModel",
                        fm.bcLModelType());
                mv.visitVarInsn(ALOAD, 1);
                mv.visitMethodInsn(INVOKEVIRTUAL, collections + "HugeArrayBuilder", "baseDirectory",
                        "()Ljava/lang/String;");
                mv.visitMethodInsn(INVOKEVIRTUAL, fm.bcModelType(), "baseDirectory", "(Ljava/lang/String;)V");
                fields.add(fm);

            } else if (fm instanceof Enumerated16FieldModel) {
                mv.visitVarInsn(ALOAD, 0);
                mv.visitTypeInsn(NEW, fm.bcModelType());
                mv.visitInsn(DUP);
                mv.visitLdcInsn(fm.fieldName());
                mv.visitIntInsn(BIPUSH, fm.fieldNumber());
                mv.visitLdcInsn(Type.getType(fm.bcLFieldType()));
                mv.visitMethodInsn(INVOKESPECIAL, fm.bcModelType(), "<init>",
                        "(Ljava/lang/String;ILjava/lang/Class;)V");
                mv.visitFieldInsn(PUTFIELD, name + "ArrayList", fm.fieldName() + "FieldModel",
                        fm.bcLModelType());
                mv.visitVarInsn(ALOAD, 0);
                mv.visitFieldInsn(GETFIELD, name + "ArrayList", fm.fieldName() + "FieldModel",
                        fm.bcLModelType());
                mv.visitVarInsn(ALOAD, 1);
                mv.visitMethodInsn(INVOKEVIRTUAL, collections + "HugeArrayBuilder", "baseDirectory",
                        "()Ljava/lang/String;");
                mv.visitMethodInsn(INVOKEVIRTUAL, fm.bcModelType(), "baseDirectory", "(Ljava/lang/String;)V");
                fields.add(fm);
            }
        }

        mv.visitInsn(RETURN);
        final Label l4 = new Label();
        mv.visitLabel(l4);
        mv.visitLocalVariable("this", "L" + name + "ArrayList;", null, l0, l4, 0);
        mv.visitLocalVariable("hab", "L" + collections + "HugeArrayBuilder;", null, l0, l4, 1);
        mv.visitMaxs(7, 2);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PROTECTED, "createAllocation",
                "(L" + collections + "impl/MappedFileChannel;)L" + name + "Allocation;", null, null);
        mv.visitCode();
        final Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(43, l0);
        mv.visitTypeInsn(NEW, name + "Allocation");
        mv.visitInsn(DUP);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, name + "ArrayList", "allocationSize", "I");
        mv.visitVarInsn(ALOAD, 1);
        mv.visitMethodInsn(INVOKESPECIAL, name + "Allocation", "<init>",
                "(IL" + collections + "impl/MappedFileChannel;)V");
        mv.visitInsn(ARETURN);
        final Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitLocalVariable("this", "L" + name + "ArrayList;", null, l0, l1, 0);
        mv.visitLocalVariable("mfc", "L" + collections + "impl/MappedFileChannel;", null, l0, l1, 1);
        mv.visitMaxs(4, 2);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PROTECTED, "createElement", "(J)L" + name + "Element;", null, null);
        mv.visitCode();
        final Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(48, l0);
        mv.visitTypeInsn(NEW, name + "Element");
        mv.visitInsn(DUP);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(LLOAD, 1);
        mv.visitMethodInsn(INVOKESPECIAL, name + "Element", "<init>",
                "(L" + collections + "impl/AbstractHugeArrayList;J)V");
        mv.visitInsn(ARETURN);
        final Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitLocalVariable("this", "L" + name + "ArrayList;", null, l0, l1, 0);
        mv.visitLocalVariable("n", "J", null, l0, l1, 1);
        mv.visitMaxs(5, 3);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PROTECTED, "createImpl", "()L" + name + ";", null, null);
        mv.visitCode();
        final Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(53, l0);
        mv.visitTypeInsn(NEW, name + "Impl");
        mv.visitInsn(DUP);
        mv.visitMethodInsn(INVOKESPECIAL, name + "Impl", "<init>", "()V");
        mv.visitInsn(ARETURN);
        final Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitLocalVariable("this", "L" + name + "ArrayList;", null, l0, l1, 0);
        mv.visitMaxs(2, 1);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PROTECTED, "compactStart", "()V", null, null);
        mv.visitCode();
        final Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(57, l0);
        for (final FieldModel fm : fields) {
            mv.visitVarInsn(ALOAD, 0);
            mv.visitFieldInsn(GETFIELD, name + "ArrayList", fm.fieldName() + "FieldModel", fm.bcLModelType());
            mv.visitMethodInsn(INVOKEVIRTUAL, fm.bcModelType(), "compactStart", "()V");
        }
        final Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitLineNumber(58, l1);
        mv.visitInsn(RETURN);
        final Label l2 = new Label();
        mv.visitLabel(l2);
        mv.visitLocalVariable("this", "L" + name + "ArrayList;", null, l0, l2, 0);
        mv.visitMaxs(1, 1);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PROTECTED, "compactOnAllocation", "(L" + name + "Allocation;J)V", null, null);
        mv.visitCode();
        final Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(65, l0);
        for (final FieldModel fm : fields) {
            mv.visitVarInsn(ALOAD, 0);
            mv.visitFieldInsn(GETFIELD, name + "ArrayList", fm.fieldName() + "FieldModel", fm.bcLModelType());
            mv.visitVarInsn(ALOAD, 1);
            mv.visitFieldInsn(GETFIELD, name + "Allocation", "m_string", fm.bcLStoreType());
            mv.visitVarInsn(LLOAD, 2);
            mv.visitMethodInsn(INVOKEVIRTUAL, fm.bcModelType(), "compactScan", "(" + fm.bcLStoreType() + "J)V");
        }
        final Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitLineNumber(66, l1);
        mv.visitInsn(RETURN);
        final Label l2 = new Label();
        mv.visitLabel(l2);
        mv.visitLocalVariable("this", "L" + name + "ArrayList;", null, l0, l2, 0);
        mv.visitLocalVariable("allocation", "L" + name + "Allocation;", null, l0, l2, 1);
        mv.visitLocalVariable("thisSize", "J", null, l0, l2, 2);
        mv.visitMaxs(4, 4);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PROTECTED, "compactEnd", "()V", null, null);
        mv.visitCode();
        final Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(69, l0);
        for (final FieldModel fm : fields) {
            mv.visitVarInsn(ALOAD, 0);
            mv.visitFieldInsn(GETFIELD, name + "ArrayList", fm.fieldName() + "FieldModel", fm.bcLModelType());
            mv.visitMethodInsn(INVOKEVIRTUAL, fm.bcModelType(), "compactEnd", "()V");
        }
        final Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitLineNumber(70, l1);
        mv.visitInsn(RETURN);
        final Label l2 = new Label();
        mv.visitLabel(l2);
        mv.visitLocalVariable("this", "L" + name + "ArrayList;", null, l0, l2, 0);
        mv.visitMaxs(1, 1);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "clear", "()V", null, null);
        mv.visitCode();
        final Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(74, l0);
        for (final FieldModel fm : fields) {
            mv.visitVarInsn(ALOAD, 0);
            mv.visitFieldInsn(GETFIELD, name + "ArrayList", fm.fieldName() + "FieldModel", fm.bcLModelType());
            mv.visitMethodInsn(INVOKEVIRTUAL, fm.bcModelType(), "clear", "()V");
        }
        final Label l3 = new Label();
        mv.visitLabel(l3);
        mv.visitLineNumber(77, l3);
        mv.visitInsn(RETURN);
        final Label l4 = new Label();
        mv.visitLabel(l4);
        mv.visitLocalVariable("this", "L" + name + "ArrayList;", null, l0, l4, 0);
        mv.visitMaxs(1, 1);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PROTECTED + ACC_BRIDGE + ACC_SYNTHETIC, "createImpl", "()Ljava/lang/Object;",
                null, null);
        mv.visitCode();
        final Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(29, l0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, name + "ArrayList", "createImpl", "()L" + name + ";");
        mv.visitInsn(ARETURN);
        final Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitLocalVariable("this", "L" + name + "ArrayList;", null, l0, l1, 0);
        mv.visitMaxs(1, 1);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PROTECTED + ACC_BRIDGE + ACC_SYNTHETIC, "createElement",
                "(J)L" + collections + "impl/AbstractHugeElement;", null, null);
        mv.visitCode();
        final Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(29, l0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(LLOAD, 1);
        mv.visitMethodInsn(INVOKEVIRTUAL, name + "ArrayList", "createElement", "(J)L" + name + "Element;");
        mv.visitInsn(ARETURN);
        final Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitLocalVariable("this", "L" + name + "ArrayList;", null, l0, l1, 0);
        mv.visitLocalVariable("x0", "J", null, l0, l1, 1);
        mv.visitMaxs(3, 3);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PROTECTED + ACC_BRIDGE + ACC_SYNTHETIC, "compactOnAllocation",
                "(L" + collections + "api/HugeAllocation;J)V", null, null);
        mv.visitCode();
        final Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(29, l0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitTypeInsn(CHECKCAST, name + "Allocation");
        mv.visitVarInsn(LLOAD, 2);
        mv.visitMethodInsn(INVOKEVIRTUAL, name + "ArrayList", "compactOnAllocation",
                "(L" + name + "Allocation;J)V");
        mv.visitInsn(RETURN);
        final Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitLocalVariable("this", "L" + name + "ArrayList;", null, l0, l1, 0);
        mv.visitLocalVariable("x0", "L" + collections + "api/HugeAllocation;", null, l0, l1, 1);
        mv.visitLocalVariable("x1", "J", null, l0, l1, 2);
        mv.visitMaxs(4, 4);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PROTECTED + ACC_BRIDGE + ACC_SYNTHETIC, "createAllocation",
                "(L" + collections + "impl/MappedFileChannel;)L" + collections + "api/HugeAllocation;", null,
                null);
        mv.visitCode();
        final Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(29, l0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitMethodInsn(INVOKEVIRTUAL, name + "ArrayList", "createAllocation",
                "(L" + collections + "impl/MappedFileChannel;)L" + name + "Allocation;");
        mv.visitInsn(ARETURN);
        final Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitLocalVariable("this", "L" + name + "ArrayList;", null, l0, l1, 0);
        mv.visitLocalVariable("x0", "L" + collections + "impl/MappedFileChannel;", null, l0, l1, 1);
        mv.visitMaxs(2, 2);
        mv.visitEnd();
    }
    cw.visitEnd();
    final byte[] bytes = cw.toByteArray();
    // ClassReader cr = new ClassReader(bytes);
    // cr.accept(new ASMifierClassVisitor(new PrintWriter(System.out)), 0);
    return bytes;
}

From source file:com.weibo.lodil.mmap.impl.GenerateHugeArrays.java

License:Apache License

public static byte[] dumpAllocation(final TypeModel tm) {

    final ClassWriter cw = new ClassWriter(0);
    FieldVisitor fv;//  w  w w.  j a  v a  2  s  . c  om
    MethodVisitor mv;

    final Class interfaceClass = tm.type();
    final String name = interfaceClass.getName().replace('.', '/');

    cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, name + "Allocation", null, "java/lang/Object",
            new String[] { collections + "api/HugeAllocation" });

    cw.visitSource(tm.type().getSimpleName() + "Allocation.java", null);

    for (final FieldModel fm : tm.fields()) {
        fv = cw.visitField(0, "m_" + fm.fieldName(), fm.bcLStoreType(), null, null);
        fv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "(IL" + collections + "impl/MappedFileChannel;)V", null,
                null);
        mv.visitCode();
        final Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(46, l0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");

        for (final FieldModel fm : tm.fields()) {
            mv.visitVarInsn(ALOAD, 0);

            if (fm instanceof ObjectFieldModel) {
                mv.visitLdcInsn(Type.getType(fm.bcLFieldType()));
                mv.visitVarInsn(ILOAD, 1);
                mv.visitMethodInsn(INVOKESTATIC, fm.bcModelType(), "newArrayOfField",
                        "(Ljava/lang/Class;I)[Ljava/lang/Object;");
                mv.visitTypeInsn(CHECKCAST, fm.bcLStoreType());
            } else {
                mv.visitVarInsn(ILOAD, 1);
                mv.visitVarInsn(ALOAD, 2);
                mv.visitMethodInsn(INVOKESTATIC, fm.bcModelType(), "newArrayOfField",
                        "(IL" + collections + "impl/MappedFileChannel;)" + fm.bcLStoreType());
            }
            mv.visitFieldInsn(PUTFIELD, name + "Allocation", "m_" + fm.fieldName(), fm.bcLStoreType());
        }

        mv.visitInsn(RETURN);
        final Label l14 = new Label();
        mv.visitLabel(l14);
        mv.visitLocalVariable("this", "L" + name + "Allocation;", null, l0, l14, 0);
        mv.visitLocalVariable("allocationSize", "I", null, l0, l14, 1);
        mv.visitLocalVariable("mfc", "L" + collections + "impl/MappedFileChannel;", null, l0, l14, 2);
        mv.visitMaxs(3, 3);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "clear", "()V", null, null);
        mv.visitCode();
        final Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(62, l0);
        for (final FieldModel fm : tm.fields()) {
            if (fm instanceof ObjectFieldModel) {
                mv.visitVarInsn(ALOAD, 0);
                mv.visitFieldInsn(GETFIELD, name + "Allocation", "m_" + fm.fieldName(), fm.bcLStoreType());
                mv.visitInsn(ACONST_NULL);
                mv.visitMethodInsn(INVOKESTATIC, "java/util/Arrays", "fill",
                        "([Ljava/lang/Object;Ljava/lang/Object;)V");
            }
        }
        final Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitLineNumber(63, l1);
        mv.visitInsn(RETURN);
        final Label l2 = new Label();
        mv.visitLabel(l2);
        mv.visitLocalVariable("this", "L" + name + "Allocation;", null, l0, l2, 0);
        mv.visitMaxs(2, 1);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "destroy", "()V", null, null);
        mv.visitCode();
        final Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(66, l0);
        for (final FieldModel fm : tm.fields()) {
            if (!fm.isBufferStore()) {
                continue;
            }
            mv.visitVarInsn(ALOAD, 0);
            mv.visitFieldInsn(GETFIELD, name + "Allocation", "m_" + fm.fieldName(), fm.bcLStoreType());
            mv.visitTypeInsn(CHECKCAST, "java/nio/Buffer");
            mv.visitMethodInsn(INVOKESTATIC, GenerateHugeArrays.class.getName().replace('.', '/'), "clean",
                    "(Ljava/nio/Buffer;)V");

        }
        final Label l3 = new Label();
        mv.visitLabel(l3);
        mv.visitLineNumber(69, l3);
        mv.visitInsn(RETURN);
        final Label l4 = new Label();
        mv.visitLabel(l4);
        mv.visitLocalVariable("this", "L" + name + "Allocation;", null, l0, l4, 0);
        mv.visitLocalVariable("m", "Ljava/lang/Object;", null, l3, l4, 1);
        mv.visitMaxs(1, 2);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PROTECTED, "finalize", "()V", null, new String[] { "java/lang/Throwable" });
        mv.visitCode();
        final Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(76, l0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "finalize", "()V");
        final Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitLineNumber(77, l1);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKEVIRTUAL, name + "Allocation", "destroy", "()V");
        final Label l2 = new Label();
        mv.visitLabel(l2);
        mv.visitLineNumber(78, l2);
        mv.visitInsn(RETURN);
        final Label l3 = new Label();
        mv.visitLabel(l3);
        mv.visitLocalVariable("this", "L" + name + "Allocation;", null, l0, l3, 0);
        mv.visitMaxs(1, 1);
        mv.visitEnd();
    }

    cw.visitEnd();
    final byte[] bytes = cw.toByteArray();
    // ClassReader cr = new ClassReader(bytes);
    // cr.accept(new ASMifierClassVisitor(new PrintWriter(System.out)), 0);
    return bytes;
}

From source file:com.weibo.lodil.mmap.impl.GenerateHugeArrays.java

License:Apache License

public static byte[] dumpElement(final TypeModel tm) {

    final ClassWriter cw = new ClassWriter(0);
    FieldVisitor fv;//from w  w  w .  ja  va 2 s.  c o m
    MethodVisitor mv;

    final String name = tm.bcType();

    cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER, name + "Element",
            "L" + collections + "impl/AbstractHugeElement<L" + name + "Allocation;>;L" + name
                    + ";Ljava/io/Externalizable;",
            collections + "impl/AbstractHugeElement", new String[] { name, "java/io/Externalizable" });

    cw.visitSource(tm.type().getSimpleName() + "Element.java", null);

    {
        fv = cw.visitField(0, "allocation", "L" + name + "Allocation;", null, null);
        fv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PUBLIC, "<init>", "(L" + collections + "impl/AbstractHugeArrayList;J)V",
                "(L" + collections + "impl/AbstractHugeArrayList<L" + name + ";L" + name + "Allocation;L" + name
                        + "Element;>;J)V",
                null);
        mv.visitCode();
        final Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(34, l0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 1);
        mv.visitVarInsn(LLOAD, 2);
        mv.visitMethodInsn(INVOKESPECIAL, collections + "impl/AbstractHugeElement", "<init>",
                "(L" + collections + "impl/AbstractHugeContainer;J)V");
        final Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitLineNumber(35, l1);
        mv.visitInsn(RETURN);
        final Label l2 = new Label();
        mv.visitLabel(l2);
        mv.visitLocalVariable("this", "L" + name + "Element;", null, l0, l2, 0);
        mv.visitLocalVariable("list", "L" + collections + "impl/AbstractHugeArrayList;", "L" + collections
                + "impl/AbstractHugeArrayList<L" + name + ";L" + name + "Allocation;L" + name + "Element;>;",
                l0, l2, 1);
        mv.visitLocalVariable("n", "J", null, l0, l2, 2);
        mv.visitMaxs(4, 4);
        mv.visitEnd();
    }
    for (final FieldModel fm : tm.fields()) {
        // /////// SETTER //////////

        int maxLocals = 2 + fm.bcFieldSize();

        mv = cw.visitMethod(ACC_PUBLIC, "set" + fm.titleFieldName(), "(" + fm.bcLFieldType() + ")V", null,
                null);
        mv.visitCode();
        final Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(39, l0);

        int invoke = INVOKESTATIC;
        if (fm.virtualGetSet()) {
            mv.visitVarInsn(ALOAD, 0);
            mv.visitFieldInsn(GETFIELD, name + "Element", "container",
                    "L" + collections + "impl/AbstractHugeContainer;");
            mv.visitTypeInsn(CHECKCAST, name + "ArrayList");
            mv.visitFieldInsn(GETFIELD, name + "ArrayList", fm.fieldName() + "FieldModel", fm.bcLModelType());
            invoke = INVOKEVIRTUAL;
            maxLocals++;
        }

        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, name + "Element", "allocation", "L" + name + "Allocation;");
        mv.visitFieldInsn(GETFIELD, name + "Allocation", "m_" + fm.fieldName(), fm.bcLStoreType());
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, name + "Element", "offset", "I");
        mv.visitVarInsn(loadFor(fm.bcType()), 1);

        mv.visitMethodInsn(invoke, fm.bcModelType(), "set",
                "(" + fm.bcLStoreType() + "I" + fm.bcLSetType() + ")V");
        mv.visitInsn(RETURN);
        final Label l2 = new Label();
        mv.visitLabel(l2);
        mv.visitLocalVariable("this", "L" + name + "Element;", null, l0, l2, 0);
        mv.visitLocalVariable("elementType", "Ljava/lang/annotation/ElementType;", null, l0, l2, 1);
        mv.visitMaxs(maxLocals, 1 + fm.bcFieldSize());
        mv.visitEnd();

        // /////// GETTER //////////

        mv = cw.visitMethod(ACC_PUBLIC, "get" + fm.titleFieldName(), "()" + fm.bcLFieldType(), null, null);
        mv.visitCode();
        final Label l3 = new Label();
        mv.visitLabel(l3);
        mv.visitLineNumber(144, l3);

        BCType bcType = fm.bcType();
        if (fm.virtualGetSet()) {
            mv.visitVarInsn(ALOAD, 0);
            mv.visitFieldInsn(GETFIELD, name + "Element", "container",
                    "L" + collections + "impl/AbstractHugeContainer;");
            mv.visitTypeInsn(CHECKCAST, name + "ArrayList");
            mv.visitFieldInsn(GETFIELD, name + "ArrayList", fm.fieldName() + "FieldModel", fm.bcLModelType());
            bcType = BCType.Reference;
        }

        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, name + "Element", "allocation", "L" + name + "Allocation;");
        mv.visitFieldInsn(GETFIELD, name + "Allocation", "m_" + fm.fieldName(), fm.bcLStoreType());
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, name + "Element", "offset", "I");
        mv.visitMethodInsn(invoke, fm.bcModelType(), "get", "(" + fm.bcLStoreType() + "I)" + fm.bcLSetType());
        if (!fm.bcLSetType().equals(fm.bcLFieldType())) {
            mv.visitTypeInsn(CHECKCAST, fm.bcFieldType());
        }
        mv.visitInsn(returnFor(bcType));
        final Label l4 = new Label();
        mv.visitLabel(l4);
        mv.visitLocalVariable("this", "L" + name + "Element;", null, l3, l4, 0);
        mv.visitMaxs(4, 2);
        mv.visitEnd();
    }
    {
        mv = cw.visitMethod(ACC_PROTECTED, "updateAllocation0", "(I)V", null, null);
        mv.visitCode();
        final Label l0 = new Label();
        mv.visitLabel(l0);
        mv.visitLineNumber(170, l0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, name + "Element", "container",
                "L" + collections + "impl/AbstractHugeContainer;");
        mv.visitVarInsn(ALOAD, 0);
        mv.visitFieldInsn(GETFIELD, name + "Element", "index", "J");
        mv.visitMethodInsn(INVOKEVIRTUAL, collections + "impl/AbstractHugeContainer", "getAllocation",
                "(J)L" + collections + "api/HugeAllocation;");
        mv.visitTypeInsn(CHECKCAST, name + "Allocation");
        mv.visitFieldInsn(PUTFIELD, name + "Element", "allocation", "L" + name + "Allocation;");
        final Label l1 = new Label();
        mv.visitLabel(l1);
        mv.visitLineNumber(171, l1);
        mv.visitInsn(RETURN);
        final Label l2 = new Label();
        mv.visitLabel(l2);
        mv.visitLocalVariable("this", "L" + name + "Element;", null, l0, l2, 0);
        mv.visitLocalVariable("allocationSize", "I", null, l0, l2, 1);
        mv.visitMaxs(4, 2);
        mv.visitEnd();
    }
    appendToStringHashCodeEqualsCopyOf(tm, cw, name + "Element", true);
    cw.visitEnd();

    final byte[] bytes = cw.toByteArray();
    // ClassReader cr = new ClassReader(bytes);
    // cr.accept(new ASMifierClassVisitor(new PrintWriter(System.out)), 0);
    return bytes;
}

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;/*from w ww.  j  ava 2s  .  co 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();
    }
}