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