Skip to content

Commit a3a0974

Browse files
authored
Merge pull request #19917 from thallium/jfr-cpp-flag
Add triggerExecutionSample native
2 parents bd018c0 + 3f48ea9 commit a3a0974

File tree

17 files changed

+2490
-15
lines changed

17 files changed

+2490
-15
lines changed

.gitattributes

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
2020

2121
# Binary files
22-
*.jpg git-encoding=BINARY working-tree-encoding=BINARY
23-
*.png git-encoding=BINARY working-tree-encoding=BINARY
24-
*.gif git-encoding=BINARY working-tree-encoding=BINARY
25-
*.zip git-encoding=BINARY working-tree-encoding=BINARY
22+
*.blob binary
23+
*.gif binary
24+
*.jpg binary
25+
*.png binary
26+
*.zip binary

jcl/jpp_configuration.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<!-- START SET DEFINITIONS -->
3838
<set
3939
label="newflags"
40-
flags="CRAC_SUPPORT,CRIU_SUPPORT,INLINE-TYPES,OPENJCEPLUS_SUPPORT,OPENJDK_METHODHANDLES"/>
40+
flags="CRAC_SUPPORT,CRIU_SUPPORT,INLINE-TYPES,JFR_SUPPORT,OPENJCEPLUS_SUPPORT,OPENJDK_METHODHANDLES"/>
4141

4242
<set
4343
label="oldflags"

jcl/src/java.base/share/classes/com/ibm/oti/vm/VM.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,4 +637,11 @@ public static ConstantPool getConstantPoolFromAnnotationBytes(Class<?> clazz, by
637637
public static Properties internalGetProperties() {
638638
return getVMLangAccess().internalGetProperties();
639639
}
640+
641+
/*[IF JFR_SUPPORT]*/
642+
/**
643+
* Trigger ExecutionSample JFR event on all Java threads.
644+
*/
645+
public static native void triggerExecutionSample();
646+
/*[ENDIF] JFR_SUPPORT */
640647
}

jcl/src/java.base/share/classes/java/lang/System.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,10 @@ private static void ensureProperties(boolean isInitialization) {
718718
/*[ENDIF] CRAC_SUPPORT */
719719
/*[ENDIF] CRIU_SUPPORT */
720720

721+
/*[IF JFR_SUPPORT]*/
722+
initializedProperties.put("org.eclipse.openj9.jfr.isJFREnabled", "true"); //$NON-NLS-1$ //$NON-NLS-2$
723+
/*[ENDIF] JFR_SUPPORT */
724+
721725
String[] list = getPropertyList();
722726
for (int i = 0; i < list.length; i += 2) {
723727
String key = list[i];

runtime/jcl/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ target_sources(jclse
113113
${CMAKE_CURRENT_SOURCE_DIR}/common/bpinit.c
114114
${CMAKE_CURRENT_SOURCE_DIR}/common/clsldr.cpp
115115
${CMAKE_CURRENT_SOURCE_DIR}/common/com_ibm_jvm_Stats.c
116-
${CMAKE_CURRENT_SOURCE_DIR}/common/com_ibm_oti_vm_VM.c
116+
${CMAKE_CURRENT_SOURCE_DIR}/common/com_ibm_oti_vm_VM.cpp
117117
${CMAKE_CURRENT_SOURCE_DIR}/common/compiler.c
118118
${CMAKE_CURRENT_SOURCE_DIR}/common/dump.c
119119
${CMAKE_CURRENT_SOURCE_DIR}/common/exhelp.c

runtime/jcl/common/com_ibm_oti_vm_VM.c renamed to runtime/jcl/common/com_ibm_oti_vm_VM.cpp

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@
2121
*******************************************************************************/
2222

2323
#include <string.h>
24-
#include "jni.h"
2524
#include "jcl.h"
2625
#include "jclglob.h"
2726
#include "jclprots.h"
28-
#include "jcl_internal.h"
27+
#include "jni.h"
28+
#include "omrlinkedlist.h"
2929
#include "util_api.h"
30+
#include "VMHelpers.hpp"
3031

31-
/* private static native byte[][] getVMArgsImpl(); */
32+
extern "C" {
3233

34+
/* private static native byte[][] getVMArgsImpl(); */
3335
jobjectArray JNICALL
3436
Java_com_ibm_oti_vm_VM_getVMArgsImpl(JNIEnv *env, jobject recv)
3537
{
@@ -53,9 +55,9 @@ Java_com_ibm_oti_vm_VM_getVMArgsImpl(JNIEnv *env, jobject recv)
5355

5456
/* Create the result array and fill it in, including only options that begin with "-" */
5557

56-
byteArrayClass = (*env)->FindClass(env, "[B");
58+
byteArrayClass = env->FindClass("[B");
5759
if (NULL != byteArrayClass) {
58-
result = (*env)->NewObjectArray(env, resultSize, byteArrayClass, NULL);
60+
result = env->NewObjectArray(resultSize, byteArrayClass, NULL);
5961
if (NULL != result) {
6062
jint writeIndex = 0;
6163

@@ -64,15 +66,15 @@ Java_com_ibm_oti_vm_VM_getVMArgsImpl(JNIEnv *env, jobject recv)
6466

6567
if ('-' == optionString[0]) {
6668
jint optionLength = (jint) strlen(optionString);
67-
jbyteArray option = (*env)->NewByteArray(env, optionLength);
69+
jbyteArray option = env->NewByteArray(optionLength);
6870

6971
if (NULL == option) {
7072
/* Don't use break here to avoid triggering the assertion below */
7173
return NULL;
7274
}
73-
(*env)->SetByteArrayRegion(env, option, 0, optionLength, (jbyte*)optionString);
74-
(*env)->SetObjectArrayElement(env, result, writeIndex, option);
75-
(*env)->DeleteLocalRef(env, option);
75+
env->SetByteArrayRegion(option, 0, optionLength, (jbyte*)optionString);
76+
env->SetObjectArrayElement(result, writeIndex, option);
77+
env->DeleteLocalRef(option);
7678
writeIndex += 1;
7779
}
7880
}
@@ -190,3 +192,30 @@ Java_com_ibm_oti_vm_VM_isJVMInSingleThreadedMode(JNIEnv *env, jclass unused)
190192
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */
191193
return result;
192194
}
195+
196+
#if defined(J9VM_OPT_JFR)
197+
void JNICALL
198+
Java_com_ibm_oti_vm_VM_triggerExecutionSample(JNIEnv *env, jclass unused) {
199+
J9VMThread *currentThread = (J9VMThread *)env;
200+
J9JavaVM *vm = currentThread->javaVM;
201+
J9InternalVMFunctions *vmFuncs = vm->internalVMFunctions;
202+
203+
vmFuncs->internalEnterVMFromJNI(currentThread);
204+
vmFuncs->acquireExclusiveVMAccess(currentThread);
205+
206+
J9VMThread *walkThread = J9_LINKED_LIST_START_DO(vm->mainThread);
207+
while (NULL != walkThread) {
208+
if (VM_VMHelpers::threadCanRunJavaCode(walkThread)
209+
&& (currentThread != walkThread)
210+
) {
211+
vmFuncs->jfrExecutionSample(currentThread, walkThread);
212+
}
213+
walkThread = J9_LINKED_LIST_NEXT_DO(vm->mainThread, walkThread);
214+
}
215+
216+
vmFuncs->releaseExclusiveVMAccess(currentThread);
217+
vmFuncs->internalExitVMToJNI(currentThread);
218+
}
219+
#endif /* defined(J9VM_OPT_JFR) */
220+
221+
} /* extern "C" */

runtime/jcl/exports.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,12 @@ if(J9VM_OPT_CRIU_SUPPORT)
687687
endif()
688688
endif()
689689

690+
if(J9VM_OPT_JFR)
691+
omr_add_exports(jclse
692+
Java_com_ibm_oti_vm_VM_triggerExecutionSample
693+
)
694+
endif()
695+
690696
# Java 19 only
691697
if(JAVA_SPEC_VERSION EQUAL 19)
692698
omr_add_exports(jclse

runtime/jcl/module.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-ex
4444
<xi:include href="uma/se19only_exports.xml"></xi:include>
4545
<xi:include href="uma/se19_exports.xml"></xi:include>
4646
<xi:include href="uma/se20_exports.xml"></xi:include>
47+
<xi:include href="uma/jfr_exports.xml"></xi:include>
4748

4849
<xi:include href="uma/vendor_jcl_exports.xml">
4950
<xi:fallback/>
@@ -140,6 +141,9 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-ex
140141
<group name="se20">
141142
<include-if condition="spec.java20"/>
142143
</group>
144+
<group name="jfr">
145+
<include-if condition="spec.flags.opt_jfr"/>
146+
</group>
143147
</exports>
144148

145149
<includes>

runtime/jcl/uma/jfr_exports.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!--
2+
Copyright IBM Corp. and others 2024
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] https://openjdk.org/legal/assembly-exception.html
19+
20+
SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
21+
-->
22+
<exports group="jfr">
23+
<export name="Java_com_ibm_oti_vm_VM_triggerExecutionSample" />
24+
</exports>

runtime/oti/j9nonbuilder.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5188,6 +5188,9 @@ typedef struct J9InternalVMFunctions {
51885188
#if defined(J9VM_ZOS_3164_INTEROPERABILITY) && (JAVA_SPEC_VERSION >= 17)
51895189
I_32 (*invoke31BitJNI_OnXLoad)(struct J9JavaVM *vm, void *handle, jboolean isOnLoad, void *reserved);
51905190
#endif /* defined(J9VM_ZOS_3164_INTEROPERABILITY) && (JAVA_SPEC_VERSION >= 17) */
5191+
#if defined(J9VM_OPT_JFR)
5192+
void (*jfrExecutionSample)(struct J9VMThread *currentThread, struct J9VMThread *sampleThread);
5193+
#endif /* defined(J9VM_OPT_JFR) */
51915194
} J9InternalVMFunctions;
51925195

51935196
/* Jazz 99339: define a new structure to replace JavaVM so as to pass J9NativeLibrary to JVMTIEnv */

0 commit comments

Comments
 (0)