Tracing application use of direct byte buffers

You can use the trace facility to diagnose the cause of excessive memory usage or OutOfMemoryError exceptions from applications that use direct byte buffers.

Trace points are available to help diagnose memory problems associated with the use of direct byte buffers. The trace point IDs are j9jcl.335 to j9jcl.338, and have the following form:
  • Trace point j9jcl.335 prints the amount of memory being allocated: >sun_misc_Unsafe_allocateDBBMemory(0x%zx)
  • Trace point j9jcl.336 prints when memory cannot be allocated: <sun_misc_Unsafe_allocateDBBMemory -- OutOfMemory
  • Trace point j9jcl.337 prints the address of the allocated memory: <sun_misc_Unsafe_allocateDBBMemory result = %p
  • Trace point j9jcl.338 prints the address of the memory being freed: >sun_misc_Unsafe_freeDBBMemory(%p)
Note: Trace point IDs are subject to change without notice. To achieve reliable results, see Determining the tracepoint ID of a trace point in the J9 VM reference.

The trace point IDs can be used with the -Xtrace option to track down problems within a component. The -Xtrace command can direct output to a file or the console, or to internal buffers, which are dumped to a file when a problem occurs. There are many options associated with the trace facility that can be used to diagnose problems. See the section Tracing Java applications in the J9 VM reference. For specific information about setting -Xtrace options, see Controlling the trace in the J9 VM reference.

For example, to generate console output when the trace points are called, use the command:
-Xtrace:print=j9jcl.335-338
The output generated is similar to:
17:41:05.420 0x61fa00           j9jcl.335      > sun_misc_Unsafe_allocateDBBMemory(0x21d8)
17:41:05.421 0x61fa00           j9jcl.337      < sun_misc_Unsafe_allocateDBBMemory result = 6B71CC10
17:41:05.428*0x6b926600           j9jcl.338      > sun_misc_Unsafe_freeDBBMemory(6B71CC10)
You can also include stack traces in the console output with the command:
-Xtrace:print=j9jcl.335-338,trigger=tpnid{j9jcl.335-338,jstacktrace}
Here is an example that includes stack trace output, generated by the command:
-Xtrace:print=j9jcl.335-338,trigger=tpnid{j9jcl.335,jstacktrace},trigger=tpnid{j9jcl.338,jstacktrace}
17:54:40.377 0x2dfd00           j9jcl.335      > sun_misc_Unsafe_allocateDBBMemory(0x21d8)
17:54:40.378 0x2dfd00       j9trc_aux.0        - jstacktrace:
17:54:40.379 0x2dfd00       j9trc_aux.1        - [1] sun.misc.Unsafe.allocateDBBMemory (Native Method)
17:54:40.380 0x2dfd00       j9trc_aux.1        - [2] java.nio.DirectByteBuffer.<init> (DirectByteBuffer.java:102)
17:54:40.381 0x2dfd00       j9trc_aux.1        - [3] java.nio.ByteBuffer.allocateDirect (ByteBuffer.java:288)
17:54:40.382 0x2dfd00       j9trc_aux.1        - [4] test.Test1a.allocatebuf (Test1a.java:10)
17:54:40.383 0x2dfd00       j9trc_aux.1        - [5] test.Test1a.main (Test1a.java:14)
17:54:40.383 0x2dfd00           j9jcl.337      < sun_misc_Unsafe_allocateDBBMemory result = 6B79D770
17:54:40.388*0x6ba02300           j9jcl.338      > sun_misc_Unsafe_freeDBBMemory(6B79D770)
17:54:40.389 0x6ba02300       j9trc_aux.0        - jstacktrace:
17:54:40.390 0x6ba02300       j9trc_aux.1        - [1] sun.misc.Unsafe.freeDBBMemory (Native Method)
17:54:40.391 0x6ba02300       j9trc_aux.1        - [2] java.nio.DirectByteBuffer$Deallocator.run (DirectByteBuffer.java:72)
17:54:40.392 0x6ba02300       j9trc_aux.1        - [3] sun.misc.Cleaner.clean (Cleaner.java:125)
17:54:40.393 0x6ba02300       j9trc_aux.1        - [4] java.lang.ref.ReferenceQueue.enqueue (ReferenceQueue.java:137)
17:54:40.393 0x6ba02300       j9trc_aux.1        - [5] java.lang.ref.Reference.enqueueImpl (Reference.java:74)