Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_base/IdleGCManager.cpp
5985 views
1
2
/*******************************************************************************
3
* Copyright (c) 1991, 2020 IBM Corp. and others
4
*
5
* This program and the accompanying materials are made available under
6
* the terms of the Eclipse Public License 2.0 which accompanies this
7
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
8
* or the Apache License, Version 2.0 which accompanies this distribution and
9
* is available at https://www.apache.org/licenses/LICENSE-2.0.
10
*
11
* This Source Code may also be made available under the following
12
* Secondary Licenses when the conditions for such availability set
13
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
14
* General Public License, version 2 with the GNU Classpath
15
* Exception [1] and GNU General Public License, version 2 with the
16
* OpenJDK Assembly Exception [2].
17
*
18
* [1] https://www.gnu.org/software/classpath/license.html
19
* [2] http://openjdk.java.net/legal/assembly-exception.html
20
*
21
* 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-exception
22
*******************************************************************************/
23
24
#include "j9.h"
25
#include "j9cfg.h"
26
#if defined(OMR_GC_IDLE_HEAP_MANAGER)
27
#include "j9protos.h"
28
#include "j9consts.h"
29
#include "vmhook_internal.h"
30
31
#include "IdleGCManager.hpp"
32
#include "EnvironmentBase.hpp"
33
#include "GCExtensions.hpp"
34
#include "OMRVMInterface.hpp"
35
#include "Heap.hpp"
36
37
MM_IdleGCManager *
38
MM_IdleGCManager::newInstance(MM_EnvironmentBase* env)
39
{
40
MM_IdleGCManager* idleGCMgr = (MM_IdleGCManager*)env->getForge()->allocate(sizeof(MM_IdleGCManager), MM_AllocationCategory::FIXED, J9_GET_CALLSITE());
41
if (idleGCMgr) {
42
new(idleGCMgr) MM_IdleGCManager(env);
43
if (!idleGCMgr->initialize(env)) {
44
idleGCMgr->kill(env);
45
idleGCMgr = NULL;
46
}
47
}
48
return idleGCMgr;
49
}
50
51
void
52
MM_IdleGCManager::kill(MM_EnvironmentBase* env)
53
{
54
tearDown(env);
55
env->getForge()->free(this);
56
}
57
58
void
59
MM_IdleGCManager::tearDown(MM_EnvironmentBase* env)
60
{
61
J9HookInterface** hookInterface = _javaVM->internalVMFunctions->getVMHookInterface(_javaVM);
62
if (NULL != hookInterface) {
63
(*hookInterface)->J9HookUnregister(hookInterface, J9HOOK_VM_RUNTIME_STATE_CHANGED, idleGCManagerVMStateHook, this);
64
}
65
}
66
67
bool
68
MM_IdleGCManager::initialize(MM_EnvironmentBase* env)
69
{
70
J9HookInterface** hookInterface = _javaVM->internalVMFunctions->getVMHookInterface(_javaVM);
71
if (NULL != hookInterface && (*hookInterface)->J9HookRegister(hookInterface, J9HOOK_VM_RUNTIME_STATE_CHANGED, idleGCManagerVMStateHook, this)) {
72
return false;
73
}
74
return true;
75
}
76
77
void
78
MM_IdleGCManager::manageFreeHeap(J9VMThread* currentThread)
79
{
80
MM_EnvironmentBase* env = MM_EnvironmentBase::getEnvironment(currentThread->omrVMThread);
81
MM_GCExtensions* _extensions = MM_GCExtensions::getExtensions(env);
82
83
_javaVM->internalVMFunctions->internalAcquireVMAccess(currentThread);
84
_extensions->heap->systemGarbageCollect(env, J9MMCONSTANT_EXPLICIT_GC_IDLE_GC);
85
_javaVM->internalVMFunctions->internalReleaseVMAccess(currentThread);
86
}
87
88
extern "C" {
89
void idleGCManagerVMStateHook(J9HookInterface** hook, uintptr_t eventNum, void* eventData, void* userData)
90
{
91
J9VMRuntimeStateChanged* j9VMState = (J9VMRuntimeStateChanged*)eventData;
92
MM_IdleGCManager* idleMgr = (MM_IdleGCManager*)userData;
93
94
/* idle gc manager currently handles only ACTIVE -> IDLE transition*/
95
if (j9VMState->state == J9VM_RUNTIME_STATE_IDLE) {
96
idleMgr->manageFreeHeap(j9VMState->vmThread);
97
}
98
}
99
} /*end extern "C" */
100
#endif /* defined(OMR_GC_IDLE_HEAP_MANAGER) */
101
102