Skip to content

Commit

Permalink
GenerationalZGC Leyden Support
Browse files Browse the repository at this point in the history
  • Loading branch information
fisk committed Jan 3, 2024
1 parent fb3c95d commit 8ce820d
Show file tree
Hide file tree
Showing 43 changed files with 2,336 additions and 542 deletions.
200 changes: 86 additions & 114 deletions src/hotspot/share/cds/archiveBuilder.cpp
Expand Up @@ -24,7 +24,6 @@

#include "precompiled.hpp"
#include "cds/archiveBuilder.hpp"
#include "cds/archiveHeapWriter.hpp"
#include "cds/archiveUtils.hpp"
#include "cds/cdsConfig.hpp"
#include "cds/classPrelinker.hpp"
Expand Down Expand Up @@ -962,7 +961,7 @@ narrowKlass ArchiveBuilder::get_requested_narrow_klass(Klass* k) {
k = get_buffered_klass(k);
Klass* requested_k = to_requested(k);
address narrow_klass_base = _requested_static_archive_bottom; // runtime encoding base == runtime mapping start
const int narrow_klass_shift = ArchiveHeapWriter::precomputed_narrow_klass_shift;
const int narrow_klass_shift = HeapShared::precomputed_narrow_klass_shift;
return CompressedKlassPointers::encode_not_null(requested_k, narrow_klass_base, narrow_klass_shift);
}
#endif // INCLUDE_CDS_JAVA_HEAP
Expand Down Expand Up @@ -1113,7 +1112,7 @@ class ArchiveBuilder::CDSMapLogger : AllStatic {
SourceObjInfo* src_info = src_objs->at(i);
address src = src_info->source_addr();
address dest = src_info->buffered_addr();
log_as_hex(last_obj_base, dest, last_obj_base + buffer_to_runtime_delta());
log_as_hex(last_obj_base, dest);
address runtime_dest = dest + buffer_to_runtime_delta();
int bytes = src_info->size_in_bytes();

Expand Down Expand Up @@ -1155,12 +1154,12 @@ class ArchiveBuilder::CDSMapLogger : AllStatic {
last_obj_end = dest + bytes;
}

log_as_hex(last_obj_base, last_obj_end, last_obj_base + buffer_to_runtime_delta());
log_as_hex(last_obj_base, last_obj_end);
if (last_obj_end < region_end) {
log_debug(cds, map)(PTR_FORMAT ": @@ Misc data " SIZE_FORMAT " bytes",
p2i(last_obj_end + buffer_to_runtime_delta()),
size_t(region_end - last_obj_end));
log_as_hex(last_obj_end, region_end, last_obj_end + buffer_to_runtime_delta());
log_as_hex(last_obj_end, region_end);
}
}

Expand All @@ -1183,52 +1182,53 @@ class ArchiveBuilder::CDSMapLogger : AllStatic {

#if INCLUDE_CDS_JAVA_HEAP
static void log_heap_region(ArchiveHeapInfo* heap_info) {
MemRegion r = heap_info->buffer_region();
address start = address(r.start());
address end = address(r.end());
log_region("heap", start, end, ArchiveHeapWriter::buffered_addr_to_requested_addr(start));

LogStreamHandle(Info, cds, map) st;

while (start < end) {
size_t byte_size;
oop source_oop = ArchiveHeapWriter::buffered_addr_to_source_obj(start);
address requested_start = ArchiveHeapWriter::buffered_addr_to_requested_addr(start);
st.print(PTR_FORMAT ": @@ Object ", p2i(requested_start));
int permobj_segment = -1;
int permobj_segment_length = -1;

if (source_oop != nullptr) {
// This is a regular oop that got archived.
print_oop_with_requested_addr_cr(&st, source_oop, false);
byte_size = source_oop->size() * BytesPerWord;
} else if (start == ArchiveHeapWriter::buffered_heap_roots_addr()) {
// HeapShared::roots() is copied specially, so it doesn't exist in
// ArchiveHeapWriter::BufferOffsetToSourceObjectTable.
// See ArchiveHeapWriter::copy_roots_to_buffer().
st.print_cr("HeapShared::roots[%d]", HeapShared::pending_roots()->length());
byte_size = ArchiveHeapWriter::heap_roots_word_size() * BytesPerWord;
} else if ((byte_size = ArchiveHeapWriter::get_filler_size_at(start)) > 0) {
// We have a filler oop, which also does not exist in BufferOffsetToSourceObjectTable.
st.print_cr("filler " SIZE_FORMAT " bytes", byte_size);
} else if ((permobj_segment = ArchiveHeapWriter::get_permobj_segment_at(start, &byte_size, &permobj_segment_length)) >= 0) {
st.print_cr("permobj_%d[%d] %zu bytes", permobj_segment, permobj_segment_length, byte_size);
} else {
ShouldNotReachHere();
}

address oop_end = start + byte_size;
log_as_hex(start, oop_end, requested_start, /*is_heap=*/true);

if (source_oop != nullptr) {
log_oop_details(heap_info, source_oop);
} else if (start == ArchiveHeapWriter::buffered_heap_roots_addr()) {
log_heap_roots();
} else if (permobj_segment >= 0) {
log_permobj_segment(permobj_segment, permobj_segment_length);
}
start = oop_end;
}
// TODO: fix logging
//MemRegion r = heap_info->buffer_region();
//address start = address(r.start());
//address end = address(r.end());
//log_region("heap", start, end, ArchiveHeapWriter::buffered_addr_to_requested_addr(start));

//LogStreamHandle(Info, cds, map) st;

//while (start < end) {
// size_t byte_size;
// oop source_oop = ArchiveHeapWriter::buffered_addr_to_source_obj(start);
// address requested_start = ArchiveHeapWriter::buffered_addr_to_requested_addr(start);
// st.print(PTR_FORMAT ": @@ Object ", p2i(requested_start));
// int permobj_segment = -1;
// int permobj_segment_length = -1;

// if (source_oop != nullptr) {
// // This is a regular oop that got archived.
// print_oop_with_requested_addr_cr(&st, source_oop, false);
// byte_size = source_oop->size() * BytesPerWord;
// } else if (start == ArchiveHeapWriter::buffered_heap_roots_addr()) {
// // HeapShared::roots() is copied specially, so it doesn't exist in
// // ArchiveHeapWriter::BufferOffsetToSourceObjectTable.
// // See ArchiveHeapWriter::copy_roots_to_buffer().
// st.print_cr("HeapShared::roots[%d]", HeapShared::pending_roots()->length());
// byte_size = ArchiveHeapWriter::heap_roots_word_size() * BytesPerWord;
// } else if ((byte_size = ArchiveHeapWriter::get_filler_size_at(start)) > 0) {
// // We have a filler oop, which also does not exist in BufferOffsetToSourceObjectTable.
// st.print_cr("filler " SIZE_FORMAT " bytes", byte_size);
// } else if ((permobj_segment = ArchiveHeapWriter::get_permobj_segment_at(start, &byte_size, &permobj_segment_length)) >= 0) {
// st.print_cr("permobj_%d[%d] %zu bytes", permobj_segment, permobj_segment_length, byte_size);
// } else {
// ShouldNotReachHere();
// }

// address oop_end = start + byte_size;
// log_as_hex(start, oop_end, requested_start, /*is_heap=*/true);

// if (source_oop != nullptr) {
// log_oop_details(heap_info, source_oop);
// } else if (start == ArchiveHeapWriter::buffered_heap_roots_addr()) {
// log_heap_roots();
// } else if (permobj_segment >= 0) {
// log_permobj_segment(permobj_segment, permobj_segment_length);
// }
// start = oop_end;
//}
}

// ArchivedFieldPrinter is used to print the fields of archived objects. We can't
Expand All @@ -1249,41 +1249,13 @@ class ArchiveBuilder::CDSMapLogger : AllStatic {
case T_ARRAY:
case T_OBJECT:
fd->print_on(_st); // print just the name and offset
print_oop_with_requested_addr_cr(_st, _source_obj->obj_field(fd->offset()));
print_oop_with_buffered_addr_cr(_st, _source_obj->obj_field(fd->offset()));
break;
default:
if (ArchiveHeapWriter::is_marked_as_native_pointer(_heap_info, _source_obj, fd->offset())) {
print_as_native_pointer(fd);
} else {
fd->print_on_for(_st, _source_obj); // name, offset, value
_st->cr();
}
fd->print_on_for(_st, _source_obj); // name, offset, value
_st->cr();
}
}

void print_as_native_pointer(fieldDescriptor* fd) {
LP64_ONLY(assert(fd->field_type() == T_LONG, "must be"));
NOT_LP64 (assert(fd->field_type() == T_INT, "must be"));

// We have a field that looks like an integer, but it's actually a pointer to a MetaspaceObj.
address source_native_ptr = (address)
LP64_ONLY(_source_obj->long_field(fd->offset()))
NOT_LP64( _source_obj->int_field (fd->offset()));
ArchiveBuilder* builder = ArchiveBuilder::current();

// The value of the native pointer at runtime.
address requested_native_ptr = builder->to_requested(builder->get_buffered_addr(source_native_ptr));

// The address of _source_obj at runtime
oop requested_obj = ArchiveHeapWriter::source_obj_to_requested_obj(_source_obj);
// The address of this field in the requested space
assert(requested_obj != nullptr, "Attempting to load field from null oop");
address requested_field_addr = cast_from_oop<address>(requested_obj) + fd->offset();

fd->print_on(_st);
_st->print_cr(PTR_FORMAT " (marked metadata pointer @" PTR_FORMAT " )",
p2i(requested_native_ptr), p2i(requested_field_addr));
}
};

// Print the fields of instanceOops, or the elements of arrayOops
Expand All @@ -1305,7 +1277,7 @@ class ArchiveBuilder::CDSMapLogger : AllStatic {
objArrayOop source_obj_array = objArrayOop(source_oop);
for (int i = 0; i < source_obj_array->length(); i++) {
st.print(" -%4d: ", i);
print_oop_with_requested_addr_cr(&st, source_obj_array->obj_at(i));
print_oop_with_buffered_addr_cr(&st, source_obj_array->obj_at(i));
}
} else {
st.print_cr(" - fields (" SIZE_FORMAT " words):", source_oop->size());
Expand All @@ -1320,51 +1292,50 @@ class ArchiveBuilder::CDSMapLogger : AllStatic {
if (st.is_enabled()) {
for (int i = 0; i < HeapShared::pending_roots()->length(); i++) {
st.print("roots[%4d]: ", i);
print_oop_with_requested_addr_cr(&st, HeapShared::pending_roots()->at(i));
print_oop_with_buffered_addr_cr(&st, HeapShared::pending_roots()->at(i));
}
}
}

static void log_permobj_segment(int permobj_segment, int permobj_segment_length) {
LogStreamHandle(Trace, cds, map, oops) st;
if (st.is_enabled()) {
for (int i = 0; i < permobj_segment_length; i++) {
st.print("permobj_%d[%4d]: ", permobj_segment, i);
print_oop_with_requested_addr_cr(&st, ArchiveHeapWriter::get_permobj_source_addr(permobj_segment, i));
}
}
// TODO: fix print code
//LogStreamHandle(Trace, cds, map, oops) st;
//if (st.is_enabled()) {
// for (int i = 0; i < permobj_segment_length; i++) {
// st.print("permobj_%d[%4d]: ", permobj_segment, i);
// print_oop_with_requested_addr_cr(&st, ArchiveHeapWriter::get_permobj_source_addr(permobj_segment, i));
// }
//}
}


// The output looks like this. The first number is the requested address. The second number is
// the narrowOop version of the requested address.
// 0x00000007ffc7e840 (0xfff8fd08) java.lang.Class
// 0x00000007ffc000f8 (0xfff8001f) [B length: 11
static void print_oop_with_requested_addr_cr(outputStream* st, oop source_oop, bool print_addr = true) {
if (source_oop == nullptr) {
st->print_cr("null");
} else {
ResourceMark rm;
oop requested_obj = ArchiveHeapWriter::source_obj_to_requested_obj(source_oop);
if (print_addr) {
st->print(PTR_FORMAT " ", p2i(requested_obj));
}
if (UseCompressedOops) {
st->print("(0x%08x) ", CompressedOops::narrow_oop_value(requested_obj));
}
if (source_oop->is_array()) {
int array_len = arrayOop(source_oop)->length();
st->print_cr("%s length: %d", source_oop->klass()->external_name(), array_len);
} else {
st->print_cr("%s", source_oop->klass()->external_name());
}
}
static void print_oop_with_buffered_addr_cr(outputStream* st, oop source_oop, bool print_addr = true) {
// TODO: fix print code
//if (source_oop == nullptr) {
// st->print_cr("null");
//} else {
// ResourceMark rm;
// address buffered_addr = ArchiveHeapWriter::source_obj_to_buffered_addr(source_oop);
// if (print_addr) {
// st->print(PTR_FORMAT " ", p2i(buffered_addr));
// }
// if (source_oop->is_array()) {
// int array_len = arrayOop(source_oop)->length();
// st->print_cr("%s length: %d", source_oop->klass()->external_name(), array_len);
// } else {
// st->print_cr("%s", source_oop->klass()->external_name());
// }
//}
}
#endif // INCLUDE_CDS_JAVA_HEAP

// Log all the data [base...top). Pretend that the base address
// will be mapped to requested_base at run-time.
static void log_as_hex(address base, address top, address requested_base, bool is_heap = false) {
static void log_as_hex(address base, address top, bool is_heap = false) {
assert(top >= base, "must be");

LogStreamHandle(Trace, cds, map) lsh;
Expand All @@ -1375,7 +1346,8 @@ class ArchiveBuilder::CDSMapLogger : AllStatic {
// longs and doubles will be split into two words.
unitsize = sizeof(narrowOop);
}
os::print_hex_dump(&lsh, base, top, unitsize, 32, requested_base);
// TODO: Fix print statement
//os::print_hex_dump(&lsh, base, top, unitsize, 32);
}
}

Expand All @@ -1396,7 +1368,7 @@ class ArchiveBuilder::CDSMapLogger : AllStatic {
address header_end = header + mapinfo->header()->header_size();
log_region("header", header, header_end, 0);
log_header(mapinfo);
log_as_hex(header, header_end, 0);
log_as_hex(header, header_end);

DumpRegion* rw_region = &builder->_rw_region;
DumpRegion* ro_region = &builder->_ro_region;
Expand All @@ -1406,7 +1378,7 @@ class ArchiveBuilder::CDSMapLogger : AllStatic {

address bitmap_end = address(bitmap + bitmap_size_in_bytes);
log_region("bitmap", address(bitmap), bitmap_end, 0);
log_as_hex((address)bitmap, bitmap_end, 0);
log_as_hex((address)bitmap, bitmap_end);

#if INCLUDE_CDS_JAVA_HEAP
if (heap_info->is_used()) {
Expand Down
1 change: 0 additions & 1 deletion src/hotspot/share/cds/archiveUtils.cpp
Expand Up @@ -24,7 +24,6 @@

#include "precompiled.hpp"
#include "cds/archiveBuilder.hpp"
#include "cds/archiveHeapLoader.inline.hpp"
#include "cds/archiveUtils.hpp"
#include "cds/cdsConfig.hpp"
#include "cds/classListParser.hpp"
Expand Down
5 changes: 2 additions & 3 deletions src/hotspot/share/cds/cdsConfig.cpp
Expand Up @@ -23,7 +23,6 @@
*/

#include "precompiled.hpp"
#include "cds/archiveHeapLoader.hpp"
#include "cds/cdsConfig.hpp"
#include "cds/cds_globals.hpp"
#include "cds/heapShared.hpp"
Expand Down Expand Up @@ -504,7 +503,7 @@ bool CDSConfig::is_dumping_heap() {
}

bool CDSConfig::is_loading_heap() {
return ArchiveHeapLoader::is_in_use();
return HeapShared::is_archived_heap_in_use();
}

bool CDSConfig::is_dumping_full_module_graph() {
Expand All @@ -524,7 +523,7 @@ bool CDSConfig::is_loading_full_module_graph() {

if (!_loading_full_module_graph_disabled &&
UseSharedSpaces &&
ArchiveHeapLoader::can_use() &&
HeapShared::can_use_archived_heap() &&
MetaspaceShared::use_optimized_module_handling()) {
// Classes used by the archived full module graph are loaded in JVMTI early phase.
assert(!(JvmtiExport::should_post_class_file_load_hook() && JvmtiExport::has_early_class_hook_env()),
Expand Down
3 changes: 1 addition & 2 deletions src/hotspot/share/cds/cdsEnumKlass.cpp
Expand Up @@ -23,7 +23,6 @@
*/

#include "precompiled.hpp"
#include "cds/archiveHeapLoader.hpp"
#include "cds/cdsEnumKlass.hpp"
#include "cds/heapShared.hpp"
#include "classfile/vmClasses.hpp"
Expand Down Expand Up @@ -173,7 +172,7 @@ void CDSEnumKlass::archive_static_primitive_field(int level, KlassSubGraphInfo*


bool CDSEnumKlass::initialize_enum_klass(InstanceKlass* k, TRAPS) {
if (!ArchiveHeapLoader::is_in_use()) {
if (!HeapShared::is_archived_heap_in_use()) {
return false;
}

Expand Down

0 comments on commit 8ce820d

Please sign in to comment.