8167650: NMT should check for invalid MEMFLAGS
authorstuefe
Wed, 23 Nov 2016 14:33:45 +0100
changeset 42593 d7be1cb119a2
parent 42592 6c1ca562e05a
child 42594 1b274c848385
child 42595 b1ae41a4eae9
8167650: NMT should check for invalid MEMFLAGS Reviewed-by: dholmes, mockner, cjplummer
hotspot/src/share/vm/services/nmtCommon.hpp
--- a/hotspot/src/share/vm/services/nmtCommon.hpp	Wed Nov 23 12:01:57 2016 +0300
+++ b/hotspot/src/share/vm/services/nmtCommon.hpp	Wed Nov 23 14:33:45 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -55,7 +55,9 @@
  public:
   // Map memory type to index
   static inline int flag_to_index(MEMFLAGS flag) {
-    return (flag & 0xff);
+    const int index = flag & 0xff;
+    assert(index >= 0 && index < (int)mt_number_of_types, "Index out of bounds");
+    return index;
   }
 
   // Map memory type to human readable name
@@ -65,6 +67,7 @@
 
   // Map an index to memory type
   static MEMFLAGS index_to_flag(int index) {
+    assert(index >= 0 && index < (int) mt_number_of_types, "Index out of bounds");
     return (MEMFLAGS)index;
   }