< prev index next >

src/share/vm/services/mallocTracker.hpp

Print this page
rev 12318 : 8167650: NMT should check for invalid MEMFLAGS
Reviewed-by: dholmes, mockner, cjplummer
   1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 124 
 125   DEBUG_ONLY(inline const MemoryCounter& malloc_counter() const { return _malloc; })
 126   DEBUG_ONLY(inline const MemoryCounter& arena_counter()  const { return _arena;  })
 127 };
 128 
 129 class MallocMemorySummary;
 130 
 131 // A snapshot of malloc'd memory, includes malloc memory
 132 // usage by types and memory used by tracking itself.
 133 class MallocMemorySnapshot : public ResourceObj {
 134   friend class MallocMemorySummary;
 135 
 136  private:
 137   MallocMemory      _malloc[mt_number_of_types];
 138   MemoryCounter     _tracking_header;
 139 
 140 
 141  public:
 142   inline MallocMemory*  by_type(MEMFLAGS flags) {
 143     int index = NMTUtil::flag_to_index(flags);

 144     return &_malloc[index];
 145   }
 146 
 147   inline MallocMemory* by_index(int index) {
 148     assert(index >= 0, "Index out of bound");
 149     assert(index < mt_number_of_types, "Index out of bound");
 150     return &_malloc[index];
 151   }
 152 
 153   inline MemoryCounter* malloc_overhead() {
 154     return &_tracking_header;
 155   }
 156 
 157   // Total malloc'd memory amount
 158   size_t total() const;
 159   // Total malloc'd memory used by arenas
 160   size_t total_arena() const;
 161 
 162   inline size_t thread_count() const {
 163     MallocMemorySnapshot* s = const_cast<MallocMemorySnapshot*>(this);


   1 /*
   2  * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 124 
 125   DEBUG_ONLY(inline const MemoryCounter& malloc_counter() const { return _malloc; })
 126   DEBUG_ONLY(inline const MemoryCounter& arena_counter()  const { return _arena;  })
 127 };
 128 
 129 class MallocMemorySummary;
 130 
 131 // A snapshot of malloc'd memory, includes malloc memory
 132 // usage by types and memory used by tracking itself.
 133 class MallocMemorySnapshot : public ResourceObj {
 134   friend class MallocMemorySummary;
 135 
 136  private:
 137   MallocMemory      _malloc[mt_number_of_types];
 138   MemoryCounter     _tracking_header;
 139 
 140 
 141  public:
 142   inline MallocMemory*  by_type(MEMFLAGS flags) {
 143     int index = NMTUtil::flag_to_index(flags);
 144     assert(index >= 0 && index < mt_number_of_types, "Index out of bound");
 145     return &_malloc[index];
 146   }
 147 
 148   inline MallocMemory* by_index(int index) {
 149     assert(index >= 0, "Index out of bound");
 150     assert(index < mt_number_of_types, "Index out of bound");
 151     return &_malloc[index];
 152   }
 153 
 154   inline MemoryCounter* malloc_overhead() {
 155     return &_tracking_header;
 156   }
 157 
 158   // Total malloc'd memory amount
 159   size_t total() const;
 160   // Total malloc'd memory used by arenas
 161   size_t total_arena() const;
 162 
 163   inline size_t thread_count() const {
 164     MallocMemorySnapshot* s = const_cast<MallocMemorySnapshot*>(this);


< prev index next >