Skip to content

Commit aa11d15

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 aa11d15

23 files changed

+373
-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,39 @@
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+
#include "includej9h.h"
29+
/* tracehelp.c defines getTraceInterfaceFromVM(), used by J9_UTINTERFACE_FROM_VM(). */
30+
#include "tracehelp.c"
31+
#include "ut_jcl_nio.c"
32+
33+
JNIEXPORT jint JNICALL
34+
JNI_OnLoad(JavaVM *vm, void *reserved)
35+
{
36+
UT_JCL_NIO_MODULE_LOADED(J9_UTINTERFACE_FROM_VM((J9JavaVM *)vm));
37+
38+
return JNI_VERSION_1_2;
39+
}

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

+31
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,33 @@ endif
3741

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

44+
BUILD_LIBNET_aix_close.c_CFLAGS := \
45+
-I$(OPENJ9OMR_TOPDIR)/include_core \
46+
-I$(OUTPUT_ROOT)/vm/runtime/jcl
47+
BUILD_LIBNET_bsd_close.c_CFLAGS := \
48+
-I$(OPENJ9OMR_TOPDIR)/include_core \
49+
-I$(OUTPUT_ROOT)/vm/runtime/jcl
50+
BUILD_LIBNET_DualStackPlainSocketImpl.c_CFLAGS := \
51+
-I$(OPENJ9OMR_TOPDIR)/include_core \
52+
-I$(OUTPUT_ROOT)/vm/runtime/jcl
53+
BUILD_LIBNET_linux_close.c_CFLAGS := \
54+
-I$(OPENJ9OMR_TOPDIR)/include_core \
55+
-I$(OUTPUT_ROOT)/vm/runtime/jcl
56+
BUILD_LIBNET_net_util.c_CFLAGS := \
57+
-I$(OPENJ9_TOPDIR)/runtime/include \
58+
-I$(OPENJ9_TOPDIR)/runtime/oti \
59+
-I$(OPENJ9OMR_TOPDIR)/include_core \
60+
-I$(OUTPUT_ROOT)/vm/runtime \
61+
-I$(OPENJ9_TOPDIR)/runtime/jcl \
62+
-I$(OPENJ9_TOPDIR)/runtime/util \
63+
-I$(OUTPUT_ROOT)/vm/runtime/jcl
64+
BUILD_LIBNET_PlainSocketImpl.c_CFLAGS := \
65+
-I$(OPENJ9OMR_TOPDIR)/include_core \
66+
-I$(OUTPUT_ROOT)/vm/runtime/jcl
67+
BUILD_LIBNET_TwoStacksPlainSocketImpl.c_CFLAGS := \
68+
-I$(OPENJ9OMR_TOPDIR)/include_core \
69+
-I$(OUTPUT_ROOT)/vm/runtime/jcl
70+
4071
LIBNET_EXCLUDE_FILES :=
4172
ifneq ($(OPENJDK_TARGET_OS), linux)
4273
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/aix/native/java/net/aix_close.c

+20
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
* questions.
2525
*/
2626

27+
/*
28+
* ===========================================================================
29+
* (c) Copyright IBM Corp. 2025, 2025 All Rights Reserved
30+
* ===========================================================================
31+
*/
32+
2733
/*
2834
* This file contains implementations of NET_... functions. The NET_.. functions are
2935
* wrappers for common file- and socket functions plus provisions for non-blocking IO.
@@ -55,6 +61,9 @@
5561
#include <errno.h>
5662

5763
#include <sys/poll.h>
64+
#include <arpa/inet.h>
65+
66+
#include "ut_jcl_net.h"
5867

5968
/*
6069
* Stack allocated by thread when doing blocking operation
@@ -370,6 +379,7 @@ int NET_Dup2(int fd, int fd2) {
370379
* preempted and the I/O system call will return -1/EBADF.
371380
*/
372381
int NET_SocketClose(int fd) {
382+
Trc_NET_SocketClose(fd);
373383
return closefd(-1, fd);
374384
}
375385

@@ -444,6 +454,16 @@ int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
444454
return -1;
445455
}
446456

457+
if (AF_INET == addr->sa_family) {
458+
char buf[INET_ADDRSTRLEN];
459+
struct sockaddr_in *sa = (struct sockaddr_in *)addr;
460+
Trc_NET_Connect4(s, inet_ntop(AF_INET, &sa->sin_addr, buf, sizeof(buf)), ntohs(sa->sin_port), addrlen);
461+
} else if (AF_INET6 == addr->sa_family) {
462+
char buf[INET6_ADDRSTRLEN];
463+
struct sockaddr_in6 *sa = (struct sockaddr_in6 *)addr;
464+
Trc_NET_Connect6(s, inet_ntop(AF_INET6, &sa->sin6_addr, buf, sizeof(buf)), ntohs(sa->sin6_port), ntohl(sa->sin6_scope_id), addrlen);
465+
}
466+
447467
/* On AIX, when the system call connect() is interrupted, the connection
448468
* is not aborted and it will be established asynchronously by the kernel.
449469
* Hence, no need to restart connect() when EINTR is received

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,18 @@
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+
#include "includej9h.h"
35+
/* tracehelp.c defines getTraceInterfaceFromVM(), used by J9_UTINTERFACE_FROM_VM(). */
36+
#include "tracehelp.c"
37+
#include "ut_jcl_java.c"
38+
3439
JNIEXPORT jint JNICALL
3540
JNI_OnLoad(JavaVM *vm, void *reserved)
3641
{
@@ -45,5 +50,8 @@ JNI_OnLoad(JavaVM *vm, void *reserved)
4550
(*env)->FatalError(env, buf);
4651
}
4752
}
53+
54+
UT_JCL_JAVA_MODULE_LOADED(J9_UTINTERFACE_FROM_VM((J9JavaVM *)vm));
55+
4856
return JNI_VERSION_1_2;
4957
}

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

+14
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,22 @@
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+
#include "includej9h.h"
38+
/* tracehelp.c defines getTraceInterfaceFromVM(), used by J9_UTINTERFACE_FROM_VM(). */
39+
#include "tracehelp.c"
40+
#include "ut_jcl_net.c"
41+
3142
int IPv6_supported() ;
3243

3344
static int IPv6_available;
@@ -53,6 +64,9 @@ JNI_OnLoad(JavaVM *vm, void *reserved)
5364
return JNI_VERSION_1_2;
5465
}
5566
}
67+
68+
UT_JCL_NET_MODULE_LOADED(J9_UTINTERFACE_FROM_VM((J9JavaVM *)vm));
69+
5670
iCls = (*env)->FindClass(env, "java/lang/Boolean");
5771
CHECK_NULL_RETURN(iCls, JNI_VERSION_1_2);
5872
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;

0 commit comments

Comments
 (0)