8377729: Running jtreg tests with -agent... option causes some tests to fail due to duplicate -agent options provided to a subprocess

Reviewed-by: lmesnik, sspitsyn
This commit is contained in:
Kirill Shirokov 2026-02-19 16:35:53 +00:00 committed by Leonid Mesnik
parent 79dbc50b4f
commit f02d190095
5 changed files with 36 additions and 10 deletions

View File

@ -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<String> options = new ArrayList<>();
Collections.addAll(options, Utils.getTestJavaOpts());
Collections.addAll(options,
"-XX:InitiatingHeapOccupancyPercent=" + ihop,
"-Dmemory.fill=" + (heapSize * 1024 * 1024 * pctToFill / 100),

View File

@ -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());

View File

@ -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) {

View File

@ -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<String> finalOptions = new ArrayList<>();
if (addTestVMOptions) {
Collections.addAll(finalOptions, InputArguments.getVmInputArgs());
Collections.addAll(finalOptions, Utils.getTestJavaOpts());
}
Collections.addAll(finalOptions, options);
finalOptions.add("-version");

View File

@ -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<String> args = new ArrayList<>();
List<String> 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<String> args) {
if (args == null || args.isEmpty()) {
return;
}
Set<String> seen = new HashSet<>();
List<String> 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) {