hotspot/src/share/vm/opto/macro.cpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 236 9a04268c8eea
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2005-2007 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
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/_macro.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// Replace any references to "oldref" in inputs to "use" with "newref".
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// Returns the number of replacements made.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
int PhaseMacroExpand::replace_input(Node *use, Node *oldref, Node *newref) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  int nreplacements = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  uint req = use->req();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  for (uint j = 0; j < use->len(); j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
    Node *uin = use->in(j);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    if (uin == oldref) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
      if (j < req)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
        use->set_req(j, newref);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
      else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
        use->set_prec(j, newref);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
      nreplacements++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    } else if (j >= req && uin == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  return nreplacements;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
void PhaseMacroExpand::copy_call_debug_info(CallNode *oldcall, CallNode * newcall) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  // Copy debug information and adjust JVMState information
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  uint old_dbg_start = oldcall->tf()->domain()->cnt();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  uint new_dbg_start = newcall->tf()->domain()->cnt();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  int jvms_adj  = new_dbg_start - old_dbg_start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  assert (new_dbg_start == newcall->req(), "argument count mismatch");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  for (uint i = old_dbg_start; i < oldcall->req(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    newcall->add_req(oldcall->in(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  newcall->set_jvms(oldcall->jvms());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  for (JVMState *jvms = newcall->jvms(); jvms != NULL; jvms = jvms->caller()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    jvms->set_map(newcall);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    jvms->set_locoff(jvms->locoff()+jvms_adj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    jvms->set_stkoff(jvms->stkoff()+jvms_adj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    jvms->set_monoff(jvms->monoff()+jvms_adj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    jvms->set_endoff(jvms->endoff()+jvms_adj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
Node* PhaseMacroExpand::opt_iff(Node* region, Node* iff) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  IfNode *opt_iff = transform_later(iff)->as_If();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // Fast path taken; set region slot 2
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  Node *fast_taken = transform_later( new (C, 1) IfFalseNode(opt_iff) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  region->init_req(2,fast_taken); // Capture fast-control
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // Fast path not-taken, i.e. slow path
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  Node *slow_taken = transform_later( new (C, 1) IfTrueNode(opt_iff) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  return slow_taken;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
//--------------------copy_predefined_input_for_runtime_call--------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
void PhaseMacroExpand::copy_predefined_input_for_runtime_call(Node * ctrl, CallNode* oldcall, CallNode* call) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  // Set fixed predefined input arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  call->init_req( TypeFunc::Control, ctrl );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  call->init_req( TypeFunc::I_O    , oldcall->in( TypeFunc::I_O) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  call->init_req( TypeFunc::Memory , oldcall->in( TypeFunc::Memory ) ); // ?????
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  call->init_req( TypeFunc::ReturnAdr, oldcall->in( TypeFunc::ReturnAdr ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  call->init_req( TypeFunc::FramePtr, oldcall->in( TypeFunc::FramePtr ) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
//------------------------------make_slow_call---------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
CallNode* PhaseMacroExpand::make_slow_call(CallNode *oldcall, const TypeFunc* slow_call_type, address slow_call, const char* leaf_name, Node* slow_path, Node* parm0, Node* parm1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  // Slow-path call
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  int size = slow_call_type->domain()->cnt();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
 CallNode *call = leaf_name
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
   ? (CallNode*)new (C, size) CallLeafNode      ( slow_call_type, slow_call, leaf_name, TypeRawPtr::BOTTOM )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
   : (CallNode*)new (C, size) CallStaticJavaNode( slow_call_type, slow_call, OptoRuntime::stub_name(slow_call), oldcall->jvms()->bci(), TypeRawPtr::BOTTOM );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  // Slow path call has no side-effects, uses few values
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  copy_predefined_input_for_runtime_call(slow_path, oldcall, call );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  if (parm0 != NULL)  call->init_req(TypeFunc::Parms+0, parm0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  if (parm1 != NULL)  call->init_req(TypeFunc::Parms+1, parm1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  copy_call_debug_info(oldcall, call);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  call->set_cnt(PROB_UNLIKELY_MAG(4));  // Same effect as RC_UNCOMMON.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  _igvn.hash_delete(oldcall);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  _igvn.subsume_node(oldcall, call);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  transform_later(call);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  return call;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
void PhaseMacroExpand::extract_call_projections(CallNode *call) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  _fallthroughproj = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  _fallthroughcatchproj = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  _ioproj_fallthrough = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  _ioproj_catchall = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  _catchallcatchproj = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  _memproj_fallthrough = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  _memproj_catchall = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  _resproj = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  for (DUIterator_Fast imax, i = call->fast_outs(imax); i < imax; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    ProjNode *pn = call->fast_out(i)->as_Proj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    switch (pn->_con) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      case TypeFunc::Control:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
        // For Control (fallthrough) and I_O (catch_all_index) we have CatchProj -> Catch -> Proj
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
        _fallthroughproj = pn;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
        DUIterator_Fast jmax, j = pn->fast_outs(jmax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
        const Node *cn = pn->fast_out(j);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
        if (cn->is_Catch()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
          ProjNode *cpn = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
          for (DUIterator_Fast kmax, k = cn->fast_outs(kmax); k < kmax; k++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
            cpn = cn->fast_out(k)->as_Proj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
            assert(cpn->is_CatchProj(), "must be a CatchProjNode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
            if (cpn->_con == CatchProjNode::fall_through_index)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
              _fallthroughcatchproj = cpn;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
            else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
              assert(cpn->_con == CatchProjNode::catch_all_index, "must be correct index.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
              _catchallcatchproj = cpn;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      case TypeFunc::I_O:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
        if (pn->_is_io_use)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
          _ioproj_catchall = pn;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
        else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
          _ioproj_fallthrough = pn;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
      case TypeFunc::Memory:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
        if (pn->_is_io_use)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
          _memproj_catchall = pn;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
        else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
          _memproj_fallthrough = pn;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
      case TypeFunc::Parms:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
        _resproj = pn;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
        assert(false, "unexpected projection from allocation node.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
//---------------------------set_eden_pointers-------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
void PhaseMacroExpand::set_eden_pointers(Node* &eden_top_adr, Node* &eden_end_adr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  if (UseTLAB) {                // Private allocation: load from TLS
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    Node* thread = transform_later(new (C, 1) ThreadLocalNode());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    int tlab_top_offset = in_bytes(JavaThread::tlab_top_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    int tlab_end_offset = in_bytes(JavaThread::tlab_end_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    eden_top_adr = basic_plus_adr(top()/*not oop*/, thread, tlab_top_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    eden_end_adr = basic_plus_adr(top()/*not oop*/, thread, tlab_end_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  } else {                      // Shared allocation: load from globals
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    CollectedHeap* ch = Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    address top_adr = (address)ch->top_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    address end_adr = (address)ch->end_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    eden_top_adr = makecon(TypeRawPtr::make(top_adr));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    eden_end_adr = basic_plus_adr(eden_top_adr, end_adr - top_adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
Node* PhaseMacroExpand::make_load(Node* ctl, Node* mem, Node* base, int offset, const Type* value_type, BasicType bt) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  Node* adr = basic_plus_adr(base, offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  const TypePtr* adr_type = TypeRawPtr::BOTTOM;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  Node* value = LoadNode::make(C, ctl, mem, adr, adr_type, value_type, bt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  transform_later(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  return value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
Node* PhaseMacroExpand::make_store(Node* ctl, Node* mem, Node* base, int offset, Node* value, BasicType bt) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  Node* adr = basic_plus_adr(base, offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  mem = StoreNode::make(C, ctl, mem, adr, NULL, value, bt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  transform_later(mem);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  return mem;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
//                              A L L O C A T I O N
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
// Allocation attempts to be fast in the case of frequent small objects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
// It breaks down like this:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
// 1) Size in doublewords is computed.  This is a constant for objects and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
// variable for most arrays.  Doubleword units are used to avoid size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
// overflow of huge doubleword arrays.  We need doublewords in the end for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
// rounding.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
// 2) Size is checked for being 'too large'.  Too-large allocations will go
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
// the slow path into the VM.  The slow path can throw any required
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
// exceptions, and does all the special checks for very large arrays.  The
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
// size test can constant-fold away for objects.  For objects with
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
// finalizers it constant-folds the otherway: you always go slow with
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
// finalizers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
// 3) If NOT using TLABs, this is the contended loop-back point.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
// Load-Locked the heap top.  If using TLABs normal-load the heap top.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
// 4) Check that heap top + size*8 < max.  If we fail go the slow ` route.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
// NOTE: "top+size*8" cannot wrap the 4Gig line!  Here's why: for largish
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
// "size*8" we always enter the VM, where "largish" is a constant picked small
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
// enough that there's always space between the eden max and 4Gig (old space is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
// there so it's quite large) and large enough that the cost of entering the VM
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
// is dwarfed by the cost to initialize the space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
// 5) If NOT using TLABs, Store-Conditional the adjusted heap top back
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
// down.  If contended, repeat at step 3.  If using TLABs normal-store
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
// adjusted heap top back down; there is no contention.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
// 6) If !ZeroTLAB then Bulk-clear the object/array.  Fill in klass & mark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
// fields.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
// 7) Merge with the slow-path; cast the raw memory pointer to the correct
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
// oop flavor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
// FastAllocateSizeLimit value is in DOUBLEWORDS.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
// Allocations bigger than this always go the slow route.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
// This value must be small enough that allocation attempts that need to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
// trigger exceptions go the slow route.  Also, it must be small enough so
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
// that heap_top + size_in_bytes does not wrap around the 4Gig limit.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
//=============================================================================j//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
// %%% Here is an old comment from parseHelper.cpp; is it outdated?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
// The allocator will coalesce int->oop copies away.  See comment in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
// coalesce.cpp about how this works.  It depends critically on the exact
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
// code shape produced here, so if you are changing this code shape
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
// make sure the GC info for the heap-top is correct in and around the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
// slow-path call.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
void PhaseMacroExpand::expand_allocate_common(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
            AllocateNode* alloc, // allocation node to be expanded
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
            Node* length,  // array length for an array allocation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
            const TypeFunc* slow_call_type, // Type of slow call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
            address slow_call_address  // Address of slow call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  Node* ctrl = alloc->in(TypeFunc::Control);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  Node* mem  = alloc->in(TypeFunc::Memory);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  Node* i_o  = alloc->in(TypeFunc::I_O);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  Node* size_in_bytes     = alloc->in(AllocateNode::AllocSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  Node* klass_node        = alloc->in(AllocateNode::KlassNode);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  Node* initial_slow_test = alloc->in(AllocateNode::InitialTest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  Node* eden_top_adr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  Node* eden_end_adr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  set_eden_pointers(eden_top_adr, eden_end_adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  uint raw_idx = C->get_alias_index(TypeRawPtr::BOTTOM);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  assert(ctrl != NULL, "must have control");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  // Load Eden::end.  Loop invariant and hoisted.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  // Note: We set the control input on "eden_end" and "old_eden_top" when using
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  //       a TLAB to work around a bug where these values were being moved across
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  //       a safepoint.  These are not oops, so they cannot be include in the oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  //       map, but the can be changed by a GC.   The proper way to fix this would
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  //       be to set the raw memory state when generating a  SafepointNode.  However
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  //       this will require extensive changes to the loop optimization in order to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  //       prevent a degradation of the optimization.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  //       See comment in memnode.hpp, around line 227 in class LoadPNode.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  Node* eden_end = make_load(ctrl, mem, eden_end_adr, 0, TypeRawPtr::BOTTOM, T_ADDRESS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  // We need a Region and corresponding Phi's to merge the slow-path and fast-path results.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  // they will not be used if "always_slow" is set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  enum { slow_result_path = 1, fast_result_path = 2 };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  Node *result_region;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  Node *result_phi_rawmem;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  Node *result_phi_rawoop;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  Node *result_phi_i_o;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  // The initial slow comparison is a size check, the comparison
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  // we want to do is a BoolTest::gt
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  bool always_slow = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  int tv = _igvn.find_int_con(initial_slow_test, -1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  if (tv >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    always_slow = (tv == 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    initial_slow_test = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    initial_slow_test = BoolNode::make_predicate(initial_slow_test, &_igvn);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  if (DTraceAllocProbes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    // Force slow-path allocation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
    always_slow = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    initial_slow_test = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  enum { too_big_or_final_path = 1, need_gc_path = 2 };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  Node *slow_region = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  Node *toobig_false = ctrl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  assert (initial_slow_test == NULL || !always_slow, "arguments must be consistent");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  // generate the initial test if necessary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  if (initial_slow_test != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    slow_region = new (C, 3) RegionNode(3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    // Now make the initial failure test.  Usually a too-big test but
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
    // might be a TRUE for finalizers or a fancy class check for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    // newInstance0.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
    IfNode *toobig_iff = new (C, 2) IfNode(ctrl, initial_slow_test, PROB_MIN, COUNT_UNKNOWN);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    transform_later(toobig_iff);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    // Plug the failing-too-big test into the slow-path region
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    Node *toobig_true = new (C, 1) IfTrueNode( toobig_iff );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    transform_later(toobig_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
    slow_region    ->init_req( too_big_or_final_path, toobig_true );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    toobig_false = new (C, 1) IfFalseNode( toobig_iff );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    transform_later(toobig_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  } else {         // No initial test, just fall into next case
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
    toobig_false = ctrl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    debug_only(slow_region = NodeSentinel);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  Node *slow_mem = mem;  // save the current memory state for slow path
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  // generate the fast allocation code unless we know that the initial test will always go slow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  if (!always_slow) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    // allocate the Region and Phi nodes for the result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    result_region = new (C, 3) RegionNode(3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    result_phi_rawmem = new (C, 3) PhiNode( result_region, Type::MEMORY, TypeRawPtr::BOTTOM );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    result_phi_rawoop = new (C, 3) PhiNode( result_region, TypeRawPtr::BOTTOM );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    result_phi_i_o    = new (C, 3) PhiNode( result_region, Type::ABIO ); // I/O is used for Prefetch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    // We need a Region for the loop-back contended case.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    enum { fall_in_path = 1, contended_loopback_path = 2 };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    Node *contended_region;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
    Node *contended_phi_rawmem;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
    if( UseTLAB ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
      contended_region = toobig_false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
      contended_phi_rawmem = mem;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
      contended_region = new (C, 3) RegionNode(3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
      contended_phi_rawmem = new (C, 3) PhiNode( contended_region, Type::MEMORY, TypeRawPtr::BOTTOM);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
      // Now handle the passing-too-big test.  We fall into the contended
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
      // loop-back merge point.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
      contended_region    ->init_req( fall_in_path, toobig_false );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
      contended_phi_rawmem->init_req( fall_in_path, mem );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
      transform_later(contended_region);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
      transform_later(contended_phi_rawmem);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
    // Load(-locked) the heap top.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
    // See note above concerning the control input when using a TLAB
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
    Node *old_eden_top = UseTLAB
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
      ? new (C, 3) LoadPNode     ( ctrl, contended_phi_rawmem, eden_top_adr, TypeRawPtr::BOTTOM, TypeRawPtr::BOTTOM )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
      : new (C, 3) LoadPLockedNode( contended_region, contended_phi_rawmem, eden_top_adr );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    transform_later(old_eden_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
    // Add to heap top to get a new heap top
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    Node *new_eden_top = new (C, 4) AddPNode( top(), old_eden_top, size_in_bytes );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    transform_later(new_eden_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    // Check for needing a GC; compare against heap end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
    Node *needgc_cmp = new (C, 3) CmpPNode( new_eden_top, eden_end );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
    transform_later(needgc_cmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    Node *needgc_bol = new (C, 2) BoolNode( needgc_cmp, BoolTest::ge );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    transform_later(needgc_bol);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    IfNode *needgc_iff = new (C, 2) IfNode(contended_region, needgc_bol, PROB_UNLIKELY_MAG(4), COUNT_UNKNOWN );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
    transform_later(needgc_iff);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
    // Plug the failing-heap-space-need-gc test into the slow-path region
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    Node *needgc_true = new (C, 1) IfTrueNode( needgc_iff );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
    transform_later(needgc_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
    if( initial_slow_test ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
      slow_region    ->init_req( need_gc_path, needgc_true );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
      // This completes all paths into the slow merge point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
      transform_later(slow_region);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
    } else {                      // No initial slow path needed!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
      // Just fall from the need-GC path straight into the VM call.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
      slow_region    = needgc_true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    // No need for a GC.  Setup for the Store-Conditional
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
    Node *needgc_false = new (C, 1) IfFalseNode( needgc_iff );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
    transform_later(needgc_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
    // Grab regular I/O before optional prefetch may change it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
    // Slow-path does no I/O so just set it to the original I/O.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    result_phi_i_o->init_req( slow_result_path, i_o );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
    i_o = prefetch_allocation(i_o, needgc_false, contended_phi_rawmem,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
                              old_eden_top, new_eden_top, length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
    // Store (-conditional) the modified eden top back down.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
    // StorePConditional produces flags for a test PLUS a modified raw
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
    // memory state.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
    Node *store_eden_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
    Node *fast_oop_ctrl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
    if( UseTLAB ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
      store_eden_top = new (C, 4) StorePNode( needgc_false, contended_phi_rawmem, eden_top_adr, TypeRawPtr::BOTTOM, new_eden_top );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
      transform_later(store_eden_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
      fast_oop_ctrl = needgc_false; // No contention, so this is the fast path
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
      store_eden_top = new (C, 5) StorePConditionalNode( needgc_false, contended_phi_rawmem, eden_top_adr, new_eden_top, old_eden_top );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
      transform_later(store_eden_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
      Node *contention_check = new (C, 2) BoolNode( store_eden_top, BoolTest::ne );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
      transform_later(contention_check);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
      store_eden_top = new (C, 1) SCMemProjNode(store_eden_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
      transform_later(store_eden_top);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
      // If not using TLABs, check to see if there was contention.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
      IfNode *contention_iff = new (C, 2) IfNode ( needgc_false, contention_check, PROB_MIN, COUNT_UNKNOWN );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
      transform_later(contention_iff);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
      Node *contention_true = new (C, 1) IfTrueNode( contention_iff );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
      transform_later(contention_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
      // If contention, loopback and try again.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
      contended_region->init_req( contended_loopback_path, contention_true );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
      contended_phi_rawmem->init_req( contended_loopback_path, store_eden_top );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
      // Fast-path succeeded with no contention!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
      Node *contention_false = new (C, 1) IfFalseNode( contention_iff );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
      transform_later(contention_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
      fast_oop_ctrl = contention_false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
    // Rename successful fast-path variables to make meaning more obvious
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
    Node* fast_oop        = old_eden_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
    Node* fast_oop_rawmem = store_eden_top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    fast_oop_rawmem = initialize_object(alloc,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
                                        fast_oop_ctrl, fast_oop_rawmem, fast_oop,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
                                        klass_node, length, size_in_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
    if (ExtendedDTraceProbes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
      // Slow-path call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
      int size = TypeFunc::Parms + 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
      CallLeafNode *call = new (C, size) CallLeafNode(OptoRuntime::dtrace_object_alloc_Type(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
                                                      CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc_base),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
                                                      "dtrace_object_alloc",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
                                                      TypeRawPtr::BOTTOM);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
      // Get base of thread-local storage area
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
      Node* thread = new (C, 1) ThreadLocalNode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
      transform_later(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
      call->init_req(TypeFunc::Parms+0, thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
      call->init_req(TypeFunc::Parms+1, fast_oop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
      call->init_req( TypeFunc::Control, fast_oop_ctrl );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
      call->init_req( TypeFunc::I_O    , top() )        ;   // does no i/o
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
      call->init_req( TypeFunc::Memory , fast_oop_rawmem );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
      call->init_req( TypeFunc::ReturnAdr, alloc->in(TypeFunc::ReturnAdr) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
      call->init_req( TypeFunc::FramePtr, alloc->in(TypeFunc::FramePtr) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
      transform_later(call);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
      fast_oop_ctrl = new (C, 1) ProjNode(call,TypeFunc::Control);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
      transform_later(fast_oop_ctrl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
      fast_oop_rawmem = new (C, 1) ProjNode(call,TypeFunc::Memory);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
      transform_later(fast_oop_rawmem);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
    // Plug in the successful fast-path into the result merge point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
    result_region    ->init_req( fast_result_path, fast_oop_ctrl );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
    result_phi_rawoop->init_req( fast_result_path, fast_oop );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
    result_phi_i_o   ->init_req( fast_result_path, i_o );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
    result_phi_rawmem->init_req( fast_result_path, fast_oop_rawmem );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    slow_region = ctrl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  // Generate slow-path call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  CallNode *call = new (C, slow_call_type->domain()->cnt())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
    CallStaticJavaNode(slow_call_type, slow_call_address,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
                       OptoRuntime::stub_name(slow_call_address),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
                       alloc->jvms()->bci(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
                       TypePtr::BOTTOM);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  call->init_req( TypeFunc::Control, slow_region );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  call->init_req( TypeFunc::I_O    , top() )     ;   // does no i/o
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  call->init_req( TypeFunc::Memory , slow_mem ); // may gc ptrs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  call->init_req( TypeFunc::ReturnAdr, alloc->in(TypeFunc::ReturnAdr) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
  call->init_req( TypeFunc::FramePtr, alloc->in(TypeFunc::FramePtr) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  call->init_req(TypeFunc::Parms+0, klass_node);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  if (length != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
    call->init_req(TypeFunc::Parms+1, length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  // Copy debug information and adjust JVMState information, then replace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  // allocate node with the call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  copy_call_debug_info((CallNode *) alloc,  call);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  if (!always_slow) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
    call->set_cnt(PROB_UNLIKELY_MAG(4));  // Same effect as RC_UNCOMMON.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  _igvn.hash_delete(alloc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  _igvn.subsume_node(alloc, call);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
  transform_later(call);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
  // Identify the output projections from the allocate node and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
  // adjust any references to them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
  // The control and io projections look like:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
  //        v---Proj(ctrl) <-----+   v---CatchProj(ctrl)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
  //  Allocate                   Catch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
  //        ^---Proj(io) <-------+   ^---CatchProj(io)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
  //  We are interested in the CatchProj nodes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
  extract_call_projections(call);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  // An allocate node has separate memory projections for the uses on the control and i_o paths
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  // Replace uses of the control memory projection with result_phi_rawmem (unless we are only generating a slow call)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
  if (!always_slow && _memproj_fallthrough != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
    for (DUIterator_Fast imax, i = _memproj_fallthrough->fast_outs(imax); i < imax; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
      Node *use = _memproj_fallthrough->fast_out(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
      _igvn.hash_delete(use);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
      imax -= replace_input(use, _memproj_fallthrough, result_phi_rawmem);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
      _igvn._worklist.push(use);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
      // back up iterator
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
      --i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
  // Now change uses of _memproj_catchall to use _memproj_fallthrough and delete _memproj_catchall so
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
  // we end up with a call that has only 1 memory projection
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
  if (_memproj_catchall != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
    if (_memproj_fallthrough == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
      _memproj_fallthrough = new (C, 1) ProjNode(call, TypeFunc::Memory);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
      transform_later(_memproj_fallthrough);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
    for (DUIterator_Fast imax, i = _memproj_catchall->fast_outs(imax); i < imax; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
      Node *use = _memproj_catchall->fast_out(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
      _igvn.hash_delete(use);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
      imax -= replace_input(use, _memproj_catchall, _memproj_fallthrough);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
      _igvn._worklist.push(use);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
      // back up iterator
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
      --i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
  mem = result_phi_rawmem;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
  // An allocate node has separate i_o projections for the uses on the control and i_o paths
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
  // Replace uses of the control i_o projection with result_phi_i_o (unless we are only generating a slow call)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
  if (_ioproj_fallthrough == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
    _ioproj_fallthrough = new (C, 1) ProjNode(call, TypeFunc::I_O);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
    transform_later(_ioproj_fallthrough);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
  } else if (!always_slow) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
    for (DUIterator_Fast imax, i = _ioproj_fallthrough->fast_outs(imax); i < imax; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
      Node *use = _ioproj_fallthrough->fast_out(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
      _igvn.hash_delete(use);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
      imax -= replace_input(use, _ioproj_fallthrough, result_phi_i_o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
      _igvn._worklist.push(use);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
      // back up iterator
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
      --i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
  // Now change uses of _ioproj_catchall to use _ioproj_fallthrough and delete _ioproj_catchall so
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
  // we end up with a call that has only 1 control projection
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  if (_ioproj_catchall != NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
    for (DUIterator_Fast imax, i = _ioproj_catchall->fast_outs(imax); i < imax; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
      Node *use = _ioproj_catchall->fast_out(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
      _igvn.hash_delete(use);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
      imax -= replace_input(use, _ioproj_catchall, _ioproj_fallthrough);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
      _igvn._worklist.push(use);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
      // back up iterator
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
      --i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  // if we generated only a slow call, we are done
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
  if (always_slow)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
  if (_fallthroughcatchproj != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
    ctrl = _fallthroughcatchproj->clone();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
    transform_later(ctrl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
    _igvn.hash_delete(_fallthroughcatchproj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
    _igvn.subsume_node(_fallthroughcatchproj, result_region);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
    ctrl = top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  Node *slow_result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
  if (_resproj == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
    // no uses of the allocation result
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
    slow_result = top();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
    slow_result = _resproj->clone();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
    transform_later(slow_result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
    _igvn.hash_delete(_resproj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
    _igvn.subsume_node(_resproj, result_phi_rawoop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
  // Plug slow-path into result merge point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
  result_region    ->init_req( slow_result_path, ctrl );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
  result_phi_rawoop->init_req( slow_result_path, slow_result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
  result_phi_rawmem->init_req( slow_result_path, _memproj_fallthrough );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
  transform_later(result_region);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
  transform_later(result_phi_rawoop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  transform_later(result_phi_rawmem);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
  transform_later(result_phi_i_o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
  // This completes all paths into the result merge point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
// Helper for PhaseMacroExpand::expand_allocate_common.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
// Initializes the newly-allocated storage.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
Node*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
PhaseMacroExpand::initialize_object(AllocateNode* alloc,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
                                    Node* control, Node* rawmem, Node* object,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
                                    Node* klass_node, Node* length,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
                                    Node* size_in_bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
  InitializeNode* init = alloc->initialization();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
  // Store the klass & mark bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  Node* mark_node = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
  // For now only enable fast locking for non-array types
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
  if (UseBiasedLocking && (length == NULL)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
    mark_node = make_load(NULL, rawmem, klass_node, Klass::prototype_header_offset_in_bytes() + sizeof(oopDesc), TypeRawPtr::BOTTOM, T_ADDRESS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
    mark_node = makecon(TypeRawPtr::make((address)markOopDesc::prototype()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
  rawmem = make_store(control, rawmem, object, oopDesc::mark_offset_in_bytes(), mark_node, T_ADDRESS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
  rawmem = make_store(control, rawmem, object, oopDesc::klass_offset_in_bytes(), klass_node, T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
  int header_size = alloc->minimum_header_size();  // conservatively small
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
  // Array length
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
  if (length != NULL) {         // Arrays need length field
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
    rawmem = make_store(control, rawmem, object, arrayOopDesc::length_offset_in_bytes(), length, T_INT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
    // conservatively small header size:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
    header_size = sizeof(arrayOopDesc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
    ciKlass* k = _igvn.type(klass_node)->is_klassptr()->klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
    if (k->is_array_klass())    // we know the exact header size in most cases:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
      header_size = Klass::layout_helper_header_size(k->layout_helper());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
  // Clear the object body, if necessary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
  if (init == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
    // The init has somehow disappeared; be cautious and clear everything.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
    // This can happen if a node is allocated but an uncommon trap occurs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
    // immediately.  In this case, the Initialize gets associated with the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
    // trap, and may be placed in a different (outer) loop, if the Allocate
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
    // is in a loop.  If (this is rare) the inner loop gets unrolled, then
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
    // there can be two Allocates to one Initialize.  The answer in all these
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
    // edge cases is safety first.  It is always safe to clear immediately
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
    // within an Allocate, and then (maybe or maybe not) clear some more later.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
    if (!ZeroTLAB)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
      rawmem = ClearArrayNode::clear_memory(control, rawmem, object,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
                                            header_size, size_in_bytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
                                            &_igvn);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
    if (!init->is_complete()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
      // Try to win by zeroing only what the init does not store.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
      // We can also try to do some peephole optimizations,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
      // such as combining some adjacent subword stores.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
      rawmem = init->complete_stores(control, rawmem, object,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
                                     header_size, size_in_bytes, &_igvn);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
    // We have no more use for this link, since the AllocateNode goes away:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
    init->set_req(InitializeNode::RawAddress, top());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
    // (If we keep the link, it just confuses the register allocator,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
    // who thinks he sees a real use of the address by the membar.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
  return rawmem;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
// Generate prefetch instructions for next allocations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
Node* PhaseMacroExpand::prefetch_allocation(Node* i_o, Node*& needgc_false,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
                                        Node*& contended_phi_rawmem,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
                                        Node* old_eden_top, Node* new_eden_top,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
                                        Node* length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
   if( UseTLAB && AllocatePrefetchStyle == 2 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
      // Generate prefetch allocation with watermark check.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
      // As an allocation hits the watermark, we will prefetch starting
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
      // at a "distance" away from watermark.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
      enum { fall_in_path = 1, pf_path = 2 };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
      Node *pf_region = new (C, 3) RegionNode(3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
      Node *pf_phi_rawmem = new (C, 3) PhiNode( pf_region, Type::MEMORY,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
                                                TypeRawPtr::BOTTOM );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
      // I/O is used for Prefetch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
      Node *pf_phi_abio = new (C, 3) PhiNode( pf_region, Type::ABIO );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
      Node *thread = new (C, 1) ThreadLocalNode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
      transform_later(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
      Node *eden_pf_adr = new (C, 4) AddPNode( top()/*not oop*/, thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
                   _igvn.MakeConX(in_bytes(JavaThread::tlab_pf_top_offset())) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
      transform_later(eden_pf_adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
      Node *old_pf_wm = new (C, 3) LoadPNode( needgc_false,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
                                   contended_phi_rawmem, eden_pf_adr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
                                   TypeRawPtr::BOTTOM, TypeRawPtr::BOTTOM );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
      transform_later(old_pf_wm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
      // check against new_eden_top
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
      Node *need_pf_cmp = new (C, 3) CmpPNode( new_eden_top, old_pf_wm );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
      transform_later(need_pf_cmp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
      Node *need_pf_bol = new (C, 2) BoolNode( need_pf_cmp, BoolTest::ge );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
      transform_later(need_pf_bol);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
      IfNode *need_pf_iff = new (C, 2) IfNode( needgc_false, need_pf_bol,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
                                       PROB_UNLIKELY_MAG(4), COUNT_UNKNOWN );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
      transform_later(need_pf_iff);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
      // true node, add prefetchdistance
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
      Node *need_pf_true = new (C, 1) IfTrueNode( need_pf_iff );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
      transform_later(need_pf_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
      Node *need_pf_false = new (C, 1) IfFalseNode( need_pf_iff );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
      transform_later(need_pf_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
      Node *new_pf_wmt = new (C, 4) AddPNode( top(), old_pf_wm,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
                                    _igvn.MakeConX(AllocatePrefetchDistance) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
      transform_later(new_pf_wmt );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
      new_pf_wmt->set_req(0, need_pf_true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
      Node *store_new_wmt = new (C, 4) StorePNode( need_pf_true,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
                                       contended_phi_rawmem, eden_pf_adr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
                                       TypeRawPtr::BOTTOM, new_pf_wmt );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
      transform_later(store_new_wmt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
      // adding prefetches
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
      pf_phi_abio->init_req( fall_in_path, i_o );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
      Node *prefetch_adr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
      Node *prefetch;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
      uint lines = AllocatePrefetchDistance / AllocatePrefetchStepSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
      uint step_size = AllocatePrefetchStepSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
      uint distance = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
      for ( uint i = 0; i < lines; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
        prefetch_adr = new (C, 4) AddPNode( old_pf_wm, new_pf_wmt,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
                                            _igvn.MakeConX(distance) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
        transform_later(prefetch_adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
        prefetch = new (C, 3) PrefetchWriteNode( i_o, prefetch_adr );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
        transform_later(prefetch);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
        distance += step_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
        i_o = prefetch;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
      pf_phi_abio->set_req( pf_path, i_o );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
      pf_region->init_req( fall_in_path, need_pf_false );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
      pf_region->init_req( pf_path, need_pf_true );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
      pf_phi_rawmem->init_req( fall_in_path, contended_phi_rawmem );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
      pf_phi_rawmem->init_req( pf_path, store_new_wmt );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
      transform_later(pf_region);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
      transform_later(pf_phi_rawmem);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
      transform_later(pf_phi_abio);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
      needgc_false = pf_region;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
      contended_phi_rawmem = pf_phi_rawmem;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
      i_o = pf_phi_abio;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
   } else if( AllocatePrefetchStyle > 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
      // Insert a prefetch for each allocation only on the fast-path
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
      Node *prefetch_adr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
      Node *prefetch;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
      // Generate several prefetch instructions only for arrays.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
      uint lines = (length != NULL) ? AllocatePrefetchLines : 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
      uint step_size = AllocatePrefetchStepSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
      uint distance = AllocatePrefetchDistance;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
      for ( uint i = 0; i < lines; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
        prefetch_adr = new (C, 4) AddPNode( old_eden_top, new_eden_top,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
                                            _igvn.MakeConX(distance) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
        transform_later(prefetch_adr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
        prefetch = new (C, 3) PrefetchWriteNode( i_o, prefetch_adr );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
        // Do not let it float too high, since if eden_top == eden_end,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
        // both might be null.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
        if( i == 0 ) { // Set control for first prefetch, next follows it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
          prefetch->init_req(0, needgc_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
        transform_later(prefetch);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
        distance += step_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
        i_o = prefetch;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
   return i_o;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
void PhaseMacroExpand::expand_allocate(AllocateNode *alloc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
  expand_allocate_common(alloc, NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
                         OptoRuntime::new_instance_Type(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
                         OptoRuntime::new_instance_Java());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
void PhaseMacroExpand::expand_allocate_array(AllocateArrayNode *alloc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
  Node* length = alloc->in(AllocateNode::ALength);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
  expand_allocate_common(alloc, length,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
                         OptoRuntime::new_array_Type(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
                         OptoRuntime::new_array_Java());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
// we have determined that this lock/unlock can be eliminated, we simply
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
// eliminate the node without expanding it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
// Note:  The membar's associated with the lock/unlock are currently not
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
//        eliminated.  This should be investigated as a future enhancement.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
void PhaseMacroExpand::eliminate_locking_node(AbstractLockNode *alock) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
  Node* mem = alock->in(TypeFunc::Memory);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
  // The memory projection from a lock/unlock is RawMem
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
  // The input to a Lock is merged memory, so extract its RawMem input
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
  // (unless the MergeMem has been optimized away.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
  if (alock->is_Lock()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
    if (mem->is_MergeMem())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
      mem = mem->as_MergeMem()->in(Compile::AliasIdxRaw);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
  extract_call_projections(alock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
  // There are 2 projections from the lock.  The lock node will
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
  // be deleted when its last use is subsumed below.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
  assert(alock->outcnt() == 2 && _fallthroughproj != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
          _memproj_fallthrough != NULL, "Unexpected projections from Lock/Unlock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
  _igvn.hash_delete(_fallthroughproj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
  _igvn.subsume_node(_fallthroughproj, alock->in(TypeFunc::Control));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
  _igvn.hash_delete(_memproj_fallthrough);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
  _igvn.subsume_node(_memproj_fallthrough, mem);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
  return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
//------------------------------expand_lock_node----------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
void PhaseMacroExpand::expand_lock_node(LockNode *lock) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
  Node* ctrl = lock->in(TypeFunc::Control);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
  Node* mem = lock->in(TypeFunc::Memory);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
  Node* obj = lock->obj_node();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
  Node* box = lock->box_node();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
  Node *flock = lock->fastlock_node();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
  if (lock->is_eliminated()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
    eliminate_locking_node(lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
  // Make the merge point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
  Node *region = new (C, 3) RegionNode(3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
  Node *bol = transform_later(new (C, 2) BoolNode(flock,BoolTest::ne));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
  Node *iff = new (C, 2) IfNode( ctrl, bol, PROB_MIN, COUNT_UNKNOWN );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
  // Optimize test; set region slot 2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
  Node *slow_path = opt_iff(region,iff);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
  // Make slow path call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
  CallNode *call = make_slow_call( (CallNode *) lock, OptoRuntime::complete_monitor_enter_Type(), OptoRuntime::complete_monitor_locking_Java(), NULL, slow_path, obj, box );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
  extract_call_projections(call);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
  // Slow path can only throw asynchronous exceptions, which are always
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
  // de-opted.  So the compiler thinks the slow-call can never throw an
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
  // exception.  If it DOES throw an exception we would need the debug
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
  // info removed first (since if it throws there is no monitor).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
  assert ( _ioproj_fallthrough == NULL && _ioproj_catchall == NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
           _memproj_catchall == NULL && _catchallcatchproj == NULL, "Unexpected projection from Lock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
  // Capture slow path
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
  // disconnect fall-through projection from call and create a new one
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
  // hook up users of fall-through projection to region
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
  Node *slow_ctrl = _fallthroughproj->clone();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
  transform_later(slow_ctrl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
  _igvn.hash_delete(_fallthroughproj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
  _fallthroughproj->disconnect_inputs(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
  region->init_req(1, slow_ctrl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
  // region inputs are now complete
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
  transform_later(region);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
  _igvn.subsume_node(_fallthroughproj, region);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
  // create a Phi for the memory state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
  Node *mem_phi = new (C, 3) PhiNode( region, Type::MEMORY, TypeRawPtr::BOTTOM);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
  Node *memproj = transform_later( new (C, 1) ProjNode(call, TypeFunc::Memory) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
  mem_phi->init_req(1, memproj );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
  mem_phi->init_req(2, mem);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
  transform_later(mem_phi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
    _igvn.hash_delete(_memproj_fallthrough);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
  _igvn.subsume_node(_memproj_fallthrough, mem_phi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
//------------------------------expand_unlock_node----------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
void PhaseMacroExpand::expand_unlock_node(UnlockNode *unlock) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
  Node *ctrl = unlock->in(TypeFunc::Control);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
  Node* mem = unlock->in(TypeFunc::Memory);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
  Node* obj = unlock->obj_node();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
  Node* box = unlock->box_node();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
  if (unlock->is_eliminated()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
    eliminate_locking_node(unlock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
  // No need for a null check on unlock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
  // Make the merge point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
  RegionNode *region = new (C, 3) RegionNode(3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
  FastUnlockNode *funlock = new (C, 3) FastUnlockNode( ctrl, obj, box );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
  funlock = transform_later( funlock )->as_FastUnlock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
  Node *bol = transform_later(new (C, 2) BoolNode(funlock,BoolTest::ne));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
  Node *iff = new (C, 2) IfNode( ctrl, bol, PROB_MIN, COUNT_UNKNOWN );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
  // Optimize test; set region slot 2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
  Node *slow_path = opt_iff(region,iff);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
  CallNode *call = make_slow_call( (CallNode *) unlock, OptoRuntime::complete_monitor_exit_Type(), CAST_FROM_FN_PTR(address, SharedRuntime::complete_monitor_unlocking_C), "complete_monitor_unlocking_C", slow_path, obj, box );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
  extract_call_projections(call);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
  assert ( _ioproj_fallthrough == NULL && _ioproj_catchall == NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
           _memproj_catchall == NULL && _catchallcatchproj == NULL, "Unexpected projection from Lock");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
  // No exceptions for unlocking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
  // Capture slow path
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
  // disconnect fall-through projection from call and create a new one
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
  // hook up users of fall-through projection to region
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
  Node *slow_ctrl = _fallthroughproj->clone();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
  transform_later(slow_ctrl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
  _igvn.hash_delete(_fallthroughproj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
  _fallthroughproj->disconnect_inputs(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
  region->init_req(1, slow_ctrl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
  // region inputs are now complete
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
  transform_later(region);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
  _igvn.subsume_node(_fallthroughproj, region);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
  // create a Phi for the memory state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
  Node *mem_phi = new (C, 3) PhiNode( region, Type::MEMORY, TypeRawPtr::BOTTOM);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
  Node *memproj = transform_later( new(C, 1) ProjNode(call, TypeFunc::Memory) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
  mem_phi->init_req(1, memproj );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
  mem_phi->init_req(2, mem);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
  transform_later(mem_phi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
    _igvn.hash_delete(_memproj_fallthrough);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
  _igvn.subsume_node(_memproj_fallthrough, mem_phi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
//------------------------------expand_macro_nodes----------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
//  Returns true if a failure occurred.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
bool PhaseMacroExpand::expand_macro_nodes() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
  if (C->macro_count() == 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
  // Make sure expansion will not cause node limit to be exceeded.  Worst case is a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
  // macro node gets expanded into about 50 nodes.  Allow 50% more for optimization
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
  if (C->check_node_count(C->macro_count() * 75, "out of nodes before macro expansion" ) )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
  // expand "macro" nodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
  // nodes are removed from the macro list as they are processed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
  while (C->macro_count() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
    Node * n = C->macro_node(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
    assert(n->is_macro(), "only macro nodes expected here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
    if (_igvn.type(n) == Type::TOP || n->in(0)->is_top() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
      // node is unreachable, so don't try to expand it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
      C->remove_macro_node(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
    switch (n->class_id()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
    case Node::Class_Allocate:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
      expand_allocate(n->as_Allocate());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
    case Node::Class_AllocateArray:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
      expand_allocate_array(n->as_AllocateArray());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
    case Node::Class_Lock:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
      expand_lock_node(n->as_Lock());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
    case Node::Class_Unlock:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
      expand_unlock_node(n->as_Unlock());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
      assert(false, "unknown node type in macro list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
    if (C->failing())  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
  _igvn.optimize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
}