Fully featured low overhead profiler for Java EE and Java SE platforms.
Ultimate profiling and monitoring solution for Gradle, Maven, Ant, JUnit and TestNG.
Easy to use performance and memory profiler for .NET framework.

Strong reference shallow size via MemorySnapshot API?

Moderators: Vladimir Kondratyev, Anton Katilin

Strong reference shallow size via MemorySnapshot API?

Postby camlow » Thu Jun 16, 2016 9:44 pm

Hello.

When I open a memory snapshot via the YourKit Java Profiler GUI, I can see the cumulative "shallow size" for all objects that are strong reachable via a GC root.

For example, I might see:

Objects: 7,935,461 / shallow size: 782 MB / retained size: 782 MB Strong reachable among them: 2,090,931 (26%) / shallow size 93 MB (11%) / retained size: 233 MB (29%)


... where "93 MB" is the cumulative "shallow size" for all objects that are strong reachable via a GC root.

Is it possible to get this same number -- the "93 MB" number from the example above -- from a memory snapshot programmatically, via the com.yourkit.api.MemorySnapshot (or some other) API? I believe the MemorySnapshot.getShallowSize() method uses XML query syntax like the examples on the "set description language" page (https://www.yourkit.com/docs/java/help/language.jsp). I haven't found anything on that page, though, which mentions anything specific about filtering the list of objects selected to only those which are reachable from GC roots via strong references, like what is shown in the Profiler GUI.

A query like "<objects class=\"*\">" would seem to just give all available objects. A query like "<retained-objects><roots/></retained-objects>" appears to consider the cumulative set of objects that are reachable from GC roots but this also appears to include objects that aren't included in the "strong reachable" filter that the GUI provides.

Thanks much for any pointers / advice you might be able to provide!
camlow
 
Posts: 2
Joined: Thu Jun 16, 2016 9:23 pm

Re: Strong reference shallow size via MemorySnapshot API?

Postby Anton Katilin » Fri Jun 17, 2016 4:30 pm

Hi,

You can approximate this with the following:

Code: Select all
<reachable-objects>
      <from>
        <roots/>
      </from>

      <object-filter>
        <objects class="*"/>
      </object-filter>

      <field-filter>
        <class name="java.lang.ref.Reference">
          <forbidden field="referent"/>
        </class>
      </field-filter>    
</reachable-objects>


This is not exactly the same as the strongly reachable objects as seen in the UI. The difference is that the above description also includes the finalization queue elements which are instances of java.lang.ref.Finalizer. Note this does not include the objects pending finalization themselves, just the finalization queue itself, i.e. "shallow" list. Nevertheless, this should be a minor fraction of objects and perhaps you can simply ignore it.

If you want, we can consider adding a dedicated tag for objects with given reachability scope in the next EAP build.

Best regards,
Anton
Anton Katilin
 
Posts: 5575
Joined: Wed Aug 11, 2004 8:37 am

Re: Strong reference shallow size via MemorySnapshot API?

Postby camlow » Fri Jun 17, 2016 9:56 pm

Hi Anton,

Thanks, that query looks great. With one slight change to filter out the 'java.lang.ref.Finalizer' objects, it seems to be giving me the same object set as what I see by just clicking on the "Strong References" link - at least for the first few snapshots I've looked at. Here's what I'm using:

Code: Select all
<reachable-objects>
           <from>
             <roots/>
           </from>
           <object-filter>
             <not>
               <objects class="java.lang.ref.Finalizer"/>
             </not>
           </object-filter>
           <field-filter>
             <class name="java.lang.ref.Reference">
               <forbidden field="referent"/>
             </class>
           </field-filter>
         </reachable-objects>


If there would be a way to add a dedicated object tag for reachability scope into the query language, that would be great. Thanks again!
camlow
 
Posts: 2
Joined: Thu Jun 16, 2016 9:23 pm

Re: Strong reference shallow size via MemorySnapshot API?

Postby Anton Katilin » Mon Jun 20, 2016 1:00 pm

Thank you for sharing the improved description.

In the next EAP build we'll add new tags <strong-reachable/>, <weak-soft-reachable/>, <pending-finalization/>, <unreachable/> that correspond to particular reachability scopes.
Anton Katilin
 
Posts: 5575
Joined: Wed Aug 11, 2004 8:37 am

Re: Strong reference shallow size via MemorySnapshot API?

Postby Anton Katilin » Wed Jun 22, 2016 2:51 pm

EAP build 12 with the new tags is available for download.
Anton Katilin
 
Posts: 5575
Joined: Wed Aug 11, 2004 8:37 am


Return to Java Profiler

Who is online

Users browsing this forum: Bing [Bot], sreejithsree, Yahoo [Bot] and 10 guests