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

zgu@2364 1 /*
zgu@2364 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
zgu@2364 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
zgu@2364 4 *
zgu@2364 5 * This code is free software; you can redistribute it and/or modify it
zgu@2364 6 * under the terms of the GNU General Public License version 2 only, as
zgu@2364 7 * published by the Free Software Foundation.
zgu@2364 8 *
zgu@2364 9 * This code is distributed in the hope that it will be useful, but WITHOUT
zgu@2364 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
zgu@2364 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
zgu@2364 12 * version 2 for more details (a copy is included in the LICENSE file that
zgu@2364 13 * accompanied this code).
zgu@2364 14 *
zgu@2364 15 * You should have received a copy of the GNU General Public License version
zgu@2364 16 * 2 along with this work; if not, write to the Free Software Foundation,
zgu@2364 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
zgu@2364 18 *
zgu@2364 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
zgu@2364 20 * or visit www.oracle.com if you need additional information or have any
zgu@2364 21 * questions.
zgu@2364 22 *
zgu@2364 23 */
zgu@2364 24
zgu@2364 25 #include "precompiled.hpp"
zgu@2364 26 #include "prims/jvm.h"
zgu@3430 27 #include "runtime/mutexLocker.hpp"
zgu@3544 28 #include "runtime/os.hpp"
zgu@2364 29 #include "utilities/decoder.hpp"
zgu@3544 30 #include "utilities/vmError.hpp"
zgu@2364 31
zgu@3430 32 #if defined(_WINDOWS)
zgu@3430 33 #include "decoder_windows.hpp"
zgu@3430 34 #elif defined(__APPLE__)
zgu@3430 35 #include "decoder_machO.hpp"
zgu@3430 36 #else
zgu@3430 37 #include "decoder_elf.hpp"
zgu@3430 38 #endif
zgu@2364 39
zgu@3544 40 AbstractDecoder* Decoder::_shared_decoder = NULL;
zgu@3544 41 AbstractDecoder* Decoder::_error_handler_decoder = NULL;
zgu@3544 42 NullDecoder Decoder::_do_nothing_decoder;
zgu@3544 43 Mutex* Decoder::_shared_decoder_lock = new Mutex(Mutex::native,
zgu@3544 44 "SharedDecoderLock");
zgu@2364 45
zgu@3544 46 AbstractDecoder* Decoder::get_shared_instance() {
zgu@3544 47 assert(_shared_decoder_lock != NULL && _shared_decoder_lock->owned_by_self(),
zgu@3430 48 "Require DecoderLock to enter");
zgu@2364 49
zgu@3544 50 if (_shared_decoder == NULL) {
zgu@3544 51 _shared_decoder = create_decoder();
zgu@3430 52 }
zgu@3544 53 return _shared_decoder;
zgu@3544 54 }
zgu@3430 55
zgu@3544 56 AbstractDecoder* Decoder::get_error_handler_instance() {
zgu@3544 57 if (_error_handler_decoder == NULL) {
zgu@3544 58 _error_handler_decoder = create_decoder();
zgu@3544 59 }
zgu@3544 60 return _error_handler_decoder;
zgu@3544 61 }
zgu@3544 62
zgu@3544 63
zgu@3544 64 AbstractDecoder* Decoder::create_decoder() {
zgu@3544 65 AbstractDecoder* decoder;
zgu@3430 66 #if defined(_WINDOWS)
zgu@3544 67 decoder = new (std::nothrow) WindowsDecoder();
zgu@3430 68 #elif defined (__APPLE__)
zgu@3544 69 decoder = new (std::nothrow)MachODecoder();
zgu@3430 70 #else
zgu@3544 71 decoder = new (std::nothrow)ElfDecoder();
zgu@3430 72 #endif
zgu@3430 73
zgu@3544 74 if (decoder == NULL || decoder->has_error()) {
zgu@3544 75 if (decoder != NULL) {
zgu@3544 76 delete decoder;
zgu@3430 77 }
zgu@3544 78 decoder = &_do_nothing_decoder;
zgu@3430 79 }
zgu@3544 80 return decoder;
zgu@3430 81 }
zgu@3430 82
zgu@3430 83 bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const char* modulepath) {
zgu@3544 84 assert(_shared_decoder_lock != NULL, "Just check");
zgu@3544 85 bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
zgu@3544 86 MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
zgu@3544 87 AbstractDecoder* decoder = error_handling_thread ?
zgu@3544 88 get_error_handler_instance(): get_shared_instance();
zgu@3430 89 assert(decoder != NULL, "null decoder");
zgu@3430 90
zgu@3430 91 return decoder->decode(addr, buf, buflen, offset, modulepath);
zgu@3430 92 }
zgu@3430 93
zgu@3430 94 bool Decoder::demangle(const char* symbol, char* buf, int buflen) {
zgu@3544 95 assert(_shared_decoder_lock != NULL, "Just check");
zgu@3544 96 bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
zgu@3544 97 MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
zgu@3544 98 AbstractDecoder* decoder = error_handling_thread ?
zgu@3544 99 get_error_handler_instance(): get_shared_instance();
zgu@3430 100 assert(decoder != NULL, "null decoder");
zgu@3430 101 return decoder->demangle(symbol, buf, buflen);
zgu@3430 102 }
zgu@2364 103
zgu@2364 104 bool Decoder::can_decode_C_frame_in_vm() {
zgu@3544 105 assert(_shared_decoder_lock != NULL, "Just check");
zgu@3544 106 bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
zgu@3544 107 MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
zgu@3544 108 AbstractDecoder* decoder = error_handling_thread ?
zgu@3544 109 get_error_handler_instance(): get_shared_instance();
zgu@3430 110 assert(decoder != NULL, "null decoder");
zgu@3430 111 return decoder->can_decode_C_frame_in_vm();
zgu@2364 112 }
zgu@2364 113
zgu@3544 114 /*
zgu@3544 115 * Shutdown shared decoder and replace it with
zgu@3544 116 * _do_nothing_decoder. Do nothing with error handler
zgu@3544 117 * instance, since the JVM is going down.
zgu@3544 118 */
zgu@3430 119 void Decoder::shutdown() {
zgu@3544 120 assert(_shared_decoder_lock != NULL, "Just check");
zgu@3544 121 MutexLockerEx locker(_shared_decoder_lock, true);
zgu@3430 122
zgu@3544 123 if (_shared_decoder != NULL &&
zgu@3544 124 _shared_decoder != &_do_nothing_decoder) {
zgu@3544 125 delete _shared_decoder;
zgu@3430 126 }
zgu@3430 127
zgu@3544 128 _shared_decoder = &_do_nothing_decoder;
zgu@2364 129 }
zgu@2364 130

mercurial