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