src/share/vm/utilities/decoder.cpp

Thu, 22 May 2014 15:52:41 -0400

author
drchase
date
Thu, 22 May 2014 15:52:41 -0400
changeset 6680
78bbf4d43a14
parent 6503
a9becfeecd1b
child 6876
710a3c8b516e
permissions
-rw-r--r--

8037816: Fix for 8036122 breaks build with Xcode5/clang
8043029: Change 8037816 breaks HS build with older GCC versions which don't support diagnostic pragmas
8043164: Format warning in traceStream.hpp
Summary: Backport of main fix + two corrections, enables clang compilation, turns on format attributes, corrects/mutes warnings
Reviewed-by: kvn, coleenp, iveresov, twisti

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

mercurial