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 #789

Merged
merged 1 commit into from
Feb 11, 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
38 changes: 38 additions & 0 deletions closed/adds/jdk/src/share/native/sun/nio/ch/nio_util.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* ===========================================================================
* (c) Copyright IBM Corp. 2025, 2025 All Rights Reserved
* ===========================================================================
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* IBM designates this particular file as subject to the "Classpath" exception
* as provided by IBM in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, see <http://www.gnu.org/licenses/>.
*
* ===========================================================================
*/

#include "jni.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
JNI_OnLoad(JavaVM *vm, void *reserved)
{
UT_JCL_NIO_MODULE_LOADED(J9_UTINTERFACE_FROM_VM((J9JavaVM *)vm));

return JNI_VERSION_1_2;
}
17 changes: 16 additions & 1 deletion jdk/make/lib/CoreLibraries.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#

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

# Include custom extensions if available.
Expand Down Expand Up @@ -152,6 +152,21 @@ LIBJAVA_SRC_DIRS += $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/java/l
$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/common \
$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/java/util

BUILD_LIBJAVA_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
BUILD_LIBJAVA_io_util_md.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR)/jcl
BUILD_LIBJAVA_UnixFileSystem_md.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR)/jcl

ifeq ($(OPENJDK_TARGET_OS), windows)
LIBJAVA_SRC_DIRS += $(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/util/locale/provider
else ifeq ($(OPENJDK_TARGET_OS), macosx)
Expand Down
31 changes: 31 additions & 0 deletions jdk/make/lib/NetworkingLibraries.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
# ===========================================================================

LIBNET_SRC_DIRS := $(JDK_TOPDIR)/src/share/native/java/net \
$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/java/net \
$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/net/ \
Expand All @@ -37,6 +41,33 @@ endif

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

BUILD_LIBNET_aix_close.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR)/jcl
BUILD_LIBNET_bsd_close.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR)/jcl
BUILD_LIBNET_DualStackPlainSocketImpl.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR)/jcl
BUILD_LIBNET_linux_close.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR)/jcl
BUILD_LIBNET_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
BUILD_LIBNET_PlainSocketImpl.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR)/jcl
BUILD_LIBNET_TwoStacksPlainSocketImpl.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR)/jcl

LIBNET_EXCLUDE_FILES :=
ifneq ($(OPENJDK_TARGET_OS), linux)
LIBNET_EXCLUDE_FILES += linux_close.c
Expand Down
24 changes: 24 additions & 0 deletions jdk/make/lib/NioLibraries.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@
# questions.
#

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

BUILD_LIBNIO_SRC := \
$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/java/nio \
$(SRC_ROOT)/closed/adds/jdk/src/share/native/sun/nio/ch \
$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/nio/ch \
$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/sun/nio/fs

Expand All @@ -34,6 +39,24 @@ BUILD_LIBNIO_CFLAGS := \
-I$(JDK_TOPDIR)/src/share/native/java/net \
-I$(JDK_TOPDIR)/src/$(OPENJDK_TARGET_OS_API_DIR)/native/java/net

BUILD_LIBNIO_FileDispatcherImpl.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR)/jcl
BUILD_LIBNIO_Net.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR)/jcl
BUILD_LIBNIO_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
BUILD_LIBNIO_SocketDispatcher.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OPENJ9_VM_BUILD_DIR)/jcl

BUILD_LIBNIO_FILES := \
DatagramChannelImpl.c \
DatagramDispatcher.c \
Expand All @@ -43,6 +66,7 @@ BUILD_LIBNIO_FILES := \
IOUtil.c \
MappedByteBuffer.c \
Net.c \
nio_util.c \
ServerSocketChannelImpl.c \
SocketChannelImpl.c \
SocketDispatcher.c
Expand Down
5 changes: 5 additions & 0 deletions jdk/make/mapfiles/libnio/mapfile-linux
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
# ===========================================================================

SUNWprivate_1.1 {
global:
Java_java_nio_MappedByteBuffer_force0;
Expand Down Expand Up @@ -203,6 +207,7 @@ SUNWprivate_1.1 {
Java_sun_nio_fs_UnixNativeDispatcher_getpwnam0;
Java_sun_nio_fs_UnixNativeDispatcher_getgrnam0;
Java_sun_nio_fs_UnixCopyFile_transfer;
JNI_OnLoad;
handleSocketError;

local:
Expand Down
5 changes: 5 additions & 0 deletions jdk/make/mapfiles/libnio/mapfile-macosx
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
# ===========================================================================

SUNWprivate_1.1 {
global:
Java_java_nio_MappedByteBuffer_force0;
Expand Down Expand Up @@ -175,6 +179,7 @@ SUNWprivate_1.1 {
Java_sun_nio_fs_UnixNativeDispatcher_getpwnam0;
Java_sun_nio_fs_UnixNativeDispatcher_getgrnam0;
Java_sun_nio_fs_UnixCopyFile_transfer;
JNI_OnLoad;
handleSocketError;

local:
Expand Down
20 changes: 20 additions & 0 deletions jdk/src/aix/native/java/net/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 @@ -55,6 +61,9 @@
#include <errno.h>

#include <sys/poll.h>
#include <arpa/inet.h>

#include "ut_jcl_net.h"

/*
* Stack allocated by thread when doing blocking operation
Expand Down Expand Up @@ -370,6 +379,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
10 changes: 9 additions & 1 deletion jdk/src/share/native/common/check_version.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@
*/
/*
* ===========================================================================
* (c) Copyright IBM Corp. 2024, 2024 All Rights Reserved
* (c) Copyright IBM Corp. 2024, 2025 All Rights Reserved
* ===========================================================================
*/

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

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

JNIEXPORT jint JNICALL
JNI_OnLoad(JavaVM *vm, void *reserved)
{
Expand All @@ -45,5 +50,8 @@ JNI_OnLoad(JavaVM *vm, void *reserved)
(*env)->FatalError(env, buf);
}
}

UT_JCL_JAVA_MODULE_LOADED(J9_UTINTERFACE_FROM_VM((J9JavaVM *)vm));

return JNI_VERSION_1_2;
}
14 changes: 14 additions & 0 deletions jdk/src/share/native/java/net/net_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,22 @@
* questions.
*/

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

#include "jni.h"
#include "jvm.h"
#include "jni_util.h"
#include "net_util.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() ;

static int IPv6_available;
Expand All @@ -53,6 +64,9 @@ JNI_OnLoad(JavaVM *vm, void *reserved)
return JNI_VERSION_1_2;
}
}

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
9 changes: 9 additions & 0 deletions jdk/src/solaris/native/java/io/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 <assert.h>
#include <sys/types.h>
#include <sys/time.h>
Expand All @@ -42,6 +48,8 @@
#include "java_io_FileSystem.h"
#include "java_io_UnixFileSystem.h"

#include "ut_jcl_java.h"

#if defined(_ALLBSD_SOURCE)
#define dirent64 dirent
#define readdir64_r readdir_r
Expand Down Expand Up @@ -255,6 +263,7 @@ Java_java_io_UnixFileSystem_createFileExclusively(JNIEnv *env, jclass cls,
if (errno != EEXIST)
JNU_ThrowIOExceptionWithLastError(env, path);
} else {
Trc_io_UnixFileSystem_createFileExclusively_close(fd);
if (close(fd) == -1)
JNU_ThrowIOExceptionWithLastError(env, path);
rv = JNI_TRUE;
Expand Down
17 changes: 17 additions & 0 deletions jdk/src/solaris/native/java/io/io_util_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
* ===========================================================================
*/

#if defined(__linux__)
#define _FILE_OFFSET_BITS 64
#endif
Expand All @@ -43,6 +49,8 @@
#include <sys/ioctl.h>
#endif

#include "ut_jcl_java.h"

#ifdef MACOSX

#include <CoreFoundation/CoreFoundation.h>
Expand Down Expand Up @@ -94,6 +102,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 @@ -148,8 +161,12 @@ fileClose(JNIEnv *env, jobject this, jfieldID fid)
dup2(devnull, fd);
close(devnull);
}
Trc_io_fileDescriptorClose((jlong)fd);
} else if (close(fd) == -1) {
Trc_io_fileDescriptorClose_err((jlong)fd, errno);
JNU_ThrowIOExceptionWithLastError(env, "close failed");
} else {
Trc_io_fileDescriptorClose((jlong)fd);
}
}

Expand Down
Loading