Path: blob/master/runtime/gc_base/IdleGCManager.cpp
5985 views
1/*******************************************************************************2* Copyright (c) 1991, 2020 IBM Corp. and others3*4* This program and the accompanying materials are made available under5* the terms of the Eclipse Public License 2.0 which accompanies this6* distribution and is available at https://www.eclipse.org/legal/epl-2.0/7* or the Apache License, Version 2.0 which accompanies this distribution and8* is available at https://www.apache.org/licenses/LICENSE-2.0.9*10* This Source Code may also be made available under the following11* Secondary Licenses when the conditions for such availability set12* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU13* General Public License, version 2 with the GNU Classpath14* Exception [1] and GNU General Public License, version 2 with the15* OpenJDK Assembly Exception [2].16*17* [1] https://www.gnu.org/software/classpath/license.html18* [2] http://openjdk.java.net/legal/assembly-exception.html19*20* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception21*******************************************************************************/2223#include "j9.h"24#include "j9cfg.h"25#if defined(OMR_GC_IDLE_HEAP_MANAGER)26#include "j9protos.h"27#include "j9consts.h"28#include "vmhook_internal.h"2930#include "IdleGCManager.hpp"31#include "EnvironmentBase.hpp"32#include "GCExtensions.hpp"33#include "OMRVMInterface.hpp"34#include "Heap.hpp"3536MM_IdleGCManager *37MM_IdleGCManager::newInstance(MM_EnvironmentBase* env)38{39MM_IdleGCManager* idleGCMgr = (MM_IdleGCManager*)env->getForge()->allocate(sizeof(MM_IdleGCManager), MM_AllocationCategory::FIXED, J9_GET_CALLSITE());40if (idleGCMgr) {41new(idleGCMgr) MM_IdleGCManager(env);42if (!idleGCMgr->initialize(env)) {43idleGCMgr->kill(env);44idleGCMgr = NULL;45}46}47return idleGCMgr;48}4950void51MM_IdleGCManager::kill(MM_EnvironmentBase* env)52{53tearDown(env);54env->getForge()->free(this);55}5657void58MM_IdleGCManager::tearDown(MM_EnvironmentBase* env)59{60J9HookInterface** hookInterface = _javaVM->internalVMFunctions->getVMHookInterface(_javaVM);61if (NULL != hookInterface) {62(*hookInterface)->J9HookUnregister(hookInterface, J9HOOK_VM_RUNTIME_STATE_CHANGED, idleGCManagerVMStateHook, this);63}64}6566bool67MM_IdleGCManager::initialize(MM_EnvironmentBase* env)68{69J9HookInterface** hookInterface = _javaVM->internalVMFunctions->getVMHookInterface(_javaVM);70if (NULL != hookInterface && (*hookInterface)->J9HookRegister(hookInterface, J9HOOK_VM_RUNTIME_STATE_CHANGED, idleGCManagerVMStateHook, this)) {71return false;72}73return true;74}7576void77MM_IdleGCManager::manageFreeHeap(J9VMThread* currentThread)78{79MM_EnvironmentBase* env = MM_EnvironmentBase::getEnvironment(currentThread->omrVMThread);80MM_GCExtensions* _extensions = MM_GCExtensions::getExtensions(env);8182_javaVM->internalVMFunctions->internalAcquireVMAccess(currentThread);83_extensions->heap->systemGarbageCollect(env, J9MMCONSTANT_EXPLICIT_GC_IDLE_GC);84_javaVM->internalVMFunctions->internalReleaseVMAccess(currentThread);85}8687extern "C" {88void idleGCManagerVMStateHook(J9HookInterface** hook, uintptr_t eventNum, void* eventData, void* userData)89{90J9VMRuntimeStateChanged* j9VMState = (J9VMRuntimeStateChanged*)eventData;91MM_IdleGCManager* idleMgr = (MM_IdleGCManager*)userData;9293/* idle gc manager currently handles only ACTIVE -> IDLE transition*/94if (j9VMState->state == J9VM_RUNTIME_STATE_IDLE) {95idleMgr->manageFreeHeap(j9VMState->vmThread);96}97}98} /*end extern "C" */99#endif /* defined(OMR_GC_IDLE_HEAP_MANAGER) */100101102