hotspot/src/share/vm/c1/c1_ValueStack.cpp
author roland
Tue, 29 Dec 2009 19:08:54 +0100
changeset 6745 a34ef8968a84
parent 5707 6c66849ed24e
child 7397 5b173b4ca846
permissions -rw-r--r--
6986046: C1 valuestack cleanup Summary: fixes an historical oddity in C1 with inlining where all of the expression stacks are kept in the topmost ValueStack instead of being in their respective ValueStacks. Reviewed-by: never Contributed-by: Christian Wimmer <cwimmer@uci.edu>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
     2
 * Copyright (c) 1999, 2006, 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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
#include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include "incls/_c1_ValueStack.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// Implementation of ValueStack
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    31
ValueStack::ValueStack(IRScope* scope, ValueStack* caller_state)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
: _scope(scope)
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    33
, _caller_state(caller_state)
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    34
, _bci(-99)
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    35
, _kind(Parsing)
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    36
, _locals(scope->method()->max_locals(), NULL)
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    37
, _stack(scope->method()->max_stack())
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    38
, _locks()
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
{
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    40
  verify();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    44
ValueStack::ValueStack(ValueStack* copy_from, Kind kind, int bci)
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    45
  : _scope(copy_from->scope())
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    46
  , _caller_state(copy_from->caller_state())
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    47
  , _bci(bci)
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    48
  , _kind(kind)
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    49
  , _locals()
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    50
  , _stack()
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    51
  , _locks(copy_from->locks_size())
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    52
{
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    53
  assert(kind != EmptyExceptionState || !Compilation::current()->env()->jvmti_can_access_local_variables(), "need locals");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    54
  if (kind != EmptyExceptionState) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    55
    // only allocate space if we need to copy the locals-array
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    56
    _locals = Values(copy_from->locals_size());
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    57
    _locals.appendAll(&copy_from->_locals);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  }
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    59
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    60
  if (kind != ExceptionState && kind != EmptyExceptionState) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    61
    if (kind == Parsing) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    62
      // stack will be modified, so reserve enough space to avoid resizing
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    63
      _stack = Values(scope()->method()->max_stack());
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    64
    } else {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    65
      // stack will not be modified, so do not waste space
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    66
      _stack = Values(copy_from->stack_size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    }
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    68
    _stack.appendAll(&copy_from->_stack);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    71
  _locks.appendAll(&copy_from->_locks);
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    72
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    73
  verify();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    77
bool ValueStack::is_same(ValueStack* s) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    78
  if (scope() != s->scope()) return false;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    79
  if (caller_state() != s->caller_state()) return false;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    80
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    81
  if (locals_size() != s->locals_size()) return false;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    82
  if (stack_size() != s->stack_size()) return false;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    83
  if (locks_size() != s->locks_size()) return false;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
    84
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  // compare each stack element with the corresponding stack element of s
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  int index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  Value value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  for_each_stack_value(this, index, value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    if (value->type()->tag() != s->stack_at(index)->type()->tag()) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  for_each_lock_value(this, index, value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    if (value != s->lock_at(index)) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
void ValueStack::clear_locals() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  for (int i = _locals.length() - 1; i >= 0; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    _locals.at_put(i, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
void ValueStack::pin_stack_for_linear_scan() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  for_each_state_value(this, v,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    if (v->as_Constant() == NULL && v->as_Local() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      v->pin(Instruction::PinStackForStateSplit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  );
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
// 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
   114
void ValueStack::apply(Values list, ValueVisitor* f) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  for (int i = 0; i < list.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    Value* va = list.adr_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    Value v0 = *va;
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   118
    if (v0 != NULL && !v0->type()->is_illegal()) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   119
      f->visit(va);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
#ifdef ASSERT
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   121
      Value v1 = *va;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   122
      assert(v1->type()->is_illegal() || v0->type()->tag() == v1->type()->tag(), "types must match");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   123
      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
   124
#endif
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   125
      if (v0->type()->is_double_word()) i++;
1
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   131
void ValueStack::values_do(ValueVisitor* f) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  ValueStack* state = this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  for_each_state(state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    apply(state->_locals, f);
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   135
    apply(state->_stack, f);
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   136
    apply(state->_locks, f);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
Values* ValueStack::pop_arguments(int argument_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  assert(stack_size() >= argument_size, "stack too small or too many arguments");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  int base = stack_size() - argument_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  Values* args = new Values(argument_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  for (int i = base; i < stack_size();) args->push(stack_at_inc(i));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  truncate_stack(base);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  return args;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   151
int ValueStack::total_locks_size() const {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   152
  int num_locks = 0;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   153
  const ValueStack* state = this;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   154
  for_each_state(state) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   155
    num_locks += state->locks_size();
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   156
  }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   157
  return num_locks;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   158
}
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   159
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   160
int ValueStack::lock(Value obj) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  _locks.push(obj);
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   162
  int num_locks = total_locks_size();
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   163
  scope()->set_min_number_of_locks(num_locks);
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   164
  return num_locks - 1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
int ValueStack::unlock() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  _locks.pop();
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   170
  return total_locks_size();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
void ValueStack::setup_phi_for_stack(BlockBegin* b, int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  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
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  ValueType* t = stack_at(index)->type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  Value phi = new Phi(t, b, -index - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  _stack[index] = phi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   181
  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
   182
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
void ValueStack::setup_phi_for_local(BlockBegin* b, int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  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
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  ValueType* t = local_at(index)->type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  Value phi = new Phi(t, b, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  store_local(index, phi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
#ifndef PRODUCT
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   193
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
void ValueStack::print() {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   195
  scope()->method()->print_name();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  if (stack_is_empty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    tty->print_cr("empty stack");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    InstructionPrinter ip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    for (int i = 0; i < stack_size();) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
      Value t = stack_at_inc(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
      tty->print("%2d  ", i);
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   203
      tty->print("%c%d ", t->type()->tchar(), t->id());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
      ip.print_instr(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  if (!no_active_locks()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    InstructionPrinter ip;
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   210
    for (int i = 0; i < locks_size(); i++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
      Value t = lock_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
      tty->print("lock %2d  ", i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
      if (t == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
        tty->print("this");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
      } else {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   216
        tty->print("%c%d ", t->type()->tchar(), t->id());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
        ip.print_instr(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  if (locals_size() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    InstructionPrinter ip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    for (int i = 0; i < locals_size();) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
      Value l = _locals[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
      tty->print("local %d ", i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
      if (l == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
        tty->print("null");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
        i ++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
      } else {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   231
        tty->print("%c%d ", l->type()->tchar(), l->id());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
        ip.print_instr(l);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
        if (l->type()->is_illegal() || l->type()->is_single_word()) i ++; else i += 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  }
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   238
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   239
  if (caller_state() != NULL) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   240
    caller_state()->print();
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   241
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
void ValueStack::verify() {
6745
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   246
  assert(scope() != NULL, "scope must exist");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   247
  if (caller_state() != NULL) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   248
    assert(caller_state()->scope() == scope()->caller(), "invalid caller scope");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   249
    caller_state()->verify();
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   250
  }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   251
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   252
  if (kind() == Parsing) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   253
    assert(bci() == -99, "bci not defined during parsing");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   254
  } else {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   255
    assert(bci() >= -1, "bci out of range");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   256
    assert(bci() < scope()->method()->code_size(), "bci out of range");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   257
    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
   258
    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
   259
  }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   260
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   261
  int i;
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   262
  for (i = 0; i < stack_size(); i++) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   263
    Value v = _stack.at(i);
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   264
    if (v == NULL) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   265
      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
   266
    } else if (v->type()->is_double_word()) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   267
      assert(_stack.at(i + 1) == NULL, "hi-word must be NULL");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   268
    }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   269
  }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   270
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   271
  for (i = 0; i < locals_size(); i++) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   272
    Value v = _locals.at(i);
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   273
    if (v != NULL && v->type()->is_double_word()) {
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   274
      assert(_locals.at(i + 1) == NULL, "hi-word must be NULL");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   275
    }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   276
  }
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   277
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   278
  for_each_state_value(this, v,
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   279
    assert(v != NULL, "just test if state-iteration succeeds");
a34ef8968a84 6986046: C1 valuestack cleanup
roland
parents: 5707
diff changeset
   280
  );
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
#endif // PRODUCT