src/hotspot/share/utilities/decoder.cpp
author mr
Tue, 29 Oct 2019 13:52:04 -0700
changeset 58850 f4290bf1cc21
parent 58579 05dd6144d434
permissions -rw-r--r--
8233137: runtime/ErrorHandling/VeryEarlyAssertTest.java fails after 8232080 Reviewed-by: stuefe, iignatyev, mchung
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
/*
54623
1126f0607c70 8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents: 52448
diff changeset
     2
 * Copyright (c) 1997, 2019, 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"
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47666
diff changeset
    26
#include "jvm.h"
48157
7c4d43c26352 8192061: Clean up allocation.inline.hpp includes
stefank
parents: 47765
diff changeset
    27
#include "memory/allocation.inline.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
47666
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
    32
#ifndef _WINDOWS
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
    33
#if defined(__APPLE__)
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    34
  #include "decoder_machO.hpp"
22827
07d991d45a51 8023033: PPC64 (part 13): basic changes for AIX
goetz
parents: 13963
diff changeset
    35
#elif defined(AIX)
07d991d45a51 8023033: PPC64 (part 13): basic changes for AIX
goetz
parents: 13963
diff changeset
    36
  #include "decoder_aix.hpp"
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    37
#else
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    38
  #include "decoder_elf.hpp"
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    39
#endif
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    40
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    41
AbstractDecoder*  Decoder::_shared_decoder = NULL;
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    42
AbstractDecoder*  Decoder::_error_handler_decoder = NULL;
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    43
NullDecoder       Decoder::_do_nothing_decoder;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    44
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    45
AbstractDecoder* Decoder::get_shared_instance() {
52448
bc5c7f63dbae 8213137: Remove static initialization of monitor/mutex instances
dholmes
parents: 48157
diff changeset
    46
  assert(shared_decoder_lock()->owned_by_self(), "Require DecoderLock to enter");
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    47
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    48
  if (_shared_decoder == NULL) {
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    49
    _shared_decoder = create_decoder();
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    50
  }
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    51
  return _shared_decoder;
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    52
}
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    53
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    54
AbstractDecoder* Decoder::get_error_handler_instance() {
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    55
  if (_error_handler_decoder == NULL) {
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    56
    _error_handler_decoder = create_decoder();
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    57
  }
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    58
  return _error_handler_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
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
AbstractDecoder* Decoder::create_decoder() {
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    63
  AbstractDecoder* decoder;
47666
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
    64
#if defined (__APPLE__)
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    65
  decoder = new (std::nothrow)MachODecoder();
22827
07d991d45a51 8023033: PPC64 (part 13): basic changes for AIX
goetz
parents: 13963
diff changeset
    66
#elif defined(AIX)
07d991d45a51 8023033: PPC64 (part 13): basic changes for AIX
goetz
parents: 13963
diff changeset
    67
  decoder = new (std::nothrow)AIXDecoder();
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    68
#else
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    69
  decoder = new (std::nothrow)ElfDecoder();
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    70
#endif
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    71
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    72
  if (decoder == NULL || decoder->has_error()) {
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    73
    if (decoder != NULL) {
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    74
      delete decoder;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    75
    }
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    76
    decoder = &_do_nothing_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
  return decoder;
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    79
}
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    80
19952
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 13963
diff changeset
    81
Mutex* Decoder::shared_decoder_lock() {
52448
bc5c7f63dbae 8213137: Remove static initialization of monitor/mutex instances
dholmes
parents: 48157
diff changeset
    82
  assert(SharedDecoder_lock != NULL, "Just check");
bc5c7f63dbae 8213137: Remove static initialization of monitor/mutex instances
dholmes
parents: 48157
diff changeset
    83
  return SharedDecoder_lock;
19952
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 13963
diff changeset
    84
}
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 13963
diff changeset
    85
31352
a6ab7217b5cc 8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents: 28163
diff changeset
    86
bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const char* modulepath, bool demangle) {
58579
05dd6144d434 8218543: ThreadsList handling during error reporting can crash
rehn
parents: 54662
diff changeset
    87
  bool error_handling_thread = os::current_thread_id() == VMError::get_first_error_tid();
54662
afce4a27f2c2 8213399: DecoderLocker is unused
coleenp
parents: 54623
diff changeset
    88
  if (error_handling_thread) {
afce4a27f2c2 8213399: DecoderLocker is unused
coleenp
parents: 54623
diff changeset
    89
    return get_error_handler_instance()->decode(addr, buf, buflen, offset, modulepath, demangle);
afce4a27f2c2 8213399: DecoderLocker is unused
coleenp
parents: 54623
diff changeset
    90
  } else {
afce4a27f2c2 8213399: DecoderLocker is unused
coleenp
parents: 54623
diff changeset
    91
    MutexLocker locker(shared_decoder_lock(), Mutex::_no_safepoint_check_flag);
afce4a27f2c2 8213399: DecoderLocker is unused
coleenp
parents: 54623
diff changeset
    92
    return get_shared_instance()->decode(addr, buf, buflen, offset, modulepath, demangle);
afce4a27f2c2 8213399: DecoderLocker is unused
coleenp
parents: 54623
diff changeset
    93
  }
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    94
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    95
}
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    96
13340
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 11761
diff changeset
    97
bool Decoder::decode(address addr, char* buf, int buflen, int* offset, const void* base) {
58579
05dd6144d434 8218543: ThreadsList handling during error reporting can crash
rehn
parents: 54662
diff changeset
    98
  bool error_handling_thread = os::current_thread_id() == VMError::get_first_error_tid();
54662
afce4a27f2c2 8213399: DecoderLocker is unused
coleenp
parents: 54623
diff changeset
    99
  if (error_handling_thread) {
afce4a27f2c2 8213399: DecoderLocker is unused
coleenp
parents: 54623
diff changeset
   100
    return get_error_handler_instance()->decode(addr, buf, buflen, offset, base);
afce4a27f2c2 8213399: DecoderLocker is unused
coleenp
parents: 54623
diff changeset
   101
  } else {
afce4a27f2c2 8213399: DecoderLocker is unused
coleenp
parents: 54623
diff changeset
   102
    MutexLocker locker(shared_decoder_lock(), Mutex::_no_safepoint_check_flag);
afce4a27f2c2 8213399: DecoderLocker is unused
coleenp
parents: 54623
diff changeset
   103
    return get_shared_instance()->decode(addr, buf, buflen, offset, base);
afce4a27f2c2 8213399: DecoderLocker is unused
coleenp
parents: 54623
diff changeset
   104
  }
13340
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 11761
diff changeset
   105
}
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 11761
diff changeset
   106
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 11761
diff changeset
   107
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   108
bool Decoder::demangle(const char* symbol, char* buf, int buflen) {
58579
05dd6144d434 8218543: ThreadsList handling during error reporting can crash
rehn
parents: 54662
diff changeset
   109
  bool error_handling_thread = os::current_thread_id() == VMError::get_first_error_tid();
54662
afce4a27f2c2 8213399: DecoderLocker is unused
coleenp
parents: 54623
diff changeset
   110
  if (error_handling_thread) {
afce4a27f2c2 8213399: DecoderLocker is unused
coleenp
parents: 54623
diff changeset
   111
    return get_error_handler_instance()->demangle(symbol, buf, buflen);
afce4a27f2c2 8213399: DecoderLocker is unused
coleenp
parents: 54623
diff changeset
   112
  } else {
afce4a27f2c2 8213399: DecoderLocker is unused
coleenp
parents: 54623
diff changeset
   113
    MutexLocker locker(shared_decoder_lock(), Mutex::_no_safepoint_check_flag);
afce4a27f2c2 8213399: DecoderLocker is unused
coleenp
parents: 54623
diff changeset
   114
    return get_shared_instance()->demangle(symbol, buf, buflen);
afce4a27f2c2 8213399: DecoderLocker is unused
coleenp
parents: 54623
diff changeset
   115
  }
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   116
}
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   117
47666
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   118
void Decoder::print_state_on(outputStream* st) {
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   119
}
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   120
47666
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   121
bool Decoder::get_source_info(address pc, char* buf, size_t buflen, int* line) {
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   122
  return false;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   123
}
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   124
47666
19219ec3f176 8185712: [windows] Improve native symbol decoder
goetz
parents: 47216
diff changeset
   125
#endif // !_WINDOWS
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents: 31352
diff changeset
   126