Mercurial > hg > truffle
diff src/share/vm/compiler/disassembler.cpp @ 17524:89152779163c
Merge with jdk8-b132
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Wed, 15 Oct 2014 11:59:32 +0200 |
parents | b1911c1e44c8 |
children | 52b4284cb496 |
line wrap: on
line diff
--- a/src/share/vm/compiler/disassembler.cpp Wed Oct 15 15:35:33 2014 +0200 +++ b/src/share/vm/compiler/disassembler.cpp Wed Oct 15 11:59:32 2014 +0200 @@ -1,163 +1,163 @@ -/* - * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -#include "precompiled.hpp" -#include "classfile/javaClasses.hpp" -#include "code/codeCache.hpp" -#include "compiler/disassembler.hpp" -#include "gc_interface/collectedHeap.hpp" -#include "memory/cardTableModRefBS.hpp" -#include "runtime/fprofiler.hpp" -#include "runtime/handles.inline.hpp" -#include "runtime/stubCodeGenerator.hpp" -#include "runtime/stubRoutines.hpp" -#ifdef TARGET_ARCH_x86 -# include "depChecker_x86.hpp" -#endif -#ifdef TARGET_ARCH_sparc -# include "depChecker_sparc.hpp" -#endif -#ifdef TARGET_ARCH_zero -# include "depChecker_zero.hpp" -#endif -#ifdef TARGET_ARCH_arm -# include "depChecker_arm.hpp" -#endif -#ifdef TARGET_ARCH_ppc -# include "depChecker_ppc.hpp" -#endif -#ifdef SHARK -#include "shark/sharkEntry.hpp" -#endif - -void* Disassembler::_library = NULL; -bool Disassembler::_tried_to_load_library = false; - -// This routine is in the shared library: -Disassembler::decode_func_virtual Disassembler::_decode_instructions_virtual = NULL; -Disassembler::decode_func Disassembler::_decode_instructions = NULL; - -static const char hsdis_library_name[] = "hsdis-"HOTSPOT_LIB_ARCH; -static const char decode_instructions_virtual_name[] = "decode_instructions_virtual"; -static const char decode_instructions_name[] = "decode_instructions"; -static bool use_new_version = true; -#define COMMENT_COLUMN 40 LP64_ONLY(+8) /*could be an option*/ -#define BYTES_COMMENT ";..." /* funky byte display comment */ - -bool Disassembler::load_library() { - if (_decode_instructions_virtual != NULL || _decode_instructions != NULL) { - // Already succeeded. - return true; - } - if (_tried_to_load_library) { - // Do not try twice. - // To force retry in debugger: assign _tried_to_load_library=0 - return false; - } - // Try to load it. - char ebuf[1024]; - char buf[JVM_MAXPATHLEN]; - os::jvm_path(buf, sizeof(buf)); - int jvm_offset = -1; - int lib_offset = -1; - { - // Match "jvm[^/]*" in jvm_path. - const char* base = buf; - const char* p = strrchr(buf, '/'); - if (p != NULL) lib_offset = p - base + 1; - p = strstr(p ? p : base, "jvm"); - if (p != NULL) jvm_offset = p - base; - } - // Find the disassembler shared library. - // Search for several paths derived from libjvm, in this order: - // 1. <home>/jre/lib/<arch>/<vm>/libhsdis-<arch>.so (for compatibility) - // 2. <home>/jre/lib/<arch>/<vm>/hsdis-<arch>.so - // 3. <home>/jre/lib/<arch>/hsdis-<arch>.so - // 4. hsdis-<arch>.so (using LD_LIBRARY_PATH) - if (jvm_offset >= 0) { - // 1. <home>/jre/lib/<arch>/<vm>/libhsdis-<arch>.so - strcpy(&buf[jvm_offset], hsdis_library_name); - strcat(&buf[jvm_offset], os::dll_file_extension()); - _library = os::dll_load(buf, ebuf, sizeof ebuf); - if (_library == NULL) { - // 2. <home>/jre/lib/<arch>/<vm>/hsdis-<arch>.so - strcpy(&buf[lib_offset], hsdis_library_name); - strcat(&buf[lib_offset], os::dll_file_extension()); - _library = os::dll_load(buf, ebuf, sizeof ebuf); - } - if (_library == NULL) { - // 3. <home>/jre/lib/<arch>/hsdis-<arch>.so - buf[lib_offset - 1] = '\0'; - const char* p = strrchr(buf, '/'); - if (p != NULL) { - lib_offset = p - buf + 1; - strcpy(&buf[lib_offset], hsdis_library_name); - strcat(&buf[lib_offset], os::dll_file_extension()); - _library = os::dll_load(buf, ebuf, sizeof ebuf); - } - } - } - if (_library == NULL) { - // 4. hsdis-<arch>.so (using LD_LIBRARY_PATH) - strcpy(&buf[0], hsdis_library_name); - strcat(&buf[0], os::dll_file_extension()); - _library = os::dll_load(buf, ebuf, sizeof ebuf); - } - if (_library != NULL) { - _decode_instructions_virtual = CAST_TO_FN_PTR(Disassembler::decode_func_virtual, - os::dll_lookup(_library, decode_instructions_virtual_name)); - } - if (_decode_instructions_virtual == NULL) { - // could not spot in new version, try old version - _decode_instructions = CAST_TO_FN_PTR(Disassembler::decode_func, - os::dll_lookup(_library, decode_instructions_name)); - use_new_version = false; - } else { - use_new_version = true; - } - _tried_to_load_library = true; - if (_decode_instructions_virtual == NULL && _decode_instructions == NULL) { - tty->print_cr("Could not load %s; %s; %s", buf, - ((_library != NULL) - ? "entry point is missing" - : (WizardMode || PrintMiscellaneous) - ? (const char*)ebuf - : "library not loadable"), - "PrintAssembly is disabled"); - return false; - } - - // Success. - tty->print_cr("Loaded disassembler from %s", buf); - return true; -} - - -class decode_env { - private: - nmethod* _nm; - CodeBlob* _code; +/* + * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#include "precompiled.hpp" +#include "classfile/javaClasses.hpp" +#include "code/codeCache.hpp" +#include "compiler/disassembler.hpp" +#include "gc_interface/collectedHeap.hpp" +#include "memory/cardTableModRefBS.hpp" +#include "runtime/fprofiler.hpp" +#include "runtime/handles.inline.hpp" +#include "runtime/stubCodeGenerator.hpp" +#include "runtime/stubRoutines.hpp" +#ifdef TARGET_ARCH_x86 +# include "depChecker_x86.hpp" +#endif +#ifdef TARGET_ARCH_sparc +# include "depChecker_sparc.hpp" +#endif +#ifdef TARGET_ARCH_zero +# include "depChecker_zero.hpp" +#endif +#ifdef TARGET_ARCH_arm +# include "depChecker_arm.hpp" +#endif +#ifdef TARGET_ARCH_ppc +# include "depChecker_ppc.hpp" +#endif +#ifdef SHARK +#include "shark/sharkEntry.hpp" +#endif + +void* Disassembler::_library = NULL; +bool Disassembler::_tried_to_load_library = false; + +// This routine is in the shared library: +Disassembler::decode_func_virtual Disassembler::_decode_instructions_virtual = NULL; +Disassembler::decode_func Disassembler::_decode_instructions = NULL; + +static const char hsdis_library_name[] = "hsdis-"HOTSPOT_LIB_ARCH; +static const char decode_instructions_virtual_name[] = "decode_instructions_virtual"; +static const char decode_instructions_name[] = "decode_instructions"; +static bool use_new_version = true; +#define COMMENT_COLUMN 40 LP64_ONLY(+8) /*could be an option*/ +#define BYTES_COMMENT ";..." /* funky byte display comment */ + +bool Disassembler::load_library() { + if (_decode_instructions_virtual != NULL || _decode_instructions != NULL) { + // Already succeeded. + return true; + } + if (_tried_to_load_library) { + // Do not try twice. + // To force retry in debugger: assign _tried_to_load_library=0 + return false; + } + // Try to load it. + char ebuf[1024]; + char buf[JVM_MAXPATHLEN]; + os::jvm_path(buf, sizeof(buf)); + int jvm_offset = -1; + int lib_offset = -1; + { + // Match "jvm[^/]*" in jvm_path. + const char* base = buf; + const char* p = strrchr(buf, '/'); + if (p != NULL) lib_offset = p - base + 1; + p = strstr(p ? p : base, "jvm"); + if (p != NULL) jvm_offset = p - base; + } + // Find the disassembler shared library. + // Search for several paths derived from libjvm, in this order: + // 1. <home>/jre/lib/<arch>/<vm>/libhsdis-<arch>.so (for compatibility) + // 2. <home>/jre/lib/<arch>/<vm>/hsdis-<arch>.so + // 3. <home>/jre/lib/<arch>/hsdis-<arch>.so + // 4. hsdis-<arch>.so (using LD_LIBRARY_PATH) + if (jvm_offset >= 0) { + // 1. <home>/jre/lib/<arch>/<vm>/libhsdis-<arch>.so + strcpy(&buf[jvm_offset], hsdis_library_name); + strcat(&buf[jvm_offset], os::dll_file_extension()); + _library = os::dll_load(buf, ebuf, sizeof ebuf); + if (_library == NULL) { + // 2. <home>/jre/lib/<arch>/<vm>/hsdis-<arch>.so + strcpy(&buf[lib_offset], hsdis_library_name); + strcat(&buf[lib_offset], os::dll_file_extension()); + _library = os::dll_load(buf, ebuf, sizeof ebuf); + } + if (_library == NULL) { + // 3. <home>/jre/lib/<arch>/hsdis-<arch>.so + buf[lib_offset - 1] = '\0'; + const char* p = strrchr(buf, '/'); + if (p != NULL) { + lib_offset = p - buf + 1; + strcpy(&buf[lib_offset], hsdis_library_name); + strcat(&buf[lib_offset], os::dll_file_extension()); + _library = os::dll_load(buf, ebuf, sizeof ebuf); + } + } + } + if (_library == NULL) { + // 4. hsdis-<arch>.so (using LD_LIBRARY_PATH) + strcpy(&buf[0], hsdis_library_name); + strcat(&buf[0], os::dll_file_extension()); + _library = os::dll_load(buf, ebuf, sizeof ebuf); + } + if (_library != NULL) { + _decode_instructions_virtual = CAST_TO_FN_PTR(Disassembler::decode_func_virtual, + os::dll_lookup(_library, decode_instructions_virtual_name)); + } + if (_decode_instructions_virtual == NULL) { + // could not spot in new version, try old version + _decode_instructions = CAST_TO_FN_PTR(Disassembler::decode_func, + os::dll_lookup(_library, decode_instructions_name)); + use_new_version = false; + } else { + use_new_version = true; + } + _tried_to_load_library = true; + if (_decode_instructions_virtual == NULL && _decode_instructions == NULL) { + tty->print_cr("Could not load %s; %s; %s", buf, + ((_library != NULL) + ? "entry point is missing" + : (WizardMode || PrintMiscellaneous) + ? (const char*)ebuf + : "library not loadable"), + "PrintAssembly is disabled"); + return false; + } + + // Success. + tty->print_cr("Loaded disassembler from %s", buf); + return true; +} + + +class decode_env { + private: + nmethod* _nm; + CodeBlob* _code; CodeStrings _strings; outputStream* _output; address _start, _end;