1 /*
   2  * Copyright (c) 2008, 2014, 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 #ifndef SHARE_VM_COMPILER_DISASSEMBLER_HPP
  26 #define SHARE_VM_COMPILER_DISASSEMBLER_HPP
  27 
  28 #include "asm/codeBuffer.hpp"
  29 #include "runtime/globals.hpp"
  30 
  31 class decode_env;
  32 
  33 // The disassembler prints out assembly code annotated
  34 // with Java specific information.
  35 
  36 class Disassembler {
  37   friend class decode_env;
  38  private:
  39   // this is the type of the dll entry point:
  40   typedef void* (*decode_func_virtual)(uintptr_t start_va, uintptr_t end_va,
  41                                unsigned char* buffer, uintptr_t length,
  42                                void* (*event_callback)(void*, const char*, void*),
  43                                void* event_stream,
  44                                int (*printf_callback)(void*, const char*, ...),
  45                                void* printf_stream,
  46                                const char* options,
  47                                int newline);
  48   // this is the type of the dll entry point for old version:
  49   typedef void* (*decode_func)(void* start_va, void* end_va,
  50                                void* (*event_callback)(void*, const char*, void*),
  51                                void* event_stream,
  52                                int (*printf_callback)(void*, const char*, ...),
  53                                void* printf_stream,
  54                                const char* options);
  55   // points to the library.
  56   static void*    _library;
  57   // bailout
  58   static bool     _tried_to_load_library;
  59   // points to the decode function.
  60   static decode_func_virtual _decode_instructions_virtual;
  61   static decode_func _decode_instructions;
  62   // tries to load library and return whether it succedded.
  63   static bool load_library();
  64 
  65   // Machine dependent stuff
  66 #ifdef TARGET_ARCH_x86
  67 # include "disassembler_x86.hpp"
  68 #endif
  69 #ifdef TARGET_ARCH_sparc
  70 # include "disassembler_sparc.hpp"
  71 #endif
  72 #ifdef TARGET_ARCH_zero
  73 # include "disassembler_zero.hpp"
  74 #endif
  75 #ifdef TARGET_ARCH_arm
  76 # include "disassembler_arm.hpp"
  77 #endif
  78 #ifdef TARGET_ARCH_ppc
  79 # include "disassembler_ppc.hpp"
  80 #endif
  81 
  82 
  83  public:
  84   static bool can_decode() {
  85     return (_decode_instructions_virtual != NULL) ||
  86            (_decode_instructions != NULL) ||
  87            load_library();
  88   }
  89   static void decode(CodeBlob *cb,               outputStream* st = NULL);
  90   static void decode(nmethod* nm,                outputStream* st = NULL);
  91   static void decode(address begin, address end, outputStream* st = NULL, CodeStrings c = CodeStrings());
  92 };
  93 
  94 #endif // SHARE_VM_COMPILER_DISASSEMBLER_HPP