607
608 void HeapShared::add_scratch_resolved_references(ConstantPool* src, objArrayOop dest) {
609 if (SystemDictionaryShared::is_builtin_loader(src->pool_holder()->class_loader_data())) {
610 _scratch_objects_table->set_oop(src, dest);
611 }
612 }
613
614 objArrayOop HeapShared::scratch_resolved_references(ConstantPool* src) {
615 return (objArrayOop)_scratch_objects_table->get_oop(src);
616 }
617
618 void HeapShared::init_dumping() {
619 _scratch_objects_table = new (mtClass)MetaspaceObjToOopHandleTable();
620 _pending_roots = new GrowableArrayCHeap<oop, mtClassShared>(500);
621 }
622
623 void HeapShared::init_scratch_objects_for_basic_type_mirrors(TRAPS) {
624 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
625 BasicType bt = (BasicType)i;
626 if (!is_reference_type(bt)) {
627 oop m = java_lang_Class::create_basic_type_mirror(type2name(bt), bt, CHECK);
628 _scratch_basic_type_mirrors[i] = OopHandle(Universe::vm_global(), m);
629 }
630 }
631 }
632
633 // Given java_mirror that represents a (primitive or reference) type T,
634 // return the "scratch" version that represents the same type T. Note
635 // that java_mirror will be returned if the mirror is already a scratch mirror.
636 //
637 // See java_lang_Class::create_scratch_mirror() for more info.
638 oop HeapShared::scratch_java_mirror(oop java_mirror) {
639 assert(java_lang_Class::is_instance(java_mirror), "must be");
640
641 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
642 BasicType bt = (BasicType)i;
643 if (!is_reference_type(bt)) {
644 if (_scratch_basic_type_mirrors[i].resolve() == java_mirror) {
645 return java_mirror;
646 }
647 }
778 }
779
780 oop class_data = java_lang_Class::class_data(orig_mirror);
781 java_lang_Class::set_class_data(m, class_data);
782 if (class_data != nullptr) {
783 bool success = archive_reachable_objects_from(1, _dump_time_special_subgraph, class_data);
784 assert(success, "sanity");
785 }
786
787 if (log_is_enabled(Debug, aot, init)) {
788 ResourceMark rm;
789 log_debug(aot, init)("copied %3d field(s) in aot-initialized mirror %s%s%s", nfields, ik->external_name(),
790 ik->is_hidden() ? " (hidden)" : "",
791 ik->is_enum_subclass() ? " (enum)" : "");
792 }
793 }
794
795 void HeapShared::copy_java_mirror(oop orig_mirror, oop scratch_m) {
796 // We need to retain the identity_hash, because it may have been used by some hashtables
797 // in the shared heap.
798 if (!orig_mirror->fast_no_hash_check()) {
799 intptr_t src_hash = orig_mirror->identity_hash();
800 if (UseCompactObjectHeaders) {
801 narrowKlass nk = CompressedKlassPointers::encode(orig_mirror->klass());
802 scratch_m->set_mark(markWord::prototype().set_narrow_klass(nk).copy_set_hash(src_hash));
803 } else {
804 scratch_m->set_mark(markWord::prototype().copy_set_hash(src_hash));
805 }
806 assert(scratch_m->mark().is_unlocked(), "sanity");
807
808 DEBUG_ONLY(intptr_t archived_hash = scratch_m->identity_hash());
809 assert(src_hash == archived_hash, "Different hash codes: original " INTPTR_FORMAT ", archived " INTPTR_FORMAT, src_hash, archived_hash);
810 }
811
812 if (CDSConfig::is_dumping_aot_linked_classes()) {
813 java_lang_Class::set_module(scratch_m, java_lang_Class::module(orig_mirror));
814 java_lang_Class::set_protection_domain(scratch_m, java_lang_Class::protection_domain(orig_mirror));
815 }
816 }
817
818 static objArrayOop get_archived_resolved_references(InstanceKlass* src_ik) {
819 if (SystemDictionaryShared::is_builtin_loader(src_ik->class_loader_data())) {
820 objArrayOop rr = src_ik->constants()->resolved_references_or_null();
821 if (rr != nullptr && !HeapShared::is_too_large_to_archive(rr)) {
822 return HeapShared::scratch_resolved_references(src_ik->constants());
823 }
824 }
825 return nullptr;
826 }
827
828 void HeapShared::archive_strings() {
829 assert(HeapShared::is_writing_mapping_mode(), "should not reach here");
|
607
608 void HeapShared::add_scratch_resolved_references(ConstantPool* src, objArrayOop dest) {
609 if (SystemDictionaryShared::is_builtin_loader(src->pool_holder()->class_loader_data())) {
610 _scratch_objects_table->set_oop(src, dest);
611 }
612 }
613
614 objArrayOop HeapShared::scratch_resolved_references(ConstantPool* src) {
615 return (objArrayOop)_scratch_objects_table->get_oop(src);
616 }
617
618 void HeapShared::init_dumping() {
619 _scratch_objects_table = new (mtClass)MetaspaceObjToOopHandleTable();
620 _pending_roots = new GrowableArrayCHeap<oop, mtClassShared>(500);
621 }
622
623 void HeapShared::init_scratch_objects_for_basic_type_mirrors(TRAPS) {
624 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
625 BasicType bt = (BasicType)i;
626 if (!is_reference_type(bt)) {
627 oop m = java_lang_Class::create_basic_type_mirror(type2name(bt), bt, true, CHECK);
628 _scratch_basic_type_mirrors[i] = OopHandle(Universe::vm_global(), m);
629 }
630 }
631 }
632
633 // Given java_mirror that represents a (primitive or reference) type T,
634 // return the "scratch" version that represents the same type T. Note
635 // that java_mirror will be returned if the mirror is already a scratch mirror.
636 //
637 // See java_lang_Class::create_scratch_mirror() for more info.
638 oop HeapShared::scratch_java_mirror(oop java_mirror) {
639 assert(java_lang_Class::is_instance(java_mirror), "must be");
640
641 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
642 BasicType bt = (BasicType)i;
643 if (!is_reference_type(bt)) {
644 if (_scratch_basic_type_mirrors[i].resolve() == java_mirror) {
645 return java_mirror;
646 }
647 }
778 }
779
780 oop class_data = java_lang_Class::class_data(orig_mirror);
781 java_lang_Class::set_class_data(m, class_data);
782 if (class_data != nullptr) {
783 bool success = archive_reachable_objects_from(1, _dump_time_special_subgraph, class_data);
784 assert(success, "sanity");
785 }
786
787 if (log_is_enabled(Debug, aot, init)) {
788 ResourceMark rm;
789 log_debug(aot, init)("copied %3d field(s) in aot-initialized mirror %s%s%s", nfields, ik->external_name(),
790 ik->is_hidden() ? " (hidden)" : "",
791 ik->is_enum_subclass() ? " (enum)" : "");
792 }
793 }
794
795 void HeapShared::copy_java_mirror(oop orig_mirror, oop scratch_m) {
796 // We need to retain the identity_hash, because it may have been used by some hashtables
797 // in the shared heap.
798 assert(!UseCompactObjectHeaders || scratch_m->mark().is_not_hashed_expanded(), "scratch mirror must have not-hashed-expanded state");
799 assert(!UseCompactObjectHeaders || !orig_mirror->mark().is_not_hashed_expanded(), "must not be not-hashed-expanded");
800 if (!orig_mirror->fast_no_hash_check()) {
801 intptr_t orig_mark = orig_mirror->mark().value();
802 intptr_t src_hash = orig_mirror->identity_hash();
803 if (UseCompactObjectHeaders) {
804 // We leave the cases not_hashed/not_hashed_expanded as they are.
805 assert(orig_mirror->mark().is_hashed_not_expanded() || orig_mirror->mark().is_hashed_expanded(), "must be hashed");
806 Klass* orig_klass = orig_mirror->klass();
807 narrowKlass nk = CompressedKlassPointers::encode(orig_klass);
808 markWord mark = markWord::prototype().set_narrow_klass(nk);
809 mark = mark.copy_hashctrl_from(orig_mirror->mark());
810 if (mark.is_hashed_not_expanded()) {
811 scratch_m->set_mark(scratch_m->initialize_hash_if_necessary(orig_mirror, orig_klass, mark));
812 } else {
813 assert(mark.is_hashed_expanded(), "must be hashed & moved");
814 int offset = orig_klass->hash_offset_in_bytes(orig_mirror, mark);
815 assert(offset >= 4, "hash offset must not be in header");
816 scratch_m->int_field_put(offset, (jint) src_hash);
817 scratch_m->set_mark(mark);
818 }
819 assert(scratch_m->mark().is_hashed_expanded(), "must be hashed & moved");
820 assert(scratch_m->mark().is_not_hashed_expanded() || scratch_m->mark().is_hashed_expanded(), "must be not hashed and expanded");
821 } else {
822 scratch_m->set_mark(markWord::prototype().copy_set_hash(src_hash));
823 DEBUG_ONLY(intptr_t archived_hash = scratch_m->identity_hash());
824 assert(src_hash == archived_hash, "Different hash codes: original " INTPTR_FORMAT ", archived " INTPTR_FORMAT, src_hash, archived_hash);
825 }
826 assert(scratch_m->mark().is_unlocked(), "sanity");
827 }
828
829 if (CDSConfig::is_dumping_aot_linked_classes()) {
830 java_lang_Class::set_module(scratch_m, java_lang_Class::module(orig_mirror));
831 java_lang_Class::set_protection_domain(scratch_m, java_lang_Class::protection_domain(orig_mirror));
832 }
833 }
834
835 static objArrayOop get_archived_resolved_references(InstanceKlass* src_ik) {
836 if (SystemDictionaryShared::is_builtin_loader(src_ik->class_loader_data())) {
837 objArrayOop rr = src_ik->constants()->resolved_references_or_null();
838 if (rr != nullptr && !HeapShared::is_too_large_to_archive(rr)) {
839 return HeapShared::scratch_resolved_references(src_ik->constants());
840 }
841 }
842 return nullptr;
843 }
844
845 void HeapShared::archive_strings() {
846 assert(HeapShared::is_writing_mapping_mode(), "should not reach here");
|