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