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
33class ZPage : public CHeapObj<mtGC> {
34 friend class VMStructs;
35 friend class ZList<ZPage>;
36
37private:
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
56public:
57 ZPage(const ZVirtualMemory& vmem, const ZPhysicalMemory& pmem);
58 ZPage(uint8_t type, const ZVirtualMemory& vmem, const ZPhysicalMemory& pmem);
59
60 uint32_t object_max_count() const;
61 size_t object_alignment_shift() const;
62 size_t object_alignment() const;
63
64 uint8_t type() const;
65 uintptr_t start() const;
66 uintptr_t end() const;
67 size_t size() const;
68 uintptr_t top() const;
69 size_t remaining() const;
70
71 const ZPhysicalMemory& physical_memory() const;
72 const ZVirtualMemory& virtual_memory() const;
73
74 uint8_t numa_id();
75
76 bool is_allocating() const;
77 bool is_relocatable() const;
78
79 bool is_mapped() const;
80 void set_pre_mapped();
81
82 uint64_t last_used() const;
83 void set_last_used();
84
85 void reset();
86
87 ZPage* retype(uint8_t type);
88 ZPage* split(size_t size);
89 ZPage* split(uint8_t type, size_t size);
90
91 bool is_in(uintptr_t addr) const;
92
93 uintptr_t block_start(uintptr_t addr) const;
94 bool block_is_obj(uintptr_t addr) const;
95
96 bool is_marked() const;
97 bool is_object_live(uintptr_t addr) const;
98 bool is_object_strongly_live(uintptr_t addr) const;
99 bool mark_object(uintptr_t addr, bool finalizable, bool& inc_live);
100
101 void inc_live_atomic(uint32_t objects, size_t bytes);
102 uint32_t live_objects() const;
103 size_t live_bytes() const;
104
105 void object_iterate(ObjectClosure* cl);
106
107 uintptr_t alloc_object(size_t size);
108 uintptr_t alloc_object_atomic(size_t size);
109
110 bool undo_alloc_object(uintptr_t addr, size_t size);
111 bool undo_alloc_object_atomic(uintptr_t addr, size_t size);
112
113 void print_on(outputStream* out) const;
114 void print() const;
115};
116
117#endif // SHARE_GC_Z_ZPAGE_HPP
118