|
|
||
Michael Nascimento Santos's BlogJanuary 2007 ArchivesMeasuring the size of your objects reloadedPosted by mister__m on January 12, 2007 at 10:56 AM | Permalink | Comments (2)The requirements for defining an agent using the So, here are the steps to build a working agent capable of computing the size of your objects. First, let's create the agent class:
One requirement for an agent that is started with the JVM is to have a Now, the main change made to agent definition is that an agent must be packaged on a jar and must be identified by a manifest attribute,
Once you build your project, your agent will be properly packaged and ready to be used. To load it, though, you need to use the
That is it. Running the sample in my machine produces: Size of Object: 8 Size of direct subclass: 8 Size of String "size": 24 Size of Calendar: 112 As a final note, agents are actually intended to allow your code to redefine classes by replace sections of their bytecode as desired. This technique is used by AspectWerkz and AspectJ, for instance, and can also be used for special tasks, such as enabling/disabling specific monitoring, for instance. The object size calculation capability is there, but it is not its main purpose. PS: genesis has been the most active project in December. 3.0 RC1 should be out in a few days. First Java SE 6 bug!Posted by mister__m on January 11, 2007 at 04:13 PM | Permalink | Comments (1)As genesis 3.0 is approaching Release Candidate, I decided to test it using the newly released Java SE 6. I ran the test suite and a single test failed, one involving script evaluation (I've blogged about genesis script support almost two years ago). Since JSR-223 was about to become part of Java SE 6, we've added support for it six months ago. By that time, either the test worked or it hadn't been written yet, but the genesis useradmin sample was running flawless. Well, I've filed a bug in genesis issue tracker and after some investigation, narrowed the problem to its real cause. Basically, you cannot invoke a static method that overloads an instance method using variable.method(arg0, arg1). The following test case demonstrates the problem:
This test output should be something like:
it actually is:test.FunctionsClass@14a9972 true true If you can change the script or the class being called, it is easy to work around this issue (by invoking the method on the class itself with, renaming it or rewriting it to become an instance method). However, if you cannot, you better use Rhino directly. When I run the same test using BSF over Rhino, it works. For future reference, this has been filed as bug # 6512123 (it might take one or two days for it to show up). Let's hope the fix make it to Java SE 6 Update 1. :-)test.FunctionsClass@14a9972 true Exception in thread "main" javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: Can't find method java.lang.Object.equals(string,string). ( | ||
|
|