< prev index next >

src/hotspot/share/cds/heapShared.cpp

Print this page

 399 
 400 void HeapShared::add_scratch_resolved_references(ConstantPool* src, objArrayOop dest) {
 401   if (SystemDictionaryShared::is_builtin_loader(src->pool_holder()->class_loader_data())) {
 402     _scratch_objects_table->set_oop(src, dest);
 403   }
 404 }
 405 
 406 objArrayOop HeapShared::scratch_resolved_references(ConstantPool* src) {
 407   return (objArrayOop)_scratch_objects_table->get_oop(src);
 408 }
 409 
 410 void HeapShared::init_dumping() {
 411   _scratch_objects_table = new (mtClass)MetaspaceObjToOopHandleTable();
 412   _pending_roots = new GrowableArrayCHeap<oop, mtClassShared>(500);
 413 }
 414 
 415 void HeapShared::init_scratch_objects_for_basic_type_mirrors(TRAPS) {
 416   for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
 417     BasicType bt = (BasicType)i;
 418     if (!is_reference_type(bt)) {
 419       oop m = java_lang_Class::create_basic_type_mirror(type2name(bt), bt, CHECK);
 420       _scratch_basic_type_mirrors[i] = OopHandle(Universe::vm_global(), m);
 421     }
 422   }
 423 }
 424 
 425 // Given java_mirror that represents a (primitive or reference) type T,
 426 // return the "scratch" version that represents the same type T.
 427 // Note that if java_mirror will be returned if it's already a
 428 // scratch mirror.
 429 //
 430 // See java_lang_Class::create_scratch_mirror() for more info.
 431 oop HeapShared::scratch_java_mirror(oop java_mirror) {
 432   assert(java_lang_Class::is_instance(java_mirror), "must be");
 433 
 434   for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
 435     BasicType bt = (BasicType)i;
 436     if (!is_reference_type(bt)) {
 437       if (_scratch_basic_type_mirrors[i].resolve() == java_mirror) {
 438         return java_mirror;
 439       }

 574   }
 575 
 576   oop class_data = java_lang_Class::class_data(orig_mirror);
 577   java_lang_Class::set_class_data(m, class_data);
 578   if (class_data != nullptr) {
 579     bool success = archive_reachable_objects_from(1, _dump_time_special_subgraph, class_data);
 580     assert(success, "sanity");
 581   }
 582 
 583   if (log_is_enabled(Debug, aot, init)) {
 584     ResourceMark rm;
 585     log_debug(aot, init)("copied %3d field(s) in aot-initialized mirror %s%s%s", nfields, ik->external_name(),
 586                          ik->is_hidden() ? " (hidden)" : "",
 587                          ik->is_enum_subclass() ? " (enum)" : "");
 588   }
 589 }
 590 
 591 static void copy_java_mirror_hashcode(oop orig_mirror, oop scratch_m) {
 592   // We need to retain the identity_hash, because it may have been used by some hashtables
 593   // in the shared heap.

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

 595     intptr_t src_hash = orig_mirror->identity_hash();
 596     if (UseCompactObjectHeaders) {
 597       narrowKlass nk = CompressedKlassPointers::encode(orig_mirror->klass());
 598       scratch_m->set_mark(markWord::prototype().set_narrow_klass(nk).copy_set_hash(src_hash));















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


 601     }
 602     assert(scratch_m->mark().is_unlocked(), "sanity");
 603 
 604     DEBUG_ONLY(intptr_t archived_hash = scratch_m->identity_hash());
 605     assert(src_hash == archived_hash, "Different hash codes: original " INTPTR_FORMAT ", archived " INTPTR_FORMAT, src_hash, archived_hash);
 606   }
 607 }
 608 
 609 static objArrayOop get_archived_resolved_references(InstanceKlass* src_ik) {
 610   if (SystemDictionaryShared::is_builtin_loader(src_ik->class_loader_data())) {
 611     objArrayOop rr = src_ik->constants()->resolved_references_or_null();
 612     if (rr != nullptr && !ArchiveHeapWriter::is_too_large_to_archive(rr)) {
 613       return HeapShared::scratch_resolved_references(src_ik->constants());
 614     }
 615   }
 616   return nullptr;
 617 }
 618 
 619 void HeapShared::archive_strings() {
 620   oop shared_strings_array = StringTable::init_shared_strings_array();
 621   bool success = archive_reachable_objects_from(1, _dump_time_special_subgraph, shared_strings_array);
 622   assert(success, "shared strings array must not point to arrays or strings that are too large to archive");
 623   StringTable::set_shared_strings_array_index(append_root(shared_strings_array));
 624 }
 625 

 399 
 400 void HeapShared::add_scratch_resolved_references(ConstantPool* src, objArrayOop dest) {
 401   if (SystemDictionaryShared::is_builtin_loader(src->pool_holder()->class_loader_data())) {
 402     _scratch_objects_table->set_oop(src, dest);
 403   }
 404 }
 405 
 406 objArrayOop HeapShared::scratch_resolved_references(ConstantPool* src) {
 407   return (objArrayOop)_scratch_objects_table->get_oop(src);
 408 }
 409 
 410 void HeapShared::init_dumping() {
 411   _scratch_objects_table = new (mtClass)MetaspaceObjToOopHandleTable();
 412   _pending_roots = new GrowableArrayCHeap<oop, mtClassShared>(500);
 413 }
 414 
 415 void HeapShared::init_scratch_objects_for_basic_type_mirrors(TRAPS) {
 416   for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
 417     BasicType bt = (BasicType)i;
 418     if (!is_reference_type(bt)) {
 419       oop m = java_lang_Class::create_basic_type_mirror(type2name(bt), bt, true, CHECK);
 420       _scratch_basic_type_mirrors[i] = OopHandle(Universe::vm_global(), m);
 421     }
 422   }
 423 }
 424 
 425 // Given java_mirror that represents a (primitive or reference) type T,
 426 // return the "scratch" version that represents the same type T.
 427 // Note that if java_mirror will be returned if it's already a
 428 // scratch mirror.
 429 //
 430 // See java_lang_Class::create_scratch_mirror() for more info.
 431 oop HeapShared::scratch_java_mirror(oop java_mirror) {
 432   assert(java_lang_Class::is_instance(java_mirror), "must be");
 433 
 434   for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
 435     BasicType bt = (BasicType)i;
 436     if (!is_reference_type(bt)) {
 437       if (_scratch_basic_type_mirrors[i].resolve() == java_mirror) {
 438         return java_mirror;
 439       }

 574   }
 575 
 576   oop class_data = java_lang_Class::class_data(orig_mirror);
 577   java_lang_Class::set_class_data(m, class_data);
 578   if (class_data != nullptr) {
 579     bool success = archive_reachable_objects_from(1, _dump_time_special_subgraph, class_data);
 580     assert(success, "sanity");
 581   }
 582 
 583   if (log_is_enabled(Debug, aot, init)) {
 584     ResourceMark rm;
 585     log_debug(aot, init)("copied %3d field(s) in aot-initialized mirror %s%s%s", nfields, ik->external_name(),
 586                          ik->is_hidden() ? " (hidden)" : "",
 587                          ik->is_enum_subclass() ? " (enum)" : "");
 588   }
 589 }
 590 
 591 static void copy_java_mirror_hashcode(oop orig_mirror, oop scratch_m) {
 592   // We need to retain the identity_hash, because it may have been used by some hashtables
 593   // in the shared heap.
 594   assert(!UseCompactObjectHeaders || scratch_m->mark().is_not_hashed_expanded(), "scratch mirror must have not-hashed-expanded state");
 595   if (!orig_mirror->fast_no_hash_check()) {
 596     intptr_t orig_mark = orig_mirror->mark().value();
 597     intptr_t src_hash = orig_mirror->identity_hash();
 598     if (UseCompactObjectHeaders) {
 599       // We leave the cases not_hashed/not_hashed_expanded as they are.
 600       assert(orig_mirror->mark().is_hashed_not_expanded() || orig_mirror->mark().is_hashed_expanded(), "must be hashed");
 601       Klass* orig_klass = orig_mirror->klass();
 602       narrowKlass nk = CompressedKlassPointers::encode(orig_klass);
 603       markWord mark = markWord::prototype().set_narrow_klass(nk);
 604       mark = mark.copy_hashctrl_from(orig_mirror->mark());
 605       if (mark.is_hashed_not_expanded()) {
 606         scratch_m->initialize_hash_if_necessary(orig_mirror, orig_klass, mark);
 607       } else {
 608         assert(mark.is_hashed_expanded(), "must be hashed & moved");
 609         int offset = orig_klass->hash_offset_in_bytes(orig_mirror, mark);
 610         assert(offset >= 8, "hash offset must not be in header");
 611         scratch_m->int_field_put(offset, (jint) src_hash);
 612         scratch_m->set_mark(mark);
 613       }
 614       assert(scratch_m->mark().is_hashed_expanded(), "must be hashed & moved");
 615       assert(scratch_m->mark().is_not_hashed_expanded() || scratch_m->mark().is_hashed_expanded(), "must be not hashed and expanded");
 616     } else {
 617       scratch_m->set_mark(markWord::prototype().copy_set_hash(src_hash));
 618       DEBUG_ONLY(intptr_t archived_hash = scratch_m->identity_hash());
 619       assert(src_hash == archived_hash, "Different hash codes: original " INTPTR_FORMAT ", archived " INTPTR_FORMAT, src_hash, archived_hash);
 620     }
 621     assert(scratch_m->mark().is_unlocked(), "sanity");



 622   }
 623 }
 624 
 625 static objArrayOop get_archived_resolved_references(InstanceKlass* src_ik) {
 626   if (SystemDictionaryShared::is_builtin_loader(src_ik->class_loader_data())) {
 627     objArrayOop rr = src_ik->constants()->resolved_references_or_null();
 628     if (rr != nullptr && !ArchiveHeapWriter::is_too_large_to_archive(rr)) {
 629       return HeapShared::scratch_resolved_references(src_ik->constants());
 630     }
 631   }
 632   return nullptr;
 633 }
 634 
 635 void HeapShared::archive_strings() {
 636   oop shared_strings_array = StringTable::init_shared_strings_array();
 637   bool success = archive_reachable_objects_from(1, _dump_time_special_subgraph, shared_strings_array);
 638   assert(success, "shared strings array must not point to arrays or strings that are too large to archive");
 639   StringTable::set_shared_strings_array_index(append_root(shared_strings_array));
 640 }
 641 
< prev index next >