Skip to content

Commit

Permalink
SapMachine SAP#1550: New malloc trace implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
schmelter-sap authored and RealCLanger committed Apr 12, 2024
1 parent 47f2833 commit f5aee32
Show file tree
Hide file tree
Showing 21 changed files with 5,233 additions and 1 deletion.
13 changes: 13 additions & 0 deletions make/modules/java.base/Copy.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,16 @@ $(eval $(call SetupTextFileProcessing, CREATE_CLASSFILE_CONSTANTS_H, \
TARGETS += $(CREATE_CLASSFILE_CONSTANTS_H)

################################################################################
# SapMachine 2023-11-28: Copy mallochook.h

ifeq ($(call isTargetOs, linux macosx), true)

$(eval $(call SetupCopyFiles, CREATE_MALLOC_HOOKS_H, \
FILES := $(TOPDIR)/src/java.base/unix/native/libmallochooks/mallochooks.h, \
DEST := $(SUPPORT_OUTPUTDIR)/modules_include/java.base/, \
))

TARGETS += $(CREATE_MALLOC_HOOKS_H)
endif

################################################################################
17 changes: 17 additions & 0 deletions make/modules/java.base/lib/CoreLibraries.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,20 @@ ifeq ($(call isTargetOs, aix), true)
TARGETS += $(BUILD_LIBJLI_STATIC)

endif

# SapMachine 2023-11-28: build libmallochooks

ifeq ($(call isTargetOs, linux macosx), true)
LIBJLI_SRC_DIRS := $(call FindSrcDirsForComponent, java.base, libmallochooks)

$(eval $(call SetupJdkLibrary, BUILD_LIBMALLOCHOOKS, \
NAME := mallochooks, \
OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \
OPTIMIZATION := LOW, \
CFLAGS := $(CFLAGS_JDKLIB), \
LDFLAGS := $(LDFLAGS_JDKLIB) $(call SET_SHARED_LIBRARY_ORIGIN), \
LIBS := -ldl, \
))

TARGETS += $(BUILD_LIBMALLOCHOOKS)
endif
3 changes: 3 additions & 0 deletions make/test/JtregNativeHotspot.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,9 @@ ifeq ($(call isTargetOs, linux), true)
BUILD_HOTSPOT_JTREG_EXECUTABLES_LIBS_exeFPRegs := -ldl
BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libAsyncGetCallTraceTest := -ldl
BUILD_HOTSPOT_JTREG_LIBRARIES_LDFLAGS_libfast-math := -ffast-math
# SapMachine 2023-10-04: Added link flags for malloc hooks tests
BUILD_HOTSPOT_JTREG_EXECUTABLES_LIBS_exetestmallochooks := -ldl
BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libtestmallochooks := -ldl
else
BUILD_HOTSPOT_JTREG_EXCLUDE += libtest-rw.c libtest-rwx.c \
exeinvoke.c exestack-gap.c exestack-tls.c libAsyncGetCallTraceTest.cpp
Expand Down
4 changes: 3 additions & 1 deletion src/hotspot/os/linux/malloctrace/mallocTrace.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 SAP SE. All rights reserved.
* Copyright (c) 2024 SAP SE. All rights reserved.
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -29,6 +29,7 @@
#include "malloctrace/assertHandling.hpp"
#include "malloctrace/locker.hpp"
#include "malloctrace/mallocTrace.hpp"
#include "malloctrace/mallocTracePosix.hpp"
#include "malloctrace/siteTable.hpp"
#include "memory/allStatic.hpp"
#include "runtime/globals.hpp"
Expand Down Expand Up @@ -137,6 +138,7 @@ class HookControl : public AllStatic {

static void enable() {
DEBUG_ONLY(verify();)
MallocStatistic::disable(NULL);
malloctrace_assert(!hooks_are_active(), "Sanity");
_old_malloc_hook = __malloc_hook;
__malloc_hook = my_malloc_hook;
Expand Down
Loading

0 comments on commit f5aee32

Please sign in to comment.