src/share/vm/utilities/decoder.cpp

Thu, 05 Sep 2013 11:04:39 -0700

author
kvn
date
Thu, 05 Sep 2013 11:04:39 -0700
changeset 6462
e2722a66aba7
parent 6461
bdd155477289
child 6472
2b8e28fdf503
permissions
-rw-r--r--

Merge

     1 /*
     2  * Copyright (c) 1997, 2012, 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 #elif defined(AIX)
    37   #include "decoder_aix.hpp"
    38 #else
    39   #include "decoder_elf.hpp"
    40 #endif
    42 AbstractDecoder*  Decoder::_shared_decoder = NULL;
    43 AbstractDecoder*  Decoder::_error_handler_decoder = NULL;
    44 NullDecoder       Decoder::_do_nothing_decoder;
    45 Mutex*            Decoder::_shared_decoder_lock = new Mutex(Mutex::native,
    46                                 "SharedDecoderLock");
    48 AbstractDecoder* Decoder::get_shared_instance() {
    49   assert(_shared_decoder_lock != NULL && _shared_decoder_lock->owned_by_self(),
    50     "Require DecoderLock to enter");
    52   if (_shared_decoder == NULL) {
    53     _shared_decoder = create_decoder();
    54   }
    55   return _shared_decoder;
    56 }
    58 AbstractDecoder* Decoder::get_error_handler_instance() {
    59   if (_error_handler_decoder == NULL) {
    60     _error_handler_decoder = create_decoder();
    61   }
    62   return _error_handler_decoder;
    63 }
    66 AbstractDecoder* Decoder::create_decoder() {
    67   AbstractDecoder* decoder;
    68 #if defined(_WINDOWS)
    69   decoder = new (std::nothrow) WindowsDecoder();
    70 #elif defined (__APPLE__)
    71   decoder = new (std::nothrow)MachODecoder();
    72 #elif defined(AIX)
    73   decoder = new (std::nothrow)AIXDecoder();
    74 #else
    75   decoder = new (std::nothrow)ElfDecoder();
    76 #endif
    78   if (decoder == NULL || decoder->has_error()) {
    79     if (decoder != NULL) {
    80       delete decoder;
    81     }
    82     decoder = &_do_nothing_decoder;
    83   }
    84   return decoder;
    85 }
    87 bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const char* modulepath) {
    88   assert(_shared_decoder_lock != NULL, "Just check");
    89   bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
    90   MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
    91   AbstractDecoder* decoder = error_handling_thread ?
    92     get_error_handler_instance(): get_shared_instance();
    93   assert(decoder != NULL, "null decoder");
    95   return decoder->decode(addr, buf, buflen, offset, modulepath);
    96 }
    98 bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const void* base) {
    99   assert(_shared_decoder_lock != NULL, "Just check");
   100   bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
   101   MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
   102   AbstractDecoder* decoder = error_handling_thread ?
   103     get_error_handler_instance(): get_shared_instance();
   104   assert(decoder != NULL, "null decoder");
   106   return decoder->decode(addr, buf, buflen, offset, base);
   107 }
   110 bool Decoder::demangle(const char* symbol, char* buf, int buflen) {
   111   assert(_shared_decoder_lock != NULL, "Just check");
   112   bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
   113   MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
   114   AbstractDecoder* decoder = error_handling_thread ?
   115     get_error_handler_instance(): get_shared_instance();
   116   assert(decoder != NULL, "null decoder");
   117   return decoder->demangle(symbol, buf, buflen);
   118 }
   120 bool Decoder::can_decode_C_frame_in_vm() {
   121   assert(_shared_decoder_lock != NULL, "Just check");
   122   bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
   123   MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
   124   AbstractDecoder* decoder = error_handling_thread ?
   125     get_error_handler_instance(): get_shared_instance();
   126   assert(decoder != NULL, "null decoder");
   127   return decoder->can_decode_C_frame_in_vm();
   128 }
   130 /*
   131  * Shutdown shared decoder and replace it with
   132  * _do_nothing_decoder. Do nothing with error handler
   133  * instance, since the JVM is going down.
   134  */
   135 void Decoder::shutdown() {
   136   assert(_shared_decoder_lock != NULL, "Just check");
   137   MutexLockerEx locker(_shared_decoder_lock, true);
   139   if (_shared_decoder != NULL &&
   140     _shared_decoder != &_do_nothing_decoder) {
   141     delete _shared_decoder;
   142   }
   144   _shared_decoder = &_do_nothing_decoder;
   145 }

mercurial