author | stefank |
Mon, 28 Oct 2019 11:27:27 +0100 | |
changeset 58815 | a4cdca87152b |
parent 58705 | f5662bdbee4a |
permissions | -rw-r--r-- |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
1 |
/* |
54162
f344a0c6e19e
8220587: ZGC: Break out forwarding information from ZPage
pliden
parents:
50525
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
4 |
* |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
8 |
* |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
13 |
* accompanied this code). |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
14 |
* |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
18 |
* |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
21 |
* questions. |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
22 |
*/ |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
23 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
24 |
#include "precompiled.hpp" |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
25 |
#include "gc/z/zList.inline.hpp" |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
26 |
#include "gc/z/zNUMA.hpp" |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
27 |
#include "gc/z/zPage.inline.hpp" |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
28 |
#include "gc/z/zPageCache.hpp" |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
29 |
#include "gc/z/zStat.hpp" |
58705
f5662bdbee4a
8232235: ZGC: Move ZValue inline funtions to zValue.inline.hpp
pliden
parents:
54834
diff
changeset
|
30 |
#include "gc/z/zValue.inline.hpp" |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
31 |
#include "logging/log.hpp" |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
32 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
33 |
static const ZStatCounter ZCounterPageCacheHitL1("Memory", "Page Cache Hit L1", ZStatUnitOpsPerSecond); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
34 |
static const ZStatCounter ZCounterPageCacheHitL2("Memory", "Page Cache Hit L2", ZStatUnitOpsPerSecond); |
54834
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
35 |
static const ZStatCounter ZCounterPageCacheHitL3("Memory", "Page Cache Hit L3", ZStatUnitOpsPerSecond); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
36 |
static const ZStatCounter ZCounterPageCacheMiss("Memory", "Page Cache Miss", ZStatUnitOpsPerSecond); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
37 |
|
54834
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
38 |
ZPageCacheFlushClosure::ZPageCacheFlushClosure(size_t requested) : |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
39 |
_requested(requested), |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
40 |
_flushed(0) {} |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
41 |
|
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
42 |
size_t ZPageCacheFlushClosure::overflushed() const { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
43 |
return _flushed > _requested ? _flushed - _requested : 0; |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
44 |
} |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
45 |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
46 |
ZPageCache::ZPageCache() : |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
47 |
_available(0), |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
48 |
_small(), |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
49 |
_medium(), |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
50 |
_large() {} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
51 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
52 |
ZPage* ZPageCache::alloc_small_page() { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
53 |
const uint32_t numa_id = ZNUMA::id(); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
54 |
const uint32_t numa_count = ZNUMA::count(); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
55 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
56 |
// Try NUMA local page cache |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
57 |
ZPage* const l1_page = _small.get(numa_id).remove_first(); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
58 |
if (l1_page != NULL) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
59 |
ZStatInc(ZCounterPageCacheHitL1); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
60 |
return l1_page; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
61 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
62 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
63 |
// Try NUMA remote page cache(s) |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
64 |
uint32_t remote_numa_id = numa_id + 1; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
65 |
const uint32_t remote_numa_count = numa_count - 1; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
66 |
for (uint32_t i = 0; i < remote_numa_count; i++) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
67 |
if (remote_numa_id == numa_count) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
68 |
remote_numa_id = 0; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
69 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
70 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
71 |
ZPage* const l2_page = _small.get(remote_numa_id).remove_first(); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
72 |
if (l2_page != NULL) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
73 |
ZStatInc(ZCounterPageCacheHitL2); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
74 |
return l2_page; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
75 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
76 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
77 |
remote_numa_id++; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
78 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
79 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
80 |
return NULL; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
81 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
82 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
83 |
ZPage* ZPageCache::alloc_medium_page() { |
54834
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
84 |
ZPage* const page = _medium.remove_first(); |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
85 |
if (page != NULL) { |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
86 |
ZStatInc(ZCounterPageCacheHitL1); |
54834
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
87 |
return page; |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
88 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
89 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
90 |
return NULL; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
91 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
92 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
93 |
ZPage* ZPageCache::alloc_large_page(size_t size) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
94 |
// Find a page with the right size |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
95 |
ZListIterator<ZPage> iter(&_large); |
54834
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
96 |
for (ZPage* page; iter.next(&page);) { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
97 |
if (size == page->size()) { |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
98 |
// Page found |
54834
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
99 |
_large.remove(page); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
100 |
ZStatInc(ZCounterPageCacheHitL1); |
54834
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
101 |
return page; |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
102 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
103 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
104 |
|
54834
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
105 |
return NULL; |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
106 |
} |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
107 |
|
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
108 |
ZPage* ZPageCache::alloc_oversized_medium_page(size_t size) { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
109 |
if (size <= ZPageSizeMedium) { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
110 |
return _medium.remove_first(); |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
111 |
} |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
112 |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
113 |
return NULL; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
114 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
115 |
|
54834
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
116 |
ZPage* ZPageCache::alloc_oversized_large_page(size_t size) { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
117 |
// Find a page that is large enough |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
118 |
ZListIterator<ZPage> iter(&_large); |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
119 |
for (ZPage* page; iter.next(&page);) { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
120 |
if (size <= page->size()) { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
121 |
// Page found |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
122 |
_large.remove(page); |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
123 |
return page; |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
124 |
} |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
125 |
} |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
126 |
|
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
127 |
return NULL; |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
128 |
} |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
129 |
|
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
130 |
ZPage* ZPageCache::alloc_oversized_page(size_t size) { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
131 |
ZPage* page = alloc_oversized_large_page(size); |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
132 |
if (page == NULL) { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
133 |
page = alloc_oversized_medium_page(size); |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
134 |
} |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
135 |
|
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
136 |
if (page != NULL) { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
137 |
ZStatInc(ZCounterPageCacheHitL3); |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
138 |
} |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
139 |
|
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
140 |
return page; |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
141 |
} |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
142 |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
143 |
ZPage* ZPageCache::alloc_page(uint8_t type, size_t size) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
144 |
ZPage* page; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
145 |
|
54834
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
146 |
// Try allocate exact page |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
147 |
if (type == ZPageTypeSmall) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
148 |
page = alloc_small_page(); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
149 |
} else if (type == ZPageTypeMedium) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
150 |
page = alloc_medium_page(); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
151 |
} else { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
152 |
page = alloc_large_page(size); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
153 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
154 |
|
54834
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
155 |
if (page == NULL) { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
156 |
// Try allocate potentially oversized page |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
157 |
ZPage* const oversized = alloc_oversized_page(size); |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
158 |
if (oversized != NULL) { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
159 |
if (size < oversized->size()) { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
160 |
// Split oversized page |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
161 |
page = oversized->split(type, size); |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
162 |
|
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
163 |
// Cache remainder |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
164 |
free_page_inner(oversized); |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
165 |
} else { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
166 |
// Re-type correctly sized page |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
167 |
page = oversized->retype(type); |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
168 |
} |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
169 |
} |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
170 |
} |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
171 |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
172 |
if (page != NULL) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
173 |
_available -= page->size(); |
54834
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
174 |
} else { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
175 |
ZStatInc(ZCounterPageCacheMiss); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
176 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
177 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
178 |
return page; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
179 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
180 |
|
54834
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
181 |
void ZPageCache::free_page_inner(ZPage* page) { |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
182 |
const uint8_t type = page->type(); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
183 |
if (type == ZPageTypeSmall) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
184 |
_small.get(page->numa_id()).insert_first(page); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
185 |
} else if (type == ZPageTypeMedium) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
186 |
_medium.insert_first(page); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
187 |
} else { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
188 |
_large.insert_first(page); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
189 |
} |
54834
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
190 |
} |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
191 |
|
54834
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
192 |
void ZPageCache::free_page(ZPage* page) { |
39ba09047e19
8222480: Implementation: JEP 351: ZGC: Uncommit Unused Memory
pliden
parents:
54618
diff
changeset
|
193 |
free_page_inner(page); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
194 |
_available += page->size(); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
195 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
196 |
|
54618 | 197 |
bool ZPageCache::flush_list_inner(ZPageCacheFlushClosure* cl, ZList<ZPage>* from, ZList<ZPage>* to) { |
198 |
ZPage* const page = from->last(); |
|
199 |
if (page == NULL || !cl->do_page(page)) { |
|
200 |
// Don't flush page |
|
201 |
return false; |
|
202 |
} |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
203 |
|
54618 | 204 |
// Flush page |
205 |
_available -= page->size(); |
|
206 |
from->remove(page); |
|
207 |
to->insert_last(page); |
|
208 |
return true; |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
209 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
210 |
|
54618 | 211 |
void ZPageCache::flush_list(ZPageCacheFlushClosure* cl, ZList<ZPage>* from, ZList<ZPage>* to) { |
212 |
while (flush_list_inner(cl, from, to)); |
|
213 |
} |
|
214 |
||
215 |
void ZPageCache::flush_per_numa_lists(ZPageCacheFlushClosure* cl, ZPerNUMA<ZList<ZPage> >* from, ZList<ZPage>* to) { |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
216 |
const uint32_t numa_count = ZNUMA::count(); |
54618 | 217 |
uint32_t numa_done = 0; |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
218 |
uint32_t numa_next = 0; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
219 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
220 |
// Flush lists round-robin |
54618 | 221 |
while (numa_done < numa_count) { |
222 |
ZList<ZPage>* numa_list = from->addr(numa_next); |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
223 |
if (++numa_next == numa_count) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
224 |
numa_next = 0; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
225 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
226 |
|
54618 | 227 |
if (flush_list_inner(cl, numa_list, to)) { |
228 |
// Not done |
|
229 |
numa_done = 0; |
|
230 |
} else { |
|
231 |
// Done |
|
232 |
numa_done++; |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
233 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
234 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
235 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
236 |
|
54618 | 237 |
void ZPageCache::flush(ZPageCacheFlushClosure* cl, ZList<ZPage>* to) { |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
238 |
// Prefer flushing large, then medium and last small pages |
54618 | 239 |
flush_list(cl, &_large, to); |
240 |
flush_list(cl, &_medium, to); |
|
241 |
flush_per_numa_lists(cl, &_small, to); |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
242 |
} |
58815
a4cdca87152b
8232604: ZGC: Make ZVerifyViews mapping and unmapping precise
stefank
parents:
58705
diff
changeset
|
243 |
|
a4cdca87152b
8232604: ZGC: Make ZVerifyViews mapping and unmapping precise
stefank
parents:
58705
diff
changeset
|
244 |
void ZPageCache::pages_do(ZPageClosure* cl) const { |
a4cdca87152b
8232604: ZGC: Make ZVerifyViews mapping and unmapping precise
stefank
parents:
58705
diff
changeset
|
245 |
// Small |
a4cdca87152b
8232604: ZGC: Make ZVerifyViews mapping and unmapping precise
stefank
parents:
58705
diff
changeset
|
246 |
ZPerNUMAConstIterator<ZList<ZPage> > iter_numa(&_small); |
a4cdca87152b
8232604: ZGC: Make ZVerifyViews mapping and unmapping precise
stefank
parents:
58705
diff
changeset
|
247 |
for (const ZList<ZPage>* list; iter_numa.next(&list);) { |
a4cdca87152b
8232604: ZGC: Make ZVerifyViews mapping and unmapping precise
stefank
parents:
58705
diff
changeset
|
248 |
ZListIterator<ZPage> iter_small(list); |
a4cdca87152b
8232604: ZGC: Make ZVerifyViews mapping and unmapping precise
stefank
parents:
58705
diff
changeset
|
249 |
for (ZPage* page; iter_small.next(&page);) { |
a4cdca87152b
8232604: ZGC: Make ZVerifyViews mapping and unmapping precise
stefank
parents:
58705
diff
changeset
|
250 |
cl->do_page(page); |
a4cdca87152b
8232604: ZGC: Make ZVerifyViews mapping and unmapping precise
stefank
parents:
58705
diff
changeset
|
251 |
} |
a4cdca87152b
8232604: ZGC: Make ZVerifyViews mapping and unmapping precise
stefank
parents:
58705
diff
changeset
|
252 |
} |
a4cdca87152b
8232604: ZGC: Make ZVerifyViews mapping and unmapping precise
stefank
parents:
58705
diff
changeset
|
253 |
|
a4cdca87152b
8232604: ZGC: Make ZVerifyViews mapping and unmapping precise
stefank
parents:
58705
diff
changeset
|
254 |
// Medium |
a4cdca87152b
8232604: ZGC: Make ZVerifyViews mapping and unmapping precise
stefank
parents:
58705
diff
changeset
|
255 |
ZListIterator<ZPage> iter_medium(&_medium); |
a4cdca87152b
8232604: ZGC: Make ZVerifyViews mapping and unmapping precise
stefank
parents:
58705
diff
changeset
|
256 |
for (ZPage* page; iter_medium.next(&page);) { |
a4cdca87152b
8232604: ZGC: Make ZVerifyViews mapping and unmapping precise
stefank
parents:
58705
diff
changeset
|
257 |
cl->do_page(page); |
a4cdca87152b
8232604: ZGC: Make ZVerifyViews mapping and unmapping precise
stefank
parents:
58705
diff
changeset
|
258 |
} |
a4cdca87152b
8232604: ZGC: Make ZVerifyViews mapping and unmapping precise
stefank
parents:
58705
diff
changeset
|
259 |
|
a4cdca87152b
8232604: ZGC: Make ZVerifyViews mapping and unmapping precise
stefank
parents:
58705
diff
changeset
|
260 |
// Large |
a4cdca87152b
8232604: ZGC: Make ZVerifyViews mapping and unmapping precise
stefank
parents:
58705
diff
changeset
|
261 |
ZListIterator<ZPage> iter_large(&_large); |
a4cdca87152b
8232604: ZGC: Make ZVerifyViews mapping and unmapping precise
stefank
parents:
58705
diff
changeset
|
262 |
for (ZPage* page; iter_large.next(&page);) { |
a4cdca87152b
8232604: ZGC: Make ZVerifyViews mapping and unmapping precise
stefank
parents:
58705
diff
changeset
|
263 |
cl->do_page(page); |
a4cdca87152b
8232604: ZGC: Make ZVerifyViews mapping and unmapping precise
stefank
parents:
58705
diff
changeset
|
264 |
} |
a4cdca87152b
8232604: ZGC: Make ZVerifyViews mapping and unmapping precise
stefank
parents:
58705
diff
changeset
|
265 |
} |