Skip to content

Commit 1b3e231

Browse files
author
Afshin Zafari
committed
8360048: NMT crash in gtest/NMTGtests.java: fatal error: NMT corruption: Block at 0x0000017748307120: header canary broken
Reviewed-by: jsjolen, gziemski
1 parent a26a6f3 commit 1b3e231

File tree

5 files changed

+104
-103
lines changed

5 files changed

+104
-103
lines changed

src/hotspot/share/nmt/memBaseline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ bool MemBaseline::aggregate_virtual_memory_allocation_sites() {
215215
site = node->data();
216216
}
217217
site->reserve_memory(rgn->size());
218-
site->commit_memory(rgn->committed_size());
218+
site->commit_memory(VirtualMemoryTracker::Instance::committed_size(rgn));
219219
}
220220

221221
_virtual_memory_sites.move(&allocation_sites);

src/hotspot/share/nmt/memReporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ void MemDetailReporter::report_virtual_memory_region(const ReservedMemoryRegion*
422422
outputStream* out = output();
423423
const char* scale = current_scale();
424424
const NativeCallStack* stack = reserved_rgn->call_stack();
425-
bool all_committed = reserved_rgn->size() == reserved_rgn->committed_size();
425+
bool all_committed = reserved_rgn->size() == VirtualMemoryTracker::Instance::committed_size(reserved_rgn);
426426
const char* region_type = (all_committed ? "reserved and committed" : "reserved");
427427
out->cr();
428428
print_virtual_memory_region(region_type, reserved_rgn->base(), reserved_rgn->size());

src/hotspot/share/nmt/virtualMemoryTracker.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,20 +219,29 @@ bool VirtualMemoryTracker::walk_virtual_memory(VirtualMemoryWalker* walker) {
219219
return true;
220220
}
221221

222-
size_t ReservedMemoryRegion::committed_size() const {
223-
size_t committed = 0;
222+
size_t VirtualMemoryTracker::committed_size(const ReservedMemoryRegion* rmr) {
224223
size_t result = 0;
225-
VirtualMemoryTracker::Instance::tree()->visit_committed_regions(*this, [&](CommittedMemoryRegion& crgn) {
224+
tree()->visit_committed_regions(*rmr, [&](CommittedMemoryRegion& crgn) {
226225
result += crgn.size();
227226
return true;
228227
});
229228
return result;
230229
}
231230

232-
address ReservedMemoryRegion::thread_stack_uncommitted_bottom() const {
233-
address bottom = base();
234-
address top = base() + size();
235-
VirtualMemoryTracker::Instance::tree()->visit_committed_regions(*this, [&](CommittedMemoryRegion& crgn) {
231+
size_t VirtualMemoryTracker::Instance::committed_size(const ReservedMemoryRegion* rmr) {
232+
assert(_tracker != nullptr, "Sanity check");
233+
return _tracker->committed_size(rmr);
234+
}
235+
236+
address VirtualMemoryTracker::Instance::thread_stack_uncommitted_bottom(const ReservedMemoryRegion* rmr) {
237+
assert(_tracker != nullptr, "Sanity check");
238+
return _tracker->thread_stack_uncommitted_bottom(rmr);
239+
}
240+
241+
address VirtualMemoryTracker::thread_stack_uncommitted_bottom(const ReservedMemoryRegion* rmr) {
242+
address bottom = rmr->base();
243+
address top = rmr->end();
244+
tree()->visit_committed_regions(*rmr, [&](CommittedMemoryRegion& crgn) {
236245
address committed_top = crgn.base() + crgn.size();
237246
if (committed_top < top) {
238247
// committed stack guard pages, skip them
@@ -291,7 +300,7 @@ class SnapshotThreadStackWalker : public VirtualMemoryWalker {
291300
assert_lock_strong(NmtVirtualMemory_lock);
292301
}
293302
if (rgn->mem_tag() == mtThreadStack) {
294-
address stack_bottom = rgn->thread_stack_uncommitted_bottom();
303+
address stack_bottom = VirtualMemoryTracker::Instance::thread_stack_uncommitted_bottom(rgn);
295304
address committed_start;
296305
size_t committed_size;
297306
size_t stack_size = rgn->base() + rgn->size() - stack_bottom;

src/hotspot/share/nmt/virtualMemoryTracker.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,6 @@ class ReservedMemoryRegion : public VirtualMemoryRegion {
330330

331331
inline MemTag mem_tag() const { return _mem_tag; }
332332

333-
// uncommitted thread stack bottom, above guard pages if there is any.
334-
address thread_stack_uncommitted_bottom() const;
335-
336-
size_t committed_size() const;
337-
338-
339333
ReservedMemoryRegion& operator= (const ReservedMemoryRegion& other) {
340334
set_base(other.base());
341335
set_size(other.size());
@@ -382,6 +376,9 @@ class VirtualMemoryTracker {
382376
// Snapshot current thread stacks
383377
void snapshot_thread_stacks();
384378
void apply_summary_diff(VMATree::SummaryDiff diff);
379+
size_t committed_size(const ReservedMemoryRegion* rmr);
380+
address thread_stack_uncommitted_bottom(const ReservedMemoryRegion* rmr);
381+
385382
RegionsTree* tree() { return &_tree; }
386383

387384
class Instance : public AllStatic {
@@ -404,6 +401,9 @@ class VirtualMemoryTracker {
404401
static bool print_containing_region(const void* p, outputStream* st);
405402
static void snapshot_thread_stacks();
406403
static void apply_summary_diff(VMATree::SummaryDiff diff);
404+
static size_t committed_size(const ReservedMemoryRegion* rmr);
405+
// uncommitted thread stack bottom, above guard pages if there is any.
406+
static address thread_stack_uncommitted_bottom(const ReservedMemoryRegion* rmr);
407407

408408
static RegionsTree* tree() { return _tracker->tree(); }
409409
};

0 commit comments

Comments
 (0)