author | stefank |
Mon, 04 Apr 2016 09:15:15 +0200 | |
changeset 37242 | 91e5f98fff6f |
parent 37202 | 4100f25e4b09 |
child 38151 | fffedc5e5cf8 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
2 |
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5402
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5402
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5402
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
26 |
#include "classfile/classLoaderData.inline.hpp" |
7397 | 27 |
#include "classfile/loaderConstraints.hpp" |
28 |
#include "memory/resourceArea.hpp" |
|
29 |
#include "oops/oop.inline.hpp" |
|
30 |
#include "runtime/handles.inline.hpp" |
|
31 |
#include "runtime/safepoint.hpp" |
|
32 |
#include "utilities/hashtable.inline.hpp" |
|
1 | 33 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
34 |
void LoaderConstraintEntry::set_loader(int i, oop p) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
35 |
set_loader_data(i, ClassLoaderData::class_loader_data(p)); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
36 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
37 |
|
1 | 38 |
LoaderConstraintTable::LoaderConstraintTable(int nof_buckets) |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
39 |
: Hashtable<Klass*, mtClass>(nof_buckets, sizeof(LoaderConstraintEntry)) {}; |
1 | 40 |
|
41 |
||
42 |
LoaderConstraintEntry* LoaderConstraintTable::new_entry( |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
43 |
unsigned int hash, Symbol* name, |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
44 |
Klass* klass, int num_loaders, |
1 | 45 |
int max_loaders) { |
46 |
LoaderConstraintEntry* entry; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
47 |
entry = (LoaderConstraintEntry*)Hashtable<Klass*, mtClass>::new_entry(hash, klass); |
1 | 48 |
entry->set_name(name); |
49 |
entry->set_num_loaders(num_loaders); |
|
50 |
entry->set_max_loaders(max_loaders); |
|
51 |
return entry; |
|
52 |
} |
|
53 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
54 |
void LoaderConstraintTable::free_entry(LoaderConstraintEntry *entry) { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
55 |
// decrement name refcount before freeing |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
56 |
entry->name()->decrement_refcount(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
57 |
Hashtable<Klass*, mtClass>::free_entry(entry); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
58 |
} |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
59 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
60 |
// Enhanced Class Redefinition support |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
61 |
void LoaderConstraintTable::classes_do(KlassClosure* f) { |
1 | 62 |
for (int index = 0; index < table_size(); index++) { |
63 |
for (LoaderConstraintEntry* probe = bucket(index); |
|
64 |
probe != NULL; |
|
65 |
probe = probe->next()) { |
|
66 |
if (probe->klass() != NULL) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
67 |
f->do_klass(probe->klass()); |
1 | 68 |
} |
69 |
} |
|
70 |
} |
|
71 |
} |
|
72 |
||
73 |
// The loaderConstraintTable must always be accessed with the |
|
74 |
// SystemDictionary lock held. This is true even for readers as |
|
75 |
// entries in the table could be being dynamically resized. |
|
76 |
||
77 |
LoaderConstraintEntry** LoaderConstraintTable::find_loader_constraint( |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
78 |
Symbol* name, Handle loader) { |
1 | 79 |
|
80 |
unsigned int hash = compute_hash(name); |
|
81 |
int index = hash_to_index(hash); |
|
82 |
LoaderConstraintEntry** pp = bucket_addr(index); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
83 |
ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(loader()); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
84 |
|
1 | 85 |
while (*pp) { |
86 |
LoaderConstraintEntry* p = *pp; |
|
87 |
if (p->hash() == hash) { |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
88 |
if (p->name() == name) { |
1 | 89 |
for (int i = p->num_loaders() - 1; i >= 0; i--) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
90 |
if (p->loader_data(i) == loader_data) { |
1 | 91 |
return pp; |
92 |
} |
|
93 |
} |
|
94 |
} |
|
95 |
} |
|
96 |
pp = p->next_addr(); |
|
97 |
} |
|
98 |
return pp; |
|
99 |
} |
|
100 |
||
101 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
102 |
void LoaderConstraintTable::purge_loader_constraints() { |
5402
c51fd0c1d005
6888953: some calls to function-like macros are missing semicolons
jcoomes
parents:
5124
diff
changeset
|
103 |
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
1 | 104 |
// Remove unloaded entries from constraint table |
105 |
for (int index = 0; index < table_size(); index++) { |
|
106 |
LoaderConstraintEntry** p = bucket_addr(index); |
|
107 |
while(*p) { |
|
108 |
LoaderConstraintEntry* probe = *p; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
109 |
Klass* klass = probe->klass(); |
1 | 110 |
// Remove klass that is no longer alive |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
111 |
if (klass != NULL && |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
112 |
klass->class_loader_data()->is_unloading()) { |
1 | 113 |
probe->set_klass(NULL); |
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
114 |
if (log_is_enabled(Info, constraints)) { |
1 | 115 |
ResourceMark rm; |
37242 | 116 |
outputStream* out = Log(classload, constraints)::info_stream(); |
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
117 |
out->print_cr("purging class object from constraint for name %s," |
1 | 118 |
" loader list:", |
119 |
probe->name()->as_C_string()); |
|
120 |
for (int i = 0; i < probe->num_loaders(); i++) { |
|
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
121 |
out->print_cr(" [%d]: %s", i, |
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
122 |
probe->loader_data(i)->loader_name()); |
1 | 123 |
} |
124 |
} |
|
125 |
} |
|
126 |
// Remove entries no longer alive from loader array |
|
127 |
int n = 0; |
|
128 |
while (n < probe->num_loaders()) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
129 |
if (probe->loader_data(n)->is_unloading()) { |
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
130 |
if (log_is_enabled(Info, classload, constraints)) { |
1 | 131 |
ResourceMark rm; |
37242 | 132 |
outputStream* out = Log(classload, constraints)::info_stream(); |
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
133 |
out->print_cr("purging loader %s from constraint for name %s", |
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
134 |
probe->loader_data(n)->loader_name(), |
1 | 135 |
probe->name()->as_C_string() |
136 |
); |
|
137 |
} |
|
138 |
||
139 |
// Compact array |
|
140 |
int num = probe->num_loaders() - 1; |
|
141 |
probe->set_num_loaders(num); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
142 |
probe->set_loader_data(n, probe->loader_data(num)); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
143 |
probe->set_loader_data(num, NULL); |
1 | 144 |
|
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
145 |
if (log_is_enabled(Info, classload, constraints)) { |
1 | 146 |
ResourceMark rm; |
37242 | 147 |
outputStream* out = Log(classload, constraints)::info_stream(); |
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
148 |
out->print_cr("new loader list:"); |
1 | 149 |
for (int i = 0; i < probe->num_loaders(); i++) { |
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
150 |
out->print_cr(" [%d]: %s", i, |
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
151 |
probe->loader_data(i)->loader_name()); |
1 | 152 |
} |
153 |
} |
|
154 |
||
155 |
continue; // current element replaced, so restart without |
|
156 |
// incrementing n |
|
157 |
} |
|
158 |
n++; |
|
159 |
} |
|
160 |
// Check whether entry should be purged |
|
161 |
if (probe->num_loaders() < 2) { |
|
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
162 |
if (log_is_enabled(Info, classload, constraints)) { |
1 | 163 |
ResourceMark rm; |
37242 | 164 |
outputStream* out = Log(classload, constraints)::info_stream(); |
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
165 |
out->print_cr("purging complete constraint for name %s", |
1 | 166 |
probe->name()->as_C_string()); |
167 |
} |
|
168 |
||
169 |
// Purge entry |
|
170 |
*p = probe->next(); |
|
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
14588
diff
changeset
|
171 |
FREE_C_HEAP_ARRAY(oop, probe->loaders()); |
1 | 172 |
free_entry(probe); |
173 |
} else { |
|
174 |
#ifdef ASSERT |
|
175 |
if (probe->klass() != NULL) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
176 |
ClassLoaderData* loader_data = |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
177 |
probe->klass()->class_loader_data(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
178 |
assert(!loader_data->is_unloading(), "klass should be live"); |
1 | 179 |
} |
180 |
#endif |
|
181 |
// Go to next entry |
|
182 |
p = probe->next_addr(); |
|
183 |
} |
|
184 |
} |
|
185 |
} |
|
186 |
} |
|
187 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
188 |
bool LoaderConstraintTable::add_entry(Symbol* class_name, |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
189 |
Klass* klass1, Handle class_loader1, |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
190 |
Klass* klass2, Handle class_loader2) { |
1 | 191 |
int failure_code = 0; // encode different reasons for failing |
192 |
||
193 |
if (klass1 != NULL && klass2 != NULL && klass1 != klass2) { |
|
194 |
failure_code = 1; |
|
195 |
} else { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
196 |
Klass* klass = klass1 != NULL ? klass1 : klass2; |
1 | 197 |
|
198 |
LoaderConstraintEntry** pp1 = find_loader_constraint(class_name, |
|
199 |
class_loader1); |
|
200 |
if (*pp1 != NULL && (*pp1)->klass() != NULL) { |
|
201 |
if (klass != NULL) { |
|
202 |
if (klass != (*pp1)->klass()) { |
|
203 |
failure_code = 2; |
|
204 |
} |
|
205 |
} else { |
|
206 |
klass = (*pp1)->klass(); |
|
207 |
} |
|
208 |
} |
|
209 |
||
210 |
LoaderConstraintEntry** pp2 = find_loader_constraint(class_name, |
|
211 |
class_loader2); |
|
212 |
if (*pp2 != NULL && (*pp2)->klass() != NULL) { |
|
213 |
if (klass != NULL) { |
|
214 |
if (klass != (*pp2)->klass()) { |
|
215 |
failure_code = 3; |
|
216 |
} |
|
217 |
} else { |
|
218 |
klass = (*pp2)->klass(); |
|
219 |
} |
|
220 |
} |
|
221 |
||
222 |
if (failure_code == 0) { |
|
223 |
if (*pp1 == NULL && *pp2 == NULL) { |
|
224 |
unsigned int hash = compute_hash(class_name); |
|
225 |
int index = hash_to_index(hash); |
|
226 |
LoaderConstraintEntry* p; |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
227 |
p = new_entry(hash, class_name, klass, 2, 2); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
228 |
p->set_loaders(NEW_C_HEAP_ARRAY(ClassLoaderData*, 2, mtClass)); |
1 | 229 |
p->set_loader(0, class_loader1()); |
230 |
p->set_loader(1, class_loader2()); |
|
231 |
p->set_klass(klass); |
|
232 |
p->set_next(bucket(index)); |
|
233 |
set_entry(index, p); |
|
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
234 |
if (log_is_enabled(Info, classload, constraints)) { |
1 | 235 |
ResourceMark rm; |
37242 | 236 |
outputStream* out = Log(classload, constraints)::info_stream(); |
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
237 |
out->print_cr("adding new constraint for name: %s, loader[0]: %s," |
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
238 |
" loader[1]: %s", |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
239 |
class_name->as_C_string(), |
1 | 240 |
SystemDictionary::loader_name(class_loader1()), |
241 |
SystemDictionary::loader_name(class_loader2()) |
|
242 |
); |
|
243 |
} |
|
244 |
} else if (*pp1 == *pp2) { |
|
245 |
/* constraint already imposed */ |
|
246 |
if ((*pp1)->klass() == NULL) { |
|
247 |
(*pp1)->set_klass(klass); |
|
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
248 |
if (log_is_enabled(Info, classload, constraints)) { |
1 | 249 |
ResourceMark rm; |
37242 | 250 |
outputStream* out = Log(classload, constraints)::info_stream(); |
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
251 |
out->print_cr("setting class object in existing constraint for" |
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
252 |
" name: %s and loader %s", |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
253 |
class_name->as_C_string(), |
1 | 254 |
SystemDictionary::loader_name(class_loader1()) |
255 |
); |
|
256 |
} |
|
257 |
} else { |
|
258 |
assert((*pp1)->klass() == klass, "loader constraints corrupted"); |
|
259 |
} |
|
260 |
} else if (*pp1 == NULL) { |
|
261 |
extend_loader_constraint(*pp2, class_loader1, klass); |
|
262 |
} else if (*pp2 == NULL) { |
|
263 |
extend_loader_constraint(*pp1, class_loader2, klass); |
|
264 |
} else { |
|
265 |
merge_loader_constraints(pp1, pp2, klass); |
|
266 |
} |
|
267 |
} |
|
268 |
} |
|
269 |
||
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
270 |
if (failure_code != 0 && log_is_enabled(Info, classload, constraints)) { |
1 | 271 |
ResourceMark rm; |
37242 | 272 |
outputStream* out = Log(classload, constraints)::info_stream(); |
1 | 273 |
const char* reason = ""; |
274 |
switch(failure_code) { |
|
275 |
case 1: reason = "the class objects presented by loader[0] and loader[1]" |
|
276 |
" are different"; break; |
|
277 |
case 2: reason = "the class object presented by loader[0] does not match" |
|
278 |
" the stored class object in the constraint"; break; |
|
279 |
case 3: reason = "the class object presented by loader[1] does not match" |
|
280 |
" the stored class object in the constraint"; break; |
|
281 |
default: reason = "unknown reason code"; |
|
282 |
} |
|
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
283 |
out->print_cr("failed to add constraint for name: %s, loader[0]: %s," |
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
284 |
" loader[1]: %s, Reason: %s", |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
285 |
class_name->as_C_string(), |
1 | 286 |
SystemDictionary::loader_name(class_loader1()), |
287 |
SystemDictionary::loader_name(class_loader2()), |
|
288 |
reason |
|
289 |
); |
|
290 |
} |
|
291 |
||
292 |
return failure_code == 0; |
|
293 |
} |
|
294 |
||
295 |
||
296 |
// return true if the constraint was updated, false if the constraint is |
|
297 |
// violated |
|
298 |
bool LoaderConstraintTable::check_or_update(instanceKlassHandle k, |
|
299 |
Handle loader, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
300 |
Symbol* name) { |
1 | 301 |
LoaderConstraintEntry* p = *(find_loader_constraint(name, loader)); |
302 |
if (p && p->klass() != NULL && p->klass() != k()) { |
|
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
303 |
if (log_is_enabled(Info, classload, constraints)) { |
1 | 304 |
ResourceMark rm; |
37242 | 305 |
outputStream* out = Log(classload, constraints)::info_stream(); |
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
306 |
out->print_cr("constraint check failed for name %s, loader %s: " |
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
307 |
"the presented class object differs from that stored", |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
308 |
name->as_C_string(), |
1 | 309 |
SystemDictionary::loader_name(loader())); |
310 |
} |
|
311 |
return false; |
|
312 |
} else { |
|
313 |
if (p && p->klass() == NULL) { |
|
314 |
p->set_klass(k()); |
|
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
315 |
if (log_is_enabled(Info, classload, constraints)) { |
1 | 316 |
ResourceMark rm; |
37242 | 317 |
outputStream* out = Log(classload, constraints)::info_stream(); |
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
318 |
out->print_cr("updating constraint for name %s, loader %s, " |
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
319 |
"by setting class object", |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
320 |
name->as_C_string(), |
1 | 321 |
SystemDictionary::loader_name(loader())); |
322 |
} |
|
323 |
} |
|
324 |
return true; |
|
325 |
} |
|
326 |
} |
|
327 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
328 |
Klass* LoaderConstraintTable::find_constrained_klass(Symbol* name, |
1 | 329 |
Handle loader) { |
330 |
LoaderConstraintEntry *p = *(find_loader_constraint(name, loader)); |
|
8314
057b1c20fd7e
6354181: nsk.logging.stress.threads.scmhml001 fails assertion in "src/share/vm/oops/instanceKlass.cpp, 111"
never
parents:
8076
diff
changeset
|
331 |
if (p != NULL && p->klass() != NULL) { |
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
27880
diff
changeset
|
332 |
if (p->klass()->is_instance_klass() && !InstanceKlass::cast(p->klass())->is_loaded()) { |
8314
057b1c20fd7e
6354181: nsk.logging.stress.threads.scmhml001 fails assertion in "src/share/vm/oops/instanceKlass.cpp, 111"
never
parents:
8076
diff
changeset
|
333 |
// Only return fully loaded classes. Classes found through the |
057b1c20fd7e
6354181: nsk.logging.stress.threads.scmhml001 fails assertion in "src/share/vm/oops/instanceKlass.cpp, 111"
never
parents:
8076
diff
changeset
|
334 |
// constraints might still be in the process of loading. |
057b1c20fd7e
6354181: nsk.logging.stress.threads.scmhml001 fails assertion in "src/share/vm/oops/instanceKlass.cpp, 111"
never
parents:
8076
diff
changeset
|
335 |
return NULL; |
057b1c20fd7e
6354181: nsk.logging.stress.threads.scmhml001 fails assertion in "src/share/vm/oops/instanceKlass.cpp, 111"
never
parents:
8076
diff
changeset
|
336 |
} |
1 | 337 |
return p->klass(); |
8314
057b1c20fd7e
6354181: nsk.logging.stress.threads.scmhml001 fails assertion in "src/share/vm/oops/instanceKlass.cpp, 111"
never
parents:
8076
diff
changeset
|
338 |
} |
1 | 339 |
|
340 |
// No constraints, or else no klass loaded yet. |
|
341 |
return NULL; |
|
342 |
} |
|
343 |
||
344 |
void LoaderConstraintTable::ensure_loader_constraint_capacity( |
|
345 |
LoaderConstraintEntry *p, |
|
346 |
int nfree) { |
|
347 |
if (p->max_loaders() - p->num_loaders() < nfree) { |
|
348 |
int n = nfree + p->num_loaders(); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
349 |
ClassLoaderData** new_loaders = NEW_C_HEAP_ARRAY(ClassLoaderData*, n, mtClass); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
350 |
memcpy(new_loaders, p->loaders(), sizeof(ClassLoaderData*) * p->num_loaders()); |
1 | 351 |
p->set_max_loaders(n); |
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
14588
diff
changeset
|
352 |
FREE_C_HEAP_ARRAY(ClassLoaderData*, p->loaders()); |
1 | 353 |
p->set_loaders(new_loaders); |
354 |
} |
|
355 |
} |
|
356 |
||
357 |
||
358 |
void LoaderConstraintTable::extend_loader_constraint(LoaderConstraintEntry* p, |
|
359 |
Handle loader, |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
360 |
Klass* klass) { |
1 | 361 |
ensure_loader_constraint_capacity(p, 1); |
362 |
int num = p->num_loaders(); |
|
363 |
p->set_loader(num, loader()); |
|
364 |
p->set_num_loaders(num + 1); |
|
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
365 |
if (log_is_enabled(Info, classload, constraints)) { |
1 | 366 |
ResourceMark rm; |
37242 | 367 |
outputStream* out = Log(classload, constraints)::info_stream(); |
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
368 |
out->print_cr("extending constraint for name %s by adding loader[%d]: %s %s", |
1 | 369 |
p->name()->as_C_string(), |
370 |
num, |
|
371 |
SystemDictionary::loader_name(loader()), |
|
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
372 |
(p->klass() == NULL ? " and setting class object" : "") |
1 | 373 |
); |
374 |
} |
|
375 |
if (p->klass() == NULL) { |
|
376 |
p->set_klass(klass); |
|
377 |
} else { |
|
378 |
assert(klass == NULL || p->klass() == klass, "constraints corrupted"); |
|
379 |
} |
|
380 |
} |
|
381 |
||
382 |
||
383 |
void LoaderConstraintTable::merge_loader_constraints( |
|
384 |
LoaderConstraintEntry** pp1, |
|
385 |
LoaderConstraintEntry** pp2, |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
386 |
Klass* klass) { |
1 | 387 |
// make sure *pp1 has higher capacity |
388 |
if ((*pp1)->max_loaders() < (*pp2)->max_loaders()) { |
|
389 |
LoaderConstraintEntry** tmp = pp2; |
|
390 |
pp2 = pp1; |
|
391 |
pp1 = tmp; |
|
392 |
} |
|
393 |
||
394 |
LoaderConstraintEntry* p1 = *pp1; |
|
395 |
LoaderConstraintEntry* p2 = *pp2; |
|
396 |
||
397 |
ensure_loader_constraint_capacity(p1, p2->num_loaders()); |
|
398 |
||
399 |
for (int i = 0; i < p2->num_loaders(); i++) { |
|
400 |
int num = p1->num_loaders(); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
401 |
p1->set_loader_data(num, p2->loader_data(i)); |
1 | 402 |
p1->set_num_loaders(num + 1); |
403 |
} |
|
404 |
||
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
405 |
if (log_is_enabled(Info, classload, constraints)) { |
1 | 406 |
ResourceMark rm; |
37242 | 407 |
outputStream* out = Log(classload, constraints)::info_stream(); |
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
408 |
out->print_cr("merged constraints for name %s, new loader list:", |
1 | 409 |
p1->name()->as_C_string() |
410 |
); |
|
411 |
||
412 |
for (int i = 0; i < p1->num_loaders(); i++) { |
|
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
413 |
out->print_cr(" [%d]: %s", i, |
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14488
diff
changeset
|
414 |
p1->loader_data(i)->loader_name()); |
1 | 415 |
} |
416 |
if (p1->klass() == NULL) { |
|
37202
4100f25e4b09
8149996: TraceLoaderConstraints has been converted to Unified Logging.
mockner
parents:
33611
diff
changeset
|
417 |
out->print_cr("... and setting class object"); |
1 | 418 |
} |
419 |
} |
|
420 |
||
421 |
// p1->klass() will hold NULL if klass, p2->klass(), and old |
|
422 |
// p1->klass() are all NULL. In addition, all three must have |
|
423 |
// matching non-NULL values, otherwise either the constraints would |
|
424 |
// have been violated, or the constraints had been corrupted (and an |
|
425 |
// assertion would fail). |
|
426 |
if (p2->klass() != NULL) { |
|
427 |
assert(p2->klass() == klass, "constraints corrupted"); |
|
428 |
} |
|
429 |
if (p1->klass() == NULL) { |
|
430 |
p1->set_klass(klass); |
|
431 |
} else { |
|
432 |
assert(p1->klass() == klass, "constraints corrupted"); |
|
433 |
} |
|
434 |
||
435 |
*pp2 = p2->next(); |
|
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
14588
diff
changeset
|
436 |
FREE_C_HEAP_ARRAY(oop, p2->loaders()); |
1 | 437 |
free_entry(p2); |
438 |
return; |
|
439 |
} |
|
440 |
||
441 |
||
4899
ab225bac579c
6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents:
1
diff
changeset
|
442 |
void LoaderConstraintTable::verify(Dictionary* dictionary, |
ab225bac579c
6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents:
1
diff
changeset
|
443 |
PlaceholderTable* placeholders) { |
1 | 444 |
Thread *thread = Thread::current(); |
445 |
for (int cindex = 0; cindex < _loader_constraint_size; cindex++) { |
|
446 |
for (LoaderConstraintEntry* probe = bucket(cindex); |
|
447 |
probe != NULL; |
|
448 |
probe = probe->next()) { |
|
449 |
if (probe->klass() != NULL) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
450 |
InstanceKlass* ik = InstanceKlass::cast(probe->klass()); |
1 | 451 |
guarantee(ik->name() == probe->name(), "name should match"); |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
452 |
Symbol* name = ik->name(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
453 |
ClassLoaderData* loader_data = ik->class_loader_data(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
454 |
unsigned int d_hash = dictionary->compute_hash(name, loader_data); |
1 | 455 |
int d_index = dictionary->hash_to_index(d_hash); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
456 |
Klass* k = dictionary->find_class(d_index, d_hash, name, loader_data); |
4899
ab225bac579c
6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents:
1
diff
changeset
|
457 |
if (k != NULL) { |
ab225bac579c
6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents:
1
diff
changeset
|
458 |
// We found the class in the system dictionary, so we should |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
459 |
// make sure that the Klass* matches what we already have. |
4899
ab225bac579c
6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents:
1
diff
changeset
|
460 |
guarantee(k == probe->klass(), "klass should be in dictionary"); |
ab225bac579c
6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents:
1
diff
changeset
|
461 |
} else { |
ab225bac579c
6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents:
1
diff
changeset
|
462 |
// If we don't find the class in the system dictionary, it |
ab225bac579c
6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents:
1
diff
changeset
|
463 |
// has to be in the placeholders table. |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
464 |
unsigned int p_hash = placeholders->compute_hash(name, loader_data); |
4899
ab225bac579c
6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents:
1
diff
changeset
|
465 |
int p_index = placeholders->hash_to_index(p_hash); |
ab225bac579c
6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents:
1
diff
changeset
|
466 |
PlaceholderEntry* entry = placeholders->get_entry(p_index, p_hash, |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
467 |
name, loader_data); |
4899
ab225bac579c
6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents:
1
diff
changeset
|
468 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
469 |
// The InstanceKlass might not be on the entry, so the only |
4899
ab225bac579c
6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents:
1
diff
changeset
|
470 |
// thing we can check here is whether we were successful in |
ab225bac579c
6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents:
1
diff
changeset
|
471 |
// finding the class in the placeholders table. |
ab225bac579c
6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents:
1
diff
changeset
|
472 |
guarantee(entry != NULL, "klass should be in the placeholders"); |
ab225bac579c
6920977: G1: guarantee(k == probe->klass(),"klass should be in dictionary") fails
tonyp
parents:
1
diff
changeset
|
473 |
} |
1 | 474 |
} |
475 |
for (int n = 0; n< probe->num_loaders(); n++) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
476 |
assert(ClassLoaderDataGraph::contains_loader_data(probe->loader_data(n)), "The loader is missing"); |
1 | 477 |
} |
478 |
} |
|
479 |
} |
|
480 |
} |
|
481 |
||
482 |
#ifndef PRODUCT |
|
483 |
||
484 |
// Called with the system dictionary lock held |
|
485 |
void LoaderConstraintTable::print() { |
|
486 |
ResourceMark rm; |
|
487 |
assert_locked_or_safepoint(SystemDictionary_lock); |
|
488 |
tty->print_cr("Java loader constraints (entries=%d)", _loader_constraint_size); |
|
489 |
for (int cindex = 0; cindex < _loader_constraint_size; cindex++) { |
|
490 |
for (LoaderConstraintEntry* probe = bucket(cindex); |
|
491 |
probe != NULL; |
|
492 |
probe = probe->next()) { |
|
493 |
tty->print("%4d: ", cindex); |
|
494 |
probe->name()->print(); |
|
495 |
tty->print(" , loaders:"); |
|
496 |
for (int n = 0; n < probe->num_loaders(); n++) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
497 |
probe->loader_data(n)->print_value(); |
1 | 498 |
tty->print(", "); |
499 |
} |
|
500 |
tty->cr(); |
|
501 |
} |
|
502 |
} |
|
503 |
} |
|
504 |
#endif |