8026735: Stream tests throw java.lang.IncompatibleClassChangeError
authoriveresov
Wed, 30 Oct 2013 22:55:11 -0700
changeset 21209 5eecc37ceb93
parent 21208 2ae445f57ac6
child 21210 7bc9ef060a52
8026735: Stream tests throw java.lang.IncompatibleClassChangeError Summary: Put a band-aid to disable CHA-based inlining for interfaces with default methods in C1 Reviewed-by: kvn, twisti
hotspot/src/share/vm/c1/c1_GraphBuilder.cpp
hotspot/src/share/vm/ci/ciInstanceKlass.cpp
hotspot/src/share/vm/ci/ciInstanceKlass.hpp
hotspot/test/compiler/inlining/InlineDefaultMethod.java
--- a/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp	Wed Oct 30 13:14:09 2013 +0100
+++ b/hotspot/src/share/vm/c1/c1_GraphBuilder.cpp	Wed Oct 30 22:55:11 2013 -0700
@@ -1873,7 +1873,7 @@
         // number of implementors for decl_interface is 0 or 1. If
         // it's 0 then no class implements decl_interface and there's
         // no point in inlining.
-        if (!holder->is_loaded() || decl_interface->nof_implementors() != 1) {
+        if (!holder->is_loaded() || decl_interface->nof_implementors() != 1 || decl_interface->has_default_methods()) {
           singleton = NULL;
         }
       }
--- a/hotspot/src/share/vm/ci/ciInstanceKlass.cpp	Wed Oct 30 13:14:09 2013 +0100
+++ b/hotspot/src/share/vm/ci/ciInstanceKlass.cpp	Wed Oct 30 22:55:11 2013 -0700
@@ -57,6 +57,7 @@
   _init_state = ik->init_state();
   _nonstatic_field_size = ik->nonstatic_field_size();
   _has_nonstatic_fields = ik->has_nonstatic_fields();
+  _has_default_methods = ik->has_default_methods();
   _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields:
 
   _implementor = NULL; // we will fill these lazily
--- a/hotspot/src/share/vm/ci/ciInstanceKlass.hpp	Wed Oct 30 13:14:09 2013 +0100
+++ b/hotspot/src/share/vm/ci/ciInstanceKlass.hpp	Wed Oct 30 22:55:11 2013 -0700
@@ -52,6 +52,7 @@
   bool                   _has_finalizer;
   bool                   _has_subklass;
   bool                   _has_nonstatic_fields;
+  bool                   _has_default_methods;
 
   ciFlags                _flags;
   jint                   _nonstatic_field_size;
@@ -171,6 +172,11 @@
     }
   }
 
+  bool has_default_methods()  {
+    assert(is_loaded(), "must be loaded");
+    return _has_default_methods;
+  }
+
   ciInstanceKlass* get_canonical_holder(int offset);
   ciField* get_field_by_offset(int field_offset, bool is_static);
   ciField* get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/inlining/InlineDefaultMethod.java	Wed Oct 30 22:55:11 2013 -0700
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2013, 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 8026735
+ * @summary CHA in C1 should make correct decisions about default methods
+ * @run main/othervm -Xcomp -XX:CompileOnly=InlineDefaultMethod::test -XX:TieredStopAtLevel=1 InlineDefaultMethod
+ */
+
+
+interface InterfaceWithDefaultMethod0 {
+    default public int defaultMethod() {
+        return 1;
+    }
+}
+
+interface InterfaceWithDefaultMethod1 extends InterfaceWithDefaultMethod0 { }
+
+abstract class Subtype implements InterfaceWithDefaultMethod1 { }
+
+class Decoy extends Subtype {
+    public int defaultMethod() {
+        return 2;
+    }
+}
+
+class Instance extends Subtype { }
+
+public class InlineDefaultMethod {
+    public static int test(InterfaceWithDefaultMethod1 x) {
+        return x.defaultMethod();
+    }
+    public static void main(String[] args) {
+        InterfaceWithDefaultMethod1 a = new Decoy();
+        InterfaceWithDefaultMethod1 b = new Instance();
+        if (test(a) != 2 ||
+            test(b) != 1) {
+          System.err.println("FAILED");
+          System.exit(97);
+        }
+        System.err.println("PASSED");
+    }
+}