src/share/vm/opto/parseHelper.cpp

Thu, 12 Nov 2009 09:24:21 -0800

author
never
date
Thu, 12 Nov 2009 09:24:21 -0800
changeset 1515
7c57aead6d3e
parent 1279
bd02caa94611
child 1641
87684f1a88b5
permissions
-rw-r--r--

6892658: C2 should optimize some stringbuilder patterns
Reviewed-by: kvn, twisti

duke@435 1 /*
xdono@1279 2 * Copyright 1998-2009 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 #include "incls/_precompiled.incl"
duke@435 26 #include "incls/_parseHelper.cpp.incl"
duke@435 27
duke@435 28 //------------------------------make_dtrace_method_entry_exit ----------------
duke@435 29 // Dtrace -- record entry or exit of a method if compiled with dtrace support
duke@435 30 void GraphKit::make_dtrace_method_entry_exit(ciMethod* method, bool is_entry) {
duke@435 31 const TypeFunc *call_type = OptoRuntime::dtrace_method_entry_exit_Type();
duke@435 32 address call_address = is_entry ? CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry) :
duke@435 33 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit);
duke@435 34 const char *call_name = is_entry ? "dtrace_method_entry" : "dtrace_method_exit";
duke@435 35
duke@435 36 // Get base of thread-local storage area
duke@435 37 Node* thread = _gvn.transform( new (C, 1) ThreadLocalNode() );
duke@435 38
duke@435 39 // Get method
duke@435 40 const TypeInstPtr* method_type = TypeInstPtr::make(TypePtr::Constant, method->klass(), true, method, 0);
kvn@599 41 Node *method_node = _gvn.transform( ConNode::make(C, method_type) );
duke@435 42
duke@435 43 kill_dead_locals();
duke@435 44
duke@435 45 // For some reason, this call reads only raw memory.
duke@435 46 const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM;
duke@435 47 make_runtime_call(RC_LEAF | RC_NARROW_MEM,
duke@435 48 call_type, call_address,
duke@435 49 call_name, raw_adr_type,
duke@435 50 thread, method_node);
duke@435 51 }
duke@435 52
duke@435 53
duke@435 54 //=============================================================================
duke@435 55 //------------------------------do_checkcast-----------------------------------
duke@435 56 void Parse::do_checkcast() {
duke@435 57 bool will_link;
duke@435 58 ciKlass* klass = iter().get_klass(will_link);
duke@435 59
duke@435 60 Node *obj = peek();
duke@435 61
duke@435 62 // Throw uncommon trap if class is not loaded or the value we are casting
duke@435 63 // _from_ is not loaded, and value is not null. If the value _is_ NULL,
duke@435 64 // then the checkcast does nothing.
duke@435 65 const TypeInstPtr *tp = _gvn.type(obj)->isa_instptr();
duke@435 66 if (!will_link || (tp && !tp->is_loaded())) {
duke@435 67 if (C->log() != NULL) {
duke@435 68 if (!will_link) {
duke@435 69 C->log()->elem("assert_null reason='checkcast' klass='%d'",
duke@435 70 C->log()->identify(klass));
duke@435 71 }
duke@435 72 if (tp && !tp->is_loaded()) {
duke@435 73 // %%% Cannot happen?
duke@435 74 C->log()->elem("assert_null reason='checkcast source' klass='%d'",
duke@435 75 C->log()->identify(tp->klass()));
duke@435 76 }
duke@435 77 }
duke@435 78 do_null_assert(obj, T_OBJECT);
duke@435 79 assert( stopped() || _gvn.type(peek())->higher_equal(TypePtr::NULL_PTR), "what's left behind is null" );
duke@435 80 if (!stopped()) {
duke@435 81 profile_null_checkcast();
duke@435 82 }
duke@435 83 return;
duke@435 84 }
duke@435 85
duke@435 86 Node *res = gen_checkcast(obj, makecon(TypeKlassPtr::make(klass)) );
duke@435 87
duke@435 88 // Pop from stack AFTER gen_checkcast because it can uncommon trap and
duke@435 89 // the debug info has to be correct.
duke@435 90 pop();
duke@435 91 push(res);
duke@435 92 }
duke@435 93
duke@435 94
duke@435 95 //------------------------------do_instanceof----------------------------------
duke@435 96 void Parse::do_instanceof() {
duke@435 97 if (stopped()) return;
duke@435 98 // We would like to return false if class is not loaded, emitting a
duke@435 99 // dependency, but Java requires instanceof to load its operand.
duke@435 100
duke@435 101 // Throw uncommon trap if class is not loaded
duke@435 102 bool will_link;
duke@435 103 ciKlass* klass = iter().get_klass(will_link);
duke@435 104
duke@435 105 if (!will_link) {
duke@435 106 if (C->log() != NULL) {
duke@435 107 C->log()->elem("assert_null reason='instanceof' klass='%d'",
duke@435 108 C->log()->identify(klass));
duke@435 109 }
duke@435 110 do_null_assert(peek(), T_OBJECT);
duke@435 111 assert( stopped() || _gvn.type(peek())->higher_equal(TypePtr::NULL_PTR), "what's left behind is null" );
duke@435 112 if (!stopped()) {
duke@435 113 // The object is now known to be null.
duke@435 114 // Shortcut the effect of gen_instanceof and return "false" directly.
duke@435 115 pop(); // pop the null
duke@435 116 push(_gvn.intcon(0)); // push false answer
duke@435 117 }
duke@435 118 return;
duke@435 119 }
duke@435 120
duke@435 121 // Push the bool result back on stack
duke@435 122 push( gen_instanceof( pop(), makecon(TypeKlassPtr::make(klass)) ) );
duke@435 123 }
duke@435 124
duke@435 125 //------------------------------array_store_check------------------------------
duke@435 126 // pull array from stack and check that the store is valid
duke@435 127 void Parse::array_store_check() {
duke@435 128
duke@435 129 // Shorthand access to array store elements
duke@435 130 Node *obj = stack(_sp-1);
duke@435 131 Node *idx = stack(_sp-2);
duke@435 132 Node *ary = stack(_sp-3);
duke@435 133
duke@435 134 if (_gvn.type(obj) == TypePtr::NULL_PTR) {
duke@435 135 // There's never a type check on null values.
duke@435 136 // This cutout lets us avoid the uncommon_trap(Reason_array_check)
duke@435 137 // below, which turns into a performance liability if the
duke@435 138 // gen_checkcast folds up completely.
duke@435 139 return;
duke@435 140 }
duke@435 141
duke@435 142 // Extract the array klass type
duke@435 143 int klass_offset = oopDesc::klass_offset_in_bytes();
duke@435 144 Node* p = basic_plus_adr( ary, ary, klass_offset );
duke@435 145 // p's type is array-of-OOPS plus klass_offset
kvn@599 146 Node* array_klass = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeInstPtr::KLASS) );
duke@435 147 // Get the array klass
duke@435 148 const TypeKlassPtr *tak = _gvn.type(array_klass)->is_klassptr();
duke@435 149
duke@435 150 // array_klass's type is generally INexact array-of-oop. Heroically
duke@435 151 // cast the array klass to EXACT array and uncommon-trap if the cast
duke@435 152 // fails.
duke@435 153 bool always_see_exact_class = false;
duke@435 154 if (MonomorphicArrayCheck
duke@435 155 && !too_many_traps(Deoptimization::Reason_array_check)) {
duke@435 156 always_see_exact_class = true;
duke@435 157 // (If no MDO at all, hope for the best, until a trap actually occurs.)
duke@435 158 }
duke@435 159
duke@435 160 // Is the array klass is exactly its defined type?
duke@435 161 if (always_see_exact_class && !tak->klass_is_exact()) {
duke@435 162 // Make a constant out of the inexact array klass
duke@435 163 const TypeKlassPtr *extak = tak->cast_to_exactness(true)->is_klassptr();
duke@435 164 Node* con = makecon(extak);
duke@435 165 Node* cmp = _gvn.transform(new (C, 3) CmpPNode( array_klass, con ));
duke@435 166 Node* bol = _gvn.transform(new (C, 2) BoolNode( cmp, BoolTest::eq ));
duke@435 167 Node* ctrl= control();
duke@435 168 { BuildCutout unless(this, bol, PROB_MAX);
duke@435 169 uncommon_trap(Deoptimization::Reason_array_check,
duke@435 170 Deoptimization::Action_maybe_recompile,
duke@435 171 tak->klass());
duke@435 172 }
duke@435 173 if (stopped()) { // MUST uncommon-trap?
duke@435 174 set_control(ctrl); // Then Don't Do It, just fall into the normal checking
duke@435 175 } else { // Cast array klass to exactness:
duke@435 176 // Use the exact constant value we know it is.
duke@435 177 replace_in_map(array_klass,con);
duke@435 178 CompileLog* log = C->log();
duke@435 179 if (log != NULL) {
duke@435 180 log->elem("cast_up reason='monomorphic_array' from='%d' to='(exact)'",
duke@435 181 log->identify(tak->klass()));
duke@435 182 }
duke@435 183 array_klass = con; // Use cast value moving forward
duke@435 184 }
duke@435 185 }
duke@435 186
duke@435 187 // Come here for polymorphic array klasses
duke@435 188
duke@435 189 // Extract the array element class
duke@435 190 int element_klass_offset = objArrayKlass::element_klass_offset_in_bytes() + sizeof(oopDesc);
duke@435 191 Node *p2 = basic_plus_adr(array_klass, array_klass, element_klass_offset);
kvn@599 192 Node *a_e_klass = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p2, tak) );
duke@435 193
duke@435 194 // Check (the hard way) and throw if not a subklass.
duke@435 195 // Result is ignored, we just need the CFG effects.
duke@435 196 gen_checkcast( obj, a_e_klass );
duke@435 197 }
duke@435 198
duke@435 199
duke@435 200 //------------------------------do_new-----------------------------------------
duke@435 201 void Parse::do_new() {
duke@435 202 kill_dead_locals();
duke@435 203
duke@435 204 bool will_link;
duke@435 205 ciInstanceKlass* klass = iter().get_klass(will_link)->as_instance_klass();
duke@435 206 assert(will_link, "_new: typeflow responsibility");
duke@435 207
duke@435 208 // Should initialize, or throw an InstantiationError?
duke@435 209 if (!klass->is_initialized() ||
duke@435 210 klass->is_abstract() || klass->is_interface() ||
duke@435 211 klass->name() == ciSymbol::java_lang_Class() ||
duke@435 212 iter().is_unresolved_klass()) {
duke@435 213 uncommon_trap(Deoptimization::Reason_uninitialized,
duke@435 214 Deoptimization::Action_reinterpret,
duke@435 215 klass);
duke@435 216 return;
duke@435 217 }
duke@435 218
duke@435 219 Node* kls = makecon(TypeKlassPtr::make(klass));
duke@435 220 Node* obj = new_instance(kls);
duke@435 221
duke@435 222 // Push resultant oop onto stack
duke@435 223 push(obj);
never@1515 224
never@1515 225 // Keep track of whether opportunities exist for StringBuilder
never@1515 226 // optimizations.
never@1515 227 if (OptimizeStringConcat &&
never@1515 228 (klass == C->env()->StringBuilder_klass() ||
never@1515 229 klass == C->env()->StringBuffer_klass())) {
never@1515 230 C->set_has_stringbuilder(true);
never@1515 231 }
duke@435 232 }
duke@435 233
duke@435 234 #ifndef PRODUCT
duke@435 235 //------------------------------dump_map_adr_mem-------------------------------
duke@435 236 // Debug dump of the mapping from address types to MergeMemNode indices.
duke@435 237 void Parse::dump_map_adr_mem() const {
duke@435 238 tty->print_cr("--- Mapping from address types to memory Nodes ---");
duke@435 239 MergeMemNode *mem = map() == NULL ? NULL : (map()->memory()->is_MergeMem() ?
duke@435 240 map()->memory()->as_MergeMem() : NULL);
duke@435 241 for (uint i = 0; i < (uint)C->num_alias_types(); i++) {
duke@435 242 C->alias_type(i)->print_on(tty);
duke@435 243 tty->print("\t");
duke@435 244 // Node mapping, if any
duke@435 245 if (mem && i < mem->req() && mem->in(i) && mem->in(i) != mem->empty_memory()) {
duke@435 246 mem->in(i)->dump();
duke@435 247 } else {
duke@435 248 tty->cr();
duke@435 249 }
duke@435 250 }
duke@435 251 }
duke@435 252
duke@435 253 #endif
duke@435 254
duke@435 255
duke@435 256 //=============================================================================
duke@435 257 //
duke@435 258 // parser methods for profiling
duke@435 259
duke@435 260
duke@435 261 //----------------------test_counter_against_threshold ------------------------
duke@435 262 void Parse::test_counter_against_threshold(Node* cnt, int limit) {
duke@435 263 // Test the counter against the limit and uncommon trap if greater.
duke@435 264
duke@435 265 // This code is largely copied from the range check code in
duke@435 266 // array_addressing()
duke@435 267
duke@435 268 // Test invocation count vs threshold
duke@435 269 Node *threshold = makecon(TypeInt::make(limit));
duke@435 270 Node *chk = _gvn.transform( new (C, 3) CmpUNode( cnt, threshold) );
duke@435 271 BoolTest::mask btest = BoolTest::lt;
duke@435 272 Node *tst = _gvn.transform( new (C, 2) BoolNode( chk, btest) );
duke@435 273 // Branch to failure if threshold exceeded
duke@435 274 { BuildCutout unless(this, tst, PROB_ALWAYS);
duke@435 275 uncommon_trap(Deoptimization::Reason_age,
duke@435 276 Deoptimization::Action_maybe_recompile);
duke@435 277 }
duke@435 278 }
duke@435 279
duke@435 280 //----------------------increment_and_test_invocation_counter-------------------
duke@435 281 void Parse::increment_and_test_invocation_counter(int limit) {
duke@435 282 if (!count_invocations()) return;
duke@435 283
duke@435 284 // Get the methodOop node.
duke@435 285 const TypePtr* adr_type = TypeOopPtr::make_from_constant(method());
duke@435 286 Node *methodOop_node = makecon(adr_type);
duke@435 287
duke@435 288 // Load the interpreter_invocation_counter from the methodOop.
duke@435 289 int offset = methodOopDesc::interpreter_invocation_counter_offset_in_bytes();
duke@435 290 Node* adr_node = basic_plus_adr(methodOop_node, methodOop_node, offset);
duke@435 291 Node* cnt = make_load(NULL, adr_node, TypeInt::INT, T_INT, adr_type);
duke@435 292
duke@435 293 test_counter_against_threshold(cnt, limit);
duke@435 294
duke@435 295 // Add one to the counter and store
duke@435 296 Node* incr = _gvn.transform(new (C, 3) AddINode(cnt, _gvn.intcon(1)));
duke@435 297 store_to_memory( NULL, adr_node, incr, T_INT, adr_type );
duke@435 298 }
duke@435 299
duke@435 300 //----------------------------method_data_addressing---------------------------
duke@435 301 Node* Parse::method_data_addressing(ciMethodData* md, ciProfileData* data, ByteSize counter_offset, Node* idx, uint stride) {
duke@435 302 // Get offset within methodDataOop of the data array
duke@435 303 ByteSize data_offset = methodDataOopDesc::data_offset();
duke@435 304
duke@435 305 // Get cell offset of the ProfileData within data array
duke@435 306 int cell_offset = md->dp_to_di(data->dp());
duke@435 307
duke@435 308 // Add in counter_offset, the # of bytes into the ProfileData of counter or flag
duke@435 309 int offset = in_bytes(data_offset) + cell_offset + in_bytes(counter_offset);
duke@435 310
duke@435 311 const TypePtr* adr_type = TypeOopPtr::make_from_constant(md);
duke@435 312 Node* mdo = makecon(adr_type);
duke@435 313 Node* ptr = basic_plus_adr(mdo, mdo, offset);
duke@435 314
duke@435 315 if (stride != 0) {
duke@435 316 Node* str = _gvn.MakeConX(stride);
duke@435 317 Node* scale = _gvn.transform( new (C, 3) MulXNode( idx, str ) );
duke@435 318 ptr = _gvn.transform( new (C, 4) AddPNode( mdo, ptr, scale ) );
duke@435 319 }
duke@435 320
duke@435 321 return ptr;
duke@435 322 }
duke@435 323
duke@435 324 //--------------------------increment_md_counter_at----------------------------
duke@435 325 void Parse::increment_md_counter_at(ciMethodData* md, ciProfileData* data, ByteSize counter_offset, Node* idx, uint stride) {
duke@435 326 Node* adr_node = method_data_addressing(md, data, counter_offset, idx, stride);
duke@435 327
duke@435 328 const TypePtr* adr_type = _gvn.type(adr_node)->is_ptr();
duke@435 329 Node* cnt = make_load(NULL, adr_node, TypeInt::INT, T_INT, adr_type);
duke@435 330 Node* incr = _gvn.transform(new (C, 3) AddINode(cnt, _gvn.intcon(DataLayout::counter_increment)));
duke@435 331 store_to_memory(NULL, adr_node, incr, T_INT, adr_type );
duke@435 332 }
duke@435 333
duke@435 334 //--------------------------test_for_osr_md_counter_at-------------------------
duke@435 335 void Parse::test_for_osr_md_counter_at(ciMethodData* md, ciProfileData* data, ByteSize counter_offset, int limit) {
duke@435 336 Node* adr_node = method_data_addressing(md, data, counter_offset);
duke@435 337
duke@435 338 const TypePtr* adr_type = _gvn.type(adr_node)->is_ptr();
duke@435 339 Node* cnt = make_load(NULL, adr_node, TypeInt::INT, T_INT, adr_type);
duke@435 340
duke@435 341 test_counter_against_threshold(cnt, limit);
duke@435 342 }
duke@435 343
duke@435 344 //-------------------------------set_md_flag_at--------------------------------
duke@435 345 void Parse::set_md_flag_at(ciMethodData* md, ciProfileData* data, int flag_constant) {
duke@435 346 Node* adr_node = method_data_addressing(md, data, DataLayout::flags_offset());
duke@435 347
duke@435 348 const TypePtr* adr_type = _gvn.type(adr_node)->is_ptr();
duke@435 349 Node* flags = make_load(NULL, adr_node, TypeInt::BYTE, T_BYTE, adr_type);
duke@435 350 Node* incr = _gvn.transform(new (C, 3) OrINode(flags, _gvn.intcon(flag_constant)));
duke@435 351 store_to_memory(NULL, adr_node, incr, T_BYTE, adr_type);
duke@435 352 }
duke@435 353
duke@435 354 //----------------------------profile_taken_branch-----------------------------
duke@435 355 void Parse::profile_taken_branch(int target_bci, bool force_update) {
duke@435 356 // This is a potential osr_site if we have a backedge.
duke@435 357 int cur_bci = bci();
duke@435 358 bool osr_site =
duke@435 359 (target_bci <= cur_bci) && count_invocations() && UseOnStackReplacement;
duke@435 360
duke@435 361 // If we are going to OSR, restart at the target bytecode.
duke@435 362 set_bci(target_bci);
duke@435 363
duke@435 364 // To do: factor out the the limit calculations below. These duplicate
duke@435 365 // the similar limit calculations in the interpreter.
duke@435 366
duke@435 367 if (method_data_update() || force_update) {
duke@435 368 ciMethodData* md = method()->method_data();
duke@435 369 assert(md != NULL, "expected valid ciMethodData");
duke@435 370 ciProfileData* data = md->bci_to_data(cur_bci);
duke@435 371 assert(data->is_JumpData(), "need JumpData for taken branch");
duke@435 372 increment_md_counter_at(md, data, JumpData::taken_offset());
duke@435 373 }
duke@435 374
duke@435 375 // In the new tiered system this is all we need to do. In the old
duke@435 376 // (c2 based) tiered sytem we must do the code below.
duke@435 377 #ifndef TIERED
duke@435 378 if (method_data_update()) {
duke@435 379 ciMethodData* md = method()->method_data();
duke@435 380 if (osr_site) {
duke@435 381 ciProfileData* data = md->bci_to_data(cur_bci);
duke@435 382 int limit = (CompileThreshold
duke@435 383 * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100;
duke@435 384 test_for_osr_md_counter_at(md, data, JumpData::taken_offset(), limit);
duke@435 385 }
duke@435 386 } else {
duke@435 387 // With method data update off, use the invocation counter to trigger an
duke@435 388 // OSR compilation, as done in the interpreter.
duke@435 389 if (osr_site) {
duke@435 390 int limit = (CompileThreshold * OnStackReplacePercentage) / 100;
duke@435 391 increment_and_test_invocation_counter(limit);
duke@435 392 }
duke@435 393 }
duke@435 394 #endif // TIERED
duke@435 395
duke@435 396 // Restore the original bytecode.
duke@435 397 set_bci(cur_bci);
duke@435 398 }
duke@435 399
duke@435 400 //--------------------------profile_not_taken_branch---------------------------
duke@435 401 void Parse::profile_not_taken_branch(bool force_update) {
duke@435 402
duke@435 403 if (method_data_update() || force_update) {
duke@435 404 ciMethodData* md = method()->method_data();
duke@435 405 assert(md != NULL, "expected valid ciMethodData");
duke@435 406 ciProfileData* data = md->bci_to_data(bci());
duke@435 407 assert(data->is_BranchData(), "need BranchData for not taken branch");
duke@435 408 increment_md_counter_at(md, data, BranchData::not_taken_offset());
duke@435 409 }
duke@435 410
duke@435 411 }
duke@435 412
duke@435 413 //---------------------------------profile_call--------------------------------
duke@435 414 void Parse::profile_call(Node* receiver) {
duke@435 415 if (!method_data_update()) return;
duke@435 416
duke@435 417 profile_generic_call();
duke@435 418
duke@435 419 switch (bc()) {
duke@435 420 case Bytecodes::_invokevirtual:
duke@435 421 case Bytecodes::_invokeinterface:
duke@435 422 profile_receiver_type(receiver);
duke@435 423 break;
duke@435 424 case Bytecodes::_invokestatic:
jrose@1161 425 case Bytecodes::_invokedynamic:
duke@435 426 case Bytecodes::_invokespecial:
duke@435 427 break;
duke@435 428 default: fatal("unexpected call bytecode");
duke@435 429 }
duke@435 430 }
duke@435 431
duke@435 432 //------------------------------profile_generic_call---------------------------
duke@435 433 void Parse::profile_generic_call() {
duke@435 434 assert(method_data_update(), "must be generating profile code");
duke@435 435
duke@435 436 ciMethodData* md = method()->method_data();
duke@435 437 assert(md != NULL, "expected valid ciMethodData");
duke@435 438 ciProfileData* data = md->bci_to_data(bci());
duke@435 439 assert(data->is_CounterData(), "need CounterData for not taken branch");
duke@435 440 increment_md_counter_at(md, data, CounterData::count_offset());
duke@435 441 }
duke@435 442
duke@435 443 //-----------------------------profile_receiver_type---------------------------
duke@435 444 void Parse::profile_receiver_type(Node* receiver) {
duke@435 445 assert(method_data_update(), "must be generating profile code");
duke@435 446
duke@435 447 // Skip if we aren't tracking receivers
duke@435 448 if (TypeProfileWidth < 1) return;
duke@435 449
duke@435 450 ciMethodData* md = method()->method_data();
duke@435 451 assert(md != NULL, "expected valid ciMethodData");
duke@435 452 ciProfileData* data = md->bci_to_data(bci());
duke@435 453 assert(data->is_ReceiverTypeData(), "need ReceiverTypeData here");
duke@435 454 ciReceiverTypeData* rdata = (ciReceiverTypeData*)data->as_ReceiverTypeData();
duke@435 455
duke@435 456 Node* method_data = method_data_addressing(md, rdata, in_ByteSize(0));
duke@435 457
duke@435 458 // Using an adr_type of TypePtr::BOTTOM to work around anti-dep problems.
duke@435 459 // A better solution might be to use TypeRawPtr::BOTTOM with RC_NARROW_MEM.
duke@435 460 make_runtime_call(RC_LEAF, OptoRuntime::profile_receiver_type_Type(),
duke@435 461 CAST_FROM_FN_PTR(address,
duke@435 462 OptoRuntime::profile_receiver_type_C),
duke@435 463 "profile_receiver_type_C",
duke@435 464 TypePtr::BOTTOM,
duke@435 465 method_data, receiver);
duke@435 466 }
duke@435 467
duke@435 468 //---------------------------------profile_ret---------------------------------
duke@435 469 void Parse::profile_ret(int target_bci) {
duke@435 470 if (!method_data_update()) return;
duke@435 471
duke@435 472 // Skip if we aren't tracking ret targets
duke@435 473 if (TypeProfileWidth < 1) return;
duke@435 474
duke@435 475 ciMethodData* md = method()->method_data();
duke@435 476 assert(md != NULL, "expected valid ciMethodData");
duke@435 477 ciProfileData* data = md->bci_to_data(bci());
duke@435 478 assert(data->is_RetData(), "need RetData for ret");
duke@435 479 ciRetData* ret_data = (ciRetData*)data->as_RetData();
duke@435 480
duke@435 481 // Look for the target_bci is already in the table
duke@435 482 uint row;
duke@435 483 bool table_full = true;
duke@435 484 for (row = 0; row < ret_data->row_limit(); row++) {
duke@435 485 int key = ret_data->bci(row);
duke@435 486 table_full &= (key != RetData::no_bci);
duke@435 487 if (key == target_bci) break;
duke@435 488 }
duke@435 489
duke@435 490 if (row >= ret_data->row_limit()) {
duke@435 491 // The target_bci was not found in the table.
duke@435 492 if (!table_full) {
duke@435 493 // XXX: Make slow call to update RetData
duke@435 494 }
duke@435 495 return;
duke@435 496 }
duke@435 497
duke@435 498 // the target_bci is already in the table
duke@435 499 increment_md_counter_at(md, data, RetData::bci_count_offset(row));
duke@435 500 }
duke@435 501
duke@435 502 //--------------------------profile_null_checkcast----------------------------
duke@435 503 void Parse::profile_null_checkcast() {
duke@435 504 // Set the null-seen flag, done in conjunction with the usual null check. We
duke@435 505 // never unset the flag, so this is a one-way switch.
duke@435 506 if (!method_data_update()) return;
duke@435 507
duke@435 508 ciMethodData* md = method()->method_data();
duke@435 509 assert(md != NULL, "expected valid ciMethodData");
duke@435 510 ciProfileData* data = md->bci_to_data(bci());
duke@435 511 assert(data->is_BitData(), "need BitData for checkcast");
duke@435 512 set_md_flag_at(md, data, BitData::null_seen_byte_constant());
duke@435 513 }
duke@435 514
duke@435 515 //-----------------------------profile_switch_case-----------------------------
duke@435 516 void Parse::profile_switch_case(int table_index) {
duke@435 517 if (!method_data_update()) return;
duke@435 518
duke@435 519 ciMethodData* md = method()->method_data();
duke@435 520 assert(md != NULL, "expected valid ciMethodData");
duke@435 521
duke@435 522 ciProfileData* data = md->bci_to_data(bci());
duke@435 523 assert(data->is_MultiBranchData(), "need MultiBranchData for switch case");
duke@435 524 if (table_index >= 0) {
duke@435 525 increment_md_counter_at(md, data, MultiBranchData::case_count_offset(table_index));
duke@435 526 } else {
duke@435 527 increment_md_counter_at(md, data, MultiBranchData::default_count_offset());
duke@435 528 }
duke@435 529 }

mercurial