src/share/vm/utilities/decoder.cpp

Tue, 24 Dec 2013 11:48:39 -0800

author
mikael
date
Tue, 24 Dec 2013 11:48:39 -0800
changeset 6198
55fb97c4c58d
parent 5667
38f750491293
child 6503
a9becfeecd1b
permissions
-rw-r--r--

8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
Summary: Copyright year updated for files modified during 2013
Reviewed-by: twisti, iveresov

     1 /*
     2  * Copyright (c) 1997, 2013, 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/os.hpp"
    28 #include "utilities/decoder.hpp"
    29 #include "utilities/vmError.hpp"
    31 #if defined(_WINDOWS)
    32   #include "decoder_windows.hpp"
    33 #elif defined(__APPLE__)
    34   #include "decoder_machO.hpp"
    35 #else
    36   #include "decoder_elf.hpp"
    37 #endif
    39 AbstractDecoder*  Decoder::_shared_decoder = NULL;
    40 AbstractDecoder*  Decoder::_error_handler_decoder = NULL;
    41 NullDecoder       Decoder::_do_nothing_decoder;
    42 Mutex*            Decoder::_shared_decoder_lock = new Mutex(Mutex::native,
    43                                 "SharedDecoderLock");
    45 AbstractDecoder* Decoder::get_shared_instance() {
    46   assert(_shared_decoder_lock != NULL && _shared_decoder_lock->owned_by_self(),
    47     "Require DecoderLock to enter");
    49   if (_shared_decoder == NULL) {
    50     _shared_decoder = create_decoder();
    51   }
    52   return _shared_decoder;
    53 }
    55 AbstractDecoder* Decoder::get_error_handler_instance() {
    56   if (_error_handler_decoder == NULL) {
    57     _error_handler_decoder = create_decoder();
    58   }
    59   return _error_handler_decoder;
    60 }
    63 AbstractDecoder* Decoder::create_decoder() {
    64   AbstractDecoder* decoder;
    65 #if defined(_WINDOWS)
    66   decoder = new (std::nothrow) WindowsDecoder();
    67 #elif defined (__APPLE__)
    68   decoder = new (std::nothrow)MachODecoder();
    69 #else
    70   decoder = new (std::nothrow)ElfDecoder();
    71 #endif
    73   if (decoder == NULL || decoder->has_error()) {
    74     if (decoder != NULL) {
    75       delete decoder;
    76     }
    77     decoder = &_do_nothing_decoder;
    78   }
    79   return decoder;
    80 }
    82 inline bool DecoderLocker::is_first_error_thread() {
    83   return (os::current_thread_id() == VMError::get_first_error_tid());
    84 }
    86 DecoderLocker::DecoderLocker() :
    87   MutexLockerEx(DecoderLocker::is_first_error_thread() ?
    88                 NULL : Decoder::shared_decoder_lock(), true) {
    89   _decoder = is_first_error_thread() ?
    90     Decoder::get_error_handler_instance() : Decoder::get_shared_instance();
    91   assert(_decoder != NULL, "null decoder");
    92 }
    94 Mutex* Decoder::shared_decoder_lock() {
    95   assert(_shared_decoder_lock != NULL, "Just check");
    96   return _shared_decoder_lock;
    97 }
    99 bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const char* modulepath) {
   100   assert(_shared_decoder_lock != NULL, "Just check");
   101   bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
   102   MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
   103   AbstractDecoder* decoder = error_handling_thread ?
   104     get_error_handler_instance(): get_shared_instance();
   105   assert(decoder != NULL, "null decoder");
   107   return decoder->decode(addr, buf, buflen, offset, modulepath);
   108 }
   110 bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const void* base) {
   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");
   118   return decoder->decode(addr, buf, buflen, offset, base);
   119 }
   122 bool Decoder::demangle(const char* symbol, char* buf, int buflen) {
   123   assert(_shared_decoder_lock != NULL, "Just check");
   124   bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
   125   MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
   126   AbstractDecoder* decoder = error_handling_thread ?
   127     get_error_handler_instance(): get_shared_instance();
   128   assert(decoder != NULL, "null decoder");
   129   return decoder->demangle(symbol, buf, buflen);
   130 }
   132 bool Decoder::can_decode_C_frame_in_vm() {
   133   assert(_shared_decoder_lock != NULL, "Just check");
   134   bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
   135   MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
   136   AbstractDecoder* decoder = error_handling_thread ?
   137     get_error_handler_instance(): get_shared_instance();
   138   assert(decoder != NULL, "null decoder");
   139   return decoder->can_decode_C_frame_in_vm();
   140 }
   142 /*
   143  * Shutdown shared decoder and replace it with
   144  * _do_nothing_decoder. Do nothing with error handler
   145  * instance, since the JVM is going down.
   146  */
   147 void Decoder::shutdown() {
   148   assert(_shared_decoder_lock != NULL, "Just check");
   149   MutexLockerEx locker(_shared_decoder_lock, true);
   151   if (_shared_decoder != NULL &&
   152     _shared_decoder != &_do_nothing_decoder) {
   153     delete _shared_decoder;
   154   }
   156   _shared_decoder = &_do_nothing_decoder;
   157 }

mercurial