Thu, 10 Oct 2013 15:44:12 +0200
8023014: CodeSweeperSweepNoFlushTest.java fails with HS crash
Summary: Ensure ensure correct initialization of compiler runtime
Reviewed-by: kvn, twisti
duke@435 | 1 | /* |
mikael@4153 | 2 | * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "c1/c1_IR.hpp" |
stefank@2314 | 27 | #include "c1/c1_InstructionPrinter.hpp" |
stefank@2314 | 28 | #include "c1/c1_ValueStack.hpp" |
duke@435 | 29 | |
duke@435 | 30 | |
duke@435 | 31 | // Implementation of ValueStack |
duke@435 | 32 | |
roland@2174 | 33 | ValueStack::ValueStack(IRScope* scope, ValueStack* caller_state) |
duke@435 | 34 | : _scope(scope) |
roland@2174 | 35 | , _caller_state(caller_state) |
roland@2174 | 36 | , _bci(-99) |
roland@2174 | 37 | , _kind(Parsing) |
roland@2174 | 38 | , _locals(scope->method()->max_locals(), NULL) |
roland@2174 | 39 | , _stack(scope->method()->max_stack()) |
roland@2174 | 40 | , _locks() |
duke@435 | 41 | { |
roland@2174 | 42 | verify(); |
duke@435 | 43 | } |
duke@435 | 44 | |
roland@2174 | 45 | |
roland@2174 | 46 | ValueStack::ValueStack(ValueStack* copy_from, Kind kind, int bci) |
roland@2174 | 47 | : _scope(copy_from->scope()) |
roland@2174 | 48 | , _caller_state(copy_from->caller_state()) |
roland@2174 | 49 | , _bci(bci) |
roland@2174 | 50 | , _kind(kind) |
roland@2174 | 51 | , _locals() |
roland@2174 | 52 | , _stack() |
roland@2174 | 53 | , _locks(copy_from->locks_size()) |
roland@2174 | 54 | { |
roland@2174 | 55 | assert(kind != EmptyExceptionState || !Compilation::current()->env()->jvmti_can_access_local_variables(), "need locals"); |
roland@2174 | 56 | if (kind != EmptyExceptionState) { |
roland@2174 | 57 | // only allocate space if we need to copy the locals-array |
roland@2174 | 58 | _locals = Values(copy_from->locals_size()); |
roland@2174 | 59 | _locals.appendAll(©_from->_locals); |
roland@2174 | 60 | } |
roland@2174 | 61 | |
roland@2174 | 62 | if (kind != ExceptionState && kind != EmptyExceptionState) { |
roland@2174 | 63 | if (kind == Parsing) { |
roland@2174 | 64 | // stack will be modified, so reserve enough space to avoid resizing |
roland@2174 | 65 | _stack = Values(scope()->method()->max_stack()); |
roland@2174 | 66 | } else { |
roland@2174 | 67 | // stack will not be modified, so do not waste space |
roland@2174 | 68 | _stack = Values(copy_from->stack_size()); |
roland@2174 | 69 | } |
roland@2174 | 70 | _stack.appendAll(©_from->_stack); |
roland@2174 | 71 | } |
roland@2174 | 72 | |
roland@2174 | 73 | _locks.appendAll(©_from->_locks); |
roland@2174 | 74 | |
roland@2174 | 75 | verify(); |
duke@435 | 76 | } |
duke@435 | 77 | |
duke@435 | 78 | |
roland@2174 | 79 | bool ValueStack::is_same(ValueStack* s) { |
roland@2174 | 80 | if (scope() != s->scope()) return false; |
roland@2174 | 81 | if (caller_state() != s->caller_state()) return false; |
duke@435 | 82 | |
roland@2174 | 83 | if (locals_size() != s->locals_size()) return false; |
roland@2174 | 84 | if (stack_size() != s->stack_size()) return false; |
roland@2174 | 85 | if (locks_size() != s->locks_size()) return false; |
duke@435 | 86 | |
duke@435 | 87 | // compare each stack element with the corresponding stack element of s |
duke@435 | 88 | int index; |
duke@435 | 89 | Value value; |
duke@435 | 90 | for_each_stack_value(this, index, value) { |
duke@435 | 91 | if (value->type()->tag() != s->stack_at(index)->type()->tag()) return false; |
duke@435 | 92 | } |
duke@435 | 93 | for_each_lock_value(this, index, value) { |
duke@435 | 94 | if (value != s->lock_at(index)) return false; |
duke@435 | 95 | } |
duke@435 | 96 | return true; |
duke@435 | 97 | } |
duke@435 | 98 | |
duke@435 | 99 | void ValueStack::clear_locals() { |
duke@435 | 100 | for (int i = _locals.length() - 1; i >= 0; i--) { |
duke@435 | 101 | _locals.at_put(i, NULL); |
duke@435 | 102 | } |
duke@435 | 103 | } |
duke@435 | 104 | |
duke@435 | 105 | |
duke@435 | 106 | void ValueStack::pin_stack_for_linear_scan() { |
duke@435 | 107 | for_each_state_value(this, v, |
duke@435 | 108 | if (v->as_Constant() == NULL && v->as_Local() == NULL) { |
duke@435 | 109 | v->pin(Instruction::PinStackForStateSplit); |
duke@435 | 110 | } |
duke@435 | 111 | ); |
duke@435 | 112 | } |
duke@435 | 113 | |
duke@435 | 114 | |
duke@435 | 115 | // apply function to all values of a list; factored out from values_do(f) |
iveresov@1939 | 116 | void ValueStack::apply(Values list, ValueVisitor* f) { |
duke@435 | 117 | for (int i = 0; i < list.length(); i++) { |
duke@435 | 118 | Value* va = list.adr_at(i); |
duke@435 | 119 | Value v0 = *va; |
roland@2174 | 120 | if (v0 != NULL && !v0->type()->is_illegal()) { |
roland@2174 | 121 | f->visit(va); |
duke@435 | 122 | #ifdef ASSERT |
roland@2174 | 123 | Value v1 = *va; |
roland@2174 | 124 | assert(v1->type()->is_illegal() || v0->type()->tag() == v1->type()->tag(), "types must match"); |
roland@2174 | 125 | assert(!v1->type()->is_double_word() || list.at(i + 1) == NULL, "hi-word of doubleword value must be NULL"); |
duke@435 | 126 | #endif |
roland@2174 | 127 | if (v0->type()->is_double_word()) i++; |
duke@435 | 128 | } |
duke@435 | 129 | } |
duke@435 | 130 | } |
duke@435 | 131 | |
duke@435 | 132 | |
iveresov@1939 | 133 | void ValueStack::values_do(ValueVisitor* f) { |
duke@435 | 134 | ValueStack* state = this; |
duke@435 | 135 | for_each_state(state) { |
duke@435 | 136 | apply(state->_locals, f); |
roland@2174 | 137 | apply(state->_stack, f); |
roland@2174 | 138 | apply(state->_locks, f); |
duke@435 | 139 | } |
duke@435 | 140 | } |
duke@435 | 141 | |
duke@435 | 142 | |
duke@435 | 143 | Values* ValueStack::pop_arguments(int argument_size) { |
duke@435 | 144 | assert(stack_size() >= argument_size, "stack too small or too many arguments"); |
duke@435 | 145 | int base = stack_size() - argument_size; |
duke@435 | 146 | Values* args = new Values(argument_size); |
duke@435 | 147 | for (int i = base; i < stack_size();) args->push(stack_at_inc(i)); |
duke@435 | 148 | truncate_stack(base); |
duke@435 | 149 | return args; |
duke@435 | 150 | } |
duke@435 | 151 | |
duke@435 | 152 | |
roland@2174 | 153 | int ValueStack::total_locks_size() const { |
roland@2174 | 154 | int num_locks = 0; |
roland@2174 | 155 | const ValueStack* state = this; |
roland@2174 | 156 | for_each_state(state) { |
roland@2174 | 157 | num_locks += state->locks_size(); |
roland@2174 | 158 | } |
roland@2174 | 159 | return num_locks; |
roland@2174 | 160 | } |
roland@2174 | 161 | |
roland@2174 | 162 | int ValueStack::lock(Value obj) { |
duke@435 | 163 | _locks.push(obj); |
roland@2174 | 164 | int num_locks = total_locks_size(); |
roland@2174 | 165 | scope()->set_min_number_of_locks(num_locks); |
roland@2174 | 166 | return num_locks - 1; |
duke@435 | 167 | } |
duke@435 | 168 | |
duke@435 | 169 | |
duke@435 | 170 | int ValueStack::unlock() { |
duke@435 | 171 | _locks.pop(); |
roland@2174 | 172 | return total_locks_size(); |
duke@435 | 173 | } |
duke@435 | 174 | |
duke@435 | 175 | |
duke@435 | 176 | void ValueStack::setup_phi_for_stack(BlockBegin* b, int index) { |
duke@435 | 177 | assert(stack_at(index)->as_Phi() == NULL || stack_at(index)->as_Phi()->block() != b, "phi function already created"); |
duke@435 | 178 | |
duke@435 | 179 | ValueType* t = stack_at(index)->type(); |
duke@435 | 180 | Value phi = new Phi(t, b, -index - 1); |
duke@435 | 181 | _stack[index] = phi; |
duke@435 | 182 | |
roland@2174 | 183 | assert(!t->is_double_word() || _stack.at(index + 1) == NULL, "hi-word of doubleword value must be NULL"); |
duke@435 | 184 | } |
duke@435 | 185 | |
duke@435 | 186 | void ValueStack::setup_phi_for_local(BlockBegin* b, int index) { |
duke@435 | 187 | assert(local_at(index)->as_Phi() == NULL || local_at(index)->as_Phi()->block() != b, "phi function already created"); |
duke@435 | 188 | |
duke@435 | 189 | ValueType* t = local_at(index)->type(); |
duke@435 | 190 | Value phi = new Phi(t, b, index); |
duke@435 | 191 | store_local(index, phi); |
duke@435 | 192 | } |
duke@435 | 193 | |
duke@435 | 194 | #ifndef PRODUCT |
roland@2174 | 195 | |
duke@435 | 196 | void ValueStack::print() { |
roland@2174 | 197 | scope()->method()->print_name(); |
twisti@3969 | 198 | tty->cr(); |
duke@435 | 199 | if (stack_is_empty()) { |
duke@435 | 200 | tty->print_cr("empty stack"); |
duke@435 | 201 | } else { |
duke@435 | 202 | InstructionPrinter ip; |
duke@435 | 203 | for (int i = 0; i < stack_size();) { |
duke@435 | 204 | Value t = stack_at_inc(i); |
duke@435 | 205 | tty->print("%2d ", i); |
roland@2174 | 206 | tty->print("%c%d ", t->type()->tchar(), t->id()); |
duke@435 | 207 | ip.print_instr(t); |
duke@435 | 208 | tty->cr(); |
duke@435 | 209 | } |
duke@435 | 210 | } |
duke@435 | 211 | if (!no_active_locks()) { |
duke@435 | 212 | InstructionPrinter ip; |
roland@2174 | 213 | for (int i = 0; i < locks_size(); i++) { |
duke@435 | 214 | Value t = lock_at(i); |
duke@435 | 215 | tty->print("lock %2d ", i); |
duke@435 | 216 | if (t == NULL) { |
duke@435 | 217 | tty->print("this"); |
duke@435 | 218 | } else { |
roland@2174 | 219 | tty->print("%c%d ", t->type()->tchar(), t->id()); |
duke@435 | 220 | ip.print_instr(t); |
duke@435 | 221 | } |
duke@435 | 222 | tty->cr(); |
duke@435 | 223 | } |
duke@435 | 224 | } |
duke@435 | 225 | if (locals_size() > 0) { |
duke@435 | 226 | InstructionPrinter ip; |
duke@435 | 227 | for (int i = 0; i < locals_size();) { |
duke@435 | 228 | Value l = _locals[i]; |
duke@435 | 229 | tty->print("local %d ", i); |
duke@435 | 230 | if (l == NULL) { |
duke@435 | 231 | tty->print("null"); |
duke@435 | 232 | i ++; |
duke@435 | 233 | } else { |
roland@2174 | 234 | tty->print("%c%d ", l->type()->tchar(), l->id()); |
duke@435 | 235 | ip.print_instr(l); |
duke@435 | 236 | if (l->type()->is_illegal() || l->type()->is_single_word()) i ++; else i += 2; |
duke@435 | 237 | } |
duke@435 | 238 | tty->cr(); |
duke@435 | 239 | } |
duke@435 | 240 | } |
roland@2174 | 241 | |
roland@2174 | 242 | if (caller_state() != NULL) { |
roland@2174 | 243 | caller_state()->print(); |
roland@2174 | 244 | } |
duke@435 | 245 | } |
duke@435 | 246 | |
duke@435 | 247 | |
duke@435 | 248 | void ValueStack::verify() { |
roland@2174 | 249 | assert(scope() != NULL, "scope must exist"); |
roland@2174 | 250 | if (caller_state() != NULL) { |
roland@2174 | 251 | assert(caller_state()->scope() == scope()->caller(), "invalid caller scope"); |
roland@2174 | 252 | caller_state()->verify(); |
roland@2174 | 253 | } |
roland@2174 | 254 | |
roland@2174 | 255 | if (kind() == Parsing) { |
roland@2174 | 256 | assert(bci() == -99, "bci not defined during parsing"); |
roland@2174 | 257 | } else { |
roland@2174 | 258 | assert(bci() >= -1, "bci out of range"); |
roland@2174 | 259 | assert(bci() < scope()->method()->code_size(), "bci out of range"); |
roland@2174 | 260 | assert(bci() == SynchronizationEntryBCI || Bytecodes::is_defined(scope()->method()->java_code_at_bci(bci())), "make sure bci points at a real bytecode"); |
roland@2174 | 261 | assert(scope()->method()->liveness_at_bci(bci()).is_valid(), "liveness at bci must be valid"); |
roland@2174 | 262 | } |
roland@2174 | 263 | |
roland@2174 | 264 | int i; |
roland@2174 | 265 | for (i = 0; i < stack_size(); i++) { |
roland@2174 | 266 | Value v = _stack.at(i); |
roland@2174 | 267 | if (v == NULL) { |
roland@2174 | 268 | assert(_stack.at(i - 1)->type()->is_double_word(), "only hi-words are NULL on stack"); |
roland@2174 | 269 | } else if (v->type()->is_double_word()) { |
roland@2174 | 270 | assert(_stack.at(i + 1) == NULL, "hi-word must be NULL"); |
roland@2174 | 271 | } |
roland@2174 | 272 | } |
roland@2174 | 273 | |
roland@2174 | 274 | for (i = 0; i < locals_size(); i++) { |
roland@2174 | 275 | Value v = _locals.at(i); |
roland@2174 | 276 | if (v != NULL && v->type()->is_double_word()) { |
roland@2174 | 277 | assert(_locals.at(i + 1) == NULL, "hi-word must be NULL"); |
roland@2174 | 278 | } |
roland@2174 | 279 | } |
roland@2174 | 280 | |
roland@2174 | 281 | for_each_state_value(this, v, |
roland@2174 | 282 | assert(v != NULL, "just test if state-iteration succeeds"); |
roland@2174 | 283 | ); |
duke@435 | 284 | } |
duke@435 | 285 | #endif // PRODUCT |