hotspot/src/share/vm/utilities/decoder.hpp
author zgu
Tue, 17 Jan 2012 13:08:52 -0500
changeset 11483 4d3f4bca0019
parent 10565 dc90c239f4ec
child 11761 bf460b379a6a
permissions -rw-r--r--
7071311: Decoder enhancement Summary: Made decoder thread-safe Reviewed-by: coleenp, kamg
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
/*
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
     2
 * Copyright (c) 1997, 2011, 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"
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
class NullDecoder: public CHeapObj {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    33
public:
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    34
  // status code for decoding native C frame
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    35
  enum decoder_status {
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    36
         not_available = -10,  // real decoder is not available
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    37
         no_error = 0,         // successfully decoded frames
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    38
         out_of_memory,        // out of memory
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    39
         file_invalid,         // invalid elf file
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    40
         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
    41
         helper_not_found,     // could not load dbghelp.dll (Windows only)
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    42
         helper_func_error,    // decoding functions not found (Windows only)
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    43
         helper_init_error     // SymInitialize failed (Windows only)
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    44
  };
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    45
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    46
  NullDecoder() {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    47
    _decoder_status = not_available;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    48
  }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    49
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    50
  ~NullDecoder() {};
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    51
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    52
  virtual bool decode(address pc, char* buf, int buflen, int* offset,
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    53
    const char* modulepath = NULL) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    54
    return false;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    55
  }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    56
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    57
  virtual bool demangle(const char* symbol, char* buf, int buflen) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    58
    return false;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    59
  }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    60
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    61
  virtual bool can_decode_C_frame_in_vm() const {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    62
    return false;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    63
  }
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    64
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    65
  virtual decoder_status status() const {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    66
    return _decoder_status;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    67
  }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    68
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    69
  virtual bool has_error() const {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    70
    return is_error(_decoder_status);
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    71
  }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    72
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    73
  static bool is_error(decoder_status status) {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    74
    return (status > 0);
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    75
  }
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    76
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    77
protected:
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    78
  decoder_status  _decoder_status;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    79
};
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    80
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    81
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    82
class Decoder: AllStatic {
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    83
public:
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    84
  static bool decode(address pc, char* buf, int buflen, int* offset, const char* modulepath = NULL);
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    85
  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
    86
  static bool can_decode_C_frame_in_vm();
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    87
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    88
  static void shutdown();
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    89
protected:
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    90
  static NullDecoder* get_decoder();
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    91
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    92
private:
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    93
  static NullDecoder*     _decoder;
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    94
  static NullDecoder      _do_nothing_decoder;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    95
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    96
protected:
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
    97
  static Mutex*       _decoder_lock;
7447
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    98
};
32c42d627f41 7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff changeset
    99
11483
4d3f4bca0019 7071311: Decoder enhancement
zgu
parents: 10565
diff changeset
   100
#endif // SHARE_VM_UTILITIES_DECODER_HPP