8187685: NMT: Tracking compiler memory usage of thread's resource area
authorzgu
Fri, 06 Oct 2017 22:40:31 -0400
changeset 47600 5c8607bb3d2d
parent 47599 0fb1d501c408
child 47603 f5f98c9f1884
child 47604 a5abbaac6165
8187685: NMT: Tracking compiler memory usage of thread's resource area Summary: Bias compiler thread's resource area to mtCompiler Reviewed-by: kvn, coleenp
src/hotspot/share/memory/resourceArea.cpp
src/hotspot/share/memory/resourceArea.hpp
src/hotspot/share/runtime/thread.cpp
--- a/src/hotspot/share/memory/resourceArea.cpp	Fri Oct 06 19:33:27 2017 -0400
+++ b/src/hotspot/share/memory/resourceArea.cpp	Fri Oct 06 22:40:31 2017 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,15 @@
 #include "memory/resourceArea.hpp"
 #include "runtime/mutexLocker.hpp"
 #include "runtime/thread.inline.hpp"
+#include "services/memTracker.hpp"
+
+void ResourceArea::bias_to(MEMFLAGS new_flags) {
+  if (new_flags != _flags) {
+    MemTracker::record_arena_free(_flags);
+    MemTracker::record_new_arena(new_flags);
+    _flags = new_flags;
+  }
+}
 
 //------------------------------ResourceMark-----------------------------------
 debug_only(int ResourceArea::_warned;)      // to suppress multiple warnings
--- a/src/hotspot/share/memory/resourceArea.hpp	Fri Oct 06 19:33:27 2017 -0400
+++ b/src/hotspot/share/memory/resourceArea.hpp	Fri Oct 06 22:40:31 2017 -0400
@@ -70,7 +70,11 @@
     return (char*)Amalloc(size, alloc_failmode);
   }
 
-  debug_only(int nesting() const { return _nesting; });
+  // Bias this resource area to specific memory type
+  // (by default, ResourceArea is tagged as mtThread, per-thread general purpose storage)
+  void bias_to(MEMFLAGS flags);
+
+  debug_only(int nesting() const { return _nesting; })
 };
 
 
--- a/src/hotspot/share/runtime/thread.cpp	Fri Oct 06 19:33:27 2017 -0400
+++ b/src/hotspot/share/runtime/thread.cpp	Fri Oct 06 22:40:31 2017 -0400
@@ -3263,6 +3263,9 @@
   _buffer_blob = NULL;
   _compiler = NULL;
 
+  // Compiler uses resource area for compilation, let's bias it to mtCompiler
+  resource_area()->bias_to(mtCompiler);
+
 #ifndef PRODUCT
   _ideal_graph_printer = NULL;
 #endif