Byteman Implementation Details

64 views Asked by At

I was looking at the byteman implementation to understand how they work specifically for cases like tracking variables AT/AFTER nth read, AT/AFTER nth write etc. In their implementation they read a class two times once for checking if it matches with the Rule specified by the user using RuleCheckMethodAdapter and second time for actually injecting the bytecode (trigger) at the interested place in the class using RuleTriggerAdapter. What I failed to understand is why do we need 2 passes, Why can't in the first pass itself we could add the trigger if there is a match with the rule? Any insights on the same would be helpful.

1

There are 1 answers

0
Byteman Project On

All the injection stages for all location types use two passes. The first pass is a verification step that ensures the location actually matches the code at a specific point in the method bytecode. It records information needed to allow injection to be performed appropriately for that location and saves it for use by the second pass. n.b. this first stage is invariably a very cheap and quick code scan.

The second stage tracks a lot more information about the code structure, abstract machine stack layouts and types, etc. This is partly to ensure that it does the injection correctly but it also has to do a lot of work to ensure that it can correctly route exceptions out of the injected regions. There is no point incurring this overhead until it is clear that the rule applies.