ehcache / sizeof

Configurable sizeOf engine for Ehcache
Apache License 2.0
105 stars 43 forks source link

Exception when size of using with Java 10 #54

Closed jrivard closed 4 years ago

jrivard commented 6 years ago

Executing the basic load of size of in AdopyOpenJDK 10.0.1:

    final SizeOf sizeof = SizeOf.newInstance();
    return sizeof.deepSizeOf( object );

Returns this exception:

InaccessibleObjectException:
java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.lang.Object jdk.internal.loader.AbstractClassLoaderValue$Sub.key accessible: module java.base does not "opens jdk.internal.loader" to unnamed module

henri-tremblay commented 6 years ago

We will probably need to revisit sizeof past Java 9. I think, we relying on reflection, sizeof will need to have JVM arguments. In this case you will need --add-opens java.base/jdk.internal.loader=ALL-UNNAMED

lorban commented 6 years ago

I don't think the sizeof engine would return correct sizes for a new major JDK without modifications. There also is another problem that the reflection-based sizeof engine really should never be picked up as it's much, much slower than the agent and unsafe ones.

Maybe we should have a look at JOL (http://openjdk.java.net/projects/code-tools/jol/) as this does a very similar job, maybe we could join forces?

henri-tremblay commented 6 years ago

Yes. It means that the agent has failed (which is expected starting with Java 9 but I think can be fixed) and Unsafe as failed (which I think is the case in Java 10). And yes joining forces with JOL sounds like a good idea.

sesuncedu commented 6 years ago

A few comments:

  1. UnsafeSizeOf seems to be ok at runtime in the recent-ish build of openjdk 11 I have installed (linux , amd64). Compiling is broken, due to the jdk.internal module not being in the build path.
  2. Layouts haven't really changed much (for hotspot) since compressed-oops ; I expect that value types will break all the things.
  3. Attaching to self requires setting the system property - jdk.attach.allowAttachSelf . If this is set from the command line, agent sizeof seems to work fine.
  4. It ought to be possible to perform the attach by spawning another jvm, passing the id of the current process, and having it do the attach.
  5. I have no idea why the JDK doesn't provide a get(deep)ObjectSize that doesn't require essentially disabling security. Which would make this library so much smaller :-)
chrisdennis commented 4 years ago

The reported issue was fixed in #61. #52 Covers the agent attach issues. Future issues will likely be needed as more issue appear in future JVMs