author | stefank |
Wed, 27 Nov 2019 11:31:46 +0100 | |
changeset 59292 | 95b1385dd476 |
parent 59040 | 1251d78fafbf |
permissions | -rw-r--r-- |
52939 | 1 |
/* |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54567
diff
changeset
|
2 |
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
52939 | 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 "precompiled.hpp" |
|
25 |
#include "classfile/classLoaderDataGraph.hpp" |
|
26 |
#include "classfile/systemDictionary.hpp" |
|
27 |
#include "code/codeBehaviours.hpp" |
|
28 |
#include "code/codeCache.hpp" |
|
29 |
#include "code/dependencyContext.hpp" |
|
30 |
#include "gc/shared/gcBehaviours.hpp" |
|
31 |
#include "gc/shared/suspendibleThreadSet.hpp" |
|
32 |
#include "gc/z/zLock.inline.hpp" |
|
53894
bf1133e7dfba
8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
52939
diff
changeset
|
33 |
#include "gc/z/zNMethod.hpp" |
52939 | 34 |
#include "gc/z/zOopClosures.hpp" |
35 |
#include "gc/z/zStat.hpp" |
|
36 |
#include "gc/z/zUnload.hpp" |
|
37 |
#include "oops/access.inline.hpp" |
|
38 |
||
59040
1251d78fafbf
8230661: ZGC: Stop reloading oops in load barriers
eosterlund
parents:
54623
diff
changeset
|
39 |
static const ZStatSubPhase ZSubPhaseConcurrentClassesUnlink("Concurrent Classes Unlink"); |
1251d78fafbf
8230661: ZGC: Stop reloading oops in load barriers
eosterlund
parents:
54623
diff
changeset
|
40 |
static const ZStatSubPhase ZSubPhaseConcurrentClassesPurge("Concurrent Classes Purge"); |
52939 | 41 |
|
42 |
class ZIsUnloadingOopClosure : public OopClosure { |
|
43 |
private: |
|
44 |
ZPhantomIsAliveObjectClosure _is_alive; |
|
45 |
bool _is_unloading; |
|
46 |
||
47 |
public: |
|
48 |
ZIsUnloadingOopClosure() : |
|
49 |
_is_alive(), |
|
50 |
_is_unloading(false) {} |
|
51 |
||
52 |
virtual void do_oop(oop* p) { |
|
53 |
const oop o = RawAccess<>::oop_load(p); |
|
54 |
if (o != NULL && !_is_alive.do_object_b(o)) { |
|
55 |
_is_unloading = true; |
|
56 |
} |
|
57 |
} |
|
58 |
||
59 |
virtual void do_oop(narrowOop* p) { |
|
60 |
ShouldNotReachHere(); |
|
61 |
} |
|
62 |
||
63 |
bool is_unloading() const { |
|
64 |
return _is_unloading; |
|
65 |
} |
|
66 |
}; |
|
67 |
||
68 |
class ZIsUnloadingBehaviour : public IsUnloadingBehaviour { |
|
69 |
public: |
|
70 |
virtual bool is_unloading(CompiledMethod* method) const { |
|
71 |
nmethod* const nm = method->as_nmethod(); |
|
53894
bf1133e7dfba
8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
52939
diff
changeset
|
72 |
ZReentrantLock* const lock = ZNMethod::lock_for_nmethod(nm); |
53921
a590b6107ab3
8218974: Free GC native structures in nmethod::flush
eosterlund
parents:
53894
diff
changeset
|
73 |
ZLocker<ZReentrantLock> locker(lock); |
a590b6107ab3
8218974: Free GC native structures in nmethod::flush
eosterlund
parents:
53894
diff
changeset
|
74 |
ZIsUnloadingOopClosure cl; |
54567
224515275cf9
8219718: ZGC: Make nmethod entry barriers and nmethod::is_unloading use ZNMethodDataOops
eosterlund
parents:
53921
diff
changeset
|
75 |
ZNMethod::nmethod_oops_do(nm, &cl); |
53921
a590b6107ab3
8218974: Free GC native structures in nmethod::flush
eosterlund
parents:
53894
diff
changeset
|
76 |
return cl.is_unloading(); |
52939 | 77 |
} |
78 |
}; |
|
79 |
||
80 |
class ZCompiledICProtectionBehaviour : public CompiledICProtectionBehaviour { |
|
81 |
public: |
|
82 |
virtual bool lock(CompiledMethod* method) { |
|
83 |
nmethod* const nm = method->as_nmethod(); |
|
53894
bf1133e7dfba
8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
52939
diff
changeset
|
84 |
ZReentrantLock* const lock = ZNMethod::lock_for_nmethod(nm); |
53921
a590b6107ab3
8218974: Free GC native structures in nmethod::flush
eosterlund
parents:
53894
diff
changeset
|
85 |
lock->lock(); |
52939 | 86 |
return true; |
87 |
} |
|
88 |
||
89 |
virtual void unlock(CompiledMethod* method) { |
|
90 |
nmethod* const nm = method->as_nmethod(); |
|
53894
bf1133e7dfba
8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
52939
diff
changeset
|
91 |
ZReentrantLock* const lock = ZNMethod::lock_for_nmethod(nm); |
53921
a590b6107ab3
8218974: Free GC native structures in nmethod::flush
eosterlund
parents:
53894
diff
changeset
|
92 |
lock->unlock(); |
52939 | 93 |
} |
94 |
||
95 |
virtual bool is_safe(CompiledMethod* method) { |
|
96 |
if (SafepointSynchronize::is_at_safepoint()) { |
|
97 |
return true; |
|
98 |
} |
|
99 |
||
100 |
nmethod* const nm = method->as_nmethod(); |
|
53894
bf1133e7dfba
8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
52939
diff
changeset
|
101 |
ZReentrantLock* const lock = ZNMethod::lock_for_nmethod(nm); |
53921
a590b6107ab3
8218974: Free GC native structures in nmethod::flush
eosterlund
parents:
53894
diff
changeset
|
102 |
return lock->is_owned(); |
52939 | 103 |
} |
104 |
}; |
|
105 |
||
106 |
ZUnload::ZUnload(ZWorkers* workers) : |
|
107 |
_workers(workers) { |
|
108 |
||
109 |
if (!ClassUnloading) { |
|
110 |
return; |
|
111 |
} |
|
112 |
||
113 |
static ZIsUnloadingBehaviour is_unloading_behaviour; |
|
114 |
IsUnloadingBehaviour::set_current(&is_unloading_behaviour); |
|
115 |
||
116 |
static ZCompiledICProtectionBehaviour ic_protection_behaviour; |
|
117 |
CompiledICProtectionBehaviour::set_current(&ic_protection_behaviour); |
|
118 |
} |
|
119 |
||
120 |
void ZUnload::prepare() { |
|
121 |
if (!ClassUnloading) { |
|
122 |
return; |
|
123 |
} |
|
124 |
||
125 |
CodeCache::increment_unloading_cycle(); |
|
126 |
DependencyContext::cleaning_start(); |
|
127 |
} |
|
128 |
||
129 |
void ZUnload::unlink() { |
|
59040
1251d78fafbf
8230661: ZGC: Stop reloading oops in load barriers
eosterlund
parents:
54623
diff
changeset
|
130 |
if (!ClassUnloading) { |
1251d78fafbf
8230661: ZGC: Stop reloading oops in load barriers
eosterlund
parents:
54623
diff
changeset
|
131 |
return; |
1251d78fafbf
8230661: ZGC: Stop reloading oops in load barriers
eosterlund
parents:
54623
diff
changeset
|
132 |
} |
1251d78fafbf
8230661: ZGC: Stop reloading oops in load barriers
eosterlund
parents:
54623
diff
changeset
|
133 |
|
1251d78fafbf
8230661: ZGC: Stop reloading oops in load barriers
eosterlund
parents:
54623
diff
changeset
|
134 |
ZStatTimer timer(ZSubPhaseConcurrentClassesUnlink); |
52939 | 135 |
SuspendibleThreadSetJoiner sts; |
136 |
bool unloading_occurred; |
|
137 |
||
138 |
{ |
|
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54567
diff
changeset
|
139 |
MutexLocker ml(ClassLoaderDataGraph_lock); |
52939 | 140 |
unloading_occurred = SystemDictionary::do_unloading(ZStatPhase::timer()); |
141 |
} |
|
142 |
||
143 |
Klass::clean_weak_klass_links(unloading_occurred); |
|
53894
bf1133e7dfba
8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
52939
diff
changeset
|
144 |
ZNMethod::unlink(_workers, unloading_occurred); |
52939 | 145 |
DependencyContext::cleaning_end(); |
146 |
} |
|
147 |
||
148 |
void ZUnload::purge() { |
|
59040
1251d78fafbf
8230661: ZGC: Stop reloading oops in load barriers
eosterlund
parents:
54623
diff
changeset
|
149 |
if (!ClassUnloading) { |
1251d78fafbf
8230661: ZGC: Stop reloading oops in load barriers
eosterlund
parents:
54623
diff
changeset
|
150 |
return; |
1251d78fafbf
8230661: ZGC: Stop reloading oops in load barriers
eosterlund
parents:
54623
diff
changeset
|
151 |
} |
1251d78fafbf
8230661: ZGC: Stop reloading oops in load barriers
eosterlund
parents:
54623
diff
changeset
|
152 |
|
1251d78fafbf
8230661: ZGC: Stop reloading oops in load barriers
eosterlund
parents:
54623
diff
changeset
|
153 |
ZStatTimer timer(ZSubPhaseConcurrentClassesPurge); |
1251d78fafbf
8230661: ZGC: Stop reloading oops in load barriers
eosterlund
parents:
54623
diff
changeset
|
154 |
|
52939 | 155 |
{ |
156 |
SuspendibleThreadSetJoiner sts; |
|
53894
bf1133e7dfba
8219469: ZGC: Extract functions out from ZNMethodTable into new ZNMethod class
stefank
parents:
52939
diff
changeset
|
157 |
ZNMethod::purge(_workers); |
52939 | 158 |
} |
159 |
||
160 |
ClassLoaderDataGraph::purge(); |
|
161 |
CodeCache::purge_exception_caches(); |
|
162 |
} |
|
163 |
||
164 |
void ZUnload::finish() { |
|
165 |
// Resize and verify metaspace |
|
166 |
MetaspaceGC::compute_new_size(); |
|
167 |
MetaspaceUtils::verify_metrics(); |
|
168 |
} |