An open API service indexing awesome lists of open source software.

https://github.com/marschall/object-size

Uses IterateOverObjectsReachableFromObject to compute java object size
https://github.com/marschall/object-size

java jvmti object-graph object-si

Last synced: 3 months ago
JSON representation

Uses IterateOverObjectsReachableFromObject to compute java object size

Awesome Lists containing this project

README

        

Java Object Graph Size
======================

Uses [IterateOverObjectsReachableFromObject](https://docs.oracle.com/en/java/javase/21/docs/specs/jvmti.html#IterateOverObjectsReachableFromObject) to compute the size of an object and all the objects reachable from it.

> During the execution of this function the state of the heap does not change: no objects are allocated, no objects are garbage collected, and the state of objects (including held values) does not change. As a result, threads executing Java programming language code, threads attempting to resume the execution of Java programming language code, and threads attempting to execute JNI functions are typically stalled.

If JFR is present we additionally generate a JFR event allowing you to assess the overhead.

Usage
-----

The native agent has to be loaded using a JVM option.

```
-agentpath:/path/to/libobject-size-agent.so
```

Then it can be used from Java

```java
ObjectSizeCalculator.getInstance().getObjectSize(myObject);
```