hotspot/src/share/vm/opto/multnode.cpp
author kvn
Tue, 26 Jun 2012 09:06:16 -0700
changeset 13111 e8a578a9b20a
parent 7397 5b173b4ca846
child 13728 882756847a04
permissions -rw-r--r--
7179138: Incorrect result with String concatenation optimization Summary: check for and skip diamond shaped NULL check code for the result of toString() Reviewed-by: twisti, roland
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
     2
 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "opto/matcher.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "opto/multnode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "opto/opcodes.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "opto/phaseX.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "opto/regmask.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "opto/type.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
//------------------------------MultiNode--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
const RegMask &MultiNode::out_RegMask() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  return RegMask::Empty;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
Node *MultiNode::match( const ProjNode *proj, const Matcher *m ) { return proj->clone(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
//------------------------------proj_out---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// Get a named projection
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
ProjNode* MultiNode::proj_out(uint which_proj) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  assert(Opcode() != Op_If || which_proj == (uint)true || which_proj == (uint)false, "must be 1 or 0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  assert(Opcode() != Op_If || outcnt() == 2, "bad if #1");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  for( DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    Node *p = fast_out(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    if( !p->is_Proj() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
      assert(p == this && this->is_Start(), "else must be proj");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    ProjNode *proj = p->as_Proj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    if( proj->_con == which_proj ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
      assert(Opcode() != Op_If || proj->Opcode() == (which_proj?Op_IfTrue:Op_IfFalse), "bad if #2");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
      return proj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
//=============================================================================
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
//------------------------------ProjNode---------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
uint ProjNode::hash() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // only one input
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  return (uintptr_t)in(TypeFunc::Control) + (_con << 1) + (_is_io_use ? 1 : 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
uint ProjNode::cmp( const Node &n ) const { return _con == ((ProjNode&)n)._con && ((ProjNode&)n)._is_io_use == _is_io_use; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
uint ProjNode::size_of() const { return sizeof(ProjNode); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
// Test if we propagate interesting control along this projection
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
bool ProjNode::is_CFG() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  Node *def = in(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  return (_con == TypeFunc::Control && def->is_CFG());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
const Type *ProjNode::bottom_type() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  if (in(0) == NULL)  return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  const Type *tb = in(0)->bottom_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  if( tb == Type::TOP ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  if( tb == Type::BOTTOM ) return Type::BOTTOM;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  const TypeTuple *t = tb->is_tuple();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  return t->field_at(_con);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
const TypePtr *ProjNode::adr_type() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  if (bottom_type() == Type::MEMORY) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    // in(0) might be a narrow MemBar; otherwise we will report TypePtr::BOTTOM
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    const TypePtr* adr_type = in(0)->adr_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    if (!is_error_reported() && !Node::in_dump())
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
      assert(adr_type != NULL, "source must have adr_type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    return adr_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  assert(bottom_type()->base() != Type::Memory, "no other memories?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
bool ProjNode::pinned() const { return in(0)->pinned(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
void ProjNode::dump_spec(outputStream *st) const { st->print("#%d",_con); if(_is_io_use) st->print(" (i_o_use)");}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
//----------------------------check_con----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
void ProjNode::check_con() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  Node* n = in(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  if (n == NULL)       return;  // should be assert, but NodeHash makes bogons
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  if (n->is_Mach())    return;  // mach. projs. are not type-safe
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  if (n->is_Start())   return;  // alas, starts can have mach. projs. also
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  if (_con == SCMemProjNode::SCMEMPROJCON ) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  const Type* t = n->bottom_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  if (t == Type::TOP)  return;  // multi is dead
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  assert(_con < t->is_tuple()->cnt(), "ProjNode::_con must be in range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
//------------------------------Value------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
const Type *ProjNode::Value( PhaseTransform *phase ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  if( !in(0) ) return Type::TOP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  const Type *t = phase->type(in(0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  if( t == Type::TOP ) return t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  if( t == Type::BOTTOM ) return t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  return t->is_tuple()->field_at(_con);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
//------------------------------out_RegMask------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
// Pass the buck uphill
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
const RegMask &ProjNode::out_RegMask() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  return RegMask::Empty;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
//------------------------------ideal_reg--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
uint ProjNode::ideal_reg() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  return Matcher::base2reg[bottom_type()->base()];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
}