166 #define DTRACE_CLASSINIT_PROBE(type, clss, thread_type) |
169 #define DTRACE_CLASSINIT_PROBE(type, clss, thread_type) |
167 #define DTRACE_CLASSINIT_PROBE_WAIT(type, clss, thread_type, wait) |
170 #define DTRACE_CLASSINIT_PROBE_WAIT(type, clss, thread_type, wait) |
168 |
171 |
169 #endif // ndef DTRACE_ENABLED |
172 #endif // ndef DTRACE_ENABLED |
170 |
173 |
171 bool instanceKlass::should_be_initialized() const { |
174 Klass* InstanceKlass::allocate_instance_klass(ClassLoaderData* loader_data, |
|
175 int vtable_len, |
|
176 int itable_len, |
|
177 int static_field_size, |
|
178 int nonstatic_oop_map_size, |
|
179 ReferenceType rt, |
|
180 AccessFlags access_flags, |
|
181 Symbol* name, |
|
182 Klass* super_klass, |
|
183 KlassHandle host_klass, |
|
184 TRAPS) { |
|
185 |
|
186 int size = InstanceKlass::size(vtable_len, itable_len, nonstatic_oop_map_size, |
|
187 access_flags.is_interface(), |
|
188 !host_klass.is_null()); |
|
189 |
|
190 // Allocation |
|
191 InstanceKlass* ik; |
|
192 if (rt == REF_NONE) { |
|
193 if (name == vmSymbols::java_lang_Class()) { |
|
194 ik = new (loader_data, size, THREAD) instanceMirrorKlass( |
|
195 vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt, |
|
196 access_flags, !host_klass.is_null()); |
|
197 } else if (name == vmSymbols::java_lang_ClassLoader() || |
|
198 (SystemDictionary::ClassLoader_klass_loaded() && |
|
199 super_klass != NULL && |
|
200 super_klass->is_subtype_of(SystemDictionary::ClassLoader_klass()))) { |
|
201 ik = new (loader_data, size, THREAD) instanceClassLoaderKlass( |
|
202 vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt, |
|
203 access_flags, !host_klass.is_null()); |
|
204 } else { |
|
205 // normal class |
|
206 ik = new (loader_data, size, THREAD) InstanceKlass( |
|
207 vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt, |
|
208 access_flags, !host_klass.is_null()); |
|
209 } |
|
210 } else { |
|
211 // reference klass |
|
212 ik = new (loader_data, size, THREAD) instanceRefKlass( |
|
213 vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt, |
|
214 access_flags, !host_klass.is_null()); |
|
215 } |
|
216 |
|
217 return ik; |
|
218 } |
|
219 |
|
220 InstanceKlass::InstanceKlass(int vtable_len, |
|
221 int itable_len, |
|
222 int static_field_size, |
|
223 int nonstatic_oop_map_size, |
|
224 ReferenceType rt, |
|
225 AccessFlags access_flags, |
|
226 bool is_anonymous) { |
|
227 No_Safepoint_Verifier no_safepoint; // until k becomes parsable |
|
228 |
|
229 int size = InstanceKlass::size(vtable_len, itable_len, nonstatic_oop_map_size, |
|
230 access_flags.is_interface(), is_anonymous); |
|
231 |
|
232 // The sizes of these these three variables are used for determining the |
|
233 // size of the instanceKlassOop. It is critical that these are set to the right |
|
234 // sizes before the first GC, i.e., when we allocate the mirror. |
|
235 this->set_vtable_length(vtable_len); |
|
236 this->set_itable_length(itable_len); |
|
237 this->set_static_field_size(static_field_size); |
|
238 this->set_nonstatic_oop_map_size(nonstatic_oop_map_size); |
|
239 this->set_access_flags(access_flags); |
|
240 this->set_is_anonymous(is_anonymous); |
|
241 assert(this->size() == size, "wrong size for object"); |
|
242 |
|
243 this->set_array_klasses(NULL); |
|
244 this->set_methods(NULL); |
|
245 this->set_method_ordering(NULL); |
|
246 this->set_local_interfaces(NULL); |
|
247 this->set_transitive_interfaces(NULL); |
|
248 this->init_implementor(); |
|
249 this->set_fields(NULL, 0); |
|
250 this->set_constants(NULL); |
|
251 this->set_class_loader_data(NULL); |
|
252 this->set_protection_domain(NULL); |
|
253 this->set_signers(NULL); |
|
254 this->set_source_file_name(NULL); |
|
255 this->set_source_debug_extension(NULL, 0); |
|
256 this->set_array_name(NULL); |
|
257 this->set_inner_classes(NULL); |
|
258 this->set_static_oop_field_count(0); |
|
259 this->set_nonstatic_field_size(0); |
|
260 this->set_is_marked_dependent(false); |
|
261 this->set_init_state(InstanceKlass::allocated); |
|
262 this->set_init_thread(NULL); |
|
263 this->set_init_lock(NULL); |
|
264 this->set_reference_type(rt); |
|
265 this->set_oop_map_cache(NULL); |
|
266 this->set_jni_ids(NULL); |
|
267 this->set_osr_nmethods_head(NULL); |
|
268 this->set_breakpoints(NULL); |
|
269 this->init_previous_versions(); |
|
270 this->set_generic_signature(NULL); |
|
271 this->release_set_methods_jmethod_ids(NULL); |
|
272 this->release_set_methods_cached_itable_indices(NULL); |
|
273 this->set_annotations(NULL); |
|
274 this->set_jvmti_cached_class_field_map(NULL); |
|
275 this->set_initial_method_idnum(0); |
|
276 |
|
277 // initialize the non-header words to zero |
|
278 intptr_t* p = (intptr_t*)this; |
|
279 for (int index = InstanceKlass::header_size(); index < size; index++) { |
|
280 p[index] = NULL_WORD; |
|
281 } |
|
282 |
|
283 // Set temporary value until parseClassFile updates it with the real instance |
|
284 // size. |
|
285 this->set_layout_helper(Klass::instance_layout_helper(0, true)); |
|
286 } |
|
287 |
|
288 |
|
289 // This function deallocates the metadata and C heap pointers that the |
|
290 // InstanceKlass points to. |
|
291 void InstanceKlass::deallocate_contents(ClassLoaderData* loader_data) { |
|
292 |
|
293 // Orphan the mirror first, CMS thinks it's still live. |
|
294 java_lang_Class::set_klass(java_mirror(), NULL); |
|
295 |
|
296 // Need to take this class off the class loader data list. |
|
297 loader_data->remove_class(this); |
|
298 |
|
299 // The array_klass for this class is created later, after error handling. |
|
300 // For class redefinition, we keep the original class so this scratch class |
|
301 // doesn't have an array class. Either way, assert that there is nothing |
|
302 // to deallocate. |
|
303 assert(array_klasses() == NULL, "array classes shouldn't be created for this class yet"); |
|
304 |
|
305 // Release C heap allocated data that this might point to, which includes |
|
306 // reference counting symbol names. |
|
307 release_C_heap_structures(); |
|
308 |
|
309 Array<Method*>* ms = methods(); |
|
310 if (ms != Universe::the_empty_method_array()) { |
|
311 for (int i = 0; i <= methods()->length() -1 ; i++) { |
|
312 Method* method = methods()->at(i); |
|
313 // Only want to delete methods that are not executing for RedefineClasses. |
|
314 // The previous version will point to them so they're not totally dangling |
|
315 assert (!method->on_stack(), "shouldn't be called with methods on stack"); |
|
316 MetadataFactory::free_metadata(loader_data, method); |
|
317 } |
|
318 MetadataFactory::free_array<Method*>(loader_data, methods()); |
|
319 } |
|
320 set_methods(NULL); |
|
321 |
|
322 if (method_ordering() != Universe::the_empty_int_array()) { |
|
323 MetadataFactory::free_array<int>(loader_data, method_ordering()); |
|
324 } |
|
325 set_method_ordering(NULL); |
|
326 |
|
327 // This array is in Klass, but remove it with the InstanceKlass since |
|
328 // this place would be the only caller and it can share memory with transitive |
|
329 // interfaces. |
|
330 if (secondary_supers() != Universe::the_empty_klass_array() && |
|
331 secondary_supers() != transitive_interfaces()) { |
|
332 MetadataFactory::free_array<Klass*>(loader_data, secondary_supers()); |
|
333 } |
|
334 set_secondary_supers(NULL); |
|
335 |
|
336 // Only deallocate transitive interfaces if not empty, same as super class |
|
337 // or same as local interfaces. See code in parseClassFile. |
|
338 Array<Klass*>* ti = transitive_interfaces(); |
|
339 if (ti != Universe::the_empty_klass_array() && ti != local_interfaces()) { |
|
340 // check that the interfaces don't come from super class |
|
341 Array<Klass*>* sti = (super() == NULL) ? NULL : |
|
342 InstanceKlass::cast(super())->transitive_interfaces(); |
|
343 if (ti != sti) { |
|
344 MetadataFactory::free_array<Klass*>(loader_data, ti); |
|
345 } |
|
346 } |
|
347 set_transitive_interfaces(NULL); |
|
348 |
|
349 // local interfaces can be empty |
|
350 Array<Klass*>* li = local_interfaces(); |
|
351 if (li != Universe::the_empty_klass_array()) { |
|
352 MetadataFactory::free_array<Klass*>(loader_data, li); |
|
353 } |
|
354 set_local_interfaces(NULL); |
|
355 |
|
356 MetadataFactory::free_array<jushort>(loader_data, fields()); |
|
357 set_fields(NULL, 0); |
|
358 |
|
359 // If a method from a redefined class is using this constant pool, don't |
|
360 // delete it, yet. The new class's previous version will point to this. |
|
361 assert (!constants()->on_stack(), "shouldn't be called if anything is onstack"); |
|
362 MetadataFactory::free_metadata(loader_data, constants()); |
|
363 set_constants(NULL); |
|
364 |
|
365 if (inner_classes() != Universe::the_empty_short_array()) { |
|
366 MetadataFactory::free_array<jushort>(loader_data, inner_classes()); |
|
367 } |
|
368 set_inner_classes(NULL); |
|
369 |
|
370 // Null out Java heap objects, although these won't be walked to keep |
|
371 // alive once this InstanceKlass is deallocated. |
|
372 set_protection_domain(NULL); |
|
373 set_signers(NULL); |
|
374 set_init_lock(NULL); |
|
375 set_annotations(NULL); |
|
376 } |
|
377 |
|
378 volatile oop InstanceKlass::init_lock() const { |
|
379 volatile oop lock = _init_lock; // read once |
|
380 assert((oop)lock != NULL || !is_not_initialized(), // initialized or in_error state |
|
381 "only fully initialized state can have a null lock"); |
|
382 return lock; |
|
383 } |
|
384 |
|
385 // Set the initialization lock to null so the object can be GC'ed. Any racing |
|
386 // threads to get this lock will see a null lock and will not lock. |
|
387 // That's okay because they all check for initialized state after getting |
|
388 // the lock and return. |
|
389 void InstanceKlass::fence_and_clear_init_lock() { |
|
390 // make sure previous stores are all done, notably the init_state. |
|
391 OrderAccess::storestore(); |
|
392 klass_oop_store(&_init_lock, NULL); |
|
393 assert(!is_not_initialized(), "class must be initialized now"); |
|
394 } |
|
395 |
|
396 |
|
397 bool InstanceKlass::should_be_initialized() const { |
172 return !is_initialized(); |
398 return !is_initialized(); |
173 } |
399 } |
174 |
400 |
175 klassVtable* instanceKlass::vtable() const { |
401 klassVtable* InstanceKlass::vtable() const { |
176 return new klassVtable(as_klassOop(), start_of_vtable(), vtable_length() / vtableEntry::size()); |
402 return new klassVtable(this, start_of_vtable(), vtable_length() / vtableEntry::size()); |
177 } |
403 } |
178 |
404 |
179 klassItable* instanceKlass::itable() const { |
405 klassItable* InstanceKlass::itable() const { |
180 return new klassItable(as_klassOop()); |
406 return new klassItable(instanceKlassHandle(this)); |
181 } |
407 } |
182 |
408 |
183 void instanceKlass::eager_initialize(Thread *thread) { |
409 void InstanceKlass::eager_initialize(Thread *thread) { |
184 if (!EagerInitialization) return; |
410 if (!EagerInitialization) return; |
185 |
411 |
186 if (this->is_not_initialized()) { |
412 if (this->is_not_initialized()) { |
187 // abort if the the class has a class initializer |
413 // abort if the the class has a class initializer |
188 if (this->class_initializer() != NULL) return; |
414 if (this->class_initializer() != NULL) return; |
189 |
415 |
190 // abort if it is java.lang.Object (initialization is handled in genesis) |
416 // abort if it is java.lang.Object (initialization is handled in genesis) |
191 klassOop super = this->super(); |
417 Klass* super = this->super(); |
192 if (super == NULL) return; |
418 if (super == NULL) return; |
193 |
419 |
194 // abort if the super class should be initialized |
420 // abort if the super class should be initialized |
195 if (!instanceKlass::cast(super)->is_initialized()) return; |
421 if (!InstanceKlass::cast(super)->is_initialized()) return; |
196 |
422 |
197 // call body to expose the this pointer |
423 // call body to expose the this pointer |
198 instanceKlassHandle this_oop(thread, this->as_klassOop()); |
424 instanceKlassHandle this_oop(thread, this); |
199 eager_initialize_impl(this_oop); |
425 eager_initialize_impl(this_oop); |
200 } |
426 } |
201 } |
427 } |
202 |
428 |
203 |
429 |
204 void instanceKlass::eager_initialize_impl(instanceKlassHandle this_oop) { |
430 void InstanceKlass::eager_initialize_impl(instanceKlassHandle this_oop) { |
205 EXCEPTION_MARK; |
431 EXCEPTION_MARK; |
206 ObjectLocker ol(this_oop, THREAD); |
432 volatile oop init_lock = this_oop->init_lock(); |
|
433 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); |
207 |
434 |
208 // abort if someone beat us to the initialization |
435 // abort if someone beat us to the initialization |
209 if (!this_oop->is_not_initialized()) return; // note: not equivalent to is_initialized() |
436 if (!this_oop->is_not_initialized()) return; // note: not equivalent to is_initialized() |
210 |
437 |
211 ClassState old_state = this_oop->init_state(); |
438 ClassState old_state = this_oop->init_state(); |
258 |
486 |
259 |
487 |
260 // Used exclusively by the shared spaces dump mechanism to prevent |
488 // Used exclusively by the shared spaces dump mechanism to prevent |
261 // classes mapped into the shared regions in new VMs from appearing linked. |
489 // classes mapped into the shared regions in new VMs from appearing linked. |
262 |
490 |
263 void instanceKlass::unlink_class() { |
491 void InstanceKlass::unlink_class() { |
264 assert(is_linked(), "must be linked"); |
492 assert(is_linked(), "must be linked"); |
265 _init_state = loaded; |
493 _init_state = loaded; |
266 } |
494 } |
267 |
495 |
268 void instanceKlass::link_class(TRAPS) { |
496 void InstanceKlass::link_class(TRAPS) { |
269 assert(is_loaded(), "must be loaded"); |
497 assert(is_loaded(), "must be loaded"); |
270 if (!is_linked()) { |
498 if (!is_linked()) { |
271 instanceKlassHandle this_oop(THREAD, this->as_klassOop()); |
499 HandleMark hm(THREAD); |
|
500 instanceKlassHandle this_oop(THREAD, this); |
272 link_class_impl(this_oop, true, CHECK); |
501 link_class_impl(this_oop, true, CHECK); |
273 } |
502 } |
274 } |
503 } |
275 |
504 |
276 // Called to verify that a class can link during initialization, without |
505 // Called to verify that a class can link during initialization, without |
277 // throwing a VerifyError. |
506 // throwing a VerifyError. |
278 bool instanceKlass::link_class_or_fail(TRAPS) { |
507 bool InstanceKlass::link_class_or_fail(TRAPS) { |
279 assert(is_loaded(), "must be loaded"); |
508 assert(is_loaded(), "must be loaded"); |
280 if (!is_linked()) { |
509 if (!is_linked()) { |
281 instanceKlassHandle this_oop(THREAD, this->as_klassOop()); |
510 HandleMark hm(THREAD); |
|
511 instanceKlassHandle this_oop(THREAD, this); |
282 link_class_impl(this_oop, false, CHECK_false); |
512 link_class_impl(this_oop, false, CHECK_false); |
283 } |
513 } |
284 return is_linked(); |
514 return is_linked(); |
285 } |
515 } |
286 |
516 |
287 bool instanceKlass::link_class_impl( |
517 bool InstanceKlass::link_class_impl( |
288 instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS) { |
518 instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS) { |
289 // check for error state |
519 // check for error state |
290 if (this_oop->is_in_error_state()) { |
520 if (this_oop->is_in_error_state()) { |
291 ResourceMark rm(THREAD); |
521 ResourceMark rm(THREAD); |
292 THROW_MSG_(vmSymbols::java_lang_NoClassDefFoundError(), |
522 THROW_MSG_(vmSymbols::java_lang_NoClassDefFoundError(), |
539 { |
773 { |
540 EXCEPTION_MARK; |
774 EXCEPTION_MARK; |
541 this_oop->set_initialization_state_and_notify(initialization_error, THREAD); |
775 this_oop->set_initialization_state_and_notify(initialization_error, THREAD); |
542 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, class initialization error is thrown below |
776 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, class initialization error is thrown below |
543 } |
777 } |
544 DTRACE_CLASSINIT_PROBE_WAIT(error, instanceKlass::cast(this_oop()), -1,wait); |
778 DTRACE_CLASSINIT_PROBE_WAIT(error, InstanceKlass::cast(this_oop()), -1,wait); |
545 if (e->is_a(SystemDictionary::Error_klass())) { |
779 if (e->is_a(SystemDictionary::Error_klass())) { |
546 THROW_OOP(e()); |
780 THROW_OOP(e()); |
547 } else { |
781 } else { |
548 JavaCallArguments args(e); |
782 JavaCallArguments args(e); |
549 THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(), |
783 THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(), |
550 vmSymbols::throwable_void_signature(), |
784 vmSymbols::throwable_void_signature(), |
551 &args); |
785 &args); |
552 } |
786 } |
553 } |
787 } |
554 DTRACE_CLASSINIT_PROBE_WAIT(end, instanceKlass::cast(this_oop()), -1,wait); |
788 DTRACE_CLASSINIT_PROBE_WAIT(end, InstanceKlass::cast(this_oop()), -1,wait); |
555 } |
789 } |
556 |
790 |
557 |
791 |
558 // Note: implementation moved to static method to expose the this pointer. |
792 // Note: implementation moved to static method to expose the this pointer. |
559 void instanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS) { |
793 void InstanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS) { |
560 instanceKlassHandle kh(THREAD, this->as_klassOop()); |
794 instanceKlassHandle kh(THREAD, this); |
561 set_initialization_state_and_notify_impl(kh, state, CHECK); |
795 set_initialization_state_and_notify_impl(kh, state, CHECK); |
562 } |
796 } |
563 |
797 |
564 void instanceKlass::set_initialization_state_and_notify_impl(instanceKlassHandle this_oop, ClassState state, TRAPS) { |
798 void InstanceKlass::set_initialization_state_and_notify_impl(instanceKlassHandle this_oop, ClassState state, TRAPS) { |
565 ObjectLocker ol(this_oop, THREAD); |
799 volatile oop init_lock = this_oop->init_lock(); |
|
800 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); |
566 this_oop->set_init_state(state); |
801 this_oop->set_init_state(state); |
|
802 this_oop->fence_and_clear_init_lock(); |
567 ol.notify_all(CHECK); |
803 ol.notify_all(CHECK); |
568 } |
804 } |
569 |
805 |
570 // The embedded _implementor field can only record one implementor. |
806 // The embedded _implementor field can only record one implementor. |
571 // When there are more than one implementors, the _implementor field |
807 // When there are more than one implementors, the _implementor field |
572 // is set to the interface klassOop itself. Following are the possible |
808 // is set to the interface Klass* itself. Following are the possible |
573 // values for the _implementor field: |
809 // values for the _implementor field: |
574 // NULL - no implementor |
810 // NULL - no implementor |
575 // implementor klassOop - one implementor |
811 // implementor Klass* - one implementor |
576 // self - more than one implementor |
812 // self - more than one implementor |
577 // |
813 // |
578 // The _implementor field only exists for interfaces. |
814 // The _implementor field only exists for interfaces. |
579 void instanceKlass::add_implementor(klassOop k) { |
815 void InstanceKlass::add_implementor(Klass* k) { |
580 assert(Compile_lock->owned_by_self(), ""); |
816 assert(Compile_lock->owned_by_self(), ""); |
581 assert(is_interface(), "not interface"); |
817 assert(is_interface(), "not interface"); |
582 // Filter out my subinterfaces. |
818 // Filter out my subinterfaces. |
583 // (Note: Interfaces are never on the subklass list.) |
819 // (Note: Interfaces are never on the subklass list.) |
584 if (instanceKlass::cast(k)->is_interface()) return; |
820 if (InstanceKlass::cast(k)->is_interface()) return; |
585 |
821 |
586 // Filter out subclasses whose supers already implement me. |
822 // Filter out subclasses whose supers already implement me. |
587 // (Note: CHA must walk subclasses of direct implementors |
823 // (Note: CHA must walk subclasses of direct implementors |
588 // in order to locate indirect implementors.) |
824 // in order to locate indirect implementors.) |
589 klassOop sk = instanceKlass::cast(k)->super(); |
825 Klass* sk = InstanceKlass::cast(k)->super(); |
590 if (sk != NULL && instanceKlass::cast(sk)->implements_interface(as_klassOop())) |
826 if (sk != NULL && InstanceKlass::cast(sk)->implements_interface(this)) |
591 // We only need to check one immediate superclass, since the |
827 // We only need to check one immediate superclass, since the |
592 // implements_interface query looks at transitive_interfaces. |
828 // implements_interface query looks at transitive_interfaces. |
593 // Any supers of the super have the same (or fewer) transitive_interfaces. |
829 // Any supers of the super have the same (or fewer) transitive_interfaces. |
594 return; |
830 return; |
595 |
831 |
596 klassOop ik = implementor(); |
832 Klass* ik = implementor(); |
597 if (ik == NULL) { |
833 if (ik == NULL) { |
598 set_implementor(k); |
834 set_implementor(k); |
599 } else if (ik != this->as_klassOop()) { |
835 } else if (ik != this) { |
600 // There is already an implementor. Use itself as an indicator of |
836 // There is already an implementor. Use itself as an indicator of |
601 // more than one implementors. |
837 // more than one implementors. |
602 set_implementor(this->as_klassOop()); |
838 set_implementor(this); |
603 } |
839 } |
604 |
840 |
605 // The implementor also implements the transitive_interfaces |
841 // The implementor also implements the transitive_interfaces |
606 for (int index = 0; index < local_interfaces()->length(); index++) { |
842 for (int index = 0; index < local_interfaces()->length(); index++) { |
607 instanceKlass::cast(klassOop(local_interfaces()->obj_at(index)))->add_implementor(k); |
843 InstanceKlass::cast(local_interfaces()->at(index))->add_implementor(k); |
608 } |
844 } |
609 } |
845 } |
610 |
846 |
611 void instanceKlass::init_implementor() { |
847 void InstanceKlass::init_implementor() { |
612 if (is_interface()) { |
848 if (is_interface()) { |
613 set_implementor(NULL); |
849 set_implementor(NULL); |
614 } |
850 } |
615 } |
851 } |
616 |
852 |
617 |
853 |
618 void instanceKlass::process_interfaces(Thread *thread) { |
854 void InstanceKlass::process_interfaces(Thread *thread) { |
619 // link this class into the implementors list of every interface it implements |
855 // link this class into the implementors list of every interface it implements |
620 KlassHandle this_as_oop (thread, this->as_klassOop()); |
856 Klass* this_as_klass_oop = this; |
621 for (int i = local_interfaces()->length() - 1; i >= 0; i--) { |
857 for (int i = local_interfaces()->length() - 1; i >= 0; i--) { |
622 assert(local_interfaces()->obj_at(i)->is_klass(), "must be a klass"); |
858 assert(local_interfaces()->at(i)->is_klass(), "must be a klass"); |
623 instanceKlass* interf = instanceKlass::cast(klassOop(local_interfaces()->obj_at(i))); |
859 InstanceKlass* interf = InstanceKlass::cast(local_interfaces()->at(i)); |
624 assert(interf->is_interface(), "expected interface"); |
860 assert(interf->is_interface(), "expected interface"); |
625 interf->add_implementor(this_as_oop()); |
861 interf->add_implementor(this_as_klass_oop); |
626 } |
862 } |
627 } |
863 } |
628 |
864 |
629 bool instanceKlass::can_be_primary_super_slow() const { |
865 bool InstanceKlass::can_be_primary_super_slow() const { |
630 if (is_interface()) |
866 if (is_interface()) |
631 return false; |
867 return false; |
632 else |
868 else |
633 return Klass::can_be_primary_super_slow(); |
869 return Klass::can_be_primary_super_slow(); |
634 } |
870 } |
635 |
871 |
636 objArrayOop instanceKlass::compute_secondary_supers(int num_extra_slots, TRAPS) { |
872 GrowableArray<Klass*>* InstanceKlass::compute_secondary_supers(int num_extra_slots) { |
637 // The secondaries are the implemented interfaces. |
873 // The secondaries are the implemented interfaces. |
638 instanceKlass* ik = instanceKlass::cast(as_klassOop()); |
874 InstanceKlass* ik = InstanceKlass::cast(this); |
639 objArrayHandle interfaces (THREAD, ik->transitive_interfaces()); |
875 Array<Klass*>* interfaces = ik->transitive_interfaces(); |
640 int num_secondaries = num_extra_slots + interfaces->length(); |
876 int num_secondaries = num_extra_slots + interfaces->length(); |
641 if (num_secondaries == 0) { |
877 if (num_secondaries == 0) { |
642 return Universe::the_empty_system_obj_array(); |
878 // Must share this for correct bootstrapping! |
|
879 set_secondary_supers(Universe::the_empty_klass_array()); |
|
880 return NULL; |
643 } else if (num_extra_slots == 0) { |
881 } else if (num_extra_slots == 0) { |
644 return interfaces(); |
882 // The secondary super list is exactly the same as the transitive interfaces. |
|
883 // Redefine classes has to be careful not to delete this! |
|
884 set_secondary_supers(interfaces); |
|
885 return NULL; |
645 } else { |
886 } else { |
646 // a mix of both |
887 // Copy transitive interfaces to a temporary growable array to be constructed |
647 objArrayOop secondaries = oopFactory::new_system_objArray(num_secondaries, CHECK_NULL); |
888 // into the secondary super list with extra slots. |
|
889 GrowableArray<Klass*>* secondaries = new GrowableArray<Klass*>(interfaces->length()); |
648 for (int i = 0; i < interfaces->length(); i++) { |
890 for (int i = 0; i < interfaces->length(); i++) { |
649 secondaries->obj_at_put(num_extra_slots+i, interfaces->obj_at(i)); |
891 secondaries->push(interfaces->at(i)); |
650 } |
892 } |
651 return secondaries; |
893 return secondaries; |
652 } |
894 } |
653 } |
895 } |
654 |
896 |
655 bool instanceKlass::compute_is_subtype_of(klassOop k) { |
897 bool InstanceKlass::compute_is_subtype_of(Klass* k) { |
656 if (Klass::cast(k)->is_interface()) { |
898 if (Klass::cast(k)->is_interface()) { |
657 return implements_interface(k); |
899 return implements_interface(k); |
658 } else { |
900 } else { |
659 return Klass::compute_is_subtype_of(k); |
901 return Klass::compute_is_subtype_of(k); |
660 } |
902 } |
661 } |
903 } |
662 |
904 |
663 bool instanceKlass::implements_interface(klassOop k) const { |
905 bool InstanceKlass::implements_interface(Klass* k) const { |
664 if (as_klassOop() == k) return true; |
906 if (this == k) return true; |
665 assert(Klass::cast(k)->is_interface(), "should be an interface class"); |
907 assert(Klass::cast(k)->is_interface(), "should be an interface class"); |
666 for (int i = 0; i < transitive_interfaces()->length(); i++) { |
908 for (int i = 0; i < transitive_interfaces()->length(); i++) { |
667 if (transitive_interfaces()->obj_at(i) == k) { |
909 if (transitive_interfaces()->at(i) == k) { |
668 return true; |
910 return true; |
669 } |
911 } |
670 } |
912 } |
671 return false; |
913 return false; |
672 } |
914 } |
673 |
915 |
674 objArrayOop instanceKlass::allocate_objArray(int n, int length, TRAPS) { |
916 objArrayOop InstanceKlass::allocate_objArray(int n, int length, TRAPS) { |
675 if (length < 0) THROW_0(vmSymbols::java_lang_NegativeArraySizeException()); |
917 if (length < 0) THROW_0(vmSymbols::java_lang_NegativeArraySizeException()); |
676 if (length > arrayOopDesc::max_array_length(T_OBJECT)) { |
918 if (length > arrayOopDesc::max_array_length(T_OBJECT)) { |
677 report_java_out_of_memory("Requested array size exceeds VM limit"); |
919 report_java_out_of_memory("Requested array size exceeds VM limit"); |
678 JvmtiExport::post_array_size_exhausted(); |
920 JvmtiExport::post_array_size_exhausted(); |
679 THROW_OOP_0(Universe::out_of_memory_error_array_size()); |
921 THROW_OOP_0(Universe::out_of_memory_error_array_size()); |
680 } |
922 } |
681 int size = objArrayOopDesc::object_size(length); |
923 int size = objArrayOopDesc::object_size(length); |
682 klassOop ak = array_klass(n, CHECK_NULL); |
924 Klass* ak = array_klass(n, CHECK_NULL); |
683 KlassHandle h_ak (THREAD, ak); |
925 KlassHandle h_ak (THREAD, ak); |
684 objArrayOop o = |
926 objArrayOop o = |
685 (objArrayOop)CollectedHeap::array_allocate(h_ak, size, length, CHECK_NULL); |
927 (objArrayOop)CollectedHeap::array_allocate(h_ak, size, length, CHECK_NULL); |
686 return o; |
928 return o; |
687 } |
929 } |
688 |
930 |
689 instanceOop instanceKlass::register_finalizer(instanceOop i, TRAPS) { |
931 instanceOop InstanceKlass::register_finalizer(instanceOop i, TRAPS) { |
690 if (TraceFinalizerRegistration) { |
932 if (TraceFinalizerRegistration) { |
691 tty->print("Registered "); |
933 tty->print("Registered "); |
692 i->print_value_on(tty); |
934 i->print_value_on(tty); |
693 tty->print_cr(" (" INTPTR_FORMAT ") as finalizable", (address)i); |
935 tty->print_cr(" (" INTPTR_FORMAT ") as finalizable", (address)i); |
694 } |
936 } |
699 methodHandle mh (THREAD, Universe::finalizer_register_method()); |
941 methodHandle mh (THREAD, Universe::finalizer_register_method()); |
700 JavaCalls::call(&result, mh, &args, CHECK_NULL); |
942 JavaCalls::call(&result, mh, &args, CHECK_NULL); |
701 return h_i(); |
943 return h_i(); |
702 } |
944 } |
703 |
945 |
704 instanceOop instanceKlass::allocate_instance(TRAPS) { |
946 instanceOop InstanceKlass::allocate_instance(TRAPS) { |
705 assert(!oop_is_instanceMirror(), "wrong allocation path"); |
|
706 bool has_finalizer_flag = has_finalizer(); // Query before possible GC |
947 bool has_finalizer_flag = has_finalizer(); // Query before possible GC |
707 int size = size_helper(); // Query before forming handle. |
948 int size = size_helper(); // Query before forming handle. |
708 |
949 |
709 KlassHandle h_k(THREAD, as_klassOop()); |
950 KlassHandle h_k(THREAD, this); |
710 |
951 |
711 instanceOop i; |
952 instanceOop i; |
712 |
953 |
713 i = (instanceOop)CollectedHeap::obj_allocate(h_k, size, CHECK_NULL); |
954 i = (instanceOop)CollectedHeap::obj_allocate(h_k, size, CHECK_NULL); |
714 if (has_finalizer_flag && !RegisterFinalizersAtInit) { |
955 if (has_finalizer_flag && !RegisterFinalizersAtInit) { |
715 i = register_finalizer(i, CHECK_NULL); |
956 i = register_finalizer(i, CHECK_NULL); |
716 } |
957 } |
717 return i; |
958 return i; |
718 } |
959 } |
719 |
960 |
720 instanceOop instanceKlass::allocate_permanent_instance(TRAPS) { |
961 void InstanceKlass::check_valid_for_instantiation(bool throwError, TRAPS) { |
721 // Finalizer registration occurs in the Object.<init> constructor |
|
722 // and constructors normally aren't run when allocating perm |
|
723 // instances so simply disallow finalizable perm objects. This can |
|
724 // be relaxed if a need for it is found. |
|
725 assert(!has_finalizer(), "perm objects not allowed to have finalizers"); |
|
726 assert(!oop_is_instanceMirror(), "wrong allocation path"); |
|
727 int size = size_helper(); // Query before forming handle. |
|
728 KlassHandle h_k(THREAD, as_klassOop()); |
|
729 instanceOop i = (instanceOop) |
|
730 CollectedHeap::permanent_obj_allocate(h_k, size, CHECK_NULL); |
|
731 return i; |
|
732 } |
|
733 |
|
734 void instanceKlass::check_valid_for_instantiation(bool throwError, TRAPS) { |
|
735 if (is_interface() || is_abstract()) { |
962 if (is_interface() || is_abstract()) { |
736 ResourceMark rm(THREAD); |
963 ResourceMark rm(THREAD); |
737 THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError() |
964 THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError() |
738 : vmSymbols::java_lang_InstantiationException(), external_name()); |
965 : vmSymbols::java_lang_InstantiationException(), external_name()); |
739 } |
966 } |
740 if (as_klassOop() == SystemDictionary::Class_klass()) { |
967 if (this == SystemDictionary::Class_klass()) { |
741 ResourceMark rm(THREAD); |
968 ResourceMark rm(THREAD); |
742 THROW_MSG(throwError ? vmSymbols::java_lang_IllegalAccessError() |
969 THROW_MSG(throwError ? vmSymbols::java_lang_IllegalAccessError() |
743 : vmSymbols::java_lang_IllegalAccessException(), external_name()); |
970 : vmSymbols::java_lang_IllegalAccessException(), external_name()); |
744 } |
971 } |
745 } |
972 } |
746 |
973 |
747 klassOop instanceKlass::array_klass_impl(bool or_null, int n, TRAPS) { |
974 Klass* InstanceKlass::array_klass_impl(bool or_null, int n, TRAPS) { |
748 instanceKlassHandle this_oop(THREAD, as_klassOop()); |
975 instanceKlassHandle this_oop(THREAD, this); |
749 return array_klass_impl(this_oop, or_null, n, THREAD); |
976 return array_klass_impl(this_oop, or_null, n, THREAD); |
750 } |
977 } |
751 |
978 |
752 klassOop instanceKlass::array_klass_impl(instanceKlassHandle this_oop, bool or_null, int n, TRAPS) { |
979 Klass* InstanceKlass::array_klass_impl(instanceKlassHandle this_oop, bool or_null, int n, TRAPS) { |
753 if (this_oop->array_klasses() == NULL) { |
980 if (this_oop->array_klasses() == NULL) { |
754 if (or_null) return NULL; |
981 if (or_null) return NULL; |
755 |
982 |
756 ResourceMark rm; |
983 ResourceMark rm; |
757 JavaThread *jt = (JavaThread *)THREAD; |
984 JavaThread *jt = (JavaThread *)THREAD; |
760 MutexLocker mc(Compile_lock, THREAD); // for vtables |
987 MutexLocker mc(Compile_lock, THREAD); // for vtables |
761 MutexLocker ma(MultiArray_lock, THREAD); |
988 MutexLocker ma(MultiArray_lock, THREAD); |
762 |
989 |
763 // Check if update has already taken place |
990 // Check if update has already taken place |
764 if (this_oop->array_klasses() == NULL) { |
991 if (this_oop->array_klasses() == NULL) { |
765 objArrayKlassKlass* oakk = |
992 Klass* k = objArrayKlass::allocate_objArray_klass(this_oop->class_loader_data(), 1, this_oop, CHECK_NULL); |
766 (objArrayKlassKlass*)Universe::objArrayKlassKlassObj()->klass_part(); |
|
767 |
|
768 klassOop k = oakk->allocate_objArray_klass(1, this_oop, CHECK_NULL); |
|
769 this_oop->set_array_klasses(k); |
993 this_oop->set_array_klasses(k); |
770 } |
994 } |
771 } |
995 } |
772 } |
996 } |
773 // _this will always be set at this point |
997 // _this will always be set at this point |
774 objArrayKlass* oak = (objArrayKlass*)this_oop->array_klasses()->klass_part(); |
998 objArrayKlass* oak = (objArrayKlass*)this_oop->array_klasses(); |
775 if (or_null) { |
999 if (or_null) { |
776 return oak->array_klass_or_null(n); |
1000 return oak->array_klass_or_null(n); |
777 } |
1001 } |
778 return oak->array_klass(n, CHECK_NULL); |
1002 return oak->array_klass(n, CHECK_NULL); |
779 } |
1003 } |
780 |
1004 |
781 klassOop instanceKlass::array_klass_impl(bool or_null, TRAPS) { |
1005 Klass* InstanceKlass::array_klass_impl(bool or_null, TRAPS) { |
782 return array_klass_impl(or_null, 1, THREAD); |
1006 return array_klass_impl(or_null, 1, THREAD); |
783 } |
1007 } |
784 |
1008 |
785 void instanceKlass::call_class_initializer(TRAPS) { |
1009 void InstanceKlass::call_class_initializer(TRAPS) { |
786 instanceKlassHandle ik (THREAD, as_klassOop()); |
1010 instanceKlassHandle ik (THREAD, this); |
787 call_class_initializer_impl(ik, THREAD); |
1011 call_class_initializer_impl(ik, THREAD); |
788 } |
1012 } |
789 |
1013 |
790 static int call_class_initializer_impl_counter = 0; // for debugging |
1014 static int call_class_initializer_impl_counter = 0; // for debugging |
791 |
1015 |
792 methodOop instanceKlass::class_initializer() { |
1016 Method* InstanceKlass::class_initializer() { |
793 methodOop clinit = find_method( |
1017 Method* clinit = find_method( |
794 vmSymbols::class_initializer_name(), vmSymbols::void_method_signature()); |
1018 vmSymbols::class_initializer_name(), vmSymbols::void_method_signature()); |
795 if (clinit != NULL && clinit->has_valid_initializer_flags()) { |
1019 if (clinit != NULL && clinit->has_valid_initializer_flags()) { |
796 return clinit; |
1020 return clinit; |
797 } |
1021 } |
798 return NULL; |
1022 return NULL; |
799 } |
1023 } |
800 |
1024 |
801 void instanceKlass::call_class_initializer_impl(instanceKlassHandle this_oop, TRAPS) { |
1025 void InstanceKlass::call_class_initializer_impl(instanceKlassHandle this_oop, TRAPS) { |
802 methodHandle h_method(THREAD, this_oop->class_initializer()); |
1026 methodHandle h_method(THREAD, this_oop->class_initializer()); |
803 assert(!this_oop->is_initialized(), "we cannot initialize twice"); |
1027 assert(!this_oop->is_initialized(), "we cannot initialize twice"); |
804 if (TraceClassInitialization) { |
1028 if (TraceClassInitialization) { |
805 tty->print("%d Initializing ", call_class_initializer_impl_counter++); |
1029 tty->print("%d Initializing ", call_class_initializer_impl_counter++); |
806 this_oop->name()->print_value(); |
1030 this_oop->name()->print_value(); |
828 // _oop_map_cache is constant after init; lookup below does is own locking. |
1052 // _oop_map_cache is constant after init; lookup below does is own locking. |
829 _oop_map_cache->lookup(method, bci, entry_for); |
1053 _oop_map_cache->lookup(method, bci, entry_for); |
830 } |
1054 } |
831 |
1055 |
832 |
1056 |
833 bool instanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const { |
1057 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const { |
834 for (JavaFieldStream fs(as_klassOop()); !fs.done(); fs.next()) { |
1058 for (JavaFieldStream fs(this); !fs.done(); fs.next()) { |
835 Symbol* f_name = fs.name(); |
1059 Symbol* f_name = fs.name(); |
836 Symbol* f_sig = fs.signature(); |
1060 Symbol* f_sig = fs.signature(); |
837 if (f_name == name && f_sig == sig) { |
1061 if (f_name == name && f_sig == sig) { |
838 fd->initialize(as_klassOop(), fs.index()); |
1062 fd->initialize(const_cast<InstanceKlass*>(this), fs.index()); |
839 return true; |
1063 return true; |
840 } |
1064 } |
841 } |
1065 } |
842 return false; |
1066 return false; |
843 } |
1067 } |
844 |
1068 |
845 |
1069 |
846 void instanceKlass::shared_symbols_iterate(SymbolClosure* closure) { |
1070 Klass* InstanceKlass::find_interface_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const { |
847 Klass::shared_symbols_iterate(closure); |
|
848 closure->do_symbol(&_generic_signature); |
|
849 closure->do_symbol(&_source_file_name); |
|
850 |
|
851 for (JavaFieldStream fs(this); !fs.done(); fs.next()) { |
|
852 int name_index = fs.name_index(); |
|
853 closure->do_symbol(constants()->symbol_at_addr(name_index)); |
|
854 int sig_index = fs.signature_index(); |
|
855 closure->do_symbol(constants()->symbol_at_addr(sig_index)); |
|
856 } |
|
857 } |
|
858 |
|
859 |
|
860 klassOop instanceKlass::find_interface_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const { |
|
861 const int n = local_interfaces()->length(); |
1071 const int n = local_interfaces()->length(); |
862 for (int i = 0; i < n; i++) { |
1072 for (int i = 0; i < n; i++) { |
863 klassOop intf1 = klassOop(local_interfaces()->obj_at(i)); |
1073 Klass* intf1 = local_interfaces()->at(i); |
864 assert(Klass::cast(intf1)->is_interface(), "just checking type"); |
1074 assert(Klass::cast(intf1)->is_interface(), "just checking type"); |
865 // search for field in current interface |
1075 // search for field in current interface |
866 if (instanceKlass::cast(intf1)->find_local_field(name, sig, fd)) { |
1076 if (InstanceKlass::cast(intf1)->find_local_field(name, sig, fd)) { |
867 assert(fd->is_static(), "interface field must be static"); |
1077 assert(fd->is_static(), "interface field must be static"); |
868 return intf1; |
1078 return intf1; |
869 } |
1079 } |
870 // search for field in direct superinterfaces |
1080 // search for field in direct superinterfaces |
871 klassOop intf2 = instanceKlass::cast(intf1)->find_interface_field(name, sig, fd); |
1081 Klass* intf2 = InstanceKlass::cast(intf1)->find_interface_field(name, sig, fd); |
872 if (intf2 != NULL) return intf2; |
1082 if (intf2 != NULL) return intf2; |
873 } |
1083 } |
874 // otherwise field lookup fails |
1084 // otherwise field lookup fails |
875 return NULL; |
1085 return NULL; |
876 } |
1086 } |
877 |
1087 |
878 |
1088 |
879 klassOop instanceKlass::find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const { |
1089 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const { |
880 // search order according to newest JVM spec (5.4.3.2, p.167). |
1090 // search order according to newest JVM spec (5.4.3.2, p.167). |
881 // 1) search for field in current klass |
1091 // 1) search for field in current klass |
882 if (find_local_field(name, sig, fd)) { |
1092 if (find_local_field(name, sig, fd)) { |
883 return as_klassOop(); |
1093 return const_cast<InstanceKlass*>(this); |
884 } |
1094 } |
885 // 2) search for field recursively in direct superinterfaces |
1095 // 2) search for field recursively in direct superinterfaces |
886 { klassOop intf = find_interface_field(name, sig, fd); |
1096 { Klass* intf = find_interface_field(name, sig, fd); |
887 if (intf != NULL) return intf; |
1097 if (intf != NULL) return intf; |
888 } |
1098 } |
889 // 3) apply field lookup recursively if superclass exists |
1099 // 3) apply field lookup recursively if superclass exists |
890 { klassOop supr = super(); |
1100 { Klass* supr = super(); |
891 if (supr != NULL) return instanceKlass::cast(supr)->find_field(name, sig, fd); |
1101 if (supr != NULL) return InstanceKlass::cast(supr)->find_field(name, sig, fd); |
892 } |
1102 } |
893 // 4) otherwise field lookup fails |
1103 // 4) otherwise field lookup fails |
894 return NULL; |
1104 return NULL; |
895 } |
1105 } |
896 |
1106 |
897 |
1107 |
898 klassOop instanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const { |
1108 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const { |
899 // search order according to newest JVM spec (5.4.3.2, p.167). |
1109 // search order according to newest JVM spec (5.4.3.2, p.167). |
900 // 1) search for field in current klass |
1110 // 1) search for field in current klass |
901 if (find_local_field(name, sig, fd)) { |
1111 if (find_local_field(name, sig, fd)) { |
902 if (fd->is_static() == is_static) return as_klassOop(); |
1112 if (fd->is_static() == is_static) return const_cast<InstanceKlass*>(this); |
903 } |
1113 } |
904 // 2) search for field recursively in direct superinterfaces |
1114 // 2) search for field recursively in direct superinterfaces |
905 if (is_static) { |
1115 if (is_static) { |
906 klassOop intf = find_interface_field(name, sig, fd); |
1116 Klass* intf = find_interface_field(name, sig, fd); |
907 if (intf != NULL) return intf; |
1117 if (intf != NULL) return intf; |
908 } |
1118 } |
909 // 3) apply field lookup recursively if superclass exists |
1119 // 3) apply field lookup recursively if superclass exists |
910 { klassOop supr = super(); |
1120 { Klass* supr = super(); |
911 if (supr != NULL) return instanceKlass::cast(supr)->find_field(name, sig, is_static, fd); |
1121 if (supr != NULL) return InstanceKlass::cast(supr)->find_field(name, sig, is_static, fd); |
912 } |
1122 } |
913 // 4) otherwise field lookup fails |
1123 // 4) otherwise field lookup fails |
914 return NULL; |
1124 return NULL; |
915 } |
1125 } |
916 |
1126 |
917 |
1127 |
918 bool instanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const { |
1128 bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const { |
919 for (JavaFieldStream fs(as_klassOop()); !fs.done(); fs.next()) { |
1129 for (JavaFieldStream fs(this); !fs.done(); fs.next()) { |
920 if (fs.offset() == offset) { |
1130 if (fs.offset() == offset) { |
921 fd->initialize(as_klassOop(), fs.index()); |
1131 fd->initialize(const_cast<InstanceKlass*>(this), fs.index()); |
922 if (fd->is_static() == is_static) return true; |
1132 if (fd->is_static() == is_static) return true; |
923 } |
1133 } |
924 } |
1134 } |
925 return false; |
1135 return false; |
926 } |
1136 } |
927 |
1137 |
928 |
1138 |
929 bool instanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const { |
1139 bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const { |
930 klassOop klass = as_klassOop(); |
1140 Klass* klass = const_cast<InstanceKlass*>(this); |
931 while (klass != NULL) { |
1141 while (klass != NULL) { |
932 if (instanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) { |
1142 if (InstanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) { |
933 return true; |
1143 return true; |
934 } |
1144 } |
935 klass = Klass::cast(klass)->super(); |
1145 klass = Klass::cast(klass)->super(); |
936 } |
1146 } |
937 return false; |
1147 return false; |
938 } |
1148 } |
939 |
1149 |
940 |
1150 |
941 void instanceKlass::methods_do(void f(methodOop method)) { |
1151 void InstanceKlass::methods_do(void f(Method* method)) { |
942 int len = methods()->length(); |
1152 int len = methods()->length(); |
943 for (int index = 0; index < len; index++) { |
1153 for (int index = 0; index < len; index++) { |
944 methodOop m = methodOop(methods()->obj_at(index)); |
1154 Method* m = methods()->at(index); |
945 assert(m->is_method(), "must be method"); |
1155 assert(m->is_method(), "must be method"); |
946 f(m); |
1156 f(m); |
947 } |
1157 } |
948 } |
1158 } |
949 |
1159 |
950 |
1160 |
951 void instanceKlass::do_local_static_fields(FieldClosure* cl) { |
1161 void InstanceKlass::do_local_static_fields(FieldClosure* cl) { |
952 for (JavaFieldStream fs(this); !fs.done(); fs.next()) { |
1162 for (JavaFieldStream fs(this); !fs.done(); fs.next()) { |
953 if (fs.access_flags().is_static()) { |
1163 if (fs.access_flags().is_static()) { |
954 fieldDescriptor fd; |
1164 fieldDescriptor fd; |
955 fd.initialize(as_klassOop(), fs.index()); |
1165 fd.initialize(this, fs.index()); |
956 cl->do_field(&fd); |
1166 cl->do_field(&fd); |
957 } |
1167 } |
958 } |
1168 } |
959 } |
1169 } |
960 |
1170 |
961 |
1171 |
962 void instanceKlass::do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS) { |
1172 void InstanceKlass::do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS) { |
963 instanceKlassHandle h_this(THREAD, as_klassOop()); |
1173 instanceKlassHandle h_this(THREAD, this); |
964 do_local_static_fields_impl(h_this, f, CHECK); |
1174 do_local_static_fields_impl(h_this, f, CHECK); |
965 } |
1175 } |
966 |
1176 |
967 |
1177 |
968 void instanceKlass::do_local_static_fields_impl(instanceKlassHandle this_oop, void f(fieldDescriptor* fd, TRAPS), TRAPS) { |
1178 void InstanceKlass::do_local_static_fields_impl(instanceKlassHandle this_oop, void f(fieldDescriptor* fd, TRAPS), TRAPS) { |
969 for (JavaFieldStream fs(this_oop()); !fs.done(); fs.next()) { |
1179 for (JavaFieldStream fs(this_oop()); !fs.done(); fs.next()) { |
970 if (fs.access_flags().is_static()) { |
1180 if (fs.access_flags().is_static()) { |
971 fieldDescriptor fd; |
1181 fieldDescriptor fd; |
972 fd.initialize(this_oop(), fs.index()); |
1182 fd.initialize(this_oop(), fs.index()); |
973 f(&fd, CHECK); |
1183 f(&fd, CHECK); |
1001 if (j > 0) { |
1211 if (j > 0) { |
1002 length = j; |
1212 length = j; |
1003 // _sort_Fn is defined in growableArray.hpp. |
1213 // _sort_Fn is defined in growableArray.hpp. |
1004 qsort(fields_sorted, length/2, 2*sizeof(int), (_sort_Fn)compare_fields_by_offset); |
1214 qsort(fields_sorted, length/2, 2*sizeof(int), (_sort_Fn)compare_fields_by_offset); |
1005 for (int i = 0; i < length; i += 2) { |
1215 for (int i = 0; i < length; i += 2) { |
1006 fd.initialize(as_klassOop(), fields_sorted[i + 1]); |
1216 fd.initialize(this, fields_sorted[i + 1]); |
1007 assert(!fd.is_static() && fd.offset() == fields_sorted[i], "only nonstatic fields"); |
1217 assert(!fd.is_static() && fd.offset() == fields_sorted[i], "only nonstatic fields"); |
1008 cl->do_field(&fd); |
1218 cl->do_field(&fd); |
1009 } |
1219 } |
1010 } |
1220 } |
1011 FREE_C_HEAP_ARRAY(int, fields_sorted, mtClass); |
1221 FREE_C_HEAP_ARRAY(int, fields_sorted, mtClass); |
1012 } |
1222 } |
1013 |
1223 |
1014 |
1224 |
1015 void instanceKlass::array_klasses_do(void f(klassOop k)) { |
1225 void InstanceKlass::array_klasses_do(void f(Klass* k, TRAPS), TRAPS) { |
|
1226 if (array_klasses() != NULL) |
|
1227 arrayKlass::cast(array_klasses())->array_klasses_do(f, THREAD); |
|
1228 } |
|
1229 |
|
1230 void InstanceKlass::array_klasses_do(void f(Klass* k)) { |
1016 if (array_klasses() != NULL) |
1231 if (array_klasses() != NULL) |
1017 arrayKlass::cast(array_klasses())->array_klasses_do(f); |
1232 arrayKlass::cast(array_klasses())->array_klasses_do(f); |
1018 } |
1233 } |
1019 |
1234 |
1020 |
1235 |
1021 void instanceKlass::with_array_klasses_do(void f(klassOop k)) { |
1236 void InstanceKlass::with_array_klasses_do(void f(Klass* k)) { |
1022 f(as_klassOop()); |
1237 f(this); |
1023 array_klasses_do(f); |
1238 array_klasses_do(f); |
1024 } |
1239 } |
1025 |
1240 |
1026 #ifdef ASSERT |
1241 #ifdef ASSERT |
1027 static int linear_search(objArrayOop methods, Symbol* name, Symbol* signature) { |
1242 static int linear_search(Array<Method*>* methods, Symbol* name, Symbol* signature) { |
1028 int len = methods->length(); |
1243 int len = methods->length(); |
1029 for (int index = 0; index < len; index++) { |
1244 for (int index = 0; index < len; index++) { |
1030 methodOop m = (methodOop)(methods->obj_at(index)); |
1245 Method* m = methods->at(index); |
1031 assert(m->is_method(), "must be method"); |
1246 assert(m->is_method(), "must be method"); |
1032 if (m->signature() == signature && m->name() == name) { |
1247 if (m->signature() == signature && m->name() == name) { |
1033 return index; |
1248 return index; |
1034 } |
1249 } |
1035 } |
1250 } |
1036 return -1; |
1251 return -1; |
1037 } |
1252 } |
1038 #endif |
1253 #endif |
1039 |
1254 |
1040 methodOop instanceKlass::find_method(Symbol* name, Symbol* signature) const { |
1255 Method* InstanceKlass::find_method(Symbol* name, Symbol* signature) const { |
1041 return instanceKlass::find_method(methods(), name, signature); |
1256 return InstanceKlass::find_method(methods(), name, signature); |
1042 } |
1257 } |
1043 |
1258 |
1044 methodOop instanceKlass::find_method(objArrayOop methods, Symbol* name, Symbol* signature) { |
1259 Method* InstanceKlass::find_method(Array<Method*>* methods, Symbol* name, Symbol* signature) { |
1045 int len = methods->length(); |
1260 int len = methods->length(); |
1046 // methods are sorted, so do binary search |
1261 // methods are sorted, so do binary search |
1047 int l = 0; |
1262 int l = 0; |
1048 int h = len - 1; |
1263 int h = len - 1; |
1049 while (l <= h) { |
1264 while (l <= h) { |
1050 int mid = (l + h) >> 1; |
1265 int mid = (l + h) >> 1; |
1051 methodOop m = (methodOop)methods->obj_at(mid); |
1266 Method* m = methods->at(mid); |
1052 assert(m->is_method(), "must be method"); |
1267 assert(m->is_method(), "must be method"); |
1053 int res = m->name()->fast_compare(name); |
1268 int res = m->name()->fast_compare(name); |
1054 if (res == 0) { |
1269 if (res == 0) { |
1055 // found matching name; do linear search to find matching signature |
1270 // found matching name; do linear search to find matching signature |
1056 // first, quick check for common case |
1271 // first, quick check for common case |
1057 if (m->signature() == signature) return m; |
1272 if (m->signature() == signature) return m; |
1058 // search downwards through overloaded methods |
1273 // search downwards through overloaded methods |
1059 int i; |
1274 int i; |
1060 for (i = mid - 1; i >= l; i--) { |
1275 for (i = mid - 1; i >= l; i--) { |
1061 methodOop m = (methodOop)methods->obj_at(i); |
1276 Method* m = methods->at(i); |
1062 assert(m->is_method(), "must be method"); |
1277 assert(m->is_method(), "must be method"); |
1063 if (m->name() != name) break; |
1278 if (m->name() != name) break; |
1064 if (m->signature() == signature) return m; |
1279 if (m->signature() == signature) return m; |
1065 } |
1280 } |
1066 // search upwards |
1281 // search upwards |
1067 for (i = mid + 1; i <= h; i++) { |
1282 for (i = mid + 1; i <= h; i++) { |
1068 methodOop m = (methodOop)methods->obj_at(i); |
1283 Method* m = methods->at(i); |
1069 assert(m->is_method(), "must be method"); |
1284 assert(m->is_method(), "must be method"); |
1070 if (m->name() != name) break; |
1285 if (m->name() != name) break; |
1071 if (m->signature() == signature) return m; |
1286 if (m->signature() == signature) return m; |
1072 } |
1287 } |
1073 // not found |
1288 // not found |
1087 assert(index == -1, err_msg("binary search should have found entry %d", index)); |
1302 assert(index == -1, err_msg("binary search should have found entry %d", index)); |
1088 #endif |
1303 #endif |
1089 return NULL; |
1304 return NULL; |
1090 } |
1305 } |
1091 |
1306 |
1092 methodOop instanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature) const { |
1307 Method* InstanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature) const { |
1093 klassOop klass = as_klassOop(); |
1308 Klass* klass = const_cast<InstanceKlass*>(this); |
1094 while (klass != NULL) { |
1309 while (klass != NULL) { |
1095 methodOop method = instanceKlass::cast(klass)->find_method(name, signature); |
1310 Method* method = InstanceKlass::cast(klass)->find_method(name, signature); |
1096 if (method != NULL) return method; |
1311 if (method != NULL) return method; |
1097 klass = instanceKlass::cast(klass)->super(); |
1312 klass = InstanceKlass::cast(klass)->super(); |
1098 } |
1313 } |
1099 return NULL; |
1314 return NULL; |
1100 } |
1315 } |
1101 |
1316 |
1102 // lookup a method in all the interfaces that this class implements |
1317 // lookup a method in all the interfaces that this class implements |
1103 methodOop instanceKlass::lookup_method_in_all_interfaces(Symbol* name, |
1318 Method* InstanceKlass::lookup_method_in_all_interfaces(Symbol* name, |
1104 Symbol* signature) const { |
1319 Symbol* signature) const { |
1105 objArrayOop all_ifs = instanceKlass::cast(as_klassOop())->transitive_interfaces(); |
1320 Array<Klass*>* all_ifs = transitive_interfaces(); |
1106 int num_ifs = all_ifs->length(); |
1321 int num_ifs = all_ifs->length(); |
1107 instanceKlass *ik = NULL; |
1322 InstanceKlass *ik = NULL; |
1108 for (int i = 0; i < num_ifs; i++) { |
1323 for (int i = 0; i < num_ifs; i++) { |
1109 ik = instanceKlass::cast(klassOop(all_ifs->obj_at(i))); |
1324 ik = InstanceKlass::cast(all_ifs->at(i)); |
1110 methodOop m = ik->lookup_method(name, signature); |
1325 Method* m = ik->lookup_method(name, signature); |
1111 if (m != NULL) { |
1326 if (m != NULL) { |
1112 return m; |
1327 return m; |
1113 } |
1328 } |
1114 } |
1329 } |
1115 return NULL; |
1330 return NULL; |
1116 } |
1331 } |
1117 |
1332 |
1118 /* jni_id_for_impl for jfieldIds only */ |
1333 /* jni_id_for_impl for jfieldIds only */ |
1119 JNIid* instanceKlass::jni_id_for_impl(instanceKlassHandle this_oop, int offset) { |
1334 JNIid* InstanceKlass::jni_id_for_impl(instanceKlassHandle this_oop, int offset) { |
1120 MutexLocker ml(JfieldIdCreation_lock); |
1335 MutexLocker ml(JfieldIdCreation_lock); |
1121 // Retry lookup after we got the lock |
1336 // Retry lookup after we got the lock |
1122 JNIid* probe = this_oop->jni_ids() == NULL ? NULL : this_oop->jni_ids()->find(offset); |
1337 JNIid* probe = this_oop->jni_ids() == NULL ? NULL : this_oop->jni_ids()->find(offset); |
1123 if (probe == NULL) { |
1338 if (probe == NULL) { |
1124 // Slow case, allocate new static field identifier |
1339 // Slow case, allocate new static field identifier |
1125 probe = new JNIid(this_oop->as_klassOop(), offset, this_oop->jni_ids()); |
1340 probe = new JNIid(this_oop(), offset, this_oop->jni_ids()); |
1126 this_oop->set_jni_ids(probe); |
1341 this_oop->set_jni_ids(probe); |
1127 } |
1342 } |
1128 return probe; |
1343 return probe; |
1129 } |
1344 } |
1130 |
1345 |
1131 |
1346 |
1132 /* jni_id_for for jfieldIds only */ |
1347 /* jni_id_for for jfieldIds only */ |
1133 JNIid* instanceKlass::jni_id_for(int offset) { |
1348 JNIid* InstanceKlass::jni_id_for(int offset) { |
1134 JNIid* probe = jni_ids() == NULL ? NULL : jni_ids()->find(offset); |
1349 JNIid* probe = jni_ids() == NULL ? NULL : jni_ids()->find(offset); |
1135 if (probe == NULL) { |
1350 if (probe == NULL) { |
1136 probe = jni_id_for_impl(this->as_klassOop(), offset); |
1351 probe = jni_id_for_impl(this, offset); |
1137 } |
1352 } |
1138 return probe; |
1353 return probe; |
1139 } |
1354 } |
1140 |
1355 |
1141 u2 instanceKlass::enclosing_method_data(int offset) { |
1356 u2 InstanceKlass::enclosing_method_data(int offset) { |
1142 typeArrayOop inner_class_list = inner_classes(); |
1357 Array<jushort>* inner_class_list = inner_classes(); |
1143 if (inner_class_list == NULL) { |
1358 if (inner_class_list == NULL) { |
1144 return 0; |
1359 return 0; |
1145 } |
1360 } |
1146 int length = inner_class_list->length(); |
1361 int length = inner_class_list->length(); |
1147 if (length % inner_class_next_offset == 0) { |
1362 if (length % inner_class_next_offset == 0) { |
1148 return 0; |
1363 return 0; |
1149 } else { |
1364 } else { |
1150 int index = length - enclosing_method_attribute_size; |
1365 int index = length - enclosing_method_attribute_size; |
1151 typeArrayHandle inner_class_list_h(inner_class_list); |
|
1152 assert(offset < enclosing_method_attribute_size, "invalid offset"); |
1366 assert(offset < enclosing_method_attribute_size, "invalid offset"); |
1153 return inner_class_list_h->ushort_at(index + offset); |
1367 return inner_class_list->at(index + offset); |
1154 } |
1368 } |
1155 } |
1369 } |
1156 |
1370 |
1157 void instanceKlass::set_enclosing_method_indices(u2 class_index, |
1371 void InstanceKlass::set_enclosing_method_indices(u2 class_index, |
1158 u2 method_index) { |
1372 u2 method_index) { |
1159 typeArrayOop inner_class_list = inner_classes(); |
1373 Array<jushort>* inner_class_list = inner_classes(); |
1160 assert (inner_class_list != NULL, "_inner_classes list is not set up"); |
1374 assert (inner_class_list != NULL, "_inner_classes list is not set up"); |
1161 int length = inner_class_list->length(); |
1375 int length = inner_class_list->length(); |
1162 if (length % inner_class_next_offset == enclosing_method_attribute_size) { |
1376 if (length % inner_class_next_offset == enclosing_method_attribute_size) { |
1163 int index = length - enclosing_method_attribute_size; |
1377 int index = length - enclosing_method_attribute_size; |
1164 typeArrayHandle inner_class_list_h(inner_class_list); |
1378 inner_class_list->at_put( |
1165 inner_class_list_h->ushort_at_put( |
|
1166 index + enclosing_method_class_index_offset, class_index); |
1379 index + enclosing_method_class_index_offset, class_index); |
1167 inner_class_list_h->ushort_at_put( |
1380 inner_class_list->at_put( |
1168 index + enclosing_method_method_index_offset, method_index); |
1381 index + enclosing_method_method_index_offset, method_index); |
1169 } |
1382 } |
1170 } |
1383 } |
1171 |
1384 |
1172 // Lookup or create a jmethodID. |
1385 // Lookup or create a jmethodID. |
1173 // This code is called by the VMThread and JavaThreads so the |
1386 // This code is called by the VMThread and JavaThreads so the |
1174 // locking has to be done very carefully to avoid deadlocks |
1387 // locking has to be done very carefully to avoid deadlocks |
1175 // and/or other cache consistency problems. |
1388 // and/or other cache consistency problems. |
1176 // |
1389 // |
1177 jmethodID instanceKlass::get_jmethod_id(instanceKlassHandle ik_h, methodHandle method_h) { |
1390 jmethodID InstanceKlass::get_jmethod_id(instanceKlassHandle ik_h, methodHandle method_h) { |
1178 size_t idnum = (size_t)method_h->method_idnum(); |
1391 size_t idnum = (size_t)method_h->method_idnum(); |
1179 jmethodID* jmeths = ik_h->methods_jmethod_ids_acquire(); |
1392 jmethodID* jmeths = ik_h->methods_jmethod_ids_acquire(); |
1180 size_t length = 0; |
1393 size_t length = 0; |
1181 jmethodID id = NULL; |
1394 jmethodID id = NULL; |
1182 |
1395 |
1730 ++map; \ |
1955 ++map; \ |
1731 } \ |
1956 } \ |
1732 } \ |
1957 } \ |
1733 } |
1958 } |
1734 |
1959 |
1735 void instanceKlass::oop_follow_contents(oop obj) { |
1960 void InstanceKlass::oop_follow_contents(oop obj) { |
1736 assert(obj != NULL, "can't follow the content of NULL object"); |
1961 assert(obj != NULL, "can't follow the content of NULL object"); |
1737 obj->follow_header(); |
1962 MarkSweep::follow_klass(obj->klass()); |
1738 InstanceKlass_OOP_MAP_ITERATE( \ |
1963 InstanceKlass_OOP_MAP_ITERATE( \ |
1739 obj, \ |
1964 obj, \ |
1740 MarkSweep::mark_and_push(p), \ |
1965 MarkSweep::mark_and_push(p), \ |
1741 assert_is_in_closed_subset) |
1966 assert_is_in_closed_subset) |
1742 } |
1967 } |
1743 |
1968 |
1744 #ifndef SERIALGC |
1969 #ifndef SERIALGC |
1745 void instanceKlass::oop_follow_contents(ParCompactionManager* cm, |
1970 void InstanceKlass::oop_follow_contents(ParCompactionManager* cm, |
1746 oop obj) { |
1971 oop obj) { |
1747 assert(obj != NULL, "can't follow the content of NULL object"); |
1972 assert(obj != NULL, "can't follow the content of NULL object"); |
1748 obj->follow_header(cm); |
1973 PSParallelCompact::follow_klass(cm, obj->klass()); |
|
1974 // Only mark the header and let the scan of the meta-data mark |
|
1975 // everything else. |
1749 InstanceKlass_OOP_MAP_ITERATE( \ |
1976 InstanceKlass_OOP_MAP_ITERATE( \ |
1750 obj, \ |
1977 obj, \ |
1751 PSParallelCompact::mark_and_push(cm, p), \ |
1978 PSParallelCompact::mark_and_push(cm, p), \ |
1752 assert_is_in) |
1979 assert_is_in) |
1753 } |
1980 } |
1754 #endif // SERIALGC |
1981 #endif // SERIALGC |
1755 |
1982 |
1756 // closure's do_header() method dicates whether the given closure should be |
1983 // closure's do_metadata() method dictates whether the given closure should be |
1757 // applied to the klass ptr in the object header. |
1984 // applied to the klass ptr in the object header. |
|
1985 |
|
1986 #define if_do_metadata_checked(closure, nv_suffix) \ |
|
1987 /* Make sure the non-virtual and the virtual versions match. */ \ |
|
1988 assert(closure->do_metadata##nv_suffix() == closure->do_metadata(), \ |
|
1989 "Inconsistency in do_metadata"); \ |
|
1990 if (closure->do_metadata##nv_suffix()) |
1758 |
1991 |
1759 #define InstanceKlass_OOP_OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \ |
1992 #define InstanceKlass_OOP_OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \ |
1760 \ |
1993 \ |
1761 int instanceKlass::oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure) { \ |
1994 int InstanceKlass::oop_oop_iterate##nv_suffix(oop obj, OopClosureType* closure) { \ |
1762 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::ik);\ |
1995 SpecializationStats::record_iterate_call##nv_suffix(SpecializationStats::ik);\ |
1763 /* header */ \ |
1996 /* header */ \ |
1764 if (closure->do_header()) { \ |
1997 if_do_metadata_checked(closure, nv_suffix) { \ |
1765 obj->oop_iterate_header(closure); \ |
1998 closure->do_klass##nv_suffix(obj->klass()); \ |
1766 } \ |
1999 } \ |
1767 InstanceKlass_OOP_MAP_ITERATE( \ |
2000 InstanceKlass_OOP_MAP_ITERATE( \ |
1768 obj, \ |
2001 obj, \ |
1769 SpecializationStats:: \ |
2002 SpecializationStats:: \ |
1770 record_do_oop_call##nv_suffix(SpecializationStats::ik); \ |
2003 record_do_oop_call##nv_suffix(SpecializationStats::ik); \ |
1816 #ifndef SERIALGC |
2051 #ifndef SERIALGC |
1817 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN) |
2052 ALL_OOP_OOP_ITERATE_CLOSURES_1(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN) |
1818 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN) |
2053 ALL_OOP_OOP_ITERATE_CLOSURES_2(InstanceKlass_OOP_OOP_ITERATE_BACKWARDS_DEFN) |
1819 #endif // !SERIALGC |
2054 #endif // !SERIALGC |
1820 |
2055 |
1821 int instanceKlass::oop_adjust_pointers(oop obj) { |
2056 int InstanceKlass::oop_adjust_pointers(oop obj) { |
1822 int size = size_helper(); |
2057 int size = size_helper(); |
1823 InstanceKlass_OOP_MAP_ITERATE( \ |
2058 InstanceKlass_OOP_MAP_ITERATE( \ |
1824 obj, \ |
2059 obj, \ |
1825 MarkSweep::adjust_pointer(p), \ |
2060 MarkSweep::adjust_pointer(p), \ |
1826 assert_is_in) |
2061 assert_is_in) |
1827 obj->adjust_header(); |
2062 MarkSweep::adjust_klass(obj->klass()); |
1828 return size; |
2063 return size; |
1829 } |
2064 } |
1830 |
2065 |
1831 #ifndef SERIALGC |
2066 #ifndef SERIALGC |
1832 void instanceKlass::oop_push_contents(PSPromotionManager* pm, oop obj) { |
2067 void InstanceKlass::oop_push_contents(PSPromotionManager* pm, oop obj) { |
1833 InstanceKlass_OOP_MAP_REVERSE_ITERATE( \ |
2068 InstanceKlass_OOP_MAP_REVERSE_ITERATE( \ |
1834 obj, \ |
2069 obj, \ |
1835 if (PSScavenge::should_scavenge(p)) { \ |
2070 if (PSScavenge::should_scavenge(p)) { \ |
1836 pm->claim_or_forward_depth(p); \ |
2071 pm->claim_or_forward_depth(p); \ |
1837 }, \ |
2072 }, \ |
1838 assert_nothing ) |
2073 assert_nothing ) |
1839 } |
2074 } |
1840 |
2075 |
1841 int instanceKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) { |
2076 int InstanceKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) { |
|
2077 int size = size_helper(); |
1842 InstanceKlass_OOP_MAP_ITERATE( \ |
2078 InstanceKlass_OOP_MAP_ITERATE( \ |
1843 obj, \ |
2079 obj, \ |
1844 PSParallelCompact::adjust_pointer(p), \ |
2080 PSParallelCompact::adjust_pointer(p), \ |
1845 assert_nothing) |
2081 assert_is_in) |
1846 return size_helper(); |
2082 obj->update_header(cm); |
|
2083 return size; |
1847 } |
2084 } |
1848 |
2085 |
1849 #endif // SERIALGC |
2086 #endif // SERIALGC |
1850 |
2087 |
1851 // This klass is alive but the implementor link is not followed/updated. |
2088 void InstanceKlass::clean_implementors_list(BoolObjectClosure* is_alive) { |
1852 // Subklass and sibling links are handled by Klass::follow_weak_klass_links |
2089 assert(is_loader_alive(is_alive), "this klass should be live"); |
1853 |
|
1854 void instanceKlass::follow_weak_klass_links( |
|
1855 BoolObjectClosure* is_alive, OopClosure* keep_alive) { |
|
1856 assert(is_alive->do_object_b(as_klassOop()), "this oop should be live"); |
|
1857 |
|
1858 if (is_interface()) { |
2090 if (is_interface()) { |
1859 if (ClassUnloading) { |
2091 if (ClassUnloading) { |
1860 klassOop impl = implementor(); |
2092 Klass* impl = implementor(); |
1861 if (impl != NULL) { |
2093 if (impl != NULL) { |
1862 if (!is_alive->do_object_b(impl)) { |
2094 if (!impl->is_loader_alive(is_alive)) { |
1863 // remove this guy |
2095 // remove this guy |
1864 *adr_implementor() = NULL; |
2096 *adr_implementor() = NULL; |
1865 } |
2097 } |
1866 } |
2098 } |
1867 } else { |
2099 } |
1868 assert(adr_implementor() != NULL, "just checking"); |
2100 } |
1869 keep_alive->do_oop(adr_implementor()); |
2101 } |
1870 } |
2102 |
1871 } |
2103 void InstanceKlass::clean_method_data(BoolObjectClosure* is_alive) { |
1872 |
2104 #ifdef COMPILER2 |
1873 Klass::follow_weak_klass_links(is_alive, keep_alive); |
2105 // Currently only used by C2. |
1874 } |
2106 for (int m = 0; m < methods()->length(); m++) { |
1875 |
2107 MethodData* mdo = methods()->at(m)->method_data(); |
1876 void instanceKlass::remove_unshareable_info() { |
2108 if (mdo != NULL) { |
|
2109 for (ProfileData* data = mdo->first_data(); |
|
2110 mdo->is_valid(data); |
|
2111 data = mdo->next_data(data)) { |
|
2112 data->clean_weak_klass_links(is_alive); |
|
2113 } |
|
2114 } |
|
2115 } |
|
2116 #else |
|
2117 #ifdef ASSERT |
|
2118 // Verify that we haven't started to use MDOs for C1. |
|
2119 for (int m = 0; m < methods()->length(); m++) { |
|
2120 MethodData* mdo = methods()->at(m)->method_data(); |
|
2121 assert(mdo == NULL, "Didn't expect C1 to use MDOs"); |
|
2122 } |
|
2123 #endif // ASSERT |
|
2124 #endif // !COMPILER2 |
|
2125 } |
|
2126 |
|
2127 |
|
2128 static void remove_unshareable_in_class(Klass* k) { |
|
2129 // remove klass's unshareable info |
|
2130 k->remove_unshareable_info(); |
|
2131 } |
|
2132 |
|
2133 void InstanceKlass::remove_unshareable_info() { |
1877 Klass::remove_unshareable_info(); |
2134 Klass::remove_unshareable_info(); |
|
2135 // Unlink the class |
|
2136 if (is_linked()) { |
|
2137 unlink_class(); |
|
2138 } |
1878 init_implementor(); |
2139 init_implementor(); |
1879 } |
2140 |
1880 |
2141 constants()->remove_unshareable_info(); |
1881 static void clear_all_breakpoints(methodOop m) { |
2142 |
|
2143 for (int i = 0; i < methods()->length(); i++) { |
|
2144 Method* m = methods()->at(i); |
|
2145 m->remove_unshareable_info(); |
|
2146 } |
|
2147 |
|
2148 // Need to reinstate when reading back the class. |
|
2149 set_init_lock(NULL); |
|
2150 |
|
2151 // do array classes also. |
|
2152 array_klasses_do(remove_unshareable_in_class); |
|
2153 } |
|
2154 |
|
2155 void restore_unshareable_in_class(Klass* k, TRAPS) { |
|
2156 k->restore_unshareable_info(CHECK); |
|
2157 } |
|
2158 |
|
2159 void InstanceKlass::restore_unshareable_info(TRAPS) { |
|
2160 Klass::restore_unshareable_info(CHECK); |
|
2161 instanceKlassHandle ik(THREAD, this); |
|
2162 |
|
2163 Array<Method*>* methods = ik->methods(); |
|
2164 int num_methods = methods->length(); |
|
2165 for (int index2 = 0; index2 < num_methods; ++index2) { |
|
2166 methodHandle m(THREAD, methods->at(index2)); |
|
2167 m()->link_method(m, CHECK); |
|
2168 } |
|
2169 if (JvmtiExport::has_redefined_a_class()) { |
|
2170 // Reinitialize vtable because RedefineClasses may have changed some |
|
2171 // entries in this vtable for super classes so the CDS vtable might |
|
2172 // point to old or obsolete entries. RedefineClasses doesn't fix up |
|
2173 // vtables in the shared system dictionary, only the main one. |
|
2174 // It also redefines the itable too so fix that too. |
|
2175 ResourceMark rm(THREAD); |
|
2176 ik->vtable()->initialize_vtable(false, CHECK); |
|
2177 ik->itable()->initialize_itable(false, CHECK); |
|
2178 } |
|
2179 |
|
2180 // Allocate a simple java object for a lock. |
|
2181 // This needs to be a java object because during class initialization |
|
2182 // it can be held across a java call. |
|
2183 typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK); |
|
2184 Handle h(THREAD, (oop)r); |
|
2185 ik->set_init_lock(h()); |
|
2186 |
|
2187 // restore constant pool resolved references |
|
2188 ik->constants()->restore_unshareable_info(CHECK); |
|
2189 |
|
2190 ik->array_klasses_do(restore_unshareable_in_class, CHECK); |
|
2191 } |
|
2192 |
|
2193 static void clear_all_breakpoints(Method* m) { |
1882 m->clear_all_breakpoints(); |
2194 m->clear_all_breakpoints(); |
1883 } |
2195 } |
1884 |
2196 |
1885 void instanceKlass::release_C_heap_structures() { |
2197 void InstanceKlass::release_C_heap_structures() { |
1886 // Deallocate oop map cache |
2198 // Deallocate oop map cache |
1887 if (_oop_map_cache != NULL) { |
2199 if (_oop_map_cache != NULL) { |
1888 delete _oop_map_cache; |
2200 delete _oop_map_cache; |
1889 _oop_map_cache = NULL; |
2201 _oop_map_cache = NULL; |
1890 } |
2202 } |
1991 dest[dest_index] = '\0'; |
2300 dest[dest_index] = '\0'; |
1992 return dest; |
2301 return dest; |
1993 } |
2302 } |
1994 |
2303 |
1995 // different verisons of is_same_class_package |
2304 // different verisons of is_same_class_package |
1996 bool instanceKlass::is_same_class_package(klassOop class2) { |
2305 bool InstanceKlass::is_same_class_package(Klass* class2) { |
1997 klassOop class1 = as_klassOop(); |
2306 Klass* class1 = this; |
1998 oop classloader1 = instanceKlass::cast(class1)->class_loader(); |
2307 oop classloader1 = InstanceKlass::cast(class1)->class_loader(); |
1999 Symbol* classname1 = Klass::cast(class1)->name(); |
2308 Symbol* classname1 = Klass::cast(class1)->name(); |
2000 |
2309 |
2001 if (Klass::cast(class2)->oop_is_objArray()) { |
2310 if (Klass::cast(class2)->oop_is_objArray()) { |
2002 class2 = objArrayKlass::cast(class2)->bottom_klass(); |
2311 class2 = objArrayKlass::cast(class2)->bottom_klass(); |
2003 } |
2312 } |
2004 oop classloader2; |
2313 oop classloader2; |
2005 if (Klass::cast(class2)->oop_is_instance()) { |
2314 if (Klass::cast(class2)->oop_is_instance()) { |
2006 classloader2 = instanceKlass::cast(class2)->class_loader(); |
2315 classloader2 = InstanceKlass::cast(class2)->class_loader(); |
2007 } else { |
2316 } else { |
2008 assert(Klass::cast(class2)->oop_is_typeArray(), "should be type array"); |
2317 assert(Klass::cast(class2)->oop_is_typeArray(), "should be type array"); |
2009 classloader2 = NULL; |
2318 classloader2 = NULL; |
2010 } |
2319 } |
2011 Symbol* classname2 = Klass::cast(class2)->name(); |
2320 Symbol* classname2 = Klass::cast(class2)->name(); |
2012 |
2321 |
2013 return instanceKlass::is_same_class_package(classloader1, classname1, |
2322 return InstanceKlass::is_same_class_package(classloader1, classname1, |
2014 classloader2, classname2); |
2323 classloader2, classname2); |
2015 } |
2324 } |
2016 |
2325 |
2017 bool instanceKlass::is_same_class_package(oop classloader2, Symbol* classname2) { |
2326 bool InstanceKlass::is_same_class_package(oop classloader2, Symbol* classname2) { |
2018 klassOop class1 = as_klassOop(); |
2327 Klass* class1 = this; |
2019 oop classloader1 = instanceKlass::cast(class1)->class_loader(); |
2328 oop classloader1 = InstanceKlass::cast(class1)->class_loader(); |
2020 Symbol* classname1 = Klass::cast(class1)->name(); |
2329 Symbol* classname1 = Klass::cast(class1)->name(); |
2021 |
2330 |
2022 return instanceKlass::is_same_class_package(classloader1, classname1, |
2331 return InstanceKlass::is_same_class_package(classloader1, classname1, |
2023 classloader2, classname2); |
2332 classloader2, classname2); |
2024 } |
2333 } |
2025 |
2334 |
2026 // return true if two classes are in the same package, classloader |
2335 // return true if two classes are in the same package, classloader |
2027 // and classname information is enough to determine a class's package |
2336 // and classname information is enough to determine a class's package |
2028 bool instanceKlass::is_same_class_package(oop class_loader1, Symbol* class_name1, |
2337 bool InstanceKlass::is_same_class_package(oop class_loader1, Symbol* class_name1, |
2029 oop class_loader2, Symbol* class_name2) { |
2338 oop class_loader2, Symbol* class_name2) { |
2030 if (class_loader1 != class_loader2) { |
2339 if (class_loader1 != class_loader2) { |
2031 return false; |
2340 return false; |
2032 } else if (class_name1 == class_name2) { |
2341 } else if (class_name1 == class_name2) { |
2033 return true; // skip painful bytewise comparison |
2342 return true; // skip painful bytewise comparison |
2190 result |= JVMTI_CLASS_STATUS_ERROR; |
2498 result |= JVMTI_CLASS_STATUS_ERROR; |
2191 } |
2499 } |
2192 return result; |
2500 return result; |
2193 } |
2501 } |
2194 |
2502 |
2195 methodOop instanceKlass::method_at_itable(klassOop holder, int index, TRAPS) { |
2503 Method* InstanceKlass::method_at_itable(Klass* holder, int index, TRAPS) { |
2196 itableOffsetEntry* ioe = (itableOffsetEntry*)start_of_itable(); |
2504 itableOffsetEntry* ioe = (itableOffsetEntry*)start_of_itable(); |
2197 int method_table_offset_in_words = ioe->offset()/wordSize; |
2505 int method_table_offset_in_words = ioe->offset()/wordSize; |
2198 int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words()) |
2506 int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words()) |
2199 / itableOffsetEntry::size(); |
2507 / itableOffsetEntry::size(); |
2200 |
2508 |
2201 for (int cnt = 0 ; ; cnt ++, ioe ++) { |
2509 for (int cnt = 0 ; ; cnt ++, ioe ++) { |
2202 // If the interface isn't implemented by the receiver class, |
2510 // If the interface isn't implemented by the receiver class, |
2203 // the VM should throw IncompatibleClassChangeError. |
2511 // the VM should throw IncompatibleClassChangeError. |
2204 if (cnt >= nof_interfaces) { |
2512 if (cnt >= nof_interfaces) { |
2205 THROW_0(vmSymbols::java_lang_IncompatibleClassChangeError()); |
2513 THROW_NULL(vmSymbols::java_lang_IncompatibleClassChangeError()); |
2206 } |
2514 } |
2207 |
2515 |
2208 klassOop ik = ioe->interface_klass(); |
2516 Klass* ik = ioe->interface_klass(); |
2209 if (ik == holder) break; |
2517 if (ik == holder) break; |
2210 } |
2518 } |
2211 |
2519 |
2212 itableMethodEntry* ime = ioe->first_method_entry(as_klassOop()); |
2520 itableMethodEntry* ime = ioe->first_method_entry(this); |
2213 methodOop m = ime[index].method(); |
2521 Method* m = ime[index].method(); |
2214 if (m == NULL) { |
2522 if (m == NULL) { |
2215 THROW_0(vmSymbols::java_lang_AbstractMethodError()); |
2523 THROW_NULL(vmSymbols::java_lang_AbstractMethodError()); |
2216 } |
2524 } |
2217 return m; |
2525 return m; |
2218 } |
2526 } |
2219 |
2527 |
2220 // On-stack replacement stuff |
2528 // On-stack replacement stuff |
2221 void instanceKlass::add_osr_nmethod(nmethod* n) { |
2529 void InstanceKlass::add_osr_nmethod(nmethod* n) { |
2222 // only one compilation can be active |
2530 // only one compilation can be active |
2223 NEEDS_CLEANUP |
2531 NEEDS_CLEANUP |
2224 // This is a short non-blocking critical region, so the no safepoint check is ok. |
2532 // This is a short non-blocking critical region, so the no safepoint check is ok. |
2225 OsrList_lock->lock_without_safepoint_check(); |
2533 OsrList_lock->lock_without_safepoint_check(); |
2226 assert(n->is_osr_method(), "wrong kind of nmethod"); |
2534 assert(n->is_osr_method(), "wrong kind of nmethod"); |
2227 n->set_osr_link(osr_nmethods_head()); |
2535 n->set_osr_link(osr_nmethods_head()); |
2228 set_osr_nmethods_head(n); |
2536 set_osr_nmethods_head(n); |
2229 // Raise the highest osr level if necessary |
2537 // Raise the highest osr level if necessary |
2230 if (TieredCompilation) { |
2538 if (TieredCompilation) { |
2231 methodOop m = n->method(); |
2539 Method* m = n->method(); |
2232 m->set_highest_osr_comp_level(MAX2(m->highest_osr_comp_level(), n->comp_level())); |
2540 m->set_highest_osr_comp_level(MAX2(m->highest_osr_comp_level(), n->comp_level())); |
2233 } |
2541 } |
2234 // Remember to unlock again |
2542 // Remember to unlock again |
2235 OsrList_lock->unlock(); |
2543 OsrList_lock->unlock(); |
2236 |
2544 |
2327 } |
2635 } |
2328 return NULL; |
2636 return NULL; |
2329 } |
2637 } |
2330 |
2638 |
2331 // ----------------------------------------------------------------------------------------------------- |
2639 // ----------------------------------------------------------------------------------------------------- |
|
2640 // Printing |
|
2641 |
2332 #ifndef PRODUCT |
2642 #ifndef PRODUCT |
2333 |
2643 |
2334 // Printing |
|
2335 |
|
2336 #define BULLET " - " |
2644 #define BULLET " - " |
|
2645 |
|
2646 static const char* state_names[] = { |
|
2647 "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error" |
|
2648 }; |
|
2649 |
|
2650 void InstanceKlass::print_on(outputStream* st) const { |
|
2651 assert(is_klass(), "must be klass"); |
|
2652 Klass::print_on(st); |
|
2653 |
|
2654 st->print(BULLET"instance size: %d", size_helper()); st->cr(); |
|
2655 st->print(BULLET"klass size: %d", size()); st->cr(); |
|
2656 st->print(BULLET"access: "); access_flags().print_on(st); st->cr(); |
|
2657 st->print(BULLET"state: "); st->print_cr(state_names[_init_state]); |
|
2658 st->print(BULLET"name: "); name()->print_value_on(st); st->cr(); |
|
2659 st->print(BULLET"super: "); super()->print_value_on_maybe_null(st); st->cr(); |
|
2660 st->print(BULLET"sub: "); |
|
2661 Klass* sub = subklass(); |
|
2662 int n; |
|
2663 for (n = 0; sub != NULL; n++, sub = sub->next_sibling()) { |
|
2664 if (n < MaxSubklassPrintSize) { |
|
2665 sub->print_value_on(st); |
|
2666 st->print(" "); |
|
2667 } |
|
2668 } |
|
2669 if (n >= MaxSubklassPrintSize) st->print("(%d more klasses...)", n - MaxSubklassPrintSize); |
|
2670 st->cr(); |
|
2671 |
|
2672 if (is_interface()) { |
|
2673 st->print_cr(BULLET"nof implementors: %d", nof_implementors()); |
|
2674 if (nof_implementors() == 1) { |
|
2675 st->print_cr(BULLET"implementor: "); |
|
2676 st->print(" "); |
|
2677 implementor()->print_value_on(st); |
|
2678 st->cr(); |
|
2679 } |
|
2680 } |
|
2681 |
|
2682 st->print(BULLET"arrays: "); array_klasses()->print_value_on_maybe_null(st); st->cr(); |
|
2683 st->print(BULLET"methods: "); methods()->print_value_on(st); st->cr(); |
|
2684 if (Verbose) { |
|
2685 Array<Method*>* method_array = methods(); |
|
2686 for(int i = 0; i < method_array->length(); i++) { |
|
2687 st->print("%d : ", i); method_array->at(i)->print_value(); st->cr(); |
|
2688 } |
|
2689 } |
|
2690 st->print(BULLET"method ordering: "); method_ordering()->print_value_on(st); st->cr(); |
|
2691 st->print(BULLET"local interfaces: "); local_interfaces()->print_value_on(st); st->cr(); |
|
2692 st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr(); |
|
2693 st->print(BULLET"constants: "); constants()->print_value_on(st); st->cr(); |
|
2694 if (class_loader_data() != NULL) { |
|
2695 st->print(BULLET"class loader data: "); |
|
2696 class_loader_data()->print_value_on(st); |
|
2697 st->cr(); |
|
2698 } |
|
2699 st->print(BULLET"protection domain: "); ((InstanceKlass*)this)->protection_domain()->print_value_on(st); st->cr(); |
|
2700 st->print(BULLET"host class: "); host_klass()->print_value_on_maybe_null(st); st->cr(); |
|
2701 st->print(BULLET"signers: "); signers()->print_value_on(st); st->cr(); |
|
2702 st->print(BULLET"init_lock: "); ((oop)init_lock())->print_value_on(st); st->cr(); |
|
2703 if (source_file_name() != NULL) { |
|
2704 st->print(BULLET"source file: "); |
|
2705 source_file_name()->print_value_on(st); |
|
2706 st->cr(); |
|
2707 } |
|
2708 if (source_debug_extension() != NULL) { |
|
2709 st->print(BULLET"source debug extension: "); |
|
2710 st->print("%s", source_debug_extension()); |
|
2711 st->cr(); |
|
2712 } |
|
2713 st->print(BULLET"annotations: "); annotations()->print_value_on(st); st->cr(); |
|
2714 { |
|
2715 ResourceMark rm; |
|
2716 // PreviousVersionInfo objects returned via PreviousVersionWalker |
|
2717 // contain a GrowableArray of handles. We have to clean up the |
|
2718 // GrowableArray _after_ the PreviousVersionWalker destructor |
|
2719 // has destroyed the handles. |
|
2720 { |
|
2721 bool have_pv = false; |
|
2722 PreviousVersionWalker pvw((InstanceKlass*)this); |
|
2723 for (PreviousVersionInfo * pv_info = pvw.next_previous_version(); |
|
2724 pv_info != NULL; pv_info = pvw.next_previous_version()) { |
|
2725 if (!have_pv) |
|
2726 st->print(BULLET"previous version: "); |
|
2727 have_pv = true; |
|
2728 pv_info->prev_constant_pool_handle()()->print_value_on(st); |
|
2729 } |
|
2730 if (have_pv) st->cr(); |
|
2731 } // pvw is cleaned up |
|
2732 } // rm is cleaned up |
|
2733 |
|
2734 if (generic_signature() != NULL) { |
|
2735 st->print(BULLET"generic signature: "); |
|
2736 generic_signature()->print_value_on(st); |
|
2737 st->cr(); |
|
2738 } |
|
2739 st->print(BULLET"inner classes: "); inner_classes()->print_value_on(st); st->cr(); |
|
2740 st->print(BULLET"java mirror: "); java_mirror()->print_value_on(st); st->cr(); |
|
2741 st->print(BULLET"vtable length %d (start addr: " INTPTR_FORMAT ")", vtable_length(), start_of_vtable()); st->cr(); |
|
2742 st->print(BULLET"itable length %d (start addr: " INTPTR_FORMAT ")", itable_length(), start_of_itable()); st->cr(); |
|
2743 st->print_cr(BULLET"---- static fields (%d words):", static_field_size()); |
|
2744 FieldPrinter print_static_field(st); |
|
2745 ((InstanceKlass*)this)->do_local_static_fields(&print_static_field); |
|
2746 st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size()); |
|
2747 FieldPrinter print_nonstatic_field(st); |
|
2748 ((InstanceKlass*)this)->do_nonstatic_fields(&print_nonstatic_field); |
|
2749 |
|
2750 st->print(BULLET"non-static oop maps: "); |
|
2751 OopMapBlock* map = start_of_nonstatic_oop_maps(); |
|
2752 OopMapBlock* end_map = map + nonstatic_oop_map_count(); |
|
2753 while (map < end_map) { |
|
2754 st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1)); |
|
2755 map++; |
|
2756 } |
|
2757 st->cr(); |
|
2758 } |
|
2759 |
|
2760 #endif //PRODUCT |
|
2761 |
|
2762 void InstanceKlass::print_value_on(outputStream* st) const { |
|
2763 assert(is_klass(), "must be klass"); |
|
2764 name()->print_value_on(st); |
|
2765 } |
|
2766 |
|
2767 #ifndef PRODUCT |
2337 |
2768 |
2338 void FieldPrinter::do_field(fieldDescriptor* fd) { |
2769 void FieldPrinter::do_field(fieldDescriptor* fd) { |
2339 _st->print(BULLET); |
2770 _st->print(BULLET); |
2340 if (_obj == NULL) { |
2771 if (_obj == NULL) { |
2341 fd->print_on(_st); |
2772 fd->print_on(_st); |
2368 |
2799 |
2369 st->print_cr(BULLET"---- fields (total size %d words):", oop_size(obj)); |
2800 st->print_cr(BULLET"---- fields (total size %d words):", oop_size(obj)); |
2370 FieldPrinter print_field(st, obj); |
2801 FieldPrinter print_field(st, obj); |
2371 do_nonstatic_fields(&print_field); |
2802 do_nonstatic_fields(&print_field); |
2372 |
2803 |
2373 if (as_klassOop() == SystemDictionary::Class_klass()) { |
2804 if (this == SystemDictionary::Class_klass()) { |
2374 st->print(BULLET"signature: "); |
2805 st->print(BULLET"signature: "); |
2375 java_lang_Class::print_signature(obj, st); |
2806 java_lang_Class::print_signature(obj, st); |
2376 st->cr(); |
2807 st->cr(); |
2377 klassOop mirrored_klass = java_lang_Class::as_klassOop(obj); |
2808 Klass* mirrored_klass = java_lang_Class::as_Klass(obj); |
2378 st->print(BULLET"fake entry for mirror: "); |
2809 st->print(BULLET"fake entry for mirror: "); |
2379 mirrored_klass->print_value_on(st); |
2810 mirrored_klass->print_value_on_maybe_null(st); |
2380 st->cr(); |
2811 st->cr(); |
2381 st->print(BULLET"fake entry resolved_constructor: "); |
2812 st->print(BULLET"fake entry resolved_constructor: "); |
2382 methodOop ctor = java_lang_Class::resolved_constructor(obj); |
2813 Method* ctor = java_lang_Class::resolved_constructor(obj); |
2383 ctor->print_value_on(st); |
2814 ctor->print_value_on_maybe_null(st); |
2384 klassOop array_klass = java_lang_Class::array_klass(obj); |
2815 Klass* array_klass = java_lang_Class::array_klass(obj); |
2385 st->cr(); |
2816 st->cr(); |
2386 st->print(BULLET"fake entry for array: "); |
2817 st->print(BULLET"fake entry for array: "); |
2387 array_klass->print_value_on(st); |
2818 array_klass->print_value_on_maybe_null(st); |
2388 st->cr(); |
2819 st->cr(); |
2389 st->print_cr(BULLET"fake entry for oop_size: %d", java_lang_Class::oop_size(obj)); |
2820 st->print_cr(BULLET"fake entry for oop_size: %d", java_lang_Class::oop_size(obj)); |
2390 st->print_cr(BULLET"fake entry for static_oop_field_count: %d", java_lang_Class::static_oop_field_count(obj)); |
2821 st->print_cr(BULLET"fake entry for static_oop_field_count: %d", java_lang_Class::static_oop_field_count(obj)); |
2391 klassOop real_klass = java_lang_Class::as_klassOop(obj); |
2822 Klass* real_klass = java_lang_Class::as_Klass(obj); |
2392 if (real_klass != NULL && real_klass->klass_part()->oop_is_instance()) { |
2823 if (real_klass != NULL && real_klass->oop_is_instance()) { |
2393 instanceKlass::cast(real_klass)->do_local_static_fields(&print_field); |
2824 InstanceKlass::cast(real_klass)->do_local_static_fields(&print_field); |
2394 } |
2825 } |
2395 } else if (as_klassOop() == SystemDictionary::MethodType_klass()) { |
2826 } else if (this == SystemDictionary::MethodType_klass()) { |
2396 st->print(BULLET"signature: "); |
2827 st->print(BULLET"signature: "); |
2397 java_lang_invoke_MethodType::print_signature(obj, st); |
2828 java_lang_invoke_MethodType::print_signature(obj, st); |
2398 st->cr(); |
2829 st->cr(); |
2399 } |
2830 } |
2400 } |
2831 } |
2401 |
2832 |
2402 #endif //PRODUCT |
2833 #endif //PRODUCT |
2403 |
2834 |
2404 void instanceKlass::oop_print_value_on(oop obj, outputStream* st) { |
2835 void InstanceKlass::oop_print_value_on(oop obj, outputStream* st) { |
2405 st->print("a "); |
2836 st->print("a "); |
2406 name()->print_value_on(st); |
2837 name()->print_value_on(st); |
2407 obj->print_address_on(st); |
2838 obj->print_address_on(st); |
2408 if (as_klassOop() == SystemDictionary::String_klass() |
2839 if (this == SystemDictionary::String_klass() |
2409 && java_lang_String::value(obj) != NULL) { |
2840 && java_lang_String::value(obj) != NULL) { |
2410 ResourceMark rm; |
2841 ResourceMark rm; |
2411 int len = java_lang_String::length(obj); |
2842 int len = java_lang_String::length(obj); |
2412 int plen = (len < 24 ? len : 12); |
2843 int plen = (len < 24 ? len : 12); |
2413 char* str = java_lang_String::as_utf8_string(obj, 0, plen); |
2844 char* str = java_lang_String::as_utf8_string(obj, 0, plen); |
2414 st->print(" = \"%s\"", str); |
2845 st->print(" = \"%s\"", str); |
2415 if (len > plen) |
2846 if (len > plen) |
2416 st->print("...[%d]", len); |
2847 st->print("...[%d]", len); |
2417 } else if (as_klassOop() == SystemDictionary::Class_klass()) { |
2848 } else if (this == SystemDictionary::Class_klass()) { |
2418 klassOop k = java_lang_Class::as_klassOop(obj); |
2849 Klass* k = java_lang_Class::as_Klass(obj); |
2419 st->print(" = "); |
2850 st->print(" = "); |
2420 if (k != NULL) { |
2851 if (k != NULL) { |
2421 k->print_value_on(st); |
2852 k->print_value_on(st); |
2422 } else { |
2853 } else { |
2423 const char* tname = type2name(java_lang_Class::primitive_type(obj)); |
2854 const char* tname = type2name(java_lang_Class::primitive_type(obj)); |
2424 st->print("%s", tname ? tname : "type?"); |
2855 st->print("%s", tname ? tname : "type?"); |
2425 } |
2856 } |
2426 } else if (as_klassOop() == SystemDictionary::MethodType_klass()) { |
2857 } else if (this == SystemDictionary::MethodType_klass()) { |
2427 st->print(" = "); |
2858 st->print(" = "); |
2428 java_lang_invoke_MethodType::print_signature(obj, st); |
2859 java_lang_invoke_MethodType::print_signature(obj, st); |
2429 } else if (java_lang_boxing_object::is_instance(obj)) { |
2860 } else if (java_lang_boxing_object::is_instance(obj)) { |
2430 st->print(" = "); |
2861 st->print(" = "); |
2431 java_lang_boxing_object::print(obj, st); |
2862 java_lang_boxing_object::print(obj, st); |
2432 } else if (as_klassOop() == SystemDictionary::LambdaForm_klass()) { |
2863 } else if (this == SystemDictionary::LambdaForm_klass()) { |
2433 oop vmentry = java_lang_invoke_LambdaForm::vmentry(obj); |
2864 oop vmentry = java_lang_invoke_LambdaForm::vmentry(obj); |
2434 if (vmentry != NULL) { |
2865 if (vmentry != NULL) { |
2435 st->print(" => "); |
2866 st->print(" => "); |
2436 vmentry->print_value_on(st); |
2867 vmentry->print_value_on(st); |
2437 } |
2868 } |
2438 } else if (as_klassOop() == SystemDictionary::MemberName_klass()) { |
2869 } else if (this == SystemDictionary::MemberName_klass()) { |
2439 oop vmtarget = java_lang_invoke_MemberName::vmtarget(obj); |
2870 Metadata* vmtarget = java_lang_invoke_MemberName::vmtarget(obj); |
2440 if (vmtarget != NULL) { |
2871 if (vmtarget != NULL) { |
2441 st->print(" = "); |
2872 st->print(" = "); |
2442 vmtarget->print_value_on(st); |
2873 vmtarget->print_value_on(st); |
2443 } else { |
2874 } else { |
2444 java_lang_invoke_MemberName::clazz(obj)->print_value_on(st); |
2875 java_lang_invoke_MemberName::clazz(obj)->print_value_on(st); |
2468 public: |
2898 public: |
2469 virtual void do_oop(oop* p) { VerifyFieldClosure::do_oop_work(p); } |
2899 virtual void do_oop(oop* p) { VerifyFieldClosure::do_oop_work(p); } |
2470 virtual void do_oop(narrowOop* p) { VerifyFieldClosure::do_oop_work(p); } |
2900 virtual void do_oop(narrowOop* p) { VerifyFieldClosure::do_oop_work(p); } |
2471 }; |
2901 }; |
2472 |
2902 |
2473 void instanceKlass::oop_verify_on(oop obj, outputStream* st) { |
2903 void InstanceKlass::verify_on(outputStream* st) { |
|
2904 Klass::verify_on(st); |
|
2905 Thread *thread = Thread::current(); |
|
2906 |
|
2907 #ifndef PRODUCT |
|
2908 // Avoid redundant verifies |
|
2909 if (_verify_count == Universe::verify_count()) return; |
|
2910 _verify_count = Universe::verify_count(); |
|
2911 #endif |
|
2912 // Verify that klass is present in SystemDictionary |
|
2913 if (is_loaded() && !is_anonymous()) { |
|
2914 Symbol* h_name = name(); |
|
2915 SystemDictionary::verify_obj_klass_present(h_name, class_loader_data()); |
|
2916 } |
|
2917 |
|
2918 // Verify static fields |
|
2919 VerifyFieldClosure blk; |
|
2920 |
|
2921 // Verify vtables |
|
2922 if (is_linked()) { |
|
2923 ResourceMark rm(thread); |
|
2924 // $$$ This used to be done only for m/s collections. Doing it |
|
2925 // always seemed a valid generalization. (DLD -- 6/00) |
|
2926 vtable()->verify(st); |
|
2927 } |
|
2928 |
|
2929 // Verify first subklass |
|
2930 if (subklass_oop() != NULL) { |
|
2931 guarantee(subklass_oop()->is_metadata(), "should be in metaspace"); |
|
2932 guarantee(subklass_oop()->is_klass(), "should be klass"); |
|
2933 } |
|
2934 |
|
2935 // Verify siblings |
|
2936 Klass* super = this->super(); |
|
2937 Klass* sib = next_sibling(); |
|
2938 if (sib != NULL) { |
|
2939 if (sib == this) { |
|
2940 fatal(err_msg("subclass points to itself " PTR_FORMAT, sib)); |
|
2941 } |
|
2942 |
|
2943 guarantee(sib->is_metadata(), "should be in metaspace"); |
|
2944 guarantee(sib->is_klass(), "should be klass"); |
|
2945 guarantee(sib->super() == super, "siblings should have same superklass"); |
|
2946 } |
|
2947 |
|
2948 // Verify implementor fields |
|
2949 Klass* im = implementor(); |
|
2950 if (im != NULL) { |
|
2951 guarantee(is_interface(), "only interfaces should have implementor set"); |
|
2952 guarantee(im->is_klass(), "should be klass"); |
|
2953 guarantee(!Klass::cast(im)->is_interface() || im == this, |
|
2954 "implementors cannot be interfaces"); |
|
2955 } |
|
2956 |
|
2957 // Verify local interfaces |
|
2958 if (local_interfaces()) { |
|
2959 Array<Klass*>* local_interfaces = this->local_interfaces(); |
|
2960 for (int j = 0; j < local_interfaces->length(); j++) { |
|
2961 Klass* e = local_interfaces->at(j); |
|
2962 guarantee(e->is_klass() && Klass::cast(e)->is_interface(), "invalid local interface"); |
|
2963 } |
|
2964 } |
|
2965 |
|
2966 // Verify transitive interfaces |
|
2967 if (transitive_interfaces() != NULL) { |
|
2968 Array<Klass*>* transitive_interfaces = this->transitive_interfaces(); |
|
2969 for (int j = 0; j < transitive_interfaces->length(); j++) { |
|
2970 Klass* e = transitive_interfaces->at(j); |
|
2971 guarantee(e->is_klass() && Klass::cast(e)->is_interface(), "invalid transitive interface"); |
|
2972 } |
|
2973 } |
|
2974 |
|
2975 // Verify methods |
|
2976 if (methods() != NULL) { |
|
2977 Array<Method*>* methods = this->methods(); |
|
2978 for (int j = 0; j < methods->length(); j++) { |
|
2979 guarantee(methods->at(j)->is_metadata(), "should be in metaspace"); |
|
2980 guarantee(methods->at(j)->is_method(), "non-method in methods array"); |
|
2981 } |
|
2982 for (int j = 0; j < methods->length() - 1; j++) { |
|
2983 Method* m1 = methods->at(j); |
|
2984 Method* m2 = methods->at(j + 1); |
|
2985 guarantee(m1->name()->fast_compare(m2->name()) <= 0, "methods not sorted correctly"); |
|
2986 } |
|
2987 } |
|
2988 |
|
2989 // Verify method ordering |
|
2990 if (method_ordering() != NULL) { |
|
2991 Array<int>* method_ordering = this->method_ordering(); |
|
2992 int length = method_ordering->length(); |
|
2993 if (JvmtiExport::can_maintain_original_method_order() || |
|
2994 (UseSharedSpaces && length != 0)) { |
|
2995 guarantee(length == methods()->length(), "invalid method ordering length"); |
|
2996 jlong sum = 0; |
|
2997 for (int j = 0; j < length; j++) { |
|
2998 int original_index = method_ordering->at(j); |
|
2999 guarantee(original_index >= 0, "invalid method ordering index"); |
|
3000 guarantee(original_index < length, "invalid method ordering index"); |
|
3001 sum += original_index; |
|
3002 } |
|
3003 // Verify sum of indices 0,1,...,length-1 |
|
3004 guarantee(sum == ((jlong)length*(length-1))/2, "invalid method ordering sum"); |
|
3005 } else { |
|
3006 guarantee(length == 0, "invalid method ordering length"); |
|
3007 } |
|
3008 } |
|
3009 |
|
3010 // Verify JNI static field identifiers |
|
3011 if (jni_ids() != NULL) { |
|
3012 jni_ids()->verify(this); |
|
3013 } |
|
3014 |
|
3015 // Verify other fields |
|
3016 if (array_klasses() != NULL) { |
|
3017 guarantee(array_klasses()->is_metadata(), "should be in metaspace"); |
|
3018 guarantee(array_klasses()->is_klass(), "should be klass"); |
|
3019 } |
|
3020 if (constants() != NULL) { |
|
3021 guarantee(constants()->is_metadata(), "should be in metaspace"); |
|
3022 guarantee(constants()->is_constantPool(), "should be constant pool"); |
|
3023 } |
|
3024 if (protection_domain() != NULL) { |
|
3025 guarantee(protection_domain()->is_oop(), "should be oop"); |
|
3026 } |
|
3027 if (host_klass() != NULL) { |
|
3028 guarantee(host_klass()->is_metadata(), "should be in metaspace"); |
|
3029 guarantee(host_klass()->is_klass(), "should be klass"); |
|
3030 } |
|
3031 if (signers() != NULL) { |
|
3032 guarantee(signers()->is_objArray(), "should be obj array"); |
|
3033 } |
|
3034 } |
|
3035 |
|
3036 void InstanceKlass::oop_verify_on(oop obj, outputStream* st) { |
2474 Klass::oop_verify_on(obj, st); |
3037 Klass::oop_verify_on(obj, st); |
2475 VerifyFieldClosure blk; |
3038 VerifyFieldClosure blk; |
2476 oop_oop_iterate(obj, &blk); |
3039 obj->oop_iterate_no_header(&blk); |
2477 } |
3040 } |
|
3041 |
2478 |
3042 |
2479 // JNIid class for jfieldIDs only |
3043 // JNIid class for jfieldIDs only |
2480 // Note to reviewers: |
3044 // Note to reviewers: |
2481 // These JNI functions are just moved over to column 1 and not changed |
3045 // These JNI functions are just moved over to column 1 and not changed |
2482 // in the compressed oops workspace. |
3046 // in the compressed oops workspace. |
2483 JNIid::JNIid(klassOop holder, int offset, JNIid* next) { |
3047 JNIid::JNIid(Klass* holder, int offset, JNIid* next) { |
2484 _holder = holder; |
3048 _holder = holder; |
2485 _offset = offset; |
3049 _offset = offset; |
2486 _next = next; |
3050 _next = next; |
2487 debug_only(_is_static_field_id = false;) |
3051 debug_only(_is_static_field_id = false;) |
2488 } |
3052 } |
2530 } |
3088 } |
2531 } |
3089 } |
2532 |
3090 |
2533 |
3091 |
2534 #ifdef ASSERT |
3092 #ifdef ASSERT |
2535 void instanceKlass::set_init_state(ClassState state) { |
3093 void InstanceKlass::set_init_state(ClassState state) { |
2536 bool good_state = as_klassOop()->is_shared() ? (_init_state <= state) |
3094 bool good_state = is_shared() ? (_init_state <= state) |
2537 : (_init_state < state); |
3095 : (_init_state < state); |
2538 assert(good_state || state == allocated, "illegal state transition"); |
3096 assert(good_state || state == allocated, "illegal state transition"); |
2539 _init_state = (u1)state; |
3097 _init_state = (u1)state; |
2540 } |
3098 } |
2541 #endif |
3099 #endif |
2542 |
3100 |
2543 |
3101 |
2544 // RedefineClasses() support for previous versions: |
3102 // RedefineClasses() support for previous versions: |
2545 |
3103 |
2546 // Add an information node that contains weak references to the |
3104 // Purge previous versions |
|
3105 static void purge_previous_versions_internal(InstanceKlass* ik, int emcp_method_count) { |
|
3106 if (ik->previous_versions() != NULL) { |
|
3107 // This klass has previous versions so see what we can cleanup |
|
3108 // while it is safe to do so. |
|
3109 |
|
3110 int deleted_count = 0; // leave debugging breadcrumbs |
|
3111 int live_count = 0; |
|
3112 ClassLoaderData* loader_data = ik->class_loader_data() == NULL ? |
|
3113 ClassLoaderData::the_null_class_loader_data() : |
|
3114 ik->class_loader_data(); |
|
3115 |
|
3116 // RC_TRACE macro has an embedded ResourceMark |
|
3117 RC_TRACE(0x00000200, ("purge: %s: previous version length=%d", |
|
3118 ik->external_name(), ik->previous_versions()->length())); |
|
3119 |
|
3120 for (int i = ik->previous_versions()->length() - 1; i >= 0; i--) { |
|
3121 // check the previous versions array |
|
3122 PreviousVersionNode * pv_node = ik->previous_versions()->at(i); |
|
3123 ConstantPool* cp_ref = pv_node->prev_constant_pool(); |
|
3124 assert(cp_ref != NULL, "cp ref was unexpectedly cleared"); |
|
3125 |
|
3126 ConstantPool* pvcp = cp_ref; |
|
3127 if (!pvcp->on_stack()) { |
|
3128 // If the constant pool isn't on stack, none of the methods |
|
3129 // are executing. Delete all the methods, the constant pool and |
|
3130 // and this previous version node. |
|
3131 GrowableArray<Method*>* method_refs = pv_node->prev_EMCP_methods(); |
|
3132 if (method_refs != NULL) { |
|
3133 for (int j = method_refs->length() - 1; j >= 0; j--) { |
|
3134 Method* method = method_refs->at(j); |
|
3135 assert(method != NULL, "method ref was unexpectedly cleared"); |
|
3136 method_refs->remove_at(j); |
|
3137 // method will be freed with associated class. |
|
3138 } |
|
3139 } |
|
3140 // Remove the constant pool |
|
3141 delete pv_node; |
|
3142 // Since we are traversing the array backwards, we don't have to |
|
3143 // do anything special with the index. |
|
3144 ik->previous_versions()->remove_at(i); |
|
3145 deleted_count++; |
|
3146 continue; |
|
3147 } else { |
|
3148 RC_TRACE(0x00000200, ("purge: previous version @%d is alive", i)); |
|
3149 assert(pvcp->pool_holder() != NULL, "Constant pool with no holder"); |
|
3150 guarantee (!loader_data->is_unloading(), "unloaded classes can't be on the stack"); |
|
3151 live_count++; |
|
3152 } |
|
3153 |
|
3154 // At least one method is live in this previous version, clean out |
|
3155 // the others or mark them as obsolete. |
|
3156 GrowableArray<Method*>* method_refs = pv_node->prev_EMCP_methods(); |
|
3157 if (method_refs != NULL) { |
|
3158 RC_TRACE(0x00000200, ("purge: previous methods length=%d", |
|
3159 method_refs->length())); |
|
3160 for (int j = method_refs->length() - 1; j >= 0; j--) { |
|
3161 Method* method = method_refs->at(j); |
|
3162 assert(method != NULL, "method ref was unexpectedly cleared"); |
|
3163 |
|
3164 // Remove the emcp method if it's not executing |
|
3165 // If it's been made obsolete by a redefinition of a non-emcp |
|
3166 // method, mark it as obsolete but leave it to clean up later. |
|
3167 if (!method->on_stack()) { |
|
3168 method_refs->remove_at(j); |
|
3169 } else if (emcp_method_count == 0) { |
|
3170 method->set_is_obsolete(); |
|
3171 } else { |
|
3172 // RC_TRACE macro has an embedded ResourceMark |
|
3173 RC_TRACE(0x00000200, |
|
3174 ("purge: %s(%s): prev method @%d in version @%d is alive", |
|
3175 method->name()->as_C_string(), |
|
3176 method->signature()->as_C_string(), j, i)); |
|
3177 } |
|
3178 } |
|
3179 } |
|
3180 } |
|
3181 assert(ik->previous_versions()->length() == live_count, "sanity check"); |
|
3182 RC_TRACE(0x00000200, |
|
3183 ("purge: previous version stats: live=%d, deleted=%d", live_count, |
|
3184 deleted_count)); |
|
3185 } |
|
3186 } |
|
3187 |
|
3188 // External interface for use during class unloading. |
|
3189 void InstanceKlass::purge_previous_versions(InstanceKlass* ik) { |
|
3190 // Call with >0 emcp methods since they are not currently being redefined. |
|
3191 purge_previous_versions_internal(ik, 1); |
|
3192 } |
|
3193 |
|
3194 |
|
3195 // Potentially add an information node that contains pointers to the |
2547 // interesting parts of the previous version of the_class. |
3196 // interesting parts of the previous version of the_class. |
2548 // This is also where we clean out any unused weak references. |
3197 // This is also where we clean out any unused references. |
2549 // Note that while we delete nodes from the _previous_versions |
3198 // Note that while we delete nodes from the _previous_versions |
2550 // array, we never delete the array itself until the klass is |
3199 // array, we never delete the array itself until the klass is |
2551 // unloaded. The has_been_redefined() query depends on that fact. |
3200 // unloaded. The has_been_redefined() query depends on that fact. |
2552 // |
3201 // |
2553 void instanceKlass::add_previous_version(instanceKlassHandle ikh, |
3202 void InstanceKlass::add_previous_version(instanceKlassHandle ikh, |
2554 BitMap* emcp_methods, int emcp_method_count) { |
3203 BitMap* emcp_methods, int emcp_method_count) { |
2555 assert(Thread::current()->is_VM_thread(), |
3204 assert(Thread::current()->is_VM_thread(), |
2556 "only VMThread can add previous versions"); |
3205 "only VMThread can add previous versions"); |
2557 |
3206 |
2558 if (_previous_versions == NULL) { |
3207 if (_previous_versions == NULL) { |
2561 // won't be redefined much. |
3210 // won't be redefined much. |
2562 _previous_versions = new (ResourceObj::C_HEAP, mtClass) |
3211 _previous_versions = new (ResourceObj::C_HEAP, mtClass) |
2563 GrowableArray<PreviousVersionNode *>(2, true); |
3212 GrowableArray<PreviousVersionNode *>(2, true); |
2564 } |
3213 } |
2565 |
3214 |
|
3215 ConstantPool* cp_ref = ikh->constants(); |
|
3216 |
2566 // RC_TRACE macro has an embedded ResourceMark |
3217 // RC_TRACE macro has an embedded ResourceMark |
2567 RC_TRACE(0x00000100, ("adding previous version ref for %s @%d, EMCP_cnt=%d", |
3218 RC_TRACE(0x00000400, ("adding previous version ref for %s @%d, EMCP_cnt=%d " |
2568 ikh->external_name(), _previous_versions->length(), emcp_method_count)); |
3219 "on_stack=%d", |
2569 constantPoolHandle cp_h(ikh->constants()); |
3220 ikh->external_name(), _previous_versions->length(), emcp_method_count, |
2570 jobject cp_ref; |
3221 cp_ref->on_stack())); |
2571 if (cp_h->is_shared()) { |
3222 |
2572 // a shared ConstantPool requires a regular reference; a weak |
3223 // If the constant pool for this previous version of the class |
2573 // reference would be collectible |
3224 // is not marked as being on the stack, then none of the methods |
2574 cp_ref = JNIHandles::make_global(cp_h); |
3225 // in this previous version of the class are on the stack so |
2575 } else { |
3226 // we don't need to create a new PreviousVersionNode. However, |
2576 cp_ref = JNIHandles::make_weak_global(cp_h); |
3227 // we still need to examine older previous versions below. |
2577 } |
3228 Array<Method*>* old_methods = ikh->methods(); |
|
3229 |
|
3230 if (cp_ref->on_stack()) { |
2578 PreviousVersionNode * pv_node = NULL; |
3231 PreviousVersionNode * pv_node = NULL; |
2579 objArrayOop old_methods = ikh->methods(); |
|
2580 |
|
2581 if (emcp_method_count == 0) { |
3232 if (emcp_method_count == 0) { |
2582 // non-shared ConstantPool gets a weak reference |
3233 // non-shared ConstantPool gets a reference |
2583 pv_node = new PreviousVersionNode(cp_ref, !cp_h->is_shared(), NULL); |
3234 pv_node = new PreviousVersionNode(cp_ref, !cp_ref->is_shared(), NULL); |
2584 RC_TRACE(0x00000400, |
3235 RC_TRACE(0x00000400, |
2585 ("add: all methods are obsolete; flushing any EMCP weak refs")); |
3236 ("add: all methods are obsolete; flushing any EMCP refs")); |
2586 } else { |
3237 } else { |
2587 int local_count = 0; |
3238 int local_count = 0; |
2588 GrowableArray<jweak>* method_refs = new (ResourceObj::C_HEAP, mtClass) |
3239 GrowableArray<Method*>* method_refs = new (ResourceObj::C_HEAP, mtClass) |
2589 GrowableArray<jweak>(emcp_method_count, true); |
3240 GrowableArray<Method*>(emcp_method_count, true); |
2590 for (int i = 0; i < old_methods->length(); i++) { |
3241 for (int i = 0; i < old_methods->length(); i++) { |
2591 if (emcp_methods->at(i)) { |
3242 if (emcp_methods->at(i)) { |
2592 // this old method is EMCP so save a weak ref |
3243 // this old method is EMCP. Save it only if it's on the stack |
2593 methodOop old_method = (methodOop) old_methods->obj_at(i); |
3244 Method* old_method = old_methods->at(i); |
2594 methodHandle old_method_h(old_method); |
3245 if (old_method->on_stack()) { |
2595 jweak method_ref = JNIHandles::make_weak_global(old_method_h); |
3246 method_refs->append(old_method); |
2596 method_refs->append(method_ref); |
3247 } |
2597 if (++local_count >= emcp_method_count) { |
3248 if (++local_count >= emcp_method_count) { |
2598 // no more EMCP methods so bail out now |
3249 // no more EMCP methods so bail out now |
2599 break; |
3250 break; |
2600 } |
3251 } |
2601 } |
3252 } |
2602 } |
3253 } |
2603 // non-shared ConstantPool gets a weak reference |
3254 // non-shared ConstantPool gets a reference |
2604 pv_node = new PreviousVersionNode(cp_ref, !cp_h->is_shared(), method_refs); |
3255 pv_node = new PreviousVersionNode(cp_ref, !cp_ref->is_shared(), method_refs); |
2605 } |
3256 } |
2606 |
3257 // append new previous version. |
2607 _previous_versions->append(pv_node); |
3258 _previous_versions->append(pv_node); |
2608 |
3259 } |
2609 // Using weak references allows the interesting parts of previous |
3260 |
2610 // classes to be GC'ed when they are no longer needed. Since the |
3261 // Since the caller is the VMThread and we are at a safepoint, this |
2611 // caller is the VMThread and we are at a safepoint, this is a good |
3262 // is a good time to clear out unused references. |
2612 // time to clear out unused weak references. |
|
2613 |
3263 |
2614 RC_TRACE(0x00000400, ("add: previous version length=%d", |
3264 RC_TRACE(0x00000400, ("add: previous version length=%d", |
2615 _previous_versions->length())); |
3265 _previous_versions->length())); |
2616 |
3266 |
2617 // skip the last entry since we just added it |
3267 // Purge previous versions not executing on the stack |
2618 for (int i = _previous_versions->length() - 2; i >= 0; i--) { |
3268 purge_previous_versions_internal(this, emcp_method_count); |
2619 // check the previous versions array for a GC'ed weak refs |
|
2620 pv_node = _previous_versions->at(i); |
|
2621 cp_ref = pv_node->prev_constant_pool(); |
|
2622 assert(cp_ref != NULL, "cp ref was unexpectedly cleared"); |
|
2623 if (cp_ref == NULL) { |
|
2624 delete pv_node; |
|
2625 _previous_versions->remove_at(i); |
|
2626 // Since we are traversing the array backwards, we don't have to |
|
2627 // do anything special with the index. |
|
2628 continue; // robustness |
|
2629 } |
|
2630 |
|
2631 constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref); |
|
2632 if (cp == NULL) { |
|
2633 // this entry has been GC'ed so remove it |
|
2634 delete pv_node; |
|
2635 _previous_versions->remove_at(i); |
|
2636 // Since we are traversing the array backwards, we don't have to |
|
2637 // do anything special with the index. |
|
2638 continue; |
|
2639 } else { |
|
2640 RC_TRACE(0x00000400, ("add: previous version @%d is alive", i)); |
|
2641 } |
|
2642 |
|
2643 GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods(); |
|
2644 if (method_refs != NULL) { |
|
2645 RC_TRACE(0x00000400, ("add: previous methods length=%d", |
|
2646 method_refs->length())); |
|
2647 for (int j = method_refs->length() - 1; j >= 0; j--) { |
|
2648 jweak method_ref = method_refs->at(j); |
|
2649 assert(method_ref != NULL, "weak method ref was unexpectedly cleared"); |
|
2650 if (method_ref == NULL) { |
|
2651 method_refs->remove_at(j); |
|
2652 // Since we are traversing the array backwards, we don't have to |
|
2653 // do anything special with the index. |
|
2654 continue; // robustness |
|
2655 } |
|
2656 |
|
2657 methodOop method = (methodOop)JNIHandles::resolve(method_ref); |
|
2658 if (method == NULL || emcp_method_count == 0) { |
|
2659 // This method entry has been GC'ed or the current |
|
2660 // RedefineClasses() call has made all methods obsolete |
|
2661 // so remove it. |
|
2662 JNIHandles::destroy_weak_global(method_ref); |
|
2663 method_refs->remove_at(j); |
|
2664 } else { |
|
2665 // RC_TRACE macro has an embedded ResourceMark |
|
2666 RC_TRACE(0x00000400, |
|
2667 ("add: %s(%s): previous method @%d in version @%d is alive", |
|
2668 method->name()->as_C_string(), method->signature()->as_C_string(), |
|
2669 j, i)); |
|
2670 } |
|
2671 } |
|
2672 } |
|
2673 } |
|
2674 |
3269 |
2675 int obsolete_method_count = old_methods->length() - emcp_method_count; |
3270 int obsolete_method_count = old_methods->length() - emcp_method_count; |
2676 |
3271 |
2677 if (emcp_method_count != 0 && obsolete_method_count != 0 && |
3272 if (emcp_method_count != 0 && obsolete_method_count != 0 && |
2678 _previous_versions->length() > 1) { |
3273 _previous_versions->length() > 0) { |
2679 // We have a mix of obsolete and EMCP methods. If there is more |
3274 // We have a mix of obsolete and EMCP methods so we have to |
2680 // than the previous version that we just added, then we have to |
|
2681 // clear out any matching EMCP method entries the hard way. |
3275 // clear out any matching EMCP method entries the hard way. |
2682 int local_count = 0; |
3276 int local_count = 0; |
2683 for (int i = 0; i < old_methods->length(); i++) { |
3277 for (int i = 0; i < old_methods->length(); i++) { |
2684 if (!emcp_methods->at(i)) { |
3278 if (!emcp_methods->at(i)) { |
2685 // only obsolete methods are interesting |
3279 // only obsolete methods are interesting |
2686 methodOop old_method = (methodOop) old_methods->obj_at(i); |
3280 Method* old_method = old_methods->at(i); |
2687 Symbol* m_name = old_method->name(); |
3281 Symbol* m_name = old_method->name(); |
2688 Symbol* m_signature = old_method->signature(); |
3282 Symbol* m_signature = old_method->signature(); |
2689 |
3283 |
2690 // skip the last entry since we just added it |
3284 // we might not have added the last entry |
2691 for (int j = _previous_versions->length() - 2; j >= 0; j--) { |
3285 for (int j = _previous_versions->length() - 1; j >= 0; j--) { |
2692 // check the previous versions array for a GC'ed weak refs |
3286 // check the previous versions array for non executing obsolete methods |
2693 pv_node = _previous_versions->at(j); |
3287 PreviousVersionNode * pv_node = _previous_versions->at(j); |
2694 cp_ref = pv_node->prev_constant_pool(); |
3288 |
2695 assert(cp_ref != NULL, "cp ref was unexpectedly cleared"); |
3289 GrowableArray<Method*>* method_refs = pv_node->prev_EMCP_methods(); |
2696 if (cp_ref == NULL) { |
|
2697 delete pv_node; |
|
2698 _previous_versions->remove_at(j); |
|
2699 // Since we are traversing the array backwards, we don't have to |
|
2700 // do anything special with the index. |
|
2701 continue; // robustness |
|
2702 } |
|
2703 |
|
2704 constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref); |
|
2705 if (cp == NULL) { |
|
2706 // this entry has been GC'ed so remove it |
|
2707 delete pv_node; |
|
2708 _previous_versions->remove_at(j); |
|
2709 // Since we are traversing the array backwards, we don't have to |
|
2710 // do anything special with the index. |
|
2711 continue; |
|
2712 } |
|
2713 |
|
2714 GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods(); |
|
2715 if (method_refs == NULL) { |
3290 if (method_refs == NULL) { |
2716 // We have run into a PreviousVersion generation where |
3291 // We have run into a PreviousVersion generation where |
2717 // all methods were made obsolete during that generation's |
3292 // all methods were made obsolete during that generation's |
2718 // RedefineClasses() operation. At the time of that |
3293 // RedefineClasses() operation. At the time of that |
2719 // operation, all EMCP methods were flushed so we don't |
3294 // operation, all EMCP methods were flushed so we don't |
2724 // from an empty method_refs for the current generation. |
3299 // from an empty method_refs for the current generation. |
2725 break; |
3300 break; |
2726 } |
3301 } |
2727 |
3302 |
2728 for (int k = method_refs->length() - 1; k >= 0; k--) { |
3303 for (int k = method_refs->length() - 1; k >= 0; k--) { |
2729 jweak method_ref = method_refs->at(k); |
3304 Method* method = method_refs->at(k); |
2730 assert(method_ref != NULL, |
3305 |
2731 "weak method ref was unexpectedly cleared"); |
3306 if (!method->is_obsolete() && |
2732 if (method_ref == NULL) { |
3307 method->name() == m_name && |
2733 method_refs->remove_at(k); |
|
2734 // Since we are traversing the array backwards, we don't |
|
2735 // have to do anything special with the index. |
|
2736 continue; // robustness |
|
2737 } |
|
2738 |
|
2739 methodOop method = (methodOop)JNIHandles::resolve(method_ref); |
|
2740 if (method == NULL) { |
|
2741 // this method entry has been GC'ed so skip it |
|
2742 JNIHandles::destroy_weak_global(method_ref); |
|
2743 method_refs->remove_at(k); |
|
2744 continue; |
|
2745 } |
|
2746 |
|
2747 if (method->name() == m_name && |
|
2748 method->signature() == m_signature) { |
3308 method->signature() == m_signature) { |
2749 // The current RedefineClasses() call has made all EMCP |
3309 // The current RedefineClasses() call has made all EMCP |
2750 // versions of this method obsolete so mark it as obsolete |
3310 // versions of this method obsolete so mark it as obsolete |
2751 // and remove the weak ref. |
3311 // and remove the reference. |
2752 RC_TRACE(0x00000400, |
3312 RC_TRACE(0x00000400, |
2753 ("add: %s(%s): flush obsolete method @%d in version @%d", |
3313 ("add: %s(%s): flush obsolete method @%d in version @%d", |
2754 m_name->as_C_string(), m_signature->as_C_string(), k, j)); |
3314 m_name->as_C_string(), m_signature->as_C_string(), k, j)); |
2755 |
3315 |
2756 method->set_is_obsolete(); |
3316 method->set_is_obsolete(); |
2757 JNIHandles::destroy_weak_global(method_ref); |
3317 // Leave obsolete methods on the previous version list to |
2758 method_refs->remove_at(k); |
3318 // clean up later. |
2759 break; |
3319 break; |
2760 } |
3320 } |
2761 } |
3321 } |
2762 |
3322 |
2763 // The previous loop may not find a matching EMCP method, but |
3323 // The previous loop may not find a matching EMCP method, but |
2764 // that doesn't mean that we can optimize and not go any |
3324 // that doesn't mean that we can optimize and not go any |
2765 // further back in the PreviousVersion generations. The EMCP |
3325 // further back in the PreviousVersion generations. The EMCP |
2766 // method for this generation could have already been GC'ed, |
3326 // method for this generation could have already been deleted, |
2767 // but there still may be an older EMCP method that has not |
3327 // but there still may be an older EMCP method that has not |
2768 // been GC'ed. |
3328 // been deleted. |
2769 } |
3329 } |
2770 |
3330 |
2771 if (++local_count >= obsolete_method_count) { |
3331 if (++local_count >= obsolete_method_count) { |
2772 // no more obsolete methods so bail out now |
3332 // no more obsolete methods so bail out now |
2773 break; |
3333 break; |
2776 } |
3336 } |
2777 } |
3337 } |
2778 } // end add_previous_version() |
3338 } // end add_previous_version() |
2779 |
3339 |
2780 |
3340 |
2781 // Determine if instanceKlass has a previous version. |
3341 // Determine if InstanceKlass has a previous version. |
2782 bool instanceKlass::has_previous_version() const { |
3342 bool InstanceKlass::has_previous_version() const { |
2783 if (_previous_versions == NULL) { |
3343 return (_previous_versions != NULL && _previous_versions->length() > 0); |
2784 // no previous versions array so answer is easy |
|
2785 return false; |
|
2786 } |
|
2787 |
|
2788 for (int i = _previous_versions->length() - 1; i >= 0; i--) { |
|
2789 // Check the previous versions array for an info node that hasn't |
|
2790 // been GC'ed |
|
2791 PreviousVersionNode * pv_node = _previous_versions->at(i); |
|
2792 |
|
2793 jobject cp_ref = pv_node->prev_constant_pool(); |
|
2794 assert(cp_ref != NULL, "cp reference was unexpectedly cleared"); |
|
2795 if (cp_ref == NULL) { |
|
2796 continue; // robustness |
|
2797 } |
|
2798 |
|
2799 constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref); |
|
2800 if (cp != NULL) { |
|
2801 // we have at least one previous version |
|
2802 return true; |
|
2803 } |
|
2804 |
|
2805 // We don't have to check the method refs. If the constant pool has |
|
2806 // been GC'ed then so have the methods. |
|
2807 } |
|
2808 |
|
2809 // all of the underlying nodes' info has been GC'ed |
|
2810 return false; |
|
2811 } // end has_previous_version() |
3344 } // end has_previous_version() |
2812 |
3345 |
2813 methodOop instanceKlass::method_with_idnum(int idnum) { |
3346 |
2814 methodOop m = NULL; |
3347 Method* InstanceKlass::method_with_idnum(int idnum) { |
|
3348 Method* m = NULL; |
2815 if (idnum < methods()->length()) { |
3349 if (idnum < methods()->length()) { |
2816 m = (methodOop) methods()->obj_at(idnum); |
3350 m = methods()->at(idnum); |
2817 } |
3351 } |
2818 if (m == NULL || m->method_idnum() != idnum) { |
3352 if (m == NULL || m->method_idnum() != idnum) { |
2819 for (int index = 0; index < methods()->length(); ++index) { |
3353 for (int index = 0; index < methods()->length(); ++index) { |
2820 m = (methodOop) methods()->obj_at(index); |
3354 m = methods()->at(index); |
2821 if (m->method_idnum() == idnum) { |
3355 if (m->method_idnum() == idnum) { |
2822 return m; |
3356 return m; |
2823 } |
3357 } |
2824 } |
3358 } |
2825 } |
3359 } |
2826 return m; |
3360 return m; |
2827 } |
3361 } |
2828 |
3362 |
2829 |
3363 |
2830 // Set the annotation at 'idnum' to 'anno'. |
|
2831 // We don't want to create or extend the array if 'anno' is NULL, since that is the |
|
2832 // default value. However, if the array exists and is long enough, we must set NULL values. |
|
2833 void instanceKlass::set_methods_annotations_of(int idnum, typeArrayOop anno, objArrayOop* md_p) { |
|
2834 objArrayOop md = *md_p; |
|
2835 if (md != NULL && md->length() > idnum) { |
|
2836 md->obj_at_put(idnum, anno); |
|
2837 } else if (anno != NULL) { |
|
2838 // create the array |
|
2839 int length = MAX2(idnum+1, (int)_idnum_allocated_count); |
|
2840 md = oopFactory::new_system_objArray(length, Thread::current()); |
|
2841 if (*md_p != NULL) { |
|
2842 // copy the existing entries |
|
2843 for (int index = 0; index < (*md_p)->length(); index++) { |
|
2844 md->obj_at_put(index, (*md_p)->obj_at(index)); |
|
2845 } |
|
2846 } |
|
2847 set_annotations(md, md_p); |
|
2848 md->obj_at_put(idnum, anno); |
|
2849 } // if no array and idnum isn't included there is nothing to do |
|
2850 } |
|
2851 |
|
2852 // Construct a PreviousVersionNode entry for the array hung off |
3364 // Construct a PreviousVersionNode entry for the array hung off |
2853 // the instanceKlass. |
3365 // the InstanceKlass. |
2854 PreviousVersionNode::PreviousVersionNode(jobject prev_constant_pool, |
3366 PreviousVersionNode::PreviousVersionNode(ConstantPool* prev_constant_pool, |
2855 bool prev_cp_is_weak, GrowableArray<jweak>* prev_EMCP_methods) { |
3367 bool prev_cp_is_weak, GrowableArray<Method*>* prev_EMCP_methods) { |
2856 |
3368 |
2857 _prev_constant_pool = prev_constant_pool; |
3369 _prev_constant_pool = prev_constant_pool; |
2858 _prev_cp_is_weak = prev_cp_is_weak; |
3370 _prev_cp_is_weak = prev_cp_is_weak; |
2859 _prev_EMCP_methods = prev_EMCP_methods; |
3371 _prev_EMCP_methods = prev_EMCP_methods; |
2860 } |
3372 } |
2861 |
3373 |
2862 |
3374 |
2863 // Destroy a PreviousVersionNode |
3375 // Destroy a PreviousVersionNode |
2864 PreviousVersionNode::~PreviousVersionNode() { |
3376 PreviousVersionNode::~PreviousVersionNode() { |
2865 if (_prev_constant_pool != NULL) { |
3377 if (_prev_constant_pool != NULL) { |
2866 if (_prev_cp_is_weak) { |
3378 _prev_constant_pool = NULL; |
2867 JNIHandles::destroy_weak_global(_prev_constant_pool); |
|
2868 } else { |
|
2869 JNIHandles::destroy_global(_prev_constant_pool); |
|
2870 } |
|
2871 } |
3379 } |
2872 |
3380 |
2873 if (_prev_EMCP_methods != NULL) { |
3381 if (_prev_EMCP_methods != NULL) { |
2874 for (int i = _prev_EMCP_methods->length() - 1; i >= 0; i--) { |
|
2875 jweak method_ref = _prev_EMCP_methods->at(i); |
|
2876 if (method_ref != NULL) { |
|
2877 JNIHandles::destroy_weak_global(method_ref); |
|
2878 } |
|
2879 } |
|
2880 delete _prev_EMCP_methods; |
3382 delete _prev_EMCP_methods; |
2881 } |
3383 } |
2882 } |
3384 } |
2883 |
3385 |
2884 |
3386 |
2885 // Construct a PreviousVersionInfo entry |
3387 // Construct a PreviousVersionInfo entry |
2886 PreviousVersionInfo::PreviousVersionInfo(PreviousVersionNode *pv_node) { |
3388 PreviousVersionInfo::PreviousVersionInfo(PreviousVersionNode *pv_node) { |
2887 _prev_constant_pool_handle = constantPoolHandle(); // NULL handle |
3389 _prev_constant_pool_handle = constantPoolHandle(); // NULL handle |
2888 _prev_EMCP_method_handles = NULL; |
3390 _prev_EMCP_method_handles = NULL; |
2889 |
3391 |
2890 jobject cp_ref = pv_node->prev_constant_pool(); |
3392 ConstantPool* cp = pv_node->prev_constant_pool(); |
2891 assert(cp_ref != NULL, "constant pool ref was unexpectedly cleared"); |
3393 assert(cp != NULL, "constant pool ref was unexpectedly cleared"); |
2892 if (cp_ref == NULL) { |
3394 if (cp == NULL) { |
2893 return; // robustness |
3395 return; // robustness |
2894 } |
3396 } |
2895 |
3397 |
2896 constantPoolOop cp = (constantPoolOop)JNIHandles::resolve(cp_ref); |
3398 // make the ConstantPool* safe to return |
2897 if (cp == NULL) { |
|
2898 // Weak reference has been GC'ed. Since the constant pool has been |
|
2899 // GC'ed, the methods have also been GC'ed. |
|
2900 return; |
|
2901 } |
|
2902 |
|
2903 // make the constantPoolOop safe to return |
|
2904 _prev_constant_pool_handle = constantPoolHandle(cp); |
3399 _prev_constant_pool_handle = constantPoolHandle(cp); |
2905 |
3400 |
2906 GrowableArray<jweak>* method_refs = pv_node->prev_EMCP_methods(); |
3401 GrowableArray<Method*>* method_refs = pv_node->prev_EMCP_methods(); |
2907 if (method_refs == NULL) { |
3402 if (method_refs == NULL) { |
2908 // the instanceKlass did not have any EMCP methods |
3403 // the InstanceKlass did not have any EMCP methods |
2909 return; |
3404 return; |
2910 } |
3405 } |
2911 |
3406 |
2912 _prev_EMCP_method_handles = new GrowableArray<methodHandle>(10); |
3407 _prev_EMCP_method_handles = new GrowableArray<methodHandle>(10); |
2913 |
3408 |
2914 int n_methods = method_refs->length(); |
3409 int n_methods = method_refs->length(); |
2915 for (int i = 0; i < n_methods; i++) { |
3410 for (int i = 0; i < n_methods; i++) { |
2916 jweak method_ref = method_refs->at(i); |
3411 Method* method = method_refs->at(i); |
2917 assert(method_ref != NULL, "weak method ref was unexpectedly cleared"); |
3412 assert (method != NULL, "method has been cleared"); |
2918 if (method_ref == NULL) { |
3413 if (method == NULL) { |
2919 continue; // robustness |
3414 continue; // robustness |
2920 } |
3415 } |
2921 |
3416 // make the Method* safe to return |
2922 methodOop method = (methodOop)JNIHandles::resolve(method_ref); |
|
2923 if (method == NULL) { |
|
2924 // this entry has been GC'ed so skip it |
|
2925 continue; |
|
2926 } |
|
2927 |
|
2928 // make the methodOop safe to return |
|
2929 _prev_EMCP_method_handles->append(methodHandle(method)); |
3417 _prev_EMCP_method_handles->append(methodHandle(method)); |
2930 } |
3418 } |
2931 } |
3419 } |
2932 |
3420 |
2933 |
3421 |