author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 57658 | 0022b39ae5ae |
permissions | -rw-r--r-- |
55603
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
1 |
/* |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
4 |
* |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
8 |
* |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
13 |
* accompanied this code). |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
14 |
* |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
18 |
* |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
21 |
* questions. |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
22 |
*/ |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
23 |
|
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
24 |
#include "precompiled.hpp" |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
25 |
#include "classfile/classLoaderData.hpp" |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
26 |
#include "gc/z/zAddress.hpp" |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
27 |
#include "gc/z/zHeap.inline.hpp" |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
28 |
#include "gc/z/zOop.hpp" |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
29 |
#include "gc/z/zResurrection.hpp" |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
30 |
#include "gc/z/zRootsIterator.hpp" |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
31 |
#include "gc/z/zStat.hpp" |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
32 |
#include "gc/z/zVerify.hpp" |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
33 |
#include "memory/iterator.inline.hpp" |
57658 | 34 |
#include "oops/oop.hpp" |
35 |
||
36 |
#define BAD_OOP_ARG(o, p) "Bad oop " PTR_FORMAT " found at " PTR_FORMAT, p2i(o), p2i(p) |
|
55603
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
37 |
|
57658 | 38 |
static void verify_oop(oop* p) { |
39 |
const oop o = RawAccess<>::oop_load(p); |
|
40 |
if (o != NULL) { |
|
41 |
const uintptr_t addr = ZOop::to_address(o); |
|
42 |
guarantee(ZAddress::is_good(addr), BAD_OOP_ARG(o, p)); |
|
43 |
guarantee(oopDesc::is_oop(ZOop::from_address(addr)), BAD_OOP_ARG(o, p)); |
|
44 |
} |
|
45 |
} |
|
55603
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
46 |
|
57658 | 47 |
static void verify_possibly_weak_oop(oop* p) { |
48 |
const oop o = RawAccess<>::oop_load(p); |
|
49 |
if (o != NULL) { |
|
50 |
const uintptr_t addr = ZOop::to_address(o); |
|
51 |
guarantee(ZAddress::is_good(addr) || ZAddress::is_finalizable_good(addr), BAD_OOP_ARG(o, p)); |
|
52 |
guarantee(oopDesc::is_oop(ZOop::from_address(ZAddress::good(addr))), BAD_OOP_ARG(o, p)); |
|
53 |
} |
|
54 |
} |
|
55 |
||
56 |
class ZVerifyRootClosure : public ZRootsIteratorClosure { |
|
55603
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
57 |
public: |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
58 |
virtual void do_oop(oop* p) { |
57658 | 59 |
verify_oop(p); |
60 |
} |
|
55603
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
61 |
|
57658 | 62 |
virtual void do_oop(narrowOop*) { |
63 |
ShouldNotReachHere(); |
|
55603
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
64 |
} |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
65 |
}; |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
66 |
|
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
67 |
class ZVerifyOopClosure : public ClaimMetadataVisitingOopIterateClosure, public ZRootsIteratorClosure { |
57658 | 68 |
private: |
69 |
const bool _verify_weaks; |
|
70 |
||
55603
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
71 |
public: |
57658 | 72 |
ZVerifyOopClosure(bool verify_weaks) : |
73 |
ClaimMetadataVisitingOopIterateClosure(ClassLoaderData::_claim_other), |
|
74 |
_verify_weaks(verify_weaks) {} |
|
55603
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
75 |
|
57658 | 76 |
virtual void do_oop(oop* p) { |
77 |
if (_verify_weaks) { |
|
78 |
verify_possibly_weak_oop(p); |
|
79 |
} else { |
|
80 |
// We should never encounter finalizable oops through strong |
|
81 |
// paths. This assumes we have only visited strong roots. |
|
82 |
verify_oop(p); |
|
83 |
} |
|
84 |
} |
|
85 |
||
86 |
virtual void do_oop(narrowOop* p) { |
|
87 |
ShouldNotReachHere(); |
|
88 |
} |
|
55603
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
89 |
|
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
90 |
virtual ReferenceIterationMode reference_iteration_mode() { |
57658 | 91 |
return _verify_weaks ? DO_FIELDS : DO_FIELDS_EXCEPT_REFERENT; |
55603
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
92 |
} |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
93 |
|
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
94 |
#ifdef ASSERT |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
95 |
// Verification handled by the closure itself |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
96 |
virtual bool should_verify_oops() { |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
97 |
return false; |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
98 |
} |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
99 |
#endif |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
100 |
}; |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
101 |
|
57658 | 102 |
template <typename RootsIterator> |
103 |
void ZVerify::roots() { |
|
104 |
assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint"); |
|
105 |
assert(!ZResurrection::is_blocked(), "Invalid phase"); |
|
55603
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
106 |
|
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
107 |
if (ZVerifyRoots) { |
57658 | 108 |
ZVerifyRootClosure cl; |
55603
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
109 |
RootsIterator iter; |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
110 |
iter.oops_do(&cl); |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
111 |
} |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
112 |
} |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
113 |
|
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
114 |
void ZVerify::roots_strong() { |
57658 | 115 |
roots<ZRootsIterator>(); |
55603
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
116 |
} |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
117 |
|
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
118 |
void ZVerify::roots_weak() { |
57658 | 119 |
roots<ZWeakRootsIterator>(); |
120 |
} |
|
55603
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
121 |
|
57658 | 122 |
void ZVerify::roots_concurrent_strong() { |
123 |
roots<ZConcurrentRootsIteratorClaimNone>(); |
|
124 |
} |
|
125 |
||
126 |
void ZVerify::roots_concurrent_weak() { |
|
127 |
roots<ZConcurrentWeakRootsIterator>(); |
|
55603
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
128 |
} |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
129 |
|
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
130 |
void ZVerify::roots(bool verify_weaks) { |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
131 |
roots_strong(); |
57658 | 132 |
roots_concurrent_strong(); |
55603
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
133 |
if (verify_weaks) { |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
134 |
roots_weak(); |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
135 |
roots_concurrent_weak(); |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
136 |
} |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
137 |
} |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
138 |
|
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
139 |
void ZVerify::objects(bool verify_weaks) { |
57658 | 140 |
assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint"); |
141 |
assert(ZGlobalPhase == ZPhaseMarkCompleted, "Invalid phase"); |
|
142 |
assert(!ZResurrection::is_blocked(), "Invalid phase"); |
|
143 |
||
55603
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
144 |
if (ZVerifyObjects) { |
57658 | 145 |
ZVerifyOopClosure cl(verify_weaks); |
146 |
ObjectToOopClosure object_cl(&cl); |
|
147 |
ZHeap::heap()->object_iterate(&object_cl, verify_weaks); |
|
55603
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
148 |
} |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
149 |
} |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
150 |
|
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
151 |
void ZVerify::roots_and_objects(bool verify_weaks) { |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
152 |
roots(verify_weaks); |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
153 |
objects(verify_weaks); |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
154 |
} |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
155 |
|
57656
9429ecaee2e0
8229135: ZGC: Adding missing ZStatTimerDisable before call to ZVerify::roots_strong()
pliden
parents:
55603
diff
changeset
|
156 |
void ZVerify::before_zoperation() { |
9429ecaee2e0
8229135: ZGC: Adding missing ZStatTimerDisable before call to ZVerify::roots_strong()
pliden
parents:
55603
diff
changeset
|
157 |
// Verify strong roots |
9429ecaee2e0
8229135: ZGC: Adding missing ZStatTimerDisable before call to ZVerify::roots_strong()
pliden
parents:
55603
diff
changeset
|
158 |
ZStatTimerDisable disable; |
9429ecaee2e0
8229135: ZGC: Adding missing ZStatTimerDisable before call to ZVerify::roots_strong()
pliden
parents:
55603
diff
changeset
|
159 |
roots_strong(); |
9429ecaee2e0
8229135: ZGC: Adding missing ZStatTimerDisable before call to ZVerify::roots_strong()
pliden
parents:
55603
diff
changeset
|
160 |
} |
9429ecaee2e0
8229135: ZGC: Adding missing ZStatTimerDisable before call to ZVerify::roots_strong()
pliden
parents:
55603
diff
changeset
|
161 |
|
55603
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
162 |
void ZVerify::after_mark() { |
57658 | 163 |
// Verify all strong roots and strong references |
164 |
ZStatTimerDisable disable; |
|
55603
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
165 |
roots_and_objects(false /* verify_weaks */); |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
166 |
} |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
167 |
|
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
168 |
void ZVerify::after_weak_processing() { |
57658 | 169 |
// Verify all roots and all references |
170 |
ZStatTimerDisable disable; |
|
55603
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
171 |
roots_and_objects(true /* verify_weaks */); |
3868dde58ebb
8227175: ZGC: ZHeapIterator visits potentially dead objects
stefank
parents:
diff
changeset
|
172 |
} |