< prev index next >

src/hotspot/share/compiler/disassembler.hpp

Print this page
rev 54763 : 8213084: Rework and enhance Print[Opto]Assembly output
Reviewed-by:


   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 #ifndef SHARE_COMPILER_DISASSEMBLER_HPP
  26 #define SHARE_COMPILER_DISASSEMBLER_HPP
  27 



  28 #include "asm/codeBuffer.hpp"

  29 #include "runtime/globals.hpp"
  30 #include "utilities/macros.hpp"
  31 
  32 class decode_env;
  33 
  34 // The disassembler prints out assembly code annotated
  35 // with Java specific information.
  36 
  37 class Disassembler {

  38   friend class decode_env;
  39  private:
  40   // this is the type of the dll entry point:
  41   typedef void* (*decode_func_virtual)(uintptr_t start_va, uintptr_t end_va,
  42                                unsigned char* buffer, uintptr_t length,
  43                                void* (*event_callback)(void*, const char*, void*),
  44                                void* event_stream,
  45                                int (*printf_callback)(void*, const char*, ...),
  46                                void* printf_stream,
  47                                const char* options,
  48                                int newline);
  49   // this is the type of the dll entry point for old version:
  50   typedef void* (*decode_func)(void* start_va, void* end_va,
  51                                void* (*event_callback)(void*, const char*, void*),
  52                                void* event_stream,
  53                                int (*printf_callback)(void*, const char*, ...),
  54                                void* printf_stream,
  55                                const char* options);
  56   // points to the library.
  57   static void*    _library;
  58   // bailout
  59   static bool     _tried_to_load_library;

  60   // points to the decode function.
  61   static decode_func_virtual _decode_instructions_virtual;
  62   static decode_func _decode_instructions;
  63   // tries to load library and return whether it succedded.
  64   static bool load_library();









  65 
  66   // Machine dependent stuff
  67 #include CPU_HEADER(disassembler)
  68 
  69  public:
  70   static bool can_decode() {
  71     ttyLocker tl;
  72     return (_decode_instructions_virtual != NULL) ||
  73            (_decode_instructions != NULL) ||



  74            load_library();
  75   }
  76   static void decode(CodeBlob *cb,               outputStream* st = NULL);
  77   static void decode(nmethod* nm,                outputStream* st = NULL);
  78   static void decode(address begin, address end, outputStream* st = NULL,
  79                      CodeStrings c = CodeStrings(), ptrdiff_t offset = 0);



















  80   static void _hook(const char* file, int line, class MacroAssembler* masm);
  81 
  82   // This functions makes it easy to generate comments in the generated
  83   // interpreter code, by riding on the customary __ macro in the interpreter generator.
  84   // See templateTable_x86.cpp for an example.
  85   template<class T> inline static T* hook(const char* file, int line, T* masm) {
  86     if (PrintInterpreter) {
  87       _hook(file, line, masm);
  88     }
  89     return masm;
  90   }
  91 };
  92 
  93 #endif // SHARE_COMPILER_DISASSEMBLER_HPP


   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 #ifndef SHARE_COMPILER_DISASSEMBLER_HPP
  26 #define SHARE_COMPILER_DISASSEMBLER_HPP
  27 
  28 #include "utilities/globalDefinitions.hpp"
  29 
  30 #include "asm/assembler.hpp"
  31 #include "asm/codeBuffer.hpp"
  32 #include "compiler/abstractDisassembler.hpp"
  33 #include "runtime/globals.hpp"
  34 #include "utilities/macros.hpp"
  35 
  36 class decode_env;
  37 
  38 // The disassembler prints out assembly code annotated
  39 // with Java specific information.
  40 
  41 // Disassembler inherits from AbstractDisassembler
  42 class Disassembler : public AbstractDisassembler {
  43   friend class decode_env;
  44  private:
  45   // this is the type of the dll entry point:
  46   typedef void* (*decode_func_virtual)(uintptr_t start_va, uintptr_t end_va,
  47                                unsigned char* buffer, uintptr_t length,
  48                                void* (*event_callback)(void*, const char*, void*),
  49                                void* event_stream,
  50                                int (*printf_callback)(void*, const char*, ...),
  51                                void* printf_stream,
  52                                const char* options,
  53                                int newline);
  54   // this is the type of the dll entry point for old version:
  55   typedef void* (*decode_func)(void* start_va, void* end_va,
  56                                void* (*event_callback)(void*, const char*, void*),
  57                                void* event_stream,
  58                                int (*printf_callback)(void*, const char*, ...),
  59                                void* printf_stream,
  60                                const char* options);
  61   // points to the library.
  62   static void*    _library;
  63   // bailout
  64   static bool     _tried_to_load_library;
  65   static bool     _library_usable;
  66   // points to the decode function.
  67   static decode_func_virtual _decode_instructions_virtual;
  68   static decode_func _decode_instructions;
  69 
  70   // tries to load library and return whether it succeeded.
  71   // Allow (diagnostic) output redirection.
  72   // No output at all if stream is NULL. Can be overridden
  73   // with -Verbose flag, in which case output goes to tty.
  74   static bool load_library(outputStream* st = NULL);
  75 
  76   // Check if the two addresses are on the same page.
  77   static bool is_same_page(address a1, address a2) {
  78     return (((uintptr_t)a1 ^ (uintptr_t)a2) & (~0x0fffUL)) == 0L;
  79   }
  80 
  81   // Machine dependent stuff
  82 #include CPU_HEADER(disassembler)
  83 
  84  public:
  85   // We can always decode code blobs.
  86   // Either we have a disassembler library available (successfully loaded)
  87   // or we will resort to the abstract disassembler. This method informs
  88   // about which decoding format is used.
  89   // We can also enforce using the abstract disassembler.
  90   static bool is_abstract() {
  91     if (!_tried_to_load_library /* && !UseAbstractDisassembler */) {
  92       load_library();
  93     }
  94     return ! _library_usable /* || UseAbstractDisassembler */;  // Not available until DecodeErrorFile is supported.
  95   }
  96 
  97   // Check out if we are doing a live disassembly or a post-mortem
  98   // disassembly where the binary data was loaded from a hs_err file.
  99   static bool is_decode_error_file() {
 100 // Activate once post-mortem disassembly (from hs-err file) is available.
 101 #if 0
 102     return DecodeErrorFile && (strlen(DecodeErrorFile) != 0);
 103 #else
 104     return false;
 105 #endif
 106   }
 107 
 108   // Directly disassemble code buffer.
 109   static void decode(CodeBuffer* cb, address start, address end, outputStream* st = NULL);
 110   // Directly disassemble code blob.
 111   static void decode(CodeBlob *cb,               outputStream* st = NULL, CodeStrings c = CodeStrings());
 112   // Directly disassemble nmethod.
 113   static void decode(nmethod* nm,                outputStream* st = NULL, CodeStrings c = CodeStrings());
 114   // Disassemble an arbitrary memory range.
 115   static void decode(address start, address end, outputStream* st = NULL, CodeStrings c = CodeStrings() /* , ptrdiff_t offset */);
 116 
 117   static void _hook(const char* file, int line, class MacroAssembler* masm);
 118 
 119   // This functions makes it easy to generate comments in the generated
 120   // interpreter code, by riding on the customary __ macro in the interpreter generator.
 121   // See templateTable_x86.cpp for an example.
 122   template<class T> inline static T* hook(const char* file, int line, T* masm) {
 123     if (PrintInterpreter) {
 124       _hook(file, line, masm);
 125     }
 126     return masm;
 127   }
 128 };
 129 
 130 #endif // SHARE_COMPILER_DISASSEMBLER_HPP
< prev index next >