From 7b00105fec7b0529d0783a0ee517b42ec3a96b2e Mon Sep 17 00:00:00 2001 From: SendaoYan Date: Sat, 2 Aug 2025 22:15:03 +0800 Subject: [PATCH 1/2] 8362087: Test containers/docker/ShareTmpDir.java intermittent fails --- .../jtreg/containers/docker/ShareTmpDir.java | 14 +++++++++----- .../jtreg/containers/docker/WaitForFlagFile.java | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/test/hotspot/jtreg/containers/docker/ShareTmpDir.java b/test/hotspot/jtreg/containers/docker/ShareTmpDir.java index 9a4748563bd73..9a0b8ac93ced6 100644 --- a/test/hotspot/jtreg/containers/docker/ShareTmpDir.java +++ b/test/hotspot/jtreg/containers/docker/ShareTmpDir.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 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 @@ -70,10 +70,12 @@ public static void main(String[] args) throws Exception { private static void test() throws Exception { File sharedtmpdir = new File("sharedtmpdir"); File flag = new File(sharedtmpdir, "flag"); - File started = new File(sharedtmpdir, "started"); + File started1 = new File(sharedtmpdir, "started-1"); + File started2 = new File(sharedtmpdir, "started-2"); sharedtmpdir.mkdir(); flag.delete(); - started.delete(); + started1.delete(); + started2.delete(); DockerRunOptions opts = new DockerRunOptions(imageName, "/jdk/bin/java", "WaitForFlagFile"); opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/"); opts.addDockerOpts("--volume", sharedtmpdir.getAbsolutePath() + ":/tmp/"); @@ -81,6 +83,7 @@ private static void test() throws Exception { Thread t1 = new Thread() { public void run() { + opts.addClassOptions("1"); try { out1 = Common.run(opts); } catch (Exception e) { e.printStackTrace(); } } }; @@ -88,13 +91,14 @@ public void run() { Thread t2 = new Thread() { public void run() { + opts.addClassOptions("2"); try { out2 = Common.run(opts); } catch (Exception e) { e.printStackTrace(); } } }; t2.start(); - while (!started.exists()) { - System.out.println("Wait for at least one JVM to start"); + while (!started1.exists() || !started2.exists()) { + System.out.println("Waiting for all the two JVM started"); Thread.sleep(1000); } diff --git a/test/hotspot/jtreg/containers/docker/WaitForFlagFile.java b/test/hotspot/jtreg/containers/docker/WaitForFlagFile.java index 64596830a3f8f..ed549e33cf125 100644 --- a/test/hotspot/jtreg/containers/docker/WaitForFlagFile.java +++ b/test/hotspot/jtreg/containers/docker/WaitForFlagFile.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 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 @@ -28,7 +28,7 @@ public class WaitForFlagFile { public static void main(String[] args) throws Exception { System.out.println("WaitForFlagFile: Entering"); - File started = new File("/tmp/started"); + File started = new File("/tmp/started-" + args.length); FileOutputStream fout = new FileOutputStream(started); fout.close(); From 284bda62c39bb71377101f87e89f215b5edb2688 Mon Sep 17 00:00:00 2001 From: SendaoYan Date: Sun, 3 Aug 2025 20:39:10 +0800 Subject: [PATCH 2/2] Add synchronized lock for addClassOptions --- test/hotspot/jtreg/containers/docker/ShareTmpDir.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/hotspot/jtreg/containers/docker/ShareTmpDir.java b/test/hotspot/jtreg/containers/docker/ShareTmpDir.java index 9a0b8ac93ced6..fe0609c58831e 100644 --- a/test/hotspot/jtreg/containers/docker/ShareTmpDir.java +++ b/test/hotspot/jtreg/containers/docker/ShareTmpDir.java @@ -77,13 +77,16 @@ private static void test() throws Exception { started1.delete(); started2.delete(); DockerRunOptions opts = new DockerRunOptions(imageName, "/jdk/bin/java", "WaitForFlagFile"); + Object lock = new Object(); opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/"); opts.addDockerOpts("--volume", sharedtmpdir.getAbsolutePath() + ":/tmp/"); opts.addJavaOpts("-Xlog:os+container=trace", "-Xlog:perf+memops=debug", "-cp", "/test-classes/"); Thread t1 = new Thread() { public void run() { - opts.addClassOptions("1"); + synchronized(lock) { + opts.addClassOptions("1"); + } try { out1 = Common.run(opts); } catch (Exception e) { e.printStackTrace(); } } }; @@ -91,7 +94,9 @@ public void run() { Thread t2 = new Thread() { public void run() { - opts.addClassOptions("2"); + synchronized(lock) { + opts.addClassOptions("2"); + } try { out2 = Common.run(opts); } catch (Exception e) { e.printStackTrace(); } } };