Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/hotspot/share/nmt/mallocLimit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,23 @@ void MallocLimitSet::print_on(outputStream* st) const {
}
}

void MallocLimitSet::print_on_xml(xmlStream* xs) const {
if (_glob.sz > 0) {
XmlParent("globalLimit");
XmlElem("amount", "%zu", _glob.sz);
XmlElem("name", "%s", mode_to_name(_glob.mode));
} else {
XmlParent("memTagLimit");
for (int i = 0; i < mt_number_of_tags; i++) {
if (_mtag[i].sz > 0) {
XmlElem("memTag", "%s", NMTUtil::tag_to_enum_name(NMTUtil::index_to_tag(i)));
XmlElem("amount", "%zu", _mtag[i].sz);
XmlElem("modeName", "%s", mode_to_name(_mtag[i].mode));
}
}
}
}

bool MallocLimitSet::parse_malloclimit_option(const char* v, const char** err) {

#define BAIL_UNLESS(condition, errormessage) if (!(condition)) { *err = errormessage; return false; }
Expand Down Expand Up @@ -228,3 +245,12 @@ void MallocLimitHandler::print_on(outputStream* st) {
st->print_cr("MallocLimit: unset");
}
}

void MallocLimitHandler::print_on_xml(xmlStream* xs) {
if (have_limit()) {
XmlParent("mallocLimits")
_limits.print_on_xml(xs);
} else {
XmlElem("mallocLimit", "unset");
}
}
3 changes: 3 additions & 0 deletions src/hotspot/share/nmt/mallocLimit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "nmt/memTag.hpp"
#include "utilities/debug.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/xmlstream.hpp"

enum class MallocLimitMode {
trigger_fatal = 0,
Expand Down Expand Up @@ -60,6 +61,7 @@ class MallocLimitSet {
const malloclimit* mem_tag_limit(MemTag mem_tag) const { return &_mtag[(int)mem_tag]; }

void print_on(outputStream* st) const;
void print_on_xml(xmlStream* st) const;
};

class MallocLimitHandler : public AllStatic {
Expand All @@ -73,6 +75,7 @@ class MallocLimitHandler : public AllStatic {

static void initialize(const char* options);
static void print_on(outputStream* st);
static void print_on_xml(xmlStream* st);

// True if there is any limit established
static bool have_limit() { return _have_limit; }
Expand Down
55 changes: 55 additions & 0 deletions src/hotspot/share/nmt/mallocSiteTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,61 @@ void MallocSiteTable::print_tuning_statistics(outputStream* st) {
st->cr();
}

void MallocSiteTable::print_tuning_statistics_xml(xmlStream* xs) {
// Total number of allocation sites, include empty sites
int total_entries = 0;
// Number of allocation sites that have all memory freed
int empty_entries = 0;
// Number of captured call stack distribution
int stack_depth_distribution[NMT_TrackingStackDepth + 1] = { 0 };
// Chain lengths
uint16_t lengths[table_size] = { 0 };
// Unused buckets
int unused_buckets = 0;

for (int i = 0; i < table_size; i ++) {
int this_chain_length = 0;
const MallocSiteHashtableEntry* head = _table[i];
if (head == nullptr) {
unused_buckets ++;
}
while (head != nullptr) {
total_entries ++;
this_chain_length ++;
if (head->size() == 0) {
empty_entries ++;
}
const int callstack_depth = head->peek()->call_stack()->frames();
assert(callstack_depth >= 0 && callstack_depth <= NMT_TrackingStackDepth,
"Sanity (%d)", callstack_depth);
stack_depth_distribution[callstack_depth] ++;
head = head->next();
}
lengths[i] = (uint16_t)MIN2(this_chain_length, USHRT_MAX);
}
XmlElem("totalEntries", "%d", total_entries);
XmlElem("emptyEntries", "%d", empty_entries);
XmlElem("emptyEntriesPercentage", "%2.2f", ((float)empty_entries * 100) / (float)total_entries);


qsort(lengths, table_size, sizeof(uint16_t), qsort_helper);

{
XmlParent("bucketChainLengthDistribution");
XmlElem("unused", "%d", unused_buckets);
XmlElem("longest", "%d", lengths[table_size - 1]);
XmlElem("median", "%d", lengths[table_size / 2]);
}

{
XmlParent("callStackDepthDistribution");
for (int i = 0; i <= NMT_TrackingStackDepth; i ++) {
XmlElem("depth", "%d", i);
XmlElem("count", "%d", stack_depth_distribution[i]);
}
}
}

bool MallocSiteHashtableEntry::atomic_insert(MallocSiteHashtableEntry* entry) {
return AtomicAccess::replace_if_null(&_next, entry);
}
2 changes: 2 additions & 0 deletions src/hotspot/share/nmt/mallocSiteTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "runtime/atomicAccess.hpp"
#include "utilities/macros.hpp"
#include "utilities/nativeCallStack.hpp"
#include "utilities/xmlstream.hpp"

// MallocSite represents a code path that eventually calls
// os::malloc() to allocate memory
Expand Down Expand Up @@ -168,6 +169,7 @@ class MallocSiteTable : AllStatic {
static bool walk_malloc_site(MallocSiteWalker* walker);

static void print_tuning_statistics(outputStream* st);
static void print_tuning_statistics_xml(xmlStream* st);

private:
static MallocSiteHashtableEntry* new_entry(const NativeCallStack& key, MemTag mem_tag);
Expand Down
Loading