Mercurial > hg > truffle
comparison src/share/vm/interpreter/bytecodeTracer.cpp @ 1602:136b78722a08
6939203: JSR 292 needs method handle constants
Summary: Add new CP types CONSTANT_MethodHandle, CONSTANT_MethodType; extend 'ldc' bytecode.
Reviewed-by: twisti, never
author | jrose |
---|---|
date | Wed, 09 Jun 2010 18:50:45 -0700 |
parents | e9ff18c4ace7 |
children | 083fde3b838e |
comparison
equal
deleted
inserted
replaced
1585:49fac4acd688 | 1602:136b78722a08 |
---|---|
47 short get_short() { short i=Bytes::get_Java_u2(_next_pc); _next_pc+=2; return i; } | 47 short get_short() { short i=Bytes::get_Java_u2(_next_pc); _next_pc+=2; return i; } |
48 int get_int() { int i=Bytes::get_Java_u4(_next_pc); _next_pc+=4; return i; } | 48 int get_int() { int i=Bytes::get_Java_u4(_next_pc); _next_pc+=4; return i; } |
49 | 49 |
50 int get_index_u1() { return *(address)_next_pc++; } | 50 int get_index_u1() { return *(address)_next_pc++; } |
51 int get_index_u2() { int i=Bytes::get_Java_u2(_next_pc); _next_pc+=2; return i; } | 51 int get_index_u2() { int i=Bytes::get_Java_u2(_next_pc); _next_pc+=2; return i; } |
52 int get_index_u1_cpcache() { return get_index_u1() + constantPoolOopDesc::CPCACHE_INDEX_TAG; } | |
52 int get_index_u2_cpcache() { int i=Bytes::get_native_u2(_next_pc); _next_pc+=2; return i + constantPoolOopDesc::CPCACHE_INDEX_TAG; } | 53 int get_index_u2_cpcache() { int i=Bytes::get_native_u2(_next_pc); _next_pc+=2; return i + constantPoolOopDesc::CPCACHE_INDEX_TAG; } |
53 int get_index_u4() { int i=Bytes::get_native_u4(_next_pc); _next_pc+=4; return i; } | 54 int get_index_u4() { int i=Bytes::get_native_u4(_next_pc); _next_pc+=4; return i; } |
54 int get_index_special() { return (is_wide()) ? get_index_u2() : get_index_u1(); } | 55 int get_index_special() { return (is_wide()) ? get_index_u2() : get_index_u1(); } |
55 methodOop method() { return _current_method; } | 56 methodOop method() { return _current_method; } |
56 bool is_wide() { return _is_wide; } | 57 bool is_wide() { return _is_wide; } |
58 | 59 |
59 | 60 |
60 bool check_index(int i, int& cp_index, outputStream* st = tty); | 61 bool check_index(int i, int& cp_index, outputStream* st = tty); |
61 void print_constant(int i, outputStream* st = tty); | 62 void print_constant(int i, outputStream* st = tty); |
62 void print_field_or_method(int i, outputStream* st = tty); | 63 void print_field_or_method(int i, outputStream* st = tty); |
64 void print_field_or_method(int orig_i, int i, outputStream* st = tty); | |
63 void print_attributes(int bci, outputStream* st = tty); | 65 void print_attributes(int bci, outputStream* st = tty); |
64 void bytecode_epilog(int bci, outputStream* st = tty); | 66 void bytecode_epilog(int bci, outputStream* st = tty); |
65 | 67 |
66 public: | 68 public: |
67 BytecodePrinter() { | 69 BytecodePrinter() { |
175 void BytecodeTracer::trace(methodHandle method, address bcp, outputStream* st) { | 177 void BytecodeTracer::trace(methodHandle method, address bcp, outputStream* st) { |
176 ttyLocker ttyl; // 5065316: keep the following output coherent | 178 ttyLocker ttyl; // 5065316: keep the following output coherent |
177 _closure->trace(method, bcp, st); | 179 _closure->trace(method, bcp, st); |
178 } | 180 } |
179 | 181 |
182 void print_symbol(symbolOop sym, outputStream* st) { | |
183 char buf[40]; | |
184 int len = sym->utf8_length(); | |
185 if (len >= (int)sizeof(buf)) { | |
186 st->print_cr(" %s...[%d]", sym->as_C_string(buf, sizeof(buf)), len); | |
187 } else { | |
188 st->print(" "); | |
189 sym->print_on(st); st->cr(); | |
190 } | |
191 } | |
192 | |
180 void print_oop(oop value, outputStream* st) { | 193 void print_oop(oop value, outputStream* st) { |
181 if (value == NULL) { | 194 if (value == NULL) { |
182 st->print_cr(" NULL"); | 195 st->print_cr(" NULL"); |
183 } else { | 196 } else if (java_lang_String::is_instance(value)) { |
184 EXCEPTION_MARK; | 197 EXCEPTION_MARK; |
185 Handle h_value (THREAD, value); | 198 Handle h_value (THREAD, value); |
186 symbolHandle sym = java_lang_String::as_symbol(h_value, CATCH); | 199 symbolHandle sym = java_lang_String::as_symbol(h_value, CATCH); |
187 if (sym->utf8_length() > 32) { | 200 print_symbol(sym(), st); |
188 st->print_cr(" ...."); | 201 } else if (value->is_symbol()) { |
189 } else { | 202 print_symbol(symbolOop(value), st); |
190 sym->print_on(st); st->cr(); | 203 } else { |
191 } | 204 st->print_cr(" " PTR_FORMAT, (intptr_t) value); |
192 } | 205 } |
193 } | 206 } |
194 | 207 |
195 bool BytecodePrinter::check_index(int i, int& cp_index, outputStream* st) { | 208 bool BytecodePrinter::check_index(int i, int& cp_index, outputStream* st) { |
196 constantPoolOop constants = method()->constants(); | 209 constantPoolOop constants = method()->constants(); |
277 } else if (tag.is_float()) { | 290 } else if (tag.is_float()) { |
278 st->print_cr(" %f", constants->float_at(i)); | 291 st->print_cr(" %f", constants->float_at(i)); |
279 } else if (tag.is_double()) { | 292 } else if (tag.is_double()) { |
280 st->print_cr(" %f", constants->double_at(i)); | 293 st->print_cr(" %f", constants->double_at(i)); |
281 } else if (tag.is_string()) { | 294 } else if (tag.is_string()) { |
282 oop string = constants->resolved_string_at(i); | 295 oop string = constants->pseudo_string_at(i); |
283 print_oop(string, st); | 296 print_oop(string, st); |
284 } else if (tag.is_unresolved_string()) { | 297 } else if (tag.is_unresolved_string()) { |
285 st->print_cr(" <unresolved string at %d>", i); | 298 const char* string = constants->string_at_noresolve(i); |
299 st->print_cr(" %s", string); | |
286 } else if (tag.is_klass()) { | 300 } else if (tag.is_klass()) { |
287 st->print_cr(" %s", constants->resolved_klass_at(i)->klass_part()->external_name()); | 301 st->print_cr(" %s", constants->resolved_klass_at(i)->klass_part()->external_name()); |
288 } else if (tag.is_unresolved_klass()) { | 302 } else if (tag.is_unresolved_klass()) { |
289 st->print_cr(" <unresolved klass at %d>", i); | 303 st->print_cr(" <unresolved klass at %d>", i); |
290 } else if (tag.is_object()) { | 304 } else if (tag.is_object()) { |
291 st->print_cr(" " PTR_FORMAT, constants->object_at(i)); | 305 st->print(" <Object>"); |
306 print_oop(constants->object_at(i), st); | |
307 } else if (tag.is_method_type()) { | |
308 int i2 = constants->method_type_index_at(i); | |
309 st->print(" <MethodType> %d", i2); | |
310 print_oop(constants->symbol_at(i2), st); | |
311 } else if (tag.is_method_handle()) { | |
312 int kind = constants->method_handle_ref_kind_at(i); | |
313 int i2 = constants->method_handle_index_at(i); | |
314 st->print(" <MethodHandle of kind %d>", kind, i2); | |
315 print_field_or_method(-i, i2, st); | |
292 } else { | 316 } else { |
293 st->print_cr(" bad tag=%d at %d", tag.value(), i); | 317 st->print_cr(" bad tag=%d at %d", tag.value(), i); |
294 } | 318 } |
295 } | 319 } |
296 | 320 |
297 void BytecodePrinter::print_field_or_method(int i, outputStream* st) { | 321 void BytecodePrinter::print_field_or_method(int i, outputStream* st) { |
298 int orig_i = i; | 322 int orig_i = i; |
299 if (!check_index(orig_i, i, st)) return; | 323 if (!check_index(orig_i, i, st)) return; |
300 | 324 print_field_or_method(orig_i, i, st); |
325 } | |
326 | |
327 void BytecodePrinter::print_field_or_method(int orig_i, int i, outputStream* st) { | |
301 constantPoolOop constants = method()->constants(); | 328 constantPoolOop constants = method()->constants(); |
302 constantTag tag = constants->tag_at(i); | 329 constantTag tag = constants->tag_at(i); |
303 | 330 |
304 int nt_index = -1; | 331 int nt_index = -1; |
305 | 332 |
312 default: | 339 default: |
313 st->print_cr(" bad tag=%d at %d", tag.value(), i); | 340 st->print_cr(" bad tag=%d at %d", tag.value(), i); |
314 return; | 341 return; |
315 } | 342 } |
316 | 343 |
344 symbolOop klass = constants->klass_name_at(constants->uncached_klass_ref_index_at(i)); | |
317 symbolOop name = constants->uncached_name_ref_at(i); | 345 symbolOop name = constants->uncached_name_ref_at(i); |
318 symbolOop signature = constants->uncached_signature_ref_at(i); | 346 symbolOop signature = constants->uncached_signature_ref_at(i); |
319 st->print_cr(" %d <%s> <%s> ", i, name->as_C_string(), signature->as_C_string()); | 347 const char* sep = (tag.is_field() ? "/" : ""); |
348 st->print_cr(" %d <%s.%s%s%s> ", i, klass->as_C_string(), name->as_C_string(), sep, signature->as_C_string()); | |
320 } | 349 } |
321 | 350 |
322 | 351 |
323 void BytecodePrinter::print_attributes(int bci, outputStream* st) { | 352 void BytecodePrinter::print_attributes(int bci, outputStream* st) { |
324 // Show attributes of pre-rewritten codes | 353 // Show attributes of pre-rewritten codes |
338 break; | 367 break; |
339 case Bytecodes::_sipush: | 368 case Bytecodes::_sipush: |
340 st->print_cr(" " INT32_FORMAT, get_short()); | 369 st->print_cr(" " INT32_FORMAT, get_short()); |
341 break; | 370 break; |
342 case Bytecodes::_ldc: | 371 case Bytecodes::_ldc: |
343 print_constant(get_index_u1(), st); | 372 if (Bytecodes::uses_cp_cache(raw_code())) { |
373 print_constant(get_index_u1_cpcache(), st); | |
374 } else { | |
375 print_constant(get_index_u1(), st); | |
376 } | |
344 break; | 377 break; |
345 | 378 |
346 case Bytecodes::_ldc_w: | 379 case Bytecodes::_ldc_w: |
347 case Bytecodes::_ldc2_w: | 380 case Bytecodes::_ldc2_w: |
348 print_constant(get_index_u2(), st); | 381 if (Bytecodes::uses_cp_cache(raw_code())) { |
382 print_constant(get_index_u2_cpcache(), st); | |
383 } else { | |
384 print_constant(get_index_u2(), st); | |
385 } | |
349 break; | 386 break; |
350 | 387 |
351 case Bytecodes::_iload: | 388 case Bytecodes::_iload: |
352 case Bytecodes::_lload: | 389 case Bytecodes::_lload: |
353 case Bytecodes::_fload: | 390 case Bytecodes::_fload: |