// Memory allocated from this code path
size_t size() const { return _c.size(); } // Peak memory ever allocated from this code path
size_t peak_size() const { return _c.peak_size(); } // The number of calls were made
size_t count() const { return _c.count(); }
// Insert an entry atomically. // Return true if the entry is inserted successfully. // The operation can be failed due to contention from other thread. bool atomic_insert(MallocSiteHashtableEntry* entry);
// The walker walks every entry on MallocSiteTable class MallocSiteWalker : public StackObj { public: virtualbool do_malloc_site(const MallocSite* e) { returnfalse; }
};
/* *Nativememorytrackingcallsitetable. *Thetableisonlyneededwhendetailtrackingisenabled.
*/ class MallocSiteTable : AllStatic { private: // The number of hash bucket in this hashtable. The number should // be tuned if malloc activities changed significantly. // The statistics data can be obtained via Jcmd // jcmd <pid> VM.native_memory statistics. staticconstint table_size = 4099;
// Table cannot be wider than a 16bit bucket idx can hold #define MAX_MALLOCSITE_TABLE_SIZE (USHRT_MAX - 1) // Each bucket chain cannot be longer than what a 16 bit pos idx can hold (hopefully way shorter) #define MAX_BUCKET_LENGTH (USHRT_MAX - 1)
// Number of hash buckets staticinlineint hash_buckets() { return (int)table_size; }
// Access and copy a call stack from this table. Shared lock should be // acquired before access the entry. staticinlinebool access_stack(NativeCallStack& stack, uint32_t marker) {
MallocSite* site = malloc_site(marker); if (site != NULL) {
stack = *site->call_stack(); returntrue;
} returnfalse;
}
// Record a new allocation from specified call path. // Return true if the allocation is recorded successfully and updates marker // to indicate the entry where the allocation information was recorded. // Return false only occurs under rare scenarios: // 1. out of memory // 2. overflow hash bucket staticinlinebool allocation_at(const NativeCallStack& stack, size_t size,
uint32_t* marker, MEMFLAGS flags) {
MallocSite* site = lookup_or_add(stack, marker, flags); if (site != NULL) site->allocate(size); return site != NULL;
}
// Record memory deallocation. marker indicates where the allocation // information was recorded. staticinlinebool deallocation_at(size_t size, uint32_t marker) {
MallocSite* site = malloc_site(marker); if (site != NULL) {
site->deallocate(size); returntrue;
} returnfalse;
}
// Walk this table. staticbool walk_malloc_site(MallocSiteWalker* walker);
private: // The callsite hashtable. It has to be a static table, // since malloc call can come from C runtime linker. static MallocSiteHashtableEntry** _table; staticconst NativeCallStack* _hash_entry_allocation_stack; staticconst MallocSiteHashtableEntry* _hash_entry_allocation_site;
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.