< prev index next >

src/hotspot/share/cds/heapShared.cpp

Print this page

 698   return (objArrayOop)_scratch_objects_table->get_oop(src);
 699 }
 700 
 701 void HeapShared::remove_scratch_resolved_references(ConstantPool* src) {
 702   if (CDSConfig::is_dumping_heap()) {
 703     _scratch_objects_table->remove_oop(src);
 704   }
 705 }
 706 
 707 void HeapShared::init_dumping() {
 708   _scratch_objects_table = new (mtClass)MetaspaceObjToOopHandleTable();
 709   _pending_roots = new GrowableArrayCHeap<oop, mtClassShared>(500);
 710   _pending_roots->append(nullptr); // root index 0 represents a null oop
 711   DEBUG_ONLY(_dumptime_classes_with_cached_oops = new (mtClassShared)ArchivableKlassTable());
 712 }
 713 
 714 void HeapShared::init_scratch_objects_for_basic_type_mirrors(TRAPS) {
 715   for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
 716     BasicType bt = (BasicType)i;
 717     if (!is_reference_type(bt)) {
 718       oop m = java_lang_Class::create_basic_type_mirror(type2name(bt), bt, CHECK);
 719       _scratch_basic_type_mirrors[i] = OopHandle(Universe::vm_global(), m);
 720     }
 721   }
 722 }
 723 
 724 // Given java_mirror that represents a (primitive or reference) type T,
 725 // return the "scratch" version that represents the same type T. Note
 726 // that java_mirror will be returned if the mirror is already a scratch mirror.
 727 //
 728 // See java_lang_Class::create_scratch_mirror() for more info.
 729 oop HeapShared::scratch_java_mirror(oop java_mirror) {
 730   assert(java_lang_Class::is_instance(java_mirror), "must be");
 731 
 732   for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
 733     BasicType bt = (BasicType)i;
 734     if (!is_reference_type(bt)) {
 735       if (_scratch_basic_type_mirrors[i].resolve() == java_mirror) {
 736         return java_mirror;
 737       }
 738     }

 869   }
 870 
 871   oop class_data = java_lang_Class::class_data(orig_mirror);
 872   java_lang_Class::set_class_data(m, class_data);
 873   if (class_data != nullptr) {
 874     bool success = archive_reachable_objects_from(1, _dump_time_special_subgraph, class_data);
 875     assert(success, "sanity");
 876   }
 877 
 878   if (log_is_enabled(Debug, aot, init)) {
 879     ResourceMark rm;
 880     log_debug(aot, init)("copied %3d field(s) in aot-initialized mirror %s%s%s", nfields, ik->external_name(),
 881                          ik->is_hidden() ? " (hidden)" : "",
 882                          ik->is_enum_subclass() ? " (enum)" : "");
 883   }
 884 }
 885 
 886 void HeapShared::copy_java_mirror(oop orig_mirror, oop scratch_m) {
 887   // We need to retain the identity_hash, because it may have been used by some hashtables
 888   // in the shared heap.


 889   if (!orig_mirror->fast_no_hash_check()) {

 890     intptr_t src_hash = orig_mirror->identity_hash();
 891     if (UseCompactObjectHeaders) {
 892       narrowKlass nk = CompressedKlassPointers::encode(orig_mirror->klass());
 893       scratch_m->set_mark(markWord::prototype().set_narrow_klass(nk).copy_set_hash(src_hash));















 894     } else {
 895       scratch_m->set_mark(markWord::prototype().copy_set_hash(src_hash));


 896     }
 897     assert(scratch_m->mark().is_unlocked(), "sanity");
 898 
 899     DEBUG_ONLY(intptr_t archived_hash = scratch_m->identity_hash());
 900     assert(src_hash == archived_hash, "Different hash codes: original " INTPTR_FORMAT ", archived " INTPTR_FORMAT, src_hash, archived_hash);
 901   }
 902 
 903   if (CDSConfig::is_dumping_aot_linked_classes()) {
 904     java_lang_Class::set_module(scratch_m, java_lang_Class::module(orig_mirror));
 905     java_lang_Class::set_protection_domain(scratch_m, java_lang_Class::protection_domain(orig_mirror));
 906   }
 907 }
 908 
 909 static objArrayOop get_archived_resolved_references(InstanceKlass* src_ik) {
 910   if (SystemDictionaryShared::is_builtin_loader(src_ik->class_loader_data())) {
 911     objArrayOop rr = src_ik->constants()->resolved_references_or_null();
 912     if (rr != nullptr && !HeapShared::is_too_large_to_archive(rr)) {
 913       return HeapShared::scratch_resolved_references(src_ik->constants());
 914     }
 915   }
 916   return nullptr;
 917 }
 918 
 919 int HeapShared::archive_exception_instance(oop exception) {
 920   bool success = archive_reachable_objects_from(1, _dump_time_special_subgraph, exception);

 698   return (objArrayOop)_scratch_objects_table->get_oop(src);
 699 }
 700 
 701 void HeapShared::remove_scratch_resolved_references(ConstantPool* src) {
 702   if (CDSConfig::is_dumping_heap()) {
 703     _scratch_objects_table->remove_oop(src);
 704   }
 705 }
 706 
 707 void HeapShared::init_dumping() {
 708   _scratch_objects_table = new (mtClass)MetaspaceObjToOopHandleTable();
 709   _pending_roots = new GrowableArrayCHeap<oop, mtClassShared>(500);
 710   _pending_roots->append(nullptr); // root index 0 represents a null oop
 711   DEBUG_ONLY(_dumptime_classes_with_cached_oops = new (mtClassShared)ArchivableKlassTable());
 712 }
 713 
 714 void HeapShared::init_scratch_objects_for_basic_type_mirrors(TRAPS) {
 715   for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
 716     BasicType bt = (BasicType)i;
 717     if (!is_reference_type(bt)) {
 718       oop m = java_lang_Class::create_basic_type_mirror(type2name(bt), bt, true, CHECK);
 719       _scratch_basic_type_mirrors[i] = OopHandle(Universe::vm_global(), m);
 720     }
 721   }
 722 }
 723 
 724 // Given java_mirror that represents a (primitive or reference) type T,
 725 // return the "scratch" version that represents the same type T. Note
 726 // that java_mirror will be returned if the mirror is already a scratch mirror.
 727 //
 728 // See java_lang_Class::create_scratch_mirror() for more info.
 729 oop HeapShared::scratch_java_mirror(oop java_mirror) {
 730   assert(java_lang_Class::is_instance(java_mirror), "must be");
 731 
 732   for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
 733     BasicType bt = (BasicType)i;
 734     if (!is_reference_type(bt)) {
 735       if (_scratch_basic_type_mirrors[i].resolve() == java_mirror) {
 736         return java_mirror;
 737       }
 738     }

 869   }
 870 
 871   oop class_data = java_lang_Class::class_data(orig_mirror);
 872   java_lang_Class::set_class_data(m, class_data);
 873   if (class_data != nullptr) {
 874     bool success = archive_reachable_objects_from(1, _dump_time_special_subgraph, class_data);
 875     assert(success, "sanity");
 876   }
 877 
 878   if (log_is_enabled(Debug, aot, init)) {
 879     ResourceMark rm;
 880     log_debug(aot, init)("copied %3d field(s) in aot-initialized mirror %s%s%s", nfields, ik->external_name(),
 881                          ik->is_hidden() ? " (hidden)" : "",
 882                          ik->is_enum_subclass() ? " (enum)" : "");
 883   }
 884 }
 885 
 886 void HeapShared::copy_java_mirror(oop orig_mirror, oop scratch_m) {
 887   // We need to retain the identity_hash, because it may have been used by some hashtables
 888   // in the shared heap.
 889   assert(!UseCompactObjectHeaders || scratch_m->mark().is_not_hashed_expanded(), "scratch mirror must have not-hashed-expanded state");
 890   assert(!UseCompactObjectHeaders || !orig_mirror->mark().is_not_hashed_expanded(), "must not be not-hashed-expanded");
 891   if (!orig_mirror->fast_no_hash_check()) {
 892     intptr_t orig_mark = orig_mirror->mark().value();
 893     intptr_t src_hash = orig_mirror->identity_hash();
 894     if (UseCompactObjectHeaders) {
 895       // We leave the cases not_hashed/not_hashed_expanded as they are.
 896       assert(orig_mirror->mark().is_hashed_not_expanded() || orig_mirror->mark().is_hashed_expanded(), "must be hashed");
 897       Klass* orig_klass = orig_mirror->klass();
 898       narrowKlass nk = CompressedKlassPointers::encode(orig_klass);
 899       markWord mark = markWord::prototype().set_narrow_klass(nk);
 900       mark = mark.copy_hashctrl_from(orig_mirror->mark());
 901       if (mark.is_hashed_not_expanded()) {
 902         scratch_m->set_mark(scratch_m->initialize_hash_if_necessary(orig_mirror, orig_klass, mark));
 903       } else {
 904         assert(mark.is_hashed_expanded(), "must be hashed & moved");
 905         int offset = orig_klass->hash_offset_in_bytes(orig_mirror, mark);
 906         assert(offset >= 4, "hash offset must not be in header");
 907         scratch_m->int_field_put(offset, (jint) src_hash);
 908         scratch_m->set_mark(mark);
 909       }
 910       assert(scratch_m->mark().is_hashed_expanded(), "must be hashed & moved");
 911       assert(scratch_m->mark().is_not_hashed_expanded() || scratch_m->mark().is_hashed_expanded(), "must be not hashed and expanded");
 912     } else {
 913       scratch_m->set_mark(markWord::prototype().copy_set_hash(src_hash));
 914       DEBUG_ONLY(intptr_t archived_hash = scratch_m->identity_hash());
 915       assert(src_hash == archived_hash, "Different hash codes: original " INTPTR_FORMAT ", archived " INTPTR_FORMAT, src_hash, archived_hash);
 916     }
 917     assert(scratch_m->mark().is_unlocked(), "sanity");



 918   }
 919 
 920   if (CDSConfig::is_dumping_aot_linked_classes()) {
 921     java_lang_Class::set_module(scratch_m, java_lang_Class::module(orig_mirror));
 922     java_lang_Class::set_protection_domain(scratch_m, java_lang_Class::protection_domain(orig_mirror));
 923   }
 924 }
 925 
 926 static objArrayOop get_archived_resolved_references(InstanceKlass* src_ik) {
 927   if (SystemDictionaryShared::is_builtin_loader(src_ik->class_loader_data())) {
 928     objArrayOop rr = src_ik->constants()->resolved_references_or_null();
 929     if (rr != nullptr && !HeapShared::is_too_large_to_archive(rr)) {
 930       return HeapShared::scratch_resolved_references(src_ik->constants());
 931     }
 932   }
 933   return nullptr;
 934 }
 935 
 936 int HeapShared::archive_exception_instance(oop exception) {
 937   bool success = archive_reachable_objects_from(1, _dump_time_special_subgraph, exception);
< prev index next >