changeset 57494:f393f34a48cd

8236140: assert(!VerifyHashTableKeys || _hash_lock == 0) failed: remove node from hash table before modifying it Summary: Add missing rehashing for modified node in InitializeNode::complete_stores(). Reviewed-by: neliasso, thartmann
author chagedorn
date Thu, 09 Jan 2020 16:14:14 +0100
parents c61db095b5b3
children eccb8316306d
files src/hotspot/share/opto/memnode.cpp src/hotspot/share/opto/memnode.hpp test/hotspot/jtreg/compiler/macronodes/TestCompleteVolatileStore.java
diffstat 3 files changed, 82 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/opto/memnode.cpp	Thu Jan 09 12:04:22 2020 +0000
+++ b/src/hotspot/share/opto/memnode.cpp	Thu Jan 09 16:14:14 2020 +0100
@@ -4170,7 +4170,7 @@
 Node* InitializeNode::complete_stores(Node* rawctl, Node* rawmem, Node* rawptr,
                                       intptr_t header_size,
                                       Node* size_in_bytes,
-                                      PhaseGVN* phase) {
+                                      PhaseIterGVN* phase) {
   assert(!is_complete(), "not already complete");
   assert(stores_are_sane(phase), "");
   assert(allocation() != NULL, "must be present");
@@ -4262,7 +4262,7 @@
     }
 
     // Collect the store and move on:
-    st->set_req(MemNode::Memory, inits);
+    phase->replace_input_of(st, MemNode::Memory, inits);
     inits = st;                 // put it on the linearized chain
     set_req(i, zmem);           // unhook from previous position
 
--- a/src/hotspot/share/opto/memnode.hpp	Thu Jan 09 12:04:22 2020 +0000
+++ b/src/hotspot/share/opto/memnode.hpp	Thu Jan 09 16:14:14 2020 +0100
@@ -1402,7 +1402,7 @@
   // Called when the associated AllocateNode is expanded into CFG.
   Node* complete_stores(Node* rawctl, Node* rawmem, Node* rawptr,
                         intptr_t header_size, Node* size_in_bytes,
-                        PhaseGVN* phase);
+                        PhaseIterGVN* phase);
 
  private:
   void remove_extra_zeroes();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/compiler/macronodes/TestCompleteVolatileStore.java	Thu Jan 09 16:14:14 2020 +0100
@@ -0,0 +1,79 @@
+/*
+ * 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.
+ */
+
+/*
+ * @test
+ * @bug 8236140
+ * @requires vm.gc.Serial
+ * @summary Tests proper rehashing of a captured volatile field StoreL node when completing it.
+ * @run main/othervm -Xbatch -XX:+UseSerialGC -XX:CompileCommand=compileonly,compiler.macronodes.TestCompleteVolatileStore::test
+ *                   compiler.macronodes.TestCompleteVolatileStore
+ */
+
+package compiler.macronodes;
+
+public class TestCompleteVolatileStore {
+    int i1 = 4;
+
+    public void test() {
+        /*
+         * The store to the volatile field 'l1' (StoreL) of 'a' is captured in the Initialize node of 'a'
+         * (i.e. additional input to it) and completed in InitializeNode::complete_stores.
+         * Since 'l1' is volatile, the hash of the StoreL is non-zero triggering the hash assertion failure.
+         */
+        A a = new A();
+
+        // Make sure that the CheckCastPP node of 'a' is used in the input chain of the Intialize node of 'b'
+        B b = new B(a);
+
+        // Make sure 'b' is non-scalar-replacable to avoid eliminating all allocations
+        B[] arr = new B[i1];
+        arr[i1-3] = b;
+    }
+
+    public static void main(String[] strArr) {
+        TestCompleteVolatileStore _instance = new TestCompleteVolatileStore();
+        for (int i = 0; i < 10_000; i++ ) {
+            _instance.test();
+        }
+    }
+}
+
+class A {
+    // Needs to be volatile to have a non-zero hash for the StoreL node.
+    volatile long l1;
+
+    A() {
+        // StoreL gets captured and is later processed in InitializeNode::complete_stores while expanding the allocation node.
+        this.l1 = 256;
+    }
+}
+
+class B {
+    A a;
+
+    B(A a) {
+        this.a = a;
+    }
+}
+