Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/jcl/common/com_ibm_jvm_Stats.c
6000 views
1
/*******************************************************************************
2
* Copyright (c) 2012, 2016 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* 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 and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
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-exception
21
*******************************************************************************/
22
23
#include "jni.h"
24
#include "j9.h"
25
#include "jclprots.h"
26
#include "jclglob.h"
27
28
/**
29
* Provides the following statistics:
30
* used heap memory
31
* committed heap memory
32
* max heap memory
33
* softmx heap memory
34
* free physical memory,
35
* total physical memory,
36
* system load average
37
* cpuTime
38
*
39
* This function avoids any allocation of a new object. Instead it sets the field
40
* variables in the class Stats.java
41
*/
42
43
void JNICALL
44
Java_com_ibm_jvm_Stats_getStats(JNIEnv *env, jobject obj)
45
{
46
/* System and Heap statistics */
47
jlong used = 0;
48
jlong committed = 0;
49
jlong max = 0;
50
jlong softmx = 0;
51
jlong free = 0;
52
jlong tot = 0;
53
jdouble sysLoadAvg = -1.0;
54
jlong cpuTime = 0;
55
56
/* Access to the current jvm */
57
J9JavaVM *javaVM = ((J9VMThread *) env)->javaVM;
58
59
/* Port lib access */
60
PORT_ACCESS_FROM_ENV(env);
61
J9PortSysInfoLoadData loadData;
62
IDATA sysInfoResult;
63
64
/* Class and method ID used to set our variables */
65
jclass setFieldsClass = NULL;
66
jmethodID methodID = NULL;
67
68
/* Calculation of java heap properties */
69
committed = javaVM->memoryManagerFunctions->j9gc_heap_total_memory(javaVM);
70
used = committed - javaVM->memoryManagerFunctions->j9gc_heap_free_memory(javaVM);
71
max = (jlong) javaVM->managementData->maximumHeapSize;
72
73
/* Calculation of softmx */
74
softmx = javaVM->memoryManagerFunctions->j9gc_get_softmx( javaVM );
75
76
/* if no softmx has been set, report -Xmx instead as it is the current max heap size */
77
if (0 == softmx) {
78
softmx = max;
79
}
80
81
/* Calculation of free physical memory from existing function in mgmtosext.c*/
82
free = Java_com_ibm_lang_management_internal_ExtendedOperatingSystemMXBeanImpl_getFreePhysicalMemorySizeImpl(env, obj);
83
84
/* Calculation of total physical memory from port lib api */
85
tot = (jlong) j9sysinfo_get_physical_memory();
86
87
/* Calculation of system load average */
88
sysInfoResult = j9sysinfo_get_load_average(&loadData);
89
if (0 == sysInfoResult) {
90
sysLoadAvg = (jdouble) loadData.oneMinuteAverage;
91
}
92
93
/* Calculation of cpu time from existing function in mgmtosext.c*/
94
cpuTime = Java_com_ibm_lang_management_internal_ExtendedOperatingSystemMXBeanImpl_getProcessCpuTimeImpl(env, obj);
95
96
/* Set the statistics by calling the java setFields function */
97
setFieldsClass = (*env)->GetObjectClass(env, obj);
98
methodID = JCL_CACHE_GET(env, MID_com_ibm_jvm_Stats_setFields);
99
if (NULL == methodID) {
100
methodID = (*env)->GetMethodID(env, setFieldsClass, "setFields", "(JJJJJDJJ)V");
101
JCL_CACHE_SET(env, MID_com_ibm_jvm_Stats_setFields, methodID);
102
}
103
104
/* Call method only if there's no exception pending (prevent crash on C side) */
105
if (!((*env)->ExceptionCheck(env))) {
106
(*env)->CallVoidMethod(env, obj, methodID, committed, used, max, free, tot, sysLoadAvg, cpuTime, softmx);
107
}
108
}
109
110