Skip to content

Commit

Permalink
8324828: Avoid multiple search of reserved regions during splitting
Browse files Browse the repository at this point in the history
Reviewed-by: stuefe, jsjolen
  • Loading branch information
Afshin Zafari committed Feb 27, 2024
1 parent c5f1dcc commit 7583419
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/hotspot/share/cds/metaspaceShared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,9 @@ char* MetaspaceShared::reserve_address_space_for_archives(FileMapInfo* static_ma
release_reserved_spaces(total_space_rs, archive_space_rs, class_space_rs);
return nullptr;
}
// NMT: fix up the space tags
MemTracker::record_virtual_memory_type(archive_space_rs.base(), mtClassShared);
MemTracker::record_virtual_memory_type(class_space_rs.base(), mtClass);
} else {
if (use_archive_base_addr && base_address != nullptr) {
total_space_rs = ReservedSpace(total_range_size, archive_space_alignment,
Expand Down Expand Up @@ -1356,16 +1359,13 @@ char* MetaspaceShared::reserve_address_space_for_archives(FileMapInfo* static_ma
(size_t)archive_space_alignment);
class_space_rs = total_space_rs.last_part(ccs_begin_offset);
MemTracker::record_virtual_memory_split_reserved(total_space_rs.base(), total_space_rs.size(),
ccs_begin_offset);
ccs_begin_offset, mtClassShared, mtClass);
}
assert(is_aligned(archive_space_rs.base(), archive_space_alignment), "Sanity");
assert(is_aligned(archive_space_rs.size(), archive_space_alignment), "Sanity");
assert(is_aligned(class_space_rs.base(), class_space_alignment), "Sanity");
assert(is_aligned(class_space_rs.size(), class_space_alignment), "Sanity");

// NMT: fix up the space tags
MemTracker::record_virtual_memory_type(archive_space_rs.base(), mtClassShared);
MemTracker::record_virtual_memory_type(class_space_rs.base(), mtClass);

return archive_space_rs.base();

Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/nmt/memTracker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ class MemTracker : AllStatic {
//
// The two new memory regions will be both registered under stack and
// memory flags of the original region.
static inline void record_virtual_memory_split_reserved(void* addr, size_t size, size_t split) {
static inline void record_virtual_memory_split_reserved(void* addr, size_t size, size_t split, MEMFLAGS flag, MEMFLAGS split_flag) {
assert_post_init();
if (!enabled()) return;
if (addr != nullptr) {
ThreadCritical tc;
VirtualMemoryTracker::split_reserved_region((address)addr, size, split);
VirtualMemoryTracker::split_reserved_region((address)addr, size, split, flag, split_flag);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/nmt/virtualMemoryTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ bool VirtualMemoryTracker::remove_released_region(address addr, size_t size) {
// Given an existing memory mapping registered with NMT, split the mapping in
// two. The newly created two mappings will be registered under the call
// stack and the memory flags of the original section.
bool VirtualMemoryTracker::split_reserved_region(address addr, size_t size, size_t split) {
bool VirtualMemoryTracker::split_reserved_region(address addr, size_t size, size_t split, MEMFLAGS flag, MEMFLAGS split_flag) {

ReservedMemoryRegion rgn(addr, size);
ReservedMemoryRegion* reserved_rgn = _reserved_regions->find(rgn);
Expand All @@ -576,8 +576,8 @@ bool VirtualMemoryTracker::split_reserved_region(address addr, size_t size, size
log_debug(nmt)("Split region \'%s\' (" INTPTR_FORMAT ", " SIZE_FORMAT ") with size " SIZE_FORMAT,
name, p2i(rgn.base()), rgn.size(), split);
// Now, create two new regions.
add_reserved_region(addr, split, original_stack, original_flags);
add_reserved_region(addr + split, size - split, original_stack, original_flags);
add_reserved_region(addr, split, original_stack, flag);
add_reserved_region(addr + split, size - split, original_stack, split_flag);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/nmt/virtualMemoryTracker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ class VirtualMemoryTracker : AllStatic {
// Given an existing memory mapping registered with NMT, split the mapping in
// two. The newly created two mappings will be registered under the call
// stack and the memory flags of the original section.
static bool split_reserved_region(address addr, size_t size, size_t split);
static bool split_reserved_region(address addr, size_t size, size_t split, MEMFLAGS flag, MEMFLAGS split_flag);

// Walk virtual memory data structure for creating baseline, etc.
static bool walk_virtual_memory(VirtualMemoryWalker* walker);
Expand Down

1 comment on commit 7583419

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.