< prev index next >

src/hotspot/os/solaris/os_solaris.cpp

Print this page
rev 52211 : [mq]: tinit

@@ -197,10 +197,14 @@
   assert((address)&st < (address)st.ss_sp, "Invalid stack base returned");
   assert((address)&st > (address)st.ss_sp-st.ss_size, "Invalid stack size returned");
   return st;
 }
 
+static void _handle_uncaught_cxx_exception() {
+  VMError::report_and_die("An uncaught C++ exception");
+}
+
 bool os::is_primordial_thread(void) {
   int r = thr_main();
   guarantee(r == 0 || r == 1, "CR6501650 or CR6493689");
   return r == 1;
 }

@@ -722,21 +726,25 @@
 
 static thread_t main_thread;
 
 // Thread start routine for all newly created threads
 extern "C" void* thread_native_entry(void* thread_addr) {
+
+  Thread* thread = (Thread*)thread_addr;
+
+  thread->record_stack_base_and_size();
+
   // Try to randomize the cache line index of hot stack frames.
   // This helps when threads of the same stack traces evict each other's
   // cache lines. The threads can be either from the same JVM instance, or
   // from different JVM instances. The benefit is especially true for
   // processors with hyperthreading technology.
   static int counter = 0;
   int pid = os::current_process_id();
   alloca(((pid ^ counter++) & 7) * 128);
 
   int prio;
-  Thread* thread = (Thread*)thread_addr;
 
   thread->initialize_thread_current();
 
   OSThread* osthr = thread->osthread();
 

@@ -773,30 +781,27 @@
   assert(osthr->get_state() == RUNNABLE, "invalid os thread state");
 
   // initialize signal mask for this thread
   os::Solaris::hotspot_sigmask(thread);
 
-  thread->run();
+  os::Solaris::init_thread_fpu_state();
+  std::set_terminate(_handle_uncaught_cxx_exception);
+
+  thread->call_run();
+
+  // Note: at this point the thread object may already have deleted itself.
+  // Do not dereference it from here on out.
 
   // One less thread is executing
   // When the VMThread gets here, the main thread may have already exited
   // which frees the CodeHeap containing the Atomic::dec code
   if (thread != VMThread::vm_thread() && VMThread::vm_thread() != NULL) {
     Atomic::dec(&os::Solaris::_os_thread_count);
   }
 
   log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ").", os::current_thread_id());
 
-  // If a thread has not deleted itself ("delete this") as part of its
-  // termination sequence, we have to ensure thread-local-storage is
-  // cleared before we actually terminate. No threads should ever be
-  // deleted asynchronously with respect to their termination.
-  if (Thread::current_or_null_safe() != NULL) {
-    assert(Thread::current_or_null_safe() == thread, "current thread is wrong");
-    thread->clear_thread_current();
-  }
-
   if (UseDetachedThreads) {
     thr_exit(NULL);
     ShouldNotReachHere();
   }
   return NULL;

@@ -1088,18 +1093,15 @@
 sigset_t* os::Solaris::vm_signals() {
   assert(signal_sets_initialized, "Not initialized");
   return &vm_sigs;
 }
 
-void _handle_uncaught_cxx_exception() {
-  VMError::report_and_die("An uncaught C++ exception");
-}
-
+// CR 7190089: on Solaris, primordial thread's stack needs adjusting.
+// Without the adjustment, stack size is incorrect if stack is set to unlimited (ulimit -s unlimited).
+void os::Solaris::correct_stack_boundaries_for_primordial_thread(Thread* thr) {
+  assert(is_primordial_thread(), "Call only for primordial thread");
 
-// First crack at OS-specific initialization, from inside the new thread.
-void os::initialize_thread(Thread* thr) {
-  if (is_primordial_thread()) {
     JavaThread* jt = (JavaThread *)thr;
     assert(jt != NULL, "Sanity check");
     size_t stack_size;
     address base = jt->stack_base();
     if (Arguments::created_by_java_launcher()) {

@@ -1116,11 +1118,11 @@
       // 6269555: If we were not created by a Java launcher, i.e. if we are
       // running embedded in a native application, treat the primordial thread
       // as much like a native attached thread as possible.  This means using
       // the current stack size from thr_stksegment(), unless it is too large
       // to reliably setup guard pages.  A reasonable max size is 8MB.
-      size_t current_size = current_stack_size();
+    size_t current_size = os::current_stack_size();
       // This should never happen, but just in case....
       if (current_size == 0) current_size = 2 * K * K;
       stack_size = current_size > (8 * K * K) ? (8 * K * K) : current_size;
     }
     address bottom = align_up(base - stack_size, os::vm_page_size());;

@@ -1142,17 +1144,11 @@
       vm_exit(1);
     }
     assert(jt->stack_size() >= stack_size,
            "Attempt to map more stack than was allocated");
     jt->set_stack_size(stack_size);
-  }
-
-  // With the T2 libthread (T1 is no longer supported) threads are always bound
-  // and we use stackbanging in all cases.
 
-  os::Solaris::init_thread_fpu_state();
-  std::set_terminate(_handle_uncaught_cxx_exception);
 }
 
 
 
 // Free Solaris resources related to the OSThread
< prev index next >