1 /*
   2  * Copyright (c) 2015, 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 #ifndef SHARE_GC_Z_ZPAGE_HPP
  25 #define SHARE_GC_Z_ZPAGE_HPP
  26 
  27 #include "gc/z/zForwardingTable.hpp"
  28 #include "gc/z/zList.hpp"
  29 #include "gc/z/zLiveMap.hpp"
  30 #include "gc/z/zPhysicalMemory.hpp"
  31 #include "gc/z/zVirtualMemory.hpp"
  32 #include "memory/allocation.hpp"
  33 
  34 class ZPage : public CHeapObj<mtGC> {
  35   friend class VMStructs;
  36   friend class ZList<ZPage>;
  37 
  38 private:
  39   // Always hot
  40   const uint8_t        _type;             // Page type
  41   volatile uint8_t     _pinned;           // Pinned flag
  42   uint8_t              _numa_id;          // NUMA node affinity
  43   uint32_t             _seqnum;           // Allocation sequence number
  44   const ZVirtualMemory _virtual;          // Virtual start/end address
  45   volatile uintptr_t   _top;              // Virtual top address
  46   ZLiveMap             _livemap;          // Live map
  47 
  48   // Hot when relocated and cached
  49   volatile uint32_t    _refcount;         // Page reference count
  50   ZForwardingTable     _forwarding;       // Forwarding table
  51   ZPhysicalMemory      _physical;         // Physical memory for page
  52   ZListNode<ZPage>     _node;             // Page list node
  53 
  54   const char* type_to_string() const;
  55   uint32_t object_max_count() const;
  56   uintptr_t relocate_object_inner(uintptr_t from_index, uintptr_t from_offset);
  57 
  58   bool is_object_marked(uintptr_t addr) const;
  59   bool is_object_strongly_marked(uintptr_t addr) const;
  60 
  61 public:
  62   ZPage(uint8_t type, ZVirtualMemory vmem, ZPhysicalMemory pmem);
  63   ~ZPage();
  64 
  65   size_t object_alignment_shift() const;
  66   size_t object_alignment() const;
  67 
  68   uint8_t type() const;
  69   uintptr_t start() const;
  70   uintptr_t end() const;
  71   size_t size() const;
  72   uintptr_t top() const;
  73   size_t remaining() const;
  74 
  75   uint8_t numa_id();
  76 
  77   ZPhysicalMemory& physical_memory();
  78   const ZVirtualMemory& virtual_memory() const;
  79 
  80   void reset();
  81 
  82   bool inc_refcount();
  83   bool dec_refcount();
  84 
  85   bool is_in(uintptr_t addr) const;
  86 
  87   uintptr_t block_start(uintptr_t addr) const;
  88   size_t block_size(uintptr_t addr) const;
  89   bool block_is_obj(uintptr_t addr) const;
  90 
  91   bool is_active() const;
  92   bool is_allocating() const;
  93   bool is_relocatable() const;
  94   bool is_detached() const;
  95 
  96   bool is_mapped() const;
  97   void set_pre_mapped();
  98 
  99   bool is_pinned() const;
 100   void set_pinned();
 101 
 102   bool is_forwarding() const;
 103   void set_forwarding();
 104   void reset_forwarding();
 105   void verify_forwarding() const;
 106 
 107   bool is_marked() const;
 108   bool is_object_live(uintptr_t addr) const;
 109   bool is_object_strongly_live(uintptr_t addr) const;
 110   bool mark_object(uintptr_t addr, bool finalizable, bool& inc_live);
 111 
 112   void inc_live_atomic(uint32_t objects, size_t bytes);
 113   size_t live_bytes() const;
 114 
 115   void object_iterate(ObjectClosure* cl);
 116 
 117   uintptr_t alloc_object(size_t size);
 118   uintptr_t alloc_object_atomic(size_t size);
 119 
 120   bool undo_alloc_object(uintptr_t addr, size_t size);
 121   bool undo_alloc_object_atomic(uintptr_t addr, size_t size);
 122 
 123   uintptr_t relocate_object(uintptr_t from);
 124   uintptr_t forward_object(uintptr_t from);
 125 
 126   void print_on(outputStream* out) const;
 127   void print() const;
 128 };
 129 
 130 #endif // SHARE_GC_Z_ZPAGE_HPP