public static byte[] dumpAllocation(TypeModel tm) {

    ClassWriter cw = new ClassWriter(0);
    FieldVisitor fv;
    MethodVisitor mv;

    Class interfaceClass = tm.type();
    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 (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();
      Label l0 = new Label();
      mv.visitLabel(l0);
      mv.visitLineNumber(46, l0);
      mv.visitVarInsn(ALOAD, 0);
      mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");

      for (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);
      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();
      Label l0 = new Label();
      mv.visitLabel(l0);
      mv.visitLineNumber(62, l0);
      for (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");
        }
      }
      Label l1 = new Label();
      mv.visitLabel(l1);
      mv.visitLineNumber(63, l1);
      mv.visitInsn(RETURN);
      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();
      Label l0 = new Label();
      mv.visitLabel(l0);
      mv.visitLineNumber(66, l0);
      for (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");

      }
      Label l3 = new Label();
      mv.visitLabel(l3);
      mv.visitLineNumber(69, l3);
      mv.visitInsn(RETURN);
      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();
      Label l0 = new Label();
      mv.visitLabel(l0);
      mv.visitLineNumber(76, l0);
      mv.visitVarInsn(ALOAD, 0);
      mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "finalize", "()V");
      Label l1 = new Label();
      mv.visitLabel(l1);
      mv.visitLineNumber(77, l1);
      mv.visitVarInsn(ALOAD, 0);
      mv.visitMethodInsn(INVOKEVIRTUAL, name + "Allocation", "destroy", "()V");
      Label l2 = new Label();
      mv.visitLabel(l2);
      mv.visitLineNumber(78, l2);
      mv.visitInsn(RETURN);
      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;
  }