8220589: ZGC: Remove superfluous ZPageTableEntry
authorpliden
Mon, 18 Mar 2019 11:50:39 +0100
changeset 54164 c585ef187216
parent 54163 790679f86a51
child 54165 84295bd6d359
8220589: ZGC: Remove superfluous ZPageTableEntry Reviewed-by: stefank, eosterlund
src/hotspot/share/gc/z/vmStructs_z.hpp
src/hotspot/share/gc/z/zDebug.gdb
src/hotspot/share/gc/z/zHeap.cpp
src/hotspot/share/gc/z/zHeap.hpp
src/hotspot/share/gc/z/zHeap.inline.hpp
src/hotspot/share/gc/z/zMark.cpp
src/hotspot/share/gc/z/zMark.hpp
src/hotspot/share/gc/z/zPageTable.cpp
src/hotspot/share/gc/z/zPageTable.hpp
src/hotspot/share/gc/z/zPageTable.inline.hpp
src/hotspot/share/gc/z/zPageTableEntry.hpp
src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZHeap.java
--- a/src/hotspot/share/gc/z/vmStructs_z.hpp	Mon Mar 18 11:50:39 2019 +0100
+++ b/src/hotspot/share/gc/z/vmStructs_z.hpp	Mon Mar 18 11:50:39 2019 +0100
@@ -53,7 +53,7 @@
   const int* _ZObjectAlignmentSmall;
 };
 
-typedef ZGranuleMap<ZPageTableEntry> ZGranuleMapForPageTable;
+typedef ZGranuleMap<ZPage*> ZGranuleMapForPageTable;
 
 #define VM_STRUCTS_ZGC(nonstatic_field, volatile_nonstatic_field, static_field)                      \
   static_field(ZGlobalsForVMStructs,            _instance_p,          ZGlobalsForVMStructs*)         \
@@ -68,7 +68,7 @@
   nonstatic_field(ZCollectedHeap,               _heap,                ZHeap)                         \
                                                                                                      \
   nonstatic_field(ZHeap,                        _page_allocator,      ZPageAllocator)                \
-  nonstatic_field(ZHeap,                        _pagetable,           ZPageTable)                    \
+  nonstatic_field(ZHeap,                        _page_table,          ZPageTable)                    \
                                                                                                      \
   nonstatic_field(ZPage,                        _type,                const uint8_t)                 \
   nonstatic_field(ZPage,                        _seqnum,              uint32_t)                      \
@@ -80,7 +80,7 @@
                                                                                                      \
   nonstatic_field(ZPageTable,                   _map,                 ZGranuleMapForPageTable)       \
                                                                                                      \
-  nonstatic_field(ZGranuleMapForPageTable,      _map,                 ZPageTableEntry* const)        \
+  nonstatic_field(ZGranuleMapForPageTable,      _map,                 ZPage** const)                 \
                                                                                                      \
   nonstatic_field(ZVirtualMemory,               _start,               uintptr_t)                     \
   nonstatic_field(ZVirtualMemory,               _end,                 uintptr_t)                     \
@@ -115,7 +115,6 @@
   declare_toplevel_type(ZPage)                                                                       \
   declare_toplevel_type(ZPageAllocator)                                                              \
   declare_toplevel_type(ZPageTable)                                                                  \
-  declare_toplevel_type(ZPageTableEntry)                                                             \
   declare_toplevel_type(ZGranuleMapForPageTable)                                                     \
   declare_toplevel_type(ZVirtualMemory)                                                              \
   declare_toplevel_type(ZForwardingTable)                                                            \
--- a/src/hotspot/share/gc/z/zDebug.gdb	Mon Mar 18 11:50:39 2019 +0100
+++ b/src/hotspot/share/gc/z/zDebug.gdb	Mon Mar 18 11:50:39 2019 +0100
@@ -53,17 +53,17 @@
     printf "Mark:  0x%016llx\tKlass: %s\n", (uintptr_t)$obj->_mark, (char*)$obj->_metadata->_klass->_name->_body
 end
 
-# Print heap page by pagetable index
+# Print heap page by page table index
 define zpp
-    set $page = (ZPage*)((uintptr_t)ZHeap::_heap._pagetable._map._map[($arg0)] & ~1)
+    set $page = (ZPage*)((uintptr_t)ZHeap::_heap._page_table._map._map[($arg0)] & ~1)
     printf "Page %p\n", $page
     print *$page
 end
 
-# Print pagetable
+# Print page_table
 define zpt
     printf "Pagetable (first 128 slots)\n"
-    x/128gx ZHeap::_heap._pagetable._map._map
+    x/128gx ZHeap::_heap._page_table._map._map
 end
 
 # Print live map
@@ -100,7 +100,7 @@
     set $addr          = $arg0
     set $obj           = ((uintptr_t)$addr & ZAddressOffsetMask)
     set $page_index    = $obj >> ZGranuleSizeShift
-    set $page_entry    = (uintptr_t)ZHeap::_heap._pagetable._map._map[$page_index]
+    set $page_entry    = (uintptr_t)ZHeap::_heap._page_table._map._map[$page_index]
     set $page          = (ZPage*)($page_entry & ~1)
     set $page_start    = (uintptr_t)$page._virtual._start
     set $page_end      = (uintptr_t)$page._virtual._end
--- a/src/hotspot/share/gc/z/zHeap.cpp	Mon Mar 18 11:50:39 2019 +0100
+++ b/src/hotspot/share/gc/z/zHeap.cpp	Mon Mar 18 11:50:39 2019 +0100
@@ -63,9 +63,9 @@
     _workers(),
     _object_allocator(_workers.nworkers()),
     _page_allocator(heap_min_size(), heap_max_size(), heap_max_reserve_size()),
-    _pagetable(),
+    _page_table(),
     _forwarding_table(),
-    _mark(&_workers, &_pagetable),
+    _mark(&_workers, &_page_table),
     _reference_processor(&_workers),
     _weak_roots_processor(&_workers),
     _relocate(&_workers),
@@ -173,7 +173,7 @@
     return false;
   }
 
-  const ZPage* const page = _pagetable.get(addr);
+  const ZPage* const page = _page_table.get(addr);
   if (page != NULL) {
     return page->is_in(addr);
   }
@@ -182,12 +182,12 @@
 }
 
 uintptr_t ZHeap::block_start(uintptr_t addr) const {
-  const ZPage* const page = _pagetable.get(addr);
+  const ZPage* const page = _page_table.get(addr);
   return page->block_start(addr);
 }
 
 bool ZHeap::block_is_obj(uintptr_t addr) const {
-  const ZPage* const page = _pagetable.get(addr);
+  const ZPage* const page = _page_table.get(addr);
   return page->block_is_obj(addr);
 }
 
@@ -221,8 +221,8 @@
 ZPage* ZHeap::alloc_page(uint8_t type, size_t size, ZAllocationFlags flags) {
   ZPage* const page = _page_allocator.alloc_page(type, size, flags);
   if (page != NULL) {
-    // Update pagetable
-    _pagetable.insert(page);
+    // Update page table
+    _page_table.insert(page);
   }
 
   return page;
@@ -252,7 +252,7 @@
 void ZHeap::after_flip() {
   if (ZVerifyViews) {
     // Map all pages
-    ZPageTableIterator iter(&_pagetable);
+    ZPageTableIterator iter(&_page_table);
     for (ZPage* page; iter.next(&page);) {
       if (!page->is_detached()) {
         _page_allocator.map_page(page);
@@ -406,8 +406,8 @@
   _page_allocator.flush_detached_pages(&list);
 
   for (ZPage* page = list.remove_first(); page != NULL; page = list.remove_first()) {
-    // Remove pagetable entry
-    _pagetable.remove(page);
+    // Remove page table entry
+    _page_table.remove(page);
 
     // Delete the page
     _page_allocator.destroy_page(page);
@@ -417,7 +417,7 @@
 void ZHeap::select_relocation_set() {
   // Register relocatable pages with selector
   ZRelocationSetSelector selector;
-  ZPageTableIterator pt_iter(&_pagetable);
+  ZPageTableIterator pt_iter(&_page_table);
   for (ZPage* page; pt_iter.next(&page);) {
     if (!page->is_relocatable()) {
       // Not relocatable, don't register
@@ -529,7 +529,7 @@
   print_on(st);
   st->cr();
 
-  ZPageTableIterator iter(&_pagetable);
+  ZPageTableIterator iter(&_page_table);
   for (ZPage* page; iter.next(&page);) {
     page->print_on(st);
   }
--- a/src/hotspot/share/gc/z/zHeap.hpp	Mon Mar 18 11:50:39 2019 +0100
+++ b/src/hotspot/share/gc/z/zHeap.hpp	Mon Mar 18 11:50:39 2019 +0100
@@ -55,7 +55,7 @@
   ZWorkers            _workers;
   ZObjectAllocator    _object_allocator;
   ZPageAllocator      _page_allocator;
-  ZPageTable          _pagetable;
+  ZPageTable          _page_table;
   ZForwardingTable    _forwarding_table;
   ZMark               _mark;
   ZReferenceProcessor _reference_processor;
--- a/src/hotspot/share/gc/z/zHeap.inline.hpp	Mon Mar 18 11:50:39 2019 +0100
+++ b/src/hotspot/share/gc/z/zHeap.inline.hpp	Mon Mar 18 11:50:39 2019 +0100
@@ -45,12 +45,12 @@
 }
 
 inline bool ZHeap::is_object_live(uintptr_t addr) const {
-  ZPage* page = _pagetable.get(addr);
+  ZPage* page = _page_table.get(addr);
   return page->is_object_live(addr);
 }
 
 inline bool ZHeap::is_object_strongly_live(uintptr_t addr) const {
-  ZPage* page = _pagetable.get(addr);
+  ZPage* page = _page_table.get(addr);
   return page->is_object_strongly_live(addr);
 }
 
@@ -83,7 +83,7 @@
 }
 
 inline void ZHeap::undo_alloc_object_for_relocation(uintptr_t addr, size_t size) {
-  ZPage* const page = _pagetable.get(addr);
+  ZPage* const page = _page_table.get(addr);
   _object_allocator.undo_alloc_object_for_relocation(page, addr, size);
 }
 
--- a/src/hotspot/share/gc/z/zMark.cpp	Mon Mar 18 11:50:39 2019 +0100
+++ b/src/hotspot/share/gc/z/zMark.cpp	Mon Mar 18 11:50:39 2019 +0100
@@ -56,9 +56,9 @@
 static const ZStatSubPhase ZSubPhaseConcurrentMarkTryTerminate("Concurrent Mark Try Terminate");
 static const ZStatSubPhase ZSubPhaseMarkTryComplete("Pause Mark Try Complete");
 
-ZMark::ZMark(ZWorkers* workers, ZPageTable* pagetable) :
+ZMark::ZMark(ZWorkers* workers, ZPageTable* page_table) :
     _workers(workers),
-    _pagetable(pagetable),
+    _page_table(page_table),
     _allocator(),
     _stripes(),
     _terminate(),
@@ -307,7 +307,7 @@
 }
 
 bool ZMark::try_mark_object(ZMarkCache* cache, uintptr_t addr, bool finalizable) {
-  ZPage* const page = _pagetable->get(addr);
+  ZPage* const page = _page_table->get(addr);
   if (page->is_allocating()) {
     // Newly allocated objects are implicitly marked
     return false;
--- a/src/hotspot/share/gc/z/zMark.hpp	Mon Mar 18 11:50:39 2019 +0100
+++ b/src/hotspot/share/gc/z/zMark.hpp	Mon Mar 18 11:50:39 2019 +0100
@@ -42,7 +42,7 @@
 
 private:
   ZWorkers* const     _workers;
-  ZPageTable* const   _pagetable;
+  ZPageTable* const   _page_table;
   ZMarkStackAllocator _allocator;
   ZMarkStripeSet      _stripes;
   ZMarkTerminate      _terminate;
@@ -101,7 +101,7 @@
   void verify_all_stacks_empty() const;
 
 public:
-  ZMark(ZWorkers* workers, ZPageTable* pagetable);
+  ZMark(ZWorkers* workers, ZPageTable* page_table);
 
   bool is_initialized() const;
 
--- a/src/hotspot/share/gc/z/zPageTable.cpp	Mon Mar 18 11:50:39 2019 +0100
+++ b/src/hotspot/share/gc/z/zPageTable.cpp	Mon Mar 18 11:50:39 2019 +0100
@@ -23,6 +23,7 @@
 
 #include "precompiled.hpp"
 #include "gc/z/zAddress.inline.hpp"
+#include "gc/z/zGranuleMap.inline.hpp"
 #include "gc/z/zPage.inline.hpp"
 #include "gc/z/zPageTable.inline.hpp"
 #include "runtime/orderAccess.hpp"
@@ -31,65 +32,26 @@
 ZPageTable::ZPageTable() :
     _map() {}
 
-ZPageTableEntry ZPageTable::get_entry(ZPage* page) const {
+void ZPageTable::insert(ZPage* page) {
   const uintptr_t addr = ZAddress::good(page->start());
-  return _map.get(addr);
-}
-
-void ZPageTable::put_entry(ZPage* page, ZPageTableEntry entry) {
-  // Make sure a newly created page is globally visible before
-  // updating the pagetable.
-  OrderAccess::storestore();
+  const size_t size = page->size();
 
-  const uintptr_t start = ZAddress::good(page->start());
-  const uintptr_t end = start + page->size();
-  for (uintptr_t addr = start; addr < end; addr += ZGranuleSize) {
-    _map.put(addr, entry);
-  }
-}
-
-void ZPageTable::insert(ZPage* page) {
-  assert(get_entry(page).page() == NULL ||
-         get_entry(page).page() == page, "Invalid entry");
-
-  // Cached pages stays in the pagetable and we must not re-insert
-  // those when they get re-allocated because they might also be
-  // relocating and we don't want to clear their relocating bit.
-  if (get_entry(page).page() == NULL) {
-    ZPageTableEntry entry(page, false /* relocating */);
-    put_entry(page, entry);
+  // Cached pages stays in the page table.
+  // Don't re-insert if it's already present.
+  if (get(addr) == NULL) {
+    // Make sure a newly created page is
+    // visible before updating the page table.
+    OrderAccess::storestore();
+    _map.put(addr, size, page);
   }
 
-  assert(get_entry(page).page() == page, "Invalid entry");
+  assert(get(addr) == page, "Invalid entry");
 }
 
 void ZPageTable::remove(ZPage* page) {
-  assert(get_entry(page).page() == page, "Invalid entry");
-
-  ZPageTableEntry entry;
-  put_entry(page, entry);
-
-  assert(get_entry(page).page() == NULL, "Invalid entry");
-}
-
-void ZPageTable::set_relocating(ZPage* page) {
-  assert(get_entry(page).page() == page, "Invalid entry");
-  assert(!get_entry(page).relocating(), "Invalid entry");
-
-  ZPageTableEntry entry(page, true /* relocating */);
-  put_entry(page, entry);
+  const uintptr_t addr = ZAddress::good(page->start());
+  const size_t size = page->size();
 
-  assert(get_entry(page).page() == page, "Invalid entry");
-  assert(get_entry(page).relocating(), "Invalid entry");
+  assert(get(addr) == page, "Invalid entry");
+  _map.put(addr, size, NULL);
 }
-
-void ZPageTable::clear_relocating(ZPage* page) {
-  assert(get_entry(page).page() == page, "Invalid entry");
-  assert(get_entry(page).relocating(), "Invalid entry");
-
-  ZPageTableEntry entry(page, false /* relocating */);
-  put_entry(page, entry);
-
-  assert(get_entry(page).page() == page, "Invalid entry");
-  assert(!get_entry(page).relocating(), "Invalid entry");
-}
--- a/src/hotspot/share/gc/z/zPageTable.hpp	Mon Mar 18 11:50:39 2019 +0100
+++ b/src/hotspot/share/gc/z/zPageTable.hpp	Mon Mar 18 11:50:39 2019 +0100
@@ -25,7 +25,6 @@
 #define SHARE_GC_Z_ZPAGETABLE_HPP
 
 #include "gc/z/zGranuleMap.hpp"
-#include "gc/z/zPageTableEntry.hpp"
 #include "memory/allocation.hpp"
 
 class ZPage;
@@ -35,30 +34,24 @@
   friend class ZPageTableIterator;
 
 private:
-  ZGranuleMap<ZPageTableEntry> _map;
-
-  ZPageTableEntry get_entry(ZPage* page) const;
-  void put_entry(ZPage* page, ZPageTableEntry entry);
+  ZGranuleMap<ZPage*> _map;
 
 public:
   ZPageTable();
 
   ZPage* get(uintptr_t addr) const;
+
   void insert(ZPage* page);
   void remove(ZPage* page);
-
-  bool is_relocating(uintptr_t addr) const;
-  void set_relocating(ZPage* page);
-  void clear_relocating(ZPage* page);
 };
 
 class ZPageTableIterator : public StackObj {
 private:
-  ZGranuleMapIterator<ZPageTableEntry> _iter;
-  ZPage*                               _prev;
+  ZGranuleMapIterator<ZPage*> _iter;
+  ZPage*                      _prev;
 
 public:
-  ZPageTableIterator(const ZPageTable* pagetable);
+  ZPageTableIterator(const ZPageTable* page_table);
 
   bool next(ZPage** page);
 };
--- a/src/hotspot/share/gc/z/zPageTable.inline.hpp	Mon Mar 18 11:50:39 2019 +0100
+++ b/src/hotspot/share/gc/z/zPageTable.inline.hpp	Mon Mar 18 11:50:39 2019 +0100
@@ -29,25 +29,18 @@
 #include "gc/z/zPageTable.hpp"
 
 inline ZPage* ZPageTable::get(uintptr_t addr) const {
-  return _map.get(addr).page();
+  return _map.get(addr);
 }
 
-inline bool ZPageTable::is_relocating(uintptr_t addr) const {
-  return _map.get(addr).relocating();
-}
-
-inline ZPageTableIterator::ZPageTableIterator(const ZPageTable* pagetable) :
-    _iter(&pagetable->_map),
+inline ZPageTableIterator::ZPageTableIterator(const ZPageTable* page_table) :
+    _iter(&page_table->_map),
     _prev(NULL) {}
 
 inline bool ZPageTableIterator::next(ZPage** page) {
-  ZPageTableEntry entry;
-
-  while (_iter.next(&entry)) {
-    ZPage* const next = entry.page();
-    if (next != NULL && next != _prev) {
+  for (ZPage* entry; _iter.next(&entry);) {
+    if (entry != NULL && entry != _prev) {
       // Next page found
-      *page = _prev = next;
+      *page = _prev = entry;
       return true;
     }
   }
--- a/src/hotspot/share/gc/z/zPageTableEntry.hpp	Mon Mar 18 11:50:39 2019 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,73 +0,0 @@
-/*
- * Copyright (c) 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-#ifndef SHARE_GC_Z_ZPAGETABLEENTRY_HPP
-#define SHARE_GC_Z_ZPAGETABLEENTRY_HPP
-
-#include "gc/z/zBitField.hpp"
-#include "memory/allocation.hpp"
-
-//
-// Page table entry layout
-// -----------------------
-//
-//   6
-//   3                                                                    1 0
-//  +----------------------------------------------------------------------+-+
-//  |11111111 11111111 11111111 11111111 11111111 11111111 11111111 1111111|1|
-//  +----------------------------------------------------------------------+-+
-//  |                                                                      |
-//  |                                          0-0 Relocating Flag (1-bit) *
-//  |
-//  |
-//  |
-//  * 63-1 Page address (63-bits)
-//
-
-class ZPage;
-
-class ZPageTableEntry {
-private:
-  typedef ZBitField<uint64_t, bool,   0, 1>     field_relocating;
-  typedef ZBitField<uint64_t, ZPage*, 1, 63, 1> field_page;
-
-  uint64_t _entry;
-
-public:
-  ZPageTableEntry() :
-      _entry(0) {}
-
-  ZPageTableEntry(ZPage* page, bool relocating) :
-      _entry(field_page::encode(page) |
-             field_relocating::encode(relocating)) {}
-
-  bool relocating() const {
-    return field_relocating::decode(_entry);
-  }
-
-  ZPage* page() const {
-    return field_page::decode(_entry);
-  }
-};
-
-#endif // SHARE_GC_Z_ZPAGETABLEENTRY_HPP
--- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZHeap.java	Mon Mar 18 11:50:39 2019 +0100
+++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/gc/z/ZHeap.java	Mon Mar 18 11:50:39 2019 +0100
@@ -48,7 +48,7 @@
         Type type = db.lookupType("ZHeap");
 
         pageAllocatorFieldOffset = type.getAddressField("_page_allocator").getOffset();
-        pageTableFieldOffset = type.getAddressField("_pagetable").getOffset();
+        pageTableFieldOffset = type.getAddressField("_page_table").getOffset();
     }
 
     public ZHeap(Address addr) {