Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javassist to ASM #56

Closed
dimzon opened this issue Apr 3, 2014 · 3 comments
Closed

Javassist to ASM #56

dimzon opened this issue Apr 3, 2014 · 3 comments
Labels

Comments

@dimzon
Copy link

dimzon commented Apr 3, 2014

What does you think about migration from Javassist to ASM? I can help You to rewrite bytecode generation procedures.

@brettwooldridge
Copy link
Owner

What is the advantage?

@dimzon
Copy link
Author

dimzon commented Apr 3, 2014

  1. less dependency size
  2. faster initialization (javassist need to parse string containing java code)

anyway it's just proposal

@brettwooldridge
Copy link
Owner

While I agree it requires a small dependency, the level at which bytecode generation occurs is simply too low for me. I don't think generating code at the bytecode level such as this:

MethodNode mn = new MethodNode(...);
InsnList il = mn.instructions;
il.add(new VarInsnNode(ILOAD, 1));
LabelNode label = new LabelNode();
il.add(new JumpInsnNode(IFLT, label));
il.add(new VarInsnNode(ALOAD, 0));
il.add(new VarInsnNode(ILOAD, 1));
il.add(new FieldInsnNode(PUTFIELD, "pkg/Bean", "f", "I"));
LabelNode end = new LabelNode();
il.add(new JumpInsnNode(GOTO, end));
il.add(label);
il.add(new FrameNode(F_SAME, 0, null, 0, null));
il.add(new TypeInsnNode(NEW, "java/lang/IllegalArgumentException"));
il.add(new InsnNode(DUP));
il.add(new MethodInsnNode(INVOKESPECIAL,
          "java/lang/IllegalArgumentException", "<init>", "()V"));
il.add(new InsnNode(ATHROW));
il.add(end);
il.add(new FrameNode(F_SAME, 0, null, 0, null));
il.add(new InsnNode(RETURN));
mn.maxStack = 2;
mn.maxLocals = 2;

... leads to particularly readable or maintainable code. I'm sure ASM has its place, for example when writing bytecode compilers, but I don't think it is a particularly good for the code generation needs of HikariCP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants