30
30
#include " gc/z/zGeneration.inline.hpp"
31
31
#include " gc/z/zGenerationId.hpp"
32
32
#include " gc/z/zGlobals.hpp"
33
+ #include " gc/z/zLargePages.inline.hpp"
33
34
#include " gc/z/zLock.inline.hpp"
34
35
#include " gc/z/zPage.inline.hpp"
35
36
#include " gc/z/zPageAge.hpp"
46
47
#include " runtime/globals.hpp"
47
48
#include " runtime/init.hpp"
48
49
#include " runtime/java.hpp"
50
+ #include " runtime/os.hpp"
49
51
#include " utilities/debug.hpp"
50
52
#include " utilities/globalDefinitions.hpp"
51
53
@@ -232,29 +234,38 @@ bool ZPageAllocator::is_initialized() const {
232
234
233
235
class ZPreTouchTask : public ZTask {
234
236
private:
235
- const ZPhysicalMemoryManager* const _physical;
236
- volatile zoffset _start;
237
- const zoffset_end _end;
237
+ volatile uintptr_t _current;
238
+ const uintptr_t _end;
239
+
240
+ static void pretouch (zaddress zaddr, size_t size) {
241
+ const uintptr_t addr = untype (zaddr);
242
+ const size_t page_size = ZLargePages::is_explicit () ? ZGranuleSize : os::vm_page_size ();
243
+ os::pretouch_memory ((void *)addr, (void *)(addr + size), page_size);
244
+ }
238
245
239
246
public:
240
- ZPreTouchTask (const ZPhysicalMemoryManager* physical, zoffset start, zoffset_end end)
247
+ ZPreTouchTask (zoffset start, zoffset_end end)
241
248
: ZTask(" ZPreTouchTask" ),
242
- _physical (physical),
243
- _start(start),
244
- _end(end) {}
249
+ _current (untype(start)),
250
+ _end(untype(end)) {}
245
251
246
252
virtual void work () {
253
+ const size_t size = ZGranuleSize;
254
+
247
255
for (;;) {
248
- // Get granule offset
249
- const size_t size = ZGranuleSize;
250
- const zoffset offset = to_zoffset (Atomic::fetch_then_add ((uintptr_t *)&_start, size));
251
- if (offset >= _end) {
256
+ // Claim an offset for this thread
257
+ const uintptr_t claimed = Atomic::fetch_then_add (&_current, size);
258
+ if (claimed >= _end) {
252
259
// Done
253
260
break ;
254
261
}
255
262
256
- // Pre-touch granule
257
- _physical->pretouch (offset, size);
263
+ // At this point we know that we have a valid zoffset / zaddress.
264
+ const zoffset offset = to_zoffset (claimed);
265
+ const zaddress addr = ZOffset::address (offset);
266
+
267
+ // Pre-touch the granule
268
+ pretouch (addr, size);
258
269
}
259
270
}
260
271
};
@@ -271,7 +282,7 @@ bool ZPageAllocator::prime_cache(ZWorkers* workers, size_t size) {
271
282
272
283
if (AlwaysPreTouch) {
273
284
// Pre-touch page
274
- ZPreTouchTask task (&_physical, page->start (), page->end ());
285
+ ZPreTouchTask task (page->start (), page->end ());
275
286
workers->run_all (&task);
276
287
}
277
288
0 commit comments