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