author | pliden |
Mon, 18 Mar 2019 11:50:40 +0100 | |
changeset 54167 | d0d26fc836dd |
parent 54163 | 790679f86a51 |
child 54172 | f92f1f1045ad |
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:
52799
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" |
54162
f344a0c6e19e
8220587: ZGC: Break out forwarding information from ZPage
pliden
parents:
52799
diff
changeset
|
25 |
#include "gc/z/zForwarding.inline.hpp" |
54163
790679f86a51
8220588: ZGC: Convert ZRelocationSet to hold ZForwardings instead of ZPages
pliden
parents:
54162
diff
changeset
|
26 |
#include "gc/z/zPage.inline.hpp" |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
27 |
#include "gc/z/zUtils.inline.hpp" |
54162
f344a0c6e19e
8220587: ZGC: Break out forwarding information from ZPage
pliden
parents:
52799
diff
changeset
|
28 |
#include "memory/allocation.hpp" |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
29 |
#include "utilities/debug.hpp" |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
30 |
|
54163
790679f86a51
8220588: ZGC: Convert ZRelocationSet to hold ZForwardings instead of ZPages
pliden
parents:
54162
diff
changeset
|
31 |
ZForwarding::ZForwarding(ZPage* page, uint32_t nentries) : |
790679f86a51
8220588: ZGC: Convert ZRelocationSet to hold ZForwardings instead of ZPages
pliden
parents:
54162
diff
changeset
|
32 |
_virtual(page->virtual_memory()), |
790679f86a51
8220588: ZGC: Convert ZRelocationSet to hold ZForwardings instead of ZPages
pliden
parents:
54162
diff
changeset
|
33 |
_object_alignment_shift(page->object_alignment_shift()), |
54162
f344a0c6e19e
8220587: ZGC: Break out forwarding information from ZPage
pliden
parents:
52799
diff
changeset
|
34 |
_nentries(nentries), |
54163
790679f86a51
8220588: ZGC: Convert ZRelocationSet to hold ZForwardings instead of ZPages
pliden
parents:
54162
diff
changeset
|
35 |
_page(page), |
54162
f344a0c6e19e
8220587: ZGC: Break out forwarding information from ZPage
pliden
parents:
52799
diff
changeset
|
36 |
_refcount(1), |
f344a0c6e19e
8220587: ZGC: Break out forwarding information from ZPage
pliden
parents:
52799
diff
changeset
|
37 |
_pinned(false) {} |
f344a0c6e19e
8220587: ZGC: Break out forwarding information from ZPage
pliden
parents:
52799
diff
changeset
|
38 |
|
54163
790679f86a51
8220588: ZGC: Convert ZRelocationSet to hold ZForwardings instead of ZPages
pliden
parents:
54162
diff
changeset
|
39 |
ZForwarding* ZForwarding::create(ZPage* page) { |
790679f86a51
8220588: ZGC: Convert ZRelocationSet to hold ZForwardings instead of ZPages
pliden
parents:
54162
diff
changeset
|
40 |
assert(page->live_objects() > 0, "Invalid value"); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
41 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
42 |
// Allocate table for linear probing. The size of the table must be |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
43 |
// a power of two to allow for quick and inexpensive indexing/masking. |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
44 |
// The table is sized to have a load factor of 50%, i.e. sized to have |
50875
2217b2fc29ea
8205993: ZGC: Fix typos and incorrect indentations
pliden
parents:
50525
diff
changeset
|
45 |
// double the number of entries actually inserted. |
54163
790679f86a51
8220588: ZGC: Convert ZRelocationSet to hold ZForwardings instead of ZPages
pliden
parents:
54162
diff
changeset
|
46 |
const uint32_t nentries = ZUtils::round_up_power_of_2(page->live_objects() * 2); |
54162
f344a0c6e19e
8220587: ZGC: Break out forwarding information from ZPage
pliden
parents:
52799
diff
changeset
|
47 |
const size_t size = sizeof(ZForwarding) + (sizeof(ZForwardingEntry) * nentries); |
f344a0c6e19e
8220587: ZGC: Break out forwarding information from ZPage
pliden
parents:
52799
diff
changeset
|
48 |
uint8_t* const addr = NEW_C_HEAP_ARRAY(uint8_t, size, mtGC); |
f344a0c6e19e
8220587: ZGC: Break out forwarding information from ZPage
pliden
parents:
52799
diff
changeset
|
49 |
ZForwardingEntry* const entries = ::new (addr + sizeof(ZForwarding)) ZForwardingEntry[nentries]; |
54163
790679f86a51
8220588: ZGC: Convert ZRelocationSet to hold ZForwardings instead of ZPages
pliden
parents:
54162
diff
changeset
|
50 |
ZForwarding* const forwarding = ::new (addr) ZForwarding(page, nentries); |
790679f86a51
8220588: ZGC: Convert ZRelocationSet to hold ZForwardings instead of ZPages
pliden
parents:
54162
diff
changeset
|
51 |
|
54162
f344a0c6e19e
8220587: ZGC: Break out forwarding information from ZPage
pliden
parents:
52799
diff
changeset
|
52 |
return forwarding; |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
53 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
54 |
|
54162
f344a0c6e19e
8220587: ZGC: Break out forwarding information from ZPage
pliden
parents:
52799
diff
changeset
|
55 |
void ZForwarding::destroy(ZForwarding* forwarding) { |
f344a0c6e19e
8220587: ZGC: Break out forwarding information from ZPage
pliden
parents:
52799
diff
changeset
|
56 |
FREE_C_HEAP_ARRAY(uint8_t, forwarding); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
57 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
58 |
|
54163
790679f86a51
8220588: ZGC: Convert ZRelocationSet to hold ZForwardings instead of ZPages
pliden
parents:
54162
diff
changeset
|
59 |
void ZForwarding::verify() const { |
790679f86a51
8220588: ZGC: Convert ZRelocationSet to hold ZForwardings instead of ZPages
pliden
parents:
54162
diff
changeset
|
60 |
guarantee(_refcount > 0, "Invalid refcount"); |
790679f86a51
8220588: ZGC: Convert ZRelocationSet to hold ZForwardings instead of ZPages
pliden
parents:
54162
diff
changeset
|
61 |
guarantee(_page != NULL, "Invalid page"); |
790679f86a51
8220588: ZGC: Convert ZRelocationSet to hold ZForwardings instead of ZPages
pliden
parents:
54162
diff
changeset
|
62 |
|
790679f86a51
8220588: ZGC: Convert ZRelocationSet to hold ZForwardings instead of ZPages
pliden
parents:
54162
diff
changeset
|
63 |
uint32_t live_objects = 0; |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
64 |
|
54162
f344a0c6e19e
8220587: ZGC: Break out forwarding information from ZPage
pliden
parents:
52799
diff
changeset
|
65 |
for (ZForwardingCursor i = 0; i < _nentries; i++) { |
f344a0c6e19e
8220587: ZGC: Break out forwarding information from ZPage
pliden
parents:
52799
diff
changeset
|
66 |
const ZForwardingEntry entry = at(&i); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
67 |
if (entry.is_empty()) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
68 |
// Skip empty entries |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
69 |
continue; |
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 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
72 |
// Check from index |
54163
790679f86a51
8220588: ZGC: Convert ZRelocationSet to hold ZForwardings instead of ZPages
pliden
parents:
54162
diff
changeset
|
73 |
guarantee(entry.from_index() < _page->object_max_count(), "Invalid from index"); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
74 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
75 |
// Check for duplicates |
54162
f344a0c6e19e
8220587: ZGC: Break out forwarding information from ZPage
pliden
parents:
52799
diff
changeset
|
76 |
for (ZForwardingCursor j = i + 1; j < _nentries; j++) { |
f344a0c6e19e
8220587: ZGC: Break out forwarding information from ZPage
pliden
parents:
52799
diff
changeset
|
77 |
const ZForwardingEntry other = at(&j); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
78 |
guarantee(entry.from_index() != other.from_index(), "Duplicate from"); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
79 |
guarantee(entry.to_offset() != other.to_offset(), "Duplicate to"); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
80 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
81 |
|
54163
790679f86a51
8220588: ZGC: Convert ZRelocationSet to hold ZForwardings instead of ZPages
pliden
parents:
54162
diff
changeset
|
82 |
live_objects++; |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
83 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
84 |
|
54163
790679f86a51
8220588: ZGC: Convert ZRelocationSet to hold ZForwardings instead of ZPages
pliden
parents:
54162
diff
changeset
|
85 |
// Check number of non-empty entries |
790679f86a51
8220588: ZGC: Convert ZRelocationSet to hold ZForwardings instead of ZPages
pliden
parents:
54162
diff
changeset
|
86 |
guarantee(live_objects == _page->live_objects(), "Invalid number of entries"); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
87 |
} |