< prev index next >

src/share/vm/utilities/decoder.hpp

Print this page
rev 13549 : 8185712: [windows] Improve native symbol decoder
Reviewed-by: goetz, zgu
   1 /*
   2  * Copyright (c) 1997, 2015, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


  41          no_error = 0,         // successfully decoded frames
  42          out_of_memory,        // out of memory
  43          file_invalid,         // invalid elf file
  44          file_not_found,       // could not found symbol file (on windows), such as jvm.pdb or jvm.map
  45          helper_func_error,    // decoding functions not found (Windows only)
  46          helper_init_error     // SymInitialize failed (Windows only)
  47   };
  48 
  49   // decode an pc address to corresponding function name and an offset from the beginning of
  50   // the function
  51   //
  52   // Note: the 'base' variant does not demangle names. The
  53   // demangling that was done systematically in the 'modulepath' variant
  54   // is now optional.
  55   virtual bool decode(address pc, char* buf, int buflen, int* offset,
  56                       const char* modulepath = NULL, bool demangle = true) = 0;
  57   virtual bool decode(address pc, char* buf, int buflen, int* offset, const void* base) = 0;
  58 
  59   // demangle a C++ symbol
  60   virtual bool demangle(const char* symbol, char* buf, int buflen) = 0;
  61   // if the decoder can decode symbols in vm
  62   virtual bool can_decode_C_frame_in_vm() const = 0;
  63 
  64   virtual decoder_status status() const {
  65     return _decoder_status;
  66   }
  67 
  68   virtual bool has_error() const {
  69     return is_error(_decoder_status);
  70   }
  71 
  72   static bool is_error(decoder_status status) {
  73     return (status > 0);
  74   }
  75 
  76 protected:
  77   decoder_status  _decoder_status;
  78 };
  79 
  80 // Do nothing decoder
  81 class NullDecoder : public AbstractDecoder {
  82 public:
  83   NullDecoder() {
  84     _decoder_status = not_available;
  85   }
  86 
  87   virtual ~NullDecoder() {};
  88 
  89   virtual bool decode(address pc, char* buf, int buflen, int* offset,
  90                       const char* modulepath, bool demangle) {
  91     return false;
  92   }
  93 
  94   virtual bool decode(address pc, char* buf, int buflen, int* offset, const void* base) {
  95     return false;
  96   }
  97 
  98   virtual bool demangle(const char* symbol, char* buf, int buflen) {
  99     return false;
 100   }
 101 
 102   virtual bool can_decode_C_frame_in_vm() const {
 103     return false;
 104   }
 105 };
 106 
 107 
 108 class Decoder : AllStatic {
 109 public:
 110   static bool decode(address pc, char* buf, int buflen, int* offset, const char* modulepath = NULL, bool demangle = true);
 111   static bool decode(address pc, char* buf, int buflen, int* offset, bool demangle) {
 112     return decode(pc, buf, buflen, offset, (const char*) NULL, demangle);
 113   }
 114   static bool decode(address pc, char* buf, int buflen, int* offset, const void* base);
 115   static bool demangle(const char* symbol, char* buf, int buflen);
 116   static bool can_decode_C_frame_in_vm();
 117 
 118   // shutdown shared instance
 119   static void shutdown();


 120 
 121   static void print_state_on(outputStream* st);
 122 
 123 protected:
 124   // shared decoder instance, _shared_instance_lock is needed
 125   static AbstractDecoder* get_shared_instance();
 126   // a private instance for error handler. Error handler can be
 127   // triggered almost everywhere, including signal handler, where
 128   // no lock can be taken. So the shared decoder can not be used
 129   // in this scenario.
 130   static AbstractDecoder* get_error_handler_instance();
 131 
 132   static AbstractDecoder* create_decoder();
 133 private:
 134   static AbstractDecoder*     _shared_decoder;
 135   static AbstractDecoder*     _error_handler_decoder;
 136   static NullDecoder          _do_nothing_decoder;
 137 
 138 protected:
 139   static Mutex*               _shared_decoder_lock;
   1 /*
   2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


  41          no_error = 0,         // successfully decoded frames
  42          out_of_memory,        // out of memory
  43          file_invalid,         // invalid elf file
  44          file_not_found,       // could not found symbol file (on windows), such as jvm.pdb or jvm.map
  45          helper_func_error,    // decoding functions not found (Windows only)
  46          helper_init_error     // SymInitialize failed (Windows only)
  47   };
  48 
  49   // decode an pc address to corresponding function name and an offset from the beginning of
  50   // the function
  51   //
  52   // Note: the 'base' variant does not demangle names. The
  53   // demangling that was done systematically in the 'modulepath' variant
  54   // is now optional.
  55   virtual bool decode(address pc, char* buf, int buflen, int* offset,
  56                       const char* modulepath = NULL, bool demangle = true) = 0;
  57   virtual bool decode(address pc, char* buf, int buflen, int* offset, const void* base) = 0;
  58 
  59   // demangle a C++ symbol
  60   virtual bool demangle(const char* symbol, char* buf, int buflen) = 0;


  61 
  62   virtual decoder_status status() const {
  63     return _decoder_status;
  64   }
  65 
  66   virtual bool has_error() const {
  67     return is_error(_decoder_status);
  68   }
  69 
  70   static bool is_error(decoder_status status) {
  71     return (status > 0);
  72   }
  73 
  74 protected:
  75   decoder_status  _decoder_status;
  76 };
  77 
  78 // Do nothing decoder
  79 class NullDecoder : public AbstractDecoder {
  80 public:
  81   NullDecoder() {
  82     _decoder_status = not_available;
  83   }
  84 
  85   virtual ~NullDecoder() {};
  86 
  87   virtual bool decode(address pc, char* buf, int buflen, int* offset,
  88                       const char* modulepath, bool demangle) {
  89     return false;
  90   }
  91 
  92   virtual bool decode(address pc, char* buf, int buflen, int* offset, const void* base) {
  93     return false;
  94   }
  95 
  96   virtual bool demangle(const char* symbol, char* buf, int buflen) {
  97     return false;
  98   }
  99 



 100 };
 101 
 102 
 103 class Decoder : AllStatic {
 104 public:
 105   static bool decode(address pc, char* buf, int buflen, int* offset, const char* modulepath = NULL, bool demangle = true);
 106   static bool decode(address pc, char* buf, int buflen, int* offset, bool demangle) {
 107     return decode(pc, buf, buflen, offset, (const char*) NULL, demangle);
 108   }
 109   static bool decode(address pc, char* buf, int buflen, int* offset, const void* base);
 110   static bool demangle(const char* symbol, char* buf, int buflen);

 111 
 112   // Attempts to retrieve source file name and line number associated with a pc.
 113   // If buf != NULL, points to a buffer of size buflen which will receive the
 114   // file name. File name will be silently truncated if output buffer is too small.
 115   static bool get_source_info(address pc, char* buf, size_t buflen, int* line);
 116 
 117   static void print_state_on(outputStream* st);
 118 
 119 protected:
 120   // shared decoder instance, _shared_instance_lock is needed
 121   static AbstractDecoder* get_shared_instance();
 122   // a private instance for error handler. Error handler can be
 123   // triggered almost everywhere, including signal handler, where
 124   // no lock can be taken. So the shared decoder can not be used
 125   // in this scenario.
 126   static AbstractDecoder* get_error_handler_instance();
 127 
 128   static AbstractDecoder* create_decoder();
 129 private:
 130   static AbstractDecoder*     _shared_decoder;
 131   static AbstractDecoder*     _error_handler_decoder;
 132   static NullDecoder          _do_nothing_decoder;
 133 
 134 protected:
 135   static Mutex*               _shared_decoder_lock;
< prev index next >