src/hotspot/share/c1/c1_Instruction.cpp
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 58961 5d462d4b7a8b
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 41698
diff changeset
     2
 * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5046
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5046
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5046
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7100
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7100
diff changeset
    26
#include "c1/c1_IR.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7100
diff changeset
    27
#include "c1/c1_Instruction.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7100
diff changeset
    28
#include "c1/c1_InstructionPrinter.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7100
diff changeset
    29
#include "c1/c1_ValueStack.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7100
diff changeset
    30
#include "ci/ciObjArrayKlass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7100
diff changeset
    31
#include "ci/ciTypeArrayKlass.hpp"
58961
5d462d4b7a8b 8233073: Make BitMap accessors more memory ordering friendly
eosterlund
parents: 53028
diff changeset
    32
#include "utilities/bitMap.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// Implementation of Instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
    38
int Instruction::dominator_depth() {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
    39
  int result = -1;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
    40
  if (block()) {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
    41
    result = block()->dominator_depth();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
    42
  }
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
    43
  assert(result != -1 || this->as_Local(), "Only locals have dominator depth -1");
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
    44
  return result;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
    45
}
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
    46
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
Instruction::Condition Instruction::mirror(Condition cond) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  switch (cond) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    case eql: return eql;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    case neq: return neq;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    case lss: return gtr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    case leq: return geq;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    case gtr: return lss;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    case geq: return leq;
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
    55
    case aeq: return beq;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
    56
    case beq: return aeq;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  return eql;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
Instruction::Condition Instruction::negate(Condition cond) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  switch (cond) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    case eql: return neq;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    case neq: return eql;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    case lss: return geq;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    case leq: return gtr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    case gtr: return leq;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    case geq: return lss;
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
    71
    case aeq: assert(false, "Above equal cannot be negated");
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
    72
    case beq: assert(false, "Below equal cannot be negated");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  return eql;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
    78
void Instruction::update_exception_state(ValueStack* state) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
    79
  if (state != NULL && (state->kind() == ValueStack::EmptyExceptionState || state->kind() == ValueStack::ExceptionState)) {
22893
e3a2b513713a 8035493: JVMTI PopFrame capability must instruct compilers not to prune locals
mgronlun
parents: 22234
diff changeset
    80
    assert(state->kind() == ValueStack::EmptyExceptionState || Compilation::current()->env()->should_retain_local_variables(), "unexpected state kind");
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
    81
    _exception_state = state;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
    82
  } else {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
    83
    _exception_state = NULL;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
    84
  }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
    85
}
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
    86
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
    87
// Prev without need to have BlockBegin
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
    88
Instruction* Instruction::prev() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  Instruction* p = NULL;
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
    90
  Instruction* q = block();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  while (q != this) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    assert(q != NULL, "this is not in the block's instruction list");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    p = q; q = q->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  return p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
    99
void Instruction::state_values_do(ValueVisitor* f) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   100
  if (state_before() != NULL) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   101
    state_before()->values_do(f);
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   102
  }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   103
  if (exception_state() != NULL){
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   104
    exception_state()->values_do(f);
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   105
  }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   106
}
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   107
20702
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 16611
diff changeset
   108
ciType* Instruction::exact_type() const {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 16611
diff changeset
   109
  ciType* t =  declared_type();
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 16611
diff changeset
   110
  if (t != NULL && t->is_klass()) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 16611
diff changeset
   111
    return t->as_klass()->exact_klass();
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 16611
diff changeset
   112
  }
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 16611
diff changeset
   113
  return NULL;
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 16611
diff changeset
   114
}
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 16611
diff changeset
   115
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   116
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
#ifndef PRODUCT
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   118
void Instruction::check_state(ValueStack* state) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   119
  if (state != NULL) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   120
    state->verify();
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   121
  }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   122
}
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   123
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   124
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
void Instruction::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  InstructionPrinter ip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  print(ip);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
void Instruction::print_line() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  InstructionPrinter ip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  ip.print_line(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
void Instruction::print(InstructionPrinter& ip) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  ip.print_head();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  ip.print_line(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
#endif // PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
// perform constant and interval tests on index value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
bool AccessIndexed::compute_needs_range_check() {
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   147
  if (length()) {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   148
    Constant* clength = length()->as_Constant();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   149
    Constant* cindex = index()->as_Constant();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   150
    if (clength && cindex) {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   151
      IntConstant* l = clength->type()->as_IntConstant();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   152
      IntConstant* i = cindex->type()->as_IntConstant();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   153
      if (l && i && i->value() < l->value() && i->value() >= 0) {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   154
        return false;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   155
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  }
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   158
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   159
  if (!this->check_flag(NeedsRangeCheckFlag)) {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   160
    return false;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   161
  }
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   162
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10509
diff changeset
   167
ciType* Constant::exact_type() const {
20702
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 16611
diff changeset
   168
  if (type()->is_object() && type()->as_ObjectType()->is_loaded()) {
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10509
diff changeset
   169
    return type()->as_ObjectType()->exact_type();
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10509
diff changeset
   170
  }
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10509
diff changeset
   171
  return NULL;
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10509
diff changeset
   172
}
9102
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 7397
diff changeset
   173
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
ciType* LoadIndexed::exact_type() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  ciType* array_type = array()->exact_type();
20702
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 16611
diff changeset
   176
  if (array_type != NULL) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 16611
diff changeset
   177
    assert(array_type->is_array_klass(), "what else?");
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 16611
diff changeset
   178
    ciArrayKlass* ak = (ciArrayKlass*)array_type;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
20702
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 16611
diff changeset
   180
    if (ak->element_type()->is_instance_klass()) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 16611
diff changeset
   181
      ciInstanceKlass* ik = (ciInstanceKlass*)ak->element_type();
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 16611
diff changeset
   182
      if (ik->is_loaded() && ik->is_final()) {
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 16611
diff changeset
   183
        return ik;
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 16611
diff changeset
   184
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  }
20702
bbe0fcde6e13 8023657: New type profiling points: arguments to call
roland
parents: 16611
diff changeset
   187
  return Instruction::exact_type();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
ciType* LoadIndexed::declared_type() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  ciType* array_type = array()->declared_type();
15476
5e4cda2ccd0b 8005114: VM is crashing in ciKlass*ciObjArrayKlass::element_klass() if metaspaces are full
roland
parents: 13728
diff changeset
   193
  if (array_type == NULL || !array_type->is_loaded()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  assert(array_type->is_array_klass(), "what else?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  ciArrayKlass* ak = (ciArrayKlass*)array_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  return ak->element_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
ciType* LoadField::declared_type() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  return field()->type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
ciType* NewTypeArray::exact_type() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  return ciTypeArrayKlass::make(elt_type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
ciType* NewObjectArray::exact_type() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  return ciObjArrayKlass::make(klass());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
9102
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 7397
diff changeset
   215
ciType* NewArray::declared_type() const {
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 7397
diff changeset
   216
  return exact_type();
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 7397
diff changeset
   217
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
ciType* NewInstance::exact_type() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  return klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
9102
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 7397
diff changeset
   223
ciType* NewInstance::declared_type() const {
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 7397
diff changeset
   224
  return exact_type();
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 7397
diff changeset
   225
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
ciType* CheckCast::declared_type() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  return klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
// Implementation of ArithmeticOp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
bool ArithmeticOp::is_commutative() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  switch (op()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    case Bytecodes::_iadd: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    case Bytecodes::_ladd: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    case Bytecodes::_fadd: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    case Bytecodes::_dadd: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    case Bytecodes::_imul: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    case Bytecodes::_lmul: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    case Bytecodes::_fmul: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    case Bytecodes::_dmul: return true;
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 41698
diff changeset
   243
    default              : return false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
bool ArithmeticOp::can_trap() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  switch (op()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    case Bytecodes::_idiv: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    case Bytecodes::_ldiv: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    case Bytecodes::_irem: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    case Bytecodes::_lrem: return true;
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 41698
diff changeset
   254
    default              : return false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
// Implementation of LogicOp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
bool LogicOp::is_commutative() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  switch (op()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    case Bytecodes::_iand: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    case Bytecodes::_land: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    case Bytecodes::_ior : // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    case Bytecodes::_lor : // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    case Bytecodes::_ixor: // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    case Bytecodes::_lxor: break;
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 41698
diff changeset
   270
    default              : ShouldNotReachHere(); break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  // all LogicOps are commutative
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  return true;
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
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   305
void StateSplit::state_values_do(ValueVisitor* f) {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   306
  Instruction::state_values_do(f);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  if (state() != NULL) state()->values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   311
void BlockBegin::state_values_do(ValueVisitor* f) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  StateSplit::state_values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  if (is_set(BlockBegin::exception_entry_flag)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    for (int i = 0; i < number_of_exception_states(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
      exception_state_at(i)->values_do(f);
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
// Implementation of Invoke
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
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
   326
               int vtable_index, ciMethod* target, ValueStack* state_before)
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   327
  : StateSplit(result_type, state_before)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  , _code(code)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  , _recv(recv)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  , _args(args)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  , _vtable_index(vtable_index)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  , _target(target)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  set_flag(TargetIsLoadedFlag,   target->is_loaded());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  set_flag(TargetIsFinalFlag,    target_is_loaded() && target->is_final_method());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  set_flag(TargetIsStrictfpFlag, target_is_loaded() && target->is_strict());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  assert(args != NULL, "args must exist");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
#ifdef ASSERT
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   340
  AssertValues assert_value;
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   341
  values_do(&assert_value);
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   342
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  // provide an initial guess of signature size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  _signature = new BasicTypeList(number_of_arguments() + (has_receiver() ? 1 : 0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  if (has_receiver()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    _signature->append(as_BasicType(receiver()->type()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  for (int i = 0; i < number_of_arguments(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    ValueType* t = argument_at(i)->type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    BasicType bt = as_BasicType(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    _signature->append(bt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   357
void Invoke::state_values_do(ValueVisitor* f) {
5046
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 1
diff changeset
   358
  StateSplit::state_values_do(f);
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 1
diff changeset
   359
  if (state_before() != NULL) state_before()->values_do(f);
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 1
diff changeset
   360
  if (state()        != NULL) state()->values_do(f);
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 1
diff changeset
   361
}
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 1
diff changeset
   362
9102
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 7397
diff changeset
   363
ciType* Invoke::declared_type() const {
41698
a3f113541801 8134389: Crash in HotSpot with jvm.dll+0x42b48 ciObjectFactory::create_new_metadata
jcm
parents: 38177
diff changeset
   364
  ciSignature* declared_signature = state()->scope()->method()->get_declared_signature_at_bci(state()->bci());
a3f113541801 8134389: Crash in HotSpot with jvm.dll+0x42b48 ciObjectFactory::create_new_metadata
jcm
parents: 38177
diff changeset
   365
  ciType *t = declared_signature->return_type();
9102
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 7397
diff changeset
   366
  assert(t->basic_type() != T_VOID, "need return value of void method?");
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 7397
diff changeset
   367
  return t;
4708a4aefb33 7033154: Improve C1 arraycopy performance
roland
parents: 7397
diff changeset
   368
}
5046
27e801a857cb 6919934: JSR 292 needs to support x86 C1
twisti
parents: 1
diff changeset
   369
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
// Implementation of Contant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
intx Constant::hash() const {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   372
  if (state_before() == NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    switch (type()->tag()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
    case intTag:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
      return HASH2(name(), type()->as_IntConstant()->value());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   376
    case addressTag:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   377
      return HASH2(name(), type()->as_AddressConstant()->value());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    case longTag:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
        jlong temp = type()->as_LongConstant()->value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
        return HASH3(name(), high(temp), low(temp));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    case floatTag:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
      return HASH2(name(), jint_cast(type()->as_FloatConstant()->value()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
    case doubleTag:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
        jlong temp = jlong_cast(type()->as_DoubleConstant()->value());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
        return HASH3(name(), high(temp), low(temp));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
    case objectTag:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
      assert(type()->as_ObjectType()->is_loaded(), "can't handle unloaded values");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
      return HASH2(name(), type()->as_ObjectType()->constant_value());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   393
    case metaDataTag:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   394
      assert(type()->as_MetadataType()->is_loaded(), "can't handle unloaded values");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   395
      return HASH2(name(), type()->as_MetadataType()->constant_value());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   396
    default:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   397
      ShouldNotReachHere();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
bool Constant::is_equal(Value v) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  if (v->as_Constant() == NULL) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  switch (type()->tag()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
    case intTag:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
        IntConstant* t1 =    type()->as_IntConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
        IntConstant* t2 = v->type()->as_IntConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
        return (t1 != NULL && t2 != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
                t1->value() == t2->value());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
    case longTag:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
        LongConstant* t1 =    type()->as_LongConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
        LongConstant* t2 = v->type()->as_LongConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
        return (t1 != NULL && t2 != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
                t1->value() == t2->value());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
    case floatTag:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
        FloatConstant* t1 =    type()->as_FloatConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
        FloatConstant* t2 = v->type()->as_FloatConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
        return (t1 != NULL && t2 != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
                jint_cast(t1->value()) == jint_cast(t2->value()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
    case doubleTag:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
        DoubleConstant* t1 =    type()->as_DoubleConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
        DoubleConstant* t2 = v->type()->as_DoubleConstant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
        return (t1 != NULL && t2 != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
                jlong_cast(t1->value()) == jlong_cast(t2->value()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
    case objectTag:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
        ObjectType* t1 =    type()->as_ObjectType();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
        ObjectType* t2 = v->type()->as_ObjectType();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
        return (t1 != NULL && t2 != NULL &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
                t1->is_loaded() && t2->is_loaded() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
                t1->constant_value() == t2->constant_value());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
      }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   443
    case metaDataTag:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   444
      {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   445
        MetadataType* t1 =    type()->as_MetadataType();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   446
        MetadataType* t2 = v->type()->as_MetadataType();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   447
        return (t1 != NULL && t2 != NULL &&
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   448
                t1->is_loaded() && t2->is_loaded() &&
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   449
                t1->constant_value() == t2->constant_value());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   450
      }
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 41698
diff changeset
   451
    default:
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 41698
diff changeset
   452
      return false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   456
Constant::CompareResult Constant::compare(Instruction::Condition cond, Value right) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  Constant* rc = right->as_Constant();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  // other is not a constant
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   459
  if (rc == NULL) return not_comparable;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  ValueType* lt = type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  ValueType* rt = rc->type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  // different types
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   464
  if (lt->base() != rt->base()) return not_comparable;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  switch (lt->tag()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  case intTag: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
    int x = lt->as_IntConstant()->value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
    int y = rt->as_IntConstant()->value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    switch (cond) {
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   470
    case If::eql: return x == y ? cond_true : cond_false;
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   471
    case If::neq: return x != y ? cond_true : cond_false;
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   472
    case If::lss: return x <  y ? cond_true : cond_false;
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   473
    case If::leq: return x <= y ? cond_true : cond_false;
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   474
    case If::gtr: return x >  y ? cond_true : cond_false;
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   475
    case If::geq: return x >= y ? cond_true : cond_false;
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 41698
diff changeset
   476
    default     : break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  case longTag: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
    jlong x = lt->as_LongConstant()->value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    jlong y = rt->as_LongConstant()->value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
    switch (cond) {
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   484
    case If::eql: return x == y ? cond_true : cond_false;
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   485
    case If::neq: return x != y ? cond_true : cond_false;
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   486
    case If::lss: return x <  y ? cond_true : cond_false;
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   487
    case If::leq: return x <= y ? cond_true : cond_false;
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   488
    case If::gtr: return x >  y ? cond_true : cond_false;
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   489
    case If::geq: return x >= y ? cond_true : cond_false;
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 41698
diff changeset
   490
    default     : break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  case objectTag: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
    ciObject* xvalue = lt->as_ObjectType()->constant_value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
    ciObject* yvalue = rt->as_ObjectType()->constant_value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
    assert(xvalue != NULL && yvalue != NULL, "not constants");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
    if (xvalue->is_loaded() && yvalue->is_loaded()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
      switch (cond) {
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   500
      case If::eql: return xvalue == yvalue ? cond_true : cond_false;
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   501
      case If::neq: return xvalue != yvalue ? cond_true : cond_false;
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 41698
diff changeset
   502
      default     : break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   507
  case metaDataTag: {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   508
    ciMetadata* xvalue = lt->as_MetadataType()->constant_value();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   509
    ciMetadata* yvalue = rt->as_MetadataType()->constant_value();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   510
    assert(xvalue != NULL && yvalue != NULL, "not constants");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   511
    if (xvalue->is_loaded() && yvalue->is_loaded()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   512
      switch (cond) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   513
      case If::eql: return xvalue == yvalue ? cond_true : cond_false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   514
      case If::neq: return xvalue != yvalue ? cond_true : cond_false;
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 41698
diff changeset
   515
      default     : break;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   516
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   517
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   518
    break;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13487
diff changeset
   519
  }
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 41698
diff changeset
   520
  default:
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 41698
diff changeset
   521
    break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  }
7100
6bcf9255d470 6991577: add IfOp optimization to C1
roland
parents: 6745
diff changeset
   523
  return not_comparable;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
// Implementation of BlockBegin
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
void BlockBegin::set_end(BlockEnd* end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
  assert(end != NULL, "should not reset block end to NULL");
10509
43d670e5701e 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 9170
diff changeset
   531
  if (end == _end) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  }
10509
43d670e5701e 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 9170
diff changeset
   534
  clear_end();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
10509
43d670e5701e 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 9170
diff changeset
   536
  // Set the new end
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
  _end = end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
  _successors.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
  // Now reset successors list based on BlockEnd
10509
43d670e5701e 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 9170
diff changeset
   541
  for (int i = 0; i < end->number_of_sux(); i++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
    BlockBegin* sux = end->sux_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
    _successors.append(sux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
    sux->_predecessors.append(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
  _end->set_begin(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
10509
43d670e5701e 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 9170
diff changeset
   550
void BlockBegin::clear_end() {
43d670e5701e 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 9170
diff changeset
   551
  // Must make the predecessors/successors match up with the
43d670e5701e 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 9170
diff changeset
   552
  // BlockEnd's notion.
43d670e5701e 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 9170
diff changeset
   553
  if (_end != NULL) {
43d670e5701e 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 9170
diff changeset
   554
    // disconnect from the old end
43d670e5701e 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 9170
diff changeset
   555
    _end->set_begin(NULL);
43d670e5701e 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 9170
diff changeset
   556
43d670e5701e 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 9170
diff changeset
   557
    // disconnect this block from it's current successors
43d670e5701e 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 9170
diff changeset
   558
    for (int i = 0; i < _successors.length(); i++) {
43d670e5701e 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 9170
diff changeset
   559
      _successors.at(i)->remove_predecessor(this);
43d670e5701e 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 9170
diff changeset
   560
    }
43d670e5701e 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 9170
diff changeset
   561
    _end = NULL;
43d670e5701e 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 9170
diff changeset
   562
  }
43d670e5701e 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 9170
diff changeset
   563
}
43d670e5701e 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 9170
diff changeset
   564
43d670e5701e 7079673: JSR 292: C1 should inline bytecoded method handle adapters
twisti
parents: 9170
diff changeset
   565
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
void BlockBegin::disconnect_edge(BlockBegin* from, BlockBegin* to) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
  // disconnect any edges between from and to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
  if (PrintIR && Verbose) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
    tty->print_cr("Disconnected edge B%d -> B%d", from->block_id(), to->block_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
  for (int s = 0; s < from->number_of_sux();) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
    BlockBegin* sux = from->sux_at(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
    if (sux == to) {
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 22893
diff changeset
   576
      int index = sux->_predecessors.find(from);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
      if (index >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
        sux->_predecessors.remove_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
      from->_successors.remove_at(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
      s++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
void BlockBegin::disconnect_from_graph() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  // disconnect this block from all other blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
  for (int p = 0; p < number_of_preds(); p++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
    pred_at(p)->remove_successor(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
  for (int s = 0; s < number_of_sux(); s++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
    sux_at(s)->remove_predecessor(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
void BlockBegin::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
  // modify predecessors before substituting successors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  for (int i = 0; i < number_of_sux(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
    if (sux_at(i) == old_sux) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
      // remove old predecessor before adding new predecessor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
      // otherwise there is a dead predecessor in the list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
      new_sux->remove_predecessor(old_sux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
      new_sux->add_predecessor(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
  old_sux->remove_predecessor(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
  end()->substitute_sux(old_sux, new_sux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
// In general it is not possible to calculate a value for the field "depth_first_number"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
// of the inserted block, without recomputing the values of the other blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
// in the CFG. Therefore the value of "depth_first_number" in BlockBegin becomes meaningless.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
BlockBegin* BlockBegin::insert_block_between(BlockBegin* sux) {
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   618
  int bci = sux->bci();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   619
  // critical edge splitting may introduce a goto after a if and array
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   620
  // bound check elimination may insert a predicate between the if and
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   621
  // goto. The bci of the goto can't be the one of the if otherwise
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   622
  // the state and bci are inconsistent and a deoptimization triggered
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   623
  // by the predicate would lead to incorrect execution/a crash.
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   624
  BlockBegin* new_sux = new BlockBegin(bci);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
  // mark this block (special treatment when block order is computed)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  new_sux->set(critical_edge_split_flag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
  // This goto is not a safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
  Goto* e = new Goto(sux, false);
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   631
  new_sux->set_next(e, bci);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
  new_sux->set_end(e);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  // setup states
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
  ValueStack* s = end()->state();
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   635
  new_sux->set_state(s->copy(s->kind(), bci));
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   636
  e->set_state(s->copy(s->kind(), bci));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
  assert(new_sux->state()->locals_size() == s->locals_size(), "local size mismatch!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
  assert(new_sux->state()->stack_size() == s->stack_size(), "stack size mismatch!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
  assert(new_sux->state()->locks_size() == s->locks_size(), "locks size mismatch!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
  // link predecessor to new block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
  end()->substitute_sux(sux, new_sux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
  // The ordering needs to be the same, so remove the link that the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
  // set_end call above added and substitute the new_sux for this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
  // block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
  sux->remove_predecessor(new_sux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
  // the successor could be the target of a switch so it might have
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
  // multiple copies of this predecessor, so substitute the new_sux
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
  // for the first and delete the rest.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
  bool assigned = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
  BlockList& list = sux->_predecessors;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
  for (int i = 0; i < list.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
    BlockBegin** b = list.adr_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
    if (*b == this) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
      if (assigned) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
        list.remove_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
        // reprocess this index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
        i--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
        assigned = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
        *b = new_sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
      // link the new block back to it's predecessors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
      new_sux->add_predecessor(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
  assert(assigned == true, "should have assigned at least once");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
  return new_sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
void BlockBegin::remove_successor(BlockBegin* pred) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
  int idx;
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 22893
diff changeset
   676
  while ((idx = _successors.find(pred)) >= 0) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
    _successors.remove_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
void BlockBegin::add_predecessor(BlockBegin* pred) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
  _predecessors.append(pred);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
void BlockBegin::remove_predecessor(BlockBegin* pred) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
  int idx;
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 22893
diff changeset
   689
  while ((idx = _predecessors.find(pred)) >= 0) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
    _predecessors.remove_at(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
void BlockBegin::add_exception_handler(BlockBegin* b) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
  assert(b != NULL && (b->is_set(exception_entry_flag)), "exception handler must exist");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
  // add only if not in the list already
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
  if (!_exception_handlers.contains(b)) _exception_handlers.append(b);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
int BlockBegin::add_exception_state(ValueStack* state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
  assert(is_set(exception_entry_flag), "only for xhandlers");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
  if (_exception_states == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
    _exception_states = new ValueStackStack(4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
  _exception_states->append(state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
  return _exception_states->length() - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
void BlockBegin::iterate_preorder(boolArray& mark, BlockClosure* closure) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
  if (!mark.at(block_id())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
    mark.at_put(block_id(), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
    closure->block_do(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
    BlockEnd* e = end(); // must do this after block_do because block_do may change it!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
    { 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
   717
    { 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
   718
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
void BlockBegin::iterate_postorder(boolArray& mark, BlockClosure* closure) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
  if (!mark.at(block_id())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
    mark.at_put(block_id(), true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
    BlockEnd* e = end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
    { 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
   727
    { 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
   728
    closure->block_do(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
void BlockBegin::iterate_preorder(BlockClosure* closure) {
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 22893
diff changeset
   734
  int mark_len = number_of_blocks();
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 22893
diff changeset
   735
  boolArray mark(mark_len, mark_len, false);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
  iterate_preorder(mark, closure);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
void BlockBegin::iterate_postorder(BlockClosure* closure) {
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 22893
diff changeset
   741
  int mark_len = number_of_blocks();
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 22893
diff changeset
   742
  boolArray mark(mark_len, mark_len, false);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
  iterate_postorder(mark, closure);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   747
void BlockBegin::block_values_do(ValueVisitor* f) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
  for (Instruction* n = this; n != NULL; n = n->next()) n->values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
#ifndef PRODUCT
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5707
diff changeset
   753
   #define TRACE_PHI(code) if (PrintPhiFunctions) { code; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
#else
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5707
diff changeset
   755
   #define TRACE_PHI(coce)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
bool BlockBegin::try_merge(ValueStack* new_state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
  TRACE_PHI(tty->print_cr("********** try_merge for block B%d", block_id()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
  // local variables used for state iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
  int index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
  Value new_value, existing_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
  ValueStack* existing_state = state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
  if (existing_state == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
    TRACE_PHI(tty->print_cr("first call of try_merge for this block"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
    if (is_set(BlockBegin::was_visited_flag)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
      // this actually happens for complicated jsr/ret structures
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
      return false; // BAILOUT in caller
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
    // copy state because it is altered
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   776
    new_state = new_state->copy(ValueStack::BlockBeginState, bci());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
    // Use method liveness to invalidate dead locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
    MethodLivenessResult liveness = new_state->scope()->method()->liveness_at_bci(bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
    if (liveness.is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
      assert((int)liveness.size() == new_state->locals_size(), "error in use of liveness");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
      for_each_local_value(new_state, index, new_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
        if (!liveness.at(index) || new_value->type()->is_illegal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
          new_state->invalidate_local(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
          TRACE_PHI(tty->print_cr("invalidating dead local %d", index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
    if (is_set(BlockBegin::parser_loop_header_flag)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
      TRACE_PHI(tty->print_cr("loop header block, initializing phi functions"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
      for_each_stack_value(new_state, index, new_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
        new_state->setup_phi_for_stack(this, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
        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
   797
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
38177
b0c9cb06506b 8141501: Problems with BitMap buffer management
stefank
parents: 38031
diff changeset
   799
      BitMap& requires_phi_function = new_state->scope()->requires_phi_function();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
      for_each_local_value(new_state, index, new_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
        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
   803
        if (requires_phi || !SelectivePhiFunctions) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
          new_state->setup_phi_for_local(this, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
          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
   806
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
    // initialize state of block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
    set_state(new_state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 6453
diff changeset
   813
  } else if (existing_state->is_same(new_state)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
    TRACE_PHI(tty->print_cr("exisiting state found"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
    assert(existing_state->scope() == new_state->scope(), "not matching");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
    assert(existing_state->locals_size() == new_state->locals_size(), "not matching");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
    assert(existing_state->stack_size() == new_state->stack_size(), "not matching");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
    if (is_set(BlockBegin::was_visited_flag)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
      TRACE_PHI(tty->print_cr("loop header block, phis must be present"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
      if (!is_set(BlockBegin::parser_loop_header_flag)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
        // this actually happens for complicated jsr/ret structures
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
        return false; // BAILOUT in caller
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
      for_each_local_value(existing_state, index, existing_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
        Value new_value = new_state->local_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
        if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) {
53028
b3830528df29 8214352: C1: Unnecessary "compilation bailout: block join failed" with JVMTI
mdoerr
parents: 47216
diff changeset
   831
          Phi* existing_phi = existing_value->as_Phi();
b3830528df29 8214352: C1: Unnecessary "compilation bailout: block join failed" with JVMTI
mdoerr
parents: 47216
diff changeset
   832
          if (existing_phi == NULL) {
b3830528df29 8214352: C1: Unnecessary "compilation bailout: block join failed" with JVMTI
mdoerr
parents: 47216
diff changeset
   833
            return false; // BAILOUT in caller
b3830528df29 8214352: C1: Unnecessary "compilation bailout: block join failed" with JVMTI
mdoerr
parents: 47216
diff changeset
   834
          }
b3830528df29 8214352: C1: Unnecessary "compilation bailout: block join failed" with JVMTI
mdoerr
parents: 47216
diff changeset
   835
          // Invalidate the phi function here. This case is very rare except for
b3830528df29 8214352: C1: Unnecessary "compilation bailout: block join failed" with JVMTI
mdoerr
parents: 47216
diff changeset
   836
          // JVMTI capability "can_access_local_variables".
b3830528df29 8214352: C1: Unnecessary "compilation bailout: block join failed" with JVMTI
mdoerr
parents: 47216
diff changeset
   837
          // In really rare cases we will bail out in LIRGenerator::move_to_phi.
b3830528df29 8214352: C1: Unnecessary "compilation bailout: block join failed" with JVMTI
mdoerr
parents: 47216
diff changeset
   838
          existing_phi->make_illegal();
b3830528df29 8214352: C1: Unnecessary "compilation bailout: block join failed" with JVMTI
mdoerr
parents: 47216
diff changeset
   839
          existing_state->invalidate_local(index);
b3830528df29 8214352: C1: Unnecessary "compilation bailout: block join failed" with JVMTI
mdoerr
parents: 47216
diff changeset
   840
          TRACE_PHI(tty->print_cr("invalidating local %d because of type mismatch", index));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
      // check that all necessary phi functions are present
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
      for_each_stack_value(existing_state, index, existing_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
        assert(existing_value->as_Phi() != NULL && existing_value->as_Phi()->block() == this, "phi function required");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
      for_each_local_value(existing_state, index, existing_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
        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
   851
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
      TRACE_PHI(tty->print_cr("creating phi functions on demand"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
      // create necessary phi functions for stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
      for_each_stack_value(existing_state, index, existing_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
        Value new_value = new_state->stack_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
        Phi* existing_phi = existing_value->as_Phi();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
        if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
          existing_state->setup_phi_for_stack(this, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
          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
   865
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
      // create necessary phi functions for locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
      for_each_local_value(existing_state, index, existing_value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
        Value new_value = new_state->local_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
        Phi* existing_phi = existing_value->as_Phi();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
        if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
          existing_state->invalidate_local(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
          TRACE_PHI(tty->print_cr("invalidating local %d because of type mismatch", index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
        } else if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
          existing_state->setup_phi_for_local(this, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
          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
   879
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
    assert(existing_state->caller_state() == new_state->caller_state(), "caller states must be equal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
    assert(false, "stack or locks not matching (invalid bytecodes)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
  TRACE_PHI(tty->print_cr("********** try_merge for block B%d successful", block_id()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
void BlockBegin::print_block() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
  InstructionPrinter ip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
  print_block(ip, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
void BlockBegin::print_block(InstructionPrinter& ip, bool live_only) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
  ip.print_instr(this); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
  ip.print_stack(this->state()); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
  ip.print_inline_level(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
  ip.print_head();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
  for (Instruction* n = next(); n != NULL; n = n->next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
    if (!live_only || n->is_pinned() || n->use_count() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
      ip.print_line(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
  tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
#endif // PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
// Implementation of BlockList
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
void BlockList::iterate_forward (BlockClosure* closure) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
  const int l = length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
  for (int i = 0; i < l; i++) closure->block_do(at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
void BlockList::iterate_backward(BlockClosure* closure) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
  for (int i = length() - 1; i >= 0; i--) closure->block_do(at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
void BlockList::blocks_do(void f(BlockBegin*)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
  for (int i = length() - 1; i >= 0; i--) f(at(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   936
void BlockList::values_do(ValueVisitor* f) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
  for (int i = length() - 1; i >= 0; i--) at(i)->block_values_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
void BlockList::print(bool cfg_only, bool live_only) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
  InstructionPrinter ip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
  for (int i = 0; i < length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
    BlockBegin* block = at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
    if (cfg_only) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
      ip.print_instr(block); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
      block->print_block(ip, live_only);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
#endif // PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
// Implementation of BlockEnd
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
void BlockEnd::set_begin(BlockBegin* begin) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
  BlockList* sux = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
  if (begin != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
    sux = begin->successors();
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   962
  } else if (this->begin() != NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
    // copy our sux list
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   964
    BlockList* sux = new BlockList(this->begin()->number_of_sux());
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   965
    for (int i = 0; i < this->begin()->number_of_sux(); i++) {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
   966
      sux->append(this->begin()->sux_at(i));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
  _sux = sux;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
void BlockEnd::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
  substitute(*_sux, old_sux, new_sux);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
// Implementation of Phi
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
// Normal phi functions take their operands from the last instruction of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
// predecessor. Special handling is needed for xhanlder entries because there
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
// the state of arbitrary instructions are needed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
Value Phi::operand_at(int i) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
  ValueStack* state;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
  if (_block->is_set(BlockBegin::exception_entry_flag)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
    state = _block->exception_state_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
    state = _block->pred_at(i)->end()->state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
  assert(state != NULL, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
  if (is_local()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
    return state->local_at(local_index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
    return state->stack_at(stack_index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
int Phi::operand_count() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
  if (_block->is_set(BlockBegin::exception_entry_flag)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
    return _block->number_of_exception_states();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
    return _block->number_of_preds();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1009
#ifdef ASSERT
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1010
// Constructor of Assert
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1011
Assert::Assert(Value x, Condition cond, bool unordered_is_true, Value y) : Instruction(illegalType)
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1012
  , _x(x)
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1013
  , _cond(cond)
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1014
  , _y(y)
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1015
{
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1016
  set_flag(UnorderedIsTrueFlag, unordered_is_true);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1017
  assert(x->type()->tag() == y->type()->tag(), "types must match");
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1018
  pin();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
16611
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1020
  stringStream strStream;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1021
  Compilation::current()->method()->print_name(&strStream);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1022
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1023
  stringStream strStream1;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1024
  InstructionPrinter ip1(1, &strStream1);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1025
  ip1.print_instr(x);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1026
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1027
  stringStream strStream2;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1028
  InstructionPrinter ip2(1, &strStream2);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1029
  ip2.print_instr(y);
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1030
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1031
  stringStream ss;
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1032
  ss.print("Assertion %s %s %s in method %s", strStream1.as_string(), ip2.cond_name(cond), strStream2.as_string(), strStream.as_string());
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1033
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1034
  _message = ss.as_string();
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1035
}
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1036
#endif
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1037
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1038
void RangeCheckPredicate::check_state() {
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1039
  assert(state()->kind() != ValueStack::EmptyExceptionState && state()->kind() != ValueStack::ExceptionState, "will deopt with empty state");
6807a703dd6b 7153771: array bound check elimination for c1
roland
parents: 15476
diff changeset
  1040
}
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5707
diff changeset
  1041
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5707
diff changeset
  1042
void ProfileInvoke::state_values_do(ValueVisitor* f) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5707
diff changeset
  1043
  if (state() != NULL) state()->values_do(f);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5707
diff changeset
  1044
}