From 049b2ad4dfbc13d21fd58467a0975097a17e8681 Mon Sep 17 00:00:00 2001
From: Alexander Zvegintsev <azvegint@openjdk.org>
Date: Sat, 24 Jul 2021 08:14:05 +0000
Subject: [PATCH 1/4] 8015886:
 java/awt/Focus/DeiconifiedFrameLoosesFocus/DeiconifiedFrameLoosesFocus.java
 sometimes failed on ubuntu

Reviewed-by: kizune, serb
---
 .../DeiconifiedFrameLoosesFocus.java              | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/test/jdk/java/awt/Focus/DeiconifiedFrameLoosesFocus/DeiconifiedFrameLoosesFocus.java b/test/jdk/java/awt/Focus/DeiconifiedFrameLoosesFocus/DeiconifiedFrameLoosesFocus.java
index ccb992035eb..cb1d8f6916b 100644
--- a/test/jdk/java/awt/Focus/DeiconifiedFrameLoosesFocus/DeiconifiedFrameLoosesFocus.java
+++ b/test/jdk/java/awt/Focus/DeiconifiedFrameLoosesFocus/DeiconifiedFrameLoosesFocus.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2021, 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
@@ -31,7 +31,9 @@
   @run        main DeiconifiedFrameLoosesFocus
 */
 
-import java.awt.*;
+import java.awt.Frame;
+import java.awt.Robot;
+import java.awt.Toolkit;
 import test.java.awt.regtesthelpers.Util;
 
 public class DeiconifiedFrameLoosesFocus {
@@ -41,7 +43,11 @@ public class DeiconifiedFrameLoosesFocus {
     public static void main(String[] args) {
         DeiconifiedFrameLoosesFocus app = new DeiconifiedFrameLoosesFocus();
         app.init();
-        app.start();
+        try {
+            app.start();
+        } finally {
+            frame.dispose();
+        }
     }
 
     public void init() {
@@ -61,6 +67,7 @@ public class DeiconifiedFrameLoosesFocus {
         frame.setVisible(true);
 
         Util.waitForIdle(robot);
+        robot.delay(1000);
 
         if (!frame.isFocused()) {
             Util.clickOnTitle(frame, robot);
@@ -79,10 +86,12 @@ public class DeiconifiedFrameLoosesFocus {
         frame.setExtendedState(Frame.ICONIFIED);
 
         Util.waitForIdle(robot);
+        robot.delay(500);
 
         frame.setExtendedState(Frame.NORMAL);
 
         Util.waitForIdle(robot);
+        robot.delay(500);
 
         if (!frame.isFocused()) {
             throw new TestFailedException("the Frame didn't regain focus after restoring!");

From 3c27f919865584bcdcd85577306726afa5412571 Mon Sep 17 00:00:00 2001
From: Igor Ignatyev <iignatyev@openjdk.org>
Date: Mon, 26 Jul 2021 17:18:26 +0000
Subject: [PATCH 2/4] 8271222: two runtime/Monitor tests don't check exit code

Reviewed-by: dholmes
---
 .../runtime/Monitor/MonitorUsedDeflationThresholdTest.java     | 1 +
 .../jtreg/runtime/Monitor/SyncOnValueBasedClassTest.java       | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/test/hotspot/jtreg/runtime/Monitor/MonitorUsedDeflationThresholdTest.java b/test/hotspot/jtreg/runtime/Monitor/MonitorUsedDeflationThresholdTest.java
index beeb7d99642..1260234f164 100644
--- a/test/hotspot/jtreg/runtime/Monitor/MonitorUsedDeflationThresholdTest.java
+++ b/test/hotspot/jtreg/runtime/Monitor/MonitorUsedDeflationThresholdTest.java
@@ -93,6 +93,7 @@ public class MonitorUsedDeflationThresholdTest {
                 "MonitorUsedDeflationThresholdTest", "33");
 
             OutputAnalyzer output_detail = new OutputAnalyzer(pb.start());
+            output_detail.shouldHaveExitValue(0);
 
             // This mesg means:
             // - AvgMonitorsPerThreadEstimate == 1 reduced in_use_list_ceiling
diff --git a/test/hotspot/jtreg/runtime/Monitor/SyncOnValueBasedClassTest.java b/test/hotspot/jtreg/runtime/Monitor/SyncOnValueBasedClassTest.java
index ad2adf3bcf8..d88025707b7 100644
--- a/test/hotspot/jtreg/runtime/Monitor/SyncOnValueBasedClassTest.java
+++ b/test/hotspot/jtreg/runtime/Monitor/SyncOnValueBasedClassTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2021, 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
@@ -95,6 +95,7 @@ public class SyncOnValueBasedClassTest {
         for (int i = 0; i < logTests.length; i++) {
             ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(logTests[i]);
             OutputAnalyzer output = ProcessTools.executeProcess(pb);
+            output.shouldHaveExitValue(0);
             checkOutput(output);
         }
     }

From 7ddabbff74668b5f907f87e6d4d471823d1ac459 Mon Sep 17 00:00:00 2001
From: Igor Ignatyev <iignatyev@openjdk.org>
Date: Mon, 26 Jul 2021 17:19:33 +0000
Subject: [PATCH 3/4] 8271175: runtime/jni/FindClassUtf8/FindClassUtf8.java
 doesn't have to be run in othervm

Reviewed-by: dholmes
---
 .../jtreg/runtime/jni/FindClassUtf8/FindClassUtf8.java | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/test/hotspot/jtreg/runtime/jni/FindClassUtf8/FindClassUtf8.java b/test/hotspot/jtreg/runtime/jni/FindClassUtf8/FindClassUtf8.java
index 03d5cebaacb..4f90838c107 100644
--- a/test/hotspot/jtreg/runtime/jni/FindClassUtf8/FindClassUtf8.java
+++ b/test/hotspot/jtreg/runtime/jni/FindClassUtf8/FindClassUtf8.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2021, 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
@@ -25,9 +25,10 @@
  * @bug 8166358
  * @summary verify that -Xcheck:jni finds a bad utf8 name for class name.
  * @library /test/lib
- * @run main/native/othervm FindClassUtf8 test
+ * @run main/native FindClassUtf8 test
  */
 
+import jdk.test.lib.Utils;
 import jdk.test.lib.process.ProcessTools;
 import jdk.test.lib.process.OutputAnalyzer;
 
@@ -42,7 +43,10 @@ public final class FindClassUtf8 {
     public static void main(String... args) throws Exception {
         if (args.length == 1) {
             // run java -Xcheck:jni FindClassUtf8 and check that the -Xcheck:jni message comes out.
-            ProcessTools.executeTestJvm("-Xcheck:jni", "-XX:-CreateCoredumpOnCrash", "FindClassUtf8")
+            ProcessTools.executeTestJvm("-Djava.library.path=" + Utils.TEST_NATIVE_PATH,
+                                        "-Xcheck:jni",
+                                        "-XX:-CreateCoredumpOnCrash",
+                                        "FindClassUtf8")
                       .shouldContain("JNI class name is not a valid UTF8 string")
                       .shouldNotHaveExitValue(0);  // you get a core dump from -Xcheck:jni failures
         } else {

From b76a83888b00faff602726f5409e1c902b91e908 Mon Sep 17 00:00:00 2001
From: Jim Laskey <jlaskey@openjdk.org>
Date: Mon, 26 Jul 2021 18:04:28 +0000
Subject: [PATCH 4/4] 8269150: UnicodeReader not translating \u005c\\u005d to
 \\]

Reviewed-by: jjg, jlahoda, darcy
---
 .../sun/tools/javac/parser/UnicodeReader.java | 28 +++++---
 .../UnicodeBackslash/UnicodeBackslash.java    | 72 +++++++++++++++++++
 2 files changed, 92 insertions(+), 8 deletions(-)
 create mode 100644 test/langtools/tools/javac/UnicodeBackslash/UnicodeBackslash.java

diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/UnicodeReader.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/UnicodeReader.java
index c51be0fdf07..b089cf396cc 100644
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/UnicodeReader.java
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/UnicodeReader.java
@@ -85,6 +85,11 @@ public class UnicodeReader {
      */
     private boolean wasBackslash;
 
+    /**
+     * true if the last character was derived from an unicode escape sequence.
+     */
+    private boolean wasUnicodeEscape;
+
     /**
      * Log for error reporting.
      */
@@ -105,6 +110,7 @@ public class UnicodeReader {
         this.character = '\0';
         this.codepoint = 0;
         this.wasBackslash = false;
+        this.wasUnicodeEscape = false;
         this.log = sf.log;
 
         nextCodePoint();
@@ -161,17 +167,22 @@ public class UnicodeReader {
         // Fetch next character.
         nextCodeUnit();
 
-        // If second backslash is detected.
-        if (wasBackslash) {
-            // Treat like a normal character (not part of unicode escape.)
-            wasBackslash = false;
-        } else if (character == '\\') {
-            // May be an unicode escape.
+        if (character == '\\' && (!wasBackslash || wasUnicodeEscape)) {
+            // Is a backslash and may be an unicode escape.
             switch (unicodeEscape()) {
-                case BACKSLASH -> wasBackslash = true;
-                case VALID_ESCAPE -> wasBackslash = false;
+                case BACKSLASH -> {
+                    wasUnicodeEscape = false;
+                    wasBackslash = !wasBackslash;
+                }
+                case VALID_ESCAPE -> {
+                    wasUnicodeEscape = true;
+                    wasBackslash = character == '\\' && !wasBackslash;
+                }
                 case BROKEN_ESCAPE -> nextUnicodeInputCharacter(); //skip broken unicode escapes
             }
+        } else {
+            wasBackslash = false;
+            wasUnicodeEscape = false;
         }
 
         // Codepoint and character match if not surrogate.
@@ -297,6 +308,7 @@ public class UnicodeReader {
         position = pos;
         width = 0;
         wasBackslash = false;
+        wasUnicodeEscape = false;
         nextCodePoint();
     }
 
diff --git a/test/langtools/tools/javac/UnicodeBackslash/UnicodeBackslash.java b/test/langtools/tools/javac/UnicodeBackslash/UnicodeBackslash.java
new file mode 100644
index 00000000000..38083e538c1
--- /dev/null
+++ b/test/langtools/tools/javac/UnicodeBackslash/UnicodeBackslash.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2021, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8269150
+ * @summary Unicode \ u 0 0 5 C not treated as an escaping backslash
+ * @run main UnicodeBackslash
+ */
+
+public class UnicodeBackslash {
+    static boolean failed = false;
+
+    public static void main(String... args) {
+        //   id     source                       expected
+        test("1.1", "\\]",                       "\\]");
+        test("1.2", "\u005C\]",                  "\\]");
+        test("1.3", "\\u005C]",                  "\\u005C]");
+        test("1.4", "\u005C\u005C]",             "\\]");
+
+        test("2.1", "\\\\]",                     "\\\\]");
+        test("2.2", "\u005C\\\]",                "\\\\]");
+        test("2.3", "\\u005C\\]",                "\\u005C\\]");
+        test("2.4", "\\\u005C\]",                "\\\\]");
+        test("2.5", "\\\\u005C]",                "\\\\u005C]");
+
+        test("3.1", "\u005C\u005C\\]",           "\\\\]");
+        test("3.2", "\u005C\\u005C\]",           "\\\\]");
+        test("3.3", "\u005C\\\u005C]",           "\\\\u005C]");
+        test("3.4", "\\u005C\u005C\]",           "\\u005C\\]");
+        test("3.5", "\\u005C\\u005C]",           "\\u005C\\u005C]");
+        test("3.6", "\\\u005C\u005C]",           "\\\\]");
+
+        test("4.1", "\u005C\u005C\u005C\]",      "\\\\]");
+        test("4.2", "\u005C\\u005C\u005C]",      "\\\\]");
+        test("4.3", "\u005C\u005C\\u005C]",      "\\\\u005C]");
+        test("4.4", "\\u005C\u005C\u005C]",      "\\u005C\\]");
+
+        test("5.1", "\u005C\u005C\u005C\u005C]", "\\\\]");
+
+        if (failed) {
+            throw new RuntimeException("Unicode escapes not handled correctly");
+        }
+    }
+
+    static void test(String id, String source, String expected) {
+        if (!source.equals(expected)) {
+            System.err.println(id + ": expected: " +  expected + ", found: " + source);
+            failed = true;
+        }
+    }
+}