< prev index next >

src/hotspot/share/interpreter/bytecodeTracer.cpp

Print this page

  5  * This code is free software; you can redistribute it and/or modify it
  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 "classfile/classPrinter.hpp"
 26 #include "classfile/javaClasses.inline.hpp"
 27 #include "interpreter/bytecodeHistogram.hpp"
 28 #include "interpreter/bytecodeStream.hpp"
 29 #include "interpreter/bytecodeTracer.hpp"
 30 #include "interpreter/bytecodes.hpp"
 31 #include "interpreter/interpreter.hpp"
 32 #include "interpreter/interpreterRuntime.hpp"
 33 #include "memory/resourceArea.hpp"
 34 #include "oops/constantPool.inline.hpp"
 35 #include "oops/methodData.hpp"
 36 #include "oops/method.hpp"
 37 #include "oops/resolvedFieldEntry.hpp"
 38 #include "oops/resolvedIndyEntry.hpp"
 39 #include "oops/resolvedMethodEntry.hpp"
 40 #include "runtime/handles.inline.hpp"
 41 #include "runtime/mutexLocker.hpp"
 42 #include "runtime/osThread.hpp"
 43 #include "runtime/timer.hpp"
 44 #include "utilities/align.hpp"

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     _next_pc = is_wide() ? bcp+2 : bcp+1;
123     // Trace each bytecode unless we're truncating the tracing output, then only print the first
124     // bytecode in every method as well as returns/throws that pop control flow
125     if (!TraceBytecodesTruncated || method_changed ||
126         code == Bytecodes::_athrow ||
127         code == Bytecodes::_return_register_finalizer ||
128         (code >= Bytecodes::_ireturn && code <= Bytecodes::_return)) {
129       int bci = (int)(bcp - method->code_base());
130       st->print("[%zu] ", Thread::current()->osthread()->thread_id_for_printing());
131       if (Verbose) {
132         st->print("%8d  %4d  " INTPTR_FORMAT " " INTPTR_FORMAT " %s",
133             BytecodeCounter::counter_value(), bci, tos, tos2, Bytecodes::name(code));
134       } else {
135         st->print("%8d  %4d  %s",
136             BytecodeCounter::counter_value(), bci, Bytecodes::name(code));
137       }
138       print_attributes(bci, st);
139     }
140     // Set is_wide for the next one, since the caller of this doesn't skip
141     // the next bytecode.
142     _is_wide = (code == Bytecodes::_wide);
143     _code = Bytecodes::_illegal;
144 
145 #ifndef PRODUCT
146     if (TraceBytecodesStopAt != 0 && BytecodeCounter::counter_value() >= TraceBytecodesStopAt) {
147       TraceBytecodes = false;
148     }
149 #endif
150   }
151 
152   // Used for Method*::print_codes().  The input bcp comes from
153   // BytecodeStream, which will skip wide bytecodes.
154   void trace(const methodHandle& method, address bcp, outputStream* st) {
155     _current_method = method();

157     ResourceMark rm;
158     Bytecodes::Code code = Bytecodes::code_at(method(), bcp);
159     // Set is_wide
160     _is_wide = (code == Bytecodes::_wide);
161     if (is_wide()) {
162       code = Bytecodes::code_at(method(), bcp+1);
163     }
164     _code = code;
165     int bci = (int)(bcp - method->code_base());
166     // Print bytecode index and name
167     if (ClassPrinter::has_mode(_flags, ClassPrinter::PRINT_BYTECODE_ADDR)) {
168       st->print(INTPTR_FORMAT " ", p2i(bcp));
169     }
170     if (is_wide()) {
171       st->print("%4d %s_w", bci, Bytecodes::name(code));
172     } else {
173       st->print("%4d %s", bci, Bytecodes::name(code));
174     }
175     _next_pc = is_wide() ? bcp+2 : bcp+1;
176     print_attributes(bci, st);
177     bytecode_epilog(bci, st);


178   }
179 };
180 
181 // We need a global instance to keep track of the states when the bytecodes
182 // are executed. Access by multiple threads are controlled by ttyLocker.
183 static BytecodePrinter _interpreter_printer;
184 
185 void BytecodeTracer::trace_interpreter(const methodHandle& method, address bcp, uintptr_t tos, uintptr_t tos2, outputStream* st) {
186   if (TraceBytecodes && BytecodeCounter::counter_value() >= TraceBytecodesAt) {
187     ttyLocker ttyl;  // 5065316: keep the following output coherent
188     // The ttyLocker also prevents races between two threads
189     // trying to use the single instance of BytecodePrinter.
190     //
191     // There used to be a leaf mutex here, but the ttyLocker will
192     // work just as well, as long as the printing operations never block.
193     _interpreter_printer.trace(method, bcp, tos, tos2, st);
194   }
195 }
196 
197 void BytecodeTracer::print_method_codes(const methodHandle& method, int from, int to, outputStream* st, int flags) {

284 
285   int bsm = constants->bootstrap_method_ref_index_at(cp_index);
286   st->print(" bsm=%d", bsm);
287 
288   Symbol* name = constants->uncached_name_ref_at(cp_index);
289   Symbol* signature = constants->uncached_signature_ref_at(cp_index);
290   const char* sep = tag.is_dynamic_constant() ? ":" : "";
291   st->print_cr(" %d <%s%s%s>", cp_index, name->as_C_string(), sep, signature->as_C_string());
292 }
293 
294 void BytecodePrinter::print_invokedynamic(int indy_index, int cp_index, outputStream* st) {
295   print_dynamic(cp_index, st);
296 
297   if (ClassPrinter::has_mode(_flags, ClassPrinter::PRINT_DYNAMIC)) {
298     print_bsm(cp_index, st);
299 
300     if (is_linked()) {
301       ResolvedIndyEntry* indy_entry = constants()->resolved_indy_entry_at(indy_index);
302       st->print("  ResolvedIndyEntry: ");
303       indy_entry->print_on(st);




304     }
305   }
306 }
307 
308 // cp_index: must be the cp_index of a JVM_CONSTANT_{Dynamic, DynamicInError, InvokeDynamic}
309 void BytecodePrinter::print_bsm(int cp_index, outputStream* st) {
310   assert(constants()->tag_at(cp_index).has_bootstrap(), "must be");
311   int bsm = constants()->bootstrap_method_ref_index_at(cp_index);
312   const char* ref_kind = "";
313   switch (constants()->method_handle_ref_kind_at(bsm)) {
314   case JVM_REF_getField         : ref_kind = "REF_getField"; break;
315   case JVM_REF_getStatic        : ref_kind = "REF_getStatic"; break;
316   case JVM_REF_putField         : ref_kind = "REF_putField"; break;
317   case JVM_REF_putStatic        : ref_kind = "REF_putStatic"; break;
318   case JVM_REF_invokeVirtual    : ref_kind = "REF_invokeVirtual"; break;
319   case JVM_REF_invokeStatic     : ref_kind = "REF_invokeStatic"; break;
320   case JVM_REF_invokeSpecial    : ref_kind = "REF_invokeSpecial"; break;
321   case JVM_REF_newInvokeSpecial : ref_kind = "REF_newInvokeSpecial"; break;
322   case JVM_REF_invokeInterface  : ref_kind = "REF_invokeInterface"; break;
323   default                       : ShouldNotReachHere();

  5  * This code is free software; you can redistribute it and/or modify it
  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 "cds/heapShared.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("[%zu] ", Thread::current()->osthread()->thread_id_for_printing());
132       if (Verbose) {
133         st->print(JLONG_FORMAT_W(8) "  %4d  " INTPTR_FORMAT " " INTPTR_FORMAT " %s",
134             BytecodeCounter::counter_value(), bci, tos, tos2, Bytecodes::name(code));
135       } else {
136         st->print(JLONG_FORMAT_W(8) "  %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     if (ClassPrinter::has_mode(_flags, ClassPrinter::PRINT_PROFILE)) {
179       bytecode_epilog(bci, st);
180     }
181   }
182 };
183 
184 // We need a global instance to keep track of the states when the bytecodes
185 // are executed. Access by multiple threads are controlled by ttyLocker.
186 static BytecodePrinter _interpreter_printer;
187 
188 void BytecodeTracer::trace_interpreter(const methodHandle& method, address bcp, uintptr_t tos, uintptr_t tos2, outputStream* st) {
189   if (TraceBytecodes && BytecodeCounter::counter_value() >= TraceBytecodesAt) {
190     ttyLocker ttyl;  // 5065316: keep the following output coherent
191     // The ttyLocker also prevents races between two threads
192     // trying to use the single instance of BytecodePrinter.
193     //
194     // There used to be a leaf mutex here, but the ttyLocker will
195     // work just as well, as long as the printing operations never block.
196     _interpreter_printer.trace(method, bcp, tos, tos2, st);
197   }
198 }
199 
200 void BytecodeTracer::print_method_codes(const methodHandle& method, int from, int to, outputStream* st, int flags) {

287 
288   int bsm = constants->bootstrap_method_ref_index_at(cp_index);
289   st->print(" bsm=%d", bsm);
290 
291   Symbol* name = constants->uncached_name_ref_at(cp_index);
292   Symbol* signature = constants->uncached_signature_ref_at(cp_index);
293   const char* sep = tag.is_dynamic_constant() ? ":" : "";
294   st->print_cr(" %d <%s%s%s>", cp_index, name->as_C_string(), sep, signature->as_C_string());
295 }
296 
297 void BytecodePrinter::print_invokedynamic(int indy_index, int cp_index, outputStream* st) {
298   print_dynamic(cp_index, st);
299 
300   if (ClassPrinter::has_mode(_flags, ClassPrinter::PRINT_DYNAMIC)) {
301     print_bsm(cp_index, st);
302 
303     if (is_linked()) {
304       ResolvedIndyEntry* indy_entry = constants()->resolved_indy_entry_at(indy_index);
305       st->print("  ResolvedIndyEntry: ");
306       indy_entry->print_on(st);
307       if (indy_entry->has_appendix()) {
308         oop apx = constants()->resolved_reference_from_indy(indy_index);
309         st->print_cr(" - appendix = " INTPTR_FORMAT, p2i(apx));
310       }
311     }
312   }
313 }
314 
315 // cp_index: must be the cp_index of a JVM_CONSTANT_{Dynamic, DynamicInError, InvokeDynamic}
316 void BytecodePrinter::print_bsm(int cp_index, outputStream* st) {
317   assert(constants()->tag_at(cp_index).has_bootstrap(), "must be");
318   int bsm = constants()->bootstrap_method_ref_index_at(cp_index);
319   const char* ref_kind = "";
320   switch (constants()->method_handle_ref_kind_at(bsm)) {
321   case JVM_REF_getField         : ref_kind = "REF_getField"; break;
322   case JVM_REF_getStatic        : ref_kind = "REF_getStatic"; break;
323   case JVM_REF_putField         : ref_kind = "REF_putField"; break;
324   case JVM_REF_putStatic        : ref_kind = "REF_putStatic"; break;
325   case JVM_REF_invokeVirtual    : ref_kind = "REF_invokeVirtual"; break;
326   case JVM_REF_invokeStatic     : ref_kind = "REF_invokeStatic"; break;
327   case JVM_REF_invokeSpecial    : ref_kind = "REF_invokeSpecial"; break;
328   case JVM_REF_newInvokeSpecial : ref_kind = "REF_newInvokeSpecial"; break;
329   case JVM_REF_invokeInterface  : ref_kind = "REF_invokeInterface"; break;
330   default                       : ShouldNotReachHere();
< prev index next >