changeset 56673:f74ec3cbfcc0

8232238: ZGC: Move ZList inline funtions to zList.inline.hpp Reviewed-by: eosterlund
author pliden
date Mon, 21 Oct 2019 09:58:07 +0200
parents 810409af12f1
children 662d9e1e2a60
files src/hotspot/share/gc/z/zList.hpp src/hotspot/share/gc/z/zList.inline.hpp src/hotspot/share/gc/z/zMemory.inline.hpp src/hotspot/share/gc/z/zPage.cpp src/hotspot/share/gc/z/zPage.hpp
diffstat 5 files changed, 222 insertions(+), 150 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/gc/z/zList.hpp	Mon Oct 21 09:57:26 2019 +0200
+++ b/src/hotspot/share/gc/z/zList.hpp	Mon Oct 21 09:58:07 2019 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, 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
@@ -25,7 +25,6 @@
 #define SHARE_GC_Z_ZLIST_HPP
 
 #include "memory/allocation.hpp"
-#include "utilities/debug.hpp"
 
 template <typename T> class ZList;
 
@@ -38,27 +37,15 @@
   ZListNode* _next;
   ZListNode* _prev;
 
-  ZListNode(ZListNode* next, ZListNode* prev) :
-      _next(next),
-      _prev(prev) {}
+  ZListNode(ZListNode* next, ZListNode* prev);
 
-  void set_unused() {
-    _next = NULL;
-    _prev = NULL;
-  }
+  void set_unused();
 
 public:
-  ZListNode() {
-    set_unused();
-  }
+  ZListNode();
+  ~ZListNode();
 
-  ~ZListNode() {
-    set_unused();
-  }
-
-  bool is_unused() const {
-    return _next == NULL && _prev == NULL;
-  }
+  bool is_unused() const;
 };
 
 // Doubly linked list
@@ -72,139 +59,34 @@
   ZList(const ZList<T>& list);
   ZList<T>& operator=(const ZList<T>& list);
 
-  void verify() const {
-    assert(_head._next->_prev == &_head, "List corrupt");
-    assert(_head._prev->_next == &_head, "List corrupt");
-  }
+  void verify() const;
 
-  void insert(ZListNode<T>* before, ZListNode<T>* node) {
-    verify();
+  void insert(ZListNode<T>* before, ZListNode<T>* node);
 
-    assert(node->is_unused(), "Already in a list");
-    node->_prev = before;
-    node->_next = before->_next;
-    before->_next = node;
-    node->_next->_prev = node;
-
-    _size++;
-  }
-
-  ZListNode<T>* cast_to_inner(T* elem) const {
-    return &elem->_node;
-  }
-
-  T* cast_to_outer(ZListNode<T>* node) const {
-    return (T*)((uintptr_t)node - offset_of(T, _node));
-  }
+  ZListNode<T>* cast_to_inner(T* elem) const;
+  T* cast_to_outer(ZListNode<T>* node) const;
 
 public:
-  ZList() :
-      _head(&_head, &_head),
-      _size(0) {
-    verify();
-  }
+  ZList();
 
-  size_t size() const {
-    verify();
-    return _size;
-  }
+  size_t size() const;
+  bool is_empty() const;
 
-  bool is_empty() const {
-    return _size == 0;
-  }
+  T* first() const;
+  T* last() const;
+  T* next(T* elem) const;
+  T* prev(T* elem) const;
 
-  T* first() const {
-    return is_empty() ? NULL : cast_to_outer(_head._next);
-  }
+  void insert_first(T* elem);
+  void insert_last(T* elem);
+  void insert_before(T* before, T* elem);
+  void insert_after(T* after, T* elem);
 
-  T* last() const {
-    return is_empty() ? NULL : cast_to_outer(_head._prev);
-  }
+  void remove(T* elem);
+  T* remove_first();
+  T* remove_last();
 
-  T* next(T* elem) const {
-    verify();
-    ZListNode<T>* next = cast_to_inner(elem)->_next;
-    return (next == &_head) ? NULL : cast_to_outer(next);
-  }
-
-  T* prev(T* elem) const {
-    verify();
-    ZListNode<T>* prev = cast_to_inner(elem)->_prev;
-    return (prev == &_head) ? NULL : cast_to_outer(prev);
-  }
-
-  void insert_first(T* elem) {
-    insert(&_head, cast_to_inner(elem));
-  }
-
-  void insert_last(T* elem) {
-    insert(_head._prev, cast_to_inner(elem));
-  }
-
-  void insert_before(T* before, T* elem) {
-    insert(cast_to_inner(before)->_prev, cast_to_inner(elem));
-  }
-
-  void insert_after(T* after, T* elem) {
-    insert(cast_to_inner(after), cast_to_inner(elem));
-  }
-
-  void remove(T* elem) {
-    verify();
-
-    ZListNode<T>* const node = cast_to_inner(elem);
-    assert(!node->is_unused(), "Not in a list");
-
-    ZListNode<T>* const next = node->_next;
-    ZListNode<T>* const prev = node->_prev;
-    assert(next->_prev == node, "List corrupt");
-    assert(prev->_next == node, "List corrupt");
-
-    prev->_next = next;
-    next->_prev = prev;
-    node->set_unused();
-
-    _size--;
-  }
-
-  T* remove_first() {
-    T* elem = first();
-    if (elem != NULL) {
-      remove(elem);
-    }
-
-    return elem;
-  }
-
-  T* remove_last() {
-    T* elem = last();
-    if (elem != NULL) {
-      remove(elem);
-    }
-
-    return elem;
-  }
-
-  void transfer(ZList<T>* list) {
-    verify();
-
-    if (!list->is_empty()) {
-      list->_head._next->_prev = _head._prev;
-      list->_head._prev->_next = _head._prev->_next;
-
-      _head._prev->_next = list->_head._next;
-      _head._prev = list->_head._prev;
-
-      list->_head._next = &list->_head;
-      list->_head._prev = &list->_head;
-
-      _size += list->_size;
-      list->_size = 0;
-
-      list->verify();
-      verify();
-    }
-  }
+  void transfer(ZList<T>* list);
 };
 
 template <typename T, bool forward>
@@ -226,15 +108,13 @@
 template <typename T>
 class ZListIterator : public ZListIteratorImpl<T, ZLIST_FORWARD> {
 public:
-  ZListIterator(const ZList<T>* list) :
-      ZListIteratorImpl<T, ZLIST_FORWARD>(list) {}
+  ZListIterator(const ZList<T>* list);
 };
 
 template <typename T>
 class ZListReverseIterator : public ZListIteratorImpl<T, ZLIST_REVERSE> {
 public:
-  ZListReverseIterator(const ZList<T>* list) :
-      ZListIteratorImpl<T, ZLIST_REVERSE>(list) {}
+  ZListReverseIterator(const ZList<T>* list);
 };
 
 #endif // SHARE_GC_Z_ZLIST_HPP
--- a/src/hotspot/share/gc/z/zList.inline.hpp	Mon Oct 21 09:57:26 2019 +0200
+++ b/src/hotspot/share/gc/z/zList.inline.hpp	Mon Oct 21 09:58:07 2019 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, 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
@@ -25,14 +25,193 @@
 #define SHARE_GC_Z_ZLIST_INLINE_HPP
 
 #include "gc/z/zList.hpp"
+#include "utilities/debug.hpp"
+
+template <typename T>
+inline ZListNode<T>::ZListNode(ZListNode* next, ZListNode* prev) :
+    _next(next),
+    _prev(prev) {}
+
+template <typename T>
+inline void ZListNode<T>::set_unused() {
+  _next = NULL;
+  _prev = NULL;
+}
+
+template <typename T>
+inline ZListNode<T>::ZListNode() {
+  set_unused();
+}
+
+template <typename T>
+inline ZListNode<T>::~ZListNode() {
+  set_unused();
+}
+
+template <typename T>
+inline bool ZListNode<T>::is_unused() const {
+  return _next == NULL && _prev == NULL;
+}
+
+template <typename T>
+inline void ZList<T>::verify() const {
+  assert(_head._next->_prev == &_head, "List corrupt");
+  assert(_head._prev->_next == &_head, "List corrupt");
+}
+
+template <typename T>
+inline void ZList<T>::insert(ZListNode<T>* before, ZListNode<T>* node) {
+  verify();
+
+  assert(node->is_unused(), "Already in a list");
+  node->_prev = before;
+  node->_next = before->_next;
+  before->_next = node;
+  node->_next->_prev = node;
+
+  _size++;
+}
+
+template <typename T>
+inline ZListNode<T>* ZList<T>::cast_to_inner(T* elem) const {
+  return &elem->_node;
+}
+
+template <typename T>
+inline T* ZList<T>::cast_to_outer(ZListNode<T>* node) const {
+  return (T*)((uintptr_t)node - offset_of(T, _node));
+}
+
+template <typename T>
+inline ZList<T>::ZList() :
+    _head(&_head, &_head),
+    _size(0) {
+  verify();
+}
+
+template <typename T>
+inline size_t ZList<T>::size() const {
+  verify();
+  return _size;
+}
+
+template <typename T>
+inline bool ZList<T>::is_empty() const {
+  return _size == 0;
+}
+
+template <typename T>
+inline T* ZList<T>::first() const {
+  return is_empty() ? NULL : cast_to_outer(_head._next);
+}
+
+template <typename T>
+inline T* ZList<T>::last() const {
+  return is_empty() ? NULL : cast_to_outer(_head._prev);
+}
+
+template <typename T>
+inline T* ZList<T>::next(T* elem) const {
+  verify();
+  ZListNode<T>* next = cast_to_inner(elem)->_next;
+  return (next == &_head) ? NULL : cast_to_outer(next);
+}
+
+template <typename T>
+inline T* ZList<T>::prev(T* elem) const {
+  verify();
+  ZListNode<T>* prev = cast_to_inner(elem)->_prev;
+  return (prev == &_head) ? NULL : cast_to_outer(prev);
+}
+
+template <typename T>
+inline void ZList<T>::insert_first(T* elem) {
+  insert(&_head, cast_to_inner(elem));
+}
+
+template <typename T>
+inline void ZList<T>::insert_last(T* elem) {
+  insert(_head._prev, cast_to_inner(elem));
+}
+
+template <typename T>
+inline void ZList<T>::insert_before(T* before, T* elem) {
+  insert(cast_to_inner(before)->_prev, cast_to_inner(elem));
+}
+
+template <typename T>
+inline void ZList<T>::insert_after(T* after, T* elem) {
+  insert(cast_to_inner(after), cast_to_inner(elem));
+}
+
+template <typename T>
+inline void ZList<T>::remove(T* elem) {
+  verify();
+
+  ZListNode<T>* const node = cast_to_inner(elem);
+  assert(!node->is_unused(), "Not in a list");
+
+  ZListNode<T>* const next = node->_next;
+  ZListNode<T>* const prev = node->_prev;
+  assert(next->_prev == node, "List corrupt");
+  assert(prev->_next == node, "List corrupt");
+
+  prev->_next = next;
+  next->_prev = prev;
+  node->set_unused();
+
+  _size--;
+}
+
+template <typename T>
+inline T* ZList<T>::remove_first() {
+  T* elem = first();
+  if (elem != NULL) {
+    remove(elem);
+  }
+
+  return elem;
+}
+
+template <typename T>
+inline T* ZList<T>::remove_last() {
+  T* elem = last();
+  if (elem != NULL) {
+    remove(elem);
+  }
+
+  return elem;
+}
+
+template <typename T>
+inline void ZList<T>::transfer(ZList<T>* list) {
+  verify();
+
+  if (!list->is_empty()) {
+    list->_head._next->_prev = _head._prev;
+    list->_head._prev->_next = _head._prev->_next;
+
+    _head._prev->_next = list->_head._next;
+    _head._prev = list->_head._prev;
+
+    list->_head._next = &list->_head;
+    list->_head._prev = &list->_head;
+
+    _size += list->_size;
+    list->_size = 0;
+
+    list->verify();
+    verify();
+  }
+}
 
 template <typename T, bool forward>
-ZListIteratorImpl<T, forward>::ZListIteratorImpl(const ZList<T>* list) :
+inline ZListIteratorImpl<T, forward>::ZListIteratorImpl(const ZList<T>* list) :
     _list(list),
     _next(forward ? list->first() : list->last()) {}
 
 template <typename T, bool forward>
-bool ZListIteratorImpl<T, forward>::next(T** elem) {
+inline bool ZListIteratorImpl<T, forward>::next(T** elem) {
   if (_next != NULL) {
     *elem = _next;
     _next = forward ? _list->next(_next) : _list->prev(_next);
@@ -43,4 +222,12 @@
   return false;
 }
 
+template <typename T>
+inline ZListIterator<T>::ZListIterator(const ZList<T>* list) :
+    ZListIteratorImpl<T, ZLIST_FORWARD>(list) {}
+
+template <typename T>
+inline ZListReverseIterator<T>::ZListReverseIterator(const ZList<T>* list) :
+    ZListIteratorImpl<T, ZLIST_REVERSE>(list) {}
+
 #endif // SHARE_GC_Z_ZLIST_INLINE_HPP
--- a/src/hotspot/share/gc/z/zMemory.inline.hpp	Mon Oct 21 09:57:26 2019 +0200
+++ b/src/hotspot/share/gc/z/zMemory.inline.hpp	Mon Oct 21 09:58:07 2019 +0200
@@ -24,6 +24,7 @@
 #ifndef SHARE_GC_Z_ZMEMORY_INLINE_HPP
 #define SHARE_GC_Z_ZMEMORY_INLINE_HPP
 
+#include "gc/z/zList.inline.hpp"
 #include "gc/z/zMemory.hpp"
 #include "utilities/debug.hpp"
 
--- a/src/hotspot/share/gc/z/zPage.cpp	Mon Oct 21 09:57:26 2019 +0200
+++ b/src/hotspot/share/gc/z/zPage.cpp	Mon Oct 21 09:58:07 2019 +0200
@@ -22,6 +22,7 @@
  */
 
 #include "precompiled.hpp"
+#include "gc/z/zList.inline.hpp"
 #include "gc/z/zPage.inline.hpp"
 #include "gc/z/zPhysicalMemory.inline.hpp"
 #include "gc/z/zVirtualMemory.inline.hpp"
@@ -52,6 +53,8 @@
   assert_initialized();
 }
 
+ZPage::~ZPage() {}
+
 void ZPage::assert_initialized() const {
   assert(!_virtual.is_null(), "Should not be null");
   assert(!_physical.is_null(), "Should not be null");
--- a/src/hotspot/share/gc/z/zPage.hpp	Mon Oct 21 09:57:26 2019 +0200
+++ b/src/hotspot/share/gc/z/zPage.hpp	Mon Oct 21 09:58:07 2019 +0200
@@ -56,6 +56,7 @@
 public:
   ZPage(const ZVirtualMemory& vmem, const ZPhysicalMemory& pmem);
   ZPage(uint8_t type, const ZVirtualMemory& vmem, const ZPhysicalMemory& pmem);
+  ~ZPage();
 
   uint32_t object_max_count() const;
   size_t object_alignment_shift() const;