395
396 void HeapShared::add_scratch_resolved_references(ConstantPool* src, objArrayOop dest) {
397 if (SystemDictionaryShared::is_builtin_loader(src->pool_holder()->class_loader_data())) {
398 _scratch_objects_table->set_oop(src, dest);
399 }
400 }
401
402 objArrayOop HeapShared::scratch_resolved_references(ConstantPool* src) {
403 return (objArrayOop)_scratch_objects_table->get_oop(src);
404 }
405
406 void HeapShared::init_dumping() {
407 _scratch_objects_table = new (mtClass)MetaspaceObjToOopHandleTable();
408 _pending_roots = new GrowableArrayCHeap<oop, mtClassShared>(500);
409 }
410
411 void HeapShared::init_scratch_objects_for_basic_type_mirrors(TRAPS) {
412 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
413 BasicType bt = (BasicType)i;
414 if (!is_reference_type(bt)) {
415 oop m = java_lang_Class::create_basic_type_mirror(type2name(bt), bt, CHECK);
416 _scratch_basic_type_mirrors[i] = OopHandle(Universe::vm_global(), m);
417 }
418 }
419 }
420
421 // Given java_mirror that represents a (primitive or reference) type T,
422 // return the "scratch" version that represents the same type T.
423 // Note that if java_mirror will be returned if it's already a
424 // scratch mirror.
425 //
426 // See java_lang_Class::create_scratch_mirror() for more info.
427 oop HeapShared::scratch_java_mirror(oop java_mirror) {
428 assert(java_lang_Class::is_instance(java_mirror), "must be");
429
430 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
431 BasicType bt = (BasicType)i;
432 if (!is_reference_type(bt)) {
433 if (_scratch_basic_type_mirrors[i].resolve() == java_mirror) {
434 return java_mirror;
435 }
563 }
564
565 oop class_data = java_lang_Class::class_data(orig_mirror);
566 java_lang_Class::set_class_data(m, class_data);
567 if (class_data != nullptr) {
568 bool success = archive_reachable_objects_from(1, _dump_time_special_subgraph, class_data);
569 assert(success, "sanity");
570 }
571
572 if (log_is_enabled(Debug, cds, init)) {
573 ResourceMark rm;
574 log_debug(cds, init)("copied %3d field(s) in aot-initialized mirror %s%s%s", nfields, ik->external_name(),
575 ik->is_hidden() ? " (hidden)" : "",
576 ik->is_enum_subclass() ? " (enum)" : "");
577 }
578 }
579
580 static void copy_java_mirror_hashcode(oop orig_mirror, oop scratch_m) {
581 // We need to retain the identity_hash, because it may have been used by some hashtables
582 // in the shared heap.
583 if (!orig_mirror->fast_no_hash_check()) {
584 intptr_t src_hash = orig_mirror->identity_hash();
585 if (UseCompactObjectHeaders) {
586 narrowKlass nk = CompressedKlassPointers::encode(orig_mirror->klass());
587 scratch_m->set_mark(markWord::prototype().set_narrow_klass(nk).copy_set_hash(src_hash));
588 } else {
589 scratch_m->set_mark(markWord::prototype().copy_set_hash(src_hash));
590 }
591 assert(scratch_m->mark().is_unlocked(), "sanity");
592
593 DEBUG_ONLY(intptr_t archived_hash = scratch_m->identity_hash());
594 assert(src_hash == archived_hash, "Different hash codes: original " INTPTR_FORMAT ", archived " INTPTR_FORMAT, src_hash, archived_hash);
595 }
596 }
597
598 static objArrayOop get_archived_resolved_references(InstanceKlass* src_ik) {
599 if (SystemDictionaryShared::is_builtin_loader(src_ik->class_loader_data())) {
600 objArrayOop rr = src_ik->constants()->resolved_references_or_null();
601 if (rr != nullptr && !ArchiveHeapWriter::is_too_large_to_archive(rr)) {
602 return HeapShared::scratch_resolved_references(src_ik->constants());
603 }
604 }
605 return nullptr;
606 }
607
608 void HeapShared::archive_strings() {
609 oop shared_strings_array = StringTable::init_shared_strings_array(_dumped_interned_strings);
610 bool success = archive_reachable_objects_from(1, _dump_time_special_subgraph, shared_strings_array);
611 // We must succeed because:
612 // - _dumped_interned_strings do not contain any large strings.
613 // - StringTable::init_shared_table() doesn't create any large arrays.
614 assert(success, "shared strings array must not point to arrays or strings that are too large to archive");
|
395
396 void HeapShared::add_scratch_resolved_references(ConstantPool* src, objArrayOop dest) {
397 if (SystemDictionaryShared::is_builtin_loader(src->pool_holder()->class_loader_data())) {
398 _scratch_objects_table->set_oop(src, dest);
399 }
400 }
401
402 objArrayOop HeapShared::scratch_resolved_references(ConstantPool* src) {
403 return (objArrayOop)_scratch_objects_table->get_oop(src);
404 }
405
406 void HeapShared::init_dumping() {
407 _scratch_objects_table = new (mtClass)MetaspaceObjToOopHandleTable();
408 _pending_roots = new GrowableArrayCHeap<oop, mtClassShared>(500);
409 }
410
411 void HeapShared::init_scratch_objects_for_basic_type_mirrors(TRAPS) {
412 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
413 BasicType bt = (BasicType)i;
414 if (!is_reference_type(bt)) {
415 oop m = java_lang_Class::create_basic_type_mirror(type2name(bt), bt, true, CHECK);
416 _scratch_basic_type_mirrors[i] = OopHandle(Universe::vm_global(), m);
417 }
418 }
419 }
420
421 // Given java_mirror that represents a (primitive or reference) type T,
422 // return the "scratch" version that represents the same type T.
423 // Note that if java_mirror will be returned if it's already a
424 // scratch mirror.
425 //
426 // See java_lang_Class::create_scratch_mirror() for more info.
427 oop HeapShared::scratch_java_mirror(oop java_mirror) {
428 assert(java_lang_Class::is_instance(java_mirror), "must be");
429
430 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
431 BasicType bt = (BasicType)i;
432 if (!is_reference_type(bt)) {
433 if (_scratch_basic_type_mirrors[i].resolve() == java_mirror) {
434 return java_mirror;
435 }
563 }
564
565 oop class_data = java_lang_Class::class_data(orig_mirror);
566 java_lang_Class::set_class_data(m, class_data);
567 if (class_data != nullptr) {
568 bool success = archive_reachable_objects_from(1, _dump_time_special_subgraph, class_data);
569 assert(success, "sanity");
570 }
571
572 if (log_is_enabled(Debug, cds, init)) {
573 ResourceMark rm;
574 log_debug(cds, init)("copied %3d field(s) in aot-initialized mirror %s%s%s", nfields, ik->external_name(),
575 ik->is_hidden() ? " (hidden)" : "",
576 ik->is_enum_subclass() ? " (enum)" : "");
577 }
578 }
579
580 static void copy_java_mirror_hashcode(oop orig_mirror, oop scratch_m) {
581 // We need to retain the identity_hash, because it may have been used by some hashtables
582 // in the shared heap.
583 assert(!UseCompactObjectHeaders || scratch_m->mark().is_not_hashed_expanded(), "scratch mirror must have not-hashed-expanded state");
584 if (!orig_mirror->fast_no_hash_check()) {
585 intptr_t orig_mark = orig_mirror->mark().value();
586 intptr_t src_hash = orig_mirror->identity_hash();
587 if (UseCompactObjectHeaders) {
588 // We leave the cases not_hashed/not_hashed_expanded as they are.
589 assert(orig_mirror->mark().is_hashed_not_expanded() || orig_mirror->mark().is_hashed_expanded(), "must be hashed");
590 Klass* orig_klass = orig_mirror->klass();
591 narrowKlass nk = CompressedKlassPointers::encode(orig_klass);
592 markWord mark = markWord::prototype().set_narrow_klass(nk);
593 mark = mark.copy_hashctrl_from(orig_mirror->mark());
594 if (mark.is_hashed_not_expanded()) {
595 scratch_m->initialize_hash_if_necessary(orig_mirror, orig_klass, mark);
596 } else {
597 assert(mark.is_hashed_expanded(), "must be hashed & moved");
598 int offset = orig_klass->hash_offset_in_bytes(orig_mirror, mark);
599 assert(offset >= 8, "hash offset must not be in header");
600 scratch_m->int_field_put(offset, (jint) src_hash);
601 scratch_m->set_mark(mark);
602 }
603 assert(scratch_m->mark().is_hashed_expanded(), "must be hashed & moved");
604 assert(scratch_m->mark().is_not_hashed_expanded() || scratch_m->mark().is_hashed_expanded(), "must be not hashed and expanded");
605 } else {
606 scratch_m->set_mark(markWord::prototype().copy_set_hash(src_hash));
607 DEBUG_ONLY(intptr_t archived_hash = scratch_m->identity_hash());
608 assert(src_hash == archived_hash, "Different hash codes: original " INTPTR_FORMAT ", archived " INTPTR_FORMAT, src_hash, archived_hash);
609 }
610 assert(scratch_m->mark().is_unlocked(), "sanity");
611 }
612 }
613
614 static objArrayOop get_archived_resolved_references(InstanceKlass* src_ik) {
615 if (SystemDictionaryShared::is_builtin_loader(src_ik->class_loader_data())) {
616 objArrayOop rr = src_ik->constants()->resolved_references_or_null();
617 if (rr != nullptr && !ArchiveHeapWriter::is_too_large_to_archive(rr)) {
618 return HeapShared::scratch_resolved_references(src_ik->constants());
619 }
620 }
621 return nullptr;
622 }
623
624 void HeapShared::archive_strings() {
625 oop shared_strings_array = StringTable::init_shared_strings_array(_dumped_interned_strings);
626 bool success = archive_reachable_objects_from(1, _dump_time_special_subgraph, shared_strings_array);
627 // We must succeed because:
628 // - _dumped_interned_strings do not contain any large strings.
629 // - StringTable::init_shared_table() doesn't create any large arrays.
630 assert(success, "shared strings array must not point to arrays or strings that are too large to archive");
|