1 /* 2 * Copyright (c) 2008, 2019, 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_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