Wed, 27 Apr 2016 01:25:04 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17
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 |
aoqi@0 | 159 | Node* array_klass = _gvn.transform( LoadKlassNode::make(_gvn, 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 | |
aoqi@0 | 163 | // array_klass's type is generally INexact array-of-oop. Heroically |
aoqi@0 | 164 | // cast the array klass to EXACT array and uncommon-trap if the cast |
aoqi@0 | 165 | // fails. |
aoqi@0 | 166 | bool always_see_exact_class = false; |
aoqi@0 | 167 | if (MonomorphicArrayCheck |
aoqi@0 | 168 | && !too_many_traps(Deoptimization::Reason_array_check)) { |
aoqi@0 | 169 | always_see_exact_class = true; |
aoqi@0 | 170 | // (If no MDO at all, hope for the best, until a trap actually occurs.) |
aoqi@0 | 171 | } |
aoqi@0 | 172 | |
aoqi@0 | 173 | // Is the array klass is exactly its defined type? |
aoqi@0 | 174 | if (always_see_exact_class && !tak->klass_is_exact()) { |
aoqi@0 | 175 | // Make a constant out of the inexact array klass |
aoqi@0 | 176 | const TypeKlassPtr *extak = tak->cast_to_exactness(true)->is_klassptr(); |
aoqi@0 | 177 | Node* con = makecon(extak); |
aoqi@0 | 178 | Node* cmp = _gvn.transform(new (C) CmpPNode( array_klass, con )); |
aoqi@0 | 179 | Node* bol = _gvn.transform(new (C) BoolNode( cmp, BoolTest::eq )); |
aoqi@0 | 180 | Node* ctrl= control(); |
aoqi@0 | 181 | { BuildCutout unless(this, bol, PROB_MAX); |
aoqi@0 | 182 | uncommon_trap(Deoptimization::Reason_array_check, |
aoqi@0 | 183 | Deoptimization::Action_maybe_recompile, |
aoqi@0 | 184 | tak->klass()); |
aoqi@0 | 185 | } |
aoqi@0 | 186 | if (stopped()) { // MUST uncommon-trap? |
aoqi@0 | 187 | set_control(ctrl); // Then Don't Do It, just fall into the normal checking |
aoqi@0 | 188 | } else { // Cast array klass to exactness: |
aoqi@0 | 189 | // Use the exact constant value we know it is. |
aoqi@0 | 190 | replace_in_map(array_klass,con); |
aoqi@0 | 191 | CompileLog* log = C->log(); |
aoqi@0 | 192 | if (log != NULL) { |
aoqi@0 | 193 | log->elem("cast_up reason='monomorphic_array' from='%d' to='(exact)'", |
aoqi@0 | 194 | log->identify(tak->klass())); |
aoqi@0 | 195 | } |
aoqi@0 | 196 | array_klass = con; // Use cast value moving forward |
aoqi@0 | 197 | } |
aoqi@0 | 198 | } |
aoqi@0 | 199 | |
aoqi@0 | 200 | // Come here for polymorphic array klasses |
aoqi@0 | 201 | |
aoqi@0 | 202 | // Extract the array element class |
aoqi@0 | 203 | int element_klass_offset = in_bytes(ObjArrayKlass::element_klass_offset()); |
aoqi@0 | 204 | Node *p2 = basic_plus_adr(array_klass, array_klass, element_klass_offset); |
aoqi@0 | 205 | Node *a_e_klass = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p2, tak) ); |
aoqi@0 | 206 | |
aoqi@0 | 207 | // Check (the hard way) and throw if not a subklass. |
aoqi@0 | 208 | // Result is ignored, we just need the CFG effects. |
aoqi@0 | 209 | gen_checkcast( obj, a_e_klass ); |
aoqi@0 | 210 | } |
aoqi@0 | 211 | |
aoqi@0 | 212 | |
aoqi@0 | 213 | void Parse::emit_guard_for_new(ciInstanceKlass* klass) { |
aoqi@0 | 214 | // Emit guarded new |
aoqi@0 | 215 | // if (klass->_init_thread != current_thread || |
aoqi@0 | 216 | // klass->_init_state != being_initialized) |
aoqi@0 | 217 | // uncommon_trap |
aoqi@0 | 218 | Node* cur_thread = _gvn.transform( new (C) ThreadLocalNode() ); |
aoqi@0 | 219 | Node* merge = new (C) RegionNode(3); |
aoqi@0 | 220 | _gvn.set_type(merge, Type::CONTROL); |
aoqi@0 | 221 | Node* kls = makecon(TypeKlassPtr::make(klass)); |
aoqi@0 | 222 | |
aoqi@0 | 223 | Node* init_thread_offset = _gvn.MakeConX(in_bytes(InstanceKlass::init_thread_offset())); |
aoqi@0 | 224 | Node* adr_node = basic_plus_adr(kls, kls, init_thread_offset); |
aoqi@0 | 225 | Node* init_thread = make_load(NULL, adr_node, TypeRawPtr::BOTTOM, T_ADDRESS, MemNode::unordered); |
aoqi@0 | 226 | Node *tst = Bool( CmpP( init_thread, cur_thread), BoolTest::eq); |
aoqi@0 | 227 | IfNode* iff = create_and_map_if(control(), tst, PROB_ALWAYS, COUNT_UNKNOWN); |
aoqi@0 | 228 | set_control(IfTrue(iff)); |
aoqi@0 | 229 | merge->set_req(1, IfFalse(iff)); |
aoqi@0 | 230 | |
aoqi@0 | 231 | Node* init_state_offset = _gvn.MakeConX(in_bytes(InstanceKlass::init_state_offset())); |
aoqi@0 | 232 | adr_node = basic_plus_adr(kls, kls, init_state_offset); |
aoqi@0 | 233 | // Use T_BOOLEAN for InstanceKlass::_init_state so the compiler |
aoqi@0 | 234 | // can generate code to load it as unsigned byte. |
aoqi@0 | 235 | Node* init_state = make_load(NULL, adr_node, TypeInt::UBYTE, T_BOOLEAN, MemNode::unordered); |
aoqi@0 | 236 | Node* being_init = _gvn.intcon(InstanceKlass::being_initialized); |
aoqi@0 | 237 | tst = Bool( CmpI( init_state, being_init), BoolTest::eq); |
aoqi@0 | 238 | iff = create_and_map_if(control(), tst, PROB_ALWAYS, COUNT_UNKNOWN); |
aoqi@0 | 239 | set_control(IfTrue(iff)); |
aoqi@0 | 240 | merge->set_req(2, IfFalse(iff)); |
aoqi@0 | 241 | |
aoqi@0 | 242 | PreserveJVMState pjvms(this); |
aoqi@0 | 243 | record_for_igvn(merge); |
aoqi@0 | 244 | set_control(merge); |
aoqi@0 | 245 | |
aoqi@0 | 246 | uncommon_trap(Deoptimization::Reason_uninitialized, |
aoqi@0 | 247 | Deoptimization::Action_reinterpret, |
aoqi@0 | 248 | klass); |
aoqi@0 | 249 | } |
aoqi@0 | 250 | |
aoqi@0 | 251 | |
aoqi@0 | 252 | //------------------------------do_new----------------------------------------- |
aoqi@0 | 253 | void Parse::do_new() { |
aoqi@0 | 254 | kill_dead_locals(); |
aoqi@0 | 255 | |
aoqi@0 | 256 | bool will_link; |
aoqi@0 | 257 | ciInstanceKlass* klass = iter().get_klass(will_link)->as_instance_klass(); |
aoqi@0 | 258 | assert(will_link, "_new: typeflow responsibility"); |
aoqi@0 | 259 | |
aoqi@0 | 260 | // Should initialize, or throw an InstantiationError? |
aoqi@0 | 261 | if (!klass->is_initialized() && !klass->is_being_initialized() || |
aoqi@0 | 262 | klass->is_abstract() || klass->is_interface() || |
aoqi@0 | 263 | klass->name() == ciSymbol::java_lang_Class() || |
aoqi@0 | 264 | iter().is_unresolved_klass()) { |
aoqi@0 | 265 | uncommon_trap(Deoptimization::Reason_uninitialized, |
aoqi@0 | 266 | Deoptimization::Action_reinterpret, |
aoqi@0 | 267 | klass); |
aoqi@0 | 268 | return; |
aoqi@0 | 269 | } |
aoqi@0 | 270 | if (klass->is_being_initialized()) { |
aoqi@0 | 271 | emit_guard_for_new(klass); |
aoqi@0 | 272 | } |
aoqi@0 | 273 | |
aoqi@0 | 274 | Node* kls = makecon(TypeKlassPtr::make(klass)); |
aoqi@0 | 275 | Node* obj = new_instance(kls); |
aoqi@0 | 276 | |
aoqi@0 | 277 | // Push resultant oop onto stack |
aoqi@0 | 278 | push(obj); |
aoqi@0 | 279 | |
aoqi@0 | 280 | // Keep track of whether opportunities exist for StringBuilder |
aoqi@0 | 281 | // optimizations. |
aoqi@0 | 282 | if (OptimizeStringConcat && |
aoqi@0 | 283 | (klass == C->env()->StringBuilder_klass() || |
aoqi@0 | 284 | klass == C->env()->StringBuffer_klass())) { |
aoqi@0 | 285 | C->set_has_stringbuilder(true); |
aoqi@0 | 286 | } |
aoqi@0 | 287 | |
aoqi@0 | 288 | // Keep track of boxed values for EliminateAutoBox optimizations. |
aoqi@0 | 289 | if (C->eliminate_boxing() && klass->is_box_klass()) { |
aoqi@0 | 290 | C->set_has_boxed_value(true); |
aoqi@0 | 291 | } |
aoqi@0 | 292 | } |
aoqi@0 | 293 | |
aoqi@0 | 294 | #ifndef PRODUCT |
aoqi@0 | 295 | //------------------------------dump_map_adr_mem------------------------------- |
aoqi@0 | 296 | // Debug dump of the mapping from address types to MergeMemNode indices. |
aoqi@0 | 297 | void Parse::dump_map_adr_mem() const { |
aoqi@0 | 298 | tty->print_cr("--- Mapping from address types to memory Nodes ---"); |
aoqi@0 | 299 | MergeMemNode *mem = map() == NULL ? NULL : (map()->memory()->is_MergeMem() ? |
aoqi@0 | 300 | map()->memory()->as_MergeMem() : NULL); |
aoqi@0 | 301 | for (uint i = 0; i < (uint)C->num_alias_types(); i++) { |
aoqi@0 | 302 | C->alias_type(i)->print_on(tty); |
aoqi@0 | 303 | tty->print("\t"); |
aoqi@0 | 304 | // Node mapping, if any |
aoqi@0 | 305 | if (mem && i < mem->req() && mem->in(i) && mem->in(i) != mem->empty_memory()) { |
aoqi@0 | 306 | mem->in(i)->dump(); |
aoqi@0 | 307 | } else { |
aoqi@0 | 308 | tty->cr(); |
aoqi@0 | 309 | } |
aoqi@0 | 310 | } |
aoqi@0 | 311 | } |
aoqi@0 | 312 | |
aoqi@0 | 313 | #endif |
aoqi@0 | 314 | |
aoqi@0 | 315 | |
aoqi@0 | 316 | //============================================================================= |
aoqi@0 | 317 | // |
aoqi@0 | 318 | // parser methods for profiling |
aoqi@0 | 319 | |
aoqi@0 | 320 | |
aoqi@0 | 321 | //----------------------test_counter_against_threshold ------------------------ |
aoqi@0 | 322 | void Parse::test_counter_against_threshold(Node* cnt, int limit) { |
aoqi@0 | 323 | // Test the counter against the limit and uncommon trap if greater. |
aoqi@0 | 324 | |
aoqi@0 | 325 | // This code is largely copied from the range check code in |
aoqi@0 | 326 | // array_addressing() |
aoqi@0 | 327 | |
aoqi@0 | 328 | // Test invocation count vs threshold |
aoqi@0 | 329 | Node *threshold = makecon(TypeInt::make(limit)); |
aoqi@0 | 330 | Node *chk = _gvn.transform( new (C) CmpUNode( cnt, threshold) ); |
aoqi@0 | 331 | BoolTest::mask btest = BoolTest::lt; |
aoqi@0 | 332 | Node *tst = _gvn.transform( new (C) BoolNode( chk, btest) ); |
aoqi@0 | 333 | // Branch to failure if threshold exceeded |
aoqi@0 | 334 | { BuildCutout unless(this, tst, PROB_ALWAYS); |
aoqi@0 | 335 | uncommon_trap(Deoptimization::Reason_age, |
aoqi@0 | 336 | Deoptimization::Action_maybe_recompile); |
aoqi@0 | 337 | } |
aoqi@0 | 338 | } |
aoqi@0 | 339 | |
aoqi@0 | 340 | //----------------------increment_and_test_invocation_counter------------------- |
aoqi@0 | 341 | void Parse::increment_and_test_invocation_counter(int limit) { |
aoqi@0 | 342 | if (!count_invocations()) return; |
aoqi@0 | 343 | |
aoqi@0 | 344 | // Get the Method* node. |
aoqi@0 | 345 | ciMethod* m = method(); |
aoqi@0 | 346 | MethodCounters* counters_adr = m->ensure_method_counters(); |
aoqi@0 | 347 | if (counters_adr == NULL) { |
aoqi@0 | 348 | C->record_failure("method counters allocation failed"); |
aoqi@0 | 349 | return; |
aoqi@0 | 350 | } |
aoqi@0 | 351 | |
aoqi@0 | 352 | Node* ctrl = control(); |
aoqi@0 | 353 | const TypePtr* adr_type = TypeRawPtr::make((address) counters_adr); |
aoqi@0 | 354 | Node *counters_node = makecon(adr_type); |
aoqi@0 | 355 | Node* adr_iic_node = basic_plus_adr(counters_node, counters_node, |
aoqi@0 | 356 | MethodCounters::interpreter_invocation_counter_offset_in_bytes()); |
aoqi@0 | 357 | Node* cnt = make_load(ctrl, adr_iic_node, TypeInt::INT, T_INT, adr_type, MemNode::unordered); |
aoqi@0 | 358 | |
aoqi@0 | 359 | test_counter_against_threshold(cnt, limit); |
aoqi@0 | 360 | |
aoqi@0 | 361 | // Add one to the counter and store |
aoqi@0 | 362 | Node* incr = _gvn.transform(new (C) AddINode(cnt, _gvn.intcon(1))); |
aoqi@0 | 363 | store_to_memory(ctrl, adr_iic_node, incr, T_INT, adr_type, MemNode::unordered); |
aoqi@0 | 364 | } |
aoqi@0 | 365 | |
aoqi@0 | 366 | //----------------------------method_data_addressing--------------------------- |
aoqi@0 | 367 | Node* Parse::method_data_addressing(ciMethodData* md, ciProfileData* data, ByteSize counter_offset, Node* idx, uint stride) { |
aoqi@0 | 368 | // Get offset within MethodData* of the data array |
aoqi@0 | 369 | ByteSize data_offset = MethodData::data_offset(); |
aoqi@0 | 370 | |
aoqi@0 | 371 | // Get cell offset of the ProfileData within data array |
aoqi@0 | 372 | int cell_offset = md->dp_to_di(data->dp()); |
aoqi@0 | 373 | |
aoqi@0 | 374 | // Add in counter_offset, the # of bytes into the ProfileData of counter or flag |
aoqi@0 | 375 | int offset = in_bytes(data_offset) + cell_offset + in_bytes(counter_offset); |
aoqi@0 | 376 | |
aoqi@0 | 377 | const TypePtr* adr_type = TypeMetadataPtr::make(md); |
aoqi@0 | 378 | Node* mdo = makecon(adr_type); |
aoqi@0 | 379 | Node* ptr = basic_plus_adr(mdo, mdo, offset); |
aoqi@0 | 380 | |
aoqi@0 | 381 | if (stride != 0) { |
aoqi@0 | 382 | Node* str = _gvn.MakeConX(stride); |
aoqi@0 | 383 | Node* scale = _gvn.transform( new (C) MulXNode( idx, str ) ); |
aoqi@0 | 384 | ptr = _gvn.transform( new (C) AddPNode( mdo, ptr, scale ) ); |
aoqi@0 | 385 | } |
aoqi@0 | 386 | |
aoqi@0 | 387 | return ptr; |
aoqi@0 | 388 | } |
aoqi@0 | 389 | |
aoqi@0 | 390 | //--------------------------increment_md_counter_at---------------------------- |
aoqi@0 | 391 | void Parse::increment_md_counter_at(ciMethodData* md, ciProfileData* data, ByteSize counter_offset, Node* idx, uint stride) { |
aoqi@0 | 392 | Node* adr_node = method_data_addressing(md, data, counter_offset, idx, stride); |
aoqi@0 | 393 | |
aoqi@0 | 394 | const TypePtr* adr_type = _gvn.type(adr_node)->is_ptr(); |
aoqi@0 | 395 | Node* cnt = make_load(NULL, adr_node, TypeInt::INT, T_INT, adr_type, MemNode::unordered); |
aoqi@0 | 396 | Node* incr = _gvn.transform(new (C) AddINode(cnt, _gvn.intcon(DataLayout::counter_increment))); |
aoqi@0 | 397 | store_to_memory(NULL, adr_node, incr, T_INT, adr_type, MemNode::unordered); |
aoqi@0 | 398 | } |
aoqi@0 | 399 | |
aoqi@0 | 400 | //--------------------------test_for_osr_md_counter_at------------------------- |
aoqi@0 | 401 | void Parse::test_for_osr_md_counter_at(ciMethodData* md, ciProfileData* data, ByteSize counter_offset, int limit) { |
aoqi@0 | 402 | Node* adr_node = method_data_addressing(md, data, counter_offset); |
aoqi@0 | 403 | |
aoqi@0 | 404 | const TypePtr* adr_type = _gvn.type(adr_node)->is_ptr(); |
aoqi@0 | 405 | Node* cnt = make_load(NULL, adr_node, TypeInt::INT, T_INT, adr_type, MemNode::unordered); |
aoqi@0 | 406 | |
aoqi@0 | 407 | test_counter_against_threshold(cnt, limit); |
aoqi@0 | 408 | } |
aoqi@0 | 409 | |
aoqi@0 | 410 | //-------------------------------set_md_flag_at-------------------------------- |
aoqi@0 | 411 | void Parse::set_md_flag_at(ciMethodData* md, ciProfileData* data, int flag_constant) { |
aoqi@0 | 412 | Node* adr_node = method_data_addressing(md, data, DataLayout::flags_offset()); |
aoqi@0 | 413 | |
aoqi@0 | 414 | const TypePtr* adr_type = _gvn.type(adr_node)->is_ptr(); |
aoqi@0 | 415 | Node* flags = make_load(NULL, adr_node, TypeInt::BYTE, T_BYTE, adr_type, MemNode::unordered); |
aoqi@0 | 416 | Node* incr = _gvn.transform(new (C) OrINode(flags, _gvn.intcon(flag_constant))); |
aoqi@0 | 417 | store_to_memory(NULL, adr_node, incr, T_BYTE, adr_type, MemNode::unordered); |
aoqi@0 | 418 | } |
aoqi@0 | 419 | |
aoqi@0 | 420 | //----------------------------profile_taken_branch----------------------------- |
aoqi@0 | 421 | void Parse::profile_taken_branch(int target_bci, bool force_update) { |
aoqi@0 | 422 | // This is a potential osr_site if we have a backedge. |
aoqi@0 | 423 | int cur_bci = bci(); |
aoqi@0 | 424 | bool osr_site = |
aoqi@0 | 425 | (target_bci <= cur_bci) && count_invocations() && UseOnStackReplacement; |
aoqi@0 | 426 | |
aoqi@0 | 427 | // If we are going to OSR, restart at the target bytecode. |
aoqi@0 | 428 | set_bci(target_bci); |
aoqi@0 | 429 | |
aoqi@0 | 430 | // To do: factor out the the limit calculations below. These duplicate |
aoqi@0 | 431 | // the similar limit calculations in the interpreter. |
aoqi@0 | 432 | |
aoqi@0 | 433 | if (method_data_update() || force_update) { |
aoqi@0 | 434 | ciMethodData* md = method()->method_data(); |
aoqi@0 | 435 | assert(md != NULL, "expected valid ciMethodData"); |
aoqi@0 | 436 | ciProfileData* data = md->bci_to_data(cur_bci); |
aoqi@0 | 437 | assert(data->is_JumpData(), "need JumpData for taken branch"); |
aoqi@0 | 438 | increment_md_counter_at(md, data, JumpData::taken_offset()); |
aoqi@0 | 439 | } |
aoqi@0 | 440 | |
aoqi@0 | 441 | // In the new tiered system this is all we need to do. In the old |
aoqi@0 | 442 | // (c2 based) tiered sytem we must do the code below. |
aoqi@0 | 443 | #ifndef TIERED |
aoqi@0 | 444 | if (method_data_update()) { |
aoqi@0 | 445 | ciMethodData* md = method()->method_data(); |
aoqi@0 | 446 | if (osr_site) { |
aoqi@0 | 447 | ciProfileData* data = md->bci_to_data(cur_bci); |
aoqi@0 | 448 | int limit = (CompileThreshold |
aoqi@0 | 449 | * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100; |
aoqi@0 | 450 | test_for_osr_md_counter_at(md, data, JumpData::taken_offset(), limit); |
aoqi@0 | 451 | } |
aoqi@0 | 452 | } else { |
aoqi@0 | 453 | // With method data update off, use the invocation counter to trigger an |
aoqi@0 | 454 | // OSR compilation, as done in the interpreter. |
aoqi@0 | 455 | if (osr_site) { |
aoqi@0 | 456 | int limit = (CompileThreshold * OnStackReplacePercentage) / 100; |
aoqi@0 | 457 | increment_and_test_invocation_counter(limit); |
aoqi@0 | 458 | } |
aoqi@0 | 459 | } |
aoqi@0 | 460 | #endif // TIERED |
aoqi@0 | 461 | |
aoqi@0 | 462 | // Restore the original bytecode. |
aoqi@0 | 463 | set_bci(cur_bci); |
aoqi@0 | 464 | } |
aoqi@0 | 465 | |
aoqi@0 | 466 | //--------------------------profile_not_taken_branch--------------------------- |
aoqi@0 | 467 | void Parse::profile_not_taken_branch(bool force_update) { |
aoqi@0 | 468 | |
aoqi@0 | 469 | if (method_data_update() || force_update) { |
aoqi@0 | 470 | ciMethodData* md = method()->method_data(); |
aoqi@0 | 471 | assert(md != NULL, "expected valid ciMethodData"); |
aoqi@0 | 472 | ciProfileData* data = md->bci_to_data(bci()); |
aoqi@0 | 473 | assert(data->is_BranchData(), "need BranchData for not taken branch"); |
aoqi@0 | 474 | increment_md_counter_at(md, data, BranchData::not_taken_offset()); |
aoqi@0 | 475 | } |
aoqi@0 | 476 | |
aoqi@0 | 477 | } |
aoqi@0 | 478 | |
aoqi@0 | 479 | //---------------------------------profile_call-------------------------------- |
aoqi@0 | 480 | void Parse::profile_call(Node* receiver) { |
aoqi@0 | 481 | if (!method_data_update()) return; |
aoqi@0 | 482 | |
aoqi@0 | 483 | switch (bc()) { |
aoqi@0 | 484 | case Bytecodes::_invokevirtual: |
aoqi@0 | 485 | case Bytecodes::_invokeinterface: |
aoqi@0 | 486 | profile_receiver_type(receiver); |
aoqi@0 | 487 | break; |
aoqi@0 | 488 | case Bytecodes::_invokestatic: |
aoqi@0 | 489 | case Bytecodes::_invokedynamic: |
aoqi@0 | 490 | case Bytecodes::_invokespecial: |
aoqi@0 | 491 | profile_generic_call(); |
aoqi@0 | 492 | break; |
aoqi@0 | 493 | default: fatal("unexpected call bytecode"); |
aoqi@0 | 494 | } |
aoqi@0 | 495 | } |
aoqi@0 | 496 | |
aoqi@0 | 497 | //------------------------------profile_generic_call--------------------------- |
aoqi@0 | 498 | void Parse::profile_generic_call() { |
aoqi@0 | 499 | assert(method_data_update(), "must be generating profile code"); |
aoqi@0 | 500 | |
aoqi@0 | 501 | ciMethodData* md = method()->method_data(); |
aoqi@0 | 502 | assert(md != NULL, "expected valid ciMethodData"); |
aoqi@0 | 503 | ciProfileData* data = md->bci_to_data(bci()); |
aoqi@0 | 504 | assert(data->is_CounterData(), "need CounterData for not taken branch"); |
aoqi@0 | 505 | increment_md_counter_at(md, data, CounterData::count_offset()); |
aoqi@0 | 506 | } |
aoqi@0 | 507 | |
aoqi@0 | 508 | //-----------------------------profile_receiver_type--------------------------- |
aoqi@0 | 509 | void Parse::profile_receiver_type(Node* receiver) { |
aoqi@0 | 510 | assert(method_data_update(), "must be generating profile code"); |
aoqi@0 | 511 | |
aoqi@0 | 512 | ciMethodData* md = method()->method_data(); |
aoqi@0 | 513 | assert(md != NULL, "expected valid ciMethodData"); |
aoqi@0 | 514 | ciProfileData* data = md->bci_to_data(bci()); |
aoqi@0 | 515 | assert(data->is_ReceiverTypeData(), "need ReceiverTypeData here"); |
aoqi@0 | 516 | |
aoqi@0 | 517 | // Skip if we aren't tracking receivers |
aoqi@0 | 518 | if (TypeProfileWidth < 1) { |
aoqi@0 | 519 | increment_md_counter_at(md, data, CounterData::count_offset()); |
aoqi@0 | 520 | return; |
aoqi@0 | 521 | } |
aoqi@0 | 522 | ciReceiverTypeData* rdata = (ciReceiverTypeData*)data->as_ReceiverTypeData(); |
aoqi@0 | 523 | |
aoqi@0 | 524 | Node* method_data = method_data_addressing(md, rdata, in_ByteSize(0)); |
aoqi@0 | 525 | |
aoqi@0 | 526 | // Using an adr_type of TypePtr::BOTTOM to work around anti-dep problems. |
aoqi@0 | 527 | // A better solution might be to use TypeRawPtr::BOTTOM with RC_NARROW_MEM. |
aoqi@0 | 528 | make_runtime_call(RC_LEAF, OptoRuntime::profile_receiver_type_Type(), |
aoqi@0 | 529 | CAST_FROM_FN_PTR(address, |
aoqi@0 | 530 | OptoRuntime::profile_receiver_type_C), |
aoqi@0 | 531 | "profile_receiver_type_C", |
aoqi@0 | 532 | TypePtr::BOTTOM, |
aoqi@0 | 533 | method_data, receiver); |
aoqi@0 | 534 | } |
aoqi@0 | 535 | |
aoqi@0 | 536 | //---------------------------------profile_ret--------------------------------- |
aoqi@0 | 537 | void Parse::profile_ret(int target_bci) { |
aoqi@0 | 538 | if (!method_data_update()) return; |
aoqi@0 | 539 | |
aoqi@0 | 540 | // Skip if we aren't tracking ret targets |
aoqi@0 | 541 | if (TypeProfileWidth < 1) return; |
aoqi@0 | 542 | |
aoqi@0 | 543 | ciMethodData* md = method()->method_data(); |
aoqi@0 | 544 | assert(md != NULL, "expected valid ciMethodData"); |
aoqi@0 | 545 | ciProfileData* data = md->bci_to_data(bci()); |
aoqi@0 | 546 | assert(data->is_RetData(), "need RetData for ret"); |
aoqi@0 | 547 | ciRetData* ret_data = (ciRetData*)data->as_RetData(); |
aoqi@0 | 548 | |
aoqi@0 | 549 | // Look for the target_bci is already in the table |
aoqi@0 | 550 | uint row; |
aoqi@0 | 551 | bool table_full = true; |
aoqi@0 | 552 | for (row = 0; row < ret_data->row_limit(); row++) { |
aoqi@0 | 553 | int key = ret_data->bci(row); |
aoqi@0 | 554 | table_full &= (key != RetData::no_bci); |
aoqi@0 | 555 | if (key == target_bci) break; |
aoqi@0 | 556 | } |
aoqi@0 | 557 | |
aoqi@0 | 558 | if (row >= ret_data->row_limit()) { |
aoqi@0 | 559 | // The target_bci was not found in the table. |
aoqi@0 | 560 | if (!table_full) { |
aoqi@0 | 561 | // XXX: Make slow call to update RetData |
aoqi@0 | 562 | } |
aoqi@0 | 563 | return; |
aoqi@0 | 564 | } |
aoqi@0 | 565 | |
aoqi@0 | 566 | // the target_bci is already in the table |
aoqi@0 | 567 | increment_md_counter_at(md, data, RetData::bci_count_offset(row)); |
aoqi@0 | 568 | } |
aoqi@0 | 569 | |
aoqi@0 | 570 | //--------------------------profile_null_checkcast---------------------------- |
aoqi@0 | 571 | void Parse::profile_null_checkcast() { |
aoqi@0 | 572 | // Set the null-seen flag, done in conjunction with the usual null check. We |
aoqi@0 | 573 | // never unset the flag, so this is a one-way switch. |
aoqi@0 | 574 | if (!method_data_update()) return; |
aoqi@0 | 575 | |
aoqi@0 | 576 | ciMethodData* md = method()->method_data(); |
aoqi@0 | 577 | assert(md != NULL, "expected valid ciMethodData"); |
aoqi@0 | 578 | ciProfileData* data = md->bci_to_data(bci()); |
aoqi@0 | 579 | assert(data->is_BitData(), "need BitData for checkcast"); |
aoqi@0 | 580 | set_md_flag_at(md, data, BitData::null_seen_byte_constant()); |
aoqi@0 | 581 | } |
aoqi@0 | 582 | |
aoqi@0 | 583 | //-----------------------------profile_switch_case----------------------------- |
aoqi@0 | 584 | void Parse::profile_switch_case(int table_index) { |
aoqi@0 | 585 | if (!method_data_update()) return; |
aoqi@0 | 586 | |
aoqi@0 | 587 | ciMethodData* md = method()->method_data(); |
aoqi@0 | 588 | assert(md != NULL, "expected valid ciMethodData"); |
aoqi@0 | 589 | |
aoqi@0 | 590 | ciProfileData* data = md->bci_to_data(bci()); |
aoqi@0 | 591 | assert(data->is_MultiBranchData(), "need MultiBranchData for switch case"); |
aoqi@0 | 592 | if (table_index >= 0) { |
aoqi@0 | 593 | increment_md_counter_at(md, data, MultiBranchData::case_count_offset(table_index)); |
aoqi@0 | 594 | } else { |
aoqi@0 | 595 | increment_md_counter_at(md, data, MultiBranchData::default_count_offset()); |
aoqi@0 | 596 | } |
aoqi@0 | 597 | } |