Skip to content

Commit 3ec7213

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 9f007bd commit 3ec7213

File tree

14 files changed

+227
-4
lines changed

14 files changed

+227
-4
lines changed

make/modules/java.base/Lib.gmk

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#
2525

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

3030
include CopyFiles.gmk
@@ -80,6 +80,26 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBNIO, \
8080
NAME := nio, \
8181
OPTIMIZATION := HIGH, \
8282
WARNINGS_AS_ERRORS_xlc := false, \
83+
Net.c_CFLAGS := \
84+
-I$(OPENJ9OMR_TOPDIR)/include_core \
85+
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
86+
nio_util.c_CFLAGS := \
87+
-I$(OPENJ9_TOPDIR)/runtime/include \
88+
-I$(OPENJ9_TOPDIR)/runtime/oti \
89+
-I$(OPENJ9OMR_TOPDIR)/include_core \
90+
-I$(OPENJ9_VM_BUILD_DIR) \
91+
-I$(OPENJ9_TOPDIR)/runtime/jcl \
92+
-I$(OPENJ9_TOPDIR)/runtime/util \
93+
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
94+
SocketDispatcher.c_CFLAGS := \
95+
-I$(OPENJ9OMR_TOPDIR)/include_core \
96+
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
97+
UnixDispatcher.c_CFLAGS := \
98+
-I$(OPENJ9OMR_TOPDIR)/include_core \
99+
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
100+
UnixDomainSockets.c_CFLAGS := \
101+
-I$(OPENJ9OMR_TOPDIR)/include_core \
102+
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
83103
EXTRA_HEADER_DIRS := \
84104
libnio/ch \
85105
libnio/fs \

make/modules/java.base/lib/CoreLibraries.gmk

Lines changed: 26 additions & 0 deletions
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
################################################################################
2731
## Build libverify
2832
################################################################################
@@ -55,10 +59,32 @@ endif
5559
$(eval $(call SetupJdkLibrary, BUILD_LIBJAVA, \
5660
NAME := java, \
5761
OPTIMIZATION := HIGH, \
62+
check_version.c_CFLAGS := \
63+
-I$(OPENJ9_TOPDIR)/runtime/include \
64+
-I$(OPENJ9_TOPDIR)/runtime/oti \
65+
-I$(OPENJ9OMR_TOPDIR)/include_core \
66+
-I$(OPENJ9_VM_BUILD_DIR) \
67+
-I$(OPENJ9_TOPDIR)/runtime/jcl \
68+
-I$(OPENJ9_TOPDIR)/runtime/util \
69+
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
70+
io_util_md.c_CFLAGS := \
71+
-I$(OPENJ9OMR_TOPDIR)/include_core \
72+
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
5873
jdk_util.c_CFLAGS := $(VERSION_CFLAGS), \
5974
ProcessImpl_md.c_CFLAGS := $(VERSION_CFLAGS), \
6075
java_props_md.c_CFLAGS := \
6176
-DARCHPROPNAME='"$(OPENJDK_TARGET_CPU_OSARCH)"', \
77+
UnixFileSystem_md.c_CFLAGS := \
78+
-I$(OPENJ9OMR_TOPDIR)/include_core \
79+
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
80+
VM.c_CFLAGS := \
81+
-I$(OPENJ9_TOPDIR)/runtime/include \
82+
-I$(OPENJ9_TOPDIR)/runtime/oti \
83+
-I$(OPENJ9OMR_TOPDIR)/include_core \
84+
-I$(OPENJ9_VM_BUILD_DIR) \
85+
-I$(OPENJ9_TOPDIR)/runtime/jcl \
86+
-I$(OPENJ9_TOPDIR)/runtime/util \
87+
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
6288
WARNINGS_AS_ERRORS_xlc := false, \
6389
DISABLED_WARNINGS_gcc_ProcessImpl_md.c := unused-result, \
6490
DISABLED_WARNINGS_clang_TimeZone_md.c := unused-variable, \

src/java.base/share/native/libjava/VM.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,26 @@
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 "jni_util.h"
2834
#include "jvm.h"
2935
#include "jdk_util.h"
3036

3137
#include "jdk_internal_misc_VM.h"
3238

39+
#if defined(WIN32)
40+
#include "j9access.h"
41+
/* tracehelp.c defines getTraceInterfaceFromVM(), used by J9_UTINTERFACE_FROM_VM(). */
42+
#include "tracehelp.c"
43+
#include "ut_jcl_java.c"
44+
#endif /* defined(WIN32) */
45+
3346
/* Only register the performance-critical methods */
3447
static JNINativeMethod methods[] = {
3548
{"getNanoTimeAdjustment", "(J)J", (void *)&JVM_GetNanoTimeAdjustment}
@@ -42,6 +55,11 @@ Java_jdk_internal_misc_VM_latestUserDefinedLoader0(JNIEnv *env, jclass cls) {
4255

4356
JNIEXPORT void JNICALL
4457
Java_jdk_internal_misc_VM_initialize(JNIEnv *env, jclass cls) {
58+
#if defined(WIN32)
59+
/* Other platforms do this in check_version.c JNI_OnLoad. */
60+
UT_JCL_JAVA_MODULE_LOADED(J9_UTINTERFACE_FROM_VM(((J9VMThread *) env)->javaVM));
61+
#endif /* defined(WIN32) */
62+
4563
// Registers implementations of native methods described in methods[]
4664
// above.
4765
// In particular, registers JVM_GetNanoTimeAdjustment as the implementation

src/java.base/share/native/libjava/check_version.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,30 @@
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 "jni_util.h"
2834
#include "jvm.h"
2935

36+
#if !defined(WIN32)
37+
#include "j9access.h"
38+
/* tracehelp.c defines getTraceInterfaceFromVM(), used by J9_UTINTERFACE_FROM_VM(). */
39+
#include "tracehelp.c"
40+
#include "ut_jcl_java.c"
41+
#endif /* !defined(WIN32) */
42+
3043
JNIEXPORT jint JNICALL
3144
DEF_JNI_OnLoad(JavaVM *vm, void *reserved)
3245
{
46+
#if !defined(WIN32)
47+
/* Windows doesn't call JNI_OnLoad for libjava.dll, initialize the tracepoint elsewhere. */
48+
UT_JCL_JAVA_MODULE_LOADED(J9_UTINTERFACE_FROM_VM((J9JavaVM *)vm));
49+
#endif /* !defined(WIN32) */
50+
3351
return JNI_VERSION_1_2;
3452
}

src/java.base/share/native/libnio/nio_util.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,21 @@
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

36+
#include "j9access.h"
37+
/* tracehelp.c defines getTraceInterfaceFromVM(), used by J9_UTINTERFACE_FROM_VM(). */
38+
#include "tracehelp.c"
39+
#include "ut_jcl_nio.c"
40+
3041
JNIEXPORT jint JNICALL
3142
DEF_JNI_OnLoad(JavaVM *vm, void *reserved)
3243
{
@@ -36,5 +47,7 @@ DEF_JNI_OnLoad(JavaVM *vm, void *reserved)
3647
return JNI_EVERSION; /* JNI version not supported */
3748
}
3849

50+
UT_JCL_NIO_MODULE_LOADED(J9_UTINTERFACE_FROM_VM((J9JavaVM *)vm));
51+
3952
return JNI_VERSION_1_2;
4053
}

src/java.base/unix/native/libjava/UnixFileSystem_md.c

Lines changed: 9 additions & 0 deletions
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 <unistd.h>
2733
#include <assert.h>
2834
#include <sys/types.h>
@@ -51,6 +57,8 @@
5157
#include "java_io_FileSystem.h"
5258
#include "java_io_UnixFileSystem.h"
5359

60+
#include "ut_jcl_java.h"
61+
5462
#if defined(_AIX)
5563
#if !defined(NAME_MAX)
5664
#define NAME_MAX MAXNAMLEN
@@ -268,6 +276,7 @@ Java_java_io_UnixFileSystem_createFileExclusively0(JNIEnv *env, jclass cls,
268276
if (errno != EEXIST)
269277
JNU_ThrowIOExceptionWithLastError(env, "Could not open file");
270278
} else {
279+
Trc_io_UnixFileSystem_createFileExclusively_close(fd);
271280
if (close(fd) == -1)
272281
JNU_ThrowIOExceptionWithLastError(env, "Could not close file");
273282
rv = JNI_TRUE;

src/java.base/unix/native/libjava/io_util_md.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25+
26+
/*
27+
* ===========================================================================
28+
* (c) Copyright IBM Corp. 2025, 2025 All Rights Reserved
29+
* ===========================================================================
30+
*/
31+
2532
#include "jni.h"
2633
#include "jni_util.h"
2734
#include "jvm.h"
@@ -39,6 +46,8 @@
3946
#include <sys/stat.h>
4047
#endif
4148

49+
#include "ut_jcl_java.h"
50+
4251
#ifdef MACOSX
4352

4453
#include <CoreFoundation/CoreFoundation.h>
@@ -90,6 +99,11 @@ handleOpen(const char *path, int oflag, int mode) {
9099
fd = -1;
91100
}
92101
}
102+
if (-1 == fd) {
103+
Trc_io_handleOpen_err(path, oflag, mode, 0, 0, errno);
104+
} else {
105+
Trc_io_handleOpen(path, oflag, mode, 0, 0, (jlong)fd);
106+
}
93107
return fd;
94108
}
95109

@@ -167,6 +181,7 @@ fileDescriptorClose(JNIEnv *env, jobject this)
167181
dup2(devnull, fd);
168182
close(devnull);
169183
}
184+
Trc_io_fileDescriptorClose((jlong)fd);
170185
} else {
171186
int result;
172187
#if defined(_AIX)
@@ -176,7 +191,10 @@ fileDescriptorClose(JNIEnv *env, jobject this)
176191
result = close(fd);
177192
#endif
178193
if (result == -1 && errno != EINTR) {
194+
Trc_io_fileDescriptorClose_err((jlong)fd, errno);
179195
JNU_ThrowIOExceptionWithLastError(env, "close failed");
196+
} else {
197+
Trc_io_fileDescriptorClose((jlong)fd);
180198
}
181199
}
182200
}

src/java.base/unix/native/libnio/ch/Net.c

Lines changed: 20 additions & 1 deletion
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 <poll.h>
2733
#include <sys/ioctl.h>
2834
#include <sys/types.h>
@@ -31,6 +37,7 @@
3137
#include <netinet/in.h>
3238
#include <netinet/tcp.h>
3339
#include <limits.h>
40+
#include <arpa/inet.h>
3441

3542
#include "jni.h"
3643
#include "jni_util.h"
@@ -47,6 +54,8 @@
4754
#include <sys/utsname.h>
4855
#endif
4956

57+
#include "ut_jcl_nio.h"
58+
5059
/**
5160
* IP_MULTICAST_ALL supported since 2.6.31 but may not be available at
5261
* build time.
@@ -380,12 +389,22 @@ Java_sun_nio_ch_Net_connect0(JNIEnv *env, jclass clazz, jboolean preferIPv6,
380389
SOCKETADDRESS sa;
381390
int sa_len = 0;
382391
int rv;
392+
int fd;
383393

384394
if (NET_InetAddressToSockaddr(env, iao, port, &sa, &sa_len, preferIPv6) != 0) {
385395
return IOS_THROWN;
386396
}
387397

388-
rv = connect(fdval(env, fdo), &sa.sa, sa_len);
398+
fd = fdval(env, fdo);
399+
if (AF_INET == sa.sa4.sin_family) {
400+
char buf[INET_ADDRSTRLEN];
401+
Trc_nio_ch_Net_connect4((jlong)fd, inet_ntop(AF_INET, &sa.sa4.sin_addr, buf, sizeof(buf)), port, sa_len);
402+
} else if (AF_INET6 == sa.sa6.sin6_family) {
403+
char buf[INET6_ADDRSTRLEN];
404+
Trc_nio_ch_Net_connect6((jlong)fd, NULL /*inet_ntop(AF_INET6, &sa.sa6.sin6_addr, buf, sizeof(buf))*/, port, ntohl(sa.sa6.sin6_scope_id), sa_len);
405+
}
406+
407+
rv = connect(fd, &sa.sa, sa_len);
389408
if (rv != 0) {
390409
if (errno == EINPROGRESS) {
391410
return IOS_UNAVAILABLE;

src/java.base/unix/native/libnio/ch/UnixDispatcher.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,19 @@
2323
* questions.
2424
*/
2525

26+
/*
27+
* ===========================================================================
28+
* (c) Copyright IBM Corp. 2025, 2025 All Rights Reserved
29+
* ===========================================================================
30+
*/
31+
2632
#include "nio.h"
2733
#include "nio_util.h"
2834

2935
#include "sun_nio_ch_UnixDispatcher.h"
3036

37+
#include "ut_jcl_nio.h"
38+
3139
static int preCloseFD = -1; /* File descriptor to which we dup other fd's
3240
before closing them for real */
3341

@@ -55,6 +63,7 @@ JNIEXPORT void JNICALL
5563
Java_sun_nio_ch_UnixDispatcher_close0(JNIEnv *env, jclass clazz, jobject fdo)
5664
{
5765
jint fd = fdval(env, fdo);
66+
Trc_nio_ch_UnixDispatcher_close(fd);
5867
closeFileDescriptor(env, fd);
5968
}
6069

src/java.base/unix/native/libnio/ch/UnixDomainSockets.c

Lines changed: 13 additions & 1 deletion
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 <poll.h>
2733
#include <sys/types.h>
2834
#include <sys/socket.h>
@@ -41,6 +47,8 @@
4147
#include "nio_util.h"
4248
#include "nio.h"
4349

50+
#include "ut_jcl_nio.h"
51+
4452
/* Subtle platform differences in how unnamed sockets (empty path)
4553
* are returned from getsockname()
4654
*/
@@ -132,12 +140,16 @@ Java_sun_nio_ch_UnixDomainSockets_connect0(JNIEnv *env, jclass clazz, jobject fd
132140
struct sockaddr_un sa;
133141
int sa_len = 0;
134142
int rv;
143+
int fd;
135144

136145
if (unixSocketAddressToSockaddr(env, path, &sa, &sa_len) != 0) {
137146
return IOS_THROWN;
138147
}
139148

140-
rv = connect(fdval(env, fdo), (struct sockaddr *)&sa, sa_len);
149+
fd = fdval(env, fdo);
150+
Trc_nio_ch_UnixDomainSockets_connect(fd, sa.sun_path, sa_len);
151+
152+
rv = connect(fd, (struct sockaddr *)&sa, sa_len);
141153
if (rv != 0) {
142154
if (errno == EINPROGRESS) {
143155
return IOS_UNAVAILABLE;

0 commit comments

Comments
 (0)