changeset 48254:a5b85019f190

ZGC: Add NMT support for Java heap
author pliden
date Thu, 14 Dec 2017 15:43:58 +0100
parents b97ac01a1c93
children 59c07aef65ac
files src/hotspot/os_cpu/linux_x86/zPhysicalMemoryBacking_linux_x86.cpp src/hotspot/os_cpu/linux_x86/zPhysicalMemoryBacking_linux_x86.hpp src/hotspot/os_cpu/solaris_sparc/zPhysicalMemoryBacking_solaris_sparc.cpp src/hotspot/os_cpu/solaris_sparc/zPhysicalMemoryBacking_solaris_sparc.hpp src/hotspot/share/gc/z/zPhysicalMemory.cpp src/hotspot/share/gc/z/zPhysicalMemory.hpp src/hotspot/share/gc/z/zVirtualMemory.cpp src/hotspot/share/gc/z/zVirtualMemory.hpp
diffstat 8 files changed, 49 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/os_cpu/linux_x86/zPhysicalMemoryBacking_linux_x86.cpp	Mon Dec 11 14:00:53 2017 +0100
+++ b/src/hotspot/os_cpu/linux_x86/zPhysicalMemoryBacking_linux_x86.cpp	Thu Dec 14 15:43:58 2017 +0100
@@ -198,6 +198,11 @@
   }
 }
 
+uintptr_t ZPhysicalMemoryBacking::nmt_address(uintptr_t offset) const {
+  // From an NMT point of view we treat the first heap mapping (marked0) as committed
+  return ZAddress::marked0(offset);
+}
+
 void ZPhysicalMemoryBacking::map(ZPhysicalMemory pmem, uintptr_t offset) const {
   if (ZUnmapBadViews) {
     // Only map the good view, for debugging only
--- a/src/hotspot/os_cpu/linux_x86/zPhysicalMemoryBacking_linux_x86.hpp	Mon Dec 11 14:00:53 2017 +0100
+++ b/src/hotspot/os_cpu/linux_x86/zPhysicalMemoryBacking_linux_x86.hpp	Thu Dec 14 15:43:58 2017 +0100
@@ -54,6 +54,8 @@
   ZPhysicalMemory alloc(size_t size);
   void free(ZPhysicalMemory pmem);
 
+  uintptr_t nmt_address(uintptr_t offset) const;
+
   void map(ZPhysicalMemory pmem, uintptr_t offset) const;
   void unmap(ZPhysicalMemory pmem, uintptr_t offset) const;
   void flip(ZPhysicalMemory pmem, uintptr_t offset) const;
--- a/src/hotspot/os_cpu/solaris_sparc/zPhysicalMemoryBacking_solaris_sparc.cpp	Mon Dec 11 14:00:53 2017 +0100
+++ b/src/hotspot/os_cpu/solaris_sparc/zPhysicalMemoryBacking_solaris_sparc.cpp	Thu Dec 14 15:43:58 2017 +0100
@@ -196,6 +196,11 @@
   }
 }
 
+uintptr_t ZPhysicalMemoryBacking::nmt_address(uintptr_t offset) const {
+  // We only have one heap mapping, so just convert the offset to a heap address
+  return ZAddress::address(offset);
+}
+
 void ZPhysicalMemoryBacking::map(ZPhysicalMemory pmem, uintptr_t offset) const {
   if (UseOSMHeap) {
     map_osm(pmem, offset);
--- a/src/hotspot/os_cpu/solaris_sparc/zPhysicalMemoryBacking_solaris_sparc.hpp	Mon Dec 11 14:00:53 2017 +0100
+++ b/src/hotspot/os_cpu/solaris_sparc/zPhysicalMemoryBacking_solaris_sparc.hpp	Thu Dec 14 15:43:58 2017 +0100
@@ -55,6 +55,8 @@
   ZPhysicalMemory alloc(size_t size);
   void free(ZPhysicalMemory pmem);
 
+  uintptr_t nmt_address(uintptr_t offset) const;
+
   void map(ZPhysicalMemory pmem, uintptr_t offset) const;
   void unmap(ZPhysicalMemory pmem, uintptr_t offset) const;
   void flip(ZPhysicalMemory pmem, uintptr_t offset) const;
--- a/src/hotspot/share/gc/z/zPhysicalMemory.cpp	Mon Dec 11 14:00:53 2017 +0100
+++ b/src/hotspot/share/gc/z/zPhysicalMemory.cpp	Thu Dec 14 15:43:58 2017 +0100
@@ -25,6 +25,7 @@
 #include "gc/z/zPhysicalMemory.inline.hpp"
 #include "logging/log.hpp"
 #include "memory/allocation.inline.hpp"
+#include "services/memTracker.hpp"
 #include "utilities/debug.hpp"
 
 ZPhysicalMemory::ZPhysicalMemory() :
@@ -126,6 +127,19 @@
   return true;
 }
 
+void ZPhysicalMemoryManager::nmt_commit(ZPhysicalMemory pmem, uintptr_t offset) {
+  const uintptr_t addr = _backing.nmt_address(offset);
+  const size_t size = pmem.size();
+  MemTracker::record_virtual_memory_commit((void*)addr, size, CALLER_PC);
+}
+
+void ZPhysicalMemoryManager::nmt_uncommit(ZPhysicalMemory pmem, uintptr_t offset) {
+  const uintptr_t addr = _backing.nmt_address(offset);
+  const size_t size = pmem.size();
+  Tracker tracker = MemTracker::get_virtual_memory_uncommit_tracker();
+  tracker.record((address)addr, size);
+}
+
 ZPhysicalMemory ZPhysicalMemoryManager::alloc(size_t size) {
   if (!ensure_available(size)) {
     // Not enough memory available
@@ -142,11 +156,19 @@
 }
 
 void ZPhysicalMemoryManager::map(ZPhysicalMemory pmem, uintptr_t offset) {
+  // Map page
   _backing.map(pmem, offset);
+
+  // Update native memory tracker
+  nmt_commit(pmem, offset);
 }
 
 void ZPhysicalMemoryManager::unmap(ZPhysicalMemory pmem, uintptr_t offset) {
+  // Unmap page
   _backing.unmap(pmem, offset);
+
+  // Update native memory tracker
+  nmt_uncommit(pmem, offset);
 }
 
 void ZPhysicalMemoryManager::flip(ZPhysicalMemory pmem, uintptr_t offset) {
--- a/src/hotspot/share/gc/z/zPhysicalMemory.hpp	Mon Dec 11 14:00:53 2017 +0100
+++ b/src/hotspot/share/gc/z/zPhysicalMemory.hpp	Thu Dec 14 15:43:58 2017 +0100
@@ -73,6 +73,9 @@
 
   bool ensure_available(size_t size);
 
+  void nmt_commit(ZPhysicalMemory pmem, uintptr_t offset);
+  void nmt_uncommit(ZPhysicalMemory pmem, uintptr_t offset);
+
 public:
   ZPhysicalMemoryManager(size_t max_capacity, size_t granule_size);
 
--- a/src/hotspot/share/gc/z/zVirtualMemory.cpp	Mon Dec 11 14:00:53 2017 +0100
+++ b/src/hotspot/share/gc/z/zVirtualMemory.cpp	Thu Dec 14 15:43:58 2017 +0100
@@ -24,6 +24,7 @@
 #include "precompiled.hpp"
 #include "gc/z/zGlobals.hpp"
 #include "gc/z/zVirtualMemory.inline.hpp"
+#include "services/memTracker.hpp"
 
 ZVirtualMemoryManager::ZVirtualMemoryManager() :
     _manager(),
@@ -36,10 +37,18 @@
   // Make the complete address view free
   _manager.free(0, ZAddressOffsetMax);
 
+  // Register address space with native memory tracker
+  nmt_reserve(ZAddressSpaceStart, ZAddressSpaceSize);
+
   // Successfully initialized
   _initialized = true;
 }
 
+void ZVirtualMemoryManager::nmt_reserve(uintptr_t start, size_t size) {
+  MemTracker::record_virtual_memory_reserve((void*)start, size, CALLER_PC);
+  MemTracker::record_virtual_memory_type((void*)start, mtJavaHeap);
+}
+
 bool ZVirtualMemoryManager::is_initialized() const {
   return _initialized;
 }
--- a/src/hotspot/share/gc/z/zVirtualMemory.hpp	Mon Dec 11 14:00:53 2017 +0100
+++ b/src/hotspot/share/gc/z/zVirtualMemory.hpp	Thu Dec 14 15:43:58 2017 +0100
@@ -50,6 +50,7 @@
   bool           _initialized;
 
   bool reserve(uintptr_t start, size_t size);
+  void nmt_reserve(uintptr_t start, size_t size);
 
 public:
   ZVirtualMemoryManager();