696 return (objArrayOop)_scratch_objects_table->get_oop(src);
697 }
698
699 void HeapShared::remove_scratch_resolved_references(ConstantPool* src) {
700 if (CDSConfig::is_dumping_heap()) {
701 _scratch_objects_table->remove_oop(src);
702 }
703 }
704
705 void HeapShared::init_dumping() {
706 _scratch_objects_table = new (mtClass)MetaspaceObjToOopHandleTable();
707 _pending_roots = new GrowableArrayCHeap<oop, mtClassShared>(500);
708 _pending_roots->append(nullptr); // root index 0 represents a null oop
709 DEBUG_ONLY(_dumptime_classes_with_cached_oops = new (mtClassShared)ArchivableKlassTable());
710 }
711
712 void HeapShared::init_scratch_objects_for_basic_type_mirrors(TRAPS) {
713 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
714 BasicType bt = (BasicType)i;
715 if (!is_reference_type(bt)) {
716 oop m = java_lang_Class::create_basic_type_mirror(type2name(bt), bt, CHECK);
717 _scratch_basic_type_mirrors[i] = OopHandle(Universe::vm_global(), m);
718 }
719 }
720 }
721
722 // Given java_mirror that represents a (primitive or reference) type T,
723 // return the "scratch" version that represents the same type T. Note
724 // that java_mirror will be returned if the mirror is already a scratch mirror.
725 //
726 // See java_lang_Class::create_scratch_mirror() for more info.
727 oop HeapShared::scratch_java_mirror(oop java_mirror) {
728 assert(java_lang_Class::is_instance(java_mirror), "must be");
729
730 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
731 BasicType bt = (BasicType)i;
732 if (!is_reference_type(bt)) {
733 if (_scratch_basic_type_mirrors[i].resolve() == java_mirror) {
734 return java_mirror;
735 }
736 }
867 }
868
869 oop class_data = java_lang_Class::class_data(orig_mirror);
870 java_lang_Class::set_class_data(m, class_data);
871 if (class_data != nullptr) {
872 bool success = archive_reachable_objects_from(1, _dump_time_special_subgraph, class_data);
873 assert(success, "sanity");
874 }
875
876 if (log_is_enabled(Debug, aot, init)) {
877 ResourceMark rm;
878 log_debug(aot, init)("copied %3d field(s) in aot-initialized mirror %s%s%s", nfields, ik->external_name(),
879 ik->is_hidden() ? " (hidden)" : "",
880 ik->is_enum_subclass() ? " (enum)" : "");
881 }
882 }
883
884 void HeapShared::copy_java_mirror(oop orig_mirror, oop scratch_m) {
885 // We need to retain the identity_hash, because it may have been used by some hashtables
886 // in the shared heap.
887 if (!orig_mirror->fast_no_hash_check()) {
888 intptr_t src_hash = orig_mirror->identity_hash();
889 if (UseCompactObjectHeaders) {
890 narrowKlass nk = CompressedKlassPointers::encode(orig_mirror->klass());
891 scratch_m->set_mark(markWord::prototype().set_narrow_klass(nk).copy_set_hash(src_hash));
892 } else {
893 scratch_m->set_mark(markWord::prototype().copy_set_hash(src_hash));
894 }
895 assert(scratch_m->mark().is_unlocked(), "sanity");
896
897 DEBUG_ONLY(intptr_t archived_hash = scratch_m->identity_hash());
898 assert(src_hash == archived_hash, "Different hash codes: original " INTPTR_FORMAT ", archived " INTPTR_FORMAT, src_hash, archived_hash);
899 }
900
901 if (CDSConfig::is_dumping_aot_linked_classes()) {
902 java_lang_Class::set_module(scratch_m, java_lang_Class::module(orig_mirror));
903 java_lang_Class::set_protection_domain(scratch_m, java_lang_Class::protection_domain(orig_mirror));
904 }
905 }
906
907 static objArrayOop get_archived_resolved_references(InstanceKlass* src_ik) {
908 if (SystemDictionaryShared::is_builtin_loader(src_ik->class_loader_data())) {
909 objArrayOop rr = src_ik->constants()->resolved_references_or_null();
910 if (rr != nullptr && !HeapShared::is_too_large_to_archive(rr)) {
911 return HeapShared::scratch_resolved_references(src_ik->constants());
912 }
913 }
914 return nullptr;
915 }
916
917 int HeapShared::archive_exception_instance(oop exception) {
918 bool success = archive_reachable_objects_from(1, _dump_time_special_subgraph, exception);
|
696 return (objArrayOop)_scratch_objects_table->get_oop(src);
697 }
698
699 void HeapShared::remove_scratch_resolved_references(ConstantPool* src) {
700 if (CDSConfig::is_dumping_heap()) {
701 _scratch_objects_table->remove_oop(src);
702 }
703 }
704
705 void HeapShared::init_dumping() {
706 _scratch_objects_table = new (mtClass)MetaspaceObjToOopHandleTable();
707 _pending_roots = new GrowableArrayCHeap<oop, mtClassShared>(500);
708 _pending_roots->append(nullptr); // root index 0 represents a null oop
709 DEBUG_ONLY(_dumptime_classes_with_cached_oops = new (mtClassShared)ArchivableKlassTable());
710 }
711
712 void HeapShared::init_scratch_objects_for_basic_type_mirrors(TRAPS) {
713 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
714 BasicType bt = (BasicType)i;
715 if (!is_reference_type(bt)) {
716 oop m = java_lang_Class::create_basic_type_mirror(type2name(bt), bt, true, CHECK);
717 _scratch_basic_type_mirrors[i] = OopHandle(Universe::vm_global(), m);
718 }
719 }
720 }
721
722 // Given java_mirror that represents a (primitive or reference) type T,
723 // return the "scratch" version that represents the same type T. Note
724 // that java_mirror will be returned if the mirror is already a scratch mirror.
725 //
726 // See java_lang_Class::create_scratch_mirror() for more info.
727 oop HeapShared::scratch_java_mirror(oop java_mirror) {
728 assert(java_lang_Class::is_instance(java_mirror), "must be");
729
730 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
731 BasicType bt = (BasicType)i;
732 if (!is_reference_type(bt)) {
733 if (_scratch_basic_type_mirrors[i].resolve() == java_mirror) {
734 return java_mirror;
735 }
736 }
867 }
868
869 oop class_data = java_lang_Class::class_data(orig_mirror);
870 java_lang_Class::set_class_data(m, class_data);
871 if (class_data != nullptr) {
872 bool success = archive_reachable_objects_from(1, _dump_time_special_subgraph, class_data);
873 assert(success, "sanity");
874 }
875
876 if (log_is_enabled(Debug, aot, init)) {
877 ResourceMark rm;
878 log_debug(aot, init)("copied %3d field(s) in aot-initialized mirror %s%s%s", nfields, ik->external_name(),
879 ik->is_hidden() ? " (hidden)" : "",
880 ik->is_enum_subclass() ? " (enum)" : "");
881 }
882 }
883
884 void HeapShared::copy_java_mirror(oop orig_mirror, oop scratch_m) {
885 // We need to retain the identity_hash, because it may have been used by some hashtables
886 // in the shared heap.
887 assert(!UseCompactObjectHeaders || scratch_m->mark().is_not_hashed_expanded(), "scratch mirror must have not-hashed-expanded state");
888 assert(!UseCompactObjectHeaders || !orig_mirror->mark().is_not_hashed_expanded(), "must not be not-hashed-expanded");
889 if (!orig_mirror->fast_no_hash_check()) {
890 intptr_t orig_mark = orig_mirror->mark().value();
891 intptr_t src_hash = orig_mirror->identity_hash();
892 if (UseCompactObjectHeaders) {
893 // We leave the cases not_hashed/not_hashed_expanded as they are.
894 assert(orig_mirror->mark().is_hashed_not_expanded() || orig_mirror->mark().is_hashed_expanded(), "must be hashed");
895 Klass* orig_klass = orig_mirror->klass();
896 narrowKlass nk = CompressedKlassPointers::encode(orig_klass);
897 markWord mark = markWord::prototype().set_narrow_klass(nk);
898 mark = mark.copy_hashctrl_from(orig_mirror->mark());
899 if (mark.is_hashed_not_expanded()) {
900 scratch_m->set_mark(scratch_m->initialize_hash_if_necessary(orig_mirror, orig_klass, mark));
901 } else {
902 assert(mark.is_hashed_expanded(), "must be hashed & moved");
903 int offset = orig_klass->hash_offset_in_bytes(orig_mirror, mark);
904 assert(offset >= 4, "hash offset must not be in header");
905 scratch_m->int_field_put(offset, (jint) src_hash);
906 scratch_m->set_mark(mark);
907 }
908 assert(scratch_m->mark().is_hashed_expanded(), "must be hashed & moved");
909 assert(scratch_m->mark().is_not_hashed_expanded() || scratch_m->mark().is_hashed_expanded(), "must be not hashed and expanded");
910 } else {
911 scratch_m->set_mark(markWord::prototype().copy_set_hash(src_hash));
912 DEBUG_ONLY(intptr_t archived_hash = scratch_m->identity_hash());
913 assert(src_hash == archived_hash, "Different hash codes: original " INTPTR_FORMAT ", archived " INTPTR_FORMAT, src_hash, archived_hash);
914 }
915 assert(scratch_m->mark().is_unlocked(), "sanity");
916 }
917
918 if (CDSConfig::is_dumping_aot_linked_classes()) {
919 java_lang_Class::set_module(scratch_m, java_lang_Class::module(orig_mirror));
920 java_lang_Class::set_protection_domain(scratch_m, java_lang_Class::protection_domain(orig_mirror));
921 }
922 }
923
924 static objArrayOop get_archived_resolved_references(InstanceKlass* src_ik) {
925 if (SystemDictionaryShared::is_builtin_loader(src_ik->class_loader_data())) {
926 objArrayOop rr = src_ik->constants()->resolved_references_or_null();
927 if (rr != nullptr && !HeapShared::is_too_large_to_archive(rr)) {
928 return HeapShared::scratch_resolved_references(src_ik->constants());
929 }
930 }
931 return nullptr;
932 }
933
934 int HeapShared::archive_exception_instance(oop exception) {
935 bool success = archive_reachable_objects_from(1, _dump_time_special_subgraph, exception);
|