Saturday, September 17, 2011

Evolution of the Stub Mechanism

Originally my plan for BCBG was to only provide Patch classes. However, I noticed transitioning a base class to a patch class was often needlessly difficult if the modifications weren't complicated. I started designing an extension to the Patch interface that would allow passing in a byte[] as class data to strip methods from, and realized "Hey, I could do this automatically!". I quickly created a very hacky interface to scan for one method and move it to another class. Then I rewrote that into a nicer interface, and made it scan all methods and fields.

The way the current mechanism works is through a "cache" system. I parse through the stub class and cache all the events ASM emits, then replay them on the target class.

The BCBG event chain - the CachingClassAdapter stores the CallCache/CachingMethodAdapter/CachingFieldAdapters to emit later


The old Patch classes are neatly worked in as pre/post Stub operations. The system is very fast, mainly thanks to ASM's optimization. Two Stubs complete in less than a second, depending on their complexity.

Next blog post I'll talk about the Patch class design and how that works in with Stub classes.

No comments:

Post a Comment