Path: blob/master/src/hotspot/share/compiler/disassembler.hpp
40930 views
/*1* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_COMPILER_DISASSEMBLER_HPP25#define SHARE_COMPILER_DISASSEMBLER_HPP2627#include "utilities/globalDefinitions.hpp"2829#include "asm/assembler.hpp"30#include "code/codeBlob.hpp"31#include "code/nmethod.hpp"32#include "compiler/abstractDisassembler.hpp"33#include "runtime/globals.hpp"34#include "utilities/macros.hpp"3536class decode_env;3738// The disassembler prints out assembly code annotated39// with Java specific information.4041// Disassembler inherits from AbstractDisassembler42class Disassembler : public AbstractDisassembler {43friend class decode_env;44private:45// this is the type of the dll entry point:46typedef void* (*decode_func_virtual)(uintptr_t start_va, uintptr_t end_va,47unsigned char* buffer, uintptr_t length,48void* (*event_callback)(void*, const char*, void*),49void* event_stream,50int (*printf_callback)(void*, const char*, ...),51void* printf_stream,52const char* options,53int newline);54// points to the library.55static void* _library;56// bailout57static bool _tried_to_load_library;58static bool _library_usable;59// points to the decode function.60static decode_func_virtual _decode_instructions_virtual;6162// tries to load library and return whether it succeeded.63// Allow (diagnostic) output redirection.64// No output at all if stream is NULL. Can be overridden65// with -Verbose flag, in which case output goes to tty.66static bool load_library(outputStream* st = NULL);6768// Check if the two addresses are on the same page.69static bool is_same_page(address a1, address a2) {70return (((uintptr_t)a1 ^ (uintptr_t)a2) & (~0x0fffUL)) == 0L;71}7273// Machine dependent stuff74#include CPU_HEADER(disassembler)7576public:77// We can always decode code blobs.78// Either we have a disassembler library available (successfully loaded)79// or we will resort to the abstract disassembler. This method informs80// about which decoding format is used.81// We can also enforce using the abstract disassembler.82static bool is_abstract() {83if (!_tried_to_load_library) {84load_library();85}86return ! _library_usable;87}8889// Check out if we are doing a live disassembly or a post-mortem90// disassembly where the binary data was loaded from a hs_err file.91static bool is_decode_error_file() {92// Activate once post-mortem disassembly (from hs-err file) is available.93#if 094return DecodeErrorFile && (strlen(DecodeErrorFile) != 0);95#else96return false;97#endif98}99100// Directly disassemble code blob.101static void decode(CodeBlob *cb, outputStream* st = NULL);102// Directly disassemble nmethod.103static void decode(nmethod* nm, outputStream* st = NULL);104// Disassemble an arbitrary memory range.105static void decode(address start, address end, outputStream* st = NULL, const CodeStrings* = NULL);106107static void _hook(const char* file, int line, class MacroAssembler* masm);108109// This functions makes it easy to generate comments in the generated110// interpreter code, by riding on the customary __ macro in the interpreter generator.111// See templateTable_x86.cpp for an example.112template<class T> inline static T* hook(const char* file, int line, T* masm) {113if (PrintInterpreter) {114_hook(file, line, masm);115}116return masm;117}118};119120#endif // SHARE_COMPILER_DISASSEMBLER_HPP121122123