annotate src/share/vm/compiler/disassembler.cpp @ 196:d1605aabd0a1 jdk7-b30

6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
author xdono
date Wed, 02 Jul 2008 12:55:16 -0700
parents c7c777385a15
children 4e6abf09f540
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
1 /*
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
2 * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
4 *
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
7 * published by the Free Software Foundation.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
8 *
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
13 * accompanied this code).
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
14 *
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
18 *
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
21 * have any questions.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
22 *
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
23 */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
24
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
25 # include "incls/_precompiled.incl"
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
26 # include "incls/_disassembler.cpp.incl"
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
27
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
28 void* Disassembler::_library = NULL;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
29 bool Disassembler::_tried_to_load_library = false;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
30
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
31 // This routine is in the shared library:
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
32 Disassembler::decode_func Disassembler::_decode_instructions = NULL;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
33
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
34 static const char hsdis_library_name[] = "hsdis-"HOTSPOT_LIB_ARCH;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
35 static const char decode_instructions_name[] = "decode_instructions";
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
36
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
37 #define COMMENT_COLUMN 40 LP64_ONLY(+8) /*could be an option*/
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
38 #define BYTES_COMMENT ";..." /* funky byte display comment */
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
39
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
40 bool Disassembler::load_library() {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
41 if (_decode_instructions != NULL) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
42 // Already succeeded.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
43 return true;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
44 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
45 if (_tried_to_load_library) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
46 // Do not try twice.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
47 // To force retry in debugger: assign _tried_to_load_library=0
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
48 return false;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
49 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
50 // Try to load it.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
51 char ebuf[1024];
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
52 char buf[JVM_MAXPATHLEN];
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
53 os::jvm_path(buf, sizeof(buf));
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
54 int jvm_offset = -1;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
55 {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
56 // Match "jvm[^/]*" in jvm_path.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
57 const char* base = buf;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
58 const char* p = strrchr(buf, '/');
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
59 p = strstr(p ? p : base, "jvm");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
60 if (p != NULL) jvm_offset = p - base;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
61 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
62 if (jvm_offset >= 0) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
63 // Find the disassembler next to libjvm.so.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
64 strcpy(&buf[jvm_offset], hsdis_library_name);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
65 strcat(&buf[jvm_offset], os::dll_file_extension());
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
66 _library = hpi::dll_load(buf, ebuf, sizeof ebuf);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
67 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
68 if (_library == NULL) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
69 // Try a free-floating lookup.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
70 strcpy(&buf[0], hsdis_library_name);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
71 strcat(&buf[0], os::dll_file_extension());
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
72 _library = hpi::dll_load(buf, ebuf, sizeof ebuf);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
73 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
74 if (_library != NULL) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
75 _decode_instructions = CAST_TO_FN_PTR(Disassembler::decode_func,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
76 hpi::dll_lookup(_library, decode_instructions_name));
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
77 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
78 _tried_to_load_library = true;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
79 if (_decode_instructions == NULL) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
80 tty->print_cr("Could not load %s; %s; %s", buf,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
81 ((_library != NULL)
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
82 ? "entry point is missing"
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
83 : (WizardMode || PrintMiscellaneous)
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
84 ? (const char*)ebuf
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
85 : "library not loadable"),
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
86 "PrintAssembly is disabled");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
87 return false;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
88 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
89
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
90 // Success.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
91 tty->print_cr("Loaded disassembler from %s", buf);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
92 return true;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
93 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
94
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
95
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
96 class decode_env {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
97 private:
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
98 nmethod* _nm;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
99 CodeBlob* _code;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
100 outputStream* _output;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
101 address _start, _end;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
102
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
103 char _option_buf[512];
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
104 char _print_raw;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
105 bool _print_pc;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
106 bool _print_bytes;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
107 address _cur_insn;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
108 int _total_ticks;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
109 int _bytes_per_line; // arch-specific formatting option
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
110
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
111 static bool match(const char* event, const char* tag) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
112 size_t taglen = strlen(tag);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
113 if (strncmp(event, tag, taglen) != 0)
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
114 return false;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
115 char delim = event[taglen];
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
116 return delim == '\0' || delim == ' ' || delim == '/' || delim == '=';
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
117 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
118
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
119 void collect_options(const char* p) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
120 if (p == NULL || p[0] == '\0') return;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
121 size_t opt_so_far = strlen(_option_buf);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
122 if (opt_so_far + 1 + strlen(p) + 1 > sizeof(_option_buf)) return;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
123 char* fillp = &_option_buf[opt_so_far];
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
124 if (opt_so_far > 0) *fillp++ = ',';
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
125 strcat(fillp, p);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
126 // replace white space by commas:
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
127 char* q = fillp;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
128 while ((q = strpbrk(q, " \t\n")) != NULL)
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
129 *q++ = ',';
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
130 // Note that multiple PrintAssemblyOptions flags accumulate with \n,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
131 // which we want to be changed to a comma...
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
132 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
133
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
134 void print_insn_labels();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
135 void print_insn_bytes(address pc0, address pc);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
136 void print_address(address value);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
137
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
138 public:
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
139 decode_env(CodeBlob* code, outputStream* output);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
140
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
141 address decode_instructions(address start, address end);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
142
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
143 void start_insn(address pc) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
144 _cur_insn = pc;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
145 output()->bol();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
146 print_insn_labels();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
147 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
148
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
149 void end_insn(address pc) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
150 address pc0 = cur_insn();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
151 outputStream* st = output();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
152 if (_print_bytes && pc > pc0)
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
153 print_insn_bytes(pc0, pc);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
154 if (_nm != NULL)
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
155 _nm->print_code_comment_on(st, COMMENT_COLUMN, pc0, pc);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
156
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
157 // Output pc bucket ticks if we have any
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
158 if (total_ticks() != 0) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
159 address bucket_pc = FlatProfiler::bucket_start_for(pc);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
160 if (bucket_pc != NULL && bucket_pc > pc0 && bucket_pc <= pc) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
161 int bucket_count = FlatProfiler::bucket_count_for(pc0);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
162 if (bucket_count != 0) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
163 st->bol();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
164 st->print_cr("%3.1f%% [%d]", bucket_count*100.0/total_ticks(), bucket_count);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
165 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
166 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
167 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
168 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
169
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
170 address handle_event(const char* event, address arg);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
171
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
172 outputStream* output() { return _output; }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
173 address cur_insn() { return _cur_insn; }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
174 int total_ticks() { return _total_ticks; }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
175 void set_total_ticks(int n) { _total_ticks = n; }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
176 const char* options() { return _option_buf; }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
177 };
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
178
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
179 decode_env::decode_env(CodeBlob* code, outputStream* output) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
180 memset(this, 0, sizeof(*this));
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
181 _output = output ? output : tty;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
182 _code = code;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
183 if (code != NULL && code->is_nmethod())
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
184 _nm = (nmethod*) code;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
185
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
186 // by default, output pc but not bytes:
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
187 _print_pc = true;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
188 _print_bytes = false;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
189 _bytes_per_line = Disassembler::pd_instruction_alignment();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
190
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
191 // parse the global option string:
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
192 collect_options(Disassembler::pd_cpu_opts());
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
193 collect_options(PrintAssemblyOptions);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
194
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
195 if (strstr(options(), "hsdis-")) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
196 if (strstr(options(), "hsdis-print-raw"))
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
197 _print_raw = (strstr(options(), "xml") ? 2 : 1);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
198 if (strstr(options(), "hsdis-print-pc"))
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
199 _print_pc = !_print_pc;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
200 if (strstr(options(), "hsdis-print-bytes"))
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
201 _print_bytes = !_print_bytes;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
202 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
203 if (strstr(options(), "help")) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
204 tty->print_cr("PrintAssemblyOptions help:");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
205 tty->print_cr(" hsdis-print-raw test plugin by requesting raw output");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
206 tty->print_cr(" hsdis-print-raw-xml test plugin by requesting raw xml");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
207 tty->print_cr(" hsdis-print-pc turn off PC printing (on by default)");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
208 tty->print_cr(" hsdis-print-bytes turn on instruction byte output");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
209 tty->print_cr("combined options: %s", options());
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
210 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
211 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
212
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
213 address decode_env::handle_event(const char* event, address arg) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
214 if (match(event, "insn")) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
215 start_insn(arg);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
216 } else if (match(event, "/insn")) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
217 end_insn(arg);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
218 } else if (match(event, "addr")) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
219 if (arg != NULL) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
220 print_address(arg);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
221 return arg;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
222 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
223 } else if (match(event, "mach")) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
224 output()->print_cr("[Disassembling for mach='%s']", arg);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
225 } else if (match(event, "format bytes-per-line")) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
226 _bytes_per_line = (int) (intptr_t) arg;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
227 } else {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
228 // ignore unrecognized markup
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
229 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
230 return NULL;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
231 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
232
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
233 // called by the disassembler to print out jump targets and data addresses
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
234 void decode_env::print_address(address adr) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
235 outputStream* st = _output;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
236
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
237 if (adr == NULL) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
238 st->print("NULL");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
239 return;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
240 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
241
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
242 int small_num = (int)(intptr_t)adr;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
243 if ((intptr_t)adr == (intptr_t)small_num
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
244 && -1 <= small_num && small_num <= 9) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
245 st->print("%d", small_num);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
246 return;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
247 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
248
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
249 if (Universe::is_fully_initialized()) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
250 if (StubRoutines::contains(adr)) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
251 StubCodeDesc* desc = StubCodeDesc::desc_for(adr);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
252 if (desc == NULL)
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
253 desc = StubCodeDesc::desc_for(adr + frame::pc_return_offset);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
254 if (desc != NULL) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
255 st->print("Stub::%s", desc->name());
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
256 if (desc->begin() != adr)
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
257 st->print("%+d 0x%p",adr - desc->begin(), adr);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
258 else if (WizardMode) st->print(" " INTPTR_FORMAT, adr);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
259 return;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
260 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
261 st->print("Stub::<unknown> " INTPTR_FORMAT, adr);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
262 return;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
263 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
264
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
265 BarrierSet* bs = Universe::heap()->barrier_set();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
266 if (bs->kind() == BarrierSet::CardTableModRef &&
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
267 adr == (address)((CardTableModRefBS*)(bs))->byte_map_base) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
268 st->print("word_map_base");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
269 if (WizardMode) st->print(" " INTPTR_FORMAT, (intptr_t)adr);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
270 return;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
271 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
272
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
273 oop obj;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
274 if (_nm != NULL
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
275 && (obj = _nm->embeddedOop_at(cur_insn())) != NULL
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
276 && (address) obj == adr) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
277 obj->print_value_on(st);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
278 return;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
279 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
280 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
281
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
282 // Fall through to a simple numeral.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
283 st->print(INTPTR_FORMAT, (intptr_t)adr);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
284 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
285
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
286 void decode_env::print_insn_labels() {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
287 address p = cur_insn();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
288 outputStream* st = output();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
289 nmethod* nm = _nm;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
290 if (nm != NULL) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
291 if (p == nm->entry_point()) st->print_cr("[Entry Point]");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
292 if (p == nm->verified_entry_point()) st->print_cr("[Verified Entry Point]");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
293 if (p == nm->exception_begin()) st->print_cr("[Exception Handler]");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
294 if (p == nm->stub_begin()) st->print_cr("[Stub Code]");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
295 if (p == nm->consts_begin()) st->print_cr("[Constants]");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
296 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
297 CodeBlob* cb = _code;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
298 if (cb != NULL) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
299 cb->print_block_comment(st, (intptr_t)(p - cb->instructions_begin()));
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
300 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
301 if (_print_pc) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
302 st->print(" " INTPTR_FORMAT ": ", (intptr_t) p);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
303 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
304 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
305
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
306 void decode_env::print_insn_bytes(address pc, address pc_limit) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
307 outputStream* st = output();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
308 size_t incr = 1;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
309 size_t perline = _bytes_per_line;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
310 if ((size_t) Disassembler::pd_instruction_alignment() >= sizeof(int)
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
311 && !((uintptr_t)pc % sizeof(int))
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
312 && !((uintptr_t)pc_limit % sizeof(int))) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
313 incr = sizeof(int);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
314 if (perline % incr) perline += incr - (perline % incr);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
315 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
316 while (pc < pc_limit) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
317 // tab to the desired column:
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
318 st->move_to(COMMENT_COLUMN);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
319 address pc0 = pc;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
320 address pc1 = pc + perline;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
321 if (pc1 > pc_limit) pc1 = pc_limit;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
322 for (; pc < pc1; pc += incr) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
323 if (pc == pc0)
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
324 st->print(BYTES_COMMENT);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
325 else if ((uint)(pc - pc0) % sizeof(int) == 0)
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
326 st->print(" "); // put out a space on word boundaries
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
327 if (incr == sizeof(int))
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
328 st->print("%08lx", *(int*)pc);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
329 else st->print("%02x", (*pc)&0xFF);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
330 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
331 st->cr();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
332 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
333 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
334
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
335
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
336 static void* event_to_env(void* env_pv, const char* event, void* arg) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
337 decode_env* env = (decode_env*) env_pv;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
338 return env->handle_event(event, (address) arg);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
339 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
340
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
341 static int printf_to_env(void* env_pv, const char* format, ...) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
342 decode_env* env = (decode_env*) env_pv;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
343 outputStream* st = env->output();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
344 size_t flen = strlen(format);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
345 const char* raw = NULL;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
346 if (flen == 0) return 0;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
347 if (flen == 1 && format[0] == '\n') { st->bol(); return 1; }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
348 if (flen < 2 ||
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
349 strchr(format, '%') == NULL) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
350 raw = format;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
351 } else if (format[0] == '%' && format[1] == '%' &&
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
352 strchr(format+2, '%') == NULL) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
353 // happens a lot on machines with names like %foo
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
354 flen--;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
355 raw = format+1;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
356 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
357 if (raw != NULL) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
358 st->print_raw(raw, (int) flen);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
359 return (int) flen;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
360 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
361 va_list ap;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
362 va_start(ap, format);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
363 julong cnt0 = st->count();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
364 st->vprint(format, ap);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
365 julong cnt1 = st->count();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
366 va_end(ap);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
367 return (int)(cnt1 - cnt0);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
368 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
369
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
370 address decode_env::decode_instructions(address start, address end) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
371 _start = start; _end = end;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
372
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
373 assert((((intptr_t)start | (intptr_t)end) % Disassembler::pd_instruction_alignment() == 0), "misaligned insn addr");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
374
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
375 const int show_bytes = false; // for disassembler debugging
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
376
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
377 //_version = Disassembler::pd_cpu_version();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
378
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
379 if (!Disassembler::can_decode()) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
380 return NULL;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
381 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
382
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
383 // decode a series of instructions and return the end of the last instruction
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
384
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
385 if (_print_raw) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
386 // Print whatever the library wants to print, w/o fancy callbacks.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
387 // This is mainly for debugging the library itself.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
388 FILE* out = stdout;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
389 FILE* xmlout = (_print_raw > 1 ? out : NULL);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
390 return (address)
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
391 (*Disassembler::_decode_instructions)(start, end,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
392 NULL, (void*) xmlout,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
393 NULL, (void*) out,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
394 options());
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
395 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
396
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
397 return (address)
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
398 (*Disassembler::_decode_instructions)(start, end,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
399 &event_to_env, (void*) this,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
400 &printf_to_env, (void*) this,
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
401 options());
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
402 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
403
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
404
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
405 void Disassembler::decode(CodeBlob* cb, outputStream* st) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
406 if (!load_library()) return;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
407 decode_env env(cb, st);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
408 env.output()->print_cr("Decoding CodeBlob " INTPTR_FORMAT, cb);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
409 env.decode_instructions(cb->instructions_begin(), cb->instructions_end());
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
410 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
411
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
412
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
413 void Disassembler::decode(address start, address end, outputStream* st) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
414 if (!load_library()) return;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
415 decode_env env(CodeCache::find_blob_unsafe(start), st);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
416 env.decode_instructions(start, end);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
417 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
418
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
419 void Disassembler::decode(nmethod* nm, outputStream* st) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
420 if (!load_library()) return;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
421 decode_env env(nm, st);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
422 env.output()->print_cr("Decoding compiled method " INTPTR_FORMAT ":", nm);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
423 env.output()->print_cr("Code:");
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
424
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
425 unsigned char* p = nm->instructions_begin();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
426 unsigned char* end = nm->instructions_end();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
427
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
428 // If there has been profiling, print the buckets.
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
429 if (FlatProfiler::bucket_start_for(p) != NULL) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
430 unsigned char* p1 = p;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
431 int total_bucket_count = 0;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
432 while (p1 < end) {
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
433 unsigned char* p0 = p1;
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
434 p1 += pd_instruction_alignment();
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
435 address bucket_pc = FlatProfiler::bucket_start_for(p1);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
436 if (bucket_pc != NULL && bucket_pc > p0 && bucket_pc <= p1)
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
437 total_bucket_count += FlatProfiler::bucket_count_for(p0);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
438 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
439 env.set_total_ticks(total_bucket_count);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
440 }
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
441
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
442 env.decode_instructions(p, end);
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents:
diff changeset
443 }