8029957: PPC64 (part 213): cppInterpreter: memory ordering for object initialization
authorgoetz
Wed, 11 Dec 2013 12:28:09 +0100
changeset 22862 495f1688b8b1
parent 22861 f5c393d456fc
child 22863 6a578e0f65ea
8029957: PPC64 (part 213): cppInterpreter: memory ordering for object initialization Summary: Add StoreStore barriers after object initialization and after constructor calls in the C++ interpreter. Reviewed-by: kvn
hotspot/src/share/vm/interpreter/bytecodeInterpreter.cpp
--- a/hotspot/src/share/vm/interpreter/bytecodeInterpreter.cpp	Wed Dec 11 00:06:11 2013 +0100
+++ b/hotspot/src/share/vm/interpreter/bytecodeInterpreter.cpp	Wed Dec 11 12:28:09 2013 +0100
@@ -2240,6 +2240,9 @@
               }
               result->set_klass_gap(0);
               result->set_klass(k_entry);
+              // Must prevent reordering of stores for object initialization
+              // with stores that publish the new object.
+              OrderAccess::storestore();
               SET_STACK_OBJECT(result, 0);
               UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);
             }
@@ -2248,6 +2251,9 @@
         // Slow case allocation
         CALL_VM(InterpreterRuntime::_new(THREAD, METHOD->constants(), index),
                 handle_exception);
+        // Must prevent reordering of stores for object initialization
+        // with stores that publish the new object.
+        OrderAccess::storestore();
         SET_STACK_OBJECT(THREAD->vm_result(), 0);
         THREAD->set_vm_result(NULL);
         UPDATE_PC_AND_TOS_AND_CONTINUE(3, 1);
@@ -2257,6 +2263,9 @@
         jint size = STACK_INT(-1);
         CALL_VM(InterpreterRuntime::anewarray(THREAD, METHOD->constants(), index, size),
                 handle_exception);
+        // Must prevent reordering of stores for object initialization
+        // with stores that publish the new object.
+        OrderAccess::storestore();
         SET_STACK_OBJECT(THREAD->vm_result(), -1);
         THREAD->set_vm_result(NULL);
         UPDATE_PC_AND_CONTINUE(3);
@@ -2271,6 +2280,9 @@
         //adjust pointer to start of stack element
         CALL_VM(InterpreterRuntime::multianewarray(THREAD, dimarray),
                 handle_exception);
+        // Must prevent reordering of stores for object initialization
+        // with stores that publish the new object.
+        OrderAccess::storestore();
         SET_STACK_OBJECT(THREAD->vm_result(), -dims);
         THREAD->set_vm_result(NULL);
         UPDATE_PC_AND_TOS_AND_CONTINUE(4, -(dims-1));
@@ -2693,6 +2705,9 @@
         jint size = STACK_INT(-1);
         CALL_VM(InterpreterRuntime::newarray(THREAD, atype, size),
                 handle_exception);
+        // Must prevent reordering of stores for object initialization
+        // with stores that publish the new object.
+        OrderAccess::storestore();
         SET_STACK_OBJECT(THREAD->vm_result(), -1);
         THREAD->set_vm_result(NULL);
 
@@ -2926,6 +2941,12 @@
   } // handle_Early_Return
 
   handle_return: {
+    // A storestore barrier is required to order initialization of
+    // final fields with publishing the reference to the object that
+    // holds the field. Without the barrier the value of final fields
+    // can be observed to change.
+    OrderAccess::storestore();
+
     DECACHE_STATE();
 
     bool suppress_error = istate->msg() == popping_frame || istate->msg() == early_return;