src/share/vm/runtime/serviceThread.cpp

Tue, 26 Apr 2011 14:04:43 -0400

author
coleenp
date
Tue, 26 Apr 2011 14:04:43 -0400
changeset 2804
01147d8aac1d
parent 2623
216d916d5c12
child 2888
78542e2b5e35
permissions
-rw-r--r--

7009923: JSR 292: VM crash in JavaThread::last_frame
Summary: Handle stack overflow before the first frame is called, by printing out the called method and not walking the stack.
Reviewed-by: dholmes, phh, dsamersoff

     1 /*
     2  * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #include "precompiled.hpp"
    26 #include "runtime/interfaceSupport.hpp"
    27 #include "runtime/javaCalls.hpp"
    28 #include "runtime/serviceThread.hpp"
    29 #include "runtime/mutexLocker.hpp"
    30 #include "prims/jvmtiImpl.hpp"
    32 ServiceThread* ServiceThread::_instance = NULL;
    34 void ServiceThread::initialize() {
    35   EXCEPTION_MARK;
    37   instanceKlassHandle klass (THREAD,  SystemDictionary::Thread_klass());
    38   instanceHandle thread_oop = klass->allocate_instance_handle(CHECK);
    40   const char* name = JDK_Version::is_gte_jdk17x_version() ?
    41       "Service Thread" : "Low Memory Detector";
    43   Handle string = java_lang_String::create_from_str(name, CHECK);
    45   // Initialize thread_oop to put it into the system threadGroup
    46   Handle thread_group (THREAD, Universe::system_thread_group());
    47   JavaValue result(T_VOID);
    48   JavaCalls::call_special(&result, thread_oop,
    49                           klass,
    50                           vmSymbols::object_initializer_name(),
    51                           vmSymbols::threadgroup_string_void_signature(),
    52                           thread_group,
    53                           string,
    54                           CHECK);
    56   {
    57     MutexLocker mu(Threads_lock);
    58     ServiceThread* thread =  new ServiceThread(&service_thread_entry);
    60     // At this point it may be possible that no osthread was created for the
    61     // JavaThread due to lack of memory. We would have to throw an exception
    62     // in that case. However, since this must work and we do not allow
    63     // exceptions anyway, check and abort if this fails.
    64     if (thread == NULL || thread->osthread() == NULL) {
    65       vm_exit_during_initialization("java.lang.OutOfMemoryError",
    66                                     "unable to create new native thread");
    67     }
    69     java_lang_Thread::set_thread(thread_oop(), thread);
    70     java_lang_Thread::set_priority(thread_oop(), NearMaxPriority);
    71     java_lang_Thread::set_daemon(thread_oop());
    72     thread->set_threadObj(thread_oop());
    73     _instance = thread;
    75     Threads::add(thread);
    76     Thread::start(thread);
    77   }
    78 }
    80 void ServiceThread::service_thread_entry(JavaThread* jt, TRAPS) {
    81   while (true) {
    82     bool sensors_changed = false;
    83     bool has_jvmti_events = false;
    84     JvmtiDeferredEvent jvmti_event;
    85     {
    86       // Need state transition ThreadBlockInVM so that this thread
    87       // will be handled by safepoint correctly when this thread is
    88       // notified at a safepoint.
    90       // This ThreadBlockInVM object is not also considered to be
    91       // suspend-equivalent because ServiceThread is not visible to
    92       // external suspension.
    94       ThreadBlockInVM tbivm(jt);
    96       MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
    97       while (!(sensors_changed = LowMemoryDetector::has_pending_requests()) &&
    98              !(has_jvmti_events = JvmtiDeferredEventQueue::has_events())) {
    99         // wait until one of the sensors has pending requests, or there is a
   100         // pending JVMTI event to post
   101         Service_lock->wait(Mutex::_no_safepoint_check_flag);
   102       }
   104       if (has_jvmti_events) {
   105         jvmti_event = JvmtiDeferredEventQueue::dequeue();
   106       }
   107     }
   109     if (has_jvmti_events) {
   110       jvmti_event.post();
   111     }
   113     if (sensors_changed) {
   114       LowMemoryDetector::process_sensor_changes(jt);
   115     }
   116   }
   117 }
   119 bool ServiceThread::is_service_thread(Thread* thread) {
   120   return thread == _instance;
   121 }

mercurial