19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/dictionary.hpp"
27 #include "classfile/javaClasses.hpp"
28 #include "classfile/systemDictionary.hpp"
29 #include "classfile/vmSymbols.hpp"
30 #include "gc/shared/collectedHeap.inline.hpp"
31 #include "logging/log.hpp"
32 #include "memory/heapInspection.hpp"
33 #include "memory/metadataFactory.hpp"
34 #include "memory/oopFactory.hpp"
35 #include "memory/resourceArea.hpp"
36 #include "oops/instanceKlass.hpp"
37 #include "oops/klass.inline.hpp"
38 #include "oops/oop.inline.hpp"
39 #include "runtime/atomic.hpp"
40 #include "runtime/orderAccess.inline.hpp"
41 #include "trace/traceMacros.hpp"
42 #include "utilities/macros.hpp"
43 #include "utilities/stack.inline.hpp"
44 #if INCLUDE_ALL_GCS
45 #include "gc/g1/g1SATBCardTableModRefBS.hpp"
46 #endif // INCLUDE_ALL_GCS
47
48 bool Klass::is_cloneable() const {
49 return _access_flags.is_cloneable_fast() ||
50 is_subtype_of(SystemDictionary::Cloneable_klass());
51 }
52
53 void Klass::set_is_cloneable() {
54 if (name() != vmSymbols::java_lang_invoke_MemberName()) {
55 _access_flags.set_is_cloneable_fast();
56 } else {
57 assert(is_final(), "no subclasses allowed");
58 // MemberName cloning should not be intrinsified and always happen in JVM_Clone.
59 }
60 }
61
62 void Klass::set_name(Symbol* n) {
63 _name = n;
64 if (_name != NULL) _name->increment_refcount();
65 }
66
423 }
424 current->set_next_sibling(sibling);
425 if (sibling != NULL) {
426 stack.push(sibling);
427 }
428
429 // Clean the implementors list and method data.
430 if (clean_alive_klasses && current->is_instance_klass()) {
431 InstanceKlass* ik = InstanceKlass::cast(current);
432 ik->clean_weak_instanceklass_links(is_alive);
433
434 // JVMTI RedefineClasses creates previous versions that are not in
435 // the class hierarchy, so process them here.
436 while ((ik = ik->previous_versions()) != NULL) {
437 ik->clean_weak_instanceklass_links(is_alive);
438 }
439 }
440 }
441 }
442
443 void Klass::klass_update_barrier_set(oop v) {
444 record_modified_oops();
445 }
446
447 // This barrier is used by G1 to remember the old oop values, so
448 // that we don't forget any objects that were live at the snapshot at
449 // the beginning. This function is only used when we write oops into Klasses.
450 void Klass::klass_update_barrier_set_pre(oop* p, oop v) {
451 #if INCLUDE_ALL_GCS
452 if (UseG1GC) {
453 oop obj = *p;
454 if (obj != NULL) {
455 G1SATBCardTableModRefBS::enqueue(obj);
456 }
457 }
458 #endif
459 }
460
461 void Klass::klass_oop_store(oop* p, oop v) {
462 assert(!Universe::heap()->is_in_reserved((void*)p), "Should store pointer into metadata");
463 assert(v == NULL || Universe::heap()->is_in_reserved((void*)v), "Should store pointer to an object");
464
465 // do the store
466 if (always_do_update_barrier) {
467 klass_oop_store((volatile oop*)p, v);
468 } else {
469 klass_update_barrier_set_pre(p, v);
470 *p = v;
471 klass_update_barrier_set(v);
472 }
473 }
474
475 void Klass::klass_oop_store(volatile oop* p, oop v) {
476 assert(!Universe::heap()->is_in_reserved((void*)p), "Should store pointer into metadata");
477 assert(v == NULL || Universe::heap()->is_in_reserved((void*)v), "Should store pointer to an object");
478
479 klass_update_barrier_set_pre((oop*)p, v); // Cast away volatile.
480 OrderAccess::release_store_ptr(p, v);
481 klass_update_barrier_set(v);
482 }
483
484 void Klass::oops_do(OopClosure* cl) {
485 cl->do_oop(&_java_mirror);
486 }
487
488 void Klass::remove_unshareable_info() {
489 assert (DumpSharedSpaces, "only called for DumpSharedSpaces");
490 TRACE_REMOVE_ID(this);
491
492 set_subklass(NULL);
493 set_next_sibling(NULL);
494 // Clear the java mirror
495 set_java_mirror(NULL);
496 set_next_link(NULL);
497
498 // Null out class_loader_data because we don't share that yet.
499 set_class_loader_data(NULL);
500 }
501
549 Klass* Klass::array_klass_or_null() {
550 EXCEPTION_MARK;
551 // No exception can be thrown by array_klass_impl when called with or_null == true.
552 // (In anycase, the execption mark will fail if it do so)
553 return array_klass_impl(true, THREAD);
554 }
555
556
557 Klass* Klass::array_klass_impl(bool or_null, int rank, TRAPS) {
558 fatal("array_klass should be dispatched to InstanceKlass, ObjArrayKlass or TypeArrayKlass");
559 return NULL;
560 }
561
562
563 Klass* Klass::array_klass_impl(bool or_null, TRAPS) {
564 fatal("array_klass should be dispatched to InstanceKlass, ObjArrayKlass or TypeArrayKlass");
565 return NULL;
566 }
567
568 oop Klass::class_loader() const { return class_loader_data()->class_loader(); }
569
570 // In product mode, this function doesn't have virtual function calls so
571 // there might be some performance advantage to handling InstanceKlass here.
572 const char* Klass::external_name() const {
573 if (is_instance_klass()) {
574 const InstanceKlass* ik = static_cast<const InstanceKlass*>(this);
575 if (ik->is_anonymous()) {
576 intptr_t hash = 0;
577 if (ik->java_mirror() != NULL) {
578 // java_mirror might not be created yet, return 0 as hash.
579 hash = ik->java_mirror()->identity_hash();
580 }
581 char hash_buf[40];
582 sprintf(hash_buf, "/" UINTX_FORMAT, (uintx)hash);
583 size_t hash_len = strlen(hash_buf);
584
585 size_t result_len = name()->utf8_length();
586 char* result = NEW_RESOURCE_ARRAY(char, result_len + hash_len + 1);
587 name()->as_klass_external_name(result, (int) result_len + 1);
588 assert(strlen(result) == result_len, "");
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/dictionary.hpp"
27 #include "classfile/javaClasses.hpp"
28 #include "classfile/systemDictionary.hpp"
29 #include "classfile/vmSymbols.hpp"
30 #include "gc/shared/collectedHeap.inline.hpp"
31 #include "logging/log.hpp"
32 #include "memory/heapInspection.hpp"
33 #include "memory/metadataFactory.hpp"
34 #include "memory/oopFactory.hpp"
35 #include "memory/resourceArea.hpp"
36 #include "oops/instanceKlass.hpp"
37 #include "oops/klass.inline.hpp"
38 #include "oops/oop.inline.hpp"
39 #include "runtime/access.inline.hpp"
40 #include "runtime/atomic.hpp"
41 #include "runtime/orderAccess.inline.hpp"
42 #include "trace/traceMacros.hpp"
43 #include "utilities/macros.hpp"
44 #include "utilities/stack.inline.hpp"
45
46 bool Klass::is_cloneable() const {
47 return _access_flags.is_cloneable_fast() ||
48 is_subtype_of(SystemDictionary::Cloneable_klass());
49 }
50
51 void Klass::set_is_cloneable() {
52 if (name() != vmSymbols::java_lang_invoke_MemberName()) {
53 _access_flags.set_is_cloneable_fast();
54 } else {
55 assert(is_final(), "no subclasses allowed");
56 // MemberName cloning should not be intrinsified and always happen in JVM_Clone.
57 }
58 }
59
60 void Klass::set_name(Symbol* n) {
61 _name = n;
62 if (_name != NULL) _name->increment_refcount();
63 }
64
421 }
422 current->set_next_sibling(sibling);
423 if (sibling != NULL) {
424 stack.push(sibling);
425 }
426
427 // Clean the implementors list and method data.
428 if (clean_alive_klasses && current->is_instance_klass()) {
429 InstanceKlass* ik = InstanceKlass::cast(current);
430 ik->clean_weak_instanceklass_links(is_alive);
431
432 // JVMTI RedefineClasses creates previous versions that are not in
433 // the class hierarchy, so process them here.
434 while ((ik = ik->previous_versions()) != NULL) {
435 ik->clean_weak_instanceklass_links(is_alive);
436 }
437 }
438 }
439 }
440
441 void Klass::set_java_mirror(oop m) {
442 KlassAccess<MO_RELEASE>::oop_store_at(this, in_bytes(java_mirror_offset()), m);
443 }
444
445 void Klass::oops_do(OopClosure* cl) {
446 cl->do_oop(&_java_mirror);
447 }
448
449 void Klass::remove_unshareable_info() {
450 assert (DumpSharedSpaces, "only called for DumpSharedSpaces");
451 TRACE_REMOVE_ID(this);
452
453 set_subklass(NULL);
454 set_next_sibling(NULL);
455 // Clear the java mirror
456 set_java_mirror(NULL);
457 set_next_link(NULL);
458
459 // Null out class_loader_data because we don't share that yet.
460 set_class_loader_data(NULL);
461 }
462
510 Klass* Klass::array_klass_or_null() {
511 EXCEPTION_MARK;
512 // No exception can be thrown by array_klass_impl when called with or_null == true.
513 // (In anycase, the execption mark will fail if it do so)
514 return array_klass_impl(true, THREAD);
515 }
516
517
518 Klass* Klass::array_klass_impl(bool or_null, int rank, TRAPS) {
519 fatal("array_klass should be dispatched to InstanceKlass, ObjArrayKlass or TypeArrayKlass");
520 return NULL;
521 }
522
523
524 Klass* Klass::array_klass_impl(bool or_null, TRAPS) {
525 fatal("array_klass should be dispatched to InstanceKlass, ObjArrayKlass or TypeArrayKlass");
526 return NULL;
527 }
528
529 oop Klass::class_loader() const { return class_loader_data()->class_loader(); }
530
531 oop* Klass::klass_holder_addr() const {
532 return class_loader_data()->class_loader_addr();
533 }
534
535 oop Klass::klass_holder() const {
536 return RootAccess<GC_ACCESS_ON_PHANTOM>::oop_load(klass_holder_addr());
537 }
538
539 // In product mode, this function doesn't have virtual function calls so
540 // there might be some performance advantage to handling InstanceKlass here.
541 const char* Klass::external_name() const {
542 if (is_instance_klass()) {
543 const InstanceKlass* ik = static_cast<const InstanceKlass*>(this);
544 if (ik->is_anonymous()) {
545 intptr_t hash = 0;
546 if (ik->java_mirror() != NULL) {
547 // java_mirror might not be created yet, return 0 as hash.
548 hash = ik->java_mirror()->identity_hash();
549 }
550 char hash_buf[40];
551 sprintf(hash_buf, "/" UINTX_FORMAT, (uintx)hash);
552 size_t hash_len = strlen(hash_buf);
553
554 size_t result_len = name()->utf8_length();
555 char* result = NEW_RESOURCE_ARRAY(char, result_len + hash_len + 1);
556 name()->as_klass_external_name(result, (int) result_len + 1);
557 assert(strlen(result) == result_len, "");
|