# HG changeset patch # User stuefe # Date 1476336338 -7200 # Thu Oct 13 07:25:38 2016 +0200 # Node ID 0f660303b144f7bbc1c42d227c366ac5cd1987ac # Parent b1c62e595c4ac0a3256296b8c13d871db9003fe8 8167650: NMT should check for invalid MEMFLAGS Reviewed-by: dholmes, mockner diff --git a/src/share/vm/services/mallocTracker.cpp b/src/share/vm/services/mallocTracker.cpp --- a/src/share/vm/services/mallocTracker.cpp +++ b/src/share/vm/services/mallocTracker.cpp @@ -55,6 +55,7 @@ void MallocMemorySnapshot::make_adjustment() { size_t arena_size = total_arena(); int chunk_idx = NMTUtil::flag_to_index(mtChunk); + assert(chunk_idx >= 0 && chunk_idx < mt_number_of_types, "Index out of bound."); _malloc[chunk_idx].record_free(arena_size); } diff --git a/src/share/vm/services/mallocTracker.hpp b/src/share/vm/services/mallocTracker.hpp --- a/src/share/vm/services/mallocTracker.hpp +++ b/src/share/vm/services/mallocTracker.hpp @@ -141,6 +141,7 @@ public: inline MallocMemory* by_type(MEMFLAGS flags) { int index = NMTUtil::flag_to_index(flags); + assert(index >= 0 && index < mt_number_of_types, "Index out of bound"); return &_malloc[index]; } diff --git a/src/share/vm/services/nmtCommon.hpp b/src/share/vm/services/nmtCommon.hpp --- a/src/share/vm/services/nmtCommon.hpp +++ b/src/share/vm/services/nmtCommon.hpp @@ -60,11 +60,14 @@ // Map memory type to human readable name static const char* flag_to_name(MEMFLAGS flag) { - return _memory_type_names[flag_to_index(flag)]; + int index = flag_to_index(flag); + assert(index >= 0 && index < mt_number_of_types, "Index out of bound."); + return _memory_type_names[index]; } // Map an index to memory type static MEMFLAGS index_to_flag(int index) { + assert(index >= 0 && index < mt_number_of_types, "Index out of bound."); return (MEMFLAGS)index; } diff --git a/src/share/vm/services/virtualMemoryTracker.hpp b/src/share/vm/services/virtualMemoryTracker.hpp --- a/src/share/vm/services/virtualMemoryTracker.hpp +++ b/src/share/vm/services/virtualMemoryTracker.hpp @@ -93,6 +93,7 @@ public: inline VirtualMemory* by_type(MEMFLAGS flag) { int index = NMTUtil::flag_to_index(flag); + assert(index >= 0 && index < mt_number_of_types, "Index out of bound."); return &_virtual_memory[index]; }