src/share/vm/utilities/decoder.cpp

Thu, 09 Feb 2012 10:16:26 -0500

author
zgu
date
Thu, 09 Feb 2012 10:16:26 -0500
changeset 3544
db006a85bf91
parent 3430
d7e3846464d0
child 3961
3b01d0321dfa
permissions
-rw-r--r--

7141259: Native stack is missing in hs_err
Summary: Code cleanup and creating a private decoder for error handler, since it can be triggered from in signal handler, where no lock can be taken
Reviewed-by: dholmes, kamg, acorn, coleenp

     1 /*
     2  * Copyright (c) 1997, 2010, 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 "prims/jvm.h"
    27 #include "runtime/mutexLocker.hpp"
    28 #include "runtime/os.hpp"
    29 #include "utilities/decoder.hpp"
    30 #include "utilities/vmError.hpp"
    32 #if defined(_WINDOWS)
    33   #include "decoder_windows.hpp"
    34 #elif defined(__APPLE__)
    35   #include "decoder_machO.hpp"
    36 #else
    37   #include "decoder_elf.hpp"
    38 #endif
    40 AbstractDecoder*  Decoder::_shared_decoder = NULL;
    41 AbstractDecoder*  Decoder::_error_handler_decoder = NULL;
    42 NullDecoder       Decoder::_do_nothing_decoder;
    43 Mutex*            Decoder::_shared_decoder_lock = new Mutex(Mutex::native,
    44                                 "SharedDecoderLock");
    46 AbstractDecoder* Decoder::get_shared_instance() {
    47   assert(_shared_decoder_lock != NULL && _shared_decoder_lock->owned_by_self(),
    48     "Require DecoderLock to enter");
    50   if (_shared_decoder == NULL) {
    51     _shared_decoder = create_decoder();
    52   }
    53   return _shared_decoder;
    54 }
    56 AbstractDecoder* Decoder::get_error_handler_instance() {
    57   if (_error_handler_decoder == NULL) {
    58     _error_handler_decoder = create_decoder();
    59   }
    60   return _error_handler_decoder;
    61 }
    64 AbstractDecoder* Decoder::create_decoder() {
    65   AbstractDecoder* decoder;
    66 #if defined(_WINDOWS)
    67   decoder = new (std::nothrow) WindowsDecoder();
    68 #elif defined (__APPLE__)
    69   decoder = new (std::nothrow)MachODecoder();
    70 #else
    71   decoder = new (std::nothrow)ElfDecoder();
    72 #endif
    74   if (decoder == NULL || decoder->has_error()) {
    75     if (decoder != NULL) {
    76       delete decoder;
    77     }
    78     decoder = &_do_nothing_decoder;
    79   }
    80   return decoder;
    81 }
    83 bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const char* modulepath) {
    84   assert(_shared_decoder_lock != NULL, "Just check");
    85   bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
    86   MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
    87   AbstractDecoder* decoder = error_handling_thread ?
    88     get_error_handler_instance(): get_shared_instance();
    89   assert(decoder != NULL, "null decoder");
    91   return decoder->decode(addr, buf, buflen, offset, modulepath);
    92 }
    94 bool Decoder::demangle(const char* symbol, char* buf, int buflen) {
    95   assert(_shared_decoder_lock != NULL, "Just check");
    96   bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
    97   MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
    98   AbstractDecoder* decoder = error_handling_thread ?
    99     get_error_handler_instance(): get_shared_instance();
   100   assert(decoder != NULL, "null decoder");
   101   return decoder->demangle(symbol, buf, buflen);
   102 }
   104 bool Decoder::can_decode_C_frame_in_vm() {
   105   assert(_shared_decoder_lock != NULL, "Just check");
   106   bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
   107   MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
   108   AbstractDecoder* decoder = error_handling_thread ?
   109     get_error_handler_instance(): get_shared_instance();
   110   assert(decoder != NULL, "null decoder");
   111   return decoder->can_decode_C_frame_in_vm();
   112 }
   114 /*
   115  * Shutdown shared decoder and replace it with
   116  * _do_nothing_decoder. Do nothing with error handler
   117  * instance, since the JVM is going down.
   118  */
   119 void Decoder::shutdown() {
   120   assert(_shared_decoder_lock != NULL, "Just check");
   121   MutexLockerEx locker(_shared_decoder_lock, true);
   123   if (_shared_decoder != NULL &&
   124     _shared_decoder != &_do_nothing_decoder) {
   125     delete _shared_decoder;
   126   }
   128   _shared_decoder = &_do_nothing_decoder;
   129 }

mercurial