src/hotspot/share/c1/c1_ValueStack.cpp
author pliden
Mon, 14 May 2018 15:42:59 +0200
changeset 50102 454fa295105c
parent 47216 71c04702a3d5
child 54074 9c6508806663
permissions -rw-r--r--
8202976: Add C1 lea patching support for x86 Reviewed-by: kvn, neliasso
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())
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    40
, _locks()
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    46
ValueStack::ValueStack(ValueStack* copy_from, Kind kind, int bci)
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    47
  : _scope(copy_from->scope())
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    48
  , _caller_state(copy_from->caller_state())
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    49
  , _bci(bci)
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    50
  , _kind(kind)
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    51
  , _locals()
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    52
  , _stack()
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    53
  , _locks(copy_from->locks_size())
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    54
{
22893
e3a2b513713a 8035493: JVMTI PopFrame capability must instruct compilers not to prune locals
mgronlun
parents: 13963
diff changeset
    55
  assert(kind != EmptyExceptionState || !Compilation::current()->env()->should_retain_local_variables(), "need locals");
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    56
  if (kind != EmptyExceptionState) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    57
    // only allocate space if we need to copy the locals-array
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    58
    _locals = Values(copy_from->locals_size());
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    59
    _locals.appendAll(&copy_from->_locals);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  }
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    61
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    62
  if (kind != ExceptionState && kind != EmptyExceptionState) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    63
    if (kind == Parsing) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    64
      // stack will be modified, so reserve enough space to avoid resizing
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    65
      _stack = Values(scope()->method()->max_stack());
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    66
    } else {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    67
      // stack will not be modified, so do not waste space
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    68
      _stack = Values(copy_from->stack_size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    }
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    70
    _stack.appendAll(&copy_from->_stack);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    73
  _locks.appendAll(&copy_from->_locks);
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    74
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    75
  verify();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    79
bool ValueStack::is_same(ValueStack* s) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    80
  if (scope() != s->scope()) return false;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    81
  if (caller_state() != s->caller_state()) return false;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    82
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    83
  if (locals_size() != s->locals_size()) return false;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    84
  if (stack_size() != s->stack_size()) return false;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    85
  if (locks_size() != s->locks_size()) return false;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    86
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  // compare each stack element with the corresponding stack element of s
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  int index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  Value value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  for_each_stack_value(this, index, value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    if (value->type()->tag() != s->stack_at(index)->type()->tag()) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  for_each_lock_value(this, index, value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    if (value != s->lock_at(index)) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
void ValueStack::clear_locals() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  for (int i = _locals.length() - 1; i >= 0; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    _locals.at_put(i, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
void ValueStack::pin_stack_for_linear_scan() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  for_each_state_value(this, v,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    if (v->as_Constant() == NULL && v->as_Local() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      v->pin(Instruction::PinStackForStateSplit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
// apply function to all values of a list; factored out from values_do(f)
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   116
void ValueStack::apply(Values list, ValueVisitor* f) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  for (int i = 0; i < list.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    Value* va = list.adr_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    Value v0 = *va;
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   120
    if (v0 != NULL && !v0->type()->is_illegal()) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   121
      f->visit(va);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
#ifdef ASSERT
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   123
      Value v1 = *va;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   124
      assert(v1->type()->is_illegal() || v0->type()->tag() == v1->type()->tag(), "types must match");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   125
      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
   126
#endif
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   127
      if (v0->type()->is_double_word()) i++;
1
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   133
void ValueStack::values_do(ValueVisitor* f) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  ValueStack* state = this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  for_each_state(state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    apply(state->_locals, f);
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   137
    apply(state->_stack, f);
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   138
    apply(state->_locks, f);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
Values* ValueStack::pop_arguments(int argument_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  assert(stack_size() >= argument_size, "stack too small or too many arguments");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  int base = stack_size() - argument_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  Values* args = new Values(argument_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  for (int i = base; i < stack_size();) args->push(stack_at_inc(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  truncate_stack(base);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  return args;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   153
int ValueStack::total_locks_size() const {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   154
  int num_locks = 0;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   155
  const ValueStack* state = this;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   156
  for_each_state(state) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   157
    num_locks += state->locks_size();
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   158
  }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   159
  return num_locks;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   160
}
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   161
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   162
int ValueStack::lock(Value obj) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  _locks.push(obj);
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   164
  int num_locks = total_locks_size();
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   165
  scope()->set_min_number_of_locks(num_locks);
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   166
  return num_locks - 1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
int ValueStack::unlock() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  _locks.pop();
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   172
  return total_locks_size();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
void ValueStack::setup_phi_for_stack(BlockBegin* b, int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  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
   178
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  ValueType* t = stack_at(index)->type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  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
   181
  _stack.at_put(index, phi);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   183
  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
   184
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
void ValueStack::setup_phi_for_local(BlockBegin* b, int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  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
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  ValueType* t = local_at(index)->type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  Value phi = new Phi(t, b, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  store_local(index, phi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
#ifndef PRODUCT
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   195
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
void ValueStack::print() {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   197
  scope()->method()->print_name();
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 7397
diff changeset
   198
  tty->cr();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  if (stack_is_empty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    tty->print_cr("empty stack");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    InstructionPrinter ip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    for (int i = 0; i < stack_size();) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
      Value t = stack_at_inc(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
      tty->print("%2d  ", i);
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   206
      tty->print("%c%d ", t->type()->tchar(), t->id());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
      ip.print_instr(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  if (!no_active_locks()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    InstructionPrinter ip;
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   213
    for (int i = 0; i < locks_size(); i++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
      Value t = lock_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
      tty->print("lock %2d  ", i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
      if (t == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
        tty->print("this");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
      } else {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   219
        tty->print("%c%d ", t->type()->tchar(), t->id());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
        ip.print_instr(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  if (locals_size() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    InstructionPrinter ip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    for (int i = 0; i < locals_size();) {
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 22893
diff changeset
   228
      Value l = _locals.at(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
      tty->print("local %d ", i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
      if (l == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
        tty->print("null");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
        i ++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
      } else {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   234
        tty->print("%c%d ", l->type()->tchar(), l->id());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
        ip.print_instr(l);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
        if (l->type()->is_illegal() || l->type()->is_single_word()) i ++; else i += 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  }
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   241
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   242
  if (caller_state() != NULL) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   243
    caller_state()->print();
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   244
  }
1
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
void ValueStack::verify() {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   249
  assert(scope() != NULL, "scope must exist");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   250
  if (caller_state() != NULL) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   251
    assert(caller_state()->scope() == scope()->caller(), "invalid caller scope");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   252
    caller_state()->verify();
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   253
  }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   254
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   255
  if (kind() == Parsing) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   256
    assert(bci() == -99, "bci not defined during parsing");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   257
  } else {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   258
    assert(bci() >= -1, "bci out of range");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   259
    assert(bci() < scope()->method()->code_size(), "bci out of range");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   260
    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
   261
    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
   262
  }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   263
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   264
  int i;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   265
  for (i = 0; i < stack_size(); i++) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   266
    Value v = _stack.at(i);
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   267
    if (v == NULL) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   268
      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
   269
    } else if (v->type()->is_double_word()) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   270
      assert(_stack.at(i + 1) == NULL, "hi-word must be NULL");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   271
    }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   272
  }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   273
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   274
  for (i = 0; i < locals_size(); i++) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   275
    Value v = _locals.at(i);
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   276
    if (v != NULL && v->type()->is_double_word()) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   277
      assert(_locals.at(i + 1) == NULL, "hi-word must be NULL");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   278
    }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   279
  }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   280
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   281
  for_each_state_value(this, v,
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   282
    assert(v != NULL, "just test if state-iteration succeeds");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   283
  );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
#endif // PRODUCT