1 /* 2 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 "precompiled.hpp" 26 #include "ci/ciValueKlass.hpp" 27 #include "classfile/systemDictionary.hpp" 28 #include "compiler/compileLog.hpp" 29 #include "oops/objArrayKlass.hpp" 30 #include "oops/valueArrayKlass.hpp" 31 #include "opto/addnode.hpp" 32 #include "opto/memnode.hpp" 33 #include "opto/mulnode.hpp" 34 #include "opto/parse.hpp" 35 #include "opto/rootnode.hpp" 36 #include "opto/runtime.hpp" 37 #include "opto/valuetypenode.hpp" 38 #include "runtime/sharedRuntime.hpp" 39 40 //------------------------------make_dtrace_method_entry_exit ---------------- 41 // Dtrace -- record entry or exit of a method if compiled with dtrace support 42 void GraphKit::make_dtrace_method_entry_exit(ciMethod* method, bool is_entry) { 43 const TypeFunc *call_type = OptoRuntime::dtrace_method_entry_exit_Type(); 44 address call_address = is_entry ? CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry) : 45 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit); 46 const char *call_name = is_entry ? "dtrace_method_entry" : "dtrace_method_exit"; 47 48 // Get base of thread-local storage area 49 Node* thread = _gvn.transform( new ThreadLocalNode() ); 50 51 // Get method 52 const TypePtr* method_type = TypeMetadataPtr::make(method); 53 Node *method_node = _gvn.transform(ConNode::make(method_type)); 54 55 kill_dead_locals(); 56 57 // For some reason, this call reads only raw memory. 58 const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM; 59 make_runtime_call(RC_LEAF | RC_NARROW_MEM, 60 call_type, call_address, 61 call_name, raw_adr_type, 62 thread, method_node); 63 } 64 65 66 //============================================================================= 67 //------------------------------do_checkcast----------------------------------- 68 void Parse::do_checkcast() { 69 bool will_link; 70 ciKlass* klass = iter().get_klass(will_link); 71 72 Node *obj = peek(); 73 74 // Throw uncommon trap if class is not loaded or the value we are casting 75 // _from_ is not loaded, and value is not null. If the value _is_ NULL, 76 // then the checkcast does nothing. 77 const TypeOopPtr *tp = _gvn.type(obj)->isa_oopptr(); 78 if (!will_link || (tp && tp->klass() && !tp->klass()->is_loaded())) { 79 if (C->log() != NULL) { 80 if (!will_link) { 81 C->log()->elem("assert_null reason='checkcast' klass='%d'", 82 C->log()->identify(klass)); 83 } 84 if (tp && tp->klass() && !tp->klass()->is_loaded()) { 85 // %%% Cannot happen? 86 C->log()->elem("assert_null reason='checkcast source' klass='%d'", 87 C->log()->identify(tp->klass())); 88 } 89 } 90 null_assert(obj); 91 assert( stopped() || _gvn.type(peek())->higher_equal(TypePtr::NULL_PTR), "what's left behind is null" ); 92 if (!stopped()) { 93 profile_null_checkcast(); 94 } 95 return; 96 } 97 98 Node *res = gen_checkcast(obj, makecon(TypeKlassPtr::make(klass)) ); 99 if (stopped()) { 100 return; 101 } 102 103 // Pop from stack AFTER gen_checkcast because it can uncommon trap and 104 // the debug info has to be correct. 105 pop(); 106 push(res); 107 } 108 109 110 //------------------------------do_instanceof---------------------------------- 111 void Parse::do_instanceof() { 112 if (stopped()) return; 113 // We would like to return false if class is not loaded, emitting a 114 // dependency, but Java requires instanceof to load its operand. 115 116 // Throw uncommon trap if class is not loaded 117 bool will_link; 118 ciKlass* klass = iter().get_klass(will_link); 119 120 if (!will_link) { 121 if (C->log() != NULL) { 122 C->log()->elem("assert_null reason='instanceof' klass='%d'", 123 C->log()->identify(klass)); 124 } 125 null_assert(peek()); 126 assert( stopped() || _gvn.type(peek())->higher_equal(TypePtr::NULL_PTR), "what's left behind is null" ); 127 if (!stopped()) { 128 // The object is now known to be null. 129 // Shortcut the effect of gen_instanceof and return "false" directly. 130 pop(); // pop the null 131 push(_gvn.intcon(0)); // push false answer 132 } 133 return; 134 } 135 136 // Push the bool result back on stack 137 Node* res = gen_instanceof(peek(), makecon(TypeKlassPtr::make(klass)), true); 138 139 // Pop from stack AFTER gen_instanceof because it can uncommon trap. 140 pop(); 141 push(res); 142 } 143 144 //------------------------------array_store_check------------------------------ 145 // pull array from stack and check that the store is valid 146 Node* Parse::array_store_check(Node* ary, Node* idx, Node* obj) { 147 const Type* elemtype = _gvn.type(ary)->is_aryptr()->elem(); 148 const TypeOopPtr* elemptr = elemtype->make_oopptr(); 149 bool is_value_array = elemtype->isa_valuetype() != NULL || (elemptr != NULL && elemptr->is_valuetypeptr()); 150 bool can_be_value_array = is_value_array || (elemptr != NULL && (elemptr->can_be_value_type())); 151 152 if (_gvn.type(obj) == TypePtr::NULL_PTR) { 153 // There's never a type check on null values. 154 // This cutout lets us avoid the uncommon_trap(Reason_array_check) 155 // below, which turns into a performance liability if the 156 // gen_checkcast folds up completely. 157 if (is_value_array) { 158 // Can not store null into a value type array 159 uncommon_trap(Deoptimization::Reason_null_check, Deoptimization::Action_none); 160 return obj; 161 } else if (can_be_value_array) { 162 // Throw exception if array is a value type array 163 gen_value_type_array_guard(ary, zerocon(T_OBJECT)); 164 return obj; 165 } 166 return obj; 167 } 168 169 // Extract the array klass type 170 Node* array_klass = load_object_klass(ary); 171 // Get the array klass 172 const TypeKlassPtr *tak = _gvn.type(array_klass)->is_klassptr(); 173 174 // The type of array_klass is usually INexact array-of-oop. Heroically 175 // cast array_klass to EXACT array and uncommon-trap if the cast fails. 176 // Make constant out of the inexact array klass, but use it only if the cast 177 // succeeds. 178 bool always_see_exact_class = false; 179 if (MonomorphicArrayCheck 180 && !too_many_traps(Deoptimization::Reason_array_check) 181 && !tak->klass_is_exact() 182 && tak != TypeKlassPtr::OBJECT) { 183 // Regarding the fourth condition in the if-statement from above: 184 // 185 // If the compiler has determined that the type of array 'ary' (represented 186 // by 'array_klass') is java/lang/Object, the compiler must not assume that 187 // the array 'ary' is monomorphic. 188 // 189 // If 'ary' were of type java/lang/Object, this arraystore would have to fail, 190 // because it is not possible to perform a arraystore into an object that is not 191 // a "proper" array. 192 // 193 // Therefore, let's obtain at runtime the type of 'ary' and check if we can still 194 // successfully perform the store. 195 // 196 // The implementation reasons for the condition are the following: 197 // 198 // java/lang/Object is the superclass of all arrays, but it is represented by the VM 199 // as an InstanceKlass. The checks generated by gen_checkcast() (see below) expect 200 // 'array_klass' to be ObjArrayKlass, which can result in invalid memory accesses. 201 // 202 // See issue JDK-8057622 for details. 203 204 always_see_exact_class = true; 205 // (If no MDO at all, hope for the best, until a trap actually occurs.) 206 207 // Make a constant out of the inexact array klass 208 const TypeKlassPtr *extak = tak->cast_to_exactness(true)->is_klassptr(); 209 Node* con = makecon(extak); 210 Node* cmp = _gvn.transform(new CmpPNode( array_klass, con )); 211 Node* bol = _gvn.transform(new BoolNode( cmp, BoolTest::eq )); 212 Node* ctrl= control(); 213 { BuildCutout unless(this, bol, PROB_MAX); 214 uncommon_trap(Deoptimization::Reason_array_check, 215 Deoptimization::Action_maybe_recompile, 216 tak->klass()); 217 } 218 if (stopped()) { // MUST uncommon-trap? 219 set_control(ctrl); // Then Don't Do It, just fall into the normal checking 220 } else { // Cast array klass to exactness: 221 // Use the exact constant value we know it is. 222 replace_in_map(array_klass,con); 223 CompileLog* log = C->log(); 224 if (log != NULL) { 225 log->elem("cast_up reason='monomorphic_array' from='%d' to='(exact)'", 226 log->identify(tak->klass())); 227 } 228 array_klass = con; // Use cast value moving forward 229 } 230 } 231 232 // Come here for polymorphic array klasses 233 234 // Extract the array element class 235 int element_klass_offset = in_bytes(ArrayKlass::element_klass_offset()); 236 237 Node *p2 = basic_plus_adr(array_klass, array_klass, element_klass_offset); 238 // We are allowed to use the constant type only if cast succeeded. If always_see_exact_class is true, 239 // we must set a control edge from the IfTrue node created by the uncommon_trap above to the 240 // LoadKlassNode. 241 Node* a_e_klass = _gvn.transform(LoadKlassNode::make(_gvn, always_see_exact_class ? control() : NULL, 242 immutable_memory(), p2, tak)); 243 244 // Handle value type arrays 245 if (is_value_array) { 246 // We statically know that this is a value type array, use precise klass ptr 247 ciValueKlass* vk = elemtype->isa_valuetype() ? elemtype->is_valuetype()->value_klass() : 248 elemptr->value_klass(); 249 a_e_klass = makecon(TypeKlassPtr::make(vk)); 250 } else if (can_be_value_array && !obj->is_ValueType()) { 251 // We cannot statically determine if the array is a value type array 252 // and we also don't know if 'obj' is a value type. Emit runtime checks. 253 gen_value_type_array_guard(ary, obj, a_e_klass); 254 } 255 256 // Check (the hard way) and throw if not a subklass. 257 return gen_checkcast(obj, a_e_klass); 258 } 259 260 261 void Parse::emit_guard_for_new(ciInstanceKlass* klass) { 262 // Emit guarded new 263 // if (klass->_init_thread != current_thread || 264 // klass->_init_state != being_initialized) 265 // uncommon_trap 266 Node* cur_thread = _gvn.transform( new ThreadLocalNode() ); 267 Node* merge = new RegionNode(3); 268 _gvn.set_type(merge, Type::CONTROL); 269 Node* kls = makecon(TypeKlassPtr::make(klass)); 270 271 Node* init_thread_offset = _gvn.MakeConX(in_bytes(InstanceKlass::init_thread_offset())); 272 Node* adr_node = basic_plus_adr(kls, kls, init_thread_offset); 273 Node* init_thread = make_load(NULL, adr_node, TypeRawPtr::BOTTOM, T_ADDRESS, MemNode::unordered); 274 Node *tst = Bool( CmpP( init_thread, cur_thread), BoolTest::eq); 275 IfNode* iff = create_and_map_if(control(), tst, PROB_ALWAYS, COUNT_UNKNOWN); 276 set_control(IfTrue(iff)); 277 merge->set_req(1, IfFalse(iff)); 278 279 Node* init_state_offset = _gvn.MakeConX(in_bytes(InstanceKlass::init_state_offset())); 280 adr_node = basic_plus_adr(kls, kls, init_state_offset); 281 // Use T_BOOLEAN for InstanceKlass::_init_state so the compiler 282 // can generate code to load it as unsigned byte. 283 Node* init_state = make_load(NULL, adr_node, TypeInt::UBYTE, T_BOOLEAN, MemNode::unordered); 284 Node* being_init = _gvn.intcon(InstanceKlass::being_initialized); 285 tst = Bool( CmpI( init_state, being_init), BoolTest::eq); 286 iff = create_and_map_if(control(), tst, PROB_ALWAYS, COUNT_UNKNOWN); 287 set_control(IfTrue(iff)); 288 merge->set_req(2, IfFalse(iff)); 289 290 PreserveJVMState pjvms(this); 291 record_for_igvn(merge); 292 set_control(merge); 293 294 uncommon_trap(Deoptimization::Reason_uninitialized, 295 Deoptimization::Action_reinterpret, 296 klass); 297 } 298 299 300 //------------------------------do_new----------------------------------------- 301 void Parse::do_new() { 302 kill_dead_locals(); 303 304 bool will_link; 305 ciInstanceKlass* klass = iter().get_klass(will_link)->as_instance_klass(); 306 assert(will_link, "_new: typeflow responsibility"); 307 308 // Should initialize, or throw an InstantiationError? 309 if ((!klass->is_initialized() && !klass->is_being_initialized()) || 310 klass->is_abstract() || klass->is_interface() || 311 klass->name() == ciSymbol::java_lang_Class() || 312 iter().is_unresolved_klass()) { 313 uncommon_trap(Deoptimization::Reason_uninitialized, 314 Deoptimization::Action_reinterpret, 315 klass); 316 return; 317 } 318 if (klass->is_being_initialized()) { 319 emit_guard_for_new(klass); 320 } 321 322 Node* kls = makecon(TypeKlassPtr::make(klass)); 323 Node* obj = new_instance(kls); 324 325 // Push resultant oop onto stack 326 push(obj); 327 328 // Keep track of whether opportunities exist for StringBuilder 329 // optimizations. 330 if (OptimizeStringConcat && 331 (klass == C->env()->StringBuilder_klass() || 332 klass == C->env()->StringBuffer_klass())) { 333 C->set_has_stringbuilder(true); 334 } 335 336 // Keep track of boxed values for EliminateAutoBox optimizations. 337 if (C->eliminate_boxing() && klass->is_box_klass()) { 338 C->set_has_boxed_value(true); 339 } 340 } 341 342 //------------------------------do_defaultvalue--------------------------------- 343 void Parse::do_defaultvalue() { 344 bool will_link; 345 ciValueKlass* vk = iter().get_klass(will_link)->as_value_klass(); 346 assert(will_link, "defaultvalue: typeflow responsibility"); 347 // Create and push a new default ValueTypeNode 348 push(ValueTypeNode::make_default(_gvn, vk)); 349 } 350 351 //------------------------------do_withfield------------------------------------ 352 void Parse::do_withfield() { 353 bool will_link; 354 ciField* field = iter().get_field(will_link); 355 assert(will_link, "withfield: typeflow responsibility"); 356 BasicType bt = field->layout_type(); 357 Node* val = type2size[bt] == 1 ? pop() : pop_pair(); 358 Node* vt = pop(); 359 assert(vt->is_ValueType(), "value type expected here"); 360 361 ValueTypeNode* new_vt = vt->clone()->as_ValueType(); 362 new_vt->set_oop(_gvn.zerocon(T_VALUETYPE)); 363 int offset = field->offset(); 364 uint i = 0; 365 for (; i < new_vt->field_count() && new_vt->field_offset(i) != offset; i++) {} 366 assert(i < new_vt->field_count(), "field not found"); 367 new_vt->set_field_value(i, val); 368 369 push(_gvn.transform(new_vt)); 370 } 371 372 #ifndef PRODUCT 373 //------------------------------dump_map_adr_mem------------------------------- 374 // Debug dump of the mapping from address types to MergeMemNode indices. 375 void Parse::dump_map_adr_mem() const { 376 tty->print_cr("--- Mapping from address types to memory Nodes ---"); 377 MergeMemNode *mem = map() == NULL ? NULL : (map()->memory()->is_MergeMem() ? 378 map()->memory()->as_MergeMem() : NULL); 379 for (uint i = 0; i < (uint)C->num_alias_types(); i++) { 380 C->alias_type(i)->print_on(tty); 381 tty->print("\t"); 382 // Node mapping, if any 383 if (mem && i < mem->req() && mem->in(i) && mem->in(i) != mem->empty_memory()) { 384 mem->in(i)->dump(); 385 } else { 386 tty->cr(); 387 } 388 } 389 } 390 391 #endif 392 393 394 //============================================================================= 395 // 396 // parser methods for profiling 397 398 399 //----------------------test_counter_against_threshold ------------------------ 400 void Parse::test_counter_against_threshold(Node* cnt, int limit) { 401 // Test the counter against the limit and uncommon trap if greater. 402 403 // This code is largely copied from the range check code in 404 // array_addressing() 405 406 // Test invocation count vs threshold 407 Node *threshold = makecon(TypeInt::make(limit)); 408 Node *chk = _gvn.transform( new CmpUNode( cnt, threshold) ); 409 BoolTest::mask btest = BoolTest::lt; 410 Node *tst = _gvn.transform( new BoolNode( chk, btest) ); 411 // Branch to failure if threshold exceeded 412 { BuildCutout unless(this, tst, PROB_ALWAYS); 413 uncommon_trap(Deoptimization::Reason_age, 414 Deoptimization::Action_maybe_recompile); 415 } 416 } 417 418 //----------------------increment_and_test_invocation_counter------------------- 419 void Parse::increment_and_test_invocation_counter(int limit) { 420 if (!count_invocations()) return; 421 422 // Get the Method* node. 423 ciMethod* m = method(); 424 MethodCounters* counters_adr = m->ensure_method_counters(); 425 if (counters_adr == NULL) { 426 C->record_failure("method counters allocation failed"); 427 return; 428 } 429 430 Node* ctrl = control(); 431 const TypePtr* adr_type = TypeRawPtr::make((address) counters_adr); 432 Node *counters_node = makecon(adr_type); 433 Node* adr_iic_node = basic_plus_adr(counters_node, counters_node, 434 MethodCounters::interpreter_invocation_counter_offset_in_bytes()); 435 Node* cnt = make_load(ctrl, adr_iic_node, TypeInt::INT, T_INT, adr_type, MemNode::unordered); 436 437 test_counter_against_threshold(cnt, limit); 438 439 // Add one to the counter and store 440 Node* incr = _gvn.transform(new AddINode(cnt, _gvn.intcon(1))); 441 store_to_memory(ctrl, adr_iic_node, incr, T_INT, adr_type, MemNode::unordered); 442 } 443 444 //----------------------------method_data_addressing--------------------------- 445 Node* Parse::method_data_addressing(ciMethodData* md, ciProfileData* data, ByteSize counter_offset, Node* idx, uint stride) { 446 // Get offset within MethodData* of the data array 447 ByteSize data_offset = MethodData::data_offset(); 448 449 // Get cell offset of the ProfileData within data array 450 int cell_offset = md->dp_to_di(data->dp()); 451 452 // Add in counter_offset, the # of bytes into the ProfileData of counter or flag 453 int offset = in_bytes(data_offset) + cell_offset + in_bytes(counter_offset); 454 455 const TypePtr* adr_type = TypeMetadataPtr::make(md); 456 Node* mdo = makecon(adr_type); 457 Node* ptr = basic_plus_adr(mdo, mdo, offset); 458 459 if (stride != 0) { 460 Node* str = _gvn.MakeConX(stride); 461 Node* scale = _gvn.transform( new MulXNode( idx, str ) ); 462 ptr = _gvn.transform( new AddPNode( mdo, ptr, scale ) ); 463 } 464 465 return ptr; 466 } 467 468 //--------------------------increment_md_counter_at---------------------------- 469 void Parse::increment_md_counter_at(ciMethodData* md, ciProfileData* data, ByteSize counter_offset, Node* idx, uint stride) { 470 Node* adr_node = method_data_addressing(md, data, counter_offset, idx, stride); 471 472 const TypePtr* adr_type = _gvn.type(adr_node)->is_ptr(); 473 Node* cnt = make_load(NULL, adr_node, TypeInt::INT, T_INT, adr_type, MemNode::unordered); 474 Node* incr = _gvn.transform(new AddINode(cnt, _gvn.intcon(DataLayout::counter_increment))); 475 store_to_memory(NULL, adr_node, incr, T_INT, adr_type, MemNode::unordered); 476 } 477 478 //--------------------------test_for_osr_md_counter_at------------------------- 479 void Parse::test_for_osr_md_counter_at(ciMethodData* md, ciProfileData* data, ByteSize counter_offset, int limit) { 480 Node* adr_node = method_data_addressing(md, data, counter_offset); 481 482 const TypePtr* adr_type = _gvn.type(adr_node)->is_ptr(); 483 Node* cnt = make_load(NULL, adr_node, TypeInt::INT, T_INT, adr_type, MemNode::unordered); 484 485 test_counter_against_threshold(cnt, limit); 486 } 487 488 //-------------------------------set_md_flag_at-------------------------------- 489 void Parse::set_md_flag_at(ciMethodData* md, ciProfileData* data, int flag_constant) { 490 Node* adr_node = method_data_addressing(md, data, DataLayout::flags_offset()); 491 492 const TypePtr* adr_type = _gvn.type(adr_node)->is_ptr(); 493 Node* flags = make_load(NULL, adr_node, TypeInt::BYTE, T_BYTE, adr_type, MemNode::unordered); 494 Node* incr = _gvn.transform(new OrINode(flags, _gvn.intcon(flag_constant))); 495 store_to_memory(NULL, adr_node, incr, T_BYTE, adr_type, MemNode::unordered); 496 } 497 498 //----------------------------profile_taken_branch----------------------------- 499 void Parse::profile_taken_branch(int target_bci, bool force_update) { 500 // This is a potential osr_site if we have a backedge. 501 int cur_bci = bci(); 502 bool osr_site = 503 (target_bci <= cur_bci) && count_invocations() && UseOnStackReplacement; 504 505 // If we are going to OSR, restart at the target bytecode. 506 set_bci(target_bci); 507 508 // To do: factor out the the limit calculations below. These duplicate 509 // the similar limit calculations in the interpreter. 510 511 if (method_data_update() || force_update) { 512 ciMethodData* md = method()->method_data(); 513 assert(md != NULL, "expected valid ciMethodData"); 514 ciProfileData* data = md->bci_to_data(cur_bci); 515 assert(data != NULL && data->is_JumpData(), "need JumpData for taken branch"); 516 increment_md_counter_at(md, data, JumpData::taken_offset()); 517 } 518 519 // In the new tiered system this is all we need to do. In the old 520 // (c2 based) tiered sytem we must do the code below. 521 #ifndef TIERED 522 if (method_data_update()) { 523 ciMethodData* md = method()->method_data(); 524 if (osr_site) { 525 ciProfileData* data = md->bci_to_data(cur_bci); 526 assert(data != NULL && data->is_JumpData(), "need JumpData for taken branch"); 527 int limit = (CompileThreshold 528 * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100; 529 test_for_osr_md_counter_at(md, data, JumpData::taken_offset(), limit); 530 } 531 } else { 532 // With method data update off, use the invocation counter to trigger an 533 // OSR compilation, as done in the interpreter. 534 if (osr_site) { 535 int limit = (CompileThreshold * OnStackReplacePercentage) / 100; 536 increment_and_test_invocation_counter(limit); 537 } 538 } 539 #endif // TIERED 540 541 // Restore the original bytecode. 542 set_bci(cur_bci); 543 } 544 545 //--------------------------profile_not_taken_branch--------------------------- 546 void Parse::profile_not_taken_branch(bool force_update) { 547 548 if (method_data_update() || force_update) { 549 ciMethodData* md = method()->method_data(); 550 assert(md != NULL, "expected valid ciMethodData"); 551 ciProfileData* data = md->bci_to_data(bci()); 552 assert(data != NULL && data->is_BranchData(), "need BranchData for not taken branch"); 553 increment_md_counter_at(md, data, BranchData::not_taken_offset()); 554 } 555 556 } 557 558 //---------------------------------profile_call-------------------------------- 559 void Parse::profile_call(Node* receiver) { 560 if (!method_data_update()) return; 561 562 switch (bc()) { 563 case Bytecodes::_invokevirtual: 564 case Bytecodes::_invokeinterface: 565 profile_receiver_type(receiver); 566 break; 567 case Bytecodes::_invokestatic: 568 case Bytecodes::_invokedynamic: 569 case Bytecodes::_invokespecial: 570 profile_generic_call(); 571 break; 572 default: fatal("unexpected call bytecode"); 573 } 574 } 575 576 //------------------------------profile_generic_call--------------------------- 577 void Parse::profile_generic_call() { 578 assert(method_data_update(), "must be generating profile code"); 579 580 ciMethodData* md = method()->method_data(); 581 assert(md != NULL, "expected valid ciMethodData"); 582 ciProfileData* data = md->bci_to_data(bci()); 583 assert(data != NULL && data->is_CounterData(), "need CounterData for not taken branch"); 584 increment_md_counter_at(md, data, CounterData::count_offset()); 585 } 586 587 //-----------------------------profile_receiver_type--------------------------- 588 void Parse::profile_receiver_type(Node* receiver) { 589 assert(method_data_update(), "must be generating profile code"); 590 591 ciMethodData* md = method()->method_data(); 592 assert(md != NULL, "expected valid ciMethodData"); 593 ciProfileData* data = md->bci_to_data(bci()); 594 assert(data != NULL && data->is_ReceiverTypeData(), "need ReceiverTypeData here"); 595 596 // Skip if we aren't tracking receivers 597 if (TypeProfileWidth < 1) { 598 increment_md_counter_at(md, data, CounterData::count_offset()); 599 return; 600 } 601 ciReceiverTypeData* rdata = (ciReceiverTypeData*)data->as_ReceiverTypeData(); 602 603 Node* method_data = method_data_addressing(md, rdata, in_ByteSize(0)); 604 605 // Using an adr_type of TypePtr::BOTTOM to work around anti-dep problems. 606 // A better solution might be to use TypeRawPtr::BOTTOM with RC_NARROW_MEM. 607 make_runtime_call(RC_LEAF, OptoRuntime::profile_receiver_type_Type(), 608 CAST_FROM_FN_PTR(address, 609 OptoRuntime::profile_receiver_type_C), 610 "profile_receiver_type_C", 611 TypePtr::BOTTOM, 612 method_data, receiver); 613 } 614 615 //---------------------------------profile_ret--------------------------------- 616 void Parse::profile_ret(int target_bci) { 617 if (!method_data_update()) return; 618 619 // Skip if we aren't tracking ret targets 620 if (TypeProfileWidth < 1) return; 621 622 ciMethodData* md = method()->method_data(); 623 assert(md != NULL, "expected valid ciMethodData"); 624 ciProfileData* data = md->bci_to_data(bci()); 625 assert(data != NULL && data->is_RetData(), "need RetData for ret"); 626 ciRetData* ret_data = (ciRetData*)data->as_RetData(); 627 628 // Look for the target_bci is already in the table 629 uint row; 630 bool table_full = true; 631 for (row = 0; row < ret_data->row_limit(); row++) { 632 int key = ret_data->bci(row); 633 table_full &= (key != RetData::no_bci); 634 if (key == target_bci) break; 635 } 636 637 if (row >= ret_data->row_limit()) { 638 // The target_bci was not found in the table. 639 if (!table_full) { 640 // XXX: Make slow call to update RetData 641 } 642 return; 643 } 644 645 // the target_bci is already in the table 646 increment_md_counter_at(md, data, RetData::bci_count_offset(row)); 647 } 648 649 //--------------------------profile_null_checkcast---------------------------- 650 void Parse::profile_null_checkcast() { 651 // Set the null-seen flag, done in conjunction with the usual null check. We 652 // never unset the flag, so this is a one-way switch. 653 if (!method_data_update()) return; 654 655 ciMethodData* md = method()->method_data(); 656 assert(md != NULL, "expected valid ciMethodData"); 657 ciProfileData* data = md->bci_to_data(bci()); 658 assert(data != NULL && data->is_BitData(), "need BitData for checkcast"); 659 set_md_flag_at(md, data, BitData::null_seen_byte_constant()); 660 } 661 662 //-----------------------------profile_switch_case----------------------------- 663 void Parse::profile_switch_case(int table_index) { 664 if (!method_data_update()) return; 665 666 ciMethodData* md = method()->method_data(); 667 assert(md != NULL, "expected valid ciMethodData"); 668 669 ciProfileData* data = md->bci_to_data(bci()); 670 assert(data != NULL && data->is_MultiBranchData(), "need MultiBranchData for switch case"); 671 if (table_index >= 0) { 672 increment_md_counter_at(md, data, MultiBranchData::case_count_offset(table_index)); 673 } else { 674 increment_md_counter_at(md, data, MultiBranchData::default_count_offset()); 675 } 676 }