1 of 1 people found this helpful
Nhan Tran wrote:
I am using Byteman to measure some methods in my project. I needed the Instrumentation object to calculate objects size, but could not find it out from inside Helper class.
Looking at HelperManager in the codebase of Byteman, I have seen the Instrumentation object there but not being used/exposed.
Hmm, I wonder if maybe there might be a good reason for that? :-)
Nhan Tran wrote:
Or do we have other better way to get the Instrumentation object?
The Instrumentation instance is the key to Pandora's box since it provides access to the whole classbase and allows transformation of any class. It is quite probably the most extreme security risk available to any Java program to provide access to this instance and exposing it would mean that loading Byteman into production systems would be a very unwise move. That would be a significant lost opportunity as Byteman is a very powerful debugging tool for live installations. So, Byteman takes great care to ensure that only specific Byteman classes (actually instances) have access to this instance.
Interestingly, your problem about computing object sizes has been raised before on this forum by Rafael Soares. On that thread I suggested just exposing the getObjectSize capability. I believe Rafael decided to implement a second agent to provide access to the getObjectSize method -- I think because he needed the behaviour imediately. However, it could be implemented safely by adding a getObjectSize() method to HelperManager and having it call the getObjectSize() method of the Instrumentation instance. The Rule could expose this via its own getObjectSize() method and, indeed, getObjectSize() might as well be added as a method in the standard Helper class so it is available by default to all rules. If you want this please raise a JIRA issue for it. Indeed, if you can implement and test it with your own application I'd be happy to accept the code as a contribution.
Andrew Dinn wrote:
The Instrumentation instance is the key to Pandora's box since it provides access to the whole classbase and allows transformation of any class. It is quite probably the most extreme security risk available to any Java program to provide access to this instance and exposing it would mean that loading Byteman into production systems would be a very unwise move
This makes sense. Thanks, Andrew
I am creating a Jira issue at https://issues.jboss.org/browse/BYTEMAN-221 and will attach the patch shortly.
Thank you very much for raising the JIRA even more so providing a fix and testing it. It's always extremely gratifying to have a user find a new use case and even better when they enable it and make the code available for others to benefit from. That's what open source is all about.
In order for me to accept your code I need to ask you to visit https://cla.jboss.org/ and follow the instructions to register as an individual contributor to Byteman (you will need to select this as the project you wish to contribute to). This is a necessary legal step to confirm that you are willing to allow Red Hat to publish your code under the open source license used by the project (LGPL). I get forwarded a notice when you sign which allows me to approve you as a contributor. After that I can add your patch to the repository and it will appear into the next release (I also always mention all new contributors when the release goes out).
Once again, thanks for your help.
Thank you for your support to get me to involve the community