1 /*
   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.
   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  *
  23  */
  24 
  25 
  26 #ifndef SHARE_VM_UTILITIES_DECODER_HPP
  27 #define SHARE_VM_UTILITIES_DECODER_HPP
  28 
  29 #include "memory/allocation.hpp"
  30 #include "runtime/mutex.hpp"
  31 
  32 class NullDecoder: public CHeapObj {
  33 public:
  34   // status code for decoding native C frame
  35   enum decoder_status {
  36          not_available = -10,  // real decoder is not available
  37          no_error = 0,         // successfully decoded frames
  38          out_of_memory,        // out of memory
  39          file_invalid,         // invalid elf file
  40          file_not_found,       // could not found symbol file (on windows), such as jvm.pdb or jvm.map
  41          helper_not_found,     // could not load dbghelp.dll (Windows only)
  42          helper_func_error,    // decoding functions not found (Windows only)
  43          helper_init_error     // SymInitialize failed (Windows only)
  44   };
  45 
  46   NullDecoder() { 
  47     _decoder_status = not_available;
  48   }
  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);
  86   static bool can_decode_C_frame_in_vm();
  87 
  88   static void shutdown();
  89 protected:
  90   static NullDecoder* get_decoder();
  91  
  92 private:
  93   static NullDecoder*     _decoder;
  94   static NullDecoder      _do_nothing_decoder;
  95 
  96 protected:
  97   static Mutex*       _decoder_lock;
  98 };
  99 
 100 #endif // SHARE_VM_UTILITIES_DECODER_HPP