0N/A/*
2362N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A *
0N/A */
0N/A
0N/A#include "precompiled.hpp"
0N/A#include "prims/jvm.h"
0N/A#include "runtime/mutexLocker.hpp"
0N/A#include "runtime/os.hpp"
0N/A#include "utilities/decoder.hpp"
0N/A#include "utilities/vmError.hpp"
0N/A
0N/A#if defined(_WINDOWS)
0N/A #include "decoder_windows.hpp"
0N/A#elif defined(__APPLE__)
0N/A #include "decoder_machO.hpp"
0N/A#else
0N/A #include "decoder_elf.hpp"
0N/A#endif
0N/A
AbstractDecoder* Decoder::_shared_decoder = NULL;
AbstractDecoder* Decoder::_error_handler_decoder = NULL;
NullDecoder Decoder::_do_nothing_decoder;
Mutex* Decoder::_shared_decoder_lock = new Mutex(Mutex::native,
"SharedDecoderLock");
AbstractDecoder* Decoder::get_shared_instance() {
assert(_shared_decoder_lock != NULL && _shared_decoder_lock->owned_by_self(),
"Require DecoderLock to enter");
if (_shared_decoder == NULL) {
_shared_decoder = create_decoder();
}
return _shared_decoder;
}
AbstractDecoder* Decoder::get_error_handler_instance() {
if (_error_handler_decoder == NULL) {
_error_handler_decoder = create_decoder();
}
return _error_handler_decoder;
}
AbstractDecoder* Decoder::create_decoder() {
AbstractDecoder* decoder;
#if defined(_WINDOWS)
decoder = new (std::nothrow) WindowsDecoder();
#elif defined (__APPLE__)
decoder = new (std::nothrow)MachODecoder();
#else
decoder = new (std::nothrow)ElfDecoder();
#endif
if (decoder == NULL || decoder->has_error()) {
if (decoder != NULL) {
delete decoder;
}
decoder = &_do_nothing_decoder;
}
return decoder;
}
bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const char* modulepath) {
assert(_shared_decoder_lock != NULL, "Just check");
bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
AbstractDecoder* decoder = error_handling_thread ?
get_error_handler_instance(): get_shared_instance();
assert(decoder != NULL, "null decoder");
return decoder->decode(addr, buf, buflen, offset, modulepath);
}
bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const void* base) {
assert(_shared_decoder_lock != NULL, "Just check");
bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
AbstractDecoder* decoder = error_handling_thread ?
get_error_handler_instance(): get_shared_instance();
assert(decoder != NULL, "null decoder");
return decoder->decode(addr, buf, buflen, offset, base);
}
bool Decoder::demangle(const char* symbol, char* buf, int buflen) {
assert(_shared_decoder_lock != NULL, "Just check");
bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
AbstractDecoder* decoder = error_handling_thread ?
get_error_handler_instance(): get_shared_instance();
assert(decoder != NULL, "null decoder");
return decoder->demangle(symbol, buf, buflen);
}
bool Decoder::can_decode_C_frame_in_vm() {
assert(_shared_decoder_lock != NULL, "Just check");
bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
AbstractDecoder* decoder = error_handling_thread ?
get_error_handler_instance(): get_shared_instance();
assert(decoder != NULL, "null decoder");
return decoder->can_decode_C_frame_in_vm();
}
/*
* Shutdown shared decoder and replace it with
* _do_nothing_decoder. Do nothing with error handler
* instance, since the JVM is going down.
*/
void Decoder::shutdown() {
assert(_shared_decoder_lock != NULL, "Just check");
MutexLockerEx locker(_shared_decoder_lock, true);
if (_shared_decoder != NULL &&
_shared_decoder != &_do_nothing_decoder) {
delete _shared_decoder;
}
_shared_decoder = &_do_nothing_decoder;
}