Skip to content

Commit

Permalink
Add selected tracepoints for OpenJ9 -Xtrace
Browse files Browse the repository at this point in the history
  • Loading branch information
pshipton committed Jan 25, 2025
1 parent c979e50 commit a371faf
Show file tree
Hide file tree
Showing 23 changed files with 373 additions and 3 deletions.
5 changes: 5 additions & 0 deletions closed/CopyToBuildJdk.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
# 2 along with this work; if not, see <http://www.gnu.org/licenses/>.
# ===========================================================================

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

all :

.PHONY : all
Expand Down Expand Up @@ -201,6 +205,7 @@ endif # windows
$(foreach file, \
$(SRC_ROOT)/closed/classlib.properties \
$(OPENJ9_VM_BUILD_DIR)/J9TraceFormat.dat \
$(OPENJ9_VM_BUILD_DIR)/JCLTraceFormat.dat \
$(OPENJ9_VM_BUILD_DIR)/OMRTraceFormat.dat, \
$(call openj9_copy_files,, $(file) $(JDK_OUTPUTDIR)/lib/$(notdir $(file))))

Expand Down
39 changes: 39 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,39 @@
/*
* ===========================================================================
* (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 "jvm.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$(OUTPUT_ROOT)/vm/runtime \
-I$(OPENJ9_TOPDIR)/runtime/jcl \
-I$(OPENJ9_TOPDIR)/runtime/util \
-I$(OUTPUT_ROOT)/vm/runtime/jcl
BUILD_LIBJAVA_io_util_md.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OUTPUT_ROOT)/vm/runtime/jcl
BUILD_LIBJAVA_UnixFileSystem_md.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OUTPUT_ROOT)/vm/runtime/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$(OUTPUT_ROOT)/vm/runtime/jcl
BUILD_LIBNET_bsd_close.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OUTPUT_ROOT)/vm/runtime/jcl
BUILD_LIBNET_DualStackPlainSocketImpl.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OUTPUT_ROOT)/vm/runtime/jcl
BUILD_LIBNET_linux_close.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OUTPUT_ROOT)/vm/runtime/jcl
BUILD_LIBNET_net_util.c_CFLAGS := \
-I$(OPENJ9_TOPDIR)/runtime/include \
-I$(OPENJ9_TOPDIR)/runtime/oti \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OUTPUT_ROOT)/vm/runtime \
-I$(OPENJ9_TOPDIR)/runtime/jcl \
-I$(OPENJ9_TOPDIR)/runtime/util \
-I$(OUTPUT_ROOT)/vm/runtime/jcl
BUILD_LIBNET_PlainSocketImpl.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OUTPUT_ROOT)/vm/runtime/jcl
BUILD_LIBNET_TwoStacksPlainSocketImpl.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OUTPUT_ROOT)/vm/runtime/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$(OUTPUT_ROOT)/vm/runtime/jcl
BUILD_LIBNIO_Net.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OUTPUT_ROOT)/vm/runtime/jcl
BUILD_LIBNIO_nio_util.c_CFLAGS := \
-I$(OPENJ9_TOPDIR)/runtime/include \
-I$(OPENJ9_TOPDIR)/runtime/oti \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OUTPUT_ROOT)/vm/runtime \
-I$(OPENJ9_TOPDIR)/runtime/jcl \
-I$(OPENJ9_TOPDIR)/runtime/util \
-I$(OUTPUT_ROOT)/vm/runtime/jcl
BUILD_LIBNIO_SocketDispatcher.c_CFLAGS := \
-I$(OPENJ9OMR_TOPDIR)/include_core \
-I$(OUTPUT_ROOT)/vm/runtime/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
Loading

0 comments on commit a371faf

Please sign in to comment.