hotspot/src/share/vm/c1/c1_Instruction.cpp
author never
Tue, 18 May 2010 13:45:03 -0700
changeset 5535 a747f18b3d7e
parent 5046 27e801a857cb
child 5547 f4b087cbb361
permissions -rw-r--r--
6953539: after 6892658 c1 reports that it doesn't inline StringBuffer.append Reviewed-by: kvn, twisti
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5046
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 1
diff changeset
     2
 * Copyright 1999-2010 Sun Microsystems, Inc.  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
 *
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/_c1_Instruction.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
// Implementation of Instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
int Instruction::_next_id = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
void Instruction::create_hi_word() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  assert(type()->is_double_word() && _hi_word == NULL, "only double word has high word");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  _hi_word = new HiWord(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
Instruction::Condition Instruction::mirror(Condition cond) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  switch (cond) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    case eql: return eql;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    case neq: return neq;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    case lss: return gtr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    case leq: return geq;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    case gtr: return lss;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    case geq: return leq;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  return eql;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
Instruction::Condition Instruction::negate(Condition cond) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  switch (cond) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    case eql: return neq;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    case neq: return eql;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    case lss: return geq;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    case leq: return gtr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    case gtr: return leq;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    case geq: return lss;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  return eql;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
Instruction* Instruction::prev(BlockBegin* block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  Instruction* p = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  Instruction* q = block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  while (q != this) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    assert(q != NULL, "this is not in the block's instruction list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    p = q; q = q->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  return p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
void Instruction::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  InstructionPrinter ip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  print(ip);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
void Instruction::print_line() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  InstructionPrinter ip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  ip.print_line(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
void Instruction::print(InstructionPrinter& ip) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  ip.print_head();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  ip.print_line(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
#endif // PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
// perform constant and interval tests on index value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
bool AccessIndexed::compute_needs_range_check() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  Constant* clength = length()->as_Constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  Constant* cindex = index()->as_Constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  if (clength && cindex) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    IntConstant* l = clength->type()->as_IntConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    IntConstant* i = cindex->type()->as_IntConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    if (l && i && i->value() < l->value() && i->value() >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
ciType* LoadIndexed::exact_type() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  ciType* array_type = array()->exact_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  if (array_type == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  assert(array_type->is_array_klass(), "what else?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  ciArrayKlass* ak = (ciArrayKlass*)array_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  if (ak->element_type()->is_instance_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    ciInstanceKlass* ik = (ciInstanceKlass*)ak->element_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    if (ik->is_loaded() && ik->is_final()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
      return ik;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
ciType* LoadIndexed::declared_type() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  ciType* array_type = array()->declared_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  if (array_type == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  assert(array_type->is_array_klass(), "what else?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  ciArrayKlass* ak = (ciArrayKlass*)array_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  return ak->element_type();
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
ciType* LoadField::declared_type() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  return field()->type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
ciType* LoadField::exact_type() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  ciType* type = declared_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  // for primitive arrays, the declared type is the exact type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  if (type->is_type_array_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    return type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  if (type->is_instance_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    ciInstanceKlass* ik = (ciInstanceKlass*)type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    if (ik->is_loaded() && ik->is_final()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
      return type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
ciType* NewTypeArray::exact_type() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  return ciTypeArrayKlass::make(elt_type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
ciType* NewObjectArray::exact_type() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  return ciObjArrayKlass::make(klass());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
ciType* NewInstance::exact_type() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  return klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
ciType* CheckCast::declared_type() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  return klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
ciType* CheckCast::exact_type() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  if (klass()->is_instance_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    ciInstanceKlass* ik = (ciInstanceKlass*)klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    if (ik->is_loaded() && ik->is_final()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
      return ik;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
void ArithmeticOp::other_values_do(void f(Value*)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  if (lock_stack() != NULL) lock_stack()->values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
void NullCheck::other_values_do(void f(Value*)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  lock_stack()->values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
void AccessArray::other_values_do(void f(Value*)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  if (lock_stack() != NULL) lock_stack()->values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
// Implementation of AccessField
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
void AccessField::other_values_do(void f(Value*)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  if (state_before() != NULL) state_before()->values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  if (lock_stack() != NULL) lock_stack()->values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
// Implementation of StoreIndexed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
IRScope* StoreIndexed::scope() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  return lock_stack()->scope();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
// Implementation of ArithmeticOp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
bool ArithmeticOp::is_commutative() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  switch (op()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    case Bytecodes::_iadd: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    case Bytecodes::_ladd: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    case Bytecodes::_fadd: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    case Bytecodes::_dadd: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    case Bytecodes::_imul: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    case Bytecodes::_lmul: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    case Bytecodes::_fmul: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    case Bytecodes::_dmul: return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
bool ArithmeticOp::can_trap() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  switch (op()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    case Bytecodes::_idiv: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    case Bytecodes::_ldiv: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    case Bytecodes::_irem: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    case Bytecodes::_lrem: return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
// Implementation of LogicOp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
bool LogicOp::is_commutative() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  switch (op()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    case Bytecodes::_iand: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    case Bytecodes::_land: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    case Bytecodes::_ior : // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    case Bytecodes::_lor : // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    case Bytecodes::_ixor: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    case Bytecodes::_lxor: break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    default              : ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  // all LogicOps are commutative
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
// Implementation of CompareOp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
void CompareOp::other_values_do(void f(Value*)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  if (state_before() != NULL) state_before()->values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
// Implementation of IfOp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
bool IfOp::is_commutative() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  return cond() == eql || cond() == neq;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
// Implementation of StateSplit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
void StateSplit::substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  NOT_PRODUCT(bool assigned = false;)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  for (int i = 0; i < list.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    BlockBegin** b = list.adr_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
    if (*b == old_block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
      *b = new_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
      NOT_PRODUCT(assigned = true;)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  assert(assigned == true, "should have assigned at least once");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
IRScope* StateSplit::scope() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  return _state->scope();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
void StateSplit::state_values_do(void f(Value*)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  if (state() != NULL) state()->values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
void BlockBegin::state_values_do(void f(Value*)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  StateSplit::state_values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  if (is_set(BlockBegin::exception_entry_flag)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    for (int i = 0; i < number_of_exception_states(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
      exception_state_at(i)->values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
void MonitorEnter::state_values_do(void f(Value*)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  StateSplit::state_values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  _lock_stack_before->values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
void Intrinsic::state_values_do(void f(Value*)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  StateSplit::state_values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  if (lock_stack() != NULL) lock_stack()->values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
// Implementation of Invoke
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
Invoke::Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
5046
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 1
diff changeset
   337
               int vtable_index, ciMethod* target, ValueStack* state_before)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  : StateSplit(result_type)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  , _code(code)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  , _recv(recv)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  , _args(args)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  , _vtable_index(vtable_index)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  , _target(target)
5046
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 1
diff changeset
   344
  , _state_before(state_before)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  set_flag(TargetIsLoadedFlag,   target->is_loaded());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  set_flag(TargetIsFinalFlag,    target_is_loaded() && target->is_final_method());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  set_flag(TargetIsStrictfpFlag, target_is_loaded() && target->is_strict());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  assert(args != NULL, "args must exist");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  values_do(assert_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  // provide an initial guess of signature size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  _signature = new BasicTypeList(number_of_arguments() + (has_receiver() ? 1 : 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  if (has_receiver()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    _signature->append(as_BasicType(receiver()->type()));
5046
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 1
diff changeset
   359
  } else if (is_invokedynamic()) {
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 1
diff changeset
   360
    // Add the synthetic MethodHandle argument to the signature.
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 1
diff changeset
   361
    _signature->append(T_OBJECT);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  for (int i = 0; i < number_of_arguments(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    ValueType* t = argument_at(i)->type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    BasicType bt = as_BasicType(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
    _signature->append(bt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
5046
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 1
diff changeset
   371
void Invoke::state_values_do(void f(Value*)) {
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 1
diff changeset
   372
  StateSplit::state_values_do(f);
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 1
diff changeset
   373
  if (state_before() != NULL) state_before()->values_do(f);
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 1
diff changeset
   374
  if (state()        != NULL) state()->values_do(f);
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 1
diff changeset
   375
}
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 1
diff changeset
   376
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 1
diff changeset
   377
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
// Implementation of Contant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
intx Constant::hash() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  if (_state == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
    switch (type()->tag()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    case intTag:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
      return HASH2(name(), type()->as_IntConstant()->value());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    case longTag:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
        jlong temp = type()->as_LongConstant()->value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
        return HASH3(name(), high(temp), low(temp));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
    case floatTag:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
      return HASH2(name(), jint_cast(type()->as_FloatConstant()->value()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
    case doubleTag:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
        jlong temp = jlong_cast(type()->as_DoubleConstant()->value());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
        return HASH3(name(), high(temp), low(temp));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    case objectTag:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
      assert(type()->as_ObjectType()->is_loaded(), "can't handle unloaded values");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
      return HASH2(name(), type()->as_ObjectType()->constant_value());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
bool Constant::is_equal(Value v) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  if (v->as_Constant() == NULL) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  switch (type()->tag()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
    case intTag:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
        IntConstant* t1 =    type()->as_IntConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
        IntConstant* t2 = v->type()->as_IntConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
        return (t1 != NULL && t2 != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
                t1->value() == t2->value());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    case longTag:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
        LongConstant* t1 =    type()->as_LongConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
        LongConstant* t2 = v->type()->as_LongConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
        return (t1 != NULL && t2 != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
                t1->value() == t2->value());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
    case floatTag:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
        FloatConstant* t1 =    type()->as_FloatConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
        FloatConstant* t2 = v->type()->as_FloatConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
        return (t1 != NULL && t2 != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
                jint_cast(t1->value()) == jint_cast(t2->value()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
    case doubleTag:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
        DoubleConstant* t1 =    type()->as_DoubleConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
        DoubleConstant* t2 = v->type()->as_DoubleConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
        return (t1 != NULL && t2 != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
                jlong_cast(t1->value()) == jlong_cast(t2->value()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
    case objectTag:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
        ObjectType* t1 =    type()->as_ObjectType();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
        ObjectType* t2 = v->type()->as_ObjectType();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
        return (t1 != NULL && t2 != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
                t1->is_loaded() && t2->is_loaded() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
                t1->constant_value() == t2->constant_value());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
BlockBegin* Constant::compare(Instruction::Condition cond, Value right,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
                              BlockBegin* true_sux, BlockBegin* false_sux) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  Constant* rc = right->as_Constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  // other is not a constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  if (rc == NULL) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  ValueType* lt = type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  ValueType* rt = rc->type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  // different types
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  if (lt->base() != rt->base()) return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  switch (lt->tag()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  case intTag: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
    int x = lt->as_IntConstant()->value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
    int y = rt->as_IntConstant()->value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
    switch (cond) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    case If::eql: return x == y ? true_sux : false_sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
    case If::neq: return x != y ? true_sux : false_sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
    case If::lss: return x <  y ? true_sux : false_sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
    case If::leq: return x <= y ? true_sux : false_sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
    case If::gtr: return x >  y ? true_sux : false_sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    case If::geq: return x >= y ? true_sux : false_sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  case longTag: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
    jlong x = lt->as_LongConstant()->value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
    jlong y = rt->as_LongConstant()->value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
    switch (cond) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
    case If::eql: return x == y ? true_sux : false_sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
    case If::neq: return x != y ? true_sux : false_sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
    case If::lss: return x <  y ? true_sux : false_sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    case If::leq: return x <= y ? true_sux : false_sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
    case If::gtr: return x >  y ? true_sux : false_sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    case If::geq: return x >= y ? true_sux : false_sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  case objectTag: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    ciObject* xvalue = lt->as_ObjectType()->constant_value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
    ciObject* yvalue = rt->as_ObjectType()->constant_value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
    assert(xvalue != NULL && yvalue != NULL, "not constants");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    if (xvalue->is_loaded() && yvalue->is_loaded()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
      switch (cond) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
      case If::eql: return xvalue == yvalue ? true_sux : false_sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
      case If::neq: return xvalue != yvalue ? true_sux : false_sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
void Constant::other_values_do(void f(Value*)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  if (state() != NULL) state()->values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
// Implementation of NewArray
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
void NewArray::other_values_do(void f(Value*)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
  if (state_before() != NULL) state_before()->values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
// Implementation of TypeCheck
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
void TypeCheck::other_values_do(void f(Value*)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
  if (state_before() != NULL) state_before()->values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
// Implementation of BlockBegin
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
int BlockBegin::_next_block_id = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
void BlockBegin::set_end(BlockEnd* end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  assert(end != NULL, "should not reset block end to NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
  BlockEnd* old_end = _end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
  if (end == old_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  // Must make the predecessors/successors match up with the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
  // BlockEnd's notion.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
  int i, n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
  if (old_end != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
    // disconnect from the old end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
    old_end->set_begin(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
    // disconnect this block from it's current successors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
    for (i = 0; i < _successors.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
      _successors.at(i)->remove_predecessor(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
  _end = end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
  _successors.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
  // Now reset successors list based on BlockEnd
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
  n = end->number_of_sux();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
  for (i = 0; i < n; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
    BlockBegin* sux = end->sux_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
    _successors.append(sux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
    sux->_predecessors.append(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
  _end->set_begin(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
void BlockBegin::disconnect_edge(BlockBegin* from, BlockBegin* to) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
  // disconnect any edges between from and to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  if (PrintIR && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
    tty->print_cr("Disconnected edge B%d -> B%d", from->block_id(), to->block_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
  for (int s = 0; s < from->number_of_sux();) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
    BlockBegin* sux = from->sux_at(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
    if (sux == to) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
      int index = sux->_predecessors.index_of(from);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
      if (index >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
        sux->_predecessors.remove_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
      from->_successors.remove_at(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
      s++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
void BlockBegin::disconnect_from_graph() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  // disconnect this block from all other blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
  for (int p = 0; p < number_of_preds(); p++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
    pred_at(p)->remove_successor(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
  for (int s = 0; s < number_of_sux(); s++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
    sux_at(s)->remove_predecessor(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
void BlockBegin::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  // modify predecessors before substituting successors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
  for (int i = 0; i < number_of_sux(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
    if (sux_at(i) == old_sux) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
      // remove old predecessor before adding new predecessor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
      // otherwise there is a dead predecessor in the list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
      new_sux->remove_predecessor(old_sux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
      new_sux->add_predecessor(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
  old_sux->remove_predecessor(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
  end()->substitute_sux(old_sux, new_sux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
// In general it is not possible to calculate a value for the field "depth_first_number"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
// of the inserted block, without recomputing the values of the other blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
// in the CFG. Therefore the value of "depth_first_number" in BlockBegin becomes meaningless.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
BlockBegin* BlockBegin::insert_block_between(BlockBegin* sux) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
  // Try to make the bci close to a block with a single pred or sux,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  // since this make the block layout algorithm work better.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
  int bci = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
  if (sux->number_of_preds() == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
    bci = sux->bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
    bci = end()->bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
  BlockBegin* new_sux = new BlockBegin(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
  // mark this block (special treatment when block order is computed)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
  new_sux->set(critical_edge_split_flag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
  // This goto is not a safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
  Goto* e = new Goto(sux, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  new_sux->set_next(e, bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
  new_sux->set_end(e);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
  // setup states
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
  ValueStack* s = end()->state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
  new_sux->set_state(s->copy());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
  e->set_state(s->copy());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  assert(new_sux->state()->locals_size() == s->locals_size(), "local size mismatch!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
  assert(new_sux->state()->stack_size() == s->stack_size(), "stack size mismatch!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
  assert(new_sux->state()->locks_size() == s->locks_size(), "locks size mismatch!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
  // link predecessor to new block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
  end()->substitute_sux(sux, new_sux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
  // The ordering needs to be the same, so remove the link that the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
  // set_end call above added and substitute the new_sux for this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
  // block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
  sux->remove_predecessor(new_sux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
  // the successor could be the target of a switch so it might have
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
  // multiple copies of this predecessor, so substitute the new_sux
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
  // for the first and delete the rest.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
  bool assigned = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
  BlockList& list = sux->_predecessors;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
  for (int i = 0; i < list.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
    BlockBegin** b = list.adr_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
    if (*b == this) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
      if (assigned) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
        list.remove_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
        // reprocess this index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
        i--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
        assigned = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
        *b = new_sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
      // link the new block back to it's predecessors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
      new_sux->add_predecessor(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
  assert(assigned == true, "should have assigned at least once");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
  return new_sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
void BlockBegin::remove_successor(BlockBegin* pred) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
  int idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
  while ((idx = _successors.index_of(pred)) >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
    _successors.remove_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
void BlockBegin::add_predecessor(BlockBegin* pred) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
  _predecessors.append(pred);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
void BlockBegin::remove_predecessor(BlockBegin* pred) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
  int idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
  while ((idx = _predecessors.index_of(pred)) >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
    _predecessors.remove_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
void BlockBegin::add_exception_handler(BlockBegin* b) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
  assert(b != NULL && (b->is_set(exception_entry_flag)), "exception handler must exist");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
  // add only if not in the list already
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
  if (!_exception_handlers.contains(b)) _exception_handlers.append(b);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
int BlockBegin::add_exception_state(ValueStack* state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
  assert(is_set(exception_entry_flag), "only for xhandlers");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
  if (_exception_states == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
    _exception_states = new ValueStackStack(4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
  _exception_states->append(state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
  return _exception_states->length() - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
void BlockBegin::iterate_preorder(boolArray& mark, BlockClosure* closure) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
  if (!mark.at(block_id())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
    mark.at_put(block_id(), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
    closure->block_do(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
    BlockEnd* e = end(); // must do this after block_do because block_do may change it!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
    { for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_preorder(mark, closure); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
    { for (int i = e->number_of_sux            () - 1; i >= 0; i--) e->sux_at           (i)->iterate_preorder(mark, closure); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
void BlockBegin::iterate_postorder(boolArray& mark, BlockClosure* closure) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
  if (!mark.at(block_id())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
    mark.at_put(block_id(), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
    BlockEnd* e = end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
    { for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_postorder(mark, closure); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
    { for (int i = e->number_of_sux            () - 1; i >= 0; i--) e->sux_at           (i)->iterate_postorder(mark, closure); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
    closure->block_do(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
void BlockBegin::iterate_preorder(BlockClosure* closure) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
  boolArray mark(number_of_blocks(), false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
  iterate_preorder(mark, closure);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
void BlockBegin::iterate_postorder(BlockClosure* closure) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
  boolArray mark(number_of_blocks(), false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
  iterate_postorder(mark, closure);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
void BlockBegin::block_values_do(void f(Value*)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
  for (Instruction* n = this; n != NULL; n = n->next()) n->values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
  #define TRACE_PHI(code) if (PrintPhiFunctions) { code; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
  #define TRACE_PHI(coce)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
bool BlockBegin::try_merge(ValueStack* new_state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
  TRACE_PHI(tty->print_cr("********** try_merge for block B%d", block_id()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
  // local variables used for state iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
  int index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
  Value new_value, existing_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
  ValueStack* existing_state = state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
  if (existing_state == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
    TRACE_PHI(tty->print_cr("first call of try_merge for this block"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
    if (is_set(BlockBegin::was_visited_flag)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
      // this actually happens for complicated jsr/ret structures
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
      return false; // BAILOUT in caller
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
    // copy state because it is altered
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
    new_state = new_state->copy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
    // Use method liveness to invalidate dead locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
    MethodLivenessResult liveness = new_state->scope()->method()->liveness_at_bci(bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
    if (liveness.is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
      assert((int)liveness.size() == new_state->locals_size(), "error in use of liveness");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
      for_each_local_value(new_state, index, new_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
        if (!liveness.at(index) || new_value->type()->is_illegal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
          new_state->invalidate_local(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
          TRACE_PHI(tty->print_cr("invalidating dead local %d", index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
    if (is_set(BlockBegin::parser_loop_header_flag)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
      TRACE_PHI(tty->print_cr("loop header block, initializing phi functions"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
      for_each_stack_value(new_state, index, new_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
        new_state->setup_phi_for_stack(this, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
        TRACE_PHI(tty->print_cr("creating phi-function %c%d for stack %d", new_state->stack_at(index)->type()->tchar(), new_state->stack_at(index)->id(), index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
      BitMap requires_phi_function = new_state->scope()->requires_phi_function();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
      for_each_local_value(new_state, index, new_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
        bool requires_phi = requires_phi_function.at(index) || (new_value->type()->is_double_word() && requires_phi_function.at(index + 1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
        if (requires_phi || !SelectivePhiFunctions) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
          new_state->setup_phi_for_local(this, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
          TRACE_PHI(tty->print_cr("creating phi-function %c%d for local %d", new_state->local_at(index)->type()->tchar(), new_state->local_at(index)->id(), index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
    // initialize state of block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
    set_state(new_state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
  } else if (existing_state->is_same_across_scopes(new_state)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
    TRACE_PHI(tty->print_cr("exisiting state found"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
    // Inlining may cause the local state not to match up, so walk up
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
    // the new state until we get to the same scope as the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
    // existing and then start processing from there.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
    while (existing_state->scope() != new_state->scope()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
      new_state = new_state->caller_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
      assert(new_state != NULL, "could not match up scopes");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
      assert(false, "check if this is necessary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
    assert(existing_state->scope() == new_state->scope(), "not matching");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
    assert(existing_state->locals_size() == new_state->locals_size(), "not matching");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
    assert(existing_state->stack_size() == new_state->stack_size(), "not matching");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
    if (is_set(BlockBegin::was_visited_flag)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
      TRACE_PHI(tty->print_cr("loop header block, phis must be present"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
      if (!is_set(BlockBegin::parser_loop_header_flag)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
        // this actually happens for complicated jsr/ret structures
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
        return false; // BAILOUT in caller
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
      for_each_local_value(existing_state, index, existing_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
        Value new_value = new_state->local_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
        if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
          // The old code invalidated the phi function here
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
          // Because dead locals are replaced with NULL, this is a very rare case now, so simply bail out
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
          return false; // BAILOUT in caller
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
      // check that all necessary phi functions are present
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
      for_each_stack_value(existing_state, index, existing_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
        assert(existing_value->as_Phi() != NULL && existing_value->as_Phi()->block() == this, "phi function required");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
      for_each_local_value(existing_state, index, existing_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
        assert(existing_value == new_state->local_at(index) || (existing_value->as_Phi() != NULL && existing_value->as_Phi()->as_Phi()->block() == this), "phi function required");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
      TRACE_PHI(tty->print_cr("creating phi functions on demand"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
      // create necessary phi functions for stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
      for_each_stack_value(existing_state, index, existing_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
        Value new_value = new_state->stack_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
        Phi* existing_phi = existing_value->as_Phi();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
        if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
          existing_state->setup_phi_for_stack(this, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
          TRACE_PHI(tty->print_cr("creating phi-function %c%d for stack %d", existing_state->stack_at(index)->type()->tchar(), existing_state->stack_at(index)->id(), index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
      // create necessary phi functions for locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
      for_each_local_value(existing_state, index, existing_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
        Value new_value = new_state->local_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
        Phi* existing_phi = existing_value->as_Phi();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
        if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
          existing_state->invalidate_local(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
          TRACE_PHI(tty->print_cr("invalidating local %d because of type mismatch", index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
        } else if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
          existing_state->setup_phi_for_local(this, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
          TRACE_PHI(tty->print_cr("creating phi-function %c%d for local %d", existing_state->local_at(index)->type()->tchar(), existing_state->local_at(index)->id(), index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
    assert(existing_state->caller_state() == new_state->caller_state(), "caller states must be equal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
    assert(false, "stack or locks not matching (invalid bytecodes)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
  TRACE_PHI(tty->print_cr("********** try_merge for block B%d successful", block_id()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
void BlockBegin::print_block() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
  InstructionPrinter ip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
  print_block(ip, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
void BlockBegin::print_block(InstructionPrinter& ip, bool live_only) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
  ip.print_instr(this); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
  ip.print_stack(this->state()); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
  ip.print_inline_level(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
  ip.print_head();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
  for (Instruction* n = next(); n != NULL; n = n->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
    if (!live_only || n->is_pinned() || n->use_count() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
      ip.print_line(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
  tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
#endif // PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
// Implementation of BlockList
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
void BlockList::iterate_forward (BlockClosure* closure) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
  const int l = length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
  for (int i = 0; i < l; i++) closure->block_do(at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
void BlockList::iterate_backward(BlockClosure* closure) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
  for (int i = length() - 1; i >= 0; i--) closure->block_do(at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
void BlockList::blocks_do(void f(BlockBegin*)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
  for (int i = length() - 1; i >= 0; i--) f(at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
void BlockList::values_do(void f(Value*)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
  for (int i = length() - 1; i >= 0; i--) at(i)->block_values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
void BlockList::print(bool cfg_only, bool live_only) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
  InstructionPrinter ip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
  for (int i = 0; i < length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
    BlockBegin* block = at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
    if (cfg_only) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
      ip.print_instr(block); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
      block->print_block(ip, live_only);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
#endif // PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
// Implementation of BlockEnd
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
void BlockEnd::set_begin(BlockBegin* begin) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
  BlockList* sux = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
  if (begin != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
    sux = begin->successors();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
  } else if (_begin != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
    // copy our sux list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
    BlockList* sux = new BlockList(_begin->number_of_sux());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
    for (int i = 0; i < _begin->number_of_sux(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
      sux->append(_begin->sux_at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
  _sux = sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
  _begin = begin;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
void BlockEnd::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
  substitute(*_sux, old_sux, new_sux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
void BlockEnd::other_values_do(void f(Value*)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
  if (state_before() != NULL) state_before()->values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
// Implementation of Phi
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
// Normal phi functions take their operands from the last instruction of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
// predecessor. Special handling is needed for xhanlder entries because there
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
// the state of arbitrary instructions are needed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
Value Phi::operand_at(int i) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
  ValueStack* state;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
  if (_block->is_set(BlockBegin::exception_entry_flag)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
    state = _block->exception_state_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
    state = _block->pred_at(i)->end()->state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
  assert(state != NULL, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
  if (is_local()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
    return state->local_at(local_index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
    return state->stack_at(stack_index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
int Phi::operand_count() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
  if (_block->is_set(BlockBegin::exception_entry_flag)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
    return _block->number_of_exception_states();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
    return _block->number_of_preds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
// Implementation of Throw
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
void Throw::state_values_do(void f(Value*)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
  BlockEnd::state_values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
}