/* * Copyright (c) 2013, 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. *
*/
// Tracker is used for guarding 'release' semantics of virtual memory operation, to avoid // the other thread obtains and records the same region that is just 'released' by current // thread but before it can record the operation. class Tracker : public StackObj { public: enum TrackerType {
uncommit,
release
};
class MemTracker : AllStatic { friendclass VirtualMemoryTrackerTest;
// Helper; asserts that we are in post-NMT-init phase staticvoid assert_post_init() {
assert(is_initialized(), "NMT not yet initialized.");
}
public:
// Initializes NMT to whatever -XX:NativeMemoryTracking says. // - Can only be called once. // - NativeMemoryTracking must be validated beforehand. staticvoid initialize();
// Returns true if NMT had been initialized. staticbool is_initialized() { return _tracking_level != NMT_unknown;
}
// Record malloc free and return malloc base address staticinlinevoid* record_free(void* memblock) { // Never turned on
assert(memblock != NULL, "caller should handle NULL"); if (!enabled()) { return memblock;
} return MallocTracker::record_free_block(memblock);
} staticinlinevoid deaccount(MallocHeader::FreeInfo free_info) {
assert(enabled(), "NMT must be enabled");
MallocTracker::deaccount(free_info);
}
// Record creation of an arena staticinlinevoid record_new_arena(MEMFLAGS flag) { if (!enabled()) return;
MallocTracker::record_new_arena(flag);
}
// Record destruction of an arena staticinlinevoid record_arena_free(MEMFLAGS flag) { if (!enabled()) return;
MallocTracker::record_arena_free(flag);
}
// Record arena size change. Arena size is the size of all arena // chunks that are backing up the arena. staticinlinevoid record_arena_size_change(ssize_t diff, MEMFLAGS flag) { if (!enabled()) return;
MallocTracker::record_arena_size_change(diff, flag);
}
// Note: virtual memory operations should only ever be called after NMT initialization // (we do not do any reservations before that).
staticinlinevoid record_virtual_memory_reserve(void* addr, size_t size, const NativeCallStack& stack,
MEMFLAGS flag = mtNone) {
assert_post_init(); if (!enabled()) return; if (addr != NULL) {
ThreadCritical tc;
VirtualMemoryTracker::add_reserved_region((address)addr, size, stack, flag);
}
}
// Given an existing memory mapping registered with NMT and a splitting // address, split the mapping in two. The memory region is supposed to // be fully uncommitted. // // The two new memory regions will be both registered under stack and // memory flags of the original region. staticinlinevoid record_virtual_memory_split_reserved(void* addr, size_t size, size_t split) {
assert_post_init(); if (!enabled()) return; if (addr != NULL) {
ThreadCritical tc;
VirtualMemoryTracker::split_reserved_region((address)addr, size, split);
}
}
staticvoid record_thread_stack(void* addr, size_t size) {
assert_post_init(); if (!enabled()) return; if (addr != NULL) {
ThreadStackTracker::new_thread_stack((address)addr, size, CALLER_PC);
}
}
staticinlinevoid release_thread_stack(void* addr, size_t size) {
assert_post_init(); if (!enabled()) return; if (addr != NULL) {
ThreadStackTracker::delete_thread_stack((address)addr, size);
}
}
// Query lock is used to synchronize the access to tracking data. // So far, it is only used by JCmd query, but it may be used by // other tools. staticinline Mutex* query_lock() {
assert(NMTQuery_lock != NULL, "not initialized!"); return NMTQuery_lock;
}
// Report during error reporting. staticvoid error_report(outputStream* output);
// Report when handling PrintNMTStatistics before VM shutdown. staticvoid final_report(outputStream* output);
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.