3

Our application uses alot of DirectByteBuffer's object via nio's FileChannel.map() and ByteBuffer.allocateDirect() to load and process files (ex. DICOM). The code is written in java 8 but compiled in java 11.0.3. We profiled our application using both JMC 7.x and JxRay (which shows DirectByteBuffers memory specifically). JxRay reported that our application used a large amount of DirectByteBuffer (off-heap memory) around 140MB even on the startup of the application, which is pretty unusual. Speficially JxRay report points to jdk.internal.jimage.ImageReader$SharedImageReader object that is holding this large memory. So I created a small hello world without any reference to DirectBuffer's class/object and JxRay reported almost identical result, which I am puzzled. Contacted JxRay team and they told me possiblly the newer JDK 11 jdk.internal.jimage.ImageReader$SharedImageReader could have been initialized and allocated that large memory. JxRay does not report this issue on JDK 1.8 version and they also said the format of the heap dump didn't change between JDK version (8 vs 11). I'm posting this question if somebody has encountered this issue or knowledge thereof.

Thanks

  • 3
    It would probably be useful to post that [mre] you created. – Slaw Jun 09 '20 at 22:39
  • 4
    I don’t understand why this is considered a problem. Every JDK/JRE loads the core classes into memory one way or another. As far as I can see, the only difference is that now this memory mapping is visible on the Java side as `DirectBuffer` whereas in previous versions, it was made by the JVM’s native code without creating an instance of `DirectBuffer`. But in either case, there was off-heap memory containing class data. – Holger Jun 10 '20 at 09:01
  • @Holger Thanks for the info. – user1652398 Jun 11 '20 at 15:45
  • 1
    As a side note, this new behavior allows modular software to read (potentially large) embedded resources more efficiently than the usual `getResourceAsStream​(…).readAllBytes()`, by accessing the memory mapped representation of the resource directly through the `ModuleReader`. – Holger Jun 11 '20 at 16:51

0 Answers0