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"
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 _next_pc = is_wide() ? bcp+2 : bcp+1;
124 // Trace each bytecode unless we're truncating the tracing output, then only print the first
125 // bytecode in every method as well as returns/throws that pop control flow
126 if (!TraceBytecodesTruncated || method_changed ||
127 code == Bytecodes::_athrow ||
128 code == Bytecodes::_return_register_finalizer ||
129 (code >= Bytecodes::_ireturn && code <= Bytecodes::_return)) {
130 int bci = (int)(bcp - method->code_base());
131 st->print("[" UINTX_FORMAT "] ", Thread::current()->osthread()->thread_id_for_printing());
132 if (Verbose) {
133 st->print("%8d %4d " INTPTR_FORMAT " " INTPTR_FORMAT " %s",
134 BytecodeCounter::counter_value(), bci, tos, tos2, Bytecodes::name(code));
135 } else {
136 st->print("%8d %4d %s",
137 BytecodeCounter::counter_value(), bci, Bytecodes::name(code));
138 }
139 print_attributes(bci, st);
140 }
141 // Set is_wide for the next one, since the caller of this doesn't skip
142 // the next bytecode.
143 _is_wide = (code == Bytecodes::_wide);
144 _code = Bytecodes::_illegal;
145
146 #ifndef PRODUCT
147 if (TraceBytecodesStopAt != 0 && BytecodeCounter::counter_value() >= TraceBytecodesStopAt) {
148 TraceBytecodes = false;
149 }
150 #endif
151 }
152
153 // Used for Method*::print_codes(). The input bcp comes from
154 // BytecodeStream, which will skip wide bytecodes.
155 void trace(const methodHandle& method, address bcp, outputStream* st) {
156 _current_method = method();
158 ResourceMark rm;
159 Bytecodes::Code code = Bytecodes::code_at(method(), bcp);
160 // Set is_wide
161 _is_wide = (code == Bytecodes::_wide);
162 if (is_wide()) {
163 code = Bytecodes::code_at(method(), bcp+1);
164 }
165 _code = code;
166 int bci = (int)(bcp - method->code_base());
167 // Print bytecode index and name
168 if (ClassPrinter::has_mode(_flags, ClassPrinter::PRINT_BYTECODE_ADDR)) {
169 st->print(INTPTR_FORMAT " ", p2i(bcp));
170 }
171 if (is_wide()) {
172 st->print("%4d %s_w", bci, Bytecodes::name(code));
173 } else {
174 st->print("%4d %s", bci, Bytecodes::name(code));
175 }
176 _next_pc = is_wide() ? bcp+2 : bcp+1;
177 print_attributes(bci, st);
178 bytecode_epilog(bci, st);
179 }
180 };
181
182 // We need a global instance to keep track of the states when the bytecodes
183 // are executed. Access by multiple threads are controlled by ttyLocker.
184 static BytecodePrinter _interpreter_printer;
185
186 void BytecodeTracer::trace_interpreter(const methodHandle& method, address bcp, uintptr_t tos, uintptr_t tos2, outputStream* st) {
187 if (TraceBytecodes && BytecodeCounter::counter_value() >= TraceBytecodesAt) {
188 ttyLocker ttyl; // 5065316: keep the following output coherent
189 // The ttyLocker also prevents races between two threads
190 // trying to use the single instance of BytecodePrinter.
191 //
192 // There used to be a leaf mutex here, but the ttyLocker will
193 // work just as well, as long as the printing operations never block.
194 _interpreter_printer.trace(method, bcp, tos, tos2, st);
195 }
196 }
197
198 void BytecodeTracer::print_method_codes(const methodHandle& method, int from, int to, outputStream* st, int flags) {
285
286 int bsm = constants->bootstrap_method_ref_index_at(cp_index);
287 st->print(" bsm=%d", bsm);
288
289 Symbol* name = constants->uncached_name_ref_at(cp_index);
290 Symbol* signature = constants->uncached_signature_ref_at(cp_index);
291 const char* sep = tag.is_dynamic_constant() ? ":" : "";
292 st->print_cr(" %d <%s%s%s>", cp_index, name->as_C_string(), sep, signature->as_C_string());
293 }
294
295 void BytecodePrinter::print_invokedynamic(int indy_index, int cp_index, outputStream* st) {
296 print_dynamic(cp_index, st);
297
298 if (ClassPrinter::has_mode(_flags, ClassPrinter::PRINT_DYNAMIC)) {
299 print_bsm(cp_index, st);
300
301 if (is_linked()) {
302 ResolvedIndyEntry* indy_entry = constants()->resolved_indy_entry_at(indy_index);
303 st->print(" ResolvedIndyEntry: ");
304 indy_entry->print_on(st);
305 }
306 }
307 }
308
309 // cp_index: must be the cp_index of a JVM_CONSTANT_{Dynamic, DynamicInError, InvokeDynamic}
310 void BytecodePrinter::print_bsm(int cp_index, outputStream* st) {
311 assert(constants()->tag_at(cp_index).has_bootstrap(), "must be");
312 int bsm = constants()->bootstrap_method_ref_index_at(cp_index);
313 const char* ref_kind = "";
314 switch (constants()->method_handle_ref_kind_at(bsm)) {
315 case JVM_REF_getField : ref_kind = "REF_getField"; break;
316 case JVM_REF_getStatic : ref_kind = "REF_getStatic"; break;
317 case JVM_REF_putField : ref_kind = "REF_putField"; break;
318 case JVM_REF_putStatic : ref_kind = "REF_putStatic"; break;
319 case JVM_REF_invokeVirtual : ref_kind = "REF_invokeVirtual"; break;
320 case JVM_REF_invokeStatic : ref_kind = "REF_invokeStatic"; break;
321 case JVM_REF_invokeSpecial : ref_kind = "REF_invokeSpecial"; break;
322 case JVM_REF_newInvokeSpecial : ref_kind = "REF_newInvokeSpecial"; break;
323 case JVM_REF_invokeInterface : ref_kind = "REF_invokeInterface"; break;
324 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"
114 assert(_is_linked, "this function must be called on methods that are already executing");
115 }
116 Bytecodes::Code code;
117 if (is_wide()) {
118 // bcp wasn't advanced if previous bytecode was _wide.
119 code = Bytecodes::code_at(method(), bcp+1);
120 } else {
121 code = Bytecodes::code_at(method(), bcp);
122 }
123 _code = code;
124 _next_pc = is_wide() ? bcp+2 : bcp+1;
125 // Trace each bytecode unless we're truncating the tracing output, then only print the first
126 // bytecode in every method as well as returns/throws that pop control flow
127 if (!TraceBytecodesTruncated || method_changed ||
128 code == Bytecodes::_athrow ||
129 code == Bytecodes::_return_register_finalizer ||
130 (code >= Bytecodes::_ireturn && code <= Bytecodes::_return)) {
131 int bci = (int)(bcp - method->code_base());
132 st->print("[" UINTX_FORMAT "] ", Thread::current()->osthread()->thread_id_for_printing());
133 if (Verbose) {
134 st->print(JLONG_FORMAT_W(8) " %4d " INTPTR_FORMAT " " INTPTR_FORMAT " %s",
135 BytecodeCounter::counter_value(), bci, tos, tos2, Bytecodes::name(code));
136 } else {
137 st->print(JLONG_FORMAT_W(8) " %4d %s",
138 BytecodeCounter::counter_value(), bci, Bytecodes::name(code));
139 }
140 print_attributes(bci, st);
141 }
142 // Set is_wide for the next one, since the caller of this doesn't skip
143 // the next bytecode.
144 _is_wide = (code == Bytecodes::_wide);
145 _code = Bytecodes::_illegal;
146
147 #ifndef PRODUCT
148 if (TraceBytecodesStopAt != 0 && BytecodeCounter::counter_value() >= TraceBytecodesStopAt) {
149 TraceBytecodes = false;
150 }
151 #endif
152 }
153
154 // Used for Method*::print_codes(). The input bcp comes from
155 // BytecodeStream, which will skip wide bytecodes.
156 void trace(const methodHandle& method, address bcp, outputStream* st) {
157 _current_method = method();
159 ResourceMark rm;
160 Bytecodes::Code code = Bytecodes::code_at(method(), bcp);
161 // Set is_wide
162 _is_wide = (code == Bytecodes::_wide);
163 if (is_wide()) {
164 code = Bytecodes::code_at(method(), bcp+1);
165 }
166 _code = code;
167 int bci = (int)(bcp - method->code_base());
168 // Print bytecode index and name
169 if (ClassPrinter::has_mode(_flags, ClassPrinter::PRINT_BYTECODE_ADDR)) {
170 st->print(INTPTR_FORMAT " ", p2i(bcp));
171 }
172 if (is_wide()) {
173 st->print("%4d %s_w", bci, Bytecodes::name(code));
174 } else {
175 st->print("%4d %s", bci, Bytecodes::name(code));
176 }
177 _next_pc = is_wide() ? bcp+2 : bcp+1;
178 print_attributes(bci, st);
179 if (ClassPrinter::has_mode(_flags, ClassPrinter::PRINT_PROFILE)) {
180 bytecode_epilog(bci, st);
181 }
182 }
183 };
184
185 // We need a global instance to keep track of the states when the bytecodes
186 // are executed. Access by multiple threads are controlled by ttyLocker.
187 static BytecodePrinter _interpreter_printer;
188
189 void BytecodeTracer::trace_interpreter(const methodHandle& method, address bcp, uintptr_t tos, uintptr_t tos2, outputStream* st) {
190 if (TraceBytecodes && BytecodeCounter::counter_value() >= TraceBytecodesAt) {
191 ttyLocker ttyl; // 5065316: keep the following output coherent
192 // The ttyLocker also prevents races between two threads
193 // trying to use the single instance of BytecodePrinter.
194 //
195 // There used to be a leaf mutex here, but the ttyLocker will
196 // work just as well, as long as the printing operations never block.
197 _interpreter_printer.trace(method, bcp, tos, tos2, st);
198 }
199 }
200
201 void BytecodeTracer::print_method_codes(const methodHandle& method, int from, int to, outputStream* st, int flags) {
288
289 int bsm = constants->bootstrap_method_ref_index_at(cp_index);
290 st->print(" bsm=%d", bsm);
291
292 Symbol* name = constants->uncached_name_ref_at(cp_index);
293 Symbol* signature = constants->uncached_signature_ref_at(cp_index);
294 const char* sep = tag.is_dynamic_constant() ? ":" : "";
295 st->print_cr(" %d <%s%s%s>", cp_index, name->as_C_string(), sep, signature->as_C_string());
296 }
297
298 void BytecodePrinter::print_invokedynamic(int indy_index, int cp_index, outputStream* st) {
299 print_dynamic(cp_index, st);
300
301 if (ClassPrinter::has_mode(_flags, ClassPrinter::PRINT_DYNAMIC)) {
302 print_bsm(cp_index, st);
303
304 if (is_linked()) {
305 ResolvedIndyEntry* indy_entry = constants()->resolved_indy_entry_at(indy_index);
306 st->print(" ResolvedIndyEntry: ");
307 indy_entry->print_on(st);
308 if (indy_entry->has_appendix()) {
309 oop apx = constants()->resolved_reference_from_indy(indy_index);
310 //FIXME: lock out of order with runtime/interpreter/BytecodeTracerTest.java
311 //int perm_index = HeapShared::get_archived_object_permanent_index(apx);
312 st->print_cr(" - appendix = " INTPTR_FORMAT, p2i(apx));
313 }
314 }
315 }
316 }
317
318 // cp_index: must be the cp_index of a JVM_CONSTANT_{Dynamic, DynamicInError, InvokeDynamic}
319 void BytecodePrinter::print_bsm(int cp_index, outputStream* st) {
320 assert(constants()->tag_at(cp_index).has_bootstrap(), "must be");
321 int bsm = constants()->bootstrap_method_ref_index_at(cp_index);
322 const char* ref_kind = "";
323 switch (constants()->method_handle_ref_kind_at(bsm)) {
324 case JVM_REF_getField : ref_kind = "REF_getField"; break;
325 case JVM_REF_getStatic : ref_kind = "REF_getStatic"; break;
326 case JVM_REF_putField : ref_kind = "REF_putField"; break;
327 case JVM_REF_putStatic : ref_kind = "REF_putStatic"; break;
328 case JVM_REF_invokeVirtual : ref_kind = "REF_invokeVirtual"; break;
329 case JVM_REF_invokeStatic : ref_kind = "REF_invokeStatic"; break;
330 case JVM_REF_invokeSpecial : ref_kind = "REF_invokeSpecial"; break;
331 case JVM_REF_newInvokeSpecial : ref_kind = "REF_newInvokeSpecial"; break;
332 case JVM_REF_invokeInterface : ref_kind = "REF_invokeInterface"; break;
333 default : ShouldNotReachHere();
|