Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/hotspot/share/cds/aotMapLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "cds/aotMappedHeapWriter.hpp"
#include "cds/aotStreamedHeapLoader.hpp"
#include "cds/aotStreamedHeapWriter.hpp"
#include "cds/archiveUtils.hpp"
#include "cds/cdsConfig.hpp"
#include "cds/filemap.hpp"
#include "classfile/moduleEntry.hpp"
Expand Down Expand Up @@ -879,7 +880,7 @@ void AOTMapLogger::runtime_log_heap_region(FileMapInfo* mapinfo) {
}

address requested_base = UseCompressedOops ? (address)mapinfo->narrow_oop_base() : AOTMappedHeapLoader::heap_region_requested_address(mapinfo);
address requested_start = requested_base + r->mapping_offset();
address requested_start = ArchiveUtils::offset_to_requested_addr(requested_base, r->mapping_offset());
log_region_range("heap", buffer_start, buffer_end, requested_start);
log_archived_objects(AOTMappedHeapLoader::oop_iterator(mapinfo, buffer_start, buffer_end));
}
Expand Down
10 changes: 5 additions & 5 deletions src/hotspot/share/cds/archiveBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,15 @@ address ArchiveBuilder::reserve_buffer() {
size_t static_archive_size = _mapped_static_archive_top - _mapped_static_archive_bottom;

// At run time, we will mmap the dynamic archive at my_archive_requested_bottom
_requested_static_archive_top = _requested_static_archive_bottom + static_archive_size;
_requested_static_archive_top = ArchiveUtils::offset_to_requested_addr(_requested_static_archive_bottom, static_archive_size);
my_archive_requested_bottom = align_up(_requested_static_archive_top, AOTMetaspace::core_region_alignment());

_requested_dynamic_archive_bottom = my_archive_requested_bottom;
}

_buffer_to_requested_delta = my_archive_requested_bottom - _buffer_bottom;

address my_archive_requested_top = my_archive_requested_bottom + buffer_size;
address my_archive_requested_top = ArchiveUtils::offset_to_requested_addr(my_archive_requested_bottom, buffer_size);
if (my_archive_requested_bottom < _requested_static_archive_bottom ||
my_archive_requested_top <= _requested_static_archive_bottom) {
// Size overflow.
Expand Down Expand Up @@ -982,7 +982,7 @@ size_t ArchiveBuilder::any_to_offset(address p) const {
}

address ArchiveBuilder::offset_to_buffered_address(size_t offset) const {
address requested_addr = _requested_static_archive_bottom + offset;
address requested_addr = ArchiveUtils::offset_to_requested_addr(_requested_static_archive_bottom, offset);
address buffered_addr = requested_addr - _buffer_to_requested_delta;
assert(is_in_buffer_space(buffered_addr), "bad offset");
return buffered_addr;
Expand Down Expand Up @@ -1048,7 +1048,7 @@ class RelocateBufferToRequested : public BitMapClosure {

address bottom = _builder->buffer_bottom();
address top = _builder->buffer_top();
address new_bottom = bottom + _buffer_to_requested_delta;
address new_bottom = ArchiveUtils::offset_to_requested_addr(bottom, _buffer_to_requested_delta);
address new_top = top + _buffer_to_requested_delta;
aot_log_debug(aot)("Relocating archive from [" INTPTR_FORMAT " - " INTPTR_FORMAT "] to "
"[" INTPTR_FORMAT " - " INTPTR_FORMAT "]",
Expand Down Expand Up @@ -1109,7 +1109,7 @@ void ArchiveBuilder::relocate_to_requested() {
size_t my_archive_size = buffer_top() - buffer_bottom();

if (CDSConfig::is_dumping_static_archive()) {
_requested_static_archive_top = _requested_static_archive_bottom + my_archive_size;
_requested_static_archive_top = ArchiveUtils::offset_to_requested_addr(_requested_static_archive_bottom, my_archive_size);
RelocateBufferToRequested<true> patcher(this);
patcher.doit();
} else {
Expand Down
6 changes: 6 additions & 0 deletions src/hotspot/share/cds/archiveUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ class ArchiveUtils {
static Array<T>* archive_array(GrowableArray<T>* tmp_array) {
return archive_ptr_array(tmp_array);
}

template <typename T>
static address offset_to_requested_addr(T requested_base, size_t offset) {
// As zero is allowed for requested_base, use integer arithmetic to avoid UB pointer arithmetic.
return (address)((uintptr_t)requested_base + offset);
}
};

class HeapRootSegments {
Expand Down