Skip to content

Commit

Permalink
Merge pull request #863 from pshipton/jcltracepoints
Browse files Browse the repository at this point in the history
Add selected tracepoints for OpenJ9 -Xtrace
  • Loading branch information
keithc-ca authored Feb 11, 2025
2 parents a754dbb + 3bdb859 commit 144fb66
Show file tree
Hide file tree
Showing 18 changed files with 318 additions and 2 deletions.
26 changes: 26 additions & 0 deletions make/lib/CoreLibraries.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
# questions.
#

# ===========================================================================
# (c) Copyright IBM Corp. 2025, 2025 All Rights Reserved
# ===========================================================================

WIN_VERIFY_LIB := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libverify/verify.lib

# Hook to include the corresponding custom file, if present.
Expand Down Expand Up @@ -102,8 +106,30 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBJAVA, \
OPTIMIZATION := HIGH, \
CFLAGS := $(CFLAGS_JDKLIB) \
$(LIBJAVA_CFLAGS), \
check_version.c_CFLAGS := \
-I$(OPENJ9_TOPDIR)/runtime/include \
-I$(OPENJ9_TOPDIR)/runtime/oti \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR) \
-I$(OPENJ9_TOPDIR)/runtime/jcl \
-I$(OPENJ9_TOPDIR)/runtime/util \
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
io_util_md.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
System.c_CFLAGS := $(VERSION_CFLAGS), \
jdk_util.c_CFLAGS := $(VERSION_CFLAGS), \
UnixFileSystem_md.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
VM.c_CFLAGS := \
-I$(OPENJ9_TOPDIR)/runtime/include \
-I$(OPENJ9_TOPDIR)/runtime/oti \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR) \
-I$(OPENJ9_TOPDIR)/runtime/jcl \
-I$(OPENJ9_TOPDIR)/runtime/util \
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
EXTRA_HEADER_DIRS := libfdlibm, \
WARNINGS_AS_ERRORS_xlc := false, \
DISABLED_WARNINGS_gcc := unused-result, \
Expand Down
42 changes: 41 additions & 1 deletion make/lib/Lib-java.base.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#

# ===========================================================================
# (c) Copyright IBM Corp. 2018, 2023 All Rights Reserved
# (c) Copyright IBM Corp. 2018, 2025 All Rights Reserved
# ===========================================================================

include LibCommon.gmk
Expand All @@ -47,6 +47,29 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBNET, \
NAME := net, \
OPTIMIZATION := LOW, \
CFLAGS := $(CFLAGS_JDKLIB), \
aix_close.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
bsd_close.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
linux_close.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
net_util.c_CFLAGS := \
-I$(OPENJ9_TOPDIR)/runtime/include \
-I$(OPENJ9_TOPDIR)/runtime/oti \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR) \
-I$(OPENJ9_TOPDIR)/runtime/jcl \
-I$(OPENJ9_TOPDIR)/runtime/util \
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
net_util_md.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
PlainSocketImpl.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
DISABLED_WARNINGS_gcc := format-nonliteral, \
DISABLED_WARNINGS_clang := parentheses-equality constant-logical-operand, \
DISABLED_WARNINGS_microsoft := 4244 4047 4133 4996, \
Expand Down Expand Up @@ -75,6 +98,23 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBNIO, \
OPTIMIZATION := HIGH, \
WARNINGS_AS_ERRORS_xlc := false, \
CFLAGS := $(CFLAGS_JDKLIB), \
FileDispatcherImpl.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
Net.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
nio_util.c_CFLAGS := \
-I$(OPENJ9_TOPDIR)/runtime/include \
-I$(OPENJ9_TOPDIR)/runtime/oti \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR) \
-I$(OPENJ9_TOPDIR)/runtime/jcl \
-I$(OPENJ9_TOPDIR)/runtime/util \
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
SocketDispatcher.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
EXTRA_HEADER_DIRS := \
libnio/ch \
libnio/fs \
Expand Down
20 changes: 20 additions & 0 deletions src/java.base/aix/native/libnet/aix_close.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
* questions.
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2025, 2025 All Rights Reserved
* ===========================================================================
*/

/*
* This file contains implementations of NET_... functions. The NET_.. functions are
* wrappers for common file- and socket functions plus provisions for non-blocking IO.
Expand Down Expand Up @@ -65,9 +71,12 @@
#include <unistd.h>
#include <errno.h>
#include <poll.h>
#include <arpa/inet.h>
#include "jvm.h"
#include "net_util.h"

#include "ut_jcl_net.h"

/*
* Stack allocated by thread when doing blocking operation
*/
Expand Down Expand Up @@ -382,6 +391,7 @@ int NET_Dup2(int fd, int fd2) {
* preempted and the I/O system call will return -1/EBADF.
*/
int NET_SocketClose(int fd) {
Trc_NET_SocketClose(fd);
return closefd(-1, fd);
}

Expand Down Expand Up @@ -444,6 +454,16 @@ int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
return -1;
}

if (AF_INET == addr->sa_family) {
char buf[INET_ADDRSTRLEN];
struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Trc_NET_Connect4(s, inet_ntop(AF_INET, &sa->sin_addr, buf, sizeof(buf)), ntohs(sa->sin_port), addrlen);
} else if (AF_INET6 == addr->sa_family) {
char buf[INET6_ADDRSTRLEN];
struct sockaddr_in6 *sa = (struct sockaddr_in6 *)addr;
Trc_NET_Connect6(s, inet_ntop(AF_INET6, &sa->sin6_addr, buf, sizeof(buf)), ntohs(sa->sin6_port), ntohl(sa->sin6_scope_id), addrlen);
}

/* On AIX, when the system call connect() is interrupted, the connection
* is not aborted and it will be established asynchronously by the kernel.
* Hence, no need to restart connect() when EINTR is received
Expand Down
19 changes: 19 additions & 0 deletions src/java.base/linux/native/libnet/linux_close.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
* questions.
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2025, 2025 All Rights Reserved
* ===========================================================================
*/

#include <assert.h>
#include <limits.h>
#include <stdio.h>
Expand All @@ -37,9 +43,12 @@
#include <unistd.h>
#include <errno.h>
#include <poll.h>
#include <arpa/inet.h>
#include "jvm.h"
#include "net_util.h"

#include "ut_jcl_net.h"

/*
* Stack allocated by thread when doing blocking operation
*/
Expand Down Expand Up @@ -339,6 +348,7 @@ int NET_Dup2(int fd, int fd2) {
* preempted and the I/O system call will return -1/EBADF.
*/
int NET_SocketClose(int fd) {
Trc_NET_SocketClose(fd);
return closefd(-1, fd);
}

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

int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
if (AF_INET == addr->sa_family) {
char buf[INET_ADDRSTRLEN];
struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Trc_NET_Connect4(s, inet_ntop(AF_INET, &sa->sin_addr, buf, sizeof(buf)), ntohs(sa->sin_port), addrlen);
} else if (AF_INET6 == addr->sa_family) {
char buf[INET6_ADDRSTRLEN];
struct sockaddr_in6 *sa = (struct sockaddr_in6 *)addr;
Trc_NET_Connect6(s, inet_ntop(AF_INET6, &sa->sin6_addr, buf, sizeof(buf)), ntohs(sa->sin6_port), ntohl(sa->sin6_scope_id), addrlen);
}
BLOCKING_IO_RETURN_INT( s, connect(s, addr, addrlen), JNI_TRUE );
}

Expand Down
19 changes: 19 additions & 0 deletions src/java.base/macosx/native/libnet/bsd_close.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
* questions.
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2025, 2025 All Rights Reserved
* ===========================================================================
*/

#include <assert.h>
#include <limits.h>
#include <stdio.h>
Expand All @@ -39,9 +45,12 @@
#include <unistd.h>
#include <errno.h>
#include <poll.h>
#include <arpa/inet.h>
#include "jvm.h"
#include "net_util.h"

#include "ut_jcl_net.h"

/*
* Stack allocated by thread when doing blocking operation
*/
Expand Down Expand Up @@ -343,6 +352,7 @@ int NET_Dup2(int fd, int fd2) {
* preempted and the I/O system call will return -1/EBADF.
*/
int NET_SocketClose(int fd) {
Trc_NET_SocketClose(fd);
return closefd(-1, fd);
}

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

int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
if (AF_INET == addr->sa_family) {
char buf[INET_ADDRSTRLEN];
struct sockaddr_in *sa = (struct sockaddr_in *)addr;
Trc_NET_Connect4(s, inet_ntop(AF_INET, &sa->sin_addr, buf, sizeof(buf)), ntohs(sa->sin_port), addrlen);
} else if (AF_INET6 == addr->sa_family) {
char buf[INET6_ADDRSTRLEN];
struct sockaddr_in6 *sa = (struct sockaddr_in6 *)addr;
Trc_NET_Connect6(s, inet_ntop(AF_INET6, &sa->sin6_addr, buf, sizeof(buf)), ntohs(sa->sin6_port), ntohl(sa->sin6_scope_id), addrlen);
}
BLOCKING_IO_RETURN_INT( s, connect(s, addr, addrlen), JNI_TRUE );
}

Expand Down
18 changes: 18 additions & 0 deletions src/java.base/share/native/libjava/VM.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,26 @@
* questions.
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2025, 2025 All Rights Reserved
* ===========================================================================
*/

#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
#include "jdk_util.h"

#include "jdk_internal_misc_VM.h"

#if defined(WIN32)
#include "j9access.h"
/* tracehelp.c defines getTraceInterfaceFromVM(), used by J9_UTINTERFACE_FROM_VM(). */
#include "tracehelp.c"
#include "ut_jcl_java.c"
#endif /* defined(WIN32) */

/* Only register the performance-critical methods */
static JNINativeMethod methods[] = {
{"getNanoTimeAdjustment", "(J)J", (void *)&JVM_GetNanoTimeAdjustment}
Expand All @@ -42,6 +55,11 @@ Java_jdk_internal_misc_VM_latestUserDefinedLoader0(JNIEnv *env, jclass cls) {

JNIEXPORT void JNICALL
Java_jdk_internal_misc_VM_initialize(JNIEnv *env, jclass cls) {
#if defined(WIN32)
/* Other platforms do this in check_version.c JNI_OnLoad. */
UT_JCL_JAVA_MODULE_LOADED(J9_UTINTERFACE_FROM_VM(((J9VMThread *) env)->javaVM));
#endif /* defined(WIN32) */

if (!JDK_InitJvmHandle()) {
JNU_ThrowInternalError(env, "Handle for JVM not found for symbol lookup");
return;
Expand Down
18 changes: 18 additions & 0 deletions src/java.base/share/native/libjava/check_version.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,31 @@
* ===========================================================================
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2025, 2025 All Rights Reserved
* ===========================================================================
*/

#include "jni.h"
#include "jni_util.h"
#include "jvm.h"

#if !defined(WIN32)
#include "j9access.h"
/* tracehelp.c defines getTraceInterfaceFromVM(), used by J9_UTINTERFACE_FROM_VM(). */
#include "tracehelp.c"
#include "ut_jcl_java.c"
#endif /* !defined(WIN32) */

JNIEXPORT jint JNICALL
DEF_JNI_OnLoad(JavaVM *vm, void *reserved)
{
#if !defined(WIN32)
/* Windows doesn't call JNI_OnLoad for libjava.dll, initialize the tracepoint elsewhere. */
UT_JCL_JAVA_MODULE_LOADED(J9_UTINTERFACE_FROM_VM((J9JavaVM *)vm));
#endif /* !defined(WIN32) */

jint vm_version = JVM_GetInterfaceVersion();
if (vm_version != JVM_INTERFACE_VERSION) {
JNIEnv *env;
Expand Down
13 changes: 13 additions & 0 deletions src/java.base/share/native/libnet/net_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,21 @@
* questions.
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2025, 2025 All Rights Reserved
* ===========================================================================
*/

#include "net_util.h"

#include "java_net_InetAddress.h"

#include "j9access.h"
/* tracehelp.c defines getTraceInterfaceFromVM(), used by J9_UTINTERFACE_FROM_VM(). */
#include "tracehelp.c"
#include "ut_jcl_net.c"

int IPv6_supported();
int reuseport_supported();

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

UT_JCL_NET_MODULE_LOADED(J9_UTINTERFACE_FROM_VM((J9JavaVM *)vm));

iCls = (*env)->FindClass(env, "java/lang/Boolean");
CHECK_NULL_RETURN(iCls, JNI_VERSION_1_2);
mid = (*env)->GetStaticMethodID(env, iCls, "getBoolean", "(Ljava/lang/String;)Z");
Expand Down
13 changes: 13 additions & 0 deletions src/java.base/share/native/libnio/nio_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,21 @@
* questions.
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2025, 2025 All Rights Reserved
* ===========================================================================
*/

#include "jni.h"
#include "jvm.h"
#include "jni_util.h"

#include "j9access.h"
/* tracehelp.c defines getTraceInterfaceFromVM(), used by J9_UTINTERFACE_FROM_VM(). */
#include "tracehelp.c"
#include "ut_jcl_nio.c"

JNIEXPORT jint JNICALL
DEF_JNI_OnLoad(JavaVM *vm, void *reserved)
{
Expand All @@ -36,5 +47,7 @@ DEF_JNI_OnLoad(JavaVM *vm, void *reserved)
return JNI_EVERSION; /* JNI version not supported */
}

UT_JCL_NIO_MODULE_LOADED(J9_UTINTERFACE_FROM_VM((J9JavaVM *)vm));

return JNI_VERSION_1_2;
}
Loading

0 comments on commit 144fb66

Please sign in to comment.