/* * Copyright (c) 2014, 2022, 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 * 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. *
*/
// 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; }
};
/* * Native memory tracking call site table. * The table is only needed when detail tracking is enabled.
*/ 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;
};
#endif// SHARE_SERVICES_MALLOCSITETABLE_HPP
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet)
¤
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 ist noch experimentell.