diff --git a/test/hotspot/jtreg/gc/g1/ihop/TestIHOPStatic.java b/test/hotspot/jtreg/gc/g1/ihop/TestIHOPStatic.java index 6f2c7c005df..2028e8751d7 100644 --- a/test/hotspot/jtreg/gc/g1/ihop/TestIHOPStatic.java +++ b/test/hotspot/jtreg/gc/g1/ihop/TestIHOPStatic.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026, 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 @@ -119,7 +119,6 @@ public class TestIHOPStatic { System.out.println(" MaxHeapSize : " + heapSize); System.out.println(" Expect for concurrent cycle initiation message : " + expectInitiationMessage); List options = new ArrayList<>(); - Collections.addAll(options, Utils.getTestJavaOpts()); Collections.addAll(options, "-XX:InitiatingHeapOccupancyPercent=" + ihop, "-Dmemory.fill=" + (heapSize * 1024 * 1024 * pctToFill / 100), diff --git a/test/jdk/sun/tools/jstack/DeadlockDetectionTest.java b/test/jdk/sun/tools/jstack/DeadlockDetectionTest.java index 80eda6fc091..d743485373e 100644 --- a/test/jdk/sun/tools/jstack/DeadlockDetectionTest.java +++ b/test/jdk/sun/tools/jstack/DeadlockDetectionTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -76,10 +76,8 @@ public class DeadlockDetectionTest { } try { - String[] vmArgs = Utils.appendTestJavaOpts("-XX:+UsePerfData"); - theApp = new LingeredAppWithDeadlock(); - LingeredApp.startApp(theApp, vmArgs); + LingeredApp.startApp(theApp, "-XX:+UsePerfData"); OutputAnalyzer output = jstack(Long.toString(theApp.getPid())); System.out.println(output.getOutput()); diff --git a/test/lib/jdk/test/lib/apps/LingeredApp.java b/test/lib/jdk/test/lib/apps/LingeredApp.java index 38ad9ae5b0e..9a8395d7879 100644 --- a/test/lib/jdk/test/lib/apps/LingeredApp.java +++ b/test/lib/jdk/test/lib/apps/LingeredApp.java @@ -46,6 +46,7 @@ import java.util.UUID; import jdk.test.lib.JDKToolFinder; import jdk.test.lib.Utils; import jdk.test.lib.process.OutputBuffer; +import jdk.test.lib.process.ProcessTools; import jdk.test.lib.process.StreamPumper; import jdk.test.lib.util.CoreUtils; @@ -451,6 +452,7 @@ public class LingeredApp { long t1 = System.currentTimeMillis(); theApp.createLock(); try { + ProcessTools.checkDuplicateAgentOpts(jvmOpts); theApp.runAppExactJvmOpts(jvmOpts); theApp.waitAppReadyOrCrashed(); } catch (Exception ex) { diff --git a/test/lib/jdk/test/lib/cli/CommandLineOptionTest.java b/test/lib/jdk/test/lib/cli/CommandLineOptionTest.java index 8e28ea08365..a9ae57bca71 100644 --- a/test/lib/jdk/test/lib/cli/CommandLineOptionTest.java +++ b/test/lib/jdk/test/lib/cli/CommandLineOptionTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2026, 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 @@ -107,7 +107,6 @@ public abstract class CommandLineOptionTest { List finalOptions = new ArrayList<>(); if (addTestVMOptions) { Collections.addAll(finalOptions, InputArguments.getVmInputArgs()); - Collections.addAll(finalOptions, Utils.getTestJavaOpts()); } Collections.addAll(finalOptions, options); finalOptions.add("-version"); diff --git a/test/lib/jdk/test/lib/process/ProcessTools.java b/test/lib/jdk/test/lib/process/ProcessTools.java index 7d03268cac4..fe9c1de9f30 100644 --- a/test/lib/jdk/test/lib/process/ProcessTools.java +++ b/test/lib/jdk/test/lib/process/ProcessTools.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2026, 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 @@ -43,8 +43,10 @@ import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.CancellationException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; @@ -448,7 +450,7 @@ public final class ProcessTools { private static ProcessBuilder createJavaProcessBuilder(String... command) { String javapath = JDKToolFinder.getJDKTool("java"); - ArrayList args = new ArrayList<>(); + List args = new ArrayList<>(); args.add(javapath); String noCPString = System.getProperty("test.noclasspath", "false"); @@ -465,6 +467,8 @@ public final class ProcessTools { Collections.addAll(args, command); } + checkDuplicateAgentOpts(args); + // Reporting StringBuilder cmdLine = new StringBuilder(); for (String cmd : args) @@ -479,6 +483,30 @@ public final class ProcessTools { return pb; } + // 8377729: Check for duplicate VM JVMTI agent options, as it may + // cause test to fail + public static void checkDuplicateAgentOpts(List args) { + if (args == null || args.isEmpty()) { + return; + } + + Set seen = new HashSet<>(); + List dupArgs = args.stream() + .filter(arg -> (arg.startsWith("-agent") + || arg.startsWith("-javaagent:")) + && !seen.add(arg)) + .collect(Collectors.toList()); + + if (!dupArgs.isEmpty()) { + System.err.println("WARNING: Duplicate JVMTI agent options may" + + " cause test to fail:\n" + dupArgs); + } + } + + public static void checkDuplicateAgentOpts(String[] args) { + checkDuplicateAgentOpts(Arrays.asList(args)); + } + private static void printStack(Thread t, StackTraceElement[] stack) { System.out.println("\t" + t + " stack: (length = " + stack.length + ")"); if (t != null) {