Skip to content

Commit

Permalink
SapMachine #1550: New malloc trace implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
schmelter-sap committed Apr 29, 2024
1 parent 6d07991 commit 8b53239
Show file tree
Hide file tree
Showing 21 changed files with 5,240 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 @@ -266,3 +266,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

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

endif

# SapMachine 2023-11-28: build libmallochooks

ifeq ($(call isTargetOs, linux macosx), true)
$(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 @@ -864,6 +864,9 @@ ifeq ($(call isTargetOs, linux), true)
BUILD_TEST_exeinvoke_exeinvoke.c_OPTIMIZATION := NONE
BUILD_HOTSPOT_JTREG_EXECUTABLES_LIBS_exeFPRegs := -ldl
BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libAsyncGetCallTraceTest := -ldl
# 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
6 changes: 5 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 @@ -129,6 +130,9 @@ class HookControl : public AllStatic {

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

0 comments on commit 8b53239

Please sign in to comment.