src/share/vm/utilities/decoder.cpp

Mon, 07 Oct 2013 14:10:29 +0400

author
vlivanov
date
Mon, 07 Oct 2013 14:10:29 +0400
changeset 5903
bf8a21c3ab3b
parent 5667
38f750491293
child 6198
55fb97c4c58d
child 6472
2b8e28fdf503
permissions
-rw-r--r--

8025849: Redundant "pid" in VM log file name (e.g. hotspot_pidpid12345.log)
Reviewed-by: twisti, azeemj

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

mercurial