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