4 ms·
This is pretty exciting... I've used them all libraries at this point in my career: CGLib, ASM, BCEL, ByteBuddy, Javassist, etc... each has its pluses and minus
by exabrial 3y ago
This is pretty exciting... I've used them all libraries at this point in my career: CGLib, ASM, BCEL, ByteBuddy, Javassist, etc... each has its pluses and minuses. I've designed everything from profiling agents, to systems that pack decimals into EBCDIC and invoke COBOL programs on big IBM iron, to lightweight JIT compilers, all using these libraries.
> In 2002, the visitor approach used by ASM seemed clever
I couldn't agree more. The visitor pattern was very hard to explain/justify back then, and still difficult to explain to newbie programmers just entering the profession.
Looking at the examples, I think this is going to be an official replacement for ASM, meaning it's going to be pretty low level. The use of streams pretty straightforward.
If anyone from the JEP is reading this: I have two pieces of feedback!
First, take some inspiration from the way CDI Portable Extensions work. This is probably the most delightful extension API I've ever used. The @Observe callbacks are super simple to explain to people and it's really easy to write extensions for the framework.
Next, I wouldn't ignore the need for a higher-level API akin to ByteBuddy or Javassist. Sometimes I just want to write an interpreter or intercept a method call and thats it.
For example in my Junit/Mockito extension https://github.com/exabrial/mockito-object-injection https://github.com/exabrial/mockito-object-injection I need to intercept a call to the class under test in order to lazily inject dependencies at the last possible moment. While I certainly could do this with ASM, Javassist makes this fairly simple with it's MethodHandler api.
Side note, it's a damn shame we don't have a mobile operating system that is JVM native :/ All this cool APIs simply never reach a huge number of devices.
- vips7L 3y agoI just want to share my support of CDI extensions. They just make sense!
- xxs 3y ago>First, take some inspiration from the way CDI Portable Extensions work It's way too late, the API is effectively locked in preview mode. While I am not a fan of ASM's visitor pattern, explaining it to anyone would be the least of my concerns, ASM requires pretty extensive knowledge on class structure, method signatures, and most of the byte code instructions. Whoever ventures in byte code editing mode should be able to read the byte code directly.
- twic 3y agoHow would something like CDI portable extensions fit in here? Are you thinking it would another way to replace ASM's visitors? Doesn't it lack all the useful structure that the design in the JEP as, around streaming and building and transformation and so on?
- exabrial 3y agoI meant the "style of" CDI portable extensions :) When you write a CDI portable extension, you register a bunch of observation handlers. So as the CDI environment is discovering stuff, it calls your observers and you have the chance to make chances to the runtime. I was thinking something akin to that here... when reading a class, your observers get called and you have a chance to manipulate the class data. I find this style intuitive.
- nvm0n2 3y agoSurely the problem you're objecting to is that Android is JVM native, so the Java APIs are a part of the OS itself.