Merge ihse-manpages-branch
authorihse
Mon, 26 Nov 2018 18:52:33 +0100
branchihse-manpages-branch
changeset 57047 d59991e5f462
parent 57046 bb6e39ffd206 (current diff)
parent 52683 e017d2f176d0 (diff)
child 57048 b2ed864c52b5
Merge
--- a/src/hotspot/share/adlc/adlparse.cpp	Mon Nov 26 18:52:20 2018 +0100
+++ b/src/hotspot/share/adlc/adlparse.cpp	Mon Nov 26 18:52:33 2018 +0100
@@ -2870,7 +2870,8 @@
   const char* param = NULL;
   inst._parameters.reset();
   while ((param = inst._parameters.iter()) != NULL) {
-    OperandForm* opForm = (OperandForm*) inst._localNames[param];
+    OpClassForm* opForm = inst._localNames[param]->is_opclass();
+    assert(opForm != NULL, "sanity");
     encoding->add_parameter(opForm->_ident, param);
   }
 
@@ -3340,7 +3341,8 @@
   const char* param = NULL;
   inst._parameters.reset();
   while ((param = inst._parameters.iter()) != NULL) {
-    OperandForm* opForm = (OperandForm*) inst._localNames[param];
+    OpClassForm* opForm = inst._localNames[param]->is_opclass();
+    assert(opForm != NULL, "sanity");
     encoding->add_parameter(opForm->_ident, param);
   }
 
--- a/src/hotspot/share/adlc/dfa.cpp	Mon Nov 26 18:52:20 2018 +0100
+++ b/src/hotspot/share/adlc/dfa.cpp	Mon Nov 26 18:52:33 2018 +0100
@@ -759,19 +759,27 @@
 }
 
 int Expr::compute_min(const Expr *c1, const Expr *c2) {
-  int result = c1->_min_value + c2->_min_value;
-  assert( result >= 0, "Invalid cost computation");
+  int v1 = c1->_min_value;
+  int v2 = c2->_min_value;
+  assert(0 <= v2 && v2 <= Expr::Max, "sanity");
+  assert(v1 <= Expr::Max - v2, "Invalid cost computation");
 
-  return result;
+  return v1 + v2;
 }
 
+
 int Expr::compute_max(const Expr *c1, const Expr *c2) {
-  int result = c1->_max_value + c2->_max_value;
-  if( result < 0 ) {  // check for overflow
-    result = Expr::Max;
+  int v1 = c1->_max_value;
+  int v2 = c2->_max_value;
+
+  // Check for overflow without producing UB. If v2 is positive
+  // and not larger than Max, the subtraction cannot underflow.
+  assert(0 <= v2 && v2 <= Expr::Max, "sanity");
+  if (v1 > Expr::Max - v2) {
+    return Expr::Max;
   }
 
-  return result;
+  return v1 + v2;
 }
 
 void Expr::print() const {
--- a/src/hotspot/share/adlc/formssel.cpp	Mon Nov 26 18:52:20 2018 +0100
+++ b/src/hotspot/share/adlc/formssel.cpp	Mon Nov 26 18:52:33 2018 +0100
@@ -919,7 +919,8 @@
   const char *name;
   const char *kill_name = NULL;
   for (_parameters.reset(); (name = _parameters.iter()) != NULL;) {
-    OperandForm *opForm = (OperandForm*)_localNames[name];
+    OpClassForm *opForm = _localNames[name]->is_opclass();
+    assert(opForm != NULL, "sanity");
 
     Effect* e = NULL;
     {
@@ -936,7 +937,8 @@
       // complex so simply enforce the restriction during parse.
       if (kill_name != NULL &&
           e->isa(Component::TEMP) && !e->isa(Component::DEF)) {
-        OperandForm* kill = (OperandForm*)_localNames[kill_name];
+        OpClassForm* kill = _localNames[kill_name]->is_opclass();
+        assert(kill != NULL, "sanity");
         globalAD->syntax_err(_linenum, "%s: %s %s must be at the end of the argument list\n",
                              _ident, kill->_ident, kill_name);
       } else if (e->isa(Component::KILL) && !e->isa(Component::USE)) {
@@ -2350,7 +2352,8 @@
   // Add parameters that "do not appear in match rule".
   const char *name;
   for (_parameters.reset(); (name = _parameters.iter()) != NULL;) {
-    OperandForm *opForm = (OperandForm*)_localNames[name];
+    OpClassForm *opForm = _localNames[name]->is_opclass();
+    assert(opForm != NULL, "sanity");
 
     if ( _components.operand_position(name) == -1 ) {
       _components.insert(name, opForm->_ident, Component::INVALID, false);
--- a/src/java.base/share/classes/java/lang/String.java	Mon Nov 26 18:52:20 2018 +0100
+++ b/src/java.base/share/classes/java/lang/String.java	Mon Nov 26 18:52:33 2018 +0100
@@ -37,6 +37,7 @@
 import java.util.Objects;
 import java.util.Spliterator;
 import java.util.StringJoiner;
+import java.util.function.Function;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
@@ -2973,6 +2974,25 @@
     }
 
     /**
+     * This method allows the application of a function to {@code this}
+     * string. The function should expect a single String argument
+     * and produce an {@code R} result.
+     *
+     * @param f    functional interface to a apply
+     *
+     * @param <R>  class of the result
+     *
+     * @return     the result of applying the function to this string
+     *
+     * @see java.util.function.Function
+     *
+     * @since 12
+     */
+    public <R> R transform(Function<? super String, ? extends R> f) {
+        return f.apply(this);
+    }
+
+    /**
      * This object (which is already a string!) is itself returned.
      *
      * @return  the string itself.
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Mon Nov 26 18:52:20 2018 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java	Mon Nov 26 18:52:33 2018 +0100
@@ -1778,9 +1778,6 @@
             if (condTypes.isEmpty()) {
                 return syms.objectType; //TODO: how to handle?
             }
-            if (condTypes.size() == 1) {
-                return condTypes.head;
-            }
             Type first = condTypes.head;
             // If same type, that is the result
             if (condTypes.tail.stream().allMatch(t -> types.isSameType(first, t)))
--- a/test/hotspot/jtreg/compiler/arguments/TestScavengeRootsInCode.java	Mon Nov 26 18:52:20 2018 +0100
+++ b/test/hotspot/jtreg/compiler/arguments/TestScavengeRootsInCode.java	Mon Nov 26 18:52:33 2018 +0100
@@ -25,7 +25,7 @@
  * @test
  * @bug 8214025
  * @summary Test compilation with non-default value for ScavengeRootsInCode.
- * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -Xcomp -XX:-TieredCompilation
+ * @run main/othervm -XX:+UnlockDiagnosticVMOptions -Xcomp -XX:-TieredCompilation
  *                   -XX:ScavengeRootsInCode=1 compiler.arguments.TestScavengeRootsInCode
  */
 
--- a/test/hotspot/jtreg/runtime/NMT/MallocStressTest.java	Mon Nov 26 18:52:20 2018 +0100
+++ b/test/hotspot/jtreg/runtime/NMT/MallocStressTest.java	Mon Nov 26 18:52:33 2018 +0100
@@ -186,13 +186,19 @@
                 if (size == 0) size = 1;
                 long addr = MallocStressTest.whiteBox.NMTMallocWithPseudoStack(size, r);
                 if (addr != 0) {
-                    MallocMemory mem = new MallocMemory(addr, size);
-                    synchronized(MallocStressTest.mallocd_memory) {
-                        MallocStressTest.mallocd_memory.add(mem);
-                        MallocStressTest.mallocd_total += size;
+                    try {
+                        MallocMemory mem = new MallocMemory(addr, size);
+                        synchronized(MallocStressTest.mallocd_memory) {
+                            MallocStressTest.mallocd_memory.add(mem);
+                            MallocStressTest.mallocd_total += size;
+                        }
+                    } catch (OutOfMemoryError e) {
+                        // Don't include this malloc memory because it didn't
+                        // get recorded in mallocd_memory list.
+                        MallocStressTest.whiteBox.NMTFree(addr);
+                        break;
                     }
                 } else {
-                    System.out.println("Out of malloc memory");
                     break;
                 }
             }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/lang/String/Transform.java	Mon Nov 26 18:52:33 2018 +0100
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2018, 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
+ * @summary Unit tests for String#transform(Function<String, R> f)
+ * @run main Transform
+ */
+
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+public class Transform {
+    public static void main(String[] args) {
+        test1();
+    }
+
+    /*
+     * Test String#transform(Function<? super String, ? extends R> f) functionality.
+     */
+    static void test1() {
+        simpleTransform("toUpperCase", "abc", s -> s.toUpperCase());
+        simpleTransform("toLowerCase", "ABC", s -> s.toLowerCase());
+        simpleTransform("substring", "John Smith", s -> s.substring(0, 4));
+
+        String multiline = "    This is line one\n" +
+                           "        This is line two\n" +
+                           "            This is line three\n";
+        String expected = "This is line one!\n" +
+                          "    This is line two!\n" +
+                          "        This is line three!\n";
+        check("multiline", multiline.transform(string -> {
+            return string.lines()
+                         .map(s -> s.transform(t -> t.substring(4) + "!"))
+                         .collect(Collectors.joining("\n", "", "\n"));
+        }), expected);
+    }
+
+    static void simpleTransform(String test, String s, Function<String, String> f) {
+        check(test, s.transform(f), f.apply(s));
+    }
+
+    static void check(String test, Object output, Object expected) {
+        if (output != expected && (output == null || !output.equals(expected))) {
+            System.err.println("Testing " + test + ": unexpected result");
+            System.err.println("Output:");
+            System.err.println(output);
+            System.err.println("Expected:");
+            System.err.println(expected);
+            throw new RuntimeException();
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/langtools/tools/javac/switchexpr/SwitchExpressionIsNotAConstant.java	Mon Nov 26 18:52:33 2018 +0100
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2018, 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 8214113
+ * @summary Verify the switch expression's type does not have a constant attached,
+ *          and so the switch expression is not elided.
+ * @compile --enable-preview --source 12 SwitchExpressionIsNotAConstant.java
+ * @run main/othervm --enable-preview SwitchExpressionIsNotAConstant
+ */
+public class SwitchExpressionIsNotAConstant {
+
+    public static void main(String[] args) {
+        int i = 0;
+        {
+            i = 0;
+            int dummy = 1 + switch (i) {
+                default -> {
+                    i++;
+                    break 1;
+                }
+            };
+            if (i != 1) {
+                throw new IllegalStateException("Side effects missing.");
+            }
+        }
+        {
+            i = 0;
+            int dummy = 1 + switch (i) {
+                case -1 -> 1;
+                default -> {
+                    i++;
+                    break 1;
+                }
+            };
+            if (i != 1) {
+                throw new IllegalStateException("Side effects missing.");
+            }
+        }
+        {
+            i = 0;
+            int dummy = 1 + switch (i) {
+                 default :
+                    i++;
+                    break 1;
+            };
+            if (i != 1) {
+                throw new IllegalStateException("Side effects missing.");
+            }
+        }
+        {
+            i = 0;
+            int dummy = 1 + switch (i) {
+                case -1: break 1;
+                default:
+                    i++;
+                    break 1;
+            };
+            if (i != 1) {
+                throw new IllegalStateException("Side effects missing.");
+            }
+        }
+    }
+
+}