6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/classPrinter.hpp"
27 #include "classfile/javaClasses.inline.hpp"
28 #include "interpreter/bytecodeHistogram.hpp"
29 #include "interpreter/bytecodeStream.hpp"
30 #include "interpreter/bytecodeTracer.hpp"
31 #include "interpreter/bytecodes.hpp"
32 #include "interpreter/interpreter.hpp"
33 #include "interpreter/interpreterRuntime.hpp"
34 #include "memory/resourceArea.hpp"
35 #include "oops/constantPool.inline.hpp"
36 #include "oops/methodData.hpp"
37 #include "oops/method.hpp"
38 #include "oops/resolvedFieldEntry.hpp"
39 #include "oops/resolvedIndyEntry.hpp"
40 #include "oops/resolvedMethodEntry.hpp"
41 #include "runtime/handles.inline.hpp"
42 #include "runtime/mutexLocker.hpp"
43 #include "runtime/osThread.hpp"
44 #include "runtime/timer.hpp"
45 #include "utilities/align.hpp"
105 // This is acceptable in a debug-only feature.
106 st->cr();
107 st->print("[%ld] ", (long) Thread::current()->osthread()->thread_id());
108 method->print_name(st);
109 st->cr();
110 _current_method = method();
111 _is_linked = method->method_holder()->is_linked();
112 assert(_is_linked, "this function must be called on methods that are already executing");
113 }
114 Bytecodes::Code code;
115 if (is_wide()) {
116 // bcp wasn't advanced if previous bytecode was _wide.
117 code = Bytecodes::code_at(method(), bcp+1);
118 } else {
119 code = Bytecodes::code_at(method(), bcp);
120 }
121 _code = code;
122 int bci = (int)(bcp - method->code_base());
123 st->print("[%ld] ", (long) Thread::current()->osthread()->thread_id());
124 if (Verbose) {
125 st->print("%8d %4d " INTPTR_FORMAT " " INTPTR_FORMAT " %s",
126 BytecodeCounter::counter_value(), bci, tos, tos2, Bytecodes::name(code));
127 } else {
128 st->print("%8d %4d %s",
129 BytecodeCounter::counter_value(), bci, Bytecodes::name(code));
130 }
131 _next_pc = is_wide() ? bcp+2 : bcp+1;
132 print_attributes(bci, st);
133 // Set is_wide for the next one, since the caller of this doesn't skip
134 // the next bytecode.
135 _is_wide = (code == Bytecodes::_wide);
136 _code = Bytecodes::_illegal;
137
138 #ifndef PRODUCT
139 if (TraceBytecodesStopAt != 0 && BytecodeCounter::counter_value() >= TraceBytecodesStopAt) {
140 TraceBytecodes = false;
141 }
142 #endif
143 }
144
145 // Used for Method*::print_codes(). The input bcp comes from
146 // BytecodeStream, which will skip wide bytecodes.
147 void trace(const methodHandle& method, address bcp, outputStream* st) {
148 _current_method = method();
150 ResourceMark rm;
151 Bytecodes::Code code = Bytecodes::code_at(method(), bcp);
152 // Set is_wide
153 _is_wide = (code == Bytecodes::_wide);
154 if (is_wide()) {
155 code = Bytecodes::code_at(method(), bcp+1);
156 }
157 _code = code;
158 int bci = (int)(bcp - method->code_base());
159 // Print bytecode index and name
160 if (ClassPrinter::has_mode(_flags, ClassPrinter::PRINT_BYTECODE_ADDR)) {
161 st->print(INTPTR_FORMAT " ", p2i(bcp));
162 }
163 if (is_wide()) {
164 st->print("%4d %s_w", bci, Bytecodes::name(code));
165 } else {
166 st->print("%4d %s", bci, Bytecodes::name(code));
167 }
168 _next_pc = is_wide() ? bcp+2 : bcp+1;
169 print_attributes(bci, st);
170 bytecode_epilog(bci, st);
171 }
172 };
173
174 // We need a global instance to keep track of the states when the bytecodes
175 // are executed. Access by multiple threads are controlled by ttyLocker.
176 static BytecodePrinter _interpreter_printer;
177
178 void BytecodeTracer::trace_interpreter(const methodHandle& method, address bcp, uintptr_t tos, uintptr_t tos2, outputStream* st) {
179 if (TraceBytecodes && BytecodeCounter::counter_value() >= TraceBytecodesAt) {
180 ttyLocker ttyl; // 5065316: keep the following output coherent
181 // The ttyLocker also prevents races between two threads
182 // trying to use the single instance of BytecodePrinter.
183 //
184 // There used to be a leaf mutex here, but the ttyLocker will
185 // work just as well, as long as the printing operations never block.
186 _interpreter_printer.trace(method, bcp, tos, tos2, st);
187 }
188 }
189
190 void BytecodeTracer::print_method_codes(const methodHandle& method, int from, int to, outputStream* st, int flags) {
277
278 int bsm = constants->bootstrap_method_ref_index_at(cp_index);
279 st->print(" bsm=%d", bsm);
280
281 Symbol* name = constants->uncached_name_ref_at(cp_index);
282 Symbol* signature = constants->uncached_signature_ref_at(cp_index);
283 const char* sep = tag.is_dynamic_constant() ? ":" : "";
284 st->print_cr(" %d <%s%s%s>", cp_index, name->as_C_string(), sep, signature->as_C_string());
285 }
286
287 void BytecodePrinter::print_invokedynamic(int indy_index, int cp_index, outputStream* st) {
288 print_dynamic(cp_index, st);
289
290 if (ClassPrinter::has_mode(_flags, ClassPrinter::PRINT_DYNAMIC)) {
291 print_bsm(cp_index, st);
292
293 if (is_linked()) {
294 ResolvedIndyEntry* indy_entry = constants()->resolved_indy_entry_at(indy_index);
295 st->print(" ResolvedIndyEntry: ");
296 indy_entry->print_on(st);
297 }
298 }
299 }
300
301 // cp_index: must be the cp_index of a JVM_CONSTANT_{Dynamic, DynamicInError, InvokeDynamic}
302 void BytecodePrinter::print_bsm(int cp_index, outputStream* st) {
303 assert(constants()->tag_at(cp_index).has_bootstrap(), "must be");
304 int bsm = constants()->bootstrap_method_ref_index_at(cp_index);
305 const char* ref_kind = "";
306 switch (constants()->method_handle_ref_kind_at(bsm)) {
307 case JVM_REF_getField : ref_kind = "REF_getField"; break;
308 case JVM_REF_getStatic : ref_kind = "REF_getStatic"; break;
309 case JVM_REF_putField : ref_kind = "REF_putField"; break;
310 case JVM_REF_putStatic : ref_kind = "REF_putStatic"; break;
311 case JVM_REF_invokeVirtual : ref_kind = "REF_invokeVirtual"; break;
312 case JVM_REF_invokeStatic : ref_kind = "REF_invokeStatic"; break;
313 case JVM_REF_invokeSpecial : ref_kind = "REF_invokeSpecial"; break;
314 case JVM_REF_newInvokeSpecial : ref_kind = "REF_newInvokeSpecial"; break;
315 case JVM_REF_invokeInterface : ref_kind = "REF_invokeInterface"; break;
316 default : ShouldNotReachHere();
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "cds/heapShared.hpp"
27 #include "classfile/classPrinter.hpp"
28 #include "classfile/javaClasses.inline.hpp"
29 #include "interpreter/bytecodeHistogram.hpp"
30 #include "interpreter/bytecodeStream.hpp"
31 #include "interpreter/bytecodeTracer.hpp"
32 #include "interpreter/bytecodes.hpp"
33 #include "interpreter/interpreter.hpp"
34 #include "interpreter/interpreterRuntime.hpp"
35 #include "memory/resourceArea.hpp"
36 #include "oops/constantPool.inline.hpp"
37 #include "oops/methodData.hpp"
38 #include "oops/method.hpp"
39 #include "oops/resolvedFieldEntry.hpp"
40 #include "oops/resolvedIndyEntry.hpp"
41 #include "oops/resolvedMethodEntry.hpp"
42 #include "runtime/handles.inline.hpp"
43 #include "runtime/mutexLocker.hpp"
44 #include "runtime/osThread.hpp"
45 #include "runtime/timer.hpp"
46 #include "utilities/align.hpp"
106 // This is acceptable in a debug-only feature.
107 st->cr();
108 st->print("[%ld] ", (long) Thread::current()->osthread()->thread_id());
109 method->print_name(st);
110 st->cr();
111 _current_method = method();
112 _is_linked = method->method_holder()->is_linked();
113 assert(_is_linked, "this function must be called on methods that are already executing");
114 }
115 Bytecodes::Code code;
116 if (is_wide()) {
117 // bcp wasn't advanced if previous bytecode was _wide.
118 code = Bytecodes::code_at(method(), bcp+1);
119 } else {
120 code = Bytecodes::code_at(method(), bcp);
121 }
122 _code = code;
123 int bci = (int)(bcp - method->code_base());
124 st->print("[%ld] ", (long) Thread::current()->osthread()->thread_id());
125 if (Verbose) {
126 st->print("%8ld %4d " INTPTR_FORMAT " " INTPTR_FORMAT " %s",
127 BytecodeCounter::counter_value(), bci, tos, tos2, Bytecodes::name(code));
128 } else {
129 st->print("%8ld %4d %s",
130 BytecodeCounter::counter_value(), bci, Bytecodes::name(code));
131 }
132 _next_pc = is_wide() ? bcp+2 : bcp+1;
133 print_attributes(bci, st);
134 // Set is_wide for the next one, since the caller of this doesn't skip
135 // the next bytecode.
136 _is_wide = (code == Bytecodes::_wide);
137 _code = Bytecodes::_illegal;
138
139 #ifndef PRODUCT
140 if (TraceBytecodesStopAt != 0 && BytecodeCounter::counter_value() >= TraceBytecodesStopAt) {
141 TraceBytecodes = false;
142 }
143 #endif
144 }
145
146 // Used for Method*::print_codes(). The input bcp comes from
147 // BytecodeStream, which will skip wide bytecodes.
148 void trace(const methodHandle& method, address bcp, outputStream* st) {
149 _current_method = method();
151 ResourceMark rm;
152 Bytecodes::Code code = Bytecodes::code_at(method(), bcp);
153 // Set is_wide
154 _is_wide = (code == Bytecodes::_wide);
155 if (is_wide()) {
156 code = Bytecodes::code_at(method(), bcp+1);
157 }
158 _code = code;
159 int bci = (int)(bcp - method->code_base());
160 // Print bytecode index and name
161 if (ClassPrinter::has_mode(_flags, ClassPrinter::PRINT_BYTECODE_ADDR)) {
162 st->print(INTPTR_FORMAT " ", p2i(bcp));
163 }
164 if (is_wide()) {
165 st->print("%4d %s_w", bci, Bytecodes::name(code));
166 } else {
167 st->print("%4d %s", bci, Bytecodes::name(code));
168 }
169 _next_pc = is_wide() ? bcp+2 : bcp+1;
170 print_attributes(bci, st);
171 if (ClassPrinter::has_mode(_flags, ClassPrinter::PRINT_PROFILE)) {
172 bytecode_epilog(bci, st);
173 }
174 }
175 };
176
177 // We need a global instance to keep track of the states when the bytecodes
178 // are executed. Access by multiple threads are controlled by ttyLocker.
179 static BytecodePrinter _interpreter_printer;
180
181 void BytecodeTracer::trace_interpreter(const methodHandle& method, address bcp, uintptr_t tos, uintptr_t tos2, outputStream* st) {
182 if (TraceBytecodes && BytecodeCounter::counter_value() >= TraceBytecodesAt) {
183 ttyLocker ttyl; // 5065316: keep the following output coherent
184 // The ttyLocker also prevents races between two threads
185 // trying to use the single instance of BytecodePrinter.
186 //
187 // There used to be a leaf mutex here, but the ttyLocker will
188 // work just as well, as long as the printing operations never block.
189 _interpreter_printer.trace(method, bcp, tos, tos2, st);
190 }
191 }
192
193 void BytecodeTracer::print_method_codes(const methodHandle& method, int from, int to, outputStream* st, int flags) {
280
281 int bsm = constants->bootstrap_method_ref_index_at(cp_index);
282 st->print(" bsm=%d", bsm);
283
284 Symbol* name = constants->uncached_name_ref_at(cp_index);
285 Symbol* signature = constants->uncached_signature_ref_at(cp_index);
286 const char* sep = tag.is_dynamic_constant() ? ":" : "";
287 st->print_cr(" %d <%s%s%s>", cp_index, name->as_C_string(), sep, signature->as_C_string());
288 }
289
290 void BytecodePrinter::print_invokedynamic(int indy_index, int cp_index, outputStream* st) {
291 print_dynamic(cp_index, st);
292
293 if (ClassPrinter::has_mode(_flags, ClassPrinter::PRINT_DYNAMIC)) {
294 print_bsm(cp_index, st);
295
296 if (is_linked()) {
297 ResolvedIndyEntry* indy_entry = constants()->resolved_indy_entry_at(indy_index);
298 st->print(" ResolvedIndyEntry: ");
299 indy_entry->print_on(st);
300 if (indy_entry->has_appendix()) {
301 oop apx = constants()->resolved_reference_from_indy(indy_index);
302 //FIXME: lock out of order with runtime/interpreter/BytecodeTracerTest.java
303 //int perm_index = HeapShared::get_archived_object_permanent_index(apx);
304 st->print_cr(" - appendix = " INTPTR_FORMAT, p2i(apx));
305 }
306 }
307 }
308 }
309
310 // cp_index: must be the cp_index of a JVM_CONSTANT_{Dynamic, DynamicInError, InvokeDynamic}
311 void BytecodePrinter::print_bsm(int cp_index, outputStream* st) {
312 assert(constants()->tag_at(cp_index).has_bootstrap(), "must be");
313 int bsm = constants()->bootstrap_method_ref_index_at(cp_index);
314 const char* ref_kind = "";
315 switch (constants()->method_handle_ref_kind_at(bsm)) {
316 case JVM_REF_getField : ref_kind = "REF_getField"; break;
317 case JVM_REF_getStatic : ref_kind = "REF_getStatic"; break;
318 case JVM_REF_putField : ref_kind = "REF_putField"; break;
319 case JVM_REF_putStatic : ref_kind = "REF_putStatic"; break;
320 case JVM_REF_invokeVirtual : ref_kind = "REF_invokeVirtual"; break;
321 case JVM_REF_invokeStatic : ref_kind = "REF_invokeStatic"; break;
322 case JVM_REF_invokeSpecial : ref_kind = "REF_invokeSpecial"; break;
323 case JVM_REF_newInvokeSpecial : ref_kind = "REF_newInvokeSpecial"; break;
324 case JVM_REF_invokeInterface : ref_kind = "REF_invokeInterface"; break;
325 default : ShouldNotReachHere();
|