src/hotspot/share/c1/c1_ValueStack.cpp
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 58586 cd9c4e6aa631
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
/*
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 22893
diff changeset
     2
 * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6745
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6745
diff changeset
    26
#include "c1/c1_IR.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6745
diff changeset
    27
#include "c1/c1_InstructionPrinter.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6745
diff changeset
    28
#include "c1/c1_ValueStack.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// Implementation of ValueStack
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    33
ValueStack::ValueStack(IRScope* scope, ValueStack* caller_state)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
: _scope(scope)
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    35
, _caller_state(caller_state)
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    36
, _bci(-99)
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    37
, _kind(Parsing)
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 22893
diff changeset
    38
, _locals(scope->method()->max_locals(), scope->method()->max_locals(), NULL)
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    39
, _stack(scope->method()->max_stack())
54074
9c6508806663 8220501: Improve c1_ValueStack locks handling
redestad
parents: 47216
diff changeset
    40
, _locks(NULL)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
{
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    42
  verify();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    45
ValueStack::ValueStack(ValueStack* copy_from, Kind kind, int bci)
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    46
  : _scope(copy_from->scope())
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    47
  , _caller_state(copy_from->caller_state())
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    48
  , _bci(bci)
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    49
  , _kind(kind)
58586
cd9c4e6aa631 8232165: Reduce allocations in ValueStack copying constructor
redestad
parents: 54074
diff changeset
    50
  , _locals(copy_from->locals_size_for_copy(kind))
cd9c4e6aa631 8232165: Reduce allocations in ValueStack copying constructor
redestad
parents: 54074
diff changeset
    51
  , _stack(copy_from->stack_size_for_copy(kind))
54074
9c6508806663 8220501: Improve c1_ValueStack locks handling
redestad
parents: 47216
diff changeset
    52
  , _locks(copy_from->locks_size() == 0 ? NULL : new Values(copy_from->locks_size()))
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    53
{
22893
e3a2b513713a 8035493: JVMTI PopFrame capability must instruct compilers not to prune locals
mgronlun
parents: 13963
diff changeset
    54
  assert(kind != EmptyExceptionState || !Compilation::current()->env()->should_retain_local_variables(), "need locals");
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    55
  if (kind != EmptyExceptionState) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    56
    _locals.appendAll(&copy_from->_locals);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  }
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    58
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    59
  if (kind != ExceptionState && kind != EmptyExceptionState) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    60
    _stack.appendAll(&copy_from->_stack);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
54074
9c6508806663 8220501: Improve c1_ValueStack locks handling
redestad
parents: 47216
diff changeset
    63
  if (copy_from->locks_size() > 0) {
9c6508806663 8220501: Improve c1_ValueStack locks handling
redestad
parents: 47216
diff changeset
    64
    _locks->appendAll(copy_from->_locks);
9c6508806663 8220501: Improve c1_ValueStack locks handling
redestad
parents: 47216
diff changeset
    65
  }
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    66
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    67
  verify();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
58586
cd9c4e6aa631 8232165: Reduce allocations in ValueStack copying constructor
redestad
parents: 54074
diff changeset
    70
int ValueStack::locals_size_for_copy(Kind kind) const {
cd9c4e6aa631 8232165: Reduce allocations in ValueStack copying constructor
redestad
parents: 54074
diff changeset
    71
  if (kind != EmptyExceptionState) {
cd9c4e6aa631 8232165: Reduce allocations in ValueStack copying constructor
redestad
parents: 54074
diff changeset
    72
    return locals_size();
cd9c4e6aa631 8232165: Reduce allocations in ValueStack copying constructor
redestad
parents: 54074
diff changeset
    73
  }
cd9c4e6aa631 8232165: Reduce allocations in ValueStack copying constructor
redestad
parents: 54074
diff changeset
    74
  return 0;
cd9c4e6aa631 8232165: Reduce allocations in ValueStack copying constructor
redestad
parents: 54074
diff changeset
    75
}
cd9c4e6aa631 8232165: Reduce allocations in ValueStack copying constructor
redestad
parents: 54074
diff changeset
    76
cd9c4e6aa631 8232165: Reduce allocations in ValueStack copying constructor
redestad
parents: 54074
diff changeset
    77
int ValueStack::stack_size_for_copy(Kind kind) const {
cd9c4e6aa631 8232165: Reduce allocations in ValueStack copying constructor
redestad
parents: 54074
diff changeset
    78
  if (kind != ExceptionState && kind != EmptyExceptionState) {
cd9c4e6aa631 8232165: Reduce allocations in ValueStack copying constructor
redestad
parents: 54074
diff changeset
    79
    if (kind == Parsing) {
cd9c4e6aa631 8232165: Reduce allocations in ValueStack copying constructor
redestad
parents: 54074
diff changeset
    80
      // stack will be modified, so reserve enough space to avoid resizing
cd9c4e6aa631 8232165: Reduce allocations in ValueStack copying constructor
redestad
parents: 54074
diff changeset
    81
      return scope()->method()->max_stack();
cd9c4e6aa631 8232165: Reduce allocations in ValueStack copying constructor
redestad
parents: 54074
diff changeset
    82
    } else {
cd9c4e6aa631 8232165: Reduce allocations in ValueStack copying constructor
redestad
parents: 54074
diff changeset
    83
      // stack will not be modified, so do not waste space
cd9c4e6aa631 8232165: Reduce allocations in ValueStack copying constructor
redestad
parents: 54074
diff changeset
    84
      return stack_size();
cd9c4e6aa631 8232165: Reduce allocations in ValueStack copying constructor
redestad
parents: 54074
diff changeset
    85
    }
cd9c4e6aa631 8232165: Reduce allocations in ValueStack copying constructor
redestad
parents: 54074
diff changeset
    86
  }
cd9c4e6aa631 8232165: Reduce allocations in ValueStack copying constructor
redestad
parents: 54074
diff changeset
    87
  return 0;
cd9c4e6aa631 8232165: Reduce allocations in ValueStack copying constructor
redestad
parents: 54074
diff changeset
    88
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    90
bool ValueStack::is_same(ValueStack* s) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    91
  if (scope() != s->scope()) return false;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    92
  if (caller_state() != s->caller_state()) return false;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    93
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    94
  if (locals_size() != s->locals_size()) return false;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    95
  if (stack_size() != s->stack_size()) return false;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    96
  if (locks_size() != s->locks_size()) return false;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    97
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // compare each stack element with the corresponding stack element of s
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  int index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  Value value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  for_each_stack_value(this, index, value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    if (value->type()->tag() != s->stack_at(index)->type()->tag()) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  }
54074
9c6508806663 8220501: Improve c1_ValueStack locks handling
redestad
parents: 47216
diff changeset
   104
  for (int i = 0; i < locks_size(); i++) {
9c6508806663 8220501: Improve c1_ValueStack locks handling
redestad
parents: 47216
diff changeset
   105
    value = lock_at(i);
9c6508806663 8220501: Improve c1_ValueStack locks handling
redestad
parents: 47216
diff changeset
   106
    if (value != NULL && value != s->lock_at(i)) {
9c6508806663 8220501: Improve c1_ValueStack locks handling
redestad
parents: 47216
diff changeset
   107
      return false;
9c6508806663 8220501: Improve c1_ValueStack locks handling
redestad
parents: 47216
diff changeset
   108
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
void ValueStack::clear_locals() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  for (int i = _locals.length() - 1; i >= 0; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    _locals.at_put(i, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
void ValueStack::pin_stack_for_linear_scan() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  for_each_state_value(this, v,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    if (v->as_Constant() == NULL && v->as_Local() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
      v->pin(Instruction::PinStackForStateSplit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
// apply function to all values of a list; factored out from values_do(f)
54074
9c6508806663 8220501: Improve c1_ValueStack locks handling
redestad
parents: 47216
diff changeset
   130
void ValueStack::apply(const Values& list, ValueVisitor* f) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  for (int i = 0; i < list.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    Value* va = list.adr_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    Value v0 = *va;
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   134
    if (v0 != NULL && !v0->type()->is_illegal()) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   135
      f->visit(va);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
#ifdef ASSERT
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   137
      Value v1 = *va;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   138
      assert(v1->type()->is_illegal() || v0->type()->tag() == v1->type()->tag(), "types must match");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   139
      assert(!v1->type()->is_double_word() || list.at(i + 1) == NULL, "hi-word of doubleword value must be NULL");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
#endif
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   141
      if (v0->type()->is_double_word()) i++;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   147
void ValueStack::values_do(ValueVisitor* f) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  ValueStack* state = this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  for_each_state(state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    apply(state->_locals, f);
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   151
    apply(state->_stack, f);
54074
9c6508806663 8220501: Improve c1_ValueStack locks handling
redestad
parents: 47216
diff changeset
   152
    if (state->_locks != NULL) {
9c6508806663 8220501: Improve c1_ValueStack locks handling
redestad
parents: 47216
diff changeset
   153
      apply(*state->_locks, f);
9c6508806663 8220501: Improve c1_ValueStack locks handling
redestad
parents: 47216
diff changeset
   154
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
Values* ValueStack::pop_arguments(int argument_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  assert(stack_size() >= argument_size, "stack too small or too many arguments");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  int base = stack_size() - argument_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  Values* args = new Values(argument_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  for (int i = base; i < stack_size();) args->push(stack_at_inc(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  truncate_stack(base);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  return args;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   169
int ValueStack::total_locks_size() const {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   170
  int num_locks = 0;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   171
  const ValueStack* state = this;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   172
  for_each_state(state) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   173
    num_locks += state->locks_size();
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   174
  }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   175
  return num_locks;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   176
}
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   177
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   178
int ValueStack::lock(Value obj) {
54074
9c6508806663 8220501: Improve c1_ValueStack locks handling
redestad
parents: 47216
diff changeset
   179
  if (_locks == NULL) {
9c6508806663 8220501: Improve c1_ValueStack locks handling
redestad
parents: 47216
diff changeset
   180
    _locks = new Values();
9c6508806663 8220501: Improve c1_ValueStack locks handling
redestad
parents: 47216
diff changeset
   181
  }
9c6508806663 8220501: Improve c1_ValueStack locks handling
redestad
parents: 47216
diff changeset
   182
  _locks->push(obj);
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   183
  int num_locks = total_locks_size();
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   184
  scope()->set_min_number_of_locks(num_locks);
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   185
  return num_locks - 1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
int ValueStack::unlock() {
54074
9c6508806663 8220501: Improve c1_ValueStack locks handling
redestad
parents: 47216
diff changeset
   190
  assert(locks_size() > 0, "sanity");
9c6508806663 8220501: Improve c1_ValueStack locks handling
redestad
parents: 47216
diff changeset
   191
  _locks->pop();
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   192
  return total_locks_size();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
void ValueStack::setup_phi_for_stack(BlockBegin* b, int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  assert(stack_at(index)->as_Phi() == NULL || stack_at(index)->as_Phi()->block() != b, "phi function already created");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  ValueType* t = stack_at(index)->type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  Value phi = new Phi(t, b, -index - 1);
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 22893
diff changeset
   201
  _stack.at_put(index, phi);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   203
  assert(!t->is_double_word() || _stack.at(index + 1) == NULL, "hi-word of doubleword value must be NULL");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
void ValueStack::setup_phi_for_local(BlockBegin* b, int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  assert(local_at(index)->as_Phi() == NULL || local_at(index)->as_Phi()->block() != b, "phi function already created");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  ValueType* t = local_at(index)->type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  Value phi = new Phi(t, b, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  store_local(index, phi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
#ifndef PRODUCT
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   215
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
void ValueStack::print() {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   217
  scope()->method()->print_name();
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 7397
diff changeset
   218
  tty->cr();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  if (stack_is_empty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    tty->print_cr("empty stack");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    InstructionPrinter ip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    for (int i = 0; i < stack_size();) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
      Value t = stack_at_inc(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
      tty->print("%2d  ", i);
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   226
      tty->print("%c%d ", t->type()->tchar(), t->id());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
      ip.print_instr(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  if (!no_active_locks()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    InstructionPrinter ip;
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   233
    for (int i = 0; i < locks_size(); i++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
      Value t = lock_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
      tty->print("lock %2d  ", i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
      if (t == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
        tty->print("this");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
      } else {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   239
        tty->print("%c%d ", t->type()->tchar(), t->id());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
        ip.print_instr(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  if (locals_size() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    InstructionPrinter ip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    for (int i = 0; i < locals_size();) {
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 22893
diff changeset
   248
      Value l = _locals.at(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
      tty->print("local %d ", i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
      if (l == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
        tty->print("null");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
        i ++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
      } else {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   254
        tty->print("%c%d ", l->type()->tchar(), l->id());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
        ip.print_instr(l);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
        if (l->type()->is_illegal() || l->type()->is_single_word()) i ++; else i += 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  }
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   261
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   262
  if (caller_state() != NULL) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   263
    caller_state()->print();
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   264
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
void ValueStack::verify() {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   269
  assert(scope() != NULL, "scope must exist");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   270
  if (caller_state() != NULL) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   271
    assert(caller_state()->scope() == scope()->caller(), "invalid caller scope");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   272
    caller_state()->verify();
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   273
  }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   274
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   275
  if (kind() == Parsing) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   276
    assert(bci() == -99, "bci not defined during parsing");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   277
  } else {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   278
    assert(bci() >= -1, "bci out of range");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   279
    assert(bci() < scope()->method()->code_size(), "bci out of range");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   280
    assert(bci() == SynchronizationEntryBCI || Bytecodes::is_defined(scope()->method()->java_code_at_bci(bci())), "make sure bci points at a real bytecode");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   281
    assert(scope()->method()->liveness_at_bci(bci()).is_valid(), "liveness at bci must be valid");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   282
  }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   283
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   284
  int i;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   285
  for (i = 0; i < stack_size(); i++) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   286
    Value v = _stack.at(i);
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   287
    if (v == NULL) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   288
      assert(_stack.at(i - 1)->type()->is_double_word(), "only hi-words are NULL on stack");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   289
    } else if (v->type()->is_double_word()) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   290
      assert(_stack.at(i + 1) == NULL, "hi-word must be NULL");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   291
    }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   292
  }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   293
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   294
  for (i = 0; i < locals_size(); i++) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   295
    Value v = _locals.at(i);
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   296
    if (v != NULL && v->type()->is_double_word()) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   297
      assert(_locals.at(i + 1) == NULL, "hi-word must be NULL");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   298
    }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   299
  }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   300
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   301
  for_each_state_value(this, v,
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   302
    assert(v != NULL, "just test if state-iteration succeeds");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   303
  );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
#endif // PRODUCT