changeset 5561:7ce2690d2182 icedtea-2.5.3pre02

RH1015432: java-1.7.0-openjdk: Fails on PPC with StackOverflowError (revised comprehensive fix) Contributed-by: chphilli@redhat.com Summary: Reverse effects of fix for Oracle bug 8013398 on Zero jvm. 1) Stack Overflow bugs found in ppc64 , ppc32 due to bad min stack allowed calc. found by Andrew Haley aph@redhat.com hotspot/src/cpu/zero/vm/stack_zero.hpp hotspot/src/cpu/zero/vm/stack_zero.inline.hpp hotspot/src/os/linux/vm/os_linux.cpp hotspot/src/os/bsd/vm/os_bsd.cpp 2) Incorrect HW flags for atomic_copy64 causing spurious SEGV's. found by Andrew Haley aph@redhat.com hotspot/make/linux/Makefile hotspot/make/bsd/Makefile hotspot/make/bsd/platform_zero.in hotspot/make/linux/platform_zero.in hotspot/src/share/vm/utilities/macros.hpp 3) Missing synch for xchg , xchg_ptr also possible cause of SEGV's. found by Andrew Haley aph@redhat.com hotspot/src/os_cpu/linux_zero/vm/atomic_linux_zero.inline.hpp hotspot/src/os_cpu/bsd_zero/vm/atomic_bsd_zero.inline.hpp 4) Workaround for gcc bug [ http://gcc.gnu.org/PR63341 Add -fno-tree-vectorize to ppc build.] found by Andrew Haley aph@redhat.com hotspot/make/linux/makefiles/gcc.make hotspot/make/bsd/makefiles/gcc.make 5) And fix code rot to allow building Zero hotspot jvm debug[jvmg] , fastdebug. hotspot/src/os_cpu/linux_zero/vm/os_linux_zero.cpp hotspot/src/share/vm/interpreter/bytecodeInterpreter.cpp
author andrew
date Wed, 01 Oct 2014 14:51:36 +0100
parents f5202a835c05
children ec692ec8cf82
files make/bsd/Makefile make/bsd/makefiles/gcc.make make/bsd/platform_zero.in make/linux/Makefile make/linux/makefiles/gcc.make make/linux/platform_zero.in src/cpu/zero/vm/stack_zero.hpp src/cpu/zero/vm/stack_zero.inline.hpp src/os/bsd/vm/os_bsd.cpp src/os/linux/vm/os_linux.cpp src/os_cpu/bsd_zero/vm/atomic_bsd_zero.inline.hpp src/os_cpu/linux_zero/vm/atomic_linux_zero.inline.hpp src/os_cpu/linux_zero/vm/os_linux_zero.cpp src/share/vm/interpreter/bytecodeInterpreter.cpp src/share/vm/utilities/macros.hpp
diffstat 15 files changed, 128 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/make/bsd/Makefile	Mon Sep 22 15:44:19 2014 +0100
+++ b/make/bsd/Makefile	Wed Oct 01 14:51:36 2014 +0100
@@ -282,7 +282,23 @@
 	$(BUILDTREE) VARIANT=shark VARIANTARCH=$(VARIANTARCH)
 
 platform_zero: $(GAMMADIR)/make/$(OSNAME)/platform_zero.in
-	$(SED) 's/@ZERO_ARCHDEF@/$(ZERO_ARCHDEF)/g;s/@ZERO_LIBARCH@/$(ZERO_LIBARCH)/g;' < $< > $@
+ifeq ($(ZERO_ARCHDEF),PPC)
+  ifndef LP64
+	$(SED) 's/@ZERO_ARCHDEF@/-DPPC -DPPC32/g;s/@ZERO_LIBARCH@/$(ZERO_LIBARCH)/g;' < $< > $@
+  else
+	$(SED) 's/@ZERO_ARCHDEF@/-DPPC -DPPC64/g;s/@ZERO_LIBARCH@/$(ZERO_LIBARCH)/g;' < $< > $@
+  endif
+else
+  ifeq ($(ZERO_ARCHDEF),PPC64) 
+	$(SED) 's/@ZERO_ARCHDEF@/-DPPC -DPPC64/g;s/@ZERO_LIBARCH@/$(ZERO_LIBARCH)/g;' < $< > $@
+  else
+    ifeq ($(ZERO_ARCHDEF),PPC32) 
+	$(SED) 's/@ZERO_ARCHDEF@/-DPPC -DPPC32/g;s/@ZERO_LIBARCH@/$(ZERO_LIBARCH)/g;' < $< > $@
+    else
+	$(SED) 's/@ZERO_ARCHDEF@/-D$(ZERO_ARCHDEF)/g;s/@ZERO_LIBARCH@/$(ZERO_LIBARCH)/g;' < $< > $@
+    endif
+  endif
+endif
 
 # Define INSTALL=y at command line to automatically copy JVM into JAVA_HOME
 
--- a/make/bsd/makefiles/gcc.make	Mon Sep 22 15:44:19 2014 +0100
+++ b/make/bsd/makefiles/gcc.make	Wed Oct 01 14:51:36 2014 +0100
@@ -137,6 +137,20 @@
   # Ineffecient 16-byte stack re-alignment on Darwin/IA32
   ARCHFLAG/i486 += -mstackrealign
 endif
+# gcc bug http://gcc.gnu.org/PR63341 in ppc code generation requires -fno-tree-vectorize for now
+ARCHFLAG/ppc     += -fno-tree-vectorize
+ARCHFLAG/ppc64   += -fno-tree-vectorize
+ifeq ($(TYPE),ZERO)
+  ifeq ($(ZERO_ARCHDEF),PPC)
+    ARCHFLAG/zero += -fno-tree-vectorize
+  endif
+  ifeq ($(ZERO_ARCHDEF),PPC32)
+    ARCHFLAG/zero += -fno-tree-vectorize
+  endif
+  ifeq ($(ZERO_ARCHDEF),PPC64)
+    ARCHFLAG/zero += -fno-tree-vectorize
+  endif
+endif
 
 CFLAGS     += $(ARCHFLAG)
 AOUT_FLAGS += $(ARCHFLAG)
--- a/make/bsd/platform_zero.in	Mon Sep 22 15:44:19 2014 +0100
+++ b/make/bsd/platform_zero.in	Wed Oct 01 14:51:36 2014 +0100
@@ -14,4 +14,4 @@
 
 gnu_dis_arch = zero
 
-sysdefs = -D_ALLBSD_SOURCE -D_GNU_SOURCE -DCC_INTERP -DZERO -D@ZERO_ARCHDEF@ -DZERO_LIBARCH=\"@ZERO_LIBARCH@\"
+sysdefs = -D_ALLBSD_SOURCE -D_GNU_SOURCE -DCC_INTERP -DZERO @ZERO_ARCHDEF@ -DZERO_LIBARCH=\"@ZERO_LIBARCH@\"
--- a/make/linux/Makefile	Mon Sep 22 15:44:19 2014 +0100
+++ b/make/linux/Makefile	Wed Oct 01 14:51:36 2014 +0100
@@ -286,7 +286,23 @@
 	$(BUILDTREE) VARIANT=shark VARIANTARCH=$(VARIANTARCH)
 
 platform_zero: $(GAMMADIR)/make/$(OSNAME)/platform_zero.in
-	$(SED) 's/@ZERO_ARCHDEF@/$(ZERO_ARCHDEF)/g;s/@ZERO_LIBARCH@/$(ZERO_LIBARCH)/g;' < $< > $@
+ifeq ($(ZERO_ARCHDEF),PPC) 
+  ifndef LP64
+	$(SED) 's/@ZERO_ARCHDEF@/-DPPC -DPPC32/g;s/@ZERO_LIBARCH@/$(ZERO_LIBARCH)/g;' < $< > $@
+  else
+	$(SED) 's/@ZERO_ARCHDEF@/-DPPC -DPPC64/g;s/@ZERO_LIBARCH@/$(ZERO_LIBARCH)/g;' < $< > $@
+  endif
+else
+  ifeq ($(ZERO_ARCHDEF),PPC64) 
+	$(SED) 's/@ZERO_ARCHDEF@/-DPPC -DPPC64/g;s/@ZERO_LIBARCH@/$(ZERO_LIBARCH)/g;' < $< > $@
+  else
+    ifeq ($(ZERO_ARCHDEF),PPC32) 
+	$(SED) 's/@ZERO_ARCHDEF@/-DPPC -DPPC32/g;s/@ZERO_LIBARCH@/$(ZERO_LIBARCH)/g;' < $< > $@
+    else
+	$(SED) 's/@ZERO_ARCHDEF@/-D$(ZERO_ARCHDEF)/g;s/@ZERO_LIBARCH@/$(ZERO_LIBARCH)/g;' < $< > $@
+    endif
+  endif
+endif
 
 # Define INSTALL=y at command line to automatically copy JVM into JAVA_HOME
 
--- a/make/linux/makefiles/gcc.make	Mon Sep 22 15:44:19 2014 +0100
+++ b/make/linux/makefiles/gcc.make	Wed Oct 01 14:51:36 2014 +0100
@@ -106,6 +106,20 @@
 ARCHFLAG/ppc     =  -mcpu=powerpc
 endif
 ARCHFLAG/ppc64   =  -m64
+# gcc bug http://gcc.gnu.org/PR63341 in ppc code generation requires -fno-tree-vectorize for now
+ARCHFLAG/ppc     += -fno-tree-vectorize
+ARCHFLAG/ppc64   += -fno-tree-vectorize
+ifeq ($(TYPE),ZERO)
+  ifeq ($(ZERO_ARCHDEF),PPC)
+    ARCHFLAG/zero += -fno-tree-vectorize
+  endif
+  ifeq ($(ZERO_ARCHDEF),PPC32)
+    ARCHFLAG/zero += -fno-tree-vectorize
+  endif
+  ifeq ($(ZERO_ARCHDEF),PPC64)
+    ARCHFLAG/zero += -fno-tree-vectorize
+  endif
+endif
 
 CFLAGS     += $(ARCHFLAG)
 AOUT_FLAGS += $(ARCHFLAG)
--- a/make/linux/platform_zero.in	Mon Sep 22 15:44:19 2014 +0100
+++ b/make/linux/platform_zero.in	Wed Oct 01 14:51:36 2014 +0100
@@ -14,4 +14,4 @@
 
 gnu_dis_arch = zero
 
-sysdefs = -DLINUX -D_GNU_SOURCE -DCC_INTERP -DZERO -DTARGET_ARCH_NYI_6939861=1 -D@ZERO_ARCHDEF@ -DZERO_LIBARCH=\"@ZERO_LIBARCH@\"
+sysdefs = -DLINUX -D_GNU_SOURCE -DCC_INTERP -DZERO @ZERO_ARCHDEF@ -DZERO_LIBARCH=\"@ZERO_LIBARCH@\"
--- a/src/cpu/zero/vm/stack_zero.hpp	Mon Sep 22 15:44:19 2014 +0100
+++ b/src/cpu/zero/vm/stack_zero.hpp	Wed Oct 01 14:51:36 2014 +0100
@@ -99,7 +99,7 @@
   int shadow_pages_size() const {
     return _shadow_pages_size;
   }
-  int abi_stack_available(Thread *thread) const;
+  ssize_t abi_stack_available(Thread *thread) const;
 
  public:
   void overflow_check(int required_words, TRAPS);
--- a/src/cpu/zero/vm/stack_zero.inline.hpp	Mon Sep 22 15:44:19 2014 +0100
+++ b/src/cpu/zero/vm/stack_zero.inline.hpp	Wed Oct 01 14:51:36 2014 +0100
@@ -47,10 +47,11 @@
 // This method returns the amount of ABI stack available for us
 // to use under normal circumstances.  Note that the returned
 // value can be negative.
-inline int ZeroStack::abi_stack_available(Thread *thread) const {
-  int stack_used = thread->stack_base() - (address) &stack_used;
-  int stack_free = thread->stack_size() - stack_used;
-  return stack_free - shadow_pages_size();
+inline ssize_t ZeroStack::abi_stack_available(Thread *thread) const {
+  ssize_t stack_used = thread->stack_base() - (address) &stack_used
+    + (StackYellowPages+StackRedPages+StackShadowPages) * os::vm_page_size();
+  ssize_t stack_free = thread->stack_size() - stack_used;
+  return stack_free;
 }
 
 #endif // CPU_ZERO_VM_STACK_ZERO_INLINE_HPP
--- a/src/os/bsd/vm/os_bsd.cpp	Mon Sep 22 15:44:19 2014 +0100
+++ b/src/os/bsd/vm/os_bsd.cpp	Wed Oct 01 14:51:36 2014 +0100
@@ -4758,6 +4758,14 @@
             (size_t)(StackYellowPages+StackRedPages+StackShadowPages+
                     2*BytesPerWord COMPILER2_PRESENT(+1)) * Bsd::page_size());
 
+#ifdef ZERO
+  // If this is Zero, allow at the very minimum one page each for the
+  // Zero stack and the native stack.  This won't make any difference
+  // for 4k pages, but is significant for large pages.
+  os::Bsd::min_stack_allowed = MAX2(os::Bsd::min_stack_allowed,
+             (size_t)(StackYellowPages+StackRedPages+StackShadowPages+2) * Bsd::page_size());
+#endif
+
   size_t threadStackSizeInBytes = ThreadStackSize * K;
   if (threadStackSizeInBytes != 0 &&
       threadStackSizeInBytes < os::Bsd::min_stack_allowed) {
--- a/src/os/linux/vm/os_linux.cpp	Mon Sep 22 15:44:19 2014 +0100
+++ b/src/os/linux/vm/os_linux.cpp	Wed Oct 01 14:51:36 2014 +0100
@@ -4905,16 +4905,18 @@
   // size.  Add a page for compiler2 recursion in main thread.
   // Add in 2*BytesPerWord times page size to account for VM stack during
   // class initialization depending on 32 or 64 bit VM.
-NOT_ZERO (
   os::Linux::min_stack_allowed = MAX2(os::Linux::min_stack_allowed,
             (size_t)(StackYellowPages+StackRedPages+StackShadowPages) * Linux::page_size() +
                     (2*BytesPerWord COMPILER2_PRESENT(+1)) * Linux::vm_default_page_size());
- )
-ZERO_ONLY (
- os::Linux::min_stack_allowed = MAX2(os::Linux::min_stack_allowed,           
-            (size_t)(StackYellowPages+StackRedPages+StackShadowPages+
-                     2*BytesPerWord COMPILER2_PRESENT(+1)) * Linux::page_size());
- )
+
+#ifdef ZERO
+  // If this is Zero, allow at the very minimum one page each for the
+  // Zero stack and the native stack.  This won't make any difference
+  // for 4k pages, but is significant for large pages.
+  os::Linux::min_stack_allowed = MAX2(os::Linux::min_stack_allowed,
+             (size_t)(StackYellowPages+StackRedPages+StackShadowPages+2) * Linux::page_size());
+#endif
+
   size_t threadStackSizeInBytes = ThreadStackSize * K;
   if (threadStackSizeInBytes != 0 &&
       threadStackSizeInBytes < os::Linux::min_stack_allowed) {
--- a/src/os_cpu/bsd_zero/vm/atomic_bsd_zero.inline.hpp	Mon Sep 22 15:44:19 2014 +0100
+++ b/src/os_cpu/bsd_zero/vm/atomic_bsd_zero.inline.hpp	Wed Oct 01 14:51:36 2014 +0100
@@ -239,7 +239,9 @@
   // operation.  Note that some platforms only support this with the
   // limitation that the only valid value to store is the immediate
   // constant 1.  There is a test for this in JNI_CreateJavaVM().
-  return __sync_lock_test_and_set (dest, exchange_value);
+  jint result = __sync_lock_test_and_set (dest, exchange_value);
+  __sync_synchronize();
+  return result;
 #endif // M68K
 #endif // ARM
 }
@@ -252,7 +254,9 @@
 #ifdef M68K
   return m68k_lock_test_and_set(dest, exchange_value);
 #else
-  return __sync_lock_test_and_set (dest, exchange_value);
+  intptr_t result = __sync_lock_test_and_set (dest, exchange_value);
+  __sync_synchronize();
+  return result;
 #endif // M68K
 #endif // ARM
 }
--- a/src/os_cpu/linux_zero/vm/atomic_linux_zero.inline.hpp	Mon Sep 22 15:44:19 2014 +0100
+++ b/src/os_cpu/linux_zero/vm/atomic_linux_zero.inline.hpp	Wed Oct 01 14:51:36 2014 +0100
@@ -243,7 +243,9 @@
   // operation.  Note that some platforms only support this with the
   // limitation that the only valid value to store is the immediate
   // constant 1.  There is a test for this in JNI_CreateJavaVM().
-  return __sync_lock_test_and_set (dest, exchange_value);
+  jint result = __sync_lock_test_and_set (dest, exchange_value);
+  __sync_synchronize();
+  return result;
 #endif // M68K
 #endif // ARM
 }
@@ -256,7 +258,9 @@
 #ifdef M68K
   return m68k_lock_test_and_set(dest, exchange_value);
 #else
-  return __sync_lock_test_and_set (dest, exchange_value);
+  intptr_t result = __sync_lock_test_and_set (dest, exchange_value);
+  __sync_synchronize();
+  return result;
 #endif // M68K
 #endif // ARM
 }
--- a/src/os_cpu/linux_zero/vm/os_linux_zero.cpp	Mon Sep 22 15:44:19 2014 +0100
+++ b/src/os_cpu/linux_zero/vm/os_linux_zero.cpp	Wed Oct 01 14:51:36 2014 +0100
@@ -317,15 +317,15 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 // thread stack
-#ifndef PPC
-size_t os::Linux::min_stack_allowed = 64 * K;
-#else
+#ifdef PPC
 #ifdef _LP64
 // Default for 64 bit must be at least 1600 K
 size_t os::Linux::min_stack_allowed = 1664 * K;
 #else
 size_t os::Linux::min_stack_allowed = 1152 * K;
 #endif
+#else
+size_t os::Linux::min_stack_allowed = 64 * K;
 #endif
 
 bool os::Linux::supports_variable_stack_size() {
@@ -540,3 +540,7 @@
   }
 };
 #endif // !_LP64
+#ifndef PRODUCT
+void os::verify_stack_alignment() {
+}
+#endif
--- a/src/share/vm/interpreter/bytecodeInterpreter.cpp	Mon Sep 22 15:44:19 2014 +0100
+++ b/src/share/vm/interpreter/bytecodeInterpreter.cpp	Wed Oct 01 14:51:36 2014 +0100
@@ -2100,8 +2100,7 @@
             if ( *count_addr > 0 ) {
               if ((Bytecodes::Code)opcode == Bytecodes::_putstatic) {
                 obj = (oop)NULL;
-              }
-              else {
+              } else {
                 if (cache->is_long() || cache->is_double()) {
                   obj = (oop) STACK_OBJECT(-3);
                 } else {
@@ -2122,7 +2121,7 @@
           // QQQ Need to make this as inlined as possible. Probably need to split all the bytecode cases
           // out so c++ compiler has a chance for constant prop to fold everything possible away.
 
-          oop obj;
+          oop obj,too;
           int count;
           TosState tos_type = cache->flag_state();
 
@@ -2146,8 +2145,9 @@
             if (tos_type == itos) {
               obj->release_int_field_put(field_offset, STACK_INT(-1));
             } else if (tos_type == atos) {
-              VERIFY_OOP(STACK_OBJECT(-1));
-              obj->release_obj_field_put(field_offset, STACK_OBJECT(-1));
+              too = (oop) STACK_OBJECT(-1);
+              VERIFY_OOP(too);
+              obj->release_obj_field_put(field_offset, too);
             } else if (tos_type == btos) {
               obj->release_byte_field_put(field_offset, STACK_INT(-1));
             } else if (tos_type == ltos) {
@@ -2166,7 +2166,8 @@
             if (tos_type == itos) {
               obj->int_field_put(field_offset, STACK_INT(-1));
             } else if (tos_type == atos) {
-              VERIFY_OOP(STACK_OBJECT(-1));
+              too = (oop) STACK_OBJECT(-1);
+              VERIFY_OOP(too);
               // On IA64 we perform all stores of references with release semantics.
               // This guarantees that everybody using this reference sees a fully
               // initialized object. On PPC64 we emit a storestore barrier after
@@ -2292,7 +2293,8 @@
       }
       CASE(_checkcast):
           if (STACK_OBJECT(-1) != NULL) {
-            VERIFY_OOP(STACK_OBJECT(-1));
+            oop too = (oop) STACK_OBJECT(-1);
+            VERIFY_OOP(too);
             u2 index = Bytes::get_Java_u2(pc+1);
             // Constant pool may have actual klass or unresolved klass. If it is
             // unresolved we must resolve it.
@@ -2329,7 +2331,8 @@
             // Profile instanceof with null_seen and receiver.
             BI_PROFILE_UPDATE_INSTANCEOF(/*null_seen=*/true, NULL);
           } else {
-            VERIFY_OOP(STACK_OBJECT(-1));
+            oop too = (oop) STACK_OBJECT(-1);
+            VERIFY_OOP(too);
             u2 index = Bytes::get_Java_u2(pc+1);
             // Constant pool may have actual klass or unresolved klass. If it is
             // unresolved we must resolve it.
@@ -2558,7 +2561,8 @@
         // another compliant java compiler.
         if (cache->is_forced_virtual()) {
           methodOop callee;
-          CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));
+          oop too = (oop) STACK_OBJECT(-(cache->parameter_size()));
+          CHECK_NULL(too);
           if (cache->is_vfinal()) {
             callee = cache->f2_as_vfinal_method();
             // Profile 'special case of invokeinterface' final call.
@@ -2645,7 +2649,8 @@
         {
           methodOop callee;
           if ((Bytecodes::Code)opcode == Bytecodes::_invokevirtual) {
-            CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));
+            oop too = (oop) STACK_OBJECT(-(cache->parameter_size()));
+            CHECK_NULL(too);
             if (cache->is_vfinal()) {
               callee = cache->f2_as_vfinal_method();
               // Profile final call.
@@ -2684,7 +2689,8 @@
             }
           } else {
             if ((Bytecodes::Code)opcode == Bytecodes::_invokespecial) {
-              CHECK_NULL(STACK_OBJECT(-(cache->parameter_size())));
+              oop too = (oop) STACK_OBJECT(-(cache->parameter_size()));
+              CHECK_NULL(too);
             }
             callee = cache->f1_as_method();
 
--- a/src/share/vm/utilities/macros.hpp	Mon Sep 22 15:44:19 2014 +0100
+++ b/src/share/vm/utilities/macros.hpp	Wed Oct 01 14:51:36 2014 +0100
@@ -234,7 +234,11 @@
 #define PPC_ONLY(code) code
 #define NOT_PPC(code)
 #else
-#undef PPC
+
+#ifdef PPC
+#error  "PPC is either 32- or 64-bit."
+#endif
+
 #define PPC_ONLY(code)
 #define NOT_PPC(code) code
 #endif