src/hotspot/share/utilities/decoder.hpp
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 47086 hotspot/src/share/vm/utilities/decoder.hpp@2b35673f6297
child 47666 19219ec3f176
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
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
/*
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 31352
diff changeset
     2
 * Copyright (c) 1997, 2015, 2017, 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
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    26
#ifndef SHARE_VM_UTILITIES_DECODER_HPP
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    27
#define SHARE_VM_UTILITIES_DECODER_HPP
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    28
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    29
#include "memory/allocation.hpp"
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    30
#include "runtime/mutex.hpp"
19952
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 13340
diff changeset
    31
#include "runtime/mutexLocker.hpp"
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents: 46630
diff changeset
    32
#include "utilities/ostream.hpp"
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    33
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11761
diff changeset
    34
class AbstractDecoder : public CHeapObj<mtInternal> {
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    35
public:
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 31352
diff changeset
    36
  virtual ~AbstractDecoder() {}
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 31352
diff changeset
    37
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    38
  // status code for decoding native C frame
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    39
  enum decoder_status {
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    40
         not_available = -10,  // real decoder is not available
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    41
         no_error = 0,         // successfully decoded frames
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    42
         out_of_memory,        // out of memory
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    43
         file_invalid,         // invalid elf file
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    44
         file_not_found,       // could not found symbol file (on windows), such as jvm.pdb or jvm.map
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    45
         helper_func_error,    // decoding functions not found (Windows only)
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    46
         helper_init_error     // SymInitialize failed (Windows only)
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    47
  };
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    48
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    49
  // decode an pc address to corresponding function name and an offset from the beginning of
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    50
  // the function
31352
a6ab7217b5cc 8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents: 22234
diff changeset
    51
  //
a6ab7217b5cc 8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents: 22234
diff changeset
    52
  // Note: the 'base' variant does not demangle names. The
a6ab7217b5cc 8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents: 22234
diff changeset
    53
  // demangling that was done systematically in the 'modulepath' variant
a6ab7217b5cc 8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents: 22234
diff changeset
    54
  // is now optional.
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    55
  virtual bool decode(address pc, char* buf, int buflen, int* offset,
31352
a6ab7217b5cc 8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents: 22234
diff changeset
    56
                      const char* modulepath = NULL, bool demangle = true) = 0;
13340
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 13195
diff changeset
    57
  virtual bool decode(address pc, char* buf, int buflen, int* offset, const void* base) = 0;
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 13195
diff changeset
    58
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    59
  // demangle a C++ symbol
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    60
  virtual bool demangle(const char* symbol, char* buf, int buflen) = 0;
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    61
  // if the decoder can decode symbols in vm
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    62
  virtual bool can_decode_C_frame_in_vm() const = 0;
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
  virtual decoder_status status() const {
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    65
    return _decoder_status;
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    66
  }
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    67
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    68
  virtual bool has_error() const {
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    69
    return is_error(_decoder_status);
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    70
  }
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    71
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    72
  static bool is_error(decoder_status status) {
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    73
    return (status > 0);
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    74
  }
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    75
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    76
protected:
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    77
  decoder_status  _decoder_status;
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    78
};
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    79
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    80
// Do nothing decoder
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    81
class NullDecoder : public AbstractDecoder {
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
    82
public:
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    83
  NullDecoder() {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    84
    _decoder_status = not_available;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    85
  }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    86
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 31352
diff changeset
    87
  virtual ~NullDecoder() {};
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    88
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    89
  virtual bool decode(address pc, char* buf, int buflen, int* offset,
31352
a6ab7217b5cc 8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents: 22234
diff changeset
    90
                      const char* modulepath, bool demangle) {
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    91
    return false;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    92
  }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    93
13340
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 13195
diff changeset
    94
  virtual bool decode(address pc, char* buf, int buflen, int* offset, const void* base) {
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 13195
diff changeset
    95
    return false;
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 13195
diff changeset
    96
  }
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 13195
diff changeset
    97
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    98
  virtual bool demangle(const char* symbol, char* buf, int buflen) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    99
    return false;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   100
  }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   101
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   102
  virtual bool can_decode_C_frame_in_vm() const {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   103
    return false;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   104
  }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   105
};
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   106
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   107
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   108
class Decoder : AllStatic {
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   109
public:
31352
a6ab7217b5cc 8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents: 22234
diff changeset
   110
  static bool decode(address pc, char* buf, int buflen, int* offset, const char* modulepath = NULL, bool demangle = true);
a6ab7217b5cc 8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents: 22234
diff changeset
   111
  static bool decode(address pc, char* buf, int buflen, int* offset, bool demangle) {
a6ab7217b5cc 8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents: 22234
diff changeset
   112
    return decode(pc, buf, buflen, offset, (const char*) NULL, demangle);
a6ab7217b5cc 8079473: allow demangling to be optional in dll_address_to_function_name
bdelsart
parents: 22234
diff changeset
   113
  }
13340
40c424a6ff53 7186778: MachO decoder implementation for MacOSX
zgu
parents: 13195
diff changeset
   114
  static bool decode(address pc, char* buf, int buflen, int* offset, const void* base);
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   115
  static bool demangle(const char* symbol, char* buf, int buflen);
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   116
  static bool can_decode_C_frame_in_vm();
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   117
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   118
  // shutdown shared instance
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   119
  static void shutdown();
47086
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents: 46630
diff changeset
   120
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents: 46630
diff changeset
   121
  static void print_state_on(outputStream* st);
2b35673f6297 8186349: [windows] Centralize dbghelp handling code
stuefe
parents: 46630
diff changeset
   122
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   123
protected:
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   124
  // shared decoder instance, _shared_instance_lock is needed
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   125
  static AbstractDecoder* get_shared_instance();
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   126
  // a private instance for error handler. Error handler can be
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   127
  // triggered almost everywhere, including signal handler, where
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   128
  // no lock can be taken. So the shared decoder can not be used
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   129
  // in this scenario.
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   130
  static AbstractDecoder* get_error_handler_instance();
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   131
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   132
  static AbstractDecoder* create_decoder();
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   133
private:
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   134
  static AbstractDecoder*     _shared_decoder;
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   135
  static AbstractDecoder*     _error_handler_decoder;
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   136
  static NullDecoder          _do_nothing_decoder;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   137
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   138
protected:
11761
bf460b379a6a 7141259: Native stack is missing in hs_err
zgu
parents: 11483
diff changeset
   139
  static Mutex*               _shared_decoder_lock;
19952
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 13340
diff changeset
   140
  static Mutex* shared_decoder_lock();
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 13340
diff changeset
   141
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 13340
diff changeset
   142
  friend class DecoderLocker;
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 13340
diff changeset
   143
};
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 13340
diff changeset
   144
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 13340
diff changeset
   145
class DecoderLocker : public MutexLockerEx {
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 13340
diff changeset
   146
  AbstractDecoder* _decoder;
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 13340
diff changeset
   147
  inline bool is_first_error_thread();
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 13340
diff changeset
   148
public:
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 13340
diff changeset
   149
  DecoderLocker();
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 13340
diff changeset
   150
  AbstractDecoder* decoder() {
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 13340
diff changeset
   151
    return _decoder;
bc974e92f881 8022335: Native stack walk while generating hs_err does not work on Windows x64
iklam
parents: 13340
diff changeset
   152
  }
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   153
};
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
   154
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   155
#endif // SHARE_VM_UTILITIES_DECODER_HPP