8183573: Refactor CodeHeap and AOTCodeHeap to devirtualize hot methods
authorredestad
Mon, 10 Jul 2017 23:28:25 +0200
changeset 46647 634dc786bf96
parent 46646 5165b3a5b44a
child 46648 527ce5a7c737
8183573: Refactor CodeHeap and AOTCodeHeap to devirtualize hot methods Reviewed-by: kvn, dlong
hotspot/src/share/vm/aot/aotCodeHeap.cpp
hotspot/src/share/vm/aot/aotCodeHeap.hpp
hotspot/src/share/vm/code/codeCache.cpp
hotspot/src/share/vm/code/codeCache.hpp
hotspot/src/share/vm/memory/heap.hpp
--- a/hotspot/src/share/vm/aot/aotCodeHeap.cpp	Mon Jul 10 10:10:49 2017 +0200
+++ b/hotspot/src/share/vm/aot/aotCodeHeap.cpp	Mon Jul 10 23:28:25 2017 +0200
@@ -258,7 +258,6 @@
   _code_to_aot = NEW_C_HEAP_ARRAY(CodeToAMethod, _method_count, mtCode);
   memset(_code_to_aot, 0, _method_count * sizeof(CodeToAMethod));
 
-  _low_boundary = _code_space;
   _memory.set_low_boundary((char *)_code_space);
   _memory.set_high_boundary((char *)_code_space);
   _memory.set_low((char *)_code_space);
--- a/hotspot/src/share/vm/aot/aotCodeHeap.hpp	Mon Jul 10 10:10:49 2017 +0200
+++ b/hotspot/src/share/vm/aot/aotCodeHeap.hpp	Mon Jul 10 23:28:25 2017 +0200
@@ -191,24 +191,20 @@
   // Collect stubs info
   int* _stubs_offsets;
 
-  address _low_boundary;
-
   bool _lib_symbols_initialized;
 
   void adjust_boundaries(AOTCompiledMethod* method) {
-    address low = _low_boundary;
-    if (method->code_begin() < low) {
-      low = method->code_begin();
+    char* low = (char*)method->code_begin();
+    if (low < low_boundary()) {
+      _memory.set_low_boundary(low);
+      _memory.set_low(low);
     }
-    address high = high_boundary();
-    if (method->code_end() > high) {
-      high = method->code_end();
+    char* high = (char *)method->code_end();
+    if (high > high_boundary()) {
+      _memory.set_high_boundary(high);
+      _memory.set_high(high);
     }
     assert(_method_count > 0, "methods count should be set already");
-
-    _low_boundary = low;
-    _memory.set_high_boundary((char *)high);
-    _memory.set_high((char *)high);
   }
 
   void register_stubs();
@@ -231,20 +227,6 @@
   AOTCodeHeap(AOTLib* lib);
   virtual ~AOTCodeHeap();
 
-  address low_boundary()  const { return _low_boundary; }
-  address high_boundary() const { return (address)CodeHeap::high(); }
-
-  bool contains(const void* p) const {
-    bool result = (low_boundary() <= p) && (p < high_boundary());
-    assert(!result || (_method_count > 0), "");
-    assert(result == CodeHeap::contains(p), "");
-    return result;
-  }
-
-  bool contains_blob(const CodeBlob* blob) const {
-    return CodeHeap::contains(blob->code_begin());
-  }
-
   AOTCompiledMethod* find_aot(address p) const;
 
   virtual void* find_start(void* p)     const;
--- a/hotspot/src/share/vm/code/codeCache.cpp	Mon Jul 10 10:10:49 2017 +0200
+++ b/hotspot/src/share/vm/code/codeCache.cpp	Mon Jul 10 23:28:25 2017 +0200
@@ -422,6 +422,16 @@
   MemoryService::add_code_heap_memory_pool(heap, name);
 }
 
+CodeHeap* CodeCache::get_code_heap_containing(void* start) {
+  assert(start != NULL, "start is null");
+  FOR_ALL_HEAPS(heap) {
+    if ((*heap)->contains(start)) {
+      return *heap;
+    }
+  }
+  return NULL;
+}
+
 CodeHeap* CodeCache::get_code_heap(const CodeBlob* cb) {
   assert(cb != NULL, "CodeBlob is null");
   FOR_ALL_HEAPS(heap) {
@@ -609,12 +619,10 @@
 // what you are doing)
 CodeBlob* CodeCache::find_blob_unsafe(void* start) {
   // NMT can walk the stack before code cache is created
-  if (_heaps != NULL && !_heaps->is_empty()) {
-    FOR_ALL_HEAPS(heap) {
-      CodeBlob* result = (*heap)->find_blob_unsafe(start);
-      if (result != NULL) {
-        return result;
-      }
+  if (_heaps != NULL) {
+    CodeHeap* heap = get_code_heap_containing(start);
+    if (heap != NULL) {
+      return heap->find_blob_unsafe(start);
     }
   }
   return NULL;
--- a/hotspot/src/share/vm/code/codeCache.hpp	Mon Jul 10 10:10:49 2017 +0200
+++ b/hotspot/src/share/vm/code/codeCache.hpp	Mon Jul 10 23:28:25 2017 +0200
@@ -102,6 +102,7 @@
   static void check_heap_sizes(size_t non_nmethod_size, size_t profiled_size, size_t non_profiled_size, size_t cache_size, bool all_set);
   // Creates a new heap with the given name and size, containing CodeBlobs of the given type
   static void add_heap(ReservedSpace rs, const char* name, int code_blob_type);
+  static CodeHeap* get_code_heap_containing(void* p);         // Returns the CodeHeap containing the given pointer, or NULL
   static CodeHeap* get_code_heap(const CodeBlob* cb);         // Returns the CodeHeap for the given CodeBlob
   static CodeHeap* get_code_heap(int code_blob_type);         // Returns the CodeHeap for the given CodeBlobType
   // Returns the name of the VM option to set the size of the corresponding CodeHeap
--- a/hotspot/src/share/vm/memory/heap.hpp	Mon Jul 10 10:10:49 2017 +0200
+++ b/hotspot/src/share/vm/memory/heap.hpp	Mon Jul 10 23:28:25 2017 +0200
@@ -149,12 +149,12 @@
   void  deallocate(void* p);    // Deallocate memory
 
   // Attributes
-  char* low_boundary() const                     { return _memory.low_boundary (); }
+  char* low_boundary() const                     { return _memory.low_boundary(); }
   char* high() const                             { return _memory.high(); }
   char* high_boundary() const                    { return _memory.high_boundary(); }
 
-  virtual bool contains(const void* p) const     { return low_boundary() <= p && p < high(); }
-  virtual bool contains_blob(const CodeBlob* blob) const { return low_boundary() <= (char*) blob && (char*) blob < high(); }
+  bool contains(const void* p) const             { return low_boundary() <= p && p < high(); }
+  bool contains_blob(const CodeBlob* blob) const { return contains(blob->code_begin()); }
 
   virtual void* find_start(void* p)     const;   // returns the block containing p or NULL
   virtual CodeBlob* find_blob_unsafe(void* start) const;