1 /*
   2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_MEMORY_METASPACE_METABASE_HPP_
  26 #define SHARE_MEMORY_METASPACE_METABASE_HPP_
  27 
  28 #include "utilities/globalDefinitions.hpp"
  29 
  30 namespace metaspace {
  31 namespace internals {
  32 
  33 // Super class of Metablock and Metachunk to allow them to
  34 // be put on the FreeList and in the BinaryTreeDictionary.
  35 template <class T>
  36 class Metabase {
  37   size_t _word_size;
  38   T*     _next;
  39   T*     _prev;
  40 
  41  protected:
  42   Metabase(size_t word_size) : _word_size(word_size), _next(NULL), _prev(NULL) {}
  43 
  44  public:
  45   T* next() const         { return _next; }
  46   T* prev() const         { return _prev; }
  47   void set_next(T* v)     { _next = v; assert(v != this, "Boom");}
  48   void set_prev(T* v)     { _prev = v; assert(v != this, "Boom");}
  49   void clear_next()       { set_next(NULL); }
  50   void clear_prev()       { set_prev(NULL); }
  51 
  52   size_t size() const volatile { return _word_size; }
  53   void set_size(size_t v) { _word_size = v; }
  54 
  55   void link_next(T* ptr)  { set_next(ptr); }
  56   void link_prev(T* ptr)  { set_prev(ptr); }
  57   void link_after(T* ptr) {
  58     link_next(ptr);
  59     if (ptr != NULL) ptr->link_prev((T*)this);
  60   }
  61 
  62   uintptr_t* end() const        { return ((uintptr_t*) this) + size(); }
  63 
  64   bool cantCoalesce() const     { return false; }
  65 
  66   // Debug support
  67 #ifdef ASSERT
  68   void* prev_addr() const { return (void*)&_prev; }
  69   void* next_addr() const { return (void*)&_next; }
  70   void* size_addr() const { return (void*)&_word_size; }
  71 #endif
  72   bool verify_chunk_in_free_list(T* tc) const { return true; }
  73   bool verify_par_locked() { return true; }
  74 
  75   void assert_is_mangled() const {/* Don't check "\*/}
  76 
  77   bool is_free()                 { return true; }
  78 };
  79 
  80 } // namespace metaspace
  81 } // namespace internals
  82 
  83 
  84 #endif /* SHARE_MEMORY_METASPACE_METABASE_HPP_ */