comparison src/share/vm/utilities/decoder.hpp @ 4803:d7e3846464d0

7071311: Decoder enhancement Summary: Made decoder thread-safe Reviewed-by: coleenp, kamg
author zgu
date Tue, 17 Jan 2012 13:08:52 -0500
parents f08d439fab8c
children db006a85bf91
comparison
equal deleted inserted replaced
4801:4f3ce9284781 4803:d7e3846464d0
1 /* 1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2011, 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.
21 * questions. 21 * questions.
22 * 22 *
23 */ 23 */
24 24
25 25
26 #ifndef __DECODER_HPP 26 #ifndef SHARE_VM_UTILITIES_DECODER_HPP
27 #define __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 31
31 #ifdef _WINDOWS 32 class NullDecoder: public CHeapObj {
32 #include <windows.h> 33 public:
33 #include <imagehlp.h>
34
35 // functions needed for decoding symbols
36 typedef DWORD (WINAPI *pfn_SymSetOptions)(DWORD);
37 typedef BOOL (WINAPI *pfn_SymInitialize)(HANDLE, PCTSTR, BOOL);
38 typedef BOOL (WINAPI *pfn_SymGetSymFromAddr64)(HANDLE, DWORD64, PDWORD64, PIMAGEHLP_SYMBOL64);
39 typedef DWORD (WINAPI *pfn_UndecorateSymbolName)(const char*, char*, DWORD, DWORD);
40
41 #elif defined(__APPLE__)
42
43 #else
44
45 class ElfFile;
46
47 #endif // _WINDOWS
48
49
50 class Decoder: public StackObj {
51
52 public:
53 // status code for decoding native C frame 34 // status code for decoding native C frame
54 enum decoder_status { 35 enum decoder_status {
55 no_error, // successfully decoded frames 36 not_available = -10, // real decoder is not available
37 no_error = 0, // successfully decoded frames
56 out_of_memory, // out of memory 38 out_of_memory, // out of memory
57 file_invalid, // invalid elf file 39 file_invalid, // invalid elf file
58 file_not_found, // could not found symbol file (on windows), such as jvm.pdb or jvm.map 40 file_not_found, // could not found symbol file (on windows), such as jvm.pdb or jvm.map
59 helper_not_found, // could not load dbghelp.dll (Windows only) 41 helper_not_found, // could not load dbghelp.dll (Windows only)
60 helper_func_error, // decoding functions not found (Windows only) 42 helper_func_error, // decoding functions not found (Windows only)
61 helper_init_error, // SymInitialize failed (Windows only) 43 helper_init_error // SymInitialize failed (Windows only)
62 symbol_not_found // could not find the symbol
63 }; 44 };
64 45
65 public: 46 NullDecoder() {
66 Decoder() { initialize(); }; 47 _decoder_status = not_available;
67 ~Decoder() { uninitialize(); }; 48 }
68 49
50 ~NullDecoder() {};
51
52 virtual bool decode(address pc, char* buf, int buflen, int* offset,
53 const char* modulepath = NULL) {
54 return false;
55 }
56
57 virtual bool demangle(const char* symbol, char* buf, int buflen) {
58 return false;
59 }
60
61 virtual bool can_decode_C_frame_in_vm() const {
62 return false;
63 }
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 };
80
81
82 class Decoder: AllStatic {
83 public:
84 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);
69 static bool can_decode_C_frame_in_vm(); 86 static bool can_decode_C_frame_in_vm();
70 87
71 static void initialize(); 88 static void shutdown();
72 static void uninitialize(); 89 protected:
90 static NullDecoder* get_decoder();
73 91
74 #ifdef _WINDOWS 92 private:
75 static decoder_status decode(address addr, char *buf, int buflen, int *offset); 93 static NullDecoder* _decoder;
76 #else 94 static NullDecoder _do_nothing_decoder;
77 static decoder_status decode(address addr, const char* filepath, char *buf, int buflen, int *offset);
78 #endif
79 95
80 static bool demangle(const char* symbol, char *buf, int buflen); 96 protected:
81 97 static Mutex* _decoder_lock;
82 static decoder_status get_status() { return _decoder_status; };
83
84 #if !defined(_WINDOWS) && !defined(__APPLE__)
85 private:
86 static ElfFile* get_elf_file(const char* filepath);
87 #endif // _WINDOWS
88
89
90 private:
91 static decoder_status _decoder_status;
92 static bool _initialized;
93
94 #ifdef _WINDOWS
95 static HMODULE _dbghelp_handle;
96 static bool _can_decode_in_vm;
97 static pfn_SymGetSymFromAddr64 _pfnSymGetSymFromAddr64;
98 static pfn_UndecorateSymbolName _pfnUndecorateSymbolName;
99 #elif __APPLE__
100 #else
101 static ElfFile* _opened_elf_files;
102 #endif // _WINDOWS
103 }; 98 };
104 99
105 #endif // __DECODER_HPP 100 #endif // SHARE_VM_UTILITIES_DECODER_HPP