TLAB retire 对应源码:
threadLocalAllocBuffer.cpp
我们再来看看 JMX 中查看线程分配内存大小的具体实现。首先对应的 JMX 的代码是:
//我们示例中底层调用的实际就是这个方法获取线程分配的内存大小 protected long getThreadAllocatedBytes(long id) { boolean verified = verifyThreadAllocatedMemory(id); if (verified) { //调用 getThreadAllocatedMemory0 获取分配的内存大小 return getThreadAllocatedMemory0( Thread.currentThread().getId() == id ? 0 : id); } return -1; } //getThreadAllocatedMemory0 是一个 native 方法 private static native long getThreadAllocatedMemory0(long id);