1 /* |
1 /* |
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
27 #define SHARE_VM_UTILITIES_DECODER_HPP |
27 #define SHARE_VM_UTILITIES_DECODER_HPP |
28 |
28 |
29 #include "memory/allocation.hpp" |
29 #include "memory/allocation.hpp" |
30 #include "runtime/mutex.hpp" |
30 #include "runtime/mutex.hpp" |
31 |
31 |
32 class NullDecoder: public CHeapObj { |
32 class AbstractDecoder : public CHeapObj { |
33 public: |
33 public: |
34 // status code for decoding native C frame |
34 // status code for decoding native C frame |
35 enum decoder_status { |
35 enum decoder_status { |
36 not_available = -10, // real decoder is not available |
36 not_available = -10, // real decoder is not available |
37 no_error = 0, // successfully decoded frames |
37 no_error = 0, // successfully decoded frames |
41 helper_not_found, // could not load dbghelp.dll (Windows only) |
41 helper_not_found, // could not load dbghelp.dll (Windows only) |
42 helper_func_error, // decoding functions not found (Windows only) |
42 helper_func_error, // decoding functions not found (Windows only) |
43 helper_init_error // SymInitialize failed (Windows only) |
43 helper_init_error // SymInitialize failed (Windows only) |
44 }; |
44 }; |
45 |
45 |
|
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: |
46 NullDecoder() { |
74 NullDecoder() { |
47 _decoder_status = not_available; |
75 _decoder_status = not_available; |
48 } |
76 } |
49 |
77 |
50 ~NullDecoder() {}; |
78 ~NullDecoder() {}; |
59 } |
87 } |
60 |
88 |
61 virtual bool can_decode_C_frame_in_vm() const { |
89 virtual bool can_decode_C_frame_in_vm() const { |
62 return false; |
90 return false; |
63 } |
91 } |
64 |
|
65 virtual decoder_status status() const { |
|
66 return _decoder_status; |
|
67 } |
|
68 |
|
69 virtual bool has_error() const { |
|
70 return is_error(_decoder_status); |
|
71 } |
|
72 |
|
73 static bool is_error(decoder_status status) { |
|
74 return (status > 0); |
|
75 } |
|
76 |
|
77 protected: |
|
78 decoder_status _decoder_status; |
|
79 }; |
92 }; |
80 |
93 |
81 |
94 |
82 class Decoder: AllStatic { |
95 class Decoder : AllStatic { |
83 public: |
96 public: |
84 static bool decode(address pc, char* buf, int buflen, int* offset, const char* modulepath = NULL); |
97 static bool decode(address pc, char* buf, int buflen, int* offset, const char* modulepath = NULL); |
85 static bool demangle(const char* symbol, char* buf, int buflen); |
98 static bool demangle(const char* symbol, char* buf, int buflen); |
86 static bool can_decode_C_frame_in_vm(); |
99 static bool can_decode_C_frame_in_vm(); |
87 |
100 |
|
101 // shutdown shared instance |
88 static void shutdown(); |
102 static void shutdown(); |
89 protected: |
103 protected: |
90 static NullDecoder* get_decoder(); |
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(); |
91 |
111 |
|
112 static AbstractDecoder* create_decoder(); |
92 private: |
113 private: |
93 static NullDecoder* _decoder; |
114 static AbstractDecoder* _shared_decoder; |
94 static NullDecoder _do_nothing_decoder; |
115 static AbstractDecoder* _error_handler_decoder; |
|
116 static NullDecoder _do_nothing_decoder; |
95 |
117 |
96 protected: |
118 protected: |
97 static Mutex* _decoder_lock; |
119 static Mutex* _shared_decoder_lock; |
98 }; |
120 }; |
99 |
121 |
100 #endif // SHARE_VM_UTILITIES_DECODER_HPP |
122 #endif // SHARE_VM_UTILITIES_DECODER_HPP |