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

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

mercurial