2008-04-02 12:09:59 -07:00
|
|
|
/*
|
2018-02-26 09:34:12 +01:00
|
|
|
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
|
2008-04-02 12:09:59 -07:00
|
|
|
* 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.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* 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.
|
2008-04-02 12:09:59 -07:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "precompiled.hpp"
|
2018-06-03 23:33:00 -07:00
|
|
|
#include "asm/macroAssembler.hpp"
|
2018-02-26 09:34:12 +01:00
|
|
|
#include "ci/ciUtilities.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "classfile/javaClasses.hpp"
|
|
|
|
#include "code/codeCache.hpp"
|
|
|
|
#include "compiler/disassembler.hpp"
|
2018-02-26 09:34:12 +01:00
|
|
|
#include "gc/shared/cardTable.hpp"
|
2018-03-19 07:38:18 +01:00
|
|
|
#include "gc/shared/cardTableBarrierSet.hpp"
|
2015-05-13 15:16:06 +02:00
|
|
|
#include "gc/shared/collectedHeap.hpp"
|
2016-04-04 12:57:48 -04:00
|
|
|
#include "memory/resourceArea.hpp"
|
2015-02-13 14:37:35 +01:00
|
|
|
#include "oops/oop.inline.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "runtime/handles.inline.hpp"
|
2014-06-26 16:05:15 +02:00
|
|
|
#include "runtime/os.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "runtime/stubCodeGenerator.hpp"
|
|
|
|
#include "runtime/stubRoutines.hpp"
|
2018-06-03 23:33:00 -07:00
|
|
|
#include "utilities/resourceHash.hpp"
|
2016-07-13 12:23:05 +02:00
|
|
|
#include CPU_HEADER(depChecker)
|
2008-04-02 12:09:59 -07:00
|
|
|
|
|
|
|
void* Disassembler::_library = NULL;
|
|
|
|
bool Disassembler::_tried_to_load_library = false;
|
|
|
|
|
|
|
|
// This routine is in the shared library:
|
2012-11-02 13:30:47 -07:00
|
|
|
Disassembler::decode_func_virtual Disassembler::_decode_instructions_virtual = NULL;
|
2008-04-02 12:09:59 -07:00
|
|
|
Disassembler::decode_func Disassembler::_decode_instructions = NULL;
|
|
|
|
|
2015-06-24 12:12:25 -04:00
|
|
|
static const char hsdis_library_name[] = "hsdis-" HOTSPOT_LIB_ARCH;
|
2012-11-02 13:30:47 -07:00
|
|
|
static const char decode_instructions_virtual_name[] = "decode_instructions_virtual";
|
|
|
|
static const char decode_instructions_name[] = "decode_instructions";
|
|
|
|
static bool use_new_version = true;
|
2018-06-03 23:33:00 -07:00
|
|
|
#define COMMENT_COLUMN 52 LP64_ONLY(+8) /*could be an option*/
|
2008-04-02 12:09:59 -07:00
|
|
|
#define BYTES_COMMENT ";..." /* funky byte display comment */
|
|
|
|
|
|
|
|
bool Disassembler::load_library() {
|
2012-11-02 13:30:47 -07:00
|
|
|
if (_decode_instructions_virtual != NULL || _decode_instructions != NULL) {
|
2008-04-02 12:09:59 -07:00
|
|
|
// 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;
|
2011-07-06 18:15:21 -07:00
|
|
|
int lib_offset = -1;
|
2015-10-19 13:21:37 -04:00
|
|
|
#ifdef STATIC_BUILD
|
|
|
|
char* p = strrchr(buf, '/');
|
|
|
|
*p = '\0';
|
|
|
|
strcat(p, "/lib/");
|
|
|
|
lib_offset = jvm_offset = strlen(buf);
|
|
|
|
#else
|
2008-04-02 12:09:59 -07:00
|
|
|
{
|
|
|
|
// Match "jvm[^/]*" in jvm_path.
|
|
|
|
const char* base = buf;
|
2014-05-17 01:59:43 -07:00
|
|
|
const char* p = strrchr(buf, *os::file_separator());
|
2011-07-06 18:15:21 -07:00
|
|
|
if (p != NULL) lib_offset = p - base + 1;
|
2008-04-02 12:09:59 -07:00
|
|
|
p = strstr(p ? p : base, "jvm");
|
2016-05-03 12:23:06 +02:00
|
|
|
if (p != NULL) jvm_offset = p - base;
|
2008-04-02 12:09:59 -07:00
|
|
|
}
|
2015-10-19 13:21:37 -04:00
|
|
|
#endif
|
2011-07-06 18:15:21 -07:00
|
|
|
// 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)
|
2008-04-02 12:09:59 -07:00
|
|
|
if (jvm_offset >= 0) {
|
2011-07-06 18:15:21 -07:00
|
|
|
// 1. <home>/jre/lib/<arch>/<vm>/libhsdis-<arch>.so
|
2008-04-02 12:09:59 -07:00
|
|
|
strcpy(&buf[jvm_offset], hsdis_library_name);
|
|
|
|
strcat(&buf[jvm_offset], os::dll_file_extension());
|
2010-12-01 18:26:32 -05:00
|
|
|
_library = os::dll_load(buf, ebuf, sizeof ebuf);
|
2016-05-03 12:23:06 +02:00
|
|
|
if (_library == NULL && lib_offset >= 0) {
|
2011-07-06 18:15:21 -07:00
|
|
|
// 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);
|
|
|
|
}
|
2016-05-03 12:23:06 +02:00
|
|
|
if (_library == NULL && lib_offset > 0) {
|
2011-07-06 18:15:21 -07:00
|
|
|
// 3. <home>/jre/lib/<arch>/hsdis-<arch>.so
|
|
|
|
buf[lib_offset - 1] = '\0';
|
2014-05-17 01:59:43 -07:00
|
|
|
const char* p = strrchr(buf, *os::file_separator());
|
2011-07-06 18:15:21 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2008-04-02 12:09:59 -07:00
|
|
|
}
|
|
|
|
if (_library == NULL) {
|
2011-07-06 18:15:21 -07:00
|
|
|
// 4. hsdis-<arch>.so (using LD_LIBRARY_PATH)
|
2008-04-02 12:09:59 -07:00
|
|
|
strcpy(&buf[0], hsdis_library_name);
|
|
|
|
strcat(&buf[0], os::dll_file_extension());
|
2010-12-01 18:26:32 -05:00
|
|
|
_library = os::dll_load(buf, ebuf, sizeof ebuf);
|
2008-04-02 12:09:59 -07:00
|
|
|
}
|
|
|
|
if (_library != NULL) {
|
2012-11-02 13:30:47 -07:00
|
|
|
_decode_instructions_virtual = CAST_TO_FN_PTR(Disassembler::decode_func_virtual,
|
|
|
|
os::dll_lookup(_library, decode_instructions_virtual_name));
|
|
|
|
}
|
2018-07-12 16:31:28 +02:00
|
|
|
if (_decode_instructions_virtual == NULL && _library != NULL) {
|
2012-11-02 13:30:47 -07:00
|
|
|
// could not spot in new version, try old version
|
2008-04-02 12:09:59 -07:00
|
|
|
_decode_instructions = CAST_TO_FN_PTR(Disassembler::decode_func,
|
2010-12-01 18:26:32 -05:00
|
|
|
os::dll_lookup(_library, decode_instructions_name));
|
2012-11-02 13:30:47 -07:00
|
|
|
use_new_version = false;
|
|
|
|
} else {
|
|
|
|
use_new_version = true;
|
2008-04-02 12:09:59 -07:00
|
|
|
}
|
|
|
|
_tried_to_load_library = true;
|
2012-11-02 13:30:47 -07:00
|
|
|
if (_decode_instructions_virtual == NULL && _decode_instructions == NULL) {
|
2008-04-02 12:09:59 -07:00
|
|
|
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;
|
2013-03-18 13:19:06 +01:00
|
|
|
CodeStrings _strings;
|
2008-04-02 12:09:59 -07:00
|
|
|
outputStream* _output;
|
|
|
|
address _start, _end;
|
2018-06-11 15:32:43 +01:00
|
|
|
ptrdiff_t _offset;
|
2008-04-02 12:09:59 -07:00
|
|
|
|
|
|
|
char _option_buf[512];
|
|
|
|
char _print_raw;
|
|
|
|
bool _print_pc;
|
|
|
|
bool _print_bytes;
|
|
|
|
address _cur_insn;
|
|
|
|
int _bytes_per_line; // arch-specific formatting option
|
2018-06-03 23:33:00 -07:00
|
|
|
bool _print_file_name;
|
2008-04-02 12:09:59 -07:00
|
|
|
|
|
|
|
static bool match(const char* event, const char* tag) {
|
|
|
|
size_t taglen = strlen(tag);
|
|
|
|
if (strncmp(event, tag, taglen) != 0)
|
|
|
|
return false;
|
|
|
|
char delim = event[taglen];
|
|
|
|
return delim == '\0' || delim == ' ' || delim == '/' || delim == '=';
|
|
|
|
}
|
|
|
|
|
|
|
|
void collect_options(const char* p) {
|
|
|
|
if (p == NULL || p[0] == '\0') return;
|
|
|
|
size_t opt_so_far = strlen(_option_buf);
|
|
|
|
if (opt_so_far + 1 + strlen(p) + 1 > sizeof(_option_buf)) return;
|
|
|
|
char* fillp = &_option_buf[opt_so_far];
|
|
|
|
if (opt_so_far > 0) *fillp++ = ',';
|
|
|
|
strcat(fillp, p);
|
|
|
|
// replace white space by commas:
|
|
|
|
char* q = fillp;
|
|
|
|
while ((q = strpbrk(q, " \t\n")) != NULL)
|
|
|
|
*q++ = ',';
|
|
|
|
// Note that multiple PrintAssemblyOptions flags accumulate with \n,
|
|
|
|
// which we want to be changed to a comma...
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_insn_labels();
|
|
|
|
void print_insn_bytes(address pc0, address pc);
|
|
|
|
void print_address(address value);
|
|
|
|
|
2018-06-03 23:33:00 -07:00
|
|
|
struct SourceFileInfo {
|
|
|
|
struct Link : public CHeapObj<mtCode> {
|
|
|
|
const char* file;
|
|
|
|
int line;
|
|
|
|
Link* next;
|
|
|
|
Link(const char* f, int l) : file(f), line(l), next(NULL) {}
|
|
|
|
};
|
|
|
|
Link *head, *tail;
|
|
|
|
|
|
|
|
static unsigned hash(const address& a) {
|
|
|
|
return primitive_hash<address>(a);
|
|
|
|
}
|
|
|
|
static bool equals(const address& a0, const address& a1) {
|
|
|
|
return primitive_equals<address>(a0, a1);
|
|
|
|
}
|
|
|
|
void append(const char* file, int line) {
|
|
|
|
if (tail != NULL && tail->file == file && tail->line == line) {
|
|
|
|
// Don't print duplicated lines at the same address. This could happen with C
|
|
|
|
// macros that end up having multiple "__" tokens on the same __LINE__.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Link *link = new Link(file, line);
|
|
|
|
if (head == NULL) {
|
|
|
|
head = tail = link;
|
|
|
|
} else {
|
|
|
|
tail->next = link;
|
|
|
|
tail = link;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SourceFileInfo(const char* file, int line) : head(NULL), tail(NULL) {
|
|
|
|
append(file, line);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef ResourceHashtable<
|
|
|
|
address, SourceFileInfo,
|
|
|
|
SourceFileInfo::hash,
|
|
|
|
SourceFileInfo::equals,
|
|
|
|
15889, // prime number
|
|
|
|
ResourceObj::C_HEAP> SourceFileInfoTable;
|
|
|
|
|
|
|
|
static SourceFileInfoTable _src_table;
|
|
|
|
static const char* _cached_src;
|
|
|
|
static GrowableArray<const char*>* _cached_src_lines;
|
|
|
|
|
2008-04-02 12:09:59 -07:00
|
|
|
public:
|
2018-06-11 15:32:43 +01:00
|
|
|
decode_env(CodeBlob* code, outputStream* output,
|
|
|
|
CodeStrings c = CodeStrings(), ptrdiff_t offset = 0);
|
2008-04-02 12:09:59 -07:00
|
|
|
|
|
|
|
address decode_instructions(address start, address end);
|
|
|
|
|
|
|
|
void start_insn(address pc) {
|
|
|
|
_cur_insn = pc;
|
|
|
|
output()->bol();
|
|
|
|
print_insn_labels();
|
|
|
|
}
|
|
|
|
|
|
|
|
void end_insn(address pc) {
|
|
|
|
address pc0 = cur_insn();
|
|
|
|
outputStream* st = output();
|
|
|
|
if (_print_bytes && pc > pc0)
|
|
|
|
print_insn_bytes(pc0, pc);
|
2010-01-08 13:47:01 -08:00
|
|
|
if (_nm != NULL) {
|
2008-04-02 12:09:59 -07:00
|
|
|
_nm->print_code_comment_on(st, COMMENT_COLUMN, pc0, pc);
|
2010-01-08 13:47:01 -08:00
|
|
|
// this calls reloc_string_for which calls oop::print_value_on
|
|
|
|
}
|
2018-06-03 23:33:00 -07:00
|
|
|
print_hook_comments(pc0, _nm != NULL);
|
2012-09-24 12:44:00 -07:00
|
|
|
// follow each complete insn by a nice newline
|
|
|
|
st->cr();
|
2008-04-02 12:09:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
address handle_event(const char* event, address arg);
|
|
|
|
|
|
|
|
outputStream* output() { return _output; }
|
|
|
|
address cur_insn() { return _cur_insn; }
|
|
|
|
const char* options() { return _option_buf; }
|
2018-06-03 23:33:00 -07:00
|
|
|
static void hook(const char* file, int line, address pc);
|
|
|
|
void print_hook_comments(address pc, bool newline);
|
2008-04-02 12:09:59 -07:00
|
|
|
};
|
|
|
|
|
2018-06-03 23:33:00 -07:00
|
|
|
decode_env::SourceFileInfoTable decode_env::_src_table;
|
|
|
|
const char* decode_env::_cached_src = NULL;
|
|
|
|
GrowableArray<const char*>* decode_env::_cached_src_lines = NULL;
|
|
|
|
|
|
|
|
void decode_env::hook(const char* file, int line, address pc) {
|
|
|
|
// For simplication, we never free from this table. It's really not
|
|
|
|
// necessary as we add to the table only when PrintInterpreter is true,
|
|
|
|
// which means we are debugging the VM and a little bit of extra
|
|
|
|
// memory usage doesn't matter.
|
|
|
|
SourceFileInfo* found = _src_table.get(pc);
|
|
|
|
if (found != NULL) {
|
|
|
|
found->append(file, line);
|
|
|
|
} else {
|
|
|
|
SourceFileInfo sfi(file, line);
|
|
|
|
_src_table.put(pc, sfi); // sfi is copied by value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void decode_env::print_hook_comments(address pc, bool newline) {
|
|
|
|
SourceFileInfo* found = _src_table.get(pc);
|
|
|
|
outputStream* st = output();
|
|
|
|
if (found != NULL) {
|
|
|
|
for (SourceFileInfo::Link *link = found->head; link; link = link->next) {
|
|
|
|
const char* file = link->file;
|
|
|
|
int line = link->line;
|
|
|
|
if (_cached_src == NULL || strcmp(_cached_src, file) != 0) {
|
|
|
|
FILE* fp;
|
|
|
|
|
|
|
|
// _cached_src_lines is a single cache of the lines of a source file, and we refill this cache
|
|
|
|
// every time we need to print a line from a different source file. It's not the fastest,
|
|
|
|
// but seems bearable.
|
|
|
|
if (_cached_src_lines != NULL) {
|
|
|
|
for (int i=0; i<_cached_src_lines->length(); i++) {
|
|
|
|
os::free((void*)_cached_src_lines->at(i));
|
|
|
|
}
|
|
|
|
_cached_src_lines->clear();
|
|
|
|
} else {
|
|
|
|
_cached_src_lines = new (ResourceObj::C_HEAP, mtCode)GrowableArray<const char*>(0, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((fp = fopen(file, "r")) == NULL) {
|
|
|
|
_cached_src = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_cached_src = file;
|
|
|
|
|
|
|
|
char line[500]; // don't write lines that are too long in your source files!
|
|
|
|
while (fgets(line, sizeof(line), fp) != NULL) {
|
|
|
|
size_t len = strlen(line);
|
|
|
|
if (len > 0 && line[len-1] == '\n') {
|
|
|
|
line[len-1] = '\0';
|
|
|
|
}
|
|
|
|
_cached_src_lines->append(os::strdup(line));
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
_print_file_name = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_print_file_name) {
|
|
|
|
// We print the file name whenever we switch to a new file, or when
|
|
|
|
// Disassembler::decode is called to disassemble a new block of code.
|
|
|
|
_print_file_name = false;
|
|
|
|
if (newline) {
|
|
|
|
st->cr();
|
|
|
|
}
|
|
|
|
st->move_to(COMMENT_COLUMN);
|
|
|
|
st->print(";;@FILE: %s", file);
|
|
|
|
newline = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int index = line - 1; // 1-based line number -> 0-based index.
|
|
|
|
if (index >= _cached_src_lines->length()) {
|
|
|
|
// This could happen if source file is mismatched.
|
|
|
|
} else {
|
|
|
|
const char* source_line = _cached_src_lines->at(index);
|
|
|
|
if (newline) {
|
|
|
|
st->cr();
|
|
|
|
}
|
|
|
|
st->move_to(COMMENT_COLUMN);
|
|
|
|
st->print(";;%5d: %s", line, source_line);
|
|
|
|
newline = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-11 15:32:43 +01:00
|
|
|
decode_env::decode_env(CodeBlob* code, outputStream* output, CodeStrings c,
|
|
|
|
ptrdiff_t offset) {
|
2014-08-29 19:45:49 -04:00
|
|
|
memset(this, 0, sizeof(*this)); // Beware, this zeroes bits of fields.
|
2008-04-02 12:09:59 -07:00
|
|
|
_output = output ? output : tty;
|
|
|
|
_code = code;
|
|
|
|
if (code != NULL && code->is_nmethod())
|
|
|
|
_nm = (nmethod*) code;
|
2014-08-29 19:45:49 -04:00
|
|
|
_strings.copy(c);
|
2018-06-11 15:32:43 +01:00
|
|
|
_offset = offset;
|
2008-04-02 12:09:59 -07:00
|
|
|
|
|
|
|
// by default, output pc but not bytes:
|
|
|
|
_print_pc = true;
|
|
|
|
_print_bytes = false;
|
|
|
|
_bytes_per_line = Disassembler::pd_instruction_alignment();
|
2018-06-03 23:33:00 -07:00
|
|
|
_print_file_name= true;
|
2008-04-02 12:09:59 -07:00
|
|
|
|
|
|
|
// parse the global option string:
|
|
|
|
collect_options(Disassembler::pd_cpu_opts());
|
|
|
|
collect_options(PrintAssemblyOptions);
|
|
|
|
|
|
|
|
if (strstr(options(), "hsdis-")) {
|
|
|
|
if (strstr(options(), "hsdis-print-raw"))
|
|
|
|
_print_raw = (strstr(options(), "xml") ? 2 : 1);
|
|
|
|
if (strstr(options(), "hsdis-print-pc"))
|
|
|
|
_print_pc = !_print_pc;
|
|
|
|
if (strstr(options(), "hsdis-print-bytes"))
|
|
|
|
_print_bytes = !_print_bytes;
|
|
|
|
}
|
|
|
|
if (strstr(options(), "help")) {
|
|
|
|
tty->print_cr("PrintAssemblyOptions help:");
|
|
|
|
tty->print_cr(" hsdis-print-raw test plugin by requesting raw output");
|
|
|
|
tty->print_cr(" hsdis-print-raw-xml test plugin by requesting raw xml");
|
|
|
|
tty->print_cr(" hsdis-print-pc turn off PC printing (on by default)");
|
|
|
|
tty->print_cr(" hsdis-print-bytes turn on instruction byte output");
|
|
|
|
tty->print_cr("combined options: %s", options());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
address decode_env::handle_event(const char* event, address arg) {
|
|
|
|
if (match(event, "insn")) {
|
|
|
|
start_insn(arg);
|
|
|
|
} else if (match(event, "/insn")) {
|
|
|
|
end_insn(arg);
|
|
|
|
} else if (match(event, "addr")) {
|
|
|
|
if (arg != NULL) {
|
|
|
|
print_address(arg);
|
|
|
|
return arg;
|
|
|
|
}
|
|
|
|
} else if (match(event, "mach")) {
|
2011-07-06 18:15:21 -07:00
|
|
|
static char buffer[32] = { 0, };
|
|
|
|
if (strcmp(buffer, (const char*)arg) != 0 ||
|
|
|
|
strlen((const char*)arg) > sizeof(buffer) - 1) {
|
|
|
|
// Only print this when the mach changes
|
|
|
|
strncpy(buffer, (const char*)arg, sizeof(buffer) - 1);
|
2015-04-07 14:19:03 +02:00
|
|
|
buffer[sizeof(buffer) - 1] = '\0';
|
2011-07-06 18:15:21 -07:00
|
|
|
output()->print_cr("[Disassembling for mach='%s']", arg);
|
|
|
|
}
|
2008-04-02 12:09:59 -07:00
|
|
|
} else if (match(event, "format bytes-per-line")) {
|
|
|
|
_bytes_per_line = (int) (intptr_t) arg;
|
|
|
|
} else {
|
|
|
|
// ignore unrecognized markup
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// called by the disassembler to print out jump targets and data addresses
|
|
|
|
void decode_env::print_address(address adr) {
|
|
|
|
outputStream* st = _output;
|
|
|
|
|
|
|
|
if (adr == NULL) {
|
|
|
|
st->print("NULL");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int small_num = (int)(intptr_t)adr;
|
|
|
|
if ((intptr_t)adr == (intptr_t)small_num
|
|
|
|
&& -1 <= small_num && small_num <= 9) {
|
|
|
|
st->print("%d", small_num);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Universe::is_fully_initialized()) {
|
|
|
|
if (StubRoutines::contains(adr)) {
|
|
|
|
StubCodeDesc* desc = StubCodeDesc::desc_for(adr);
|
2015-10-09 09:42:33 +02:00
|
|
|
if (desc == NULL) {
|
2008-04-02 12:09:59 -07:00
|
|
|
desc = StubCodeDesc::desc_for(adr + frame::pc_return_offset);
|
2015-10-09 09:42:33 +02:00
|
|
|
}
|
2008-04-02 12:09:59 -07:00
|
|
|
if (desc != NULL) {
|
|
|
|
st->print("Stub::%s", desc->name());
|
2015-10-09 09:42:33 +02:00
|
|
|
if (desc->begin() != adr) {
|
|
|
|
st->print(INTX_FORMAT_W(+) " " PTR_FORMAT, adr - desc->begin(), p2i(adr));
|
|
|
|
} else if (WizardMode) {
|
|
|
|
st->print(" " PTR_FORMAT, p2i(adr));
|
|
|
|
}
|
2008-04-02 12:09:59 -07:00
|
|
|
return;
|
|
|
|
}
|
2015-10-09 09:42:33 +02:00
|
|
|
st->print("Stub::<unknown> " PTR_FORMAT, p2i(adr));
|
2008-04-02 12:09:59 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-12 11:22:24 +02:00
|
|
|
BarrierSet* bs = BarrierSet::barrier_set();
|
2018-03-19 07:38:18 +01:00
|
|
|
if (bs->is_a(BarrierSet::CardTableBarrierSet) &&
|
2018-02-26 09:34:12 +01:00
|
|
|
adr == ci_card_table_address_as<address>()) {
|
2008-04-02 12:09:59 -07:00
|
|
|
st->print("word_map_base");
|
2015-10-09 09:42:33 +02:00
|
|
|
if (WizardMode) st->print(" " INTPTR_FORMAT, p2i(adr));
|
2008-04-02 12:09:59 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-07 09:19:26 -08:00
|
|
|
if (_nm == NULL) {
|
|
|
|
// Don't do this for native methods, as the function name will be printed in
|
|
|
|
// nmethod::reloc_string_for().
|
|
|
|
ResourceMark rm;
|
|
|
|
const int buflen = 1024;
|
|
|
|
char* buf = NEW_RESOURCE_ARRAY(char, buflen);
|
|
|
|
int offset;
|
|
|
|
if (os::dll_address_to_function_name(adr, buf, buflen, &offset)) {
|
|
|
|
st->print(PTR_FORMAT " = %s", p2i(adr), buf);
|
|
|
|
if (offset != 0) {
|
|
|
|
st->print("+%d", offset);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-06 16:33:13 -07:00
|
|
|
// Fall through to a simple (hexadecimal) numeral.
|
2015-10-09 09:42:33 +02:00
|
|
|
st->print(PTR_FORMAT, p2i(adr));
|
2008-04-02 12:09:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void decode_env::print_insn_labels() {
|
|
|
|
address p = cur_insn();
|
|
|
|
outputStream* st = output();
|
|
|
|
CodeBlob* cb = _code;
|
|
|
|
if (cb != NULL) {
|
2010-01-08 13:47:01 -08:00
|
|
|
cb->print_block_comment(st, p);
|
2008-04-02 12:09:59 -07:00
|
|
|
}
|
2018-06-11 15:32:43 +01:00
|
|
|
_strings.print_block_comment(st, (intptr_t)(p - _start + _offset));
|
2008-04-02 12:09:59 -07:00
|
|
|
if (_print_pc) {
|
2015-10-09 09:42:33 +02:00
|
|
|
st->print(" " PTR_FORMAT ": ", p2i(p));
|
2008-04-02 12:09:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void decode_env::print_insn_bytes(address pc, address pc_limit) {
|
|
|
|
outputStream* st = output();
|
|
|
|
size_t incr = 1;
|
|
|
|
size_t perline = _bytes_per_line;
|
|
|
|
if ((size_t) Disassembler::pd_instruction_alignment() >= sizeof(int)
|
|
|
|
&& !((uintptr_t)pc % sizeof(int))
|
|
|
|
&& !((uintptr_t)pc_limit % sizeof(int))) {
|
|
|
|
incr = sizeof(int);
|
|
|
|
if (perline % incr) perline += incr - (perline % incr);
|
|
|
|
}
|
|
|
|
while (pc < pc_limit) {
|
|
|
|
// tab to the desired column:
|
|
|
|
st->move_to(COMMENT_COLUMN);
|
|
|
|
address pc0 = pc;
|
|
|
|
address pc1 = pc + perline;
|
|
|
|
if (pc1 > pc_limit) pc1 = pc_limit;
|
|
|
|
for (; pc < pc1; pc += incr) {
|
2015-10-09 09:42:33 +02:00
|
|
|
if (pc == pc0) {
|
2008-04-02 12:09:59 -07:00
|
|
|
st->print(BYTES_COMMENT);
|
2015-10-09 09:42:33 +02:00
|
|
|
} else if ((uint)(pc - pc0) % sizeof(int) == 0) {
|
2008-04-02 12:09:59 -07:00
|
|
|
st->print(" "); // put out a space on word boundaries
|
2015-10-09 09:42:33 +02:00
|
|
|
}
|
|
|
|
if (incr == sizeof(int)) {
|
|
|
|
st->print("%08x", *(int*)pc);
|
|
|
|
} else {
|
|
|
|
st->print("%02x", (*pc)&0xFF);
|
|
|
|
}
|
2008-04-02 12:09:59 -07:00
|
|
|
}
|
|
|
|
st->cr();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void* event_to_env(void* env_pv, const char* event, void* arg) {
|
|
|
|
decode_env* env = (decode_env*) env_pv;
|
|
|
|
return env->handle_event(event, (address) arg);
|
|
|
|
}
|
|
|
|
|
2014-05-09 16:50:54 -04:00
|
|
|
ATTRIBUTE_PRINTF(2, 3)
|
2008-04-02 12:09:59 -07:00
|
|
|
static int printf_to_env(void* env_pv, const char* format, ...) {
|
|
|
|
decode_env* env = (decode_env*) env_pv;
|
|
|
|
outputStream* st = env->output();
|
|
|
|
size_t flen = strlen(format);
|
|
|
|
const char* raw = NULL;
|
|
|
|
if (flen == 0) return 0;
|
|
|
|
if (flen == 1 && format[0] == '\n') { st->bol(); return 1; }
|
|
|
|
if (flen < 2 ||
|
|
|
|
strchr(format, '%') == NULL) {
|
|
|
|
raw = format;
|
|
|
|
} else if (format[0] == '%' && format[1] == '%' &&
|
|
|
|
strchr(format+2, '%') == NULL) {
|
|
|
|
// happens a lot on machines with names like %foo
|
|
|
|
flen--;
|
|
|
|
raw = format+1;
|
|
|
|
}
|
|
|
|
if (raw != NULL) {
|
|
|
|
st->print_raw(raw, (int) flen);
|
|
|
|
return (int) flen;
|
|
|
|
}
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
julong cnt0 = st->count();
|
|
|
|
st->vprint(format, ap);
|
|
|
|
julong cnt1 = st->count();
|
|
|
|
va_end(ap);
|
|
|
|
return (int)(cnt1 - cnt0);
|
|
|
|
}
|
|
|
|
|
|
|
|
address decode_env::decode_instructions(address start, address end) {
|
|
|
|
_start = start; _end = end;
|
|
|
|
|
2010-08-03 08:13:38 -04:00
|
|
|
assert(((((intptr_t)start | (intptr_t)end) % Disassembler::pd_instruction_alignment()) == 0), "misaligned insn addr");
|
2008-04-02 12:09:59 -07:00
|
|
|
|
|
|
|
const int show_bytes = false; // for disassembler debugging
|
|
|
|
|
|
|
|
//_version = Disassembler::pd_cpu_version();
|
|
|
|
|
|
|
|
if (!Disassembler::can_decode()) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// decode a series of instructions and return the end of the last instruction
|
|
|
|
|
|
|
|
if (_print_raw) {
|
|
|
|
// Print whatever the library wants to print, w/o fancy callbacks.
|
|
|
|
// This is mainly for debugging the library itself.
|
|
|
|
FILE* out = stdout;
|
|
|
|
FILE* xmlout = (_print_raw > 1 ? out : NULL);
|
2012-11-02 13:30:47 -07:00
|
|
|
return use_new_version ?
|
|
|
|
(address)
|
|
|
|
(*Disassembler::_decode_instructions_virtual)((uintptr_t)start, (uintptr_t)end,
|
|
|
|
start, end - start,
|
|
|
|
NULL, (void*) xmlout,
|
|
|
|
NULL, (void*) out,
|
|
|
|
options(), 0/*nice new line*/)
|
|
|
|
:
|
|
|
|
(address)
|
|
|
|
(*Disassembler::_decode_instructions)(start, end,
|
2008-04-02 12:09:59 -07:00
|
|
|
NULL, (void*) xmlout,
|
|
|
|
NULL, (void*) out,
|
|
|
|
options());
|
|
|
|
}
|
|
|
|
|
2012-11-02 13:30:47 -07:00
|
|
|
return use_new_version ?
|
|
|
|
(address)
|
|
|
|
(*Disassembler::_decode_instructions_virtual)((uintptr_t)start, (uintptr_t)end,
|
|
|
|
start, end - start,
|
|
|
|
&event_to_env, (void*) this,
|
|
|
|
&printf_to_env, (void*) this,
|
|
|
|
options(), 0/*nice new line*/)
|
|
|
|
:
|
|
|
|
(address)
|
|
|
|
(*Disassembler::_decode_instructions)(start, end,
|
2008-04-02 12:09:59 -07:00
|
|
|
&event_to_env, (void*) this,
|
|
|
|
&printf_to_env, (void*) this,
|
|
|
|
options());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Disassembler::decode(CodeBlob* cb, outputStream* st) {
|
2015-12-18 20:23:26 +03:00
|
|
|
ttyLocker ttyl;
|
2008-04-02 12:09:59 -07:00
|
|
|
if (!load_library()) return;
|
2015-10-08 12:49:30 -10:00
|
|
|
if (cb->is_nmethod()) {
|
|
|
|
decode((nmethod*)cb, st);
|
|
|
|
return;
|
|
|
|
}
|
2008-04-02 12:09:59 -07:00
|
|
|
decode_env env(cb, st);
|
2015-10-08 12:49:30 -10:00
|
|
|
env.output()->print_cr("----------------------------------------------------------------------");
|
2016-12-11 19:07:04 -08:00
|
|
|
if (cb->is_aot()) {
|
|
|
|
env.output()->print("A ");
|
|
|
|
if (cb->is_compiled()) {
|
|
|
|
CompiledMethod* cm = (CompiledMethod*)cb;
|
|
|
|
env.output()->print("%d ",cm->compile_id());
|
|
|
|
cm->method()->method_holder()->name()->print_symbol_on(env.output());
|
|
|
|
env.output()->print(".");
|
|
|
|
cm->method()->name()->print_symbol_on(env.output());
|
|
|
|
cm->method()->signature()->print_symbol_on(env.output());
|
|
|
|
} else {
|
|
|
|
env.output()->print_cr("%s", cb->name());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
env.output()->print_cr("%s", cb->name());
|
|
|
|
}
|
2015-10-17 19:40:30 -04:00
|
|
|
env.output()->print_cr(" at [" PTR_FORMAT ", " PTR_FORMAT "] " JLONG_FORMAT " bytes", p2i(cb->code_begin()), p2i(cb->code_end()), ((jlong)(cb->code_end() - cb->code_begin())) * sizeof(unsigned char*));
|
2010-08-25 05:27:54 -07:00
|
|
|
env.decode_instructions(cb->code_begin(), cb->code_end());
|
2008-04-02 12:09:59 -07:00
|
|
|
}
|
|
|
|
|
2018-06-11 15:32:43 +01:00
|
|
|
void Disassembler::decode(address start, address end, outputStream* st, CodeStrings c,
|
|
|
|
ptrdiff_t offset) {
|
2015-12-18 20:23:26 +03:00
|
|
|
ttyLocker ttyl;
|
2008-04-02 12:09:59 -07:00
|
|
|
if (!load_library()) return;
|
2018-06-11 15:32:43 +01:00
|
|
|
decode_env env(CodeCache::find_blob_unsafe(start), st, c, offset);
|
2008-04-02 12:09:59 -07:00
|
|
|
env.decode_instructions(start, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Disassembler::decode(nmethod* nm, outputStream* st) {
|
2015-12-18 20:23:26 +03:00
|
|
|
ttyLocker ttyl;
|
2008-04-02 12:09:59 -07:00
|
|
|
if (!load_library()) return;
|
|
|
|
decode_env env(nm, st);
|
2015-10-08 12:49:30 -10:00
|
|
|
env.output()->print_cr("----------------------------------------------------------------------");
|
2008-04-02 12:09:59 -07:00
|
|
|
|
2010-08-25 05:27:54 -07:00
|
|
|
unsigned char* p = nm->code_begin();
|
|
|
|
unsigned char* end = nm->code_end();
|
2008-04-02 12:09:59 -07:00
|
|
|
|
2015-10-08 12:49:30 -10:00
|
|
|
nm->method()->method_holder()->name()->print_symbol_on(env.output());
|
|
|
|
env.output()->print(".");
|
|
|
|
nm->method()->name()->print_symbol_on(env.output());
|
|
|
|
nm->method()->signature()->print_symbol_on(env.output());
|
|
|
|
#if INCLUDE_JVMCI
|
|
|
|
{
|
|
|
|
char buffer[O_BUFLEN];
|
|
|
|
char* jvmciName = nm->jvmci_installed_code_name(buffer, O_BUFLEN);
|
|
|
|
if (jvmciName != NULL) {
|
|
|
|
env.output()->print(" (%s)", jvmciName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2015-10-17 19:40:30 -04:00
|
|
|
env.output()->print_cr(" [" PTR_FORMAT ", " PTR_FORMAT "] " JLONG_FORMAT " bytes", p2i(p), p2i(end), ((jlong)(end - p)));
|
2015-10-08 12:49:30 -10:00
|
|
|
|
2010-12-03 01:34:31 -08:00
|
|
|
// Print constant table.
|
|
|
|
if (nm->consts_size() > 0) {
|
|
|
|
nm->print_nmethod_labels(env.output(), nm->consts_begin());
|
|
|
|
int offset = 0;
|
|
|
|
for (address p = nm->consts_begin(); p < nm->consts_end(); p += 4, offset += 4) {
|
|
|
|
if ((offset % 8) == 0) {
|
2015-10-09 09:42:33 +02:00
|
|
|
env.output()->print_cr(" " PTR_FORMAT " (offset: %4d): " PTR32_FORMAT " " PTR64_FORMAT, p2i(p), offset, *((int32_t*) p), *((int64_t*) p));
|
2010-12-03 01:34:31 -08:00
|
|
|
} else {
|
2015-10-09 09:42:33 +02:00
|
|
|
env.output()->print_cr(" " PTR_FORMAT " (offset: %4d): " PTR32_FORMAT, p2i(p), offset, *((int32_t*) p));
|
2010-12-03 01:34:31 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-02 12:09:59 -07:00
|
|
|
env.decode_instructions(p, end);
|
|
|
|
}
|
2018-06-03 23:33:00 -07:00
|
|
|
|
|
|
|
// To prevent excessive code expansion in the interpreter generator, we
|
|
|
|
// do not inline this function into Disassembler::hook().
|
|
|
|
void Disassembler::_hook(const char* file, int line, MacroAssembler* masm) {
|
|
|
|
decode_env::hook(file, line, masm->code_section()->end());
|
|
|
|
}
|