Skip to content

Commit 144fb66

Browse files
authored
Merge pull request #863 from pshipton/jcltracepoints
Add selected tracepoints for OpenJ9 -Xtrace
2 parents a754dbb + 3bdb859 commit 144fb66

File tree

18 files changed

+318
-2
lines changed

18 files changed

+318
-2
lines changed

make/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
WIN_VERIFY_LIB := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libverify/verify.lib
2731

2832
# Hook to include the corresponding custom file, if present.
@@ -102,8 +106,30 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBJAVA, \
102106
OPTIMIZATION := HIGH, \
103107
CFLAGS := $(CFLAGS_JDKLIB) \
104108
$(LIBJAVA_CFLAGS), \
109+
check_version.c_CFLAGS := \
110+
-I$(OPENJ9_TOPDIR)/runtime/include \
111+
-I$(OPENJ9_TOPDIR)/runtime/oti \
112+
-I$(OPENJ9OMR_TOPDIR)/include_core \
113+
-I$(OPENJ9_VM_BUILD_DIR) \
114+
-I$(OPENJ9_TOPDIR)/runtime/jcl \
115+
-I$(OPENJ9_TOPDIR)/runtime/util \
116+
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
117+
io_util_md.c_CFLAGS := \
118+
-I$(OPENJ9OMR_TOPDIR)/include_core \
119+
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
105120
System.c_CFLAGS := $(VERSION_CFLAGS), \
106121
jdk_util.c_CFLAGS := $(VERSION_CFLAGS), \
122+
UnixFileSystem_md.c_CFLAGS := \
123+
-I$(OPENJ9OMR_TOPDIR)/include_core \
124+
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
125+
VM.c_CFLAGS := \
126+
-I$(OPENJ9_TOPDIR)/runtime/include \
127+
-I$(OPENJ9_TOPDIR)/runtime/oti \
128+
-I$(OPENJ9OMR_TOPDIR)/include_core \
129+
-I$(OPENJ9_VM_BUILD_DIR) \
130+
-I$(OPENJ9_TOPDIR)/runtime/jcl \
131+
-I$(OPENJ9_TOPDIR)/runtime/util \
132+
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
107133
EXTRA_HEADER_DIRS := libfdlibm, \
108134
WARNINGS_AS_ERRORS_xlc := false, \
109135
DISABLED_WARNINGS_gcc := unused-result, \

make/lib/Lib-java.base.gmk

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

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

3030
include LibCommon.gmk
@@ -47,6 +47,29 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBNET, \
4747
NAME := net, \
4848
OPTIMIZATION := LOW, \
4949
CFLAGS := $(CFLAGS_JDKLIB), \
50+
aix_close.c_CFLAGS := \
51+
-I$(OPENJ9OMR_TOPDIR)/include_core \
52+
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
53+
bsd_close.c_CFLAGS := \
54+
-I$(OPENJ9OMR_TOPDIR)/include_core \
55+
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
56+
linux_close.c_CFLAGS := \
57+
-I$(OPENJ9OMR_TOPDIR)/include_core \
58+
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
59+
net_util.c_CFLAGS := \
60+
-I$(OPENJ9_TOPDIR)/runtime/include \
61+
-I$(OPENJ9_TOPDIR)/runtime/oti \
62+
-I$(OPENJ9OMR_TOPDIR)/include_core \
63+
-I$(OPENJ9_VM_BUILD_DIR) \
64+
-I$(OPENJ9_TOPDIR)/runtime/jcl \
65+
-I$(OPENJ9_TOPDIR)/runtime/util \
66+
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
67+
net_util_md.c_CFLAGS := \
68+
-I$(OPENJ9OMR_TOPDIR)/include_core \
69+
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
70+
PlainSocketImpl.c_CFLAGS := \
71+
-I$(OPENJ9OMR_TOPDIR)/include_core \
72+
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
5073
DISABLED_WARNINGS_gcc := format-nonliteral, \
5174
DISABLED_WARNINGS_clang := parentheses-equality constant-logical-operand, \
5275
DISABLED_WARNINGS_microsoft := 4244 4047 4133 4996, \
@@ -75,6 +98,23 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBNIO, \
7598
OPTIMIZATION := HIGH, \
7699
WARNINGS_AS_ERRORS_xlc := false, \
77100
CFLAGS := $(CFLAGS_JDKLIB), \
101+
FileDispatcherImpl.c_CFLAGS := \
102+
-I$(OPENJ9OMR_TOPDIR)/include_core \
103+
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
104+
Net.c_CFLAGS := \
105+
-I$(OPENJ9OMR_TOPDIR)/include_core \
106+
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
107+
nio_util.c_CFLAGS := \
108+
-I$(OPENJ9_TOPDIR)/runtime/include \
109+
-I$(OPENJ9_TOPDIR)/runtime/oti \
110+
-I$(OPENJ9OMR_TOPDIR)/include_core \
111+
-I$(OPENJ9_VM_BUILD_DIR) \
112+
-I$(OPENJ9_TOPDIR)/runtime/jcl \
113+
-I$(OPENJ9_TOPDIR)/runtime/util \
114+
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
115+
SocketDispatcher.c_CFLAGS := \
116+
-I$(OPENJ9OMR_TOPDIR)/include_core \
117+
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
78118
EXTRA_HEADER_DIRS := \
79119
libnio/ch \
80120
libnio/fs \

src/java.base/aix/native/libnet/aix_close.c

Lines changed: 20 additions & 0 deletions
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.
@@ -65,9 +71,12 @@
6571
#include <unistd.h>
6672
#include <errno.h>
6773
#include <poll.h>
74+
#include <arpa/inet.h>
6875
#include "jvm.h"
6976
#include "net_util.h"
7077

78+
#include "ut_jcl_net.h"
79+
7180
/*
7281
* Stack allocated by thread when doing blocking operation
7382
*/
@@ -382,6 +391,7 @@ int NET_Dup2(int fd, int fd2) {
382391
* preempted and the I/O system call will return -1/EBADF.
383392
*/
384393
int NET_SocketClose(int fd) {
394+
Trc_NET_SocketClose(fd);
385395
return closefd(-1, fd);
386396
}
387397

@@ -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

src/java.base/linux/native/libnet/linux_close.c

Lines changed: 19 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 <assert.h>
2733
#include <limits.h>
2834
#include <stdio.h>
@@ -37,9 +43,12 @@
3743
#include <unistd.h>
3844
#include <errno.h>
3945
#include <poll.h>
46+
#include <arpa/inet.h>
4047
#include "jvm.h"
4148
#include "net_util.h"
4249

50+
#include "ut_jcl_net.h"
51+
4352
/*
4453
* Stack allocated by thread when doing blocking operation
4554
*/
@@ -339,6 +348,7 @@ int NET_Dup2(int fd, int fd2) {
339348
* preempted and the I/O system call will return -1/EBADF.
340349
*/
341350
int NET_SocketClose(int fd) {
351+
Trc_NET_SocketClose(fd);
342352
return closefd(-1, fd);
343353
}
344354

@@ -392,6 +402,15 @@ int NET_Accept(int s, struct sockaddr *addr, socklen_t *addrlen) {
392402
}
393403

394404
int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
405+
if (AF_INET == addr->sa_family) {
406+
char buf[INET_ADDRSTRLEN];
407+
struct sockaddr_in *sa = (struct sockaddr_in *)addr;
408+
Trc_NET_Connect4(s, inet_ntop(AF_INET, &sa->sin_addr, buf, sizeof(buf)), ntohs(sa->sin_port), addrlen);
409+
} else if (AF_INET6 == addr->sa_family) {
410+
char buf[INET6_ADDRSTRLEN];
411+
struct sockaddr_in6 *sa = (struct sockaddr_in6 *)addr;
412+
Trc_NET_Connect6(s, inet_ntop(AF_INET6, &sa->sin6_addr, buf, sizeof(buf)), ntohs(sa->sin6_port), ntohl(sa->sin6_scope_id), addrlen);
413+
}
395414
BLOCKING_IO_RETURN_INT( s, connect(s, addr, addrlen), JNI_TRUE );
396415
}
397416

src/java.base/macosx/native/libnet/bsd_close.c

Lines changed: 19 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 <assert.h>
2733
#include <limits.h>
2834
#include <stdio.h>
@@ -39,9 +45,12 @@
3945
#include <unistd.h>
4046
#include <errno.h>
4147
#include <poll.h>
48+
#include <arpa/inet.h>
4249
#include "jvm.h"
4350
#include "net_util.h"
4451

52+
#include "ut_jcl_net.h"
53+
4554
/*
4655
* Stack allocated by thread when doing blocking operation
4756
*/
@@ -343,6 +352,7 @@ int NET_Dup2(int fd, int fd2) {
343352
* preempted and the I/O system call will return -1/EBADF.
344353
*/
345354
int NET_SocketClose(int fd) {
355+
Trc_NET_SocketClose(fd);
346356
return closefd(-1, fd);
347357
}
348358

@@ -396,6 +406,15 @@ int NET_Accept(int s, struct sockaddr *addr, socklen_t *addrlen) {
396406
}
397407

398408
int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
409+
if (AF_INET == addr->sa_family) {
410+
char buf[INET_ADDRSTRLEN];
411+
struct sockaddr_in *sa = (struct sockaddr_in *)addr;
412+
Trc_NET_Connect4(s, inet_ntop(AF_INET, &sa->sin_addr, buf, sizeof(buf)), ntohs(sa->sin_port), addrlen);
413+
} else if (AF_INET6 == addr->sa_family) {
414+
char buf[INET6_ADDRSTRLEN];
415+
struct sockaddr_in6 *sa = (struct sockaddr_in6 *)addr;
416+
Trc_NET_Connect6(s, inet_ntop(AF_INET6, &sa->sin6_addr, buf, sizeof(buf)), ntohs(sa->sin6_port), ntohl(sa->sin6_scope_id), addrlen);
417+
}
399418
BLOCKING_IO_RETURN_INT( s, connect(s, addr, addrlen), JNI_TRUE );
400419
}
401420

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
if (!JDK_InitJvmHandle()) {
4664
JNU_ThrowInternalError(env, "Handle for JVM not found for symbol lookup");
4765
return;

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,31 @@
2828
* ===========================================================================
2929
*/
3030

31+
/*
32+
* ===========================================================================
33+
* (c) Copyright IBM Corp. 2025, 2025 All Rights Reserved
34+
* ===========================================================================
35+
*/
36+
3137
#include "jni.h"
3238
#include "jni_util.h"
3339
#include "jvm.h"
3440

41+
#if !defined(WIN32)
42+
#include "j9access.h"
43+
/* tracehelp.c defines getTraceInterfaceFromVM(), used by J9_UTINTERFACE_FROM_VM(). */
44+
#include "tracehelp.c"
45+
#include "ut_jcl_java.c"
46+
#endif /* !defined(WIN32) */
47+
3548
JNIEXPORT jint JNICALL
3649
DEF_JNI_OnLoad(JavaVM *vm, void *reserved)
3750
{
51+
#if !defined(WIN32)
52+
/* Windows doesn't call JNI_OnLoad for libjava.dll, initialize the tracepoint elsewhere. */
53+
UT_JCL_JAVA_MODULE_LOADED(J9_UTINTERFACE_FROM_VM((J9JavaVM *)vm));
54+
#endif /* !defined(WIN32) */
55+
3856
jint vm_version = JVM_GetInterfaceVersion();
3957
if (vm_version != JVM_INTERFACE_VERSION) {
4058
JNIEnv *env;

src/java.base/share/native/libnet/net_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 "net_util.h"
2733

2834
#include "java_net_InetAddress.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_net.c"
40+
3041
int IPv6_supported();
3142
int reuseport_supported();
3243

@@ -55,6 +66,8 @@ DEF_JNI_OnLoad(JavaVM *vm, void *reserved)
5566
return JNI_EVERSION; /* JNI version not supported */
5667
}
5768

69+
UT_JCL_NET_MODULE_LOADED(J9_UTINTERFACE_FROM_VM((J9JavaVM *)vm));
70+
5871
iCls = (*env)->FindClass(env, "java/lang/Boolean");
5972
CHECK_NULL_RETURN(iCls, JNI_VERSION_1_2);
6073
mid = (*env)->GetStaticMethodID(env, iCls, "getBoolean", "(Ljava/lang/String;)Z");

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
}

0 commit comments

Comments
 (0)