author | stefank |
Wed, 20 Feb 2019 11:39:36 +0100 | |
changeset 53891 | 29273bb37241 |
parent 53890 | 70a6a7b15d36 |
child 53892 | 33790c8e4647 |
permissions | -rw-r--r-- |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
1 |
/* |
53891
29273bb37241
8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents:
53890
diff
changeset
|
2 |
* Copyright (c) 2017, 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 "code/relocInfo.hpp" |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
26 |
#include "code/nmethod.hpp" |
52939 | 27 |
#include "code/icBuffer.hpp" |
28 |
#include "gc/shared/barrierSet.hpp" |
|
29 |
#include "gc/shared/barrierSetNMethod.hpp" |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
30 |
#include "gc/z/zGlobals.hpp" |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
31 |
#include "gc/z/zHash.inline.hpp" |
52939 | 32 |
#include "gc/z/zLock.inline.hpp" |
53891
29273bb37241
8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents:
53890
diff
changeset
|
33 |
#include "gc/z/zNMethodAllocator.hpp" |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
34 |
#include "gc/z/zNMethodTable.hpp" |
52939 | 35 |
#include "gc/z/zOopClosures.inline.hpp" |
36 |
#include "gc/z/zTask.hpp" |
|
37 |
#include "gc/z/zWorkers.hpp" |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
38 |
#include "logging/log.hpp" |
53891
29273bb37241
8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents:
53890
diff
changeset
|
39 |
#include "memory/allocation.hpp" |
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
40 |
#include "memory/iterator.hpp" |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
41 |
#include "memory/resourceArea.hpp" |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
42 |
#include "runtime/atomic.hpp" |
52939 | 43 |
#include "runtime/orderAccess.hpp" |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
44 |
#include "utilities/debug.hpp" |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
45 |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
46 |
class ZNMethodDataOops { |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
47 |
private: |
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
48 |
const size_t _nimmediates; |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
49 |
bool _has_non_immediates; |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
50 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
51 |
static size_t header_size(); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
52 |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
53 |
ZNMethodDataOops(const GrowableArray<oop*>& immediates, bool has_non_immediates); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
54 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
55 |
public: |
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
56 |
static ZNMethodDataOops* create(const GrowableArray<oop*>& immediates, bool has_non_immediates); |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
57 |
static void destroy(ZNMethodDataOops* oops); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
58 |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
59 |
size_t immediates_count() const; |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
60 |
oop** immediates_begin() const; |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
61 |
oop** immediates_end() const; |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
62 |
|
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
63 |
bool has_non_immediates() const; |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
64 |
}; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
65 |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
66 |
size_t ZNMethodDataOops::header_size() { |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
67 |
const size_t size = sizeof(ZNMethodDataOops); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
68 |
assert(is_aligned(size, sizeof(oop*)), "Header misaligned"); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
69 |
return size; |
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 |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
72 |
ZNMethodDataOops* ZNMethodDataOops::create(const GrowableArray<oop*>& immediates, bool has_non_immediates) { |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
73 |
// Allocate memory for the ZNMethodDataOops object |
52939 | 74 |
// plus the immediate oop* array that follows right after. |
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
75 |
const size_t size = ZNMethodDataOops::header_size() + (sizeof(oop*) * immediates.length()); |
53891
29273bb37241
8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents:
53890
diff
changeset
|
76 |
void* const mem = ZNMethodAllocator::allocate(size); |
29273bb37241
8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents:
53890
diff
changeset
|
77 |
return ::new (mem) ZNMethodDataOops(immediates, has_non_immediates); |
52939 | 78 |
} |
79 |
||
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
80 |
void ZNMethodDataOops::destroy(ZNMethodDataOops* oops) { |
53891
29273bb37241
8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents:
53890
diff
changeset
|
81 |
ZNMethodAllocator::free(oops); |
52939 | 82 |
} |
83 |
||
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
84 |
ZNMethodDataOops::ZNMethodDataOops(const GrowableArray<oop*>& immediates, bool has_non_immediates) : |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
85 |
_nimmediates(immediates.length()), |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
86 |
_has_non_immediates(has_non_immediates) { |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
87 |
// Save all immediate oops |
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
88 |
for (size_t i = 0; i < _nimmediates; i++) { |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
89 |
immediates_begin()[i] = immediates.at(i); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
90 |
} |
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 |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
93 |
size_t ZNMethodDataOops::immediates_count() const { |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
94 |
return _nimmediates; |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
95 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
96 |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
97 |
oop** ZNMethodDataOops::immediates_begin() const { |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
98 |
// The immediate oop* array starts immediately after this object |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
99 |
return (oop**)((uintptr_t)this + header_size()); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
100 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
101 |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
102 |
oop** ZNMethodDataOops::immediates_end() const { |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
103 |
return immediates_begin() + immediates_count(); |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
104 |
} |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
105 |
|
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
106 |
bool ZNMethodDataOops::has_non_immediates() const { |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
107 |
return _has_non_immediates; |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
108 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
109 |
|
52939 | 110 |
class ZNMethodData { |
111 |
private: |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
112 |
ZReentrantLock _lock; |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
113 |
ZNMethodDataOops* volatile _oops; |
52939 | 114 |
|
115 |
ZNMethodData(nmethod* nm); |
|
116 |
||
117 |
public: |
|
118 |
static ZNMethodData* create(nmethod* nm); |
|
119 |
static void destroy(ZNMethodData* data); |
|
120 |
||
121 |
ZReentrantLock* lock(); |
|
122 |
||
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
123 |
ZNMethodDataOops* oops() const; |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
124 |
ZNMethodDataOops* swap_oops(ZNMethodDataOops* oops); |
52939 | 125 |
}; |
126 |
||
127 |
ZNMethodData* ZNMethodData::create(nmethod* nm) { |
|
53891
29273bb37241
8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents:
53890
diff
changeset
|
128 |
void* const mem = ZNMethodAllocator::allocate(sizeof(ZNMethodData)); |
29273bb37241
8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents:
53890
diff
changeset
|
129 |
return ::new (mem) ZNMethodData(nm); |
52939 | 130 |
} |
131 |
||
132 |
void ZNMethodData::destroy(ZNMethodData* data) { |
|
53891
29273bb37241
8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents:
53890
diff
changeset
|
133 |
ZNMethodAllocator::free(data->oops()); |
29273bb37241
8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents:
53890
diff
changeset
|
134 |
ZNMethodAllocator::free(data); |
52939 | 135 |
} |
136 |
||
137 |
ZNMethodData::ZNMethodData(nmethod* nm) : |
|
138 |
_lock(), |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
139 |
_oops(NULL) {} |
52939 | 140 |
|
141 |
ZReentrantLock* ZNMethodData::lock() { |
|
142 |
return &_lock; |
|
143 |
} |
|
144 |
||
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
145 |
ZNMethodDataOops* ZNMethodData::oops() const { |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
146 |
return OrderAccess::load_acquire(&_oops); |
52939 | 147 |
} |
148 |
||
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
149 |
ZNMethodDataOops* ZNMethodData::swap_oops(ZNMethodDataOops* new_oops) { |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
150 |
return Atomic::xchg(new_oops, &_oops); |
52939 | 151 |
} |
152 |
||
153 |
static ZNMethodData* gc_data(const nmethod* nm) { |
|
154 |
return nm->gc_data<ZNMethodData>(); |
|
155 |
} |
|
156 |
||
157 |
static void set_gc_data(nmethod* nm, ZNMethodData* data) { |
|
158 |
return nm->set_gc_data<ZNMethodData>(data); |
|
159 |
} |
|
160 |
||
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
161 |
ZNMethodTableEntry* ZNMethodTable::_table = NULL; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
162 |
size_t ZNMethodTable::_size = 0; |
52939 | 163 |
ZNMethodTableEntry* ZNMethodTable::_iter_table = NULL; |
164 |
size_t ZNMethodTable::_iter_table_size = 0; |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
165 |
size_t ZNMethodTable::_nregistered = 0; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
166 |
size_t ZNMethodTable::_nunregistered = 0; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
167 |
volatile size_t ZNMethodTable::_claimed = 0; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
168 |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
169 |
void ZNMethodTable::attach_gc_data(nmethod* nm) { |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
170 |
GrowableArray<oop*> immediate_oops; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
171 |
bool non_immediate_oops = false; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
172 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
173 |
// Find all oops relocations |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
174 |
RelocIterator iter(nm); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
175 |
while (iter.next()) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
176 |
if (iter.type() != relocInfo::oop_type) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
177 |
// Not an oop |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
178 |
continue; |
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 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
181 |
oop_Relocation* r = iter.oop_reloc(); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
182 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
183 |
if (!r->oop_is_immediate()) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
184 |
// Non-immediate oop found |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
185 |
non_immediate_oops = true; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
186 |
continue; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
187 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
188 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
189 |
if (r->oop_value() != NULL) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
190 |
// Non-NULL immediate oop found. NULL oops can safely be |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
191 |
// ignored since the method will be re-registered if they |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
192 |
// are later patched to be non-NULL. |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
193 |
immediate_oops.push(r->oop_addr()); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
194 |
} |
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 |
|
52939 | 197 |
// Attach GC data to nmethod |
198 |
ZNMethodData* data = gc_data(nm); |
|
199 |
if (data == NULL) { |
|
200 |
data = ZNMethodData::create(nm); |
|
201 |
set_gc_data(nm, data); |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
202 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
203 |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
204 |
// Attach oops in GC data |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
205 |
ZNMethodDataOops* const new_oops = ZNMethodDataOops::create(immediate_oops, non_immediate_oops); |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
206 |
ZNMethodDataOops* const old_oops = data->swap_oops(new_oops); |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
207 |
ZNMethodDataOops::destroy(old_oops); |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
208 |
} |
52939 | 209 |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
210 |
void ZNMethodTable::detach_gc_data(nmethod* nm) { |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
211 |
// Destroy GC data |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
212 |
ZNMethodData::destroy(gc_data(nm)); |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
213 |
set_gc_data(nm, NULL); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
214 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
215 |
|
52939 | 216 |
ZReentrantLock* ZNMethodTable::lock_for_nmethod(nmethod* nm) { |
217 |
ZNMethodData* const data = gc_data(nm); |
|
218 |
if (data == NULL) { |
|
219 |
return NULL; |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
220 |
} |
52939 | 221 |
return data->lock(); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
222 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
223 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
224 |
size_t ZNMethodTable::first_index(const nmethod* nm, size_t size) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
225 |
assert(is_power_of_2(size), "Invalid size"); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
226 |
const size_t mask = size - 1; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
227 |
const size_t hash = ZHash::address_to_uint32((uintptr_t)nm); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
228 |
return hash & mask; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
229 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
230 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
231 |
size_t ZNMethodTable::next_index(size_t prev_index, size_t size) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
232 |
assert(is_power_of_2(size), "Invalid size"); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
233 |
const size_t mask = size - 1; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
234 |
return (prev_index + 1) & mask; |
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 |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
237 |
bool ZNMethodTable::register_entry(ZNMethodTableEntry* table, size_t size, nmethod* nm) { |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
238 |
const ZNMethodTableEntry entry(nm); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
239 |
size_t index = first_index(nm, size); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
240 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
241 |
for (;;) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
242 |
const ZNMethodTableEntry table_entry = table[index]; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
243 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
244 |
if (!table_entry.registered() && !table_entry.unregistered()) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
245 |
// Insert new entry |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
246 |
table[index] = entry; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
247 |
return true; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
248 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
249 |
|
52939 | 250 |
if (table_entry.registered() && table_entry.method() == nm) { |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
251 |
// Replace existing entry |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
252 |
table[index] = entry; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
253 |
return false; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
254 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
255 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
256 |
index = next_index(index, size); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
257 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
258 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
259 |
|
53500 | 260 |
void ZNMethodTable::unregister_entry(ZNMethodTableEntry* table, size_t size, nmethod* nm) { |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
261 |
size_t index = first_index(nm, size); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
262 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
263 |
for (;;) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
264 |
const ZNMethodTableEntry table_entry = table[index]; |
53500 | 265 |
assert(table_entry.registered() || table_entry.unregistered(), "Entry not found"); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
266 |
|
52939 | 267 |
if (table_entry.registered() && table_entry.method() == nm) { |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
268 |
// Remove entry |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
269 |
table[index] = ZNMethodTableEntry(true /* unregistered */); |
53500 | 270 |
return; |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
271 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
272 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
273 |
index = next_index(index, size); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
274 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
275 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
276 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
277 |
void ZNMethodTable::rebuild(size_t new_size) { |
53888
a858ad440eb9
8219463: ZGC: Remove redundant ZNMethodTable::_iter_lock
stefank
parents:
53887
diff
changeset
|
278 |
assert(CodeCache_lock->owned_by_self(), "Lock must be held"); |
a858ad440eb9
8219463: ZGC: Remove redundant ZNMethodTable::_iter_lock
stefank
parents:
53887
diff
changeset
|
279 |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
280 |
assert(is_power_of_2(new_size), "Invalid size"); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
281 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
282 |
log_debug(gc, nmethod)("Rebuilding NMethod Table: " |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
283 |
SIZE_FORMAT "->" SIZE_FORMAT " entries, " |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
284 |
SIZE_FORMAT "(%.0lf%%->%.0lf%%) registered, " |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
285 |
SIZE_FORMAT "(%.0lf%%->%.0lf%%) unregistered", |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
286 |
_size, new_size, |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
287 |
_nregistered, percent_of(_nregistered, _size), percent_of(_nregistered, new_size), |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
288 |
_nunregistered, percent_of(_nunregistered, _size), 0.0); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
289 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
290 |
// Allocate new table |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
291 |
ZNMethodTableEntry* const new_table = new ZNMethodTableEntry[new_size]; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
292 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
293 |
// Transfer all registered entries |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
294 |
for (size_t i = 0; i < _size; i++) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
295 |
const ZNMethodTableEntry entry = _table[i]; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
296 |
if (entry.registered()) { |
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
297 |
register_entry(new_table, new_size, entry.method()); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
298 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
299 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
300 |
|
52939 | 301 |
if (_iter_table != _table) { |
302 |
// Delete old table |
|
303 |
delete [] _table; |
|
304 |
} |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
305 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
306 |
// Install new table |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
307 |
_table = new_table; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
308 |
_size = new_size; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
309 |
_nunregistered = 0; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
310 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
311 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
312 |
void ZNMethodTable::rebuild_if_needed() { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
313 |
// The hash table uses linear probing. To avoid wasting memory while |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
314 |
// at the same time maintaining good hash collision behavior we want |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
315 |
// to keep the table occupancy between 30% and 70%. The table always |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
316 |
// grows/shrinks by doubling/halving its size. Pruning of unregistered |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
317 |
// entries is done by rebuilding the table with or without resizing it. |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
318 |
const size_t min_size = 1024; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
319 |
const size_t shrink_threshold = _size * 0.30; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
320 |
const size_t prune_threshold = _size * 0.65; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
321 |
const size_t grow_threshold = _size * 0.70; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
322 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
323 |
if (_size == 0) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
324 |
// Initialize table |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
325 |
rebuild(min_size); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
326 |
} else if (_nregistered < shrink_threshold && _size > min_size) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
327 |
// Shrink table |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
328 |
rebuild(_size / 2); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
329 |
} else if (_nregistered + _nunregistered > grow_threshold) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
330 |
// Prune or grow table |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
331 |
if (_nregistered < prune_threshold) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
332 |
// Prune table |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
333 |
rebuild(_size); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
334 |
} else { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
335 |
// Grow table |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
336 |
rebuild(_size * 2); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
337 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
338 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
339 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
340 |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
341 |
void ZNMethodTable::log_register(const nmethod* nm) { |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
342 |
LogTarget(Trace, gc, nmethod) log; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
343 |
if (!log.is_enabled()) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
344 |
return; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
345 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
346 |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
347 |
const ZNMethodDataOops* const oops = gc_data(nm)->oops(); |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
348 |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
349 |
log.print("Register NMethod: %s.%s (" PTR_FORMAT "), " |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
350 |
"Compiler: %s, Oops: %d, ImmediateOops: " SIZE_FORMAT ", NonImmediateOops: %s", |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
351 |
nm->method()->method_holder()->external_name(), |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
352 |
nm->method()->name()->as_C_string(), |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
353 |
p2i(nm), |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
354 |
nm->compiler_name(), |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
355 |
nm->oops_count() - 1, |
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
356 |
oops->immediates_count(), |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
357 |
oops->has_non_immediates() ? "Yes" : "No"); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
358 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
359 |
LogTarget(Trace, gc, nmethod, oops) log_oops; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
360 |
if (!log_oops.is_enabled()) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
361 |
return; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
362 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
363 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
364 |
// Print nmethod oops table |
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
365 |
{ |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
366 |
oop* const begin = nm->oops_begin(); |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
367 |
oop* const end = nm->oops_end(); |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
368 |
for (oop* p = begin; p < end; p++) { |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
369 |
log_oops.print(" Oop[" SIZE_FORMAT "] " PTR_FORMAT " (%s)", |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
370 |
(p - begin), p2i(*p), (*p)->klass()->external_name()); |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
371 |
} |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
372 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
373 |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
374 |
// Print nmethod immediate oops |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
375 |
{ |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
376 |
oop** const begin = oops->immediates_begin(); |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
377 |
oop** const end = oops->immediates_end(); |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
378 |
for (oop** p = begin; p < end; p++) { |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
379 |
log_oops.print(" ImmediateOop[" SIZE_FORMAT "] " PTR_FORMAT " @ " PTR_FORMAT " (%s)", |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
380 |
(p - begin), p2i(**p), p2i(*p), (**p)->klass()->external_name()); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
381 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
382 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
383 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
384 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
385 |
void ZNMethodTable::log_unregister(const nmethod* nm) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
386 |
LogTarget(Debug, gc, nmethod) log; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
387 |
if (!log.is_enabled()) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
388 |
return; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
389 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
390 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
391 |
log.print("Unregister NMethod: %s.%s (" PTR_FORMAT ")", |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
392 |
nm->method()->method_holder()->external_name(), |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
393 |
nm->method()->name()->as_C_string(), |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
394 |
p2i(nm)); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
395 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
396 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
397 |
size_t ZNMethodTable::registered_nmethods() { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
398 |
return _nregistered; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
399 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
400 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
401 |
size_t ZNMethodTable::unregistered_nmethods() { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
402 |
return _nunregistered; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
403 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
404 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
405 |
void ZNMethodTable::register_nmethod(nmethod* nm) { |
52939 | 406 |
assert(CodeCache_lock->owned_by_self(), "Lock must be held"); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
407 |
ResourceMark rm; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
408 |
|
52939 | 409 |
// Grow/Shrink/Prune table if needed |
410 |
rebuild_if_needed(); |
|
411 |
||
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
412 |
// Create and attach gc data |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
413 |
attach_gc_data(nm); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
414 |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
415 |
log_register(nm); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
416 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
417 |
// Insert new entry |
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
418 |
if (register_entry(_table, _size, nm)) { |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
419 |
// New entry registered. When register_entry() instead returns |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
420 |
// false the nmethod was already in the table so we do not want |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
421 |
// to increase number of registered entries in that case. |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
422 |
_nregistered++; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
423 |
} |
52939 | 424 |
|
425 |
// Disarm nmethod entry barrier |
|
426 |
disarm_nmethod(nm); |
|
427 |
} |
|
428 |
||
53887 | 429 |
void ZNMethodTable::wait_until_iteration_done() { |
430 |
assert(CodeCache_lock->owned_by_self(), "Lock must be held"); |
|
52939 | 431 |
|
432 |
while (_iter_table != NULL) { |
|
53887 | 433 |
CodeCache_lock->wait(Monitor::_no_safepoint_check_flag); |
52939 | 434 |
} |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
435 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
436 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
437 |
void ZNMethodTable::unregister_nmethod(nmethod* nm) { |
53500 | 438 |
assert(CodeCache_lock->owned_by_self(), "Lock must be held"); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
439 |
|
53887 | 440 |
if (Thread::current()->is_Code_cache_sweeper_thread()) { |
441 |
// The sweeper must wait for any ongoing iteration to complete |
|
442 |
// before it can unregister an nmethod. |
|
443 |
ZNMethodTable::wait_until_iteration_done(); |
|
444 |
} |
|
445 |
||
446 |
ResourceMark rm; |
|
52939 | 447 |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
448 |
log_unregister(nm); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
449 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
450 |
// Remove entry |
53500 | 451 |
unregister_entry(_table, _size, nm); |
452 |
_nunregistered++; |
|
453 |
_nregistered--; |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
454 |
|
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
455 |
detach_gc_data(nm); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
456 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
457 |
|
52939 | 458 |
void ZNMethodTable::disarm_nmethod(nmethod* nm) { |
459 |
BarrierSetNMethod* const bs = BarrierSet::barrier_set()->barrier_set_nmethod(); |
|
460 |
if (bs != NULL) { |
|
461 |
bs->disarm(nm); |
|
462 |
} |
|
463 |
} |
|
464 |
||
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
465 |
void ZNMethodTable::nmethods_do_begin() { |
52939 | 466 |
MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
467 |
||
53891
29273bb37241
8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents:
53890
diff
changeset
|
468 |
// Make sure we don't free data while iterating |
29273bb37241
8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents:
53890
diff
changeset
|
469 |
ZNMethodAllocator::activate_deferred_frees(); |
29273bb37241
8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents:
53890
diff
changeset
|
470 |
|
52939 | 471 |
// Prepare iteration |
472 |
_iter_table = _table; |
|
473 |
_iter_table_size = _size; |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
474 |
_claimed = 0; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
475 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
476 |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
477 |
void ZNMethodTable::nmethods_do_end() { |
52939 | 478 |
MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
479 |
||
480 |
// Finish iteration |
|
481 |
if (_iter_table != _table) { |
|
482 |
delete [] _iter_table; |
|
483 |
} |
|
484 |
_iter_table = NULL; |
|
53887 | 485 |
|
52939 | 486 |
assert(_claimed >= _iter_table_size, "Failed to claim all table entries"); |
487 |
||
53891
29273bb37241
8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents:
53890
diff
changeset
|
488 |
// Process deferred frees |
29273bb37241
8219466: ZGC: Extract allocation functionality into a new ZNMethodAllocator class
stefank
parents:
53890
diff
changeset
|
489 |
ZNMethodAllocator::deactivate_and_process_deferred_frees(); |
53887 | 490 |
|
491 |
// Notify iteration done |
|
492 |
CodeCache_lock->notify_all(); |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
493 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
494 |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
495 |
void ZNMethodTable::oops_do(nmethod* nm, OopClosure* cl) { |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
496 |
// Process oops table |
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
497 |
{ |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
498 |
oop* const begin = nm->oops_begin(); |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
499 |
oop* const end = nm->oops_end(); |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
500 |
for (oop* p = begin; p < end; p++) { |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
501 |
if (*p != Universe::non_oop_word()) { |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
502 |
cl->do_oop(p); |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
503 |
} |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
504 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
505 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
506 |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
507 |
ZNMethodDataOops* const oops = gc_data(nm)->oops(); |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
508 |
|
52939 | 509 |
// Process immediate oops |
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
510 |
{ |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
511 |
oop** const begin = oops->immediates_begin(); |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
512 |
oop** const end = oops->immediates_end(); |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
513 |
for (oop** p = begin; p < end; p++) { |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
514 |
if (**p != Universe::non_oop_word()) { |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
515 |
cl->do_oop(*p); |
52939 | 516 |
} |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
517 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
518 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
519 |
|
52939 | 520 |
// Process non-immediate oops |
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
521 |
if (oops->has_non_immediates()) { |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
522 |
nm->fix_oop_relocations(); |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
523 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
524 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
525 |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
526 |
class ZNMethodToOopsDoClosure : public NMethodClosure { |
52939 | 527 |
private: |
528 |
OopClosure* _cl; |
|
529 |
||
530 |
public: |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
531 |
ZNMethodToOopsDoClosure(OopClosure* cl) : |
52939 | 532 |
_cl(cl) {} |
533 |
||
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
534 |
virtual void do_nmethod(nmethod* nm) { |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
535 |
ZNMethodTable::oops_do(nm, _cl); |
52939 | 536 |
} |
537 |
}; |
|
538 |
||
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
539 |
void ZNMethodTable::oops_do(OopClosure* cl) { |
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
540 |
ZNMethodToOopsDoClosure nm_cl(cl); |
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
541 |
nmethods_do(&nm_cl); |
52939 | 542 |
} |
543 |
||
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
544 |
void ZNMethodTable::nmethods_do(NMethodClosure* cl) { |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
545 |
for (;;) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
546 |
// Claim table partition. Each partition is currently sized to span |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
547 |
// two cache lines. This number is just a guess, but seems to work well. |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
548 |
const size_t partition_size = (ZCacheLineSize * 2) / sizeof(ZNMethodTableEntry); |
52939 | 549 |
const size_t partition_start = MIN2(Atomic::add(partition_size, &_claimed) - partition_size, _iter_table_size); |
550 |
const size_t partition_end = MIN2(partition_start + partition_size, _iter_table_size); |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
551 |
if (partition_start == partition_end) { |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
552 |
// End of table |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
553 |
break; |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
554 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
555 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
556 |
// Process table partition |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
557 |
for (size_t i = partition_start; i < partition_end; i++) { |
52939 | 558 |
const ZNMethodTableEntry entry = _iter_table[i]; |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
559 |
if (entry.registered()) { |
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
560 |
cl->do_nmethod(entry.method()); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
561 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
562 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
563 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
564 |
} |
52939 | 565 |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
566 |
class ZNMethodTableUnlinkClosure : public NMethodClosure { |
52939 | 567 |
private: |
568 |
bool _unloading_occurred; |
|
569 |
volatile bool _failed; |
|
570 |
||
571 |
void set_failed() { |
|
572 |
Atomic::store(true, &_failed); |
|
573 |
} |
|
574 |
||
575 |
public: |
|
576 |
ZNMethodTableUnlinkClosure(bool unloading_occurred) : |
|
577 |
_unloading_occurred(unloading_occurred), |
|
578 |
_failed(false) {} |
|
579 |
||
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
580 |
virtual void do_nmethod(nmethod* nm) { |
52939 | 581 |
if (failed()) { |
582 |
return; |
|
583 |
} |
|
584 |
||
585 |
if (!nm->is_alive()) { |
|
586 |
return; |
|
587 |
} |
|
588 |
||
53282
cb7fff9105a8
8215754: ZGC: nmethod is not unlinked from Method before rendezvous handshake
eosterlund
parents:
52939
diff
changeset
|
589 |
ZLocker<ZReentrantLock> locker(ZNMethodTable::lock_for_nmethod(nm)); |
cb7fff9105a8
8215754: ZGC: nmethod is not unlinked from Method before rendezvous handshake
eosterlund
parents:
52939
diff
changeset
|
590 |
|
52939 | 591 |
if (nm->is_unloading()) { |
592 |
// Unlinking of the dependencies must happen before the |
|
593 |
// handshake separating unlink and purge. |
|
594 |
nm->flush_dependencies(false /* delete_immediately */); |
|
53282
cb7fff9105a8
8215754: ZGC: nmethod is not unlinked from Method before rendezvous handshake
eosterlund
parents:
52939
diff
changeset
|
595 |
|
cb7fff9105a8
8215754: ZGC: nmethod is not unlinked from Method before rendezvous handshake
eosterlund
parents:
52939
diff
changeset
|
596 |
// We don't need to take the lock when unlinking nmethods from |
cb7fff9105a8
8215754: ZGC: nmethod is not unlinked from Method before rendezvous handshake
eosterlund
parents:
52939
diff
changeset
|
597 |
// the Method, because it is only concurrently unlinked by |
cb7fff9105a8
8215754: ZGC: nmethod is not unlinked from Method before rendezvous handshake
eosterlund
parents:
52939
diff
changeset
|
598 |
// the entry barrier, which acquires the per nmethod lock. |
cb7fff9105a8
8215754: ZGC: nmethod is not unlinked from Method before rendezvous handshake
eosterlund
parents:
52939
diff
changeset
|
599 |
nm->unlink_from_method(false /* acquire_lock */); |
52939 | 600 |
return; |
601 |
} |
|
602 |
||
603 |
// Heal oops and disarm |
|
604 |
ZNMethodOopClosure cl; |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
605 |
ZNMethodTable::oops_do(nm, &cl); |
52939 | 606 |
ZNMethodTable::disarm_nmethod(nm); |
607 |
||
608 |
// Clear compiled ICs and exception caches |
|
609 |
if (!nm->unload_nmethod_caches(_unloading_occurred)) { |
|
610 |
set_failed(); |
|
611 |
} |
|
612 |
} |
|
613 |
||
614 |
bool failed() const { |
|
615 |
return Atomic::load(&_failed); |
|
616 |
} |
|
617 |
}; |
|
618 |
||
619 |
class ZNMethodTableUnlinkTask : public ZTask { |
|
620 |
private: |
|
621 |
ZNMethodTableUnlinkClosure _cl; |
|
622 |
ICRefillVerifier* _verifier; |
|
623 |
||
624 |
public: |
|
625 |
ZNMethodTableUnlinkTask(bool unloading_occurred, ICRefillVerifier* verifier) : |
|
626 |
ZTask("ZNMethodTableUnlinkTask"), |
|
627 |
_cl(unloading_occurred), |
|
628 |
_verifier(verifier) { |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
629 |
ZNMethodTable::nmethods_do_begin(); |
52939 | 630 |
} |
631 |
||
632 |
~ZNMethodTableUnlinkTask() { |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
633 |
ZNMethodTable::nmethods_do_end(); |
52939 | 634 |
} |
635 |
||
636 |
virtual void work() { |
|
637 |
ICRefillVerifierMark mark(_verifier); |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
638 |
ZNMethodTable::nmethods_do(&_cl); |
52939 | 639 |
} |
640 |
||
641 |
bool success() const { |
|
642 |
return !_cl.failed(); |
|
643 |
} |
|
644 |
}; |
|
645 |
||
646 |
void ZNMethodTable::unlink(ZWorkers* workers, bool unloading_occurred) { |
|
647 |
for (;;) { |
|
648 |
ICRefillVerifier verifier; |
|
649 |
||
650 |
{ |
|
651 |
ZNMethodTableUnlinkTask task(unloading_occurred, &verifier); |
|
652 |
workers->run_concurrent(&task); |
|
653 |
if (task.success()) { |
|
654 |
return; |
|
655 |
} |
|
656 |
} |
|
657 |
||
658 |
// Cleaning failed because we ran out of transitional IC stubs, |
|
659 |
// so we have to refill and try again. Refilling requires taking |
|
660 |
// a safepoint, so we temporarily leave the suspendible thread set. |
|
661 |
SuspendibleThreadSetLeaver sts; |
|
662 |
InlineCacheBuffer::refill_ic_stubs(); |
|
663 |
} |
|
664 |
} |
|
665 |
||
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
666 |
class ZNMethodTablePurgeClosure : public NMethodClosure { |
52939 | 667 |
public: |
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
668 |
virtual void do_nmethod(nmethod* nm) { |
52939 | 669 |
if (nm->is_alive() && nm->is_unloading()) { |
670 |
nm->make_unloaded(); |
|
671 |
} |
|
672 |
} |
|
673 |
}; |
|
674 |
||
675 |
class ZNMethodTablePurgeTask : public ZTask { |
|
676 |
private: |
|
677 |
ZNMethodTablePurgeClosure _cl; |
|
678 |
||
679 |
public: |
|
680 |
ZNMethodTablePurgeTask() : |
|
681 |
ZTask("ZNMethodTablePurgeTask"), |
|
682 |
_cl() { |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
683 |
ZNMethodTable::nmethods_do_begin(); |
52939 | 684 |
} |
685 |
||
686 |
~ZNMethodTablePurgeTask() { |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
687 |
ZNMethodTable::nmethods_do_end(); |
52939 | 688 |
} |
689 |
||
690 |
virtual void work() { |
|
53890
70a6a7b15d36
8219464: ZGC: Move nmethod oop properties from ZNMethodTableEntry to ZNMethodData
stefank
parents:
53888
diff
changeset
|
691 |
ZNMethodTable::nmethods_do(&_cl); |
52939 | 692 |
} |
693 |
}; |
|
694 |
||
695 |
void ZNMethodTable::purge(ZWorkers* workers) { |
|
696 |
ZNMethodTablePurgeTask task; |
|
697 |
workers->run_concurrent(&task); |
|
698 |
} |