/* * Copyright (c) 2003, 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. *
*/
// Returns an instanceOop of a MemoryPool object. // It creates a MemoryPool instance when the first time // this function is called.
instanceOop MemoryPool::get_memory_pool_instance(TRAPS) { // Must do an acquire so as to force ordering of subsequent // loads from anything _memory_pool_obj points to or implies.
oop pool_obj = Atomic::load_acquire(&_memory_pool_obj).resolve(); if (pool_obj == NULL) { // It's ok for more than one thread to execute the code up to the locked region. // Extra pool instances will just be gc'ed.
InstanceKlass* ik = Management::sun_management_ManagementFactoryHelper_klass(CHECK_NULL);
instanceOop p = (instanceOop) result.get_oop();
instanceHandle pool(THREAD, p);
{ // Get lock since another thread may have create the instance
MutexLocker ml(THREAD, Management_lock);
// Check if another thread has created the pool. We reload // _memory_pool_obj here because some other thread may have // initialized it while we were executing the code before the lock.
pool_obj = Atomic::load(&_memory_pool_obj).resolve(); if (pool_obj != NULL) { return (instanceOop)pool_obj;
}
// Get the address of the object we created via call_special.
pool_obj = pool();
// Use store barrier to make sure the memory accesses associated // with creating the pool are visible before publishing its address. // The unlock will publish the store to _memory_pool_obj because // it does a release first.
Atomic::release_store(&_memory_pool_obj, OopHandle(Universe::vm_global(), pool_obj));
}
}
void MemoryPool::record_peak_memory_usage() { // Caller in JDK is responsible for synchronization - // acquire the lock for this memory pool before calling VM
MemoryUsage usage = get_memory_usage();
size_t peak_used = get_max_value(usage.used(), _peak_usage.used());
size_t peak_committed = get_max_value(usage.committed(), _peak_usage.committed());
size_t peak_max_size = get_max_value(usage.max_size(), _peak_usage.max_size());
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.