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