We have a Java EE application on WildFly 26 and OpenJDK 1.8, deployed as EAR and containing a JSF application in a WAR file.
I like to measure the size of a list of HttpSession objects, so I need something to calculate deep object size.
I tried different approaches and ended up with Java Object Layout (JOL, https://github.com/openjdk/jol) and its GraphLayout class:
GraphLayout.parseInstance(sessions).totalSize());
When the application runs, I get
java.lang.NoClassDefFoundError: Lorg/jboss/vfs/VirtualFile;
at java.lang.Class.getDeclaredFields0(Native Method) [rt.jar:1.8.0_345]
at java.lang.Class.privateGetDeclaredFields(Class.java:2583) [rt.jar:1.8.0_345]
at java.lang.Class.getDeclaredFields(Class.java:1916) [rt.jar:1.8.0_345]
at org.openjdk.jol.info.GraphWalker.getAllReferences(GraphWalker.java:128)
at org.openjdk.jol.info.GraphWalker.walk(GraphWalker.java:96)
at org.openjdk.jol.info.GraphLayout.parseInstance(GraphLayout.java:63)
at <myClass> [..]
Caused by: java.lang.ClassNotFoundException: org.jboss.vfs.VirtualFile from [Module "org.jboss.as.weld.ejb" version 26.1.1.Final from local module loader [..]
It seems the dependency to the vfs module is missing somewhere, but I don't know how and where to configure that.
Can anyone help me to make this work or propose a different approach, which works for an application as described above?
Edit 1: I put org.jboss.vfs in org/jboss/as/weld/ejb module but this only lead to another class not found in infinispan. Besides JOL, I tested two other approaches, but they ended up in the same error. And I tried to use the approach via an agent as decribed in this SO post, but couldn't make it work in combination with WildFly.
Edit 2: I saw, that the described problem has to do with using reflection, since using an old approach from Heinz Kabutz led to the very same exception:
Caused by: java.lang.NoClassDefFoundError: Lorg/jboss/vfs/VirtualFile;
at java.lang.Class.getDeclaredFields0(Native Method [rt.jar:1.8.0_345]
at java.lang.Class.getDeclaredFields0(Native Method) [rt.jar:1.8.0_345]
at java.lang.Class.privateGetDeclaredFields(Class.java:2583) [rt.jar:1.8.0_345]
at java.lang.Class.getDeclaredFields(Class.java:1916) [rt.jar:1.8.0_345]
at MemoryCounter._estimate( [..]