From 45fb75353d3854d25e3e84b87cdb7a0a05ad0b1c Mon Sep 17 00:00:00 2001 From: duke Date: Wed, 26 Nov 2025 15:21:40 +0000 Subject: [PATCH] Backport 69a9b4ceaf3852a299ee268a39e56575ad8207ab --- make/hotspot/lib/CompileJvm.gmk | 5 +++++ src/hotspot/share/prims/whitebox.cpp | 9 +++++++++ .../NMT/CheckForProperDetailStackTrace.java | 17 ++++++++++++++--- test/lib/jdk/test/whitebox/WhiteBox.java | 2 ++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/make/hotspot/lib/CompileJvm.gmk b/make/hotspot/lib/CompileJvm.gmk index 6b5edc85b23..f7a7732993a 100644 --- a/make/hotspot/lib/CompileJvm.gmk +++ b/make/hotspot/lib/CompileJvm.gmk @@ -156,6 +156,10 @@ ifeq ($(call isTargetOs, windows), true) WIN_EXPORT_FILE := $(JVM_OUTPUTDIR)/win-exports.def endif + ifeq ($(SHIP_DEBUG_SYMBOLS), public) + CFLAGS_STRIPPED_DEBUGINFO := -DHAS_STRIPPED_DEBUGINFO + endif + JVM_LDFLAGS += -def:$(WIN_EXPORT_FILE) endif @@ -181,6 +185,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBJVM, \ CFLAGS := $(JVM_CFLAGS), \ abstract_vm_version.cpp_CXXFLAGS := $(CFLAGS_VM_VERSION), \ arguments.cpp_CXXFLAGS := $(CFLAGS_VM_VERSION), \ + whitebox.cpp_CXXFLAGS := $(CFLAGS_STRIPPED_DEBUGINFO), \ DISABLED_WARNINGS_gcc := $(DISABLED_WARNINGS_gcc), \ DISABLED_WARNINGS_gcc_ad_$(HOTSPOT_TARGET_CPU_ARCH).cpp := nonnull, \ DISABLED_WARNINGS_gcc_bytecodeInterpreter.cpp := unused-label, \ diff --git a/src/hotspot/share/prims/whitebox.cpp b/src/hotspot/share/prims/whitebox.cpp index 0041bf68729..93a24ec7221 100644 --- a/src/hotspot/share/prims/whitebox.cpp +++ b/src/hotspot/share/prims/whitebox.cpp @@ -504,6 +504,14 @@ WB_ENTRY(jboolean, WB_ConcurrentGCRunTo(JNIEnv* env, jobject o, jobject at)) return ConcurrentGCBreakpoints::run_to(c_name); WB_END +WB_ENTRY(jboolean, WB_HasExternalSymbolsStripped(JNIEnv* env, jobject o)) +#if defined(HAS_STRIPPED_DEBUGINFO) + return true; +#else + return false; +#endif +WB_END + #if INCLUDE_G1GC WB_ENTRY(jboolean, WB_G1IsHumongous(JNIEnv* env, jobject o, jobject obj)) @@ -2761,6 +2769,7 @@ static JNINativeMethod methods[] = { {CC"getVMLargePageSize", CC"()J", (void*)&WB_GetVMLargePageSize}, {CC"getHeapSpaceAlignment", CC"()J", (void*)&WB_GetHeapSpaceAlignment}, {CC"getHeapAlignment", CC"()J", (void*)&WB_GetHeapAlignment}, + {CC"hasExternalSymbolsStripped", CC"()Z", (void*)&WB_HasExternalSymbolsStripped}, {CC"countAliveClasses0", CC"(Ljava/lang/String;)I", (void*)&WB_CountAliveClasses }, {CC"getSymbolRefcount", CC"(Ljava/lang/String;)I", (void*)&WB_GetSymbolRefcount }, {CC"parseCommandLine0", diff --git a/test/hotspot/jtreg/runtime/NMT/CheckForProperDetailStackTrace.java b/test/hotspot/jtreg/runtime/NMT/CheckForProperDetailStackTrace.java index 398d6b523ad..28af0692721 100644 --- a/test/hotspot/jtreg/runtime/NMT/CheckForProperDetailStackTrace.java +++ b/test/hotspot/jtreg/runtime/NMT/CheckForProperDetailStackTrace.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,11 +26,14 @@ * @bug 8133747 8218458 * @summary Running with NMT detail should produce expected stack traces. * @library /test/lib + * @library / * @modules java.base/jdk.internal.misc * java.management * @requires vm.debug + * @build jdk.test.whitebox.WhiteBox * @compile ../modules/CompilerUtils.java - * @run driver CheckForProperDetailStackTrace + * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI CheckForProperDetailStackTrace */ import jdk.test.lib.Platform; @@ -40,6 +43,7 @@ import java.nio.file.Paths; import java.util.regex.Matcher; import java.util.regex.Pattern; +import jdk.test.whitebox.WhiteBox; /** * We are checking for details that should be seen with NMT detail enabled. @@ -59,7 +63,10 @@ public class CheckForProperDetailStackTrace { private static final Path SRC_DIR = Paths.get(TEST_SRC, "src"); private static final Path MODS_DIR = Paths.get(TEST_CLASSES, "mods"); - private static final boolean expectSourceInformation = Platform.isLinux() || Platform.isWindows(); + // Windows has source information only in full pdbs, not in stripped pdbs + private static boolean expectSourceInformation = Platform.isLinux() || Platform.isWindows(); + + static WhiteBox wb = WhiteBox.getWhiteBox(); /* The stack trace we look for by default. Note that :: has been replaced by .* to make sure it matches even if the symbol is not unmangled. @@ -138,6 +145,10 @@ public static void main(String args[]) throws Exception { throw new RuntimeException("Expected stack trace missing from output"); } + if (wb.hasExternalSymbolsStripped()) { + expectSourceInformation = false; + } + System.out.println("Looking for source information:"); if (expectSourceInformation) { if (!stackTraceMatches(".*moduleEntry.cpp.*", output)) { diff --git a/test/lib/jdk/test/whitebox/WhiteBox.java b/test/lib/jdk/test/whitebox/WhiteBox.java index 2b96cbc3a94..59bb75abf4d 100644 --- a/test/lib/jdk/test/whitebox/WhiteBox.java +++ b/test/lib/jdk/test/whitebox/WhiteBox.java @@ -78,6 +78,8 @@ public long getObjectAddress(Object o) { public native long getHeapSpaceAlignment(); public native long getHeapAlignment(); + public native boolean hasExternalSymbolsStripped(); + private native boolean isObjectInOldGen0(Object o); public boolean isObjectInOldGen(Object o) { Objects.requireNonNull(o);