Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_trace/TgcExcessivegc.cpp
5985 views
1
2
/*******************************************************************************
3
* Copyright (c) 1991, 2018 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
#include "j9port.h"
27
#include "modronopt.h"
28
#include "mmhook.h"
29
30
#include "GCExtensions.hpp"
31
#include "EnvironmentBase.hpp"
32
#include "TgcExtensions.hpp"
33
34
/**
35
* Check for excessive GC.
36
* Function called by a hook when the collector checks for excessive GC
37
*
38
*/
39
static void
40
tgcHookExcessiveGCCheckGCActivity(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)
41
{
42
MM_ExcessiveGCCheckGCActivityEvent* event = (MM_ExcessiveGCCheckGCActivityEvent *)eventData;
43
MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(event->currentThread);
44
45
tgcExtensions->printf("\texcessiveGC: gcid=\"%zu\" intimems=\"%llu.%03.3llu\" outtimems=\"%llu.%03.3llu\" percent=\"%2.2f\" averagepercent=\"%2.2f\" \n",
46
event->gcCount,
47
event->gcInTime / 1000,
48
event->gcInTime % 1000,
49
event->gcOutTime / 1000,
50
event->gcOutTime % 1000,
51
event->newGCPercent,
52
event->averageGCPercent);
53
}
54
55
/**
56
* Excessive GC raised.
57
* Function called by a hook when the collector raises excessive GC condition.
58
*
59
*/
60
static void
61
tgcHookExcessiveGCCheckFreeSpace(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)
62
{
63
MM_ExcessiveGCCheckFreeSpaceEvent* event = (MM_ExcessiveGCCheckFreeSpaceEvent *)eventData;
64
MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions(event->currentThread);
65
66
tgcExtensions->printf("\texcessiveGC: gcid=\"%zu\" percentreclaimed=\"%2.2f\" freedelta=\"%zu\" activesize=\"%zu\" currentsize=\"%zu\" maxiumumsize=\"%zu\" \n",
67
event->gcCount,
68
event->reclaimedPercent,
69
event->freeMemoryDelta,
70
event->activeHeapSize,
71
event->currentHeapSize,
72
event->maximumHeapSize);
73
}
74
75
/**
76
* Excessive GC raised.
77
* Function called by a hook when the collector raises excessive GC condition.
78
*
79
*/
80
static void
81
tgcHookExcessiveGCRaised(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)
82
{
83
MM_ExcessiveGCRaisedEvent* event = (MM_ExcessiveGCRaisedEvent *)eventData;
84
MM_TgcExtensions *tgcExtensions = MM_TgcExtensions::getExtensions((J9VMThread*)(event->currentThread->_language_vmthread));
85
86
tgcExtensions->printf("\texcessiveGC: gcid=\"%zu\" percentreclaimed=\"%2.2f\" minimum=\"%2.2f\" excessive gc raised \n",
87
event->gcCount,
88
event->reclaimedPercent,
89
event->triggerPercent);
90
}
91
92
/**
93
* Initialize excessive tgc tracing.
94
* Initializes the TgcExcessiveGCExtensions object associated with excessive GC tgc tracing. Attaches hooks
95
* to the appropriate functions handling events used by excessive GC tgc tracing.
96
*/
97
bool
98
tgcExcessiveGCInitialize(J9JavaVM *javaVM)
99
{
100
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
101
bool result = true;
102
103
J9HookInterface** privateHooks = J9_HOOK_INTERFACE(extensions->privateHookInterface);
104
J9HookInterface** publicHooks = J9_HOOK_INTERFACE(extensions->hookInterface);
105
J9HookInterface** omrPublicHooks = J9_HOOK_INTERFACE(extensions->omrHookInterface);
106
(*privateHooks)->J9HookRegisterWithCallSite(privateHooks, J9HOOK_MM_PRIVATE_EXCESSIVEGC_CHECK_GC_ACTIVITY, tgcHookExcessiveGCCheckGCActivity, OMR_GET_CALLSITE(), NULL);
107
(*privateHooks)->J9HookRegisterWithCallSite(privateHooks, J9HOOK_MM_PRIVATE_EXCESSIVEGC_CHECK_FREE_SPACE, tgcHookExcessiveGCCheckFreeSpace, OMR_GET_CALLSITE(), NULL);
108
(*publicHooks)->J9HookRegisterWithCallSite(omrPublicHooks, J9HOOK_MM_OMR_EXCESSIVEGC_RAISED, tgcHookExcessiveGCRaised, OMR_GET_CALLSITE(), NULL);
109
110
return result;
111
}
112
113