author | zgu |
Wed, 27 Nov 2019 11:52:57 -0500 | |
changeset 59296 | 9186be5c78ba |
permissions | -rw-r--r-- |
59296
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
1 |
/* |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Red Hat, Inc. All rights reserved. |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
3 |
* |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
4 |
* This code is free software; you can redistribute it and/or modify it |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
5 |
* under the terms of the GNU General Public License version 2 only, as |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
6 |
* published by the Free Software Foundation. |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
7 |
* |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
8 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
9 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
10 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
11 |
* version 2 for more details (a copy is included in the LICENSE file that |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
12 |
* accompanied this code). |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
13 |
* |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License version |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
15 |
* 2 along with this work; if not, write to the Free Software Foundation, |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
16 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
17 |
* |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
18 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
19 |
* or visit www.oracle.com if you need additional information or have any |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
20 |
* questions. |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
21 |
* |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
22 |
*/ |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
23 |
|
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
24 |
#ifndef SHARE_GC_SHENANDOAH_SHENANDOAHNMETHOD_INLINE_HPP |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
25 |
#define SHARE_GC_SHENANDOAH_SHENANDOAHNMETHOD_INLINE_HPP |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
26 |
|
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
27 |
#include "gc/shared/barrierSet.hpp" |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
28 |
#include "gc/shared/barrierSetNMethod.hpp" |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
29 |
#include "gc/shenandoah/shenandoahConcurrentRoots.hpp" |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
30 |
#include "gc/shenandoah/shenandoahNMethod.hpp" |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
31 |
|
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
32 |
nmethod* ShenandoahNMethod::nm() const { |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
33 |
return _nm; |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
34 |
} |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
35 |
|
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
36 |
ShenandoahReentrantLock* ShenandoahNMethod::lock() { |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
37 |
return &_lock; |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
38 |
} |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
39 |
|
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
40 |
int ShenandoahNMethod::oop_count() const { |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
41 |
return _oops_count + static_cast<int>(nm()->oops_end() - nm()->oops_begin()); |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
42 |
} |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
43 |
|
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
44 |
bool ShenandoahNMethod::has_oops() const { |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
45 |
return oop_count() > 0; |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
46 |
} |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
47 |
|
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
48 |
void ShenandoahNMethod::mark_unregistered() { |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
49 |
_unregistered = true; |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
50 |
} |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
51 |
|
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
52 |
bool ShenandoahNMethod::is_unregistered() const { |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
53 |
return _unregistered; |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
54 |
} |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
55 |
|
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
56 |
void ShenandoahNMethod::disarm_nmethod(nmethod* nm) { |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
57 |
if (!ShenandoahConcurrentRoots::can_do_concurrent_class_unloading()) { |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
58 |
return; |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
59 |
} |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
60 |
|
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
61 |
BarrierSetNMethod* const bs = BarrierSet::barrier_set()->barrier_set_nmethod(); |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
62 |
assert(bs != NULL, "Sanity"); |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
63 |
bs->disarm(nm); |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
64 |
} |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
65 |
|
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
66 |
ShenandoahNMethod* ShenandoahNMethod::gc_data(nmethod* nm) { |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
67 |
return nm->gc_data<ShenandoahNMethod>(); |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
68 |
} |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
69 |
|
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
70 |
void ShenandoahNMethod::attach_gc_data(nmethod* nm, ShenandoahNMethod* gc_data) { |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
71 |
nm->set_gc_data<ShenandoahNMethod>(gc_data); |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
72 |
} |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
73 |
|
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
74 |
ShenandoahReentrantLock* ShenandoahNMethod::lock_for_nmethod(nmethod* nm) { |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
75 |
return gc_data(nm)->lock(); |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
76 |
} |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
77 |
|
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
78 |
bool ShenandoahNMethodTable::iteration_in_progress() const { |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
79 |
return _iteration_in_progress; |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
80 |
} |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
81 |
|
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
82 |
template<bool CSET_FILTER> |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
83 |
void ShenandoahNMethodTableSnapshot::parallel_blobs_do(CodeBlobClosure *f) { |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
84 |
size_t stride = 256; // educated guess |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
85 |
|
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
86 |
ShenandoahNMethod** const list = _array; |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
87 |
|
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
88 |
size_t max = (size_t)_length; |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
89 |
while (_claimed < max) { |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
90 |
size_t cur = Atomic::add(&_claimed, stride) - stride; |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
91 |
size_t start = cur; |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
92 |
size_t end = MIN2(cur + stride, max); |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
93 |
if (start >= max) break; |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
94 |
|
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
95 |
for (size_t idx = start; idx < end; idx++) { |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
96 |
ShenandoahNMethod* nmr = list[idx]; |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
97 |
assert(nmr != NULL, "Sanity"); |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
98 |
if (nmr->is_unregistered()) { |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
99 |
continue; |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
100 |
} |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
101 |
|
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
102 |
nmr->assert_alive_and_correct(); |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
103 |
|
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
104 |
if (CSET_FILTER && !nmr->has_cset_oops(_heap)) { |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
105 |
continue; |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
106 |
} |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
107 |
|
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
108 |
f->do_code_blob(nmr->nm()); |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
109 |
} |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
110 |
} |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
111 |
} |
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
112 |
|
9186be5c78ba
8228720: Shenandoah: Implementation of concurrent class unloading
zgu
parents:
diff
changeset
|
113 |
#endif // SHARE_GC_SHENANDOAH_SHENANDOAHNMETHOD_INLINE_HPP |