Skip to content

Commit 0248779

Browse files
committed
Rename manager files
1 parent f935345 commit 0248779

15 files changed

+246
-43
lines changed

src/hotspot/os/posix/gc/z/zVirtualMemory_posix.cpp renamed to src/hotspot/os/posix/gc/z/zVirtualMemoryManager_posix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323

2424
#include "gc/z/zAddress.inline.hpp"
25-
#include "gc/z/zVirtualMemory.hpp"
25+
#include "gc/z/zVirtualMemoryManager.hpp"
2626
#include "logging/log.hpp"
2727

2828
#include <sys/mman.h>
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
/*
2+
* Copyright (c) 2019, 2025, 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+
#include "gc/z/zAddress.inline.hpp"
25+
#include "gc/z/zGlobals.hpp"
26+
#include "gc/z/zLargePages.inline.hpp"
27+
#include "gc/z/zMapper_windows.hpp"
28+
#include "gc/z/zSyscall_windows.hpp"
29+
#include "gc/z/zValue.inline.hpp"
30+
#include "gc/z/zMemory.inline.hpp"
31+
#include "utilities/align.hpp"
32+
#include "utilities/debug.hpp"
33+
34+
class ZVirtualMemoryManagerImpl : public CHeapObj<mtGC> {
35+
public:
36+
virtual void initialize_before_reserve() {}
37+
virtual void initialize_after_reserve(ZMemoryManager* manager) {}
38+
virtual bool reserve(zaddress_unsafe addr, size_t size) = 0;
39+
virtual void unreserve(zaddress_unsafe addr, size_t size) = 0;
40+
};
41+
42+
// Implements small pages (paged) support using placeholder reservation.
43+
//
44+
// When a memory area is free (kept by the virtual memory manager) a
45+
// single placeholder is covering that memory area. When memory is
46+
// allocated from the manager the placeholder is split into granule
47+
// sized placeholders to allow mapping operations on that granularity.
48+
class ZVirtualMemoryManagerSmallPages : public ZVirtualMemoryManagerImpl {
49+
private:
50+
class PlaceholderCallbacks : public AllStatic {
51+
public:
52+
static void split_placeholder(zoffset start, size_t size) {
53+
ZMapper::split_placeholder(ZOffset::address_unsafe(start), size);
54+
}
55+
56+
static void coalesce_placeholders(zoffset start, size_t size) {
57+
ZMapper::coalesce_placeholders(ZOffset::address_unsafe(start), size);
58+
}
59+
60+
// Turn the single placeholder covering the memory area into granule
61+
// sized placeholders.
62+
static void split_into_granule_sized_placeholders(zoffset start, size_t size) {
63+
assert(size >= ZGranuleSize, "Must be at least one granule");
64+
assert(is_aligned(size, ZGranuleSize), "Must be granule aligned");
65+
66+
// Don't call split_placeholder on the last granule, since it is already
67+
// a placeholder and the system call would therefore fail.
68+
const size_t limit = size - ZGranuleSize;
69+
for (size_t offset = 0; offset < limit; offset += ZGranuleSize) {
70+
split_placeholder(start + offset, ZGranuleSize);
71+
}
72+
}
73+
74+
static void coalesce_into_one_placeholder(zoffset start, size_t size) {
75+
assert(is_aligned(size, ZGranuleSize), "Must be granule aligned");
76+
77+
// Granule sized areas are already covered by a single placeholder
78+
if (size > ZGranuleSize) {
79+
coalesce_placeholders(start, size);
80+
}
81+
}
82+
83+
// Called when a memory area is returned to the memory manager but can't
84+
// be merged with an already existing area. Make sure this area is covered
85+
// by a single placeholder.
86+
static void create_callback(const ZMemoryRange& range) {
87+
assert(is_aligned(range.size(), ZGranuleSize), "Must be granule aligned");
88+
89+
coalesce_into_one_placeholder(range.start(), range.size());
90+
}
91+
92+
// Called when a complete memory area in the memory manager is allocated.
93+
// Create granule sized placeholders for the entire area.
94+
static void destroy_callback(const ZMemoryRange& range) {
95+
assert(is_aligned(range.size(), ZGranuleSize), "Must be granule aligned");
96+
97+
split_into_granule_sized_placeholders(range.start(), range.size());
98+
}
99+
100+
// Called when a memory area is allocated at the front of an exising memory area.
101+
// Turn the first part of the memory area into granule sized placeholders.
102+
static void shrink_from_front_callback(const ZMemoryRange& range, size_t size) {
103+
assert(range.size() > size, "Must be larger than what we try to split out");
104+
assert(is_aligned(size, ZGranuleSize), "Must be granule aligned");
105+
106+
// Split the area into two placeholders
107+
split_placeholder(range.start(), size);
108+
109+
// Split the first part into granule sized placeholders
110+
split_into_granule_sized_placeholders(range.start(), size);
111+
}
112+
113+
// Called when a memory area is allocated at the end of an existing memory area.
114+
// Turn the second part of the memory area into granule sized placeholders.
115+
static void shrink_from_back_callback(const ZMemoryRange& range, size_t size) {
116+
assert(range.size() > size, "Must be larger than what we try to split out");
117+
assert(is_aligned(size, ZGranuleSize), "Must be granule aligned");
118+
119+
// Split the area into two placeholders
120+
const zoffset start = to_zoffset(range.end() - size);
121+
split_placeholder(start, size);
122+
123+
// Split the second part into granule sized placeholders
124+
split_into_granule_sized_placeholders(start, size);
125+
}
126+
127+
// Called when freeing a memory area and it can be merged at the start of an
128+
// existing area. Coalesce the underlying placeholders into one.
129+
static void grow_from_front_callback(const ZMemoryRange& range, size_t size) {
130+
assert(is_aligned(range.size(), ZGranuleSize), "Must be granule aligned");
131+
132+
const zoffset start = range.start() - size;
133+
coalesce_into_one_placeholder(start, range.size() + size);
134+
}
135+
136+
// Called when freeing a memory area and it can be merged at the end of an
137+
// existing area. Coalesce the underlying placeholders into one.
138+
static void grow_from_back_callback(const ZMemoryRange& range, size_t size) {
139+
assert(is_aligned(range.size(), ZGranuleSize), "Must be granule aligned");
140+
141+
coalesce_into_one_placeholder(range.start(), range.size() + size);
142+
}
143+
144+
static void register_with(ZMemoryManager* manager) {
145+
// Each reserved virtual memory address area registered in _manager is
146+
// exactly covered by a single placeholder. Callbacks are installed so
147+
// that whenever a memory area changes, the corresponding placeholder
148+
// is adjusted.
149+
//
150+
// The create and grow callbacks are called when virtual memory is
151+
// returned to the memory manager. The new memory area is then covered
152+
// by a new single placeholder.
153+
//
154+
// The destroy and shrink callbacks are called when virtual memory is
155+
// allocated from the memory manager. The memory area is then is split
156+
// into granule-sized placeholders.
157+
//
158+
// See comment in zMapper_windows.cpp explaining why placeholders are
159+
// split into ZGranuleSize sized placeholders.
160+
161+
ZMemoryManager::Callbacks callbacks;
162+
163+
callbacks._create = &create_callback;
164+
callbacks._destroy = &destroy_callback;
165+
callbacks._shrink_from_front = &shrink_from_front_callback;
166+
callbacks._shrink_from_back = &shrink_from_back_callback;
167+
callbacks._grow_from_front = &grow_from_front_callback;
168+
callbacks._grow_from_back = &grow_from_back_callback;
169+
170+
manager->register_callbacks(callbacks);
171+
}
172+
};
173+
174+
virtual void initialize_after_reserve(ZMemoryManager* manager) {
175+
PlaceholderCallbacks::register_with(manager);
176+
}
177+
178+
virtual bool reserve(zaddress_unsafe addr, size_t size) {
179+
const zaddress_unsafe res = ZMapper::reserve(addr, size);
180+
181+
assert(res == addr || untype(res) == 0, "Should not reserve other memory than requested");
182+
return res == addr;
183+
}
184+
185+
virtual void unreserve(zaddress_unsafe addr, size_t size) {
186+
ZMapper::unreserve(addr, size);
187+
}
188+
};
189+
190+
// Implements Large Pages (locked) support using shared AWE physical memory.
191+
192+
// ZPhysicalMemory layer needs access to the section
193+
HANDLE ZAWESection;
194+
195+
class ZVirtualMemoryManagerLargePages : public ZVirtualMemoryManagerImpl {
196+
private:
197+
virtual void initialize_before_reserve() {
198+
ZAWESection = ZMapper::create_shared_awe_section();
199+
}
200+
201+
virtual bool reserve(zaddress_unsafe addr, size_t size) {
202+
const zaddress_unsafe res = ZMapper::reserve_for_shared_awe(ZAWESection, addr, size);
203+
204+
assert(res == addr || untype(res) == 0, "Should not reserve other memory than requested");
205+
return res == addr;
206+
}
207+
208+
virtual void unreserve(zaddress_unsafe addr, size_t size) {
209+
ZMapper::unreserve_for_shared_awe(addr, size);
210+
}
211+
};
212+
213+
static ZVirtualMemoryManagerImpl* _impl = nullptr;
214+
215+
void ZVirtualMemoryManager::pd_initialize_before_reserve() {
216+
if (ZLargePages::is_enabled()) {
217+
_impl = new ZVirtualMemoryManagerLargePages();
218+
} else {
219+
_impl = new ZVirtualMemoryManagerSmallPages();
220+
}
221+
_impl->initialize_before_reserve();
222+
}
223+
224+
void ZVirtualMemoryManager::pd_initialize_after_reserve() {
225+
_impl->initialize_after_reserve(_managers.addr(0));
226+
}
227+
228+
bool ZVirtualMemoryManager::pd_reserve(zaddress_unsafe addr, size_t size) {
229+
return _impl->reserve(addr, size);
230+
}
231+
232+
void ZVirtualMemoryManager::pd_unreserve(zaddress_unsafe addr, size_t size) {
233+
_impl->unreserve(addr, size);
234+
}

src/hotspot/os/windows/gc/z/zVirtualMemory_windows.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "gc/z/zMapper_windows.hpp"
2828
#include "gc/z/zSyscall_windows.hpp"
2929
#include "gc/z/zValue.inline.hpp"
30+
#include "gc/z/zVirtualMemoryManager.hpp"
3031
#include "gc/z/zMemory.inline.hpp"
3132
#include "utilities/align.hpp"
3233
#include "utilities/debug.hpp"

src/hotspot/share/gc/z/zForwarding.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
#include "gc/z/zForwardingEntry.hpp"
3030
#include "gc/z/zGenerationId.hpp"
3131
#include "gc/z/zLock.hpp"
32+
#include "gc/z/zMemory.hpp"
3233
#include "gc/z/zPageAge.hpp"
3334
#include "gc/z/zPageType.hpp"
34-
#include "gc/z/zVirtualMemory.hpp"
3535

3636
class ObjectClosure;
3737
class ZForwardingAllocator;

src/hotspot/share/gc/z/zMappedCache.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include "gc/z/zArray.hpp"
2828
#include "gc/z/zIntrusiveRBTree.hpp"
29-
#include "gc/z/zVirtualMemory.hpp"
29+
#include "gc/z/zMemory.hpp"
3030
#include "utilities/globalDefinitions.hpp"
3131

3232
class ZMappedCacheEntry;

src/hotspot/share/gc/z/zNMT.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "gc/z/zAddress.inline.hpp"
2525
#include "gc/z/zGlobals.hpp"
2626
#include "gc/z/zNMT.hpp"
27-
#include "gc/z/zVirtualMemory.hpp"
2827
#include "nmt/memTag.hpp"
2928
#include "nmt/memTracker.hpp"
3029
#include "nmt/memoryFileTracker.hpp"

src/hotspot/share/gc/z/zNMT.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "gc/z/zAddress.hpp"
2828
#include "gc/z/zGlobals.hpp"
2929
#include "gc/z/zMemory.hpp"
30-
#include "gc/z/zVirtualMemory.hpp"
3130
#include "memory/allStatic.hpp"
3231
#include "nmt/memTracker.hpp"
3332
#include "nmt/memoryFileTracker.hpp"

src/hotspot/share/gc/z/zPageAllocator.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#include "gc/z/zTask.hpp"
4444
#include "gc/z/zUncommitter.hpp"
4545
#include "gc/z/zValue.inline.hpp"
46-
#include "gc/z/zVirtualMemory.inline.hpp"
4746
#include "gc/z/zWorkers.hpp"
4847
#include "jfr/jfrEvents.hpp"
4948
#include "logging/log.hpp"

src/hotspot/share/gc/z/zPageAllocator.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
#include "gc/z/zPage.hpp"
3333
#include "gc/z/zPageAge.hpp"
3434
#include "gc/z/zPageType.hpp"
35-
#include "gc/z/zPhysicalMemory.hpp"
35+
#include "gc/z/zPhysicalMemoryManager.hpp"
3636
#include "gc/z/zSafeDelete.hpp"
3737
#include "gc/z/zValue.hpp"
38-
#include "gc/z/zVirtualMemory.hpp"
38+
#include "gc/z/zVirtualMemoryManager.hpp"
3939

4040
class ThreadClosure;
4141
class ZCacheState;
File renamed without changes.

0 commit comments

Comments
 (0)