src/share/vm/opto/parseHelper.cpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/opto/parseHelper.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,597 @@
     1.4 +/*
     1.5 + * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "precompiled.hpp"
    1.29 +#include "classfile/systemDictionary.hpp"
    1.30 +#include "compiler/compileLog.hpp"
    1.31 +#include "oops/objArrayKlass.hpp"
    1.32 +#include "opto/addnode.hpp"
    1.33 +#include "opto/memnode.hpp"
    1.34 +#include "opto/mulnode.hpp"
    1.35 +#include "opto/parse.hpp"
    1.36 +#include "opto/rootnode.hpp"
    1.37 +#include "opto/runtime.hpp"
    1.38 +#include "runtime/sharedRuntime.hpp"
    1.39 +
    1.40 +//------------------------------make_dtrace_method_entry_exit ----------------
    1.41 +// Dtrace -- record entry or exit of a method if compiled with dtrace support
    1.42 +void GraphKit::make_dtrace_method_entry_exit(ciMethod* method, bool is_entry) {
    1.43 +  const TypeFunc *call_type    = OptoRuntime::dtrace_method_entry_exit_Type();
    1.44 +  address         call_address = is_entry ? CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry) :
    1.45 +                                            CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit);
    1.46 +  const char     *call_name    = is_entry ? "dtrace_method_entry" : "dtrace_method_exit";
    1.47 +
    1.48 +  // Get base of thread-local storage area
    1.49 +  Node* thread = _gvn.transform( new (C) ThreadLocalNode() );
    1.50 +
    1.51 +  // Get method
    1.52 +  const TypePtr* method_type = TypeMetadataPtr::make(method);
    1.53 +  Node *method_node = _gvn.transform( ConNode::make(C, method_type) );
    1.54 +
    1.55 +  kill_dead_locals();
    1.56 +
    1.57 +  // For some reason, this call reads only raw memory.
    1.58 +  const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM;
    1.59 +  make_runtime_call(RC_LEAF | RC_NARROW_MEM,
    1.60 +                    call_type, call_address,
    1.61 +                    call_name, raw_adr_type,
    1.62 +                    thread, method_node);
    1.63 +}
    1.64 +
    1.65 +
    1.66 +//=============================================================================
    1.67 +//------------------------------do_checkcast-----------------------------------
    1.68 +void Parse::do_checkcast() {
    1.69 +  bool will_link;
    1.70 +  ciKlass* klass = iter().get_klass(will_link);
    1.71 +
    1.72 +  Node *obj = peek();
    1.73 +
    1.74 +  // Throw uncommon trap if class is not loaded or the value we are casting
    1.75 +  // _from_ is not loaded, and value is not null.  If the value _is_ NULL,
    1.76 +  // then the checkcast does nothing.
    1.77 +  const TypeOopPtr *tp = _gvn.type(obj)->isa_oopptr();
    1.78 +  if (!will_link || (tp && tp->klass() && !tp->klass()->is_loaded())) {
    1.79 +    if (C->log() != NULL) {
    1.80 +      if (!will_link) {
    1.81 +        C->log()->elem("assert_null reason='checkcast' klass='%d'",
    1.82 +                       C->log()->identify(klass));
    1.83 +      }
    1.84 +      if (tp && tp->klass() && !tp->klass()->is_loaded()) {
    1.85 +        // %%% Cannot happen?
    1.86 +        C->log()->elem("assert_null reason='checkcast source' klass='%d'",
    1.87 +                       C->log()->identify(tp->klass()));
    1.88 +      }
    1.89 +    }
    1.90 +    null_assert(obj);
    1.91 +    assert( stopped() || _gvn.type(peek())->higher_equal(TypePtr::NULL_PTR), "what's left behind is null" );
    1.92 +    if (!stopped()) {
    1.93 +      profile_null_checkcast();
    1.94 +    }
    1.95 +    return;
    1.96 +  }
    1.97 +
    1.98 +  Node *res = gen_checkcast(obj, makecon(TypeKlassPtr::make(klass)) );
    1.99 +
   1.100 +  // Pop from stack AFTER gen_checkcast because it can uncommon trap and
   1.101 +  // the debug info has to be correct.
   1.102 +  pop();
   1.103 +  push(res);
   1.104 +}
   1.105 +
   1.106 +
   1.107 +//------------------------------do_instanceof----------------------------------
   1.108 +void Parse::do_instanceof() {
   1.109 +  if (stopped())  return;
   1.110 +  // We would like to return false if class is not loaded, emitting a
   1.111 +  // dependency, but Java requires instanceof to load its operand.
   1.112 +
   1.113 +  // Throw uncommon trap if class is not loaded
   1.114 +  bool will_link;
   1.115 +  ciKlass* klass = iter().get_klass(will_link);
   1.116 +
   1.117 +  if (!will_link) {
   1.118 +    if (C->log() != NULL) {
   1.119 +      C->log()->elem("assert_null reason='instanceof' klass='%d'",
   1.120 +                     C->log()->identify(klass));
   1.121 +    }
   1.122 +    null_assert(peek());
   1.123 +    assert( stopped() || _gvn.type(peek())->higher_equal(TypePtr::NULL_PTR), "what's left behind is null" );
   1.124 +    if (!stopped()) {
   1.125 +      // The object is now known to be null.
   1.126 +      // Shortcut the effect of gen_instanceof and return "false" directly.
   1.127 +      pop();                   // pop the null
   1.128 +      push(_gvn.intcon(0));    // push false answer
   1.129 +    }
   1.130 +    return;
   1.131 +  }
   1.132 +
   1.133 +  // Push the bool result back on stack
   1.134 +  Node* res = gen_instanceof(peek(), makecon(TypeKlassPtr::make(klass)), true);
   1.135 +
   1.136 +  // Pop from stack AFTER gen_instanceof because it can uncommon trap.
   1.137 +  pop();
   1.138 +  push(res);
   1.139 +}
   1.140 +
   1.141 +//------------------------------array_store_check------------------------------
   1.142 +// pull array from stack and check that the store is valid
   1.143 +void Parse::array_store_check() {
   1.144 +
   1.145 +  // Shorthand access to array store elements without popping them.
   1.146 +  Node *obj = peek(0);
   1.147 +  Node *idx = peek(1);
   1.148 +  Node *ary = peek(2);
   1.149 +
   1.150 +  if (_gvn.type(obj) == TypePtr::NULL_PTR) {
   1.151 +    // There's never a type check on null values.
   1.152 +    // This cutout lets us avoid the uncommon_trap(Reason_array_check)
   1.153 +    // below, which turns into a performance liability if the
   1.154 +    // gen_checkcast folds up completely.
   1.155 +    return;
   1.156 +  }
   1.157 +
   1.158 +  // Extract the array klass type
   1.159 +  int klass_offset = oopDesc::klass_offset_in_bytes();
   1.160 +  Node* p = basic_plus_adr( ary, ary, klass_offset );
   1.161 +  // p's type is array-of-OOPS plus klass_offset
   1.162 +  Node* array_klass = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p, TypeInstPtr::KLASS) );
   1.163 +  // Get the array klass
   1.164 +  const TypeKlassPtr *tak = _gvn.type(array_klass)->is_klassptr();
   1.165 +
   1.166 +  // array_klass's type is generally INexact array-of-oop.  Heroically
   1.167 +  // cast the array klass to EXACT array and uncommon-trap if the cast
   1.168 +  // fails.
   1.169 +  bool always_see_exact_class = false;
   1.170 +  if (MonomorphicArrayCheck
   1.171 +      && !too_many_traps(Deoptimization::Reason_array_check)) {
   1.172 +    always_see_exact_class = true;
   1.173 +    // (If no MDO at all, hope for the best, until a trap actually occurs.)
   1.174 +  }
   1.175 +
   1.176 +  // Is the array klass is exactly its defined type?
   1.177 +  if (always_see_exact_class && !tak->klass_is_exact()) {
   1.178 +    // Make a constant out of the inexact array klass
   1.179 +    const TypeKlassPtr *extak = tak->cast_to_exactness(true)->is_klassptr();
   1.180 +    Node* con = makecon(extak);
   1.181 +    Node* cmp = _gvn.transform(new (C) CmpPNode( array_klass, con ));
   1.182 +    Node* bol = _gvn.transform(new (C) BoolNode( cmp, BoolTest::eq ));
   1.183 +    Node* ctrl= control();
   1.184 +    { BuildCutout unless(this, bol, PROB_MAX);
   1.185 +      uncommon_trap(Deoptimization::Reason_array_check,
   1.186 +                    Deoptimization::Action_maybe_recompile,
   1.187 +                    tak->klass());
   1.188 +    }
   1.189 +    if (stopped()) {          // MUST uncommon-trap?
   1.190 +      set_control(ctrl);      // Then Don't Do It, just fall into the normal checking
   1.191 +    } else {                  // Cast array klass to exactness:
   1.192 +      // Use the exact constant value we know it is.
   1.193 +      replace_in_map(array_klass,con);
   1.194 +      CompileLog* log = C->log();
   1.195 +      if (log != NULL) {
   1.196 +        log->elem("cast_up reason='monomorphic_array' from='%d' to='(exact)'",
   1.197 +                  log->identify(tak->klass()));
   1.198 +      }
   1.199 +      array_klass = con;      // Use cast value moving forward
   1.200 +    }
   1.201 +  }
   1.202 +
   1.203 +  // Come here for polymorphic array klasses
   1.204 +
   1.205 +  // Extract the array element class
   1.206 +  int element_klass_offset = in_bytes(ObjArrayKlass::element_klass_offset());
   1.207 +  Node *p2 = basic_plus_adr(array_klass, array_klass, element_klass_offset);
   1.208 +  Node *a_e_klass = _gvn.transform( LoadKlassNode::make(_gvn, immutable_memory(), p2, tak) );
   1.209 +
   1.210 +  // Check (the hard way) and throw if not a subklass.
   1.211 +  // Result is ignored, we just need the CFG effects.
   1.212 +  gen_checkcast( obj, a_e_klass );
   1.213 +}
   1.214 +
   1.215 +
   1.216 +void Parse::emit_guard_for_new(ciInstanceKlass* klass) {
   1.217 +  // Emit guarded new
   1.218 +  //   if (klass->_init_thread != current_thread ||
   1.219 +  //       klass->_init_state != being_initialized)
   1.220 +  //      uncommon_trap
   1.221 +  Node* cur_thread = _gvn.transform( new (C) ThreadLocalNode() );
   1.222 +  Node* merge = new (C) RegionNode(3);
   1.223 +  _gvn.set_type(merge, Type::CONTROL);
   1.224 +  Node* kls = makecon(TypeKlassPtr::make(klass));
   1.225 +
   1.226 +  Node* init_thread_offset = _gvn.MakeConX(in_bytes(InstanceKlass::init_thread_offset()));
   1.227 +  Node* adr_node = basic_plus_adr(kls, kls, init_thread_offset);
   1.228 +  Node* init_thread = make_load(NULL, adr_node, TypeRawPtr::BOTTOM, T_ADDRESS, MemNode::unordered);
   1.229 +  Node *tst   = Bool( CmpP( init_thread, cur_thread), BoolTest::eq);
   1.230 +  IfNode* iff = create_and_map_if(control(), tst, PROB_ALWAYS, COUNT_UNKNOWN);
   1.231 +  set_control(IfTrue(iff));
   1.232 +  merge->set_req(1, IfFalse(iff));
   1.233 +
   1.234 +  Node* init_state_offset = _gvn.MakeConX(in_bytes(InstanceKlass::init_state_offset()));
   1.235 +  adr_node = basic_plus_adr(kls, kls, init_state_offset);
   1.236 +  // Use T_BOOLEAN for InstanceKlass::_init_state so the compiler
   1.237 +  // can generate code to load it as unsigned byte.
   1.238 +  Node* init_state = make_load(NULL, adr_node, TypeInt::UBYTE, T_BOOLEAN, MemNode::unordered);
   1.239 +  Node* being_init = _gvn.intcon(InstanceKlass::being_initialized);
   1.240 +  tst   = Bool( CmpI( init_state, being_init), BoolTest::eq);
   1.241 +  iff = create_and_map_if(control(), tst, PROB_ALWAYS, COUNT_UNKNOWN);
   1.242 +  set_control(IfTrue(iff));
   1.243 +  merge->set_req(2, IfFalse(iff));
   1.244 +
   1.245 +  PreserveJVMState pjvms(this);
   1.246 +  record_for_igvn(merge);
   1.247 +  set_control(merge);
   1.248 +
   1.249 +  uncommon_trap(Deoptimization::Reason_uninitialized,
   1.250 +                Deoptimization::Action_reinterpret,
   1.251 +                klass);
   1.252 +}
   1.253 +
   1.254 +
   1.255 +//------------------------------do_new-----------------------------------------
   1.256 +void Parse::do_new() {
   1.257 +  kill_dead_locals();
   1.258 +
   1.259 +  bool will_link;
   1.260 +  ciInstanceKlass* klass = iter().get_klass(will_link)->as_instance_klass();
   1.261 +  assert(will_link, "_new: typeflow responsibility");
   1.262 +
   1.263 +  // Should initialize, or throw an InstantiationError?
   1.264 +  if (!klass->is_initialized() && !klass->is_being_initialized() ||
   1.265 +      klass->is_abstract() || klass->is_interface() ||
   1.266 +      klass->name() == ciSymbol::java_lang_Class() ||
   1.267 +      iter().is_unresolved_klass()) {
   1.268 +    uncommon_trap(Deoptimization::Reason_uninitialized,
   1.269 +                  Deoptimization::Action_reinterpret,
   1.270 +                  klass);
   1.271 +    return;
   1.272 +  }
   1.273 +  if (klass->is_being_initialized()) {
   1.274 +    emit_guard_for_new(klass);
   1.275 +  }
   1.276 +
   1.277 +  Node* kls = makecon(TypeKlassPtr::make(klass));
   1.278 +  Node* obj = new_instance(kls);
   1.279 +
   1.280 +  // Push resultant oop onto stack
   1.281 +  push(obj);
   1.282 +
   1.283 +  // Keep track of whether opportunities exist for StringBuilder
   1.284 +  // optimizations.
   1.285 +  if (OptimizeStringConcat &&
   1.286 +      (klass == C->env()->StringBuilder_klass() ||
   1.287 +       klass == C->env()->StringBuffer_klass())) {
   1.288 +    C->set_has_stringbuilder(true);
   1.289 +  }
   1.290 +
   1.291 +  // Keep track of boxed values for EliminateAutoBox optimizations.
   1.292 +  if (C->eliminate_boxing() && klass->is_box_klass()) {
   1.293 +    C->set_has_boxed_value(true);
   1.294 +  }
   1.295 +}
   1.296 +
   1.297 +#ifndef PRODUCT
   1.298 +//------------------------------dump_map_adr_mem-------------------------------
   1.299 +// Debug dump of the mapping from address types to MergeMemNode indices.
   1.300 +void Parse::dump_map_adr_mem() const {
   1.301 +  tty->print_cr("--- Mapping from address types to memory Nodes ---");
   1.302 +  MergeMemNode *mem = map() == NULL ? NULL : (map()->memory()->is_MergeMem() ?
   1.303 +                                      map()->memory()->as_MergeMem() : NULL);
   1.304 +  for (uint i = 0; i < (uint)C->num_alias_types(); i++) {
   1.305 +    C->alias_type(i)->print_on(tty);
   1.306 +    tty->print("\t");
   1.307 +    // Node mapping, if any
   1.308 +    if (mem && i < mem->req() && mem->in(i) && mem->in(i) != mem->empty_memory()) {
   1.309 +      mem->in(i)->dump();
   1.310 +    } else {
   1.311 +      tty->cr();
   1.312 +    }
   1.313 +  }
   1.314 +}
   1.315 +
   1.316 +#endif
   1.317 +
   1.318 +
   1.319 +//=============================================================================
   1.320 +//
   1.321 +// parser methods for profiling
   1.322 +
   1.323 +
   1.324 +//----------------------test_counter_against_threshold ------------------------
   1.325 +void Parse::test_counter_against_threshold(Node* cnt, int limit) {
   1.326 +  // Test the counter against the limit and uncommon trap if greater.
   1.327 +
   1.328 +  // This code is largely copied from the range check code in
   1.329 +  // array_addressing()
   1.330 +
   1.331 +  // Test invocation count vs threshold
   1.332 +  Node *threshold = makecon(TypeInt::make(limit));
   1.333 +  Node *chk   = _gvn.transform( new (C) CmpUNode( cnt, threshold) );
   1.334 +  BoolTest::mask btest = BoolTest::lt;
   1.335 +  Node *tst   = _gvn.transform( new (C) BoolNode( chk, btest) );
   1.336 +  // Branch to failure if threshold exceeded
   1.337 +  { BuildCutout unless(this, tst, PROB_ALWAYS);
   1.338 +    uncommon_trap(Deoptimization::Reason_age,
   1.339 +                  Deoptimization::Action_maybe_recompile);
   1.340 +  }
   1.341 +}
   1.342 +
   1.343 +//----------------------increment_and_test_invocation_counter-------------------
   1.344 +void Parse::increment_and_test_invocation_counter(int limit) {
   1.345 +  if (!count_invocations()) return;
   1.346 +
   1.347 +  // Get the Method* node.
   1.348 +  ciMethod* m = method();
   1.349 +  MethodCounters* counters_adr = m->ensure_method_counters();
   1.350 +  if (counters_adr == NULL) {
   1.351 +    C->record_failure("method counters allocation failed");
   1.352 +    return;
   1.353 +  }
   1.354 +
   1.355 +  Node* ctrl = control();
   1.356 +  const TypePtr* adr_type = TypeRawPtr::make((address) counters_adr);
   1.357 +  Node *counters_node = makecon(adr_type);
   1.358 +  Node* adr_iic_node = basic_plus_adr(counters_node, counters_node,
   1.359 +    MethodCounters::interpreter_invocation_counter_offset_in_bytes());
   1.360 +  Node* cnt = make_load(ctrl, adr_iic_node, TypeInt::INT, T_INT, adr_type, MemNode::unordered);
   1.361 +
   1.362 +  test_counter_against_threshold(cnt, limit);
   1.363 +
   1.364 +  // Add one to the counter and store
   1.365 +  Node* incr = _gvn.transform(new (C) AddINode(cnt, _gvn.intcon(1)));
   1.366 +  store_to_memory(ctrl, adr_iic_node, incr, T_INT, adr_type, MemNode::unordered);
   1.367 +}
   1.368 +
   1.369 +//----------------------------method_data_addressing---------------------------
   1.370 +Node* Parse::method_data_addressing(ciMethodData* md, ciProfileData* data, ByteSize counter_offset, Node* idx, uint stride) {
   1.371 +  // Get offset within MethodData* of the data array
   1.372 +  ByteSize data_offset = MethodData::data_offset();
   1.373 +
   1.374 +  // Get cell offset of the ProfileData within data array
   1.375 +  int cell_offset = md->dp_to_di(data->dp());
   1.376 +
   1.377 +  // Add in counter_offset, the # of bytes into the ProfileData of counter or flag
   1.378 +  int offset = in_bytes(data_offset) + cell_offset + in_bytes(counter_offset);
   1.379 +
   1.380 +  const TypePtr* adr_type = TypeMetadataPtr::make(md);
   1.381 +  Node* mdo = makecon(adr_type);
   1.382 +  Node* ptr = basic_plus_adr(mdo, mdo, offset);
   1.383 +
   1.384 +  if (stride != 0) {
   1.385 +    Node* str = _gvn.MakeConX(stride);
   1.386 +    Node* scale = _gvn.transform( new (C) MulXNode( idx, str ) );
   1.387 +    ptr   = _gvn.transform( new (C) AddPNode( mdo, ptr, scale ) );
   1.388 +  }
   1.389 +
   1.390 +  return ptr;
   1.391 +}
   1.392 +
   1.393 +//--------------------------increment_md_counter_at----------------------------
   1.394 +void Parse::increment_md_counter_at(ciMethodData* md, ciProfileData* data, ByteSize counter_offset, Node* idx, uint stride) {
   1.395 +  Node* adr_node = method_data_addressing(md, data, counter_offset, idx, stride);
   1.396 +
   1.397 +  const TypePtr* adr_type = _gvn.type(adr_node)->is_ptr();
   1.398 +  Node* cnt  = make_load(NULL, adr_node, TypeInt::INT, T_INT, adr_type, MemNode::unordered);
   1.399 +  Node* incr = _gvn.transform(new (C) AddINode(cnt, _gvn.intcon(DataLayout::counter_increment)));
   1.400 +  store_to_memory(NULL, adr_node, incr, T_INT, adr_type, MemNode::unordered);
   1.401 +}
   1.402 +
   1.403 +//--------------------------test_for_osr_md_counter_at-------------------------
   1.404 +void Parse::test_for_osr_md_counter_at(ciMethodData* md, ciProfileData* data, ByteSize counter_offset, int limit) {
   1.405 +  Node* adr_node = method_data_addressing(md, data, counter_offset);
   1.406 +
   1.407 +  const TypePtr* adr_type = _gvn.type(adr_node)->is_ptr();
   1.408 +  Node* cnt  = make_load(NULL, adr_node, TypeInt::INT, T_INT, adr_type, MemNode::unordered);
   1.409 +
   1.410 +  test_counter_against_threshold(cnt, limit);
   1.411 +}
   1.412 +
   1.413 +//-------------------------------set_md_flag_at--------------------------------
   1.414 +void Parse::set_md_flag_at(ciMethodData* md, ciProfileData* data, int flag_constant) {
   1.415 +  Node* adr_node = method_data_addressing(md, data, DataLayout::flags_offset());
   1.416 +
   1.417 +  const TypePtr* adr_type = _gvn.type(adr_node)->is_ptr();
   1.418 +  Node* flags = make_load(NULL, adr_node, TypeInt::BYTE, T_BYTE, adr_type, MemNode::unordered);
   1.419 +  Node* incr = _gvn.transform(new (C) OrINode(flags, _gvn.intcon(flag_constant)));
   1.420 +  store_to_memory(NULL, adr_node, incr, T_BYTE, adr_type, MemNode::unordered);
   1.421 +}
   1.422 +
   1.423 +//----------------------------profile_taken_branch-----------------------------
   1.424 +void Parse::profile_taken_branch(int target_bci, bool force_update) {
   1.425 +  // This is a potential osr_site if we have a backedge.
   1.426 +  int cur_bci = bci();
   1.427 +  bool osr_site =
   1.428 +    (target_bci <= cur_bci) && count_invocations() && UseOnStackReplacement;
   1.429 +
   1.430 +  // If we are going to OSR, restart at the target bytecode.
   1.431 +  set_bci(target_bci);
   1.432 +
   1.433 +  // To do: factor out the the limit calculations below. These duplicate
   1.434 +  // the similar limit calculations in the interpreter.
   1.435 +
   1.436 +  if (method_data_update() || force_update) {
   1.437 +    ciMethodData* md = method()->method_data();
   1.438 +    assert(md != NULL, "expected valid ciMethodData");
   1.439 +    ciProfileData* data = md->bci_to_data(cur_bci);
   1.440 +    assert(data->is_JumpData(), "need JumpData for taken branch");
   1.441 +    increment_md_counter_at(md, data, JumpData::taken_offset());
   1.442 +  }
   1.443 +
   1.444 +  // In the new tiered system this is all we need to do. In the old
   1.445 +  // (c2 based) tiered sytem we must do the code below.
   1.446 +#ifndef TIERED
   1.447 +  if (method_data_update()) {
   1.448 +    ciMethodData* md = method()->method_data();
   1.449 +    if (osr_site) {
   1.450 +      ciProfileData* data = md->bci_to_data(cur_bci);
   1.451 +      int limit = (CompileThreshold
   1.452 +                   * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100;
   1.453 +      test_for_osr_md_counter_at(md, data, JumpData::taken_offset(), limit);
   1.454 +    }
   1.455 +  } else {
   1.456 +    // With method data update off, use the invocation counter to trigger an
   1.457 +    // OSR compilation, as done in the interpreter.
   1.458 +    if (osr_site) {
   1.459 +      int limit = (CompileThreshold * OnStackReplacePercentage) / 100;
   1.460 +      increment_and_test_invocation_counter(limit);
   1.461 +    }
   1.462 +  }
   1.463 +#endif // TIERED
   1.464 +
   1.465 +  // Restore the original bytecode.
   1.466 +  set_bci(cur_bci);
   1.467 +}
   1.468 +
   1.469 +//--------------------------profile_not_taken_branch---------------------------
   1.470 +void Parse::profile_not_taken_branch(bool force_update) {
   1.471 +
   1.472 +  if (method_data_update() || force_update) {
   1.473 +    ciMethodData* md = method()->method_data();
   1.474 +    assert(md != NULL, "expected valid ciMethodData");
   1.475 +    ciProfileData* data = md->bci_to_data(bci());
   1.476 +    assert(data->is_BranchData(), "need BranchData for not taken branch");
   1.477 +    increment_md_counter_at(md, data, BranchData::not_taken_offset());
   1.478 +  }
   1.479 +
   1.480 +}
   1.481 +
   1.482 +//---------------------------------profile_call--------------------------------
   1.483 +void Parse::profile_call(Node* receiver) {
   1.484 +  if (!method_data_update()) return;
   1.485 +
   1.486 +  switch (bc()) {
   1.487 +  case Bytecodes::_invokevirtual:
   1.488 +  case Bytecodes::_invokeinterface:
   1.489 +    profile_receiver_type(receiver);
   1.490 +    break;
   1.491 +  case Bytecodes::_invokestatic:
   1.492 +  case Bytecodes::_invokedynamic:
   1.493 +  case Bytecodes::_invokespecial:
   1.494 +    profile_generic_call();
   1.495 +    break;
   1.496 +  default: fatal("unexpected call bytecode");
   1.497 +  }
   1.498 +}
   1.499 +
   1.500 +//------------------------------profile_generic_call---------------------------
   1.501 +void Parse::profile_generic_call() {
   1.502 +  assert(method_data_update(), "must be generating profile code");
   1.503 +
   1.504 +  ciMethodData* md = method()->method_data();
   1.505 +  assert(md != NULL, "expected valid ciMethodData");
   1.506 +  ciProfileData* data = md->bci_to_data(bci());
   1.507 +  assert(data->is_CounterData(), "need CounterData for not taken branch");
   1.508 +  increment_md_counter_at(md, data, CounterData::count_offset());
   1.509 +}
   1.510 +
   1.511 +//-----------------------------profile_receiver_type---------------------------
   1.512 +void Parse::profile_receiver_type(Node* receiver) {
   1.513 +  assert(method_data_update(), "must be generating profile code");
   1.514 +
   1.515 +  ciMethodData* md = method()->method_data();
   1.516 +  assert(md != NULL, "expected valid ciMethodData");
   1.517 +  ciProfileData* data = md->bci_to_data(bci());
   1.518 +  assert(data->is_ReceiverTypeData(), "need ReceiverTypeData here");
   1.519 +
   1.520 +  // Skip if we aren't tracking receivers
   1.521 +  if (TypeProfileWidth < 1) {
   1.522 +    increment_md_counter_at(md, data, CounterData::count_offset());
   1.523 +    return;
   1.524 +  }
   1.525 +  ciReceiverTypeData* rdata = (ciReceiverTypeData*)data->as_ReceiverTypeData();
   1.526 +
   1.527 +  Node* method_data = method_data_addressing(md, rdata, in_ByteSize(0));
   1.528 +
   1.529 +  // Using an adr_type of TypePtr::BOTTOM to work around anti-dep problems.
   1.530 +  // A better solution might be to use TypeRawPtr::BOTTOM with RC_NARROW_MEM.
   1.531 +  make_runtime_call(RC_LEAF, OptoRuntime::profile_receiver_type_Type(),
   1.532 +                    CAST_FROM_FN_PTR(address,
   1.533 +                                     OptoRuntime::profile_receiver_type_C),
   1.534 +                    "profile_receiver_type_C",
   1.535 +                    TypePtr::BOTTOM,
   1.536 +                    method_data, receiver);
   1.537 +}
   1.538 +
   1.539 +//---------------------------------profile_ret---------------------------------
   1.540 +void Parse::profile_ret(int target_bci) {
   1.541 +  if (!method_data_update()) return;
   1.542 +
   1.543 +  // Skip if we aren't tracking ret targets
   1.544 +  if (TypeProfileWidth < 1) return;
   1.545 +
   1.546 +  ciMethodData* md = method()->method_data();
   1.547 +  assert(md != NULL, "expected valid ciMethodData");
   1.548 +  ciProfileData* data = md->bci_to_data(bci());
   1.549 +  assert(data->is_RetData(), "need RetData for ret");
   1.550 +  ciRetData* ret_data = (ciRetData*)data->as_RetData();
   1.551 +
   1.552 +  // Look for the target_bci is already in the table
   1.553 +  uint row;
   1.554 +  bool table_full = true;
   1.555 +  for (row = 0; row < ret_data->row_limit(); row++) {
   1.556 +    int key = ret_data->bci(row);
   1.557 +    table_full &= (key != RetData::no_bci);
   1.558 +    if (key == target_bci) break;
   1.559 +  }
   1.560 +
   1.561 +  if (row >= ret_data->row_limit()) {
   1.562 +    // The target_bci was not found in the table.
   1.563 +    if (!table_full) {
   1.564 +      // XXX: Make slow call to update RetData
   1.565 +    }
   1.566 +    return;
   1.567 +  }
   1.568 +
   1.569 +  // the target_bci is already in the table
   1.570 +  increment_md_counter_at(md, data, RetData::bci_count_offset(row));
   1.571 +}
   1.572 +
   1.573 +//--------------------------profile_null_checkcast----------------------------
   1.574 +void Parse::profile_null_checkcast() {
   1.575 +  // Set the null-seen flag, done in conjunction with the usual null check. We
   1.576 +  // never unset the flag, so this is a one-way switch.
   1.577 +  if (!method_data_update()) return;
   1.578 +
   1.579 +  ciMethodData* md = method()->method_data();
   1.580 +  assert(md != NULL, "expected valid ciMethodData");
   1.581 +  ciProfileData* data = md->bci_to_data(bci());
   1.582 +  assert(data->is_BitData(), "need BitData for checkcast");
   1.583 +  set_md_flag_at(md, data, BitData::null_seen_byte_constant());
   1.584 +}
   1.585 +
   1.586 +//-----------------------------profile_switch_case-----------------------------
   1.587 +void Parse::profile_switch_case(int table_index) {
   1.588 +  if (!method_data_update()) return;
   1.589 +
   1.590 +  ciMethodData* md = method()->method_data();
   1.591 +  assert(md != NULL, "expected valid ciMethodData");
   1.592 +
   1.593 +  ciProfileData* data = md->bci_to_data(bci());
   1.594 +  assert(data->is_MultiBranchData(), "need MultiBranchData for switch case");
   1.595 +  if (table_index >= 0) {
   1.596 +    increment_md_counter_at(md, data, MultiBranchData::case_count_offset(table_index));
   1.597 +  } else {
   1.598 +    increment_md_counter_at(md, data, MultiBranchData::default_count_offset());
   1.599 +  }
   1.600 +}

mercurial