Skip to content

Instantly share code, notes, and snippets.

@coderplay
Last active December 22, 2015 10:29
Show Gist options
  • Save coderplay/6459358 to your computer and use it in GitHub Desktop.
Save coderplay/6459358 to your computer and use it in GitHub Desktop.
Direct ByteBuffer的内存查看

Java应用中经常用ByteBuffer.allocateDirect()或者Unsafe.allocateMemory()分配一段内存。 MAT等内存查看器看不到native的内存, 所以需要借助gdb等工具来查看.

ByteBuffer bb = ByteBuffer.allocateDirect(capacity)
                              .order(ByteOrder.nativeOrder());

这种ByteBuffer可以得到它的起始内存地址

long address = (DirectBuffer) bb).address();
$sudo gdb /home/min/software/jdk1.7.0_25/bin/java `pgrep java`
(gdb) help x
Examine memory: x/FMT ADDRESS.
ADDRESS is an expression for the memory address to examine.
FMT is a repeat count followed by a format letter and a size letter.
Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),
  t(binary), f(float), a(address), i(instruction), c(char) and s(string).
Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).
The specified number of objects of the specified size are printed
according to the format.

Defaults for format and size letters are those previously used.
Default count is 1.  Default address is following last thing printed
with this command or "print".

(gdb) x/x 140527036522496
0x7fcf0017e000:	0x00000003
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment