src/share/vm/opto/parseHelper.cpp

Thu, 24 May 2018 19:26:50 +0800

author
aoqi
date
Thu, 24 May 2018 19:26:50 +0800
changeset 8862
fd13a567f179
parent 7535
7ae4e26cb1e0
permissions
-rw-r--r--

#7046 C2 supports long branch
Contributed-by: fujie

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

mercurial