Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add selected tracepoints for OpenJ9 -Xtrace #17

Merged
merged 1 commit into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion make/modules/java.base/Lib.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#

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

include CopyFiles.gmk
Expand Down Expand Up @@ -80,6 +80,26 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBNIO, \
NAME := nio, \
OPTIMIZATION := HIGH, \
WARNINGS_AS_ERRORS_xlc := false, \
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, \
UnixDispatcher.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
UnixDomainSockets.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR)/jcl, \
EXTRA_HEADER_DIRS := \
libnio/ch \
libnio/fs \
Expand Down
26 changes: 26 additions & 0 deletions make/modules/java.base/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
# ===========================================================================

################################################################################
## Build libverify
################################################################################
Expand Down Expand Up @@ -55,10 +59,32 @@ endif
$(eval $(call SetupJdkLibrary, BUILD_LIBJAVA, \
NAME := java, \
OPTIMIZATION := HIGH, \
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, \
jdk_util.c_CFLAGS := $(VERSION_CFLAGS), \
ProcessImpl_md.c_CFLAGS := $(VERSION_CFLAGS), \
java_props_md.c_CFLAGS := \
-DARCHPROPNAME='"$(OPENJDK_TARGET_CPU_OSARCH)"', \
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, \
WARNINGS_AS_ERRORS_xlc := false, \
DISABLED_WARNINGS_gcc_ProcessImpl_md.c := unused-result, \
DISABLED_WARNINGS_clang_TimeZone_md.c := unused-variable, \
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) */

// Registers implementations of native methods described in methods[]
// above.
// In particular, registers JVM_GetNanoTimeAdjustment as the implementation
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 @@ -23,12 +23,30 @@
* questions.
*/

/*
* ===========================================================================
* (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) */

return JNI_VERSION_1_2;
}
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;
}
9 changes: 9 additions & 0 deletions src/java.base/unix/native/libjava/UnixFileSystem_md.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 <unistd.h>
#include <assert.h>
#include <sys/types.h>
Expand Down Expand Up @@ -51,6 +57,8 @@
#include "java_io_FileSystem.h"
#include "java_io_UnixFileSystem.h"

#include "ut_jcl_java.h"

#if defined(_AIX)
#if !defined(NAME_MAX)
#define NAME_MAX MAXNAMLEN
Expand Down Expand Up @@ -268,6 +276,7 @@ Java_java_io_UnixFileSystem_createFileExclusively0(JNIEnv *env, jclass cls,
if (errno != EEXIST)
JNU_ThrowIOExceptionWithLastError(env, "Could not open file");
} else {
Trc_io_UnixFileSystem_createFileExclusively_close(fd);
if (close(fd) == -1)
JNU_ThrowIOExceptionWithLastError(env, "Could not close file");
rv = JNI_TRUE;
Expand Down
18 changes: 18 additions & 0 deletions src/java.base/unix/native/libjava/io_util_md.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

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

#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
Expand All @@ -39,6 +46,8 @@
#include <sys/stat.h>
#endif

#include "ut_jcl_java.h"

#ifdef MACOSX

#include <CoreFoundation/CoreFoundation.h>
Expand Down Expand Up @@ -90,6 +99,11 @@ handleOpen(const char *path, int oflag, int mode) {
fd = -1;
}
}
if (-1 == fd) {
Trc_io_handleOpen_err(path, oflag, mode, 0, 0, errno);
} else {
Trc_io_handleOpen(path, oflag, mode, 0, 0, (jlong)fd);
}
return fd;
}

Expand Down Expand Up @@ -167,6 +181,7 @@ fileDescriptorClose(JNIEnv *env, jobject this)
dup2(devnull, fd);
close(devnull);
}
Trc_io_fileDescriptorClose((jlong)fd);
} else {
int result;
#if defined(_AIX)
Expand All @@ -176,7 +191,10 @@ fileDescriptorClose(JNIEnv *env, jobject this)
result = close(fd);
#endif
if (result == -1 && errno != EINTR) {
Trc_io_fileDescriptorClose_err((jlong)fd, errno);
JNU_ThrowIOExceptionWithLastError(env, "close failed");
} else {
Trc_io_fileDescriptorClose((jlong)fd);
}
}
}
Expand Down
21 changes: 20 additions & 1 deletion src/java.base/unix/native/libnio/ch/Net.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 <poll.h>
#include <sys/ioctl.h>
#include <sys/types.h>
Expand All @@ -31,6 +37,7 @@
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <limits.h>
#include <arpa/inet.h>

#include "jni.h"
#include "jni_util.h"
Expand All @@ -47,6 +54,8 @@
#include <sys/utsname.h>
#endif

#include "ut_jcl_nio.h"

/**
* IP_MULTICAST_ALL supported since 2.6.31 but may not be available at
* build time.
Expand Down Expand Up @@ -380,12 +389,22 @@ Java_sun_nio_ch_Net_connect0(JNIEnv *env, jclass clazz, jboolean preferIPv6,
SOCKETADDRESS sa;
int sa_len = 0;
int rv;
int fd;

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

rv = connect(fdval(env, fdo), &sa.sa, sa_len);
fd = fdval(env, fdo);
if (AF_INET == sa.sa4.sin_family) {
char buf[INET_ADDRSTRLEN];
Trc_nio_ch_Net_connect4((jlong)fd, inet_ntop(AF_INET, &sa.sa4.sin_addr, buf, sizeof(buf)), port, sa_len);
} else if (AF_INET6 == sa.sa6.sin6_family) {
char buf[INET6_ADDRSTRLEN];
Trc_nio_ch_Net_connect6((jlong)fd, inet_ntop(AF_INET6, &sa.sa6.sin6_addr, buf, sizeof(buf)), port, ntohl(sa.sa6.sin6_scope_id), sa_len);
}

rv = connect(fd, &sa.sa, sa_len);
if (rv != 0) {
if (errno == EINPROGRESS) {
return IOS_UNAVAILABLE;
Expand Down
9 changes: 9 additions & 0 deletions src/java.base/unix/native/libnio/ch/UnixDispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,19 @@
* questions.
*/

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

#include "nio.h"
#include "nio_util.h"

#include "sun_nio_ch_UnixDispatcher.h"

#include "ut_jcl_nio.h"

static int preCloseFD = -1; /* File descriptor to which we dup other fd's
before closing them for real */

Expand Down Expand Up @@ -55,6 +63,7 @@ JNIEXPORT void JNICALL
Java_sun_nio_ch_UnixDispatcher_close0(JNIEnv *env, jclass clazz, jobject fdo)
{
jint fd = fdval(env, fdo);
Trc_nio_ch_UnixDispatcher_close(fd);
closeFileDescriptor(env, fd);
}

Expand Down
14 changes: 13 additions & 1 deletion src/java.base/unix/native/libnio/ch/UnixDomainSockets.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 <poll.h>
#include <sys/types.h>
#include <sys/socket.h>
Expand All @@ -41,6 +47,8 @@
#include "nio_util.h"
#include "nio.h"

#include "ut_jcl_nio.h"

/* Subtle platform differences in how unnamed sockets (empty path)
* are returned from getsockname()
*/
Expand Down Expand Up @@ -132,12 +140,16 @@ Java_sun_nio_ch_UnixDomainSockets_connect0(JNIEnv *env, jclass clazz, jobject fd
struct sockaddr_un sa;
int sa_len = 0;
int rv;
int fd;

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

rv = connect(fdval(env, fdo), (struct sockaddr *)&sa, sa_len);
fd = fdval(env, fdo);
Trc_nio_ch_UnixDomainSockets_connect(fd, sa.sun_path, sa_len);

rv = connect(fd, (struct sockaddr *)&sa, sa_len);
if (rv != 0) {
if (errno == EINPROGRESS) {
return IOS_UNAVAILABLE;
Expand Down
Loading