decoder.hpp 3.0 KB
Newer Older
1
/*
Z
zgu 已提交
2
 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 *
 */


Z
zgu 已提交
26 27
#ifndef SHARE_VM_UTILITIES_DECODER_HPP
#define SHARE_VM_UTILITIES_DECODER_HPP
28 29

#include "memory/allocation.hpp"
Z
zgu 已提交
30
#include "runtime/mutex.hpp"
31

Z
zgu 已提交
32 33
class NullDecoder: public CHeapObj {
public:
34 35
  // status code for decoding native C frame
  enum decoder_status {
Z
zgu 已提交
36 37
         not_available = -10,  // real decoder is not available
         no_error = 0,         // successfully decoded frames
38 39 40 41 42
         out_of_memory,        // out of memory
         file_invalid,         // invalid elf file
         file_not_found,       // could not found symbol file (on windows), such as jvm.pdb or jvm.map
         helper_not_found,     // could not load dbghelp.dll (Windows only)
         helper_func_error,    // decoding functions not found (Windows only)
Z
zgu 已提交
43
         helper_init_error     // SymInitialize failed (Windows only)
44 45
  };

Z
zgu 已提交
46 47 48
  NullDecoder() {
    _decoder_status = not_available;
  }
49

Z
zgu 已提交
50 51 52 53 54 55
  ~NullDecoder() {};

  virtual bool decode(address pc, char* buf, int buflen, int* offset,
    const char* modulepath = NULL) {
    return false;
  }
56

Z
zgu 已提交
57 58 59
  virtual bool demangle(const char* symbol, char* buf, int buflen) {
    return false;
  }
60

Z
zgu 已提交
61 62 63
  virtual bool can_decode_C_frame_in_vm() const {
    return false;
  }
64

Z
zgu 已提交
65 66 67
  virtual decoder_status status() const {
    return _decoder_status;
  }
68

Z
zgu 已提交
69 70 71
  virtual bool has_error() const {
    return is_error(_decoder_status);
  }
72

Z
zgu 已提交
73 74 75 76 77 78 79 80 81 82 83 84 85 86
  static bool is_error(decoder_status status) {
    return (status > 0);
  }

protected:
  decoder_status  _decoder_status;
};


class Decoder: AllStatic {
public:
  static bool decode(address pc, char* buf, int buflen, int* offset, const char* modulepath = NULL);
  static bool demangle(const char* symbol, char* buf, int buflen);
  static bool can_decode_C_frame_in_vm();
87

Z
zgu 已提交
88 89 90
  static void shutdown();
protected:
  static NullDecoder* get_decoder();
91

Z
zgu 已提交
92 93 94
private:
  static NullDecoder*     _decoder;
  static NullDecoder      _do_nothing_decoder;
95

Z
zgu 已提交
96 97
protected:
  static Mutex*       _decoder_lock;
98 99
};

Z
zgu 已提交
100
#endif // SHARE_VM_UTILITIES_DECODER_HPP