1 /*
  2  * Copyright (c) 2015, 2019, 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/zList.hpp"
 28 #include "gc/z/zLiveMap.hpp"
 29 #include "gc/z/zPhysicalMemory.hpp"
 30 #include "gc/z/zVirtualMemory.hpp"
 31 #include "memory/allocation.hpp"
 32 
 33 class ZPage : public CHeapObj<mtGC> {
 34   friend class VMStructs;
 35   friend class ZList<ZPage>;
 36 
 37 private:
 38   uint8_t            _type;
 39   uint8_t            _numa_id;
 40   uint32_t           _seqnum;
 41   ZVirtualMemory     _virtual;
 42   volatile uintptr_t _top;
 43   ZLiveMap           _livemap;
 44   uint64_t           _last_used;
 45   ZPhysicalMemory    _physical;
 46   ZListNode<ZPage>   _node;
 47 
 48   void assert_initialized() const;
 49 
 50   uint8_t type_from_size(size_t size) const;
 51   const char* type_to_string() const;
 52 
 53   bool is_object_marked(uintptr_t addr) const;
 54   bool is_object_strongly_marked(uintptr_t addr) const;
 55 
 56 public:
 57   ZPage(const ZVirtualMemory& vmem, const ZPhysicalMemory& pmem);
 58   ZPage(uint8_t type, const ZVirtualMemory& vmem, const ZPhysicalMemory& pmem);
 59   ~ZPage();
 60 
 61   uint32_t object_max_count() const;
 62   size_t object_alignment_shift() const;
 63   size_t object_alignment() const;
 64 
 65   uint8_t type() const;
 66   uintptr_t start() const;
 67   uintptr_t end() const;
 68   size_t size() const;
 69   uintptr_t top() const;
 70   size_t remaining() const;
 71 
 72   const ZPhysicalMemory& physical_memory() const;
 73   const ZVirtualMemory& virtual_memory() const;
 74 
 75   uint8_t numa_id();
 76 
 77   bool is_allocating() const;
 78   bool is_relocatable() const;
 79 
 80   bool is_mapped() const;
 81   void set_pre_mapped();
 82 
 83   uint64_t last_used() const;
 84   void set_last_used();
 85 
 86   void reset();
 87 
 88   ZPage* retype(uint8_t type);
 89   ZPage* split(size_t size);
 90   ZPage* split(uint8_t type, size_t size);
 91 
 92   bool is_in(uintptr_t addr) const;
 93 
 94   bool is_marked() const;
 95   bool is_object_live(uintptr_t addr) const;
 96   bool is_object_strongly_live(uintptr_t addr) const;
 97   bool mark_object(uintptr_t addr, bool finalizable, bool& inc_live);
 98 
 99   void inc_live(uint32_t objects, size_t bytes);
100   uint32_t live_objects() const;
101   size_t live_bytes() const;
102 
103   void object_iterate(ObjectClosure* cl);
104 
105   uintptr_t alloc_object(size_t size);
106   uintptr_t alloc_object_atomic(size_t size);
107 
108   bool undo_alloc_object(uintptr_t addr, size_t size);
109   bool undo_alloc_object_atomic(uintptr_t addr, size_t size);
110 
111   void print_on(outputStream* out) const;
112   void print() const;
113 };
114 
115 class ZPageClosure {
116 public:
117   virtual void do_page(const ZPage* page) = 0;
118 };
119 
120 #endif // SHARE_GC_Z_ZPAGE_HPP