@@ -163,60 +163,31 @@ static inline bool is_class_loader(const Symbol* class_name,
163
163
// private: called to verify that k is a static member of this nest.
164
164
// We know that k is an instance class in the same package and hence the
165
165
// same classloader.
166
- bool InstanceKlass::has_nest_member (InstanceKlass* k, TRAPS ) const {
166
+ bool InstanceKlass::has_nest_member (JavaThread* current, InstanceKlass* k ) const {
167
167
assert (!is_hidden (), " unexpected hidden class" );
168
168
if (_nest_members == NULL || _nest_members == Universe::the_empty_short_array ()) {
169
169
if (log_is_enabled (Trace, class , nestmates)) {
170
- ResourceMark rm (THREAD );
170
+ ResourceMark rm (current );
171
171
log_trace (class , nestmates)(" Checked nest membership of %s in non-nest-host class %s" ,
172
172
k->external_name (), this ->external_name ());
173
173
}
174
174
return false ;
175
175
}
176
176
177
177
if (log_is_enabled (Trace, class , nestmates)) {
178
- ResourceMark rm (THREAD );
178
+ ResourceMark rm (current );
179
179
log_trace (class , nestmates)(" Checking nest membership of %s in %s" ,
180
180
k->external_name (), this ->external_name ());
181
181
}
182
182
183
- // Check for a resolved cp entry , else fall back to a name check .
184
- // We don't want to resolve any class other than the one being checked .
183
+ // Check for the named class in _nest_members .
184
+ // We don't resolve, or load, any classes .
185
185
for (int i = 0 ; i < _nest_members->length (); i++) {
186
186
int cp_index = _nest_members->at (i);
187
- if (_constants->tag_at (cp_index).is_klass ()) {
188
- Klass* k2 = _constants->klass_at (cp_index, THREAD);
189
- assert (!HAS_PENDING_EXCEPTION || PENDING_EXCEPTION->is_a (vmClasses::VirtualMachineError_klass ()),
190
- " Exceptions should not be possible here" );
191
- if (k2 == k) {
192
- log_trace (class , nestmates)(" - class is listed at nest_members[%d] => cp[%d]" , i, cp_index);
193
- return true ;
194
- }
195
- }
196
- else {
197
- Symbol* name = _constants->klass_name_at (cp_index);
198
- if (name == k->name ()) {
199
- log_trace (class , nestmates)(" - Found it at nest_members[%d] => cp[%d]" , i, cp_index);
200
-
201
- // Names match so check actual klass. This may trigger class loading if
202
- // it doesn't match though that should be impossible as it means one classloader
203
- // has defined two different classes with the same name! A compiler thread won't be
204
- // able to perform that loading but we can't exclude the compiler threads from
205
- // executing this logic. But it should actually be impossible to trigger loading here.
206
- Klass* k2 = _constants->klass_at (cp_index, THREAD);
207
- assert (!HAS_PENDING_EXCEPTION || PENDING_EXCEPTION->is_a (vmClasses::VirtualMachineError_klass ()),
208
- " Exceptions should not be possible here" );
209
- if (k2 == k) {
210
- log_trace (class , nestmates)(" - class is listed as a nest member" );
211
- return true ;
212
- }
213
- else {
214
- // same name but different klass!
215
- log_trace (class , nestmates)(" - klass comparison failed!" );
216
- // can't have two names the same, so we're done
217
- return false ;
218
- }
219
- }
187
+ Symbol* name = _constants->klass_name_at (cp_index);
188
+ if (name == k->name ()) {
189
+ log_trace (class , nestmates)(" - named class found at nest_members[%d] => cp[%d]" , i, cp_index);
190
+ return true ;
220
191
}
221
192
}
222
193
log_trace (class , nestmates)(" - class is NOT a nest member!" );
@@ -287,7 +258,8 @@ InstanceKlass* InstanceKlass::nest_host(TRAPS) {
287
258
// need to resolve and save our nest-host class.
288
259
if (_nest_host_index != 0 ) { // we have a real nest_host
289
260
// Before trying to resolve check if we're in a suitable context
290
- if (!THREAD->can_call_java () && !_constants->tag_at (_nest_host_index).is_klass ()) {
261
+ bool can_resolve = THREAD->can_call_java ();
262
+ if (!can_resolve && !_constants->tag_at (_nest_host_index).is_klass ()) {
291
263
log_trace (class , nestmates)(" Rejected resolution of nest-host of %s in unsuitable thread" ,
292
264
this ->external_name ());
293
265
return NULL ; // sentinel to say "try again from a different context"
@@ -325,26 +297,15 @@ InstanceKlass* InstanceKlass::nest_host(TRAPS) {
325
297
// not an instance class.
326
298
if (k->is_instance_klass ()) {
327
299
nest_host_k = InstanceKlass::cast (k);
328
- bool is_member = nest_host_k->has_nest_member (this , THREAD);
329
- // exception is rare, perhaps impossible
330
- if (!HAS_PENDING_EXCEPTION) {
331
- if (is_member) {
332
- _nest_host = nest_host_k; // save resolved nest-host value
333
-
334
- log_trace (class , nestmates)(" Resolved nest-host of %s to %s" ,
335
- this ->external_name (), k->external_name ());
336
- return nest_host_k;
337
- } else {
338
- error = " current type is not listed as a nest member" ;
339
- }
300
+ bool is_member = nest_host_k->has_nest_member (THREAD->as_Java_thread (), this );
301
+ if (is_member) {
302
+ _nest_host = nest_host_k; // save resolved nest-host value
303
+
304
+ log_trace (class , nestmates)(" Resolved nest-host of %s to %s" ,
305
+ this ->external_name (), k->external_name ());
306
+ return nest_host_k;
340
307
} else {
341
- if (PENDING_EXCEPTION->is_a (vmClasses::VirtualMachineError_klass ())) {
342
- return NULL ; // propagate VMEs
343
- }
344
- stringStream ss;
345
- ss.print (" exception on member check: " );
346
- java_lang_Throwable::print (PENDING_EXCEPTION, &ss);
347
- error = ss.as_string ();
308
+ error = " current type is not listed as a nest member" ;
348
309
}
349
310
} else {
350
311
error = " host is not an instance class" ;
0 commit comments