memBaseline.cpp revision 4168
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "memory/allocation.hpp"
#include "services/memBaseline.hpp"
#include "services/memTracker.hpp"
{mtJavaHeap, "Java Heap"},
{mtClass, "Class"},
{mtThreadStack,"Thread Stack"},
{mtThread, "Thread"},
{mtCode, "Code"},
{mtGC, "GC"},
{mtCompiler, "Compiler"},
{mtInternal, "Internal"},
{mtOther, "Other"},
{mtSymbol, "Symbol"},
{mtNMT, "Memory Tracking"},
{mtTracing, "Tracing"},
{mtChunk, "Pooled Free Chunks"},
{mtClassShared,"Shared spaces for classes"},
// behind
};
MemBaseline::MemBaseline() {
_baselined = false;
}
_malloc_cs = NULL;
_number_of_classes = 0;
_number_of_threads = 0;
}
void MemBaseline::clear() {
if (_malloc_cs != NULL) {
delete _malloc_cs;
_malloc_cs = NULL;
}
delete _vm_cs;
}
delete _vm_map;
}
reset();
}
void MemBaseline::reset() {
_baselined = false;
_total_vm_reserved = 0;
_total_vm_committed = 0;
_total_malloced = 0;
_number_of_classes = 0;
}
}
MemBaseline::~MemBaseline() {
clear();
}
// baseline malloc'd memory records, generate overall summary and summaries by
// memory types
size_t used_arena_size = 0;
int index;
while (malloc_ptr != NULL) {
if (malloc_ptr->is_arena_memory_record()) {
// We do have anonymous arenas, they are either used as value objects,
// which are embedded inside other objects, or used as stack objects.
used_arena_size += size;
} else {
_total_malloced += size;
if (malloc_ptr->is_arena_record()) {
// see if arena memory record present
if (next_malloc_ptr->is_arena_memory_record()) {
"Arena records do not match");
used_arena_size += size;
malloc_itr.next();
}
}
}
}
// substract used arena size to get size of arena chunk in free list
// we really don't know how many chunks in free list, so just set to
// 0
return true;
}
// baseline mmap'd memory records, generate overall summary and summaries by
// memory types
int index;
if (vm_ptr->is_reserved_region()) {
// we use the number of thread stack to count threads
}
} else {
}
}
return true;
}
// baseline malloc'd memory by callsites, but only the callsites with memory allocation
// over 1KB are stored.
// initailize malloc callsite array
if (_malloc_cs == NULL) {
// out of native memory
return false;
}
} else {
_malloc_cs->clear();
}
// sort into callsite pc order. Details are aggregated by callsites
bool ret = true;
// baseline memory that is totaled over 1 KB
while (malloc_ptr != NULL) {
// skip thread stacks
if ((malloc_callsite.amount()/K) > 0) {
ret = false;
break;
}
}
}
}
}
}
// restore to address order. Snapshot malloc data is maintained in memory
// address order.
if (!ret) {
return false;
}
// deal with last record
return false;
}
}
return true;
}
// baseline mmap'd memory by callsites
// initialize virtual memory map array
return false;
}
} else {
}
// initialize virtual memory callsite array
return false;
}
} else {
}
// consolidate virtual memory data
// vm_ptr is coming in increasing base address order
if (vm_ptr->is_reserved_region()) {
// consolidate reserved memory regions for virtual memory map.
// The criteria for consolidation is:
// 1. two adjacent reserved memory regions
// 2. belong to the same memory type
// 3. reserved from the same callsite
if (reserved_rec == NULL ||
return false;
}
// inserted reserved region, we need the pointer to the element in virtual
// memory map array.
} else {
}
return false;
}
} else {
// consolidate committed memory regions for virtual memory map
// The criterial is:
// 1. two adjacent committed memory regions
// 2. committed from the same callsite
if (committed_rec == NULL ||
return false;
}
} else {
}
}
}
// deal with last record
return false;
}
// sort it into callsite pc order. Details are aggregated by callsites
// walk the array to consolidate record by pc
} else {
}
}
return true;
}
// baseline a snapshot. If summary_only = false, memory usages aggregated by
// callsites are also baselined.
reset();
}
return _baselined;
}
return index;
}
}
assert(false, "no type");
return -1;
}
}
}
return NULL;
}
}
if (MemTracker::track_callsite()) {
"not properly baselined");
_malloc_cs->clear();
int index;
}
}
}
return *this;
}
/* compare functions for sorting */
// sort snapshot malloc'd records in callsite pc order
}
// sort baselined malloc'd records in size order
}
// sort baselined malloc'd records in callsite pc order
}
// sort baselined mmap'd records in size (reserved size) order
}
// sort baselined mmap'd records in callsite pc order
}
// sort snapshot malloc'd records in memory block address order
return delta;
}