mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-18 01:54:47 +02:00
8293291: Simplify relocation of native pointers in archive heap
Reviewed-by: ccheung, coleenp
This commit is contained in:
parent
1553551d82
commit
3f4964f83d
17 changed files with 275 additions and 235 deletions
|
@ -82,6 +82,7 @@ struct ArchivableStaticFieldInfo {
|
|||
|
||||
bool HeapShared::_disable_writing = false;
|
||||
DumpedInternedStrings *HeapShared::_dumped_interned_strings = NULL;
|
||||
GrowableArrayCHeap<Metadata**, mtClassShared>* HeapShared::_native_pointers = NULL;
|
||||
|
||||
#ifndef PRODUCT
|
||||
#define ARCHIVE_TEST_FIELD_NAME "archivedObjects"
|
||||
|
@ -320,6 +321,7 @@ oop HeapShared::archive_object(oop obj) {
|
|||
if (_original_object_table != NULL) {
|
||||
_original_object_table->put(archived_oop, obj);
|
||||
}
|
||||
mark_native_pointers(obj, archived_oop);
|
||||
if (log_is_enabled(Debug, cds, heap)) {
|
||||
ResourceMark rm;
|
||||
log_debug(cds, heap)("Archived heap object " PTR_FORMAT " ==> " PTR_FORMAT " : %s",
|
||||
|
@ -353,6 +355,32 @@ void HeapShared::archive_klass_objects() {
|
|||
}
|
||||
}
|
||||
|
||||
void HeapShared::mark_native_pointers(oop orig_obj, oop archived_obj) {
|
||||
if (java_lang_Class::is_instance(orig_obj)) {
|
||||
mark_one_native_pointer(archived_obj, java_lang_Class::klass_offset());
|
||||
mark_one_native_pointer(archived_obj, java_lang_Class::array_klass_offset());
|
||||
}
|
||||
}
|
||||
|
||||
void HeapShared::mark_one_native_pointer(oop archived_obj, int offset) {
|
||||
Metadata* ptr = archived_obj->metadata_field_acquire(offset);
|
||||
if (ptr != NULL) {
|
||||
// Set the native pointer to the requested address (at runtime, if the metadata
|
||||
// is mapped at the default location, it will be at this address).
|
||||
address buffer_addr = ArchiveBuilder::current()->get_buffered_addr((address)ptr);
|
||||
address requested_addr = ArchiveBuilder::current()->to_requested(buffer_addr);
|
||||
archived_obj->metadata_field_put(offset, (Metadata*)requested_addr);
|
||||
|
||||
// Remember this pointer. At runtime, if the metadata is mapped at a non-default
|
||||
// location, the pointer needs to be patched (see ArchiveHeapLoader::patch_native_pointers()).
|
||||
_native_pointers->append(archived_obj->field_addr<Metadata*>(offset));
|
||||
|
||||
log_debug(cds, heap, mirror)(
|
||||
"Marked metadata field at %d: " PTR_FORMAT " ==> " PTR_FORMAT,
|
||||
offset, p2i(ptr), p2i(requested_addr));
|
||||
}
|
||||
}
|
||||
|
||||
// -- Handling of Enum objects
|
||||
// Java Enum classes have synthetic <clinit> methods that look like this
|
||||
// enum MyEnum {FOO, BAR}
|
||||
|
@ -1632,6 +1660,7 @@ void HeapShared::init_for_dumping(TRAPS) {
|
|||
if (HeapShared::can_write()) {
|
||||
setup_test_class(ArchiveHeapTestClass);
|
||||
_dumped_interned_strings = new (ResourceObj::C_HEAP, mtClass)DumpedInternedStrings();
|
||||
_native_pointers = new GrowableArrayCHeap<Metadata**, mtClassShared>(2048);
|
||||
init_subgraph_entry_fields(CHECK);
|
||||
}
|
||||
}
|
||||
|
@ -1797,4 +1826,33 @@ ResourceBitMap HeapShared::calculate_oopmap(MemRegion region) {
|
|||
return oopmap;
|
||||
}
|
||||
|
||||
|
||||
ResourceBitMap HeapShared::calculate_ptrmap(MemRegion region) {
|
||||
size_t num_bits = region.byte_size() / sizeof(Metadata*);
|
||||
ResourceBitMap oopmap(num_bits);
|
||||
|
||||
Metadata** start = (Metadata**)region.start();
|
||||
Metadata** end = (Metadata**)region.end();
|
||||
|
||||
int num_non_null_ptrs = 0;
|
||||
int len = _native_pointers->length();
|
||||
for (int i = 0; i < len; i++) {
|
||||
Metadata** p = _native_pointers->at(i);
|
||||
if (start <= p && p < end) {
|
||||
assert(*p != NULL, "must be non-null");
|
||||
num_non_null_ptrs ++;
|
||||
size_t idx = p - start;
|
||||
oopmap.set_bit(idx);
|
||||
}
|
||||
}
|
||||
|
||||
log_info(cds, heap)("calculate_ptrmap: marked %d non-null native pointers out of "
|
||||
SIZE_FORMAT " possible locations", num_non_null_ptrs, num_bits);
|
||||
if (num_non_null_ptrs > 0) {
|
||||
return oopmap;
|
||||
} else {
|
||||
return ResourceBitMap(0);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // INCLUDE_CDS_JAVA_HEAP
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue