8150534: C1 compilation fails with "Constant field loads are folded during parsing"
authorshade
Thu, 25 Feb 2016 15:10:16 +0300
changeset 36325 1330e79162ac
parent 36324 7f71620b8732
child 36328 f627026bc04a
8150534: C1 compilation fails with "Constant field loads are folded during parsing" Reviewed-by: vlivanov, thartmann
hotspot/src/share/vm/c1/c1_Canonicalizer.cpp
hotspot/test/compiler/c1/CanonicalizeArrayLength.java
--- a/hotspot/src/share/vm/c1/c1_Canonicalizer.cpp	Thu Feb 25 11:17:33 2016 +0100
+++ b/hotspot/src/share/vm/c1/c1_Canonicalizer.cpp	Thu Feb 25 15:10:16 2016 +0300
@@ -224,6 +224,7 @@
 void Canonicalizer::do_ArrayLength    (ArrayLength*     x) {
   NewArray*  na;
   Constant*  ct;
+  LoadField* lf;
 
   if ((na = x->array()->as_NewArray()) != NULL) {
     // New arrays might have the known length.
@@ -244,12 +245,15 @@
       set_constant(cnst->value()->length());
     }
 
-#ifdef ASSERT
-  } else {
-    LoadField* lf = x->array()->as_LoadField();
-    bool is_static_constant = (lf != NULL) && lf->field()->is_constant() && lf->field()->is_static();
-    assert(!is_static_constant, "Constant field loads are folded during parsing");
-#endif // ASSERT
+  } else if ((lf = x->array()->as_LoadField()) != NULL) {
+    ciField* field = lf->field();
+    if (field->is_constant() && field->is_static()) {
+      assert(PatchALot || ScavengeRootsInCode < 2, "Constant field loads are folded during parsing");
+      ciObject* c = field->constant_value().as_object();
+      if (!c->is_null_object()) {
+        set_constant(c->as_array()->length());
+      }
+    }
   }
 }
 
--- a/hotspot/test/compiler/c1/CanonicalizeArrayLength.java	Thu Feb 25 11:17:33 2016 +0100
+++ b/hotspot/test/compiler/c1/CanonicalizeArrayLength.java	Thu Feb 25 15:10:16 2016 +0300
@@ -23,12 +23,13 @@
 
 /*
  * @test
- * @bug 8150102 8150514
+ * @bug 8150102 8150514 8150534
  * @summary C1 crashes in Canonicalizer::do_ArrayLength() after fix for JDK-8150102
  * @run main/othervm -XX:CompileThreshold=100 -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -XX:-BackgroundCompilation CanonicalizeArrayLength
- *
+ * @run main/othervm -XX:CompileThreshold=100 -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -XX:-BackgroundCompilation -XX:+PatchALot CanonicalizeArrayLength
+ * @run main/othervm -XX:CompileThreshold=100 -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -XX:-BackgroundCompilation -XX:ScavengeRootsInCode=0 CanonicalizeArrayLength
+ * @run main/othervm -XX:CompileThreshold=100 -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -XX:-BackgroundCompilation -XX:ScavengeRootsInCode=1 CanonicalizeArrayLength
  */
-
 public class CanonicalizeArrayLength {
     int[] arr = new int[42];
     int[] arrNull = null;