Skip to content

Commit 765150f

Browse files
committed
Add selected tracepoints for OpenJ9 -Xtrace
Depends on eclipse-openj9/openj9#20936 Issue https://github.ibm.com/runtimes/semeru-requests/issues/46 Signed-off-by: Peter Shipton <[email protected]>
1 parent c979e50 commit 765150f

21 files changed

+365
-3
lines changed

closed/CopyToBuildJdk.gmk

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
# 2 along with this work; if not, see <http://www.gnu.org/licenses/>.
1919
# ===========================================================================
2020

21+
# ===========================================================================
22+
# (c) Copyright IBM Corp. 2025, 2025 All Rights Reserved
23+
# ===========================================================================
24+
2125
all :
2226

2327
.PHONY : all
@@ -201,6 +205,7 @@ endif # windows
201205
$(foreach file, \
202206
$(SRC_ROOT)/closed/classlib.properties \
203207
$(OPENJ9_VM_BUILD_DIR)/J9TraceFormat.dat \
208+
$(OPENJ9_VM_BUILD_DIR)/JCLTraceFormat.dat \
204209
$(OPENJ9_VM_BUILD_DIR)/OMRTraceFormat.dat, \
205210
$(call openj9_copy_files,, $(file) $(JDK_OUTPUTDIR)/lib/$(notdir $(file))))
206211

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* ===========================================================================
3+
* (c) Copyright IBM Corp. 2025, 2025 All Rights Reserved
4+
* ===========================================================================
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* IBM designates this particular file as subject to the "Classpath" exception
11+
* as provided by IBM in the LICENSE file that accompanied this code.
12+
*
13+
* This code is distributed in the hope that it will be useful, but WITHOUT
14+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16+
* version 2 for more details (a copy is included in the LICENSE file that
17+
* accompanied this code).
18+
*
19+
* You should have received a copy of the GNU General Public License version
20+
* 2 along with this work; if not, see <http://www.gnu.org/licenses/>.
21+
*
22+
* ===========================================================================
23+
*/
24+
25+
#include "jni.h"
26+
#include "jvm.h"
27+
28+
/* These definitions required by j9.h are in the OpenJ9 jni.h, but OpenJDK jni.h is used here. */
29+
struct GCStatus;
30+
typedef struct GCStatus GCStatus;
31+
struct JavaVMQuery;
32+
typedef struct JavaVMQuery JavaVMQuery;
33+
struct JVMExtensionInterface_;
34+
typedef const struct JVMExtensionInterface_ *JVMExt;
35+
36+
#define COPY_PROGRESS_INFO_MASK 0
37+
#if defined(WIN32)
38+
#define OMR_OS_WINDOWS
39+
#endif /* defined(WIN32) */
40+
41+
#include "j9.h"
42+
#include "tracehelp.c"
43+
#include "ut_jcl_nio.c"
44+
45+
JNIEXPORT jint JNICALL
46+
JNI_OnLoad(JavaVM *vm, void *reserved)
47+
{
48+
UT_JCL_NIO_MODULE_LOADED(J9_UTINTERFACE_FROM_VM((J9JavaVM *)vm));
49+
50+
return JNI_VERSION_1_2;
51+
}

jdk/make/lib/CoreLibraries.gmk

+16-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#
2525

2626
# ===========================================================================
27-
# (c) Copyright IBM Corp. 2023, 2023 All Rights Reserved
27+
# (c) Copyright IBM Corp. 2023, 2025 All Rights Reserved
2828
# ===========================================================================
2929

3030
# Include custom extensions if available.
@@ -152,6 +152,21 @@ LIBJAVA_SRC_DIRS += $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/java/l
152152
$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/common \
153153
$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/java/util
154154

155+
BUILD_LIBJAVA_check_version.c_CFLAGS := \
156+
-I$(OPENJ9_TOPDIR)/runtime/include \
157+
-I$(OPENJ9_TOPDIR)/runtime/oti \
158+
-I$(OPENJ9OMR_TOPDIR)/include_core \
159+
-I$(OUTPUT_ROOT)/vm/runtime \
160+
-I$(OPENJ9_TOPDIR)/runtime/jcl \
161+
-I$(OPENJ9_TOPDIR)/runtime/util \
162+
-I$(OUTPUT_ROOT)/vm/runtime/jcl
163+
BUILD_LIBJAVA_io_util_md.c_CFLAGS := \
164+
-I$(OPENJ9OMR_TOPDIR)/include_core \
165+
-I$(OUTPUT_ROOT)/vm/runtime/jcl
166+
BUILD_LIBJAVA_UnixFileSystem_md.c_CFLAGS := \
167+
-I$(OPENJ9OMR_TOPDIR)/include_core \
168+
-I$(OUTPUT_ROOT)/vm/runtime/jcl
169+
155170
ifeq ($(OPENJDK_TARGET_OS), windows)
156171
LIBJAVA_SRC_DIRS += $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/util/locale/provider
157172
else ifeq ($(OPENJDK_TARGET_OS), macosx)

jdk/make/lib/NetworkingLibraries.gmk

+25
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
# questions.
2424
#
2525

26+
# ===========================================================================
27+
# (c) Copyright IBM Corp. 2025, 2025 All Rights Reserved
28+
# ===========================================================================
29+
2630
LIBNET_SRC_DIRS := $(JDK_TOPDIR)/src/share/native/java/net \
2731
$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/java/net \
2832
$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/net/ \
@@ -37,6 +41,27 @@ endif
3741

3842
LIBNET_CFLAGS := $(foreach dir, $(LIBNET_SRC_DIRS), -I$(dir))
3943

44+
BUILD_LIBNET_DualStackPlainSocketImpl.c_CFLAGS := \
45+
-I$(OPENJ9OMR_TOPDIR)/include_core \
46+
-I$(OUTPUT_ROOT)/vm/runtime/jcl
47+
BUILD_LIBNET_linux_close.c_CFLAGS := \
48+
-I$(OPENJ9OMR_TOPDIR)/include_core \
49+
-I$(OUTPUT_ROOT)/vm/runtime/jcl
50+
BUILD_LIBNET_net_util.c_CFLAGS := \
51+
-I$(OPENJ9_TOPDIR)/runtime/include \
52+
-I$(OPENJ9_TOPDIR)/runtime/oti \
53+
-I$(OPENJ9OMR_TOPDIR)/include_core \
54+
-I$(OUTPUT_ROOT)/vm/runtime \
55+
-I$(OPENJ9_TOPDIR)/runtime/jcl \
56+
-I$(OPENJ9_TOPDIR)/runtime/util \
57+
-I$(OUTPUT_ROOT)/vm/runtime/jcl
58+
BUILD_LIBNET_PlainSocketImpl.c_CFLAGS := \
59+
-I$(OPENJ9OMR_TOPDIR)/include_core \
60+
-I$(OUTPUT_ROOT)/vm/runtime/jcl
61+
BUILD_LIBNET_TwoStacksPlainSocketImpl.c_CFLAGS := \
62+
-I$(OPENJ9OMR_TOPDIR)/include_core \
63+
-I$(OUTPUT_ROOT)/vm/runtime/jcl
64+
4065
LIBNET_EXCLUDE_FILES :=
4166
ifneq ($(OPENJDK_TARGET_OS), linux)
4267
LIBNET_EXCLUDE_FILES += linux_close.c

jdk/make/lib/NioLibraries.gmk

+24
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@
2323
# questions.
2424
#
2525

26+
# ===========================================================================
27+
# (c) Copyright IBM Corp. 2025, 2025 All Rights Reserved
28+
# ===========================================================================
29+
2630
BUILD_LIBNIO_SRC := \
2731
$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/java/nio \
32+
$(SRC_ROOT)/closed/adds/jdk/src/share/native/sun/nio/ch \
2833
$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/nio/ch \
2934
$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/nio/fs
3035

@@ -34,6 +39,24 @@ BUILD_LIBNIO_CFLAGS := \
3439
-I$(JDK_TOPDIR)/src/share/native/java/net \
3540
-I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/java/net
3641

42+
BUILD_LIBNIO_FileDispatcherImpl.c_CFLAGS := \
43+
-I$(OPENJ9OMR_TOPDIR)/include_core \
44+
-I$(OUTPUT_ROOT)/vm/runtime/jcl
45+
BUILD_LIBNIO_Net.c_CFLAGS := \
46+
-I$(OPENJ9OMR_TOPDIR)/include_core \
47+
-I$(OUTPUT_ROOT)/vm/runtime/jcl
48+
BUILD_LIBNIO_nio_util.c_CFLAGS := \
49+
-I$(OPENJ9_TOPDIR)/runtime/include \
50+
-I$(OPENJ9_TOPDIR)/runtime/oti \
51+
-I$(OPENJ9OMR_TOPDIR)/include_core \
52+
-I$(OUTPUT_ROOT)/vm/runtime \
53+
-I$(OPENJ9_TOPDIR)/runtime/jcl \
54+
-I$(OPENJ9_TOPDIR)/runtime/util \
55+
-I$(OUTPUT_ROOT)/vm/runtime/jcl
56+
BUILD_LIBNIO_SocketDispatcher.c_CFLAGS := \
57+
-I$(OPENJ9OMR_TOPDIR)/include_core \
58+
-I$(OUTPUT_ROOT)/vm/runtime/jcl
59+
3760
BUILD_LIBNIO_FILES := \
3861
DatagramChannelImpl.c \
3962
DatagramDispatcher.c \
@@ -43,6 +66,7 @@ BUILD_LIBNIO_FILES := \
4366
IOUtil.c \
4467
MappedByteBuffer.c \
4568
Net.c \
69+
nio_util.c \
4670
ServerSocketChannelImpl.c \
4771
SocketChannelImpl.c \
4872
SocketDispatcher.c

jdk/make/mapfiles/libnio/mapfile-linux

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
# questions.
2424
#
2525

26+
# ===========================================================================
27+
# (c) Copyright IBM Corp. 2025, 2025 All Rights Reserved
28+
# ===========================================================================
29+
2630
SUNWprivate_1.1 {
2731
global:
2832
Java_java_nio_MappedByteBuffer_force0;
@@ -203,6 +207,7 @@ SUNWprivate_1.1 {
203207
Java_sun_nio_fs_UnixNativeDispatcher_getpwnam0;
204208
Java_sun_nio_fs_UnixNativeDispatcher_getgrnam0;
205209
Java_sun_nio_fs_UnixCopyFile_transfer;
210+
JNI_OnLoad;
206211
handleSocketError;
207212

208213
local:

jdk/make/mapfiles/libnio/mapfile-macosx

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
# questions.
2424
#
2525

26+
# ===========================================================================
27+
# (c) Copyright IBM Corp. 2025, 2025 All Rights Reserved
28+
# ===========================================================================
29+
2630
SUNWprivate_1.1 {
2731
global:
2832
Java_java_nio_MappedByteBuffer_force0;
@@ -175,6 +179,7 @@ SUNWprivate_1.1 {
175179
Java_sun_nio_fs_UnixNativeDispatcher_getpwnam0;
176180
Java_sun_nio_fs_UnixNativeDispatcher_getgrnam0;
177181
Java_sun_nio_fs_UnixCopyFile_transfer;
182+
JNI_OnLoad;
178183
handleSocketError;
179184

180185
local:

jdk/src/share/native/common/check_version.c

+22-1
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,31 @@
2424
*/
2525
/*
2626
* ===========================================================================
27-
* (c) Copyright IBM Corp. 2024, 2024 All Rights Reserved
27+
* (c) Copyright IBM Corp. 2024, 2025 All Rights Reserved
2828
* ===========================================================================
2929
*/
3030

3131
#include "jni.h"
3232
#include "jvm.h"
3333

34+
/* These definitions required by j9.h are in the OpenJ9 jni.h, but OpenJDK jni.h is used here. */
35+
struct GCStatus;
36+
typedef struct GCStatus GCStatus;
37+
struct JavaVMQuery;
38+
typedef struct JavaVMQuery JavaVMQuery;
39+
struct JVMExtensionInterface_;
40+
typedef const struct JVMExtensionInterface_ *JVMExt;
41+
42+
#define COPY_PROGRESS_INFO_MASK 0
43+
#if defined(WIN32)
44+
#define OMR_OS_WINDOWS
45+
#endif /* defined(WIN32) */
46+
47+
#include "j9.h"
48+
#include "ut_jcl_java.h"
49+
#include "tracehelp.c"
50+
#include "ut_jcl_java.c"
51+
3452
JNIEXPORT jint JNICALL
3553
JNI_OnLoad(JavaVM *vm, void *reserved)
3654
{
@@ -45,5 +63,8 @@ JNI_OnLoad(JavaVM *vm, void *reserved)
4563
(*env)->FatalError(env, buf);
4664
}
4765
}
66+
67+
UT_JCL_JAVA_MODULE_LOADED(J9_UTINTERFACE_FROM_VM((J9JavaVM *)vm));
68+
4869
return JNI_VERSION_1_2;
4970
}

jdk/src/share/native/java/net/net_util.c

+26
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,34 @@
2323
* questions.
2424
*/
2525

26+
/*
27+
* ===========================================================================
28+
* (c) Copyright IBM Corp. 2025, 2025 All Rights Reserved
29+
* ===========================================================================
30+
*/
31+
2632
#include "jni.h"
2733
#include "jvm.h"
2834
#include "jni_util.h"
2935
#include "net_util.h"
3036

37+
/* These definitions required by j9.h are in the OpenJ9 jni.h, but OpenJDK jni.h is used here. */
38+
struct GCStatus;
39+
typedef struct GCStatus GCStatus;
40+
struct JavaVMQuery;
41+
typedef struct JavaVMQuery JavaVMQuery;
42+
struct JVMExtensionInterface_;
43+
typedef const struct JVMExtensionInterface_ *JVMExt;
44+
45+
#define COPY_PROGRESS_INFO_MASK 0
46+
#if defined(WIN32)
47+
#define OMR_OS_WINDOWS
48+
#endif /* defined(WIN32) */
49+
50+
#include "j9.h"
51+
#include "tracehelp.c"
52+
#include "ut_jcl_net.c"
53+
3154
int IPv6_supported() ;
3255

3356
static int IPv6_available;
@@ -53,6 +76,9 @@ JNI_OnLoad(JavaVM *vm, void *reserved)
5376
return JNI_VERSION_1_2;
5477
}
5578
}
79+
80+
UT_JCL_NET_MODULE_LOADED(J9_UTINTERFACE_FROM_VM((J9JavaVM *)vm));
81+
5682
iCls = (*env)->FindClass(env, "java/lang/Boolean");
5783
CHECK_NULL_RETURN(iCls, JNI_VERSION_1_2);
5884
mid = (*env)->GetStaticMethodID(env, iCls, "getBoolean", "(Ljava/lang/String;)Z");

jdk/src/solaris/native/java/io/UnixFileSystem_md.c

+9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
* questions.
2424
*/
2525

26+
/*
27+
* ===========================================================================
28+
* (c) Copyright IBM Corp. 2025, 2025 All Rights Reserved
29+
* ===========================================================================
30+
*/
31+
2632
#include <assert.h>
2733
#include <sys/types.h>
2834
#include <sys/time.h>
@@ -42,6 +48,8 @@
4248
#include "java_io_FileSystem.h"
4349
#include "java_io_UnixFileSystem.h"
4450

51+
#include "ut_jcl_java.h"
52+
4553
#if defined(_ALLBSD_SOURCE)
4654
#define dirent64 dirent
4755
#define readdir64_r readdir_r
@@ -255,6 +263,7 @@ Java_java_io_UnixFileSystem_createFileExclusively(JNIEnv *env, jclass cls,
255263
if (errno != EEXIST)
256264
JNU_ThrowIOExceptionWithLastError(env, path);
257265
} else {
266+
Trc_io_UnixFileSystem_createFileExclusively_close(fd);
258267
if (close(fd) == -1)
259268
JNU_ThrowIOExceptionWithLastError(env, path);
260269
rv = JNI_TRUE;

jdk/src/solaris/native/java/io/io_util_md.c

+17
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
* questions.
2424
*/
2525

26+
/*
27+
* ===========================================================================
28+
* (c) Copyright IBM Corp. 2025, 2025 All Rights Reserved
29+
* ===========================================================================
30+
*/
31+
2632
#if defined(__linux__)
2733
#define _FILE_OFFSET_BITS 64
2834
#endif
@@ -43,6 +49,8 @@
4349
#include <sys/ioctl.h>
4450
#endif
4551

52+
#include "ut_jcl_java.h"
53+
4654
#ifdef MACOSX
4755

4856
#include <CoreFoundation/CoreFoundation.h>
@@ -94,6 +102,11 @@ handleOpen(const char *path, int oflag, int mode) {
94102
fd = -1;
95103
}
96104
}
105+
if (-1 == fd) {
106+
Trc_io_handleOpen_err(path, oflag, mode, 0, 0, errno);
107+
} else {
108+
Trc_io_handleOpen(path, oflag, mode, 0, 0, (jlong)fd);
109+
}
97110
return fd;
98111
}
99112

@@ -148,8 +161,12 @@ fileClose(JNIEnv *env, jobject this, jfieldID fid)
148161
dup2(devnull, fd);
149162
close(devnull);
150163
}
164+
Trc_io_fileDescriptorClose((jlong)fd);
151165
} else if (close(fd) == -1) {
166+
Trc_io_fileDescriptorClose_err((jlong)fd, errno);
152167
JNU_ThrowIOExceptionWithLastError(env, "close failed");
168+
} else {
169+
Trc_io_fileDescriptorClose((jlong)fd);
153170
}
154171
}
155172

0 commit comments

Comments
 (0)