From 941643ece9e4023db8bed038a618ee28c82e5167 Mon Sep 17 00:00:00 2001
From: Harold Seigel <hseigel@openjdk.org>
Date: Tue, 28 Apr 2020 14:13:44 +0000
Subject: [PATCH] 8242921:
 test/hotspot/jtreg/runtime/CompactStrings/TestMethodNames.java uses nashorn
 script engine

Put method names in a .jcod file instead of using nashorn to generate them

Reviewed-by: lfoltan, coleenp
---
 test/hotspot/jtreg/ProblemList.txt            |   1 -
 .../CompactStrings/TestMethodNames.java       |  16 +-
 .../runtime/CompactStrings/methodNames.jcod   | 187 ++++++++++++++++++
 3 files changed, 193 insertions(+), 11 deletions(-)
 create mode 100644 test/hotspot/jtreg/runtime/CompactStrings/methodNames.jcod

diff --git a/test/hotspot/jtreg/ProblemList.txt b/test/hotspot/jtreg/ProblemList.txt
index ac90c0947cc..457bd05491f 100644
--- a/test/hotspot/jtreg/ProblemList.txt
+++ b/test/hotspot/jtreg/ProblemList.txt
@@ -95,7 +95,6 @@ gc/metaspace/CompressedClassSpaceSizeInJmapHeap.java 8241293 macosx-x64
 
 runtime/jni/terminatedThread/TestTerminatedThread.java 8219652 aix-ppc64
 runtime/ReservedStack/ReservedStackTest.java 8231031 generic-all
-runtime/CompactStrings/TestMethodNames.java 8242921 generic-all
 
 #############################################################################
 
diff --git a/test/hotspot/jtreg/runtime/CompactStrings/TestMethodNames.java b/test/hotspot/jtreg/runtime/CompactStrings/TestMethodNames.java
index f9d4ce5ef0e..ffaf90012f3 100644
--- a/test/hotspot/jtreg/runtime/CompactStrings/TestMethodNames.java
+++ b/test/hotspot/jtreg/runtime/CompactStrings/TestMethodNames.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2020, 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
@@ -21,23 +21,19 @@
  * questions.
  */
 
-import javax.script.*;
-import java.util.function.*;
-
 /*
  * @test
  * @bug 8164612
  * @summary Test method names containing Latin-1 supplement characters.
+ * @compile methodNames.jcod
  * @run main/othervm -XX:+CompactStrings TestMethodNames
  * @run main/othervm -XX:-CompactStrings TestMethodNames
  */
 public class TestMethodNames {
-    public static void main(String[] args) throws Exception {
-        ScriptEngineManager m = new ScriptEngineManager();
-        ScriptEngine e = m.getEngineByName("nashorn");
 
-        e.eval("({get \"\0\"(){}})[\"\0\"]");
-        e.eval("({get \"\\x80\"(){}})[\"\\x80\"]");
-        e.eval("({get \"\\xff\"(){}})[\"\\xff\"]");
+    public static void main(String[] args) throws Exception {
+        // Load class containing methods with names containing Latin-1
+        // supplement characters.
+        Class newClass = Class.forName("methodNames");
     }
 }
diff --git a/test/hotspot/jtreg/runtime/CompactStrings/methodNames.jcod b/test/hotspot/jtreg/runtime/CompactStrings/methodNames.jcod
new file mode 100644
index 00000000000..dd14f73eb18
--- /dev/null
+++ b/test/hotspot/jtreg/runtime/CompactStrings/methodNames.jcod
@@ -0,0 +1,187 @@
+/*
+ * Copyright (c) 2020, 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.
+ */
+
+// This .jcod file contains three methods containing Latin-1 supplement
+// characters in their names.  The method names are:
+//    "get \ufffd\ufffd"
+//    "get \u0080"
+//    "get \u00ff"
+class methodNames {
+  0xCAFEBABE;
+  0; // minor version
+  59; // version
+  [32] { // Constant Pool
+    ; // first element is empty
+    Method #2 #3; // #1     at 0x0A
+    class #4; // #2     at 0x0F
+    NameAndType #5 #6; // #3     at 0x12
+    Utf8 "java/lang/Object"; // #4     at 0x17
+    Utf8 "<init>"; // #5     at 0x2A
+    Utf8 "()V"; // #6     at 0x33
+    Field #8 #9; // #7     at 0x39
+    class #10; // #8     at 0x3E
+    NameAndType #11 #12; // #9     at 0x41
+    Utf8 "java/lang/System"; // #10     at 0x46
+    Utf8 "out"; // #11     at 0x59
+    Utf8 "Ljava/io/PrintStream;"; // #12     at 0x5F
+    String #14; // #13     at 0x77
+    Utf8 "get \ufffd\ufffd"; // #14     at 0x7A
+    Method #16 #17; // #15     at 0x7F
+    class #18; // #16     at 0x84
+    NameAndType #19 #20; // #17     at 0x87
+    Utf8 "java/io/PrintStream"; // #18     at 0x8C
+    Utf8 "println"; // #19     at 0xA2
+    Utf8 "(Ljava/lang/String;)V"; // #20     at 0xAC
+    String #22; // #21     at 0xC4
+    Utf8 "get \u0080"; // #22     at 0xC7
+    String #24; // #23     at 0xCC
+    Utf8 "get \u00ff"; // #24     at 0xCF
+    class #26; // #25     at 0xD4
+    Utf8 "methodNames"; // #26     at 0xD7
+    Utf8 "Code"; // #27     at 0xDC
+    Utf8 "LineNumberTable"; // #28     at 0xE3
+    Utf8 "(Ljava/lang/Object;)Ljava/lang/Object;"; // #29     at 0xF5
+    Utf8 "SourceFile"; // #30     at 0x011E
+    Utf8 "methodNames.java"; // #31     at 0x012B
+  } // Constant Pool
+
+  0x0021; // access [ ACC_PUBLIC ACC_SUPER ]
+  #25;// this_cpx
+  #2;// super_cpx
+
+  [0] { // Interfaces
+  } // Interfaces
+
+  [0] { // fields
+  } // fields
+
+  [4] { // methods
+    { // Member at 0x0141
+      0x0001; // access
+      #5; // name_cpx
+      #6; // sig_cpx
+      [1] { // Attributes
+        Attr(#27, 29) { // Code at 0x0149
+          1; // max_stack
+          1; // max_locals
+          Bytes[5]{
+            0x2AB70001B1;
+          }
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#28, 6) { // LineNumberTable at 0x0160
+              [1] { // LineNumberTable
+                0  1; //  at 0x016C
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+      } // Attributes
+    } // Member
+    ;
+    { // Member at 0x016C
+      0x0001; // access
+      #14; // name_cpx
+      #29; // sig_cpx
+      [1] { // Attributes
+        Attr(#27, 38) { // Code at 0x0174
+          2; // max_stack
+          2; // max_locals
+          Bytes[10]{
+            0xB20007120DB6000F;
+            0x2BB0;
+          }
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#28, 10) { // LineNumberTable at 0x0190
+              [2] { // LineNumberTable
+                0  4; //  at 0x019C
+                8  5; //  at 0x01A0
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+      } // Attributes
+    } // Member
+    ;
+    { // Member at 0x01A0
+      0x0001; // access
+      #22; // name_cpx
+      #29; // sig_cpx
+      [1] { // Attributes
+        Attr(#27, 38) { // Code at 0x01A8
+          2; // max_stack
+          2; // max_locals
+          Bytes[10]{
+            0xB200071215B6000F;
+            0x2BB0;
+          }
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#28, 10) { // LineNumberTable at 0x01C4
+              [2] { // LineNumberTable
+                0  9; //  at 0x01D0
+                8  10; //  at 0x01D4
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+      } // Attributes
+    } // Member
+    ;
+    { // Member at 0x01D4
+      0x0001; // access
+      #24; // name_cpx
+      #29; // sig_cpx
+      [1] { // Attributes
+        Attr(#27, 38) { // Code at 0x01DC
+          2; // max_stack
+          2; // max_locals
+          Bytes[10]{
+            0xB200071217B6000F;
+            0x2BB0;
+          }
+          [0] { // Traps
+          } // end Traps
+          [1] { // Attributes
+            Attr(#28, 10) { // LineNumberTable at 0x01F8
+              [2] { // LineNumberTable
+                0  14; //  at 0x0204
+                8  15; //  at 0x0208
+              }
+            } // end LineNumberTable
+          } // Attributes
+        } // end Code
+      } // Attributes
+    } // Member
+  } // methods
+
+  [1] { // Attributes
+    Attr(#30, 2) { // SourceFile at 0x020A
+      #31;
+    } // end SourceFile
+  } // Attributes
+} // end class methodNames