Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do popular frameworks use bytecode manipulation internally?

I heard that many frameworks (Struts, Spring, Hibernate, AspectJ) use bytecode manipulation internally. What are the compelling reasons to use bytecode manipulation? I'm expecting a answer with at least a use-case for each particular framework.

like image 693
Nuwan Arambage Avatar asked Dec 19 '25 17:12

Nuwan Arambage


1 Answers

These frameworks manipulate the bytecode of your classes so that they can add support for their features into them. For example, Hibernate may code into getters/setters of a class in order to help it track when the entity has been updated (become dirty) and/or to return proxies of sub-entities that contain code to do lazy-loading.

Aspectj manipulates bytecode in order to add the aspects that you have requested it to enforce. For example, if you want to add advice to all the methods of a class to log when they are invoked, then aspectj may add bytecode (that performs that logging) to each method.

like image 66
jhouse Avatar answered Dec 21 '25 05:12

jhouse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!