Mercurial > hg > truffle
annotate src/share/vm/utilities/decoder.hpp @ 6086:cdd249497b34
7170053: crash in C2 when using -XX:+CountCompiledCalls
Reviewed-by: kvn, twisti
Contributed-by: Krystal Mok <sajia@taobao.com>
author | twisti |
---|---|
date | Fri, 18 May 2012 12:20:24 -0700 |
parents | db006a85bf91 |
children | d2a62e0f25eb |
rev | line source |
---|---|
2022
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
1 /* |
4917 | 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
2022
2d4762ec74af
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. |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
4 * |
2d4762ec74af
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 |
2d4762ec74af
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 |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
8 * |
2d4762ec74af
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 |
2d4762ec74af
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 |
2d4762ec74af
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 |
2d4762ec74af
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 |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
13 * accompanied this code). |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
14 * |
2d4762ec74af
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 |
2d4762ec74af
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, |
2d4762ec74af
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. |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
18 * |
2d4762ec74af
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 |
2d4762ec74af
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 |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
21 * questions. |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
22 * |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
23 */ |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
24 |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
25 |
4803 | 26 #ifndef SHARE_VM_UTILITIES_DECODER_HPP |
27 #define SHARE_VM_UTILITIES_DECODER_HPP | |
2022
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
28 |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
29 #include "memory/allocation.hpp" |
4803 | 30 #include "runtime/mutex.hpp" |
2022
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
31 |
4917 | 32 class AbstractDecoder : public CHeapObj { |
4803 | 33 public: |
2022
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
34 // status code for decoding native C frame |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
35 enum decoder_status { |
4803 | 36 not_available = -10, // real decoder is not available |
37 no_error = 0, // successfully decoded frames | |
2022
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
38 out_of_memory, // out of memory |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
39 file_invalid, // invalid elf file |
2d4762ec74af
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 |
2d4762ec74af
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) |
2d4762ec74af
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) |
4803 | 43 helper_init_error // SymInitialize failed (Windows only) |
2022
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
44 }; |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
45 |
4917 | 46 // decode an pc address to corresponding function name and an offset from the beginning of |
47 // the function | |
48 virtual bool decode(address pc, char* buf, int buflen, int* offset, | |
49 const char* modulepath = NULL) = 0; | |
50 // demangle a C++ symbol | |
51 virtual bool demangle(const char* symbol, char* buf, int buflen) = 0; | |
52 // if the decoder can decode symbols in vm | |
53 virtual bool can_decode_C_frame_in_vm() const = 0; | |
54 | |
55 virtual decoder_status status() const { | |
56 return _decoder_status; | |
57 } | |
58 | |
59 virtual bool has_error() const { | |
60 return is_error(_decoder_status); | |
61 } | |
62 | |
63 static bool is_error(decoder_status status) { | |
64 return (status > 0); | |
65 } | |
66 | |
67 protected: | |
68 decoder_status _decoder_status; | |
69 }; | |
70 | |
71 // Do nothing decoder | |
72 class NullDecoder : public AbstractDecoder { | |
73 public: | |
4803 | 74 NullDecoder() { |
75 _decoder_status = not_available; | |
76 } | |
77 | |
78 ~NullDecoder() {}; | |
79 | |
80 virtual bool decode(address pc, char* buf, int buflen, int* offset, | |
81 const char* modulepath = NULL) { | |
82 return false; | |
83 } | |
84 | |
85 virtual bool demangle(const char* symbol, char* buf, int buflen) { | |
86 return false; | |
87 } | |
88 | |
89 virtual bool can_decode_C_frame_in_vm() const { | |
90 return false; | |
91 } | |
92 }; | |
93 | |
94 | |
4917 | 95 class Decoder : AllStatic { |
4803 | 96 public: |
97 static bool decode(address pc, char* buf, int buflen, int* offset, const char* modulepath = NULL); | |
98 static bool demangle(const char* symbol, char* buf, int buflen); | |
2022
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
99 static bool can_decode_C_frame_in_vm(); |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
100 |
4917 | 101 // shutdown shared instance |
4803 | 102 static void shutdown(); |
103 protected: | |
4917 | 104 // shared decoder instance, _shared_instance_lock is needed |
105 static AbstractDecoder* get_shared_instance(); | |
106 // a private instance for error handler. Error handler can be | |
107 // triggered almost everywhere, including signal handler, where | |
108 // no lock can be taken. So the shared decoder can not be used | |
109 // in this scenario. | |
110 static AbstractDecoder* get_error_handler_instance(); | |
2022
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
111 |
4917 | 112 static AbstractDecoder* create_decoder(); |
4803 | 113 private: |
4917 | 114 static AbstractDecoder* _shared_decoder; |
115 static AbstractDecoder* _error_handler_decoder; | |
116 static NullDecoder _do_nothing_decoder; | |
2022
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
117 |
4803 | 118 protected: |
4917 | 119 static Mutex* _shared_decoder_lock; |
2022
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
120 }; |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
diff
changeset
|
121 |
4803 | 122 #endif // SHARE_VM_UTILITIES_DECODER_HPP |