changeset 4646:fc4660f7922c

8016131: nsk/sysdict/vm/stress/chain tests crash the VM in 'entry_frame_is_first()' Reviewed-by: jrose, kvn, mgronlun
author rbackman
date Wed, 12 Jun 2013 11:17:39 +0200
parents 097c49f39521
children a189e8cd4811
files src/cpu/sparc/vm/frame_sparc.inline.hpp src/cpu/x86/vm/frame_x86.inline.hpp src/share/vm/prims/forte.cpp src/share/vm/runtime/frame.cpp src/share/vm/runtime/frame.hpp src/share/vm/runtime/javaCalls.hpp src/share/vm/runtime/thread.cpp src/share/vm/runtime/thread.hpp
diffstat 8 files changed, 39 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/cpu/sparc/vm/frame_sparc.inline.hpp	Mon Jul 15 15:30:13 2013 -0700
+++ b/src/cpu/sparc/vm/frame_sparc.inline.hpp	Wed Jun 12 11:17:39 2013 +0200
@@ -231,10 +231,10 @@
 #endif // CC_INTERP
 
 
-inline JavaCallWrapper* frame::entry_frame_call_wrapper() const {
+inline JavaCallWrapper** frame::entry_frame_call_wrapper_addr() const {
   // note: adjust this code if the link argument in StubGenerator::call_stub() changes!
   const Argument link = Argument(0, false);
-  return (JavaCallWrapper*)sp()[link.as_in().as_register()->sp_offset_in_saved_window()];
+  return (JavaCallWrapper**)&sp()[link.as_in().as_register()->sp_offset_in_saved_window()];
 }
 
 
--- a/src/cpu/x86/vm/frame_x86.inline.hpp	Mon Jul 15 15:30:13 2013 -0700
+++ b/src/cpu/x86/vm/frame_x86.inline.hpp	Wed Jun 12 11:17:39 2013 +0200
@@ -270,11 +270,10 @@
 
 // Entry frames
 
-inline JavaCallWrapper* frame::entry_frame_call_wrapper() const {
- return (JavaCallWrapper*)at(entry_frame_call_wrapper_offset);
+inline JavaCallWrapper** frame::entry_frame_call_wrapper_addr() const {
+ return (JavaCallWrapper**)addr_at(entry_frame_call_wrapper_offset);
 }
 
-
 // Compiled frames
 
 inline int frame::local_offset_for_compiler(int local_index, int nof_args, int max_nof_locals, int max_nof_monitors) {
--- a/src/share/vm/prims/forte.cpp	Mon Jul 15 15:30:13 2013 -0700
+++ b/src/share/vm/prims/forte.cpp	Wed Jun 12 11:17:39 2013 +0200
@@ -31,6 +31,7 @@
 #include "oops/oop.inline.hpp"
 #include "oops/oop.inline2.hpp"
 #include "prims/forte.hpp"
+#include "runtime/javaCalls.hpp"
 #include "runtime/thread.hpp"
 #include "runtime/vframe.hpp"
 #include "runtime/vframeArray.hpp"
@@ -296,10 +297,14 @@
 
   for (loop_count = 0; loop_count < loop_max; loop_count++) {
 
-    if (candidate.is_first_frame()) {
+    if (candidate.is_entry_frame()) {
+      // jcw is NULL if the java call wrapper couldn't be found
+      JavaCallWrapper *jcw = candidate.entry_frame_call_wrapper_if_safe(thread);
       // If initial frame is frame from StubGenerator and there is no
       // previous anchor, there are no java frames associated with a method
-      return false;
+      if (jcw == NULL || jcw->is_first_frame()) {
+        return false;
+      }
     }
 
     if (candidate.is_interpreted_frame()) {
--- a/src/share/vm/runtime/frame.cpp	Mon Jul 15 15:30:13 2013 -0700
+++ b/src/share/vm/runtime/frame.cpp	Wed Jun 12 11:17:39 2013 +0200
@@ -220,9 +220,20 @@
 
 
 bool frame::entry_frame_is_first() const {
-  return entry_frame_call_wrapper()->anchor()->last_Java_sp() == NULL;
+  return entry_frame_call_wrapper()->is_first_frame();
 }
 
+JavaCallWrapper* frame::entry_frame_call_wrapper_if_safe(JavaThread* thread) const {
+  JavaCallWrapper** jcw = entry_frame_call_wrapper_addr();
+  address addr = (address) jcw;
+
+  // addr must be within the usable part of the stack
+  if (thread->is_in_usable_stack(addr)) {
+    return *jcw;
+  }
+
+  return NULL;
+}
 
 bool frame::should_be_deoptimized() const {
   if (_deopt_state == is_deoptimized ||
--- a/src/share/vm/runtime/frame.hpp	Mon Jul 15 15:30:13 2013 -0700
+++ b/src/share/vm/runtime/frame.hpp	Wed Jun 12 11:17:39 2013 +0200
@@ -354,7 +354,9 @@
 
  public:
   // Entry frames
-  JavaCallWrapper* entry_frame_call_wrapper() const;
+  JavaCallWrapper* entry_frame_call_wrapper() const { return *entry_frame_call_wrapper_addr(); }
+  JavaCallWrapper* entry_frame_call_wrapper_if_safe(JavaThread* thread) const;
+  JavaCallWrapper** entry_frame_call_wrapper_addr() const;
   intptr_t* entry_frame_argument_at(int offset) const;
 
   // tells whether there is another chunk of Delta stack above
--- a/src/share/vm/runtime/javaCalls.hpp	Mon Jul 15 15:30:13 2013 -0700
+++ b/src/share/vm/runtime/javaCalls.hpp	Wed Jun 12 11:17:39 2013 +0200
@@ -91,6 +91,8 @@
   oop              receiver()               { return _receiver; }
   void             oops_do(OopClosure* f);
 
+  bool             is_first_frame() const   { return _anchor.last_Java_sp() == NULL; }
+
 };
 
 
--- a/src/share/vm/runtime/thread.cpp	Mon Jul 15 15:30:13 2013 -0700
+++ b/src/share/vm/runtime/thread.cpp	Wed Jun 12 11:17:39 2013 +0200
@@ -936,6 +936,14 @@
 }
 
 
+bool Thread::is_in_usable_stack(address adr) const {
+  size_t stack_guard_size = os::uses_stack_guard_pages() ? (StackYellowPages + StackRedPages) * os::vm_page_size() : 0;
+  size_t usable_stack_size = _stack_size - stack_guard_size;
+
+  return ((adr < stack_base()) && (adr >= stack_base() - usable_stack_size));
+}
+
+
 // We had to move these methods here, because vm threads get into ObjectSynchronizer::enter
 // However, there is a note in JavaThread::is_lock_owned() about the VM threads not being
 // used for compilation in the future. If that change is made, the need for these methods
--- a/src/share/vm/runtime/thread.hpp	Mon Jul 15 15:30:13 2013 -0700
+++ b/src/share/vm/runtime/thread.hpp	Wed Jun 12 11:17:39 2013 +0200
@@ -506,6 +506,9 @@
   // Check if address is in the stack of the thread (not just for locks).
   // Warning: the method can only be used on the running thread
   bool is_in_stack(address adr) const;
+  // Check if address is in the usable part of the stack (excludes protected
+  // guard pages)
+  bool is_in_usable_stack(address adr) const;
 
   // Sets this thread as starting thread. Returns failure if thread
   // creation fails due to lack of memory, too many threads etc.