hotspot/src/share/vm/utilities/decoder.cpp
author jprovino
Wed, 23 Jan 2013 13:02:39 -0500
changeset 15482 470d0b0c09f1
parent 13963 e5b53c306fb5
child 19952 bc974e92f881
child 22827 07d991d45a51
permissions -rw-r--r--
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS Summary: Rename INCLUDE_ALTERNATE_GCS to INCLUDE_ALL_GCS and replace SERIALGC with INCLUDE_ALL_GCS. Reviewed-by: coleenp, stefank
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     1
/*
13963
e5b53c306fb5 7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents: 13340
diff changeset
     2
 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     4
 *
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     7
 * published by the Free Software Foundation.
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     8
 *
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    13
 * accompanied this code).
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    14
 *
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    18
 *
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    21
 * questions.
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    22
 *
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    23
 */
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    24
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    25
#include "precompiled.hpp"
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    26
#include "prims/jvm.h"
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    27
#include "runtime/mutexLocker.hpp"
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    28
#include "runtime/os.hpp"
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    29
#include "utilities/decoder.hpp"
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    30
#include "utilities/vmError.hpp"
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    31
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    32
#if defined(_WINDOWS)
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    33
  #include "decoder_windows.hpp"
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    34
#elif defined(__APPLE__)
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    35
  #include "decoder_machO.hpp"
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    36
#else
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    37
  #include "decoder_elf.hpp"
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    38
#endif
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    39
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    40
AbstractDecoder*  Decoder::_shared_decoder = NULL;
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    41
AbstractDecoder*  Decoder::_error_handler_decoder = NULL;
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    42
NullDecoder       Decoder::_do_nothing_decoder;
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    43
Mutex*            Decoder::_shared_decoder_lock = new Mutex(Mutex::native,
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    44
                                "SharedDecoderLock");
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    45
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    46
AbstractDecoder* Decoder::get_shared_instance() {
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    47
  assert(_shared_decoder_lock != NULL && _shared_decoder_lock->owned_by_self(),
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    48
    "Require DecoderLock to enter");
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    49
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    50
  if (_shared_decoder == NULL) {
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    51
    _shared_decoder = create_decoder();
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    52
  }
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    53
  return _shared_decoder;
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    54
}
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    55
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    56
AbstractDecoder* Decoder::get_error_handler_instance() {
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    57
  if (_error_handler_decoder == NULL) {
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    58
    _error_handler_decoder = create_decoder();
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    59
  }
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    60
  return _error_handler_decoder;
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    61
}
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    62
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    63
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    64
AbstractDecoder* Decoder::create_decoder() {
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    65
  AbstractDecoder* decoder;
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    66
#if defined(_WINDOWS)
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    67
  decoder = new (std::nothrow) WindowsDecoder();
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    68
#elif defined (__APPLE__)
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    69
  decoder = new (std::nothrow)MachODecoder();
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    70
#else
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    71
  decoder = new (std::nothrow)ElfDecoder();
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    72
#endif
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    73
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    74
  if (decoder == NULL || decoder->has_error()) {
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    75
    if (decoder != NULL) {
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    76
      delete decoder;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    77
    }
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    78
    decoder = &_do_nothing_decoder;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    79
  }
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    80
  return decoder;
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    81
}
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    82
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    83
bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const char* modulepath) {
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    84
  assert(_shared_decoder_lock != NULL, "Just check");
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    85
  bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    86
  MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    87
  AbstractDecoder* decoder = error_handling_thread ?
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    88
    get_error_handler_instance(): get_shared_instance();
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    89
  assert(decoder != NULL, "null decoder");
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    90
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    91
  return decoder->decode(addr, buf, buflen, offset, modulepath);
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    92
}
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    93
13340
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 11761
diff changeset
    94
bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const void* base) {
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 11761
diff changeset
    95
  assert(_shared_decoder_lock != NULL, "Just check");
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 11761
diff changeset
    96
  bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 11761
diff changeset
    97
  MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 11761
diff changeset
    98
  AbstractDecoder* decoder = error_handling_thread ?
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 11761
diff changeset
    99
    get_error_handler_instance(): get_shared_instance();
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 11761
diff changeset
   100
  assert(decoder != NULL, "null decoder");
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 11761
diff changeset
   101
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 11761
diff changeset
   102
  return decoder->decode(addr, buf, buflen, offset, base);
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 11761
diff changeset
   103
}
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 11761
diff changeset
   104
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 11761
diff changeset
   105
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   106
bool Decoder::demangle(const char* symbol, char* buf, int buflen) {
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   107
  assert(_shared_decoder_lock != NULL, "Just check");
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   108
  bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   109
  MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   110
  AbstractDecoder* decoder = error_handling_thread ?
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   111
    get_error_handler_instance(): get_shared_instance();
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   112
  assert(decoder != NULL, "null decoder");
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   113
  return decoder->demangle(symbol, buf, buflen);
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   114
}
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   115
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   116
bool Decoder::can_decode_C_frame_in_vm() {
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   117
  assert(_shared_decoder_lock != NULL, "Just check");
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   118
  bool error_handling_thread = os::current_thread_id() == VMError::first_error_tid;
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   119
  MutexLockerEx locker(error_handling_thread ? NULL : _shared_decoder_lock, true);
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   120
  AbstractDecoder* decoder = error_handling_thread ?
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   121
    get_error_handler_instance(): get_shared_instance();
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   122
  assert(decoder != NULL, "null decoder");
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   123
  return decoder->can_decode_C_frame_in_vm();
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   124
}
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   125
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   126
/*
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   127
 * Shutdown shared decoder and replace it with
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   128
 * _do_nothing_decoder. Do nothing with error handler
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   129
 * instance, since the JVM is going down.
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   130
 */
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   131
void Decoder::shutdown() {
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   132
  assert(_shared_decoder_lock != NULL, "Just check");
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   133
  MutexLockerEx locker(_shared_decoder_lock, true);
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   134
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   135
  if (_shared_decoder != NULL &&
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   136
    _shared_decoder != &_do_nothing_decoder) {
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   137
    delete _shared_decoder;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   138
  }
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   139
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   140
  _shared_decoder = &_do_nothing_decoder;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   141
}
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   142