src/share/vm/ci/ciTypeFlow.cpp

Tue, 17 Oct 2017 12:58:25 +0800

author
aoqi
date
Tue, 17 Oct 2017 12:58:25 +0800
changeset 7994
04ff2f6cd0eb
parent 7546
4181e5e64dd0
parent 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "ci/ciConstant.hpp"
aoqi@0 27 #include "ci/ciField.hpp"
aoqi@0 28 #include "ci/ciMethod.hpp"
aoqi@0 29 #include "ci/ciMethodData.hpp"
aoqi@0 30 #include "ci/ciObjArrayKlass.hpp"
aoqi@0 31 #include "ci/ciStreams.hpp"
aoqi@0 32 #include "ci/ciTypeArrayKlass.hpp"
aoqi@0 33 #include "ci/ciTypeFlow.hpp"
aoqi@0 34 #include "compiler/compileLog.hpp"
aoqi@0 35 #include "interpreter/bytecode.hpp"
aoqi@0 36 #include "interpreter/bytecodes.hpp"
aoqi@0 37 #include "memory/allocation.inline.hpp"
vlivanov@7385 38 #include "opto/compile.hpp"
goetz@7546 39 #include "opto/node.hpp"
aoqi@0 40 #include "runtime/deoptimization.hpp"
aoqi@0 41 #include "utilities/growableArray.hpp"
aoqi@0 42
aoqi@0 43 // ciTypeFlow::JsrSet
aoqi@0 44 //
aoqi@0 45 // A JsrSet represents some set of JsrRecords. This class
aoqi@0 46 // is used to record a set of all jsr routines which we permit
aoqi@0 47 // execution to return (ret) from.
aoqi@0 48 //
aoqi@0 49 // During abstract interpretation, JsrSets are used to determine
aoqi@0 50 // whether two paths which reach a given block are unique, and
aoqi@0 51 // should be cloned apart, or are compatible, and should merge
aoqi@0 52 // together.
aoqi@0 53
aoqi@0 54 // ------------------------------------------------------------------
aoqi@0 55 // ciTypeFlow::JsrSet::JsrSet
aoqi@0 56 ciTypeFlow::JsrSet::JsrSet(Arena* arena, int default_len) {
aoqi@0 57 if (arena != NULL) {
aoqi@0 58 // Allocate growable array in Arena.
aoqi@0 59 _set = new (arena) GrowableArray<JsrRecord*>(arena, default_len, 0, NULL);
aoqi@0 60 } else {
aoqi@0 61 // Allocate growable array in current ResourceArea.
aoqi@0 62 _set = new GrowableArray<JsrRecord*>(4, 0, NULL, false);
aoqi@0 63 }
aoqi@0 64 }
aoqi@0 65
aoqi@0 66 // ------------------------------------------------------------------
aoqi@0 67 // ciTypeFlow::JsrSet::copy_into
aoqi@0 68 void ciTypeFlow::JsrSet::copy_into(JsrSet* jsrs) {
aoqi@0 69 int len = size();
aoqi@0 70 jsrs->_set->clear();
aoqi@0 71 for (int i = 0; i < len; i++) {
aoqi@0 72 jsrs->_set->append(_set->at(i));
aoqi@0 73 }
aoqi@0 74 }
aoqi@0 75
aoqi@0 76 // ------------------------------------------------------------------
aoqi@0 77 // ciTypeFlow::JsrSet::is_compatible_with
aoqi@0 78 //
aoqi@0 79 // !!!! MISGIVINGS ABOUT THIS... disregard
aoqi@0 80 //
aoqi@0 81 // Is this JsrSet compatible with some other JsrSet?
aoqi@0 82 //
aoqi@0 83 // In set-theoretic terms, a JsrSet can be viewed as a partial function
aoqi@0 84 // from entry addresses to return addresses. Two JsrSets A and B are
aoqi@0 85 // compatible iff
aoqi@0 86 //
aoqi@0 87 // For any x,
aoqi@0 88 // A(x) defined and B(x) defined implies A(x) == B(x)
aoqi@0 89 //
aoqi@0 90 // Less formally, two JsrSets are compatible when they have identical
aoqi@0 91 // return addresses for any entry addresses they share in common.
aoqi@0 92 bool ciTypeFlow::JsrSet::is_compatible_with(JsrSet* other) {
aoqi@0 93 // Walk through both sets in parallel. If the same entry address
aoqi@0 94 // appears in both sets, then the return address must match for
aoqi@0 95 // the sets to be compatible.
aoqi@0 96 int size1 = size();
aoqi@0 97 int size2 = other->size();
aoqi@0 98
aoqi@0 99 // Special case. If nothing is on the jsr stack, then there can
aoqi@0 100 // be no ret.
aoqi@0 101 if (size2 == 0) {
aoqi@0 102 return true;
aoqi@0 103 } else if (size1 != size2) {
aoqi@0 104 return false;
aoqi@0 105 } else {
aoqi@0 106 for (int i = 0; i < size1; i++) {
aoqi@0 107 JsrRecord* record1 = record_at(i);
aoqi@0 108 JsrRecord* record2 = other->record_at(i);
aoqi@0 109 if (record1->entry_address() != record2->entry_address() ||
aoqi@0 110 record1->return_address() != record2->return_address()) {
aoqi@0 111 return false;
aoqi@0 112 }
aoqi@0 113 }
aoqi@0 114 return true;
aoqi@0 115 }
aoqi@0 116
aoqi@0 117 #if 0
aoqi@0 118 int pos1 = 0;
aoqi@0 119 int pos2 = 0;
aoqi@0 120 int size1 = size();
aoqi@0 121 int size2 = other->size();
aoqi@0 122 while (pos1 < size1 && pos2 < size2) {
aoqi@0 123 JsrRecord* record1 = record_at(pos1);
aoqi@0 124 JsrRecord* record2 = other->record_at(pos2);
aoqi@0 125 int entry1 = record1->entry_address();
aoqi@0 126 int entry2 = record2->entry_address();
aoqi@0 127 if (entry1 < entry2) {
aoqi@0 128 pos1++;
aoqi@0 129 } else if (entry1 > entry2) {
aoqi@0 130 pos2++;
aoqi@0 131 } else {
aoqi@0 132 if (record1->return_address() == record2->return_address()) {
aoqi@0 133 pos1++;
aoqi@0 134 pos2++;
aoqi@0 135 } else {
aoqi@0 136 // These two JsrSets are incompatible.
aoqi@0 137 return false;
aoqi@0 138 }
aoqi@0 139 }
aoqi@0 140 }
aoqi@0 141 // The two JsrSets agree.
aoqi@0 142 return true;
aoqi@0 143 #endif
aoqi@0 144 }
aoqi@0 145
aoqi@0 146 // ------------------------------------------------------------------
aoqi@0 147 // ciTypeFlow::JsrSet::insert_jsr_record
aoqi@0 148 //
aoqi@0 149 // Insert the given JsrRecord into the JsrSet, maintaining the order
aoqi@0 150 // of the set and replacing any element with the same entry address.
aoqi@0 151 void ciTypeFlow::JsrSet::insert_jsr_record(JsrRecord* record) {
aoqi@0 152 int len = size();
aoqi@0 153 int entry = record->entry_address();
aoqi@0 154 int pos = 0;
aoqi@0 155 for ( ; pos < len; pos++) {
aoqi@0 156 JsrRecord* current = record_at(pos);
aoqi@0 157 if (entry == current->entry_address()) {
aoqi@0 158 // Stomp over this entry.
aoqi@0 159 _set->at_put(pos, record);
aoqi@0 160 assert(size() == len, "must be same size");
aoqi@0 161 return;
aoqi@0 162 } else if (entry < current->entry_address()) {
aoqi@0 163 break;
aoqi@0 164 }
aoqi@0 165 }
aoqi@0 166
aoqi@0 167 // Insert the record into the list.
aoqi@0 168 JsrRecord* swap = record;
aoqi@0 169 JsrRecord* temp = NULL;
aoqi@0 170 for ( ; pos < len; pos++) {
aoqi@0 171 temp = _set->at(pos);
aoqi@0 172 _set->at_put(pos, swap);
aoqi@0 173 swap = temp;
aoqi@0 174 }
aoqi@0 175 _set->append(swap);
aoqi@0 176 assert(size() == len+1, "must be larger");
aoqi@0 177 }
aoqi@0 178
aoqi@0 179 // ------------------------------------------------------------------
aoqi@0 180 // ciTypeFlow::JsrSet::remove_jsr_record
aoqi@0 181 //
aoqi@0 182 // Remove the JsrRecord with the given return address from the JsrSet.
aoqi@0 183 void ciTypeFlow::JsrSet::remove_jsr_record(int return_address) {
aoqi@0 184 int len = size();
aoqi@0 185 for (int i = 0; i < len; i++) {
aoqi@0 186 if (record_at(i)->return_address() == return_address) {
aoqi@0 187 // We have found the proper entry. Remove it from the
aoqi@0 188 // JsrSet and exit.
aoqi@0 189 for (int j = i+1; j < len ; j++) {
aoqi@0 190 _set->at_put(j-1, _set->at(j));
aoqi@0 191 }
aoqi@0 192 _set->trunc_to(len-1);
aoqi@0 193 assert(size() == len-1, "must be smaller");
aoqi@0 194 return;
aoqi@0 195 }
aoqi@0 196 }
aoqi@0 197 assert(false, "verify: returning from invalid subroutine");
aoqi@0 198 }
aoqi@0 199
aoqi@0 200 // ------------------------------------------------------------------
aoqi@0 201 // ciTypeFlow::JsrSet::apply_control
aoqi@0 202 //
aoqi@0 203 // Apply the effect of a control-flow bytecode on the JsrSet. The
aoqi@0 204 // only bytecodes that modify the JsrSet are jsr and ret.
aoqi@0 205 void ciTypeFlow::JsrSet::apply_control(ciTypeFlow* analyzer,
aoqi@0 206 ciBytecodeStream* str,
aoqi@0 207 ciTypeFlow::StateVector* state) {
aoqi@0 208 Bytecodes::Code code = str->cur_bc();
aoqi@0 209 if (code == Bytecodes::_jsr) {
aoqi@0 210 JsrRecord* record =
aoqi@0 211 analyzer->make_jsr_record(str->get_dest(), str->next_bci());
aoqi@0 212 insert_jsr_record(record);
aoqi@0 213 } else if (code == Bytecodes::_jsr_w) {
aoqi@0 214 JsrRecord* record =
aoqi@0 215 analyzer->make_jsr_record(str->get_far_dest(), str->next_bci());
aoqi@0 216 insert_jsr_record(record);
aoqi@0 217 } else if (code == Bytecodes::_ret) {
aoqi@0 218 Cell local = state->local(str->get_index());
aoqi@0 219 ciType* return_address = state->type_at(local);
aoqi@0 220 assert(return_address->is_return_address(), "verify: wrong type");
aoqi@0 221 if (size() == 0) {
aoqi@0 222 // Ret-state underflow: Hit a ret w/o any previous jsrs. Bail out.
aoqi@0 223 // This can happen when a loop is inside a finally clause (4614060).
aoqi@0 224 analyzer->record_failure("OSR in finally clause");
aoqi@0 225 return;
aoqi@0 226 }
aoqi@0 227 remove_jsr_record(return_address->as_return_address()->bci());
aoqi@0 228 }
aoqi@0 229 }
aoqi@0 230
aoqi@0 231 #ifndef PRODUCT
aoqi@0 232 // ------------------------------------------------------------------
aoqi@0 233 // ciTypeFlow::JsrSet::print_on
aoqi@0 234 void ciTypeFlow::JsrSet::print_on(outputStream* st) const {
aoqi@0 235 st->print("{ ");
aoqi@0 236 int num_elements = size();
aoqi@0 237 if (num_elements > 0) {
aoqi@0 238 int i = 0;
aoqi@0 239 for( ; i < num_elements - 1; i++) {
aoqi@0 240 _set->at(i)->print_on(st);
aoqi@0 241 st->print(", ");
aoqi@0 242 }
aoqi@0 243 _set->at(i)->print_on(st);
aoqi@0 244 st->print(" ");
aoqi@0 245 }
aoqi@0 246 st->print("}");
aoqi@0 247 }
aoqi@0 248 #endif
aoqi@0 249
aoqi@0 250 // ciTypeFlow::StateVector
aoqi@0 251 //
aoqi@0 252 // A StateVector summarizes the type information at some point in
aoqi@0 253 // the program.
aoqi@0 254
aoqi@0 255 // ------------------------------------------------------------------
aoqi@0 256 // ciTypeFlow::StateVector::type_meet
aoqi@0 257 //
aoqi@0 258 // Meet two types.
aoqi@0 259 //
aoqi@0 260 // The semi-lattice of types use by this analysis are modeled on those
aoqi@0 261 // of the verifier. The lattice is as follows:
aoqi@0 262 //
aoqi@0 263 // top_type() >= all non-extremal types >= bottom_type
aoqi@0 264 // and
aoqi@0 265 // Every primitive type is comparable only with itself. The meet of
aoqi@0 266 // reference types is determined by their kind: instance class,
aoqi@0 267 // interface, or array class. The meet of two types of the same
aoqi@0 268 // kind is their least common ancestor. The meet of two types of
aoqi@0 269 // different kinds is always java.lang.Object.
aoqi@0 270 ciType* ciTypeFlow::StateVector::type_meet_internal(ciType* t1, ciType* t2, ciTypeFlow* analyzer) {
aoqi@0 271 assert(t1 != t2, "checked in caller");
aoqi@0 272 if (t1->equals(top_type())) {
aoqi@0 273 return t2;
aoqi@0 274 } else if (t2->equals(top_type())) {
aoqi@0 275 return t1;
aoqi@0 276 } else if (t1->is_primitive_type() || t2->is_primitive_type()) {
aoqi@0 277 // Special case null_type. null_type meet any reference type T
aoqi@0 278 // is T. null_type meet null_type is null_type.
aoqi@0 279 if (t1->equals(null_type())) {
aoqi@0 280 if (!t2->is_primitive_type() || t2->equals(null_type())) {
aoqi@0 281 return t2;
aoqi@0 282 }
aoqi@0 283 } else if (t2->equals(null_type())) {
aoqi@0 284 if (!t1->is_primitive_type()) {
aoqi@0 285 return t1;
aoqi@0 286 }
aoqi@0 287 }
aoqi@0 288
aoqi@0 289 // At least one of the two types is a non-top primitive type.
aoqi@0 290 // The other type is not equal to it. Fall to bottom.
aoqi@0 291 return bottom_type();
aoqi@0 292 } else {
aoqi@0 293 // Both types are non-top non-primitive types. That is,
aoqi@0 294 // both types are either instanceKlasses or arrayKlasses.
aoqi@0 295 ciKlass* object_klass = analyzer->env()->Object_klass();
aoqi@0 296 ciKlass* k1 = t1->as_klass();
aoqi@0 297 ciKlass* k2 = t2->as_klass();
aoqi@0 298 if (k1->equals(object_klass) || k2->equals(object_klass)) {
aoqi@0 299 return object_klass;
aoqi@0 300 } else if (!k1->is_loaded() || !k2->is_loaded()) {
aoqi@0 301 // Unloaded classes fall to java.lang.Object at a merge.
aoqi@0 302 return object_klass;
aoqi@0 303 } else if (k1->is_interface() != k2->is_interface()) {
aoqi@0 304 // When an interface meets a non-interface, we get Object;
aoqi@0 305 // This is what the verifier does.
aoqi@0 306 return object_klass;
aoqi@0 307 } else if (k1->is_array_klass() || k2->is_array_klass()) {
aoqi@0 308 // When an array meets a non-array, we get Object.
aoqi@0 309 // When objArray meets typeArray, we also get Object.
aoqi@0 310 // And when typeArray meets different typeArray, we again get Object.
aoqi@0 311 // But when objArray meets objArray, we look carefully at element types.
aoqi@0 312 if (k1->is_obj_array_klass() && k2->is_obj_array_klass()) {
aoqi@0 313 // Meet the element types, then construct the corresponding array type.
aoqi@0 314 ciKlass* elem1 = k1->as_obj_array_klass()->element_klass();
aoqi@0 315 ciKlass* elem2 = k2->as_obj_array_klass()->element_klass();
aoqi@0 316 ciKlass* elem = type_meet_internal(elem1, elem2, analyzer)->as_klass();
aoqi@0 317 // Do an easy shortcut if one type is a super of the other.
aoqi@0 318 if (elem == elem1) {
aoqi@0 319 assert(k1 == ciObjArrayKlass::make(elem), "shortcut is OK");
aoqi@0 320 return k1;
aoqi@0 321 } else if (elem == elem2) {
aoqi@0 322 assert(k2 == ciObjArrayKlass::make(elem), "shortcut is OK");
aoqi@0 323 return k2;
aoqi@0 324 } else {
aoqi@0 325 return ciObjArrayKlass::make(elem);
aoqi@0 326 }
aoqi@0 327 } else {
aoqi@0 328 return object_klass;
aoqi@0 329 }
aoqi@0 330 } else {
aoqi@0 331 // Must be two plain old instance klasses.
aoqi@0 332 assert(k1->is_instance_klass(), "previous cases handle non-instances");
aoqi@0 333 assert(k2->is_instance_klass(), "previous cases handle non-instances");
aoqi@0 334 return k1->least_common_ancestor(k2);
aoqi@0 335 }
aoqi@0 336 }
aoqi@0 337 }
aoqi@0 338
aoqi@0 339
aoqi@0 340 // ------------------------------------------------------------------
aoqi@0 341 // ciTypeFlow::StateVector::StateVector
aoqi@0 342 //
aoqi@0 343 // Build a new state vector
aoqi@0 344 ciTypeFlow::StateVector::StateVector(ciTypeFlow* analyzer) {
aoqi@0 345 _outer = analyzer;
aoqi@0 346 _stack_size = -1;
aoqi@0 347 _monitor_count = -1;
aoqi@0 348 // Allocate the _types array
aoqi@0 349 int max_cells = analyzer->max_cells();
aoqi@0 350 _types = (ciType**)analyzer->arena()->Amalloc(sizeof(ciType*) * max_cells);
aoqi@0 351 for (int i=0; i<max_cells; i++) {
aoqi@0 352 _types[i] = top_type();
aoqi@0 353 }
aoqi@0 354 _trap_bci = -1;
aoqi@0 355 _trap_index = 0;
aoqi@0 356 _def_locals.clear();
aoqi@0 357 }
aoqi@0 358
aoqi@0 359
aoqi@0 360 // ------------------------------------------------------------------
aoqi@0 361 // ciTypeFlow::get_start_state
aoqi@0 362 //
aoqi@0 363 // Set this vector to the method entry state.
aoqi@0 364 const ciTypeFlow::StateVector* ciTypeFlow::get_start_state() {
aoqi@0 365 StateVector* state = new StateVector(this);
aoqi@0 366 if (is_osr_flow()) {
aoqi@0 367 ciTypeFlow* non_osr_flow = method()->get_flow_analysis();
aoqi@0 368 if (non_osr_flow->failing()) {
aoqi@0 369 record_failure(non_osr_flow->failure_reason());
aoqi@0 370 return NULL;
aoqi@0 371 }
aoqi@0 372 JsrSet* jsrs = new JsrSet(NULL, 16);
aoqi@0 373 Block* non_osr_block = non_osr_flow->existing_block_at(start_bci(), jsrs);
aoqi@0 374 if (non_osr_block == NULL) {
aoqi@0 375 record_failure("cannot reach OSR point");
aoqi@0 376 return NULL;
aoqi@0 377 }
aoqi@0 378 // load up the non-OSR state at this point
aoqi@0 379 non_osr_block->copy_state_into(state);
aoqi@0 380 int non_osr_start = non_osr_block->start();
aoqi@0 381 if (non_osr_start != start_bci()) {
aoqi@0 382 // must flow forward from it
aoqi@0 383 if (CITraceTypeFlow) {
aoqi@0 384 tty->print_cr(">> Interpreting pre-OSR block %d:", non_osr_start);
aoqi@0 385 }
aoqi@0 386 Block* block = block_at(non_osr_start, jsrs);
aoqi@0 387 assert(block->limit() == start_bci(), "must flow forward to start");
aoqi@0 388 flow_block(block, state, jsrs);
aoqi@0 389 }
aoqi@0 390 return state;
aoqi@0 391 // Note: The code below would be an incorrect for an OSR flow,
aoqi@0 392 // even if it were possible for an OSR entry point to be at bci zero.
aoqi@0 393 }
aoqi@0 394 // "Push" the method signature into the first few locals.
aoqi@0 395 state->set_stack_size(-max_locals());
aoqi@0 396 if (!method()->is_static()) {
aoqi@0 397 state->push(method()->holder());
aoqi@0 398 assert(state->tos() == state->local(0), "");
aoqi@0 399 }
aoqi@0 400 for (ciSignatureStream str(method()->signature());
aoqi@0 401 !str.at_return_type();
aoqi@0 402 str.next()) {
aoqi@0 403 state->push_translate(str.type());
aoqi@0 404 }
aoqi@0 405 // Set the rest of the locals to bottom.
aoqi@0 406 Cell cell = state->next_cell(state->tos());
aoqi@0 407 state->set_stack_size(0);
aoqi@0 408 int limit = state->limit_cell();
aoqi@0 409 for (; cell < limit; cell = state->next_cell(cell)) {
aoqi@0 410 state->set_type_at(cell, state->bottom_type());
aoqi@0 411 }
aoqi@0 412 // Lock an object, if necessary.
aoqi@0 413 state->set_monitor_count(method()->is_synchronized() ? 1 : 0);
aoqi@0 414 return state;
aoqi@0 415 }
aoqi@0 416
aoqi@0 417 // ------------------------------------------------------------------
aoqi@0 418 // ciTypeFlow::StateVector::copy_into
aoqi@0 419 //
aoqi@0 420 // Copy our value into some other StateVector
aoqi@0 421 void ciTypeFlow::StateVector::copy_into(ciTypeFlow::StateVector* copy)
aoqi@0 422 const {
aoqi@0 423 copy->set_stack_size(stack_size());
aoqi@0 424 copy->set_monitor_count(monitor_count());
aoqi@0 425 Cell limit = limit_cell();
aoqi@0 426 for (Cell c = start_cell(); c < limit; c = next_cell(c)) {
aoqi@0 427 copy->set_type_at(c, type_at(c));
aoqi@0 428 }
aoqi@0 429 }
aoqi@0 430
aoqi@0 431 // ------------------------------------------------------------------
aoqi@0 432 // ciTypeFlow::StateVector::meet
aoqi@0 433 //
aoqi@0 434 // Meets this StateVector with another, destructively modifying this
aoqi@0 435 // one. Returns true if any modification takes place.
aoqi@0 436 bool ciTypeFlow::StateVector::meet(const ciTypeFlow::StateVector* incoming) {
aoqi@0 437 if (monitor_count() == -1) {
aoqi@0 438 set_monitor_count(incoming->monitor_count());
aoqi@0 439 }
aoqi@0 440 assert(monitor_count() == incoming->monitor_count(), "monitors must match");
aoqi@0 441
aoqi@0 442 if (stack_size() == -1) {
aoqi@0 443 set_stack_size(incoming->stack_size());
aoqi@0 444 Cell limit = limit_cell();
aoqi@0 445 #ifdef ASSERT
aoqi@0 446 { for (Cell c = start_cell(); c < limit; c = next_cell(c)) {
aoqi@0 447 assert(type_at(c) == top_type(), "");
aoqi@0 448 } }
aoqi@0 449 #endif
aoqi@0 450 // Make a simple copy of the incoming state.
aoqi@0 451 for (Cell c = start_cell(); c < limit; c = next_cell(c)) {
aoqi@0 452 set_type_at(c, incoming->type_at(c));
aoqi@0 453 }
aoqi@0 454 return true; // it is always different the first time
aoqi@0 455 }
aoqi@0 456 #ifdef ASSERT
aoqi@0 457 if (stack_size() != incoming->stack_size()) {
aoqi@0 458 _outer->method()->print_codes();
aoqi@0 459 tty->print_cr("!!!! Stack size conflict");
aoqi@0 460 tty->print_cr("Current state:");
aoqi@0 461 print_on(tty);
aoqi@0 462 tty->print_cr("Incoming state:");
aoqi@0 463 ((StateVector*)incoming)->print_on(tty);
aoqi@0 464 }
aoqi@0 465 #endif
aoqi@0 466 assert(stack_size() == incoming->stack_size(), "sanity");
aoqi@0 467
aoqi@0 468 bool different = false;
aoqi@0 469 Cell limit = limit_cell();
aoqi@0 470 for (Cell c = start_cell(); c < limit; c = next_cell(c)) {
aoqi@0 471 ciType* t1 = type_at(c);
aoqi@0 472 ciType* t2 = incoming->type_at(c);
aoqi@0 473 if (!t1->equals(t2)) {
aoqi@0 474 ciType* new_type = type_meet(t1, t2);
aoqi@0 475 if (!t1->equals(new_type)) {
aoqi@0 476 set_type_at(c, new_type);
aoqi@0 477 different = true;
aoqi@0 478 }
aoqi@0 479 }
aoqi@0 480 }
aoqi@0 481 return different;
aoqi@0 482 }
aoqi@0 483
aoqi@0 484 // ------------------------------------------------------------------
aoqi@0 485 // ciTypeFlow::StateVector::meet_exception
aoqi@0 486 //
aoqi@0 487 // Meets this StateVector with another, destructively modifying this
aoqi@0 488 // one. The incoming state is coming via an exception. Returns true
aoqi@0 489 // if any modification takes place.
aoqi@0 490 bool ciTypeFlow::StateVector::meet_exception(ciInstanceKlass* exc,
aoqi@0 491 const ciTypeFlow::StateVector* incoming) {
aoqi@0 492 if (monitor_count() == -1) {
aoqi@0 493 set_monitor_count(incoming->monitor_count());
aoqi@0 494 }
aoqi@0 495 assert(monitor_count() == incoming->monitor_count(), "monitors must match");
aoqi@0 496
aoqi@0 497 if (stack_size() == -1) {
aoqi@0 498 set_stack_size(1);
aoqi@0 499 }
aoqi@0 500
aoqi@0 501 assert(stack_size() == 1, "must have one-element stack");
aoqi@0 502
aoqi@0 503 bool different = false;
aoqi@0 504
aoqi@0 505 // Meet locals from incoming array.
aoqi@0 506 Cell limit = local(_outer->max_locals()-1);
aoqi@0 507 for (Cell c = start_cell(); c <= limit; c = next_cell(c)) {
aoqi@0 508 ciType* t1 = type_at(c);
aoqi@0 509 ciType* t2 = incoming->type_at(c);
aoqi@0 510 if (!t1->equals(t2)) {
aoqi@0 511 ciType* new_type = type_meet(t1, t2);
aoqi@0 512 if (!t1->equals(new_type)) {
aoqi@0 513 set_type_at(c, new_type);
aoqi@0 514 different = true;
aoqi@0 515 }
aoqi@0 516 }
aoqi@0 517 }
aoqi@0 518
aoqi@0 519 // Handle stack separately. When an exception occurs, the
aoqi@0 520 // only stack entry is the exception instance.
aoqi@0 521 ciType* tos_type = type_at_tos();
aoqi@0 522 if (!tos_type->equals(exc)) {
aoqi@0 523 ciType* new_type = type_meet(tos_type, exc);
aoqi@0 524 if (!tos_type->equals(new_type)) {
aoqi@0 525 set_type_at_tos(new_type);
aoqi@0 526 different = true;
aoqi@0 527 }
aoqi@0 528 }
aoqi@0 529
aoqi@0 530 return different;
aoqi@0 531 }
aoqi@0 532
aoqi@0 533 // ------------------------------------------------------------------
aoqi@0 534 // ciTypeFlow::StateVector::push_translate
aoqi@0 535 void ciTypeFlow::StateVector::push_translate(ciType* type) {
aoqi@0 536 BasicType basic_type = type->basic_type();
aoqi@0 537 if (basic_type == T_BOOLEAN || basic_type == T_CHAR ||
aoqi@0 538 basic_type == T_BYTE || basic_type == T_SHORT) {
aoqi@0 539 push_int();
aoqi@0 540 } else {
aoqi@0 541 push(type);
aoqi@0 542 if (type->is_two_word()) {
aoqi@0 543 push(half_type(type));
aoqi@0 544 }
aoqi@0 545 }
aoqi@0 546 }
aoqi@0 547
aoqi@0 548 // ------------------------------------------------------------------
aoqi@0 549 // ciTypeFlow::StateVector::do_aaload
aoqi@0 550 void ciTypeFlow::StateVector::do_aaload(ciBytecodeStream* str) {
aoqi@0 551 pop_int();
aoqi@0 552 ciObjArrayKlass* array_klass = pop_objArray();
aoqi@0 553 if (array_klass == NULL) {
aoqi@0 554 // Did aaload on a null reference; push a null and ignore the exception.
aoqi@0 555 // This instruction will never continue normally. All we have to do
aoqi@0 556 // is report a value that will meet correctly with any downstream
aoqi@0 557 // reference types on paths that will truly be executed. This null type
aoqi@0 558 // meets with any reference type to yield that same reference type.
aoqi@0 559 // (The compiler will generate an unconditional exception here.)
aoqi@0 560 push(null_type());
aoqi@0 561 return;
aoqi@0 562 }
aoqi@0 563 if (!array_klass->is_loaded()) {
aoqi@0 564 // Only fails for some -Xcomp runs
aoqi@0 565 trap(str, array_klass,
aoqi@0 566 Deoptimization::make_trap_request
aoqi@0 567 (Deoptimization::Reason_unloaded,
aoqi@0 568 Deoptimization::Action_reinterpret));
aoqi@0 569 return;
aoqi@0 570 }
aoqi@0 571 ciKlass* element_klass = array_klass->element_klass();
aoqi@0 572 if (!element_klass->is_loaded() && element_klass->is_instance_klass()) {
aoqi@0 573 Untested("unloaded array element class in ciTypeFlow");
aoqi@0 574 trap(str, element_klass,
aoqi@0 575 Deoptimization::make_trap_request
aoqi@0 576 (Deoptimization::Reason_unloaded,
aoqi@0 577 Deoptimization::Action_reinterpret));
aoqi@0 578 } else {
aoqi@0 579 push_object(element_klass);
aoqi@0 580 }
aoqi@0 581 }
aoqi@0 582
aoqi@0 583
aoqi@0 584 // ------------------------------------------------------------------
aoqi@0 585 // ciTypeFlow::StateVector::do_checkcast
aoqi@0 586 void ciTypeFlow::StateVector::do_checkcast(ciBytecodeStream* str) {
aoqi@0 587 bool will_link;
aoqi@0 588 ciKlass* klass = str->get_klass(will_link);
aoqi@0 589 if (!will_link) {
aoqi@0 590 // VM's interpreter will not load 'klass' if object is NULL.
aoqi@0 591 // Type flow after this block may still be needed in two situations:
aoqi@0 592 // 1) C2 uses do_null_assert() and continues compilation for later blocks
aoqi@0 593 // 2) C2 does an OSR compile in a later block (see bug 4778368).
aoqi@0 594 pop_object();
aoqi@0 595 do_null_assert(klass);
aoqi@0 596 } else {
aoqi@0 597 pop_object();
aoqi@0 598 push_object(klass);
aoqi@0 599 }
aoqi@0 600 }
aoqi@0 601
aoqi@0 602 // ------------------------------------------------------------------
aoqi@0 603 // ciTypeFlow::StateVector::do_getfield
aoqi@0 604 void ciTypeFlow::StateVector::do_getfield(ciBytecodeStream* str) {
aoqi@0 605 // could add assert here for type of object.
aoqi@0 606 pop_object();
aoqi@0 607 do_getstatic(str);
aoqi@0 608 }
aoqi@0 609
aoqi@0 610 // ------------------------------------------------------------------
aoqi@0 611 // ciTypeFlow::StateVector::do_getstatic
aoqi@0 612 void ciTypeFlow::StateVector::do_getstatic(ciBytecodeStream* str) {
aoqi@0 613 bool will_link;
aoqi@0 614 ciField* field = str->get_field(will_link);
aoqi@0 615 if (!will_link) {
aoqi@0 616 trap(str, field->holder(), str->get_field_holder_index());
aoqi@0 617 } else {
aoqi@0 618 ciType* field_type = field->type();
aoqi@0 619 if (!field_type->is_loaded()) {
aoqi@0 620 // Normally, we need the field's type to be loaded if we are to
aoqi@0 621 // do anything interesting with its value.
aoqi@0 622 // We used to do this: trap(str, str->get_field_signature_index());
aoqi@0 623 //
aoqi@0 624 // There is one good reason not to trap here. Execution can
aoqi@0 625 // get past this "getfield" or "getstatic" if the value of
aoqi@0 626 // the field is null. As long as the value is null, the class
aoqi@0 627 // does not need to be loaded! The compiler must assume that
aoqi@0 628 // the value of the unloaded class reference is null; if the code
aoqi@0 629 // ever sees a non-null value, loading has occurred.
aoqi@0 630 //
aoqi@0 631 // This actually happens often enough to be annoying. If the
aoqi@0 632 // compiler throws an uncommon trap at this bytecode, you can
aoqi@0 633 // get an endless loop of recompilations, when all the code
aoqi@0 634 // needs to do is load a series of null values. Also, a trap
aoqi@0 635 // here can make an OSR entry point unreachable, triggering the
aoqi@0 636 // assert on non_osr_block in ciTypeFlow::get_start_state.
aoqi@0 637 // (See bug 4379915.)
aoqi@0 638 do_null_assert(field_type->as_klass());
aoqi@0 639 } else {
aoqi@0 640 push_translate(field_type);
aoqi@0 641 }
aoqi@0 642 }
aoqi@0 643 }
aoqi@0 644
aoqi@0 645 // ------------------------------------------------------------------
aoqi@0 646 // ciTypeFlow::StateVector::do_invoke
aoqi@0 647 void ciTypeFlow::StateVector::do_invoke(ciBytecodeStream* str,
aoqi@0 648 bool has_receiver) {
aoqi@0 649 bool will_link;
aoqi@0 650 ciSignature* declared_signature = NULL;
aoqi@0 651 ciMethod* callee = str->get_method(will_link, &declared_signature);
aoqi@0 652 assert(declared_signature != NULL, "cannot be null");
aoqi@0 653 if (!will_link) {
aoqi@0 654 // We weren't able to find the method.
aoqi@0 655 if (str->cur_bc() == Bytecodes::_invokedynamic) {
aoqi@0 656 trap(str, NULL,
aoqi@0 657 Deoptimization::make_trap_request
aoqi@0 658 (Deoptimization::Reason_uninitialized,
aoqi@0 659 Deoptimization::Action_reinterpret));
aoqi@0 660 } else {
aoqi@0 661 ciKlass* unloaded_holder = callee->holder();
aoqi@0 662 trap(str, unloaded_holder, str->get_method_holder_index());
aoqi@0 663 }
aoqi@0 664 } else {
aoqi@0 665 // We are using the declared signature here because it might be
aoqi@0 666 // different from the callee signature (Cf. invokedynamic and
aoqi@0 667 // invokehandle).
aoqi@0 668 ciSignatureStream sigstr(declared_signature);
aoqi@0 669 const int arg_size = declared_signature->size();
aoqi@0 670 const int stack_base = stack_size() - arg_size;
aoqi@0 671 int i = 0;
aoqi@0 672 for( ; !sigstr.at_return_type(); sigstr.next()) {
aoqi@0 673 ciType* type = sigstr.type();
aoqi@0 674 ciType* stack_type = type_at(stack(stack_base + i++));
aoqi@0 675 // Do I want to check this type?
aoqi@0 676 // assert(stack_type->is_subtype_of(type), "bad type for field value");
aoqi@0 677 if (type->is_two_word()) {
aoqi@0 678 ciType* stack_type2 = type_at(stack(stack_base + i++));
aoqi@0 679 assert(stack_type2->equals(half_type(type)), "must be 2nd half");
aoqi@0 680 }
aoqi@0 681 }
aoqi@0 682 assert(arg_size == i, "must match");
aoqi@0 683 for (int j = 0; j < arg_size; j++) {
aoqi@0 684 pop();
aoqi@0 685 }
aoqi@0 686 if (has_receiver) {
aoqi@0 687 // Check this?
aoqi@0 688 pop_object();
aoqi@0 689 }
aoqi@0 690 assert(!sigstr.is_done(), "must have return type");
aoqi@0 691 ciType* return_type = sigstr.type();
aoqi@0 692 if (!return_type->is_void()) {
aoqi@0 693 if (!return_type->is_loaded()) {
aoqi@0 694 // As in do_getstatic(), generally speaking, we need the return type to
aoqi@0 695 // be loaded if we are to do anything interesting with its value.
aoqi@0 696 // We used to do this: trap(str, str->get_method_signature_index());
aoqi@0 697 //
aoqi@0 698 // We do not trap here since execution can get past this invoke if
aoqi@0 699 // the return value is null. As long as the value is null, the class
aoqi@0 700 // does not need to be loaded! The compiler must assume that
aoqi@0 701 // the value of the unloaded class reference is null; if the code
aoqi@0 702 // ever sees a non-null value, loading has occurred.
aoqi@0 703 //
aoqi@0 704 // See do_getstatic() for similar explanation, as well as bug 4684993.
aoqi@0 705 do_null_assert(return_type->as_klass());
aoqi@0 706 } else {
aoqi@0 707 push_translate(return_type);
aoqi@0 708 }
aoqi@0 709 }
aoqi@0 710 }
aoqi@0 711 }
aoqi@0 712
aoqi@0 713 // ------------------------------------------------------------------
aoqi@0 714 // ciTypeFlow::StateVector::do_jsr
aoqi@0 715 void ciTypeFlow::StateVector::do_jsr(ciBytecodeStream* str) {
aoqi@0 716 push(ciReturnAddress::make(str->next_bci()));
aoqi@0 717 }
aoqi@0 718
aoqi@0 719 // ------------------------------------------------------------------
aoqi@0 720 // ciTypeFlow::StateVector::do_ldc
aoqi@0 721 void ciTypeFlow::StateVector::do_ldc(ciBytecodeStream* str) {
aoqi@0 722 ciConstant con = str->get_constant();
aoqi@0 723 BasicType basic_type = con.basic_type();
aoqi@0 724 if (basic_type == T_ILLEGAL) {
aoqi@0 725 // OutOfMemoryError in the CI while loading constant
aoqi@0 726 push_null();
aoqi@0 727 outer()->record_failure("ldc did not link");
aoqi@0 728 return;
aoqi@0 729 }
aoqi@0 730 if (basic_type == T_OBJECT || basic_type == T_ARRAY) {
aoqi@0 731 ciObject* obj = con.as_object();
aoqi@0 732 if (obj->is_null_object()) {
aoqi@0 733 push_null();
aoqi@0 734 } else {
vlivanov@7288 735 assert(obj->is_instance() || obj->is_array(), "must be java_mirror of klass");
aoqi@0 736 push_object(obj->klass());
aoqi@0 737 }
aoqi@0 738 } else {
aoqi@0 739 push_translate(ciType::make(basic_type));
aoqi@0 740 }
aoqi@0 741 }
aoqi@0 742
aoqi@0 743 // ------------------------------------------------------------------
aoqi@0 744 // ciTypeFlow::StateVector::do_multianewarray
aoqi@0 745 void ciTypeFlow::StateVector::do_multianewarray(ciBytecodeStream* str) {
aoqi@0 746 int dimensions = str->get_dimensions();
aoqi@0 747 bool will_link;
aoqi@0 748 ciArrayKlass* array_klass = str->get_klass(will_link)->as_array_klass();
aoqi@0 749 if (!will_link) {
aoqi@0 750 trap(str, array_klass, str->get_klass_index());
aoqi@0 751 } else {
aoqi@0 752 for (int i = 0; i < dimensions; i++) {
aoqi@0 753 pop_int();
aoqi@0 754 }
aoqi@0 755 push_object(array_klass);
aoqi@0 756 }
aoqi@0 757 }
aoqi@0 758
aoqi@0 759 // ------------------------------------------------------------------
aoqi@0 760 // ciTypeFlow::StateVector::do_new
aoqi@0 761 void ciTypeFlow::StateVector::do_new(ciBytecodeStream* str) {
aoqi@0 762 bool will_link;
aoqi@0 763 ciKlass* klass = str->get_klass(will_link);
aoqi@0 764 if (!will_link || str->is_unresolved_klass()) {
aoqi@0 765 trap(str, klass, str->get_klass_index());
aoqi@0 766 } else {
aoqi@0 767 push_object(klass);
aoqi@0 768 }
aoqi@0 769 }
aoqi@0 770
aoqi@0 771 // ------------------------------------------------------------------
aoqi@0 772 // ciTypeFlow::StateVector::do_newarray
aoqi@0 773 void ciTypeFlow::StateVector::do_newarray(ciBytecodeStream* str) {
aoqi@0 774 pop_int();
aoqi@0 775 ciKlass* klass = ciTypeArrayKlass::make((BasicType)str->get_index());
aoqi@0 776 push_object(klass);
aoqi@0 777 }
aoqi@0 778
aoqi@0 779 // ------------------------------------------------------------------
aoqi@0 780 // ciTypeFlow::StateVector::do_putfield
aoqi@0 781 void ciTypeFlow::StateVector::do_putfield(ciBytecodeStream* str) {
aoqi@0 782 do_putstatic(str);
aoqi@0 783 if (_trap_bci != -1) return; // unloaded field holder, etc.
aoqi@0 784 // could add assert here for type of object.
aoqi@0 785 pop_object();
aoqi@0 786 }
aoqi@0 787
aoqi@0 788 // ------------------------------------------------------------------
aoqi@0 789 // ciTypeFlow::StateVector::do_putstatic
aoqi@0 790 void ciTypeFlow::StateVector::do_putstatic(ciBytecodeStream* str) {
aoqi@0 791 bool will_link;
aoqi@0 792 ciField* field = str->get_field(will_link);
aoqi@0 793 if (!will_link) {
aoqi@0 794 trap(str, field->holder(), str->get_field_holder_index());
aoqi@0 795 } else {
aoqi@0 796 ciType* field_type = field->type();
aoqi@0 797 ciType* type = pop_value();
aoqi@0 798 // Do I want to check this type?
aoqi@0 799 // assert(type->is_subtype_of(field_type), "bad type for field value");
aoqi@0 800 if (field_type->is_two_word()) {
aoqi@0 801 ciType* type2 = pop_value();
aoqi@0 802 assert(type2->is_two_word(), "must be 2nd half");
aoqi@0 803 assert(type == half_type(type2), "must be 2nd half");
aoqi@0 804 }
aoqi@0 805 }
aoqi@0 806 }
aoqi@0 807
aoqi@0 808 // ------------------------------------------------------------------
aoqi@0 809 // ciTypeFlow::StateVector::do_ret
aoqi@0 810 void ciTypeFlow::StateVector::do_ret(ciBytecodeStream* str) {
aoqi@0 811 Cell index = local(str->get_index());
aoqi@0 812
aoqi@0 813 ciType* address = type_at(index);
aoqi@0 814 assert(address->is_return_address(), "bad return address");
aoqi@0 815 set_type_at(index, bottom_type());
aoqi@0 816 }
aoqi@0 817
aoqi@0 818 // ------------------------------------------------------------------
aoqi@0 819 // ciTypeFlow::StateVector::trap
aoqi@0 820 //
aoqi@0 821 // Stop interpretation of this path with a trap.
aoqi@0 822 void ciTypeFlow::StateVector::trap(ciBytecodeStream* str, ciKlass* klass, int index) {
aoqi@0 823 _trap_bci = str->cur_bci();
aoqi@0 824 _trap_index = index;
aoqi@0 825
aoqi@0 826 // Log information about this trap:
aoqi@0 827 CompileLog* log = outer()->env()->log();
aoqi@0 828 if (log != NULL) {
aoqi@0 829 int mid = log->identify(outer()->method());
aoqi@0 830 int kid = (klass == NULL)? -1: log->identify(klass);
aoqi@0 831 log->begin_elem("uncommon_trap method='%d' bci='%d'", mid, str->cur_bci());
aoqi@0 832 char buf[100];
aoqi@0 833 log->print(" %s", Deoptimization::format_trap_request(buf, sizeof(buf),
aoqi@0 834 index));
aoqi@0 835 if (kid >= 0)
aoqi@0 836 log->print(" klass='%d'", kid);
aoqi@0 837 log->end_elem();
aoqi@0 838 }
aoqi@0 839 }
aoqi@0 840
aoqi@0 841 // ------------------------------------------------------------------
aoqi@0 842 // ciTypeFlow::StateVector::do_null_assert
aoqi@0 843 // Corresponds to graphKit::do_null_assert.
aoqi@0 844 void ciTypeFlow::StateVector::do_null_assert(ciKlass* unloaded_klass) {
aoqi@0 845 if (unloaded_klass->is_loaded()) {
aoqi@0 846 // We failed to link, but we can still compute with this class,
aoqi@0 847 // since it is loaded somewhere. The compiler will uncommon_trap
aoqi@0 848 // if the object is not null, but the typeflow pass can not assume
aoqi@0 849 // that the object will be null, otherwise it may incorrectly tell
aoqi@0 850 // the parser that an object is known to be null. 4761344, 4807707
aoqi@0 851 push_object(unloaded_klass);
aoqi@0 852 } else {
aoqi@0 853 // The class is not loaded anywhere. It is safe to model the
aoqi@0 854 // null in the typestates, because we can compile in a null check
aoqi@0 855 // which will deoptimize us if someone manages to load the
aoqi@0 856 // class later.
aoqi@0 857 push_null();
aoqi@0 858 }
aoqi@0 859 }
aoqi@0 860
aoqi@0 861
aoqi@0 862 // ------------------------------------------------------------------
aoqi@0 863 // ciTypeFlow::StateVector::apply_one_bytecode
aoqi@0 864 //
aoqi@0 865 // Apply the effect of one bytecode to this StateVector
aoqi@0 866 bool ciTypeFlow::StateVector::apply_one_bytecode(ciBytecodeStream* str) {
aoqi@0 867 _trap_bci = -1;
aoqi@0 868 _trap_index = 0;
aoqi@0 869
aoqi@0 870 if (CITraceTypeFlow) {
aoqi@0 871 tty->print_cr(">> Interpreting bytecode %d:%s", str->cur_bci(),
aoqi@0 872 Bytecodes::name(str->cur_bc()));
aoqi@0 873 }
aoqi@0 874
aoqi@0 875 switch(str->cur_bc()) {
aoqi@0 876 case Bytecodes::_aaload: do_aaload(str); break;
aoqi@0 877
aoqi@0 878 case Bytecodes::_aastore:
aoqi@0 879 {
aoqi@0 880 pop_object();
aoqi@0 881 pop_int();
aoqi@0 882 pop_objArray();
aoqi@0 883 break;
aoqi@0 884 }
aoqi@0 885 case Bytecodes::_aconst_null:
aoqi@0 886 {
aoqi@0 887 push_null();
aoqi@0 888 break;
aoqi@0 889 }
aoqi@0 890 case Bytecodes::_aload: load_local_object(str->get_index()); break;
aoqi@0 891 case Bytecodes::_aload_0: load_local_object(0); break;
aoqi@0 892 case Bytecodes::_aload_1: load_local_object(1); break;
aoqi@0 893 case Bytecodes::_aload_2: load_local_object(2); break;
aoqi@0 894 case Bytecodes::_aload_3: load_local_object(3); break;
aoqi@0 895
aoqi@0 896 case Bytecodes::_anewarray:
aoqi@0 897 {
aoqi@0 898 pop_int();
aoqi@0 899 bool will_link;
aoqi@0 900 ciKlass* element_klass = str->get_klass(will_link);
aoqi@0 901 if (!will_link) {
aoqi@0 902 trap(str, element_klass, str->get_klass_index());
aoqi@0 903 } else {
aoqi@0 904 push_object(ciObjArrayKlass::make(element_klass));
aoqi@0 905 }
aoqi@0 906 break;
aoqi@0 907 }
aoqi@0 908 case Bytecodes::_areturn:
aoqi@0 909 case Bytecodes::_ifnonnull:
aoqi@0 910 case Bytecodes::_ifnull:
aoqi@0 911 {
aoqi@0 912 pop_object();
aoqi@0 913 break;
aoqi@0 914 }
aoqi@0 915 case Bytecodes::_monitorenter:
aoqi@0 916 {
aoqi@0 917 pop_object();
aoqi@0 918 set_monitor_count(monitor_count() + 1);
aoqi@0 919 break;
aoqi@0 920 }
aoqi@0 921 case Bytecodes::_monitorexit:
aoqi@0 922 {
aoqi@0 923 pop_object();
aoqi@0 924 assert(monitor_count() > 0, "must be a monitor to exit from");
aoqi@0 925 set_monitor_count(monitor_count() - 1);
aoqi@0 926 break;
aoqi@0 927 }
aoqi@0 928 case Bytecodes::_arraylength:
aoqi@0 929 {
aoqi@0 930 pop_array();
aoqi@0 931 push_int();
aoqi@0 932 break;
aoqi@0 933 }
aoqi@0 934 case Bytecodes::_astore: store_local_object(str->get_index()); break;
aoqi@0 935 case Bytecodes::_astore_0: store_local_object(0); break;
aoqi@0 936 case Bytecodes::_astore_1: store_local_object(1); break;
aoqi@0 937 case Bytecodes::_astore_2: store_local_object(2); break;
aoqi@0 938 case Bytecodes::_astore_3: store_local_object(3); break;
aoqi@0 939
aoqi@0 940 case Bytecodes::_athrow:
aoqi@0 941 {
aoqi@0 942 NEEDS_CLEANUP;
aoqi@0 943 pop_object();
aoqi@0 944 break;
aoqi@0 945 }
aoqi@0 946 case Bytecodes::_baload:
aoqi@0 947 case Bytecodes::_caload:
aoqi@0 948 case Bytecodes::_iaload:
aoqi@0 949 case Bytecodes::_saload:
aoqi@0 950 {
aoqi@0 951 pop_int();
aoqi@0 952 ciTypeArrayKlass* array_klass = pop_typeArray();
aoqi@0 953 // Put assert here for right type?
aoqi@0 954 push_int();
aoqi@0 955 break;
aoqi@0 956 }
aoqi@0 957 case Bytecodes::_bastore:
aoqi@0 958 case Bytecodes::_castore:
aoqi@0 959 case Bytecodes::_iastore:
aoqi@0 960 case Bytecodes::_sastore:
aoqi@0 961 {
aoqi@0 962 pop_int();
aoqi@0 963 pop_int();
aoqi@0 964 pop_typeArray();
aoqi@0 965 // assert here?
aoqi@0 966 break;
aoqi@0 967 }
aoqi@0 968 case Bytecodes::_bipush:
aoqi@0 969 case Bytecodes::_iconst_m1:
aoqi@0 970 case Bytecodes::_iconst_0:
aoqi@0 971 case Bytecodes::_iconst_1:
aoqi@0 972 case Bytecodes::_iconst_2:
aoqi@0 973 case Bytecodes::_iconst_3:
aoqi@0 974 case Bytecodes::_iconst_4:
aoqi@0 975 case Bytecodes::_iconst_5:
aoqi@0 976 case Bytecodes::_sipush:
aoqi@0 977 {
aoqi@0 978 push_int();
aoqi@0 979 break;
aoqi@0 980 }
aoqi@0 981 case Bytecodes::_checkcast: do_checkcast(str); break;
aoqi@0 982
aoqi@0 983 case Bytecodes::_d2f:
aoqi@0 984 {
aoqi@0 985 pop_double();
aoqi@0 986 push_float();
aoqi@0 987 break;
aoqi@0 988 }
aoqi@0 989 case Bytecodes::_d2i:
aoqi@0 990 {
aoqi@0 991 pop_double();
aoqi@0 992 push_int();
aoqi@0 993 break;
aoqi@0 994 }
aoqi@0 995 case Bytecodes::_d2l:
aoqi@0 996 {
aoqi@0 997 pop_double();
aoqi@0 998 push_long();
aoqi@0 999 break;
aoqi@0 1000 }
aoqi@0 1001 case Bytecodes::_dadd:
aoqi@0 1002 case Bytecodes::_ddiv:
aoqi@0 1003 case Bytecodes::_dmul:
aoqi@0 1004 case Bytecodes::_drem:
aoqi@0 1005 case Bytecodes::_dsub:
aoqi@0 1006 {
aoqi@0 1007 pop_double();
aoqi@0 1008 pop_double();
aoqi@0 1009 push_double();
aoqi@0 1010 break;
aoqi@0 1011 }
aoqi@0 1012 case Bytecodes::_daload:
aoqi@0 1013 {
aoqi@0 1014 pop_int();
aoqi@0 1015 ciTypeArrayKlass* array_klass = pop_typeArray();
aoqi@0 1016 // Put assert here for right type?
aoqi@0 1017 push_double();
aoqi@0 1018 break;
aoqi@0 1019 }
aoqi@0 1020 case Bytecodes::_dastore:
aoqi@0 1021 {
aoqi@0 1022 pop_double();
aoqi@0 1023 pop_int();
aoqi@0 1024 pop_typeArray();
aoqi@0 1025 // assert here?
aoqi@0 1026 break;
aoqi@0 1027 }
aoqi@0 1028 case Bytecodes::_dcmpg:
aoqi@0 1029 case Bytecodes::_dcmpl:
aoqi@0 1030 {
aoqi@0 1031 pop_double();
aoqi@0 1032 pop_double();
aoqi@0 1033 push_int();
aoqi@0 1034 break;
aoqi@0 1035 }
aoqi@0 1036 case Bytecodes::_dconst_0:
aoqi@0 1037 case Bytecodes::_dconst_1:
aoqi@0 1038 {
aoqi@0 1039 push_double();
aoqi@0 1040 break;
aoqi@0 1041 }
aoqi@0 1042 case Bytecodes::_dload: load_local_double(str->get_index()); break;
aoqi@0 1043 case Bytecodes::_dload_0: load_local_double(0); break;
aoqi@0 1044 case Bytecodes::_dload_1: load_local_double(1); break;
aoqi@0 1045 case Bytecodes::_dload_2: load_local_double(2); break;
aoqi@0 1046 case Bytecodes::_dload_3: load_local_double(3); break;
aoqi@0 1047
aoqi@0 1048 case Bytecodes::_dneg:
aoqi@0 1049 {
aoqi@0 1050 pop_double();
aoqi@0 1051 push_double();
aoqi@0 1052 break;
aoqi@0 1053 }
aoqi@0 1054 case Bytecodes::_dreturn:
aoqi@0 1055 {
aoqi@0 1056 pop_double();
aoqi@0 1057 break;
aoqi@0 1058 }
aoqi@0 1059 case Bytecodes::_dstore: store_local_double(str->get_index()); break;
aoqi@0 1060 case Bytecodes::_dstore_0: store_local_double(0); break;
aoqi@0 1061 case Bytecodes::_dstore_1: store_local_double(1); break;
aoqi@0 1062 case Bytecodes::_dstore_2: store_local_double(2); break;
aoqi@0 1063 case Bytecodes::_dstore_3: store_local_double(3); break;
aoqi@0 1064
aoqi@0 1065 case Bytecodes::_dup:
aoqi@0 1066 {
aoqi@0 1067 push(type_at_tos());
aoqi@0 1068 break;
aoqi@0 1069 }
aoqi@0 1070 case Bytecodes::_dup_x1:
aoqi@0 1071 {
aoqi@0 1072 ciType* value1 = pop_value();
aoqi@0 1073 ciType* value2 = pop_value();
aoqi@0 1074 push(value1);
aoqi@0 1075 push(value2);
aoqi@0 1076 push(value1);
aoqi@0 1077 break;
aoqi@0 1078 }
aoqi@0 1079 case Bytecodes::_dup_x2:
aoqi@0 1080 {
aoqi@0 1081 ciType* value1 = pop_value();
aoqi@0 1082 ciType* value2 = pop_value();
aoqi@0 1083 ciType* value3 = pop_value();
aoqi@0 1084 push(value1);
aoqi@0 1085 push(value3);
aoqi@0 1086 push(value2);
aoqi@0 1087 push(value1);
aoqi@0 1088 break;
aoqi@0 1089 }
aoqi@0 1090 case Bytecodes::_dup2:
aoqi@0 1091 {
aoqi@0 1092 ciType* value1 = pop_value();
aoqi@0 1093 ciType* value2 = pop_value();
aoqi@0 1094 push(value2);
aoqi@0 1095 push(value1);
aoqi@0 1096 push(value2);
aoqi@0 1097 push(value1);
aoqi@0 1098 break;
aoqi@0 1099 }
aoqi@0 1100 case Bytecodes::_dup2_x1:
aoqi@0 1101 {
aoqi@0 1102 ciType* value1 = pop_value();
aoqi@0 1103 ciType* value2 = pop_value();
aoqi@0 1104 ciType* value3 = pop_value();
aoqi@0 1105 push(value2);
aoqi@0 1106 push(value1);
aoqi@0 1107 push(value3);
aoqi@0 1108 push(value2);
aoqi@0 1109 push(value1);
aoqi@0 1110 break;
aoqi@0 1111 }
aoqi@0 1112 case Bytecodes::_dup2_x2:
aoqi@0 1113 {
aoqi@0 1114 ciType* value1 = pop_value();
aoqi@0 1115 ciType* value2 = pop_value();
aoqi@0 1116 ciType* value3 = pop_value();
aoqi@0 1117 ciType* value4 = pop_value();
aoqi@0 1118 push(value2);
aoqi@0 1119 push(value1);
aoqi@0 1120 push(value4);
aoqi@0 1121 push(value3);
aoqi@0 1122 push(value2);
aoqi@0 1123 push(value1);
aoqi@0 1124 break;
aoqi@0 1125 }
aoqi@0 1126 case Bytecodes::_f2d:
aoqi@0 1127 {
aoqi@0 1128 pop_float();
aoqi@0 1129 push_double();
aoqi@0 1130 break;
aoqi@0 1131 }
aoqi@0 1132 case Bytecodes::_f2i:
aoqi@0 1133 {
aoqi@0 1134 pop_float();
aoqi@0 1135 push_int();
aoqi@0 1136 break;
aoqi@0 1137 }
aoqi@0 1138 case Bytecodes::_f2l:
aoqi@0 1139 {
aoqi@0 1140 pop_float();
aoqi@0 1141 push_long();
aoqi@0 1142 break;
aoqi@0 1143 }
aoqi@0 1144 case Bytecodes::_fadd:
aoqi@0 1145 case Bytecodes::_fdiv:
aoqi@0 1146 case Bytecodes::_fmul:
aoqi@0 1147 case Bytecodes::_frem:
aoqi@0 1148 case Bytecodes::_fsub:
aoqi@0 1149 {
aoqi@0 1150 pop_float();
aoqi@0 1151 pop_float();
aoqi@0 1152 push_float();
aoqi@0 1153 break;
aoqi@0 1154 }
aoqi@0 1155 case Bytecodes::_faload:
aoqi@0 1156 {
aoqi@0 1157 pop_int();
aoqi@0 1158 ciTypeArrayKlass* array_klass = pop_typeArray();
aoqi@0 1159 // Put assert here.
aoqi@0 1160 push_float();
aoqi@0 1161 break;
aoqi@0 1162 }
aoqi@0 1163 case Bytecodes::_fastore:
aoqi@0 1164 {
aoqi@0 1165 pop_float();
aoqi@0 1166 pop_int();
aoqi@0 1167 ciTypeArrayKlass* array_klass = pop_typeArray();
aoqi@0 1168 // Put assert here.
aoqi@0 1169 break;
aoqi@0 1170 }
aoqi@0 1171 case Bytecodes::_fcmpg:
aoqi@0 1172 case Bytecodes::_fcmpl:
aoqi@0 1173 {
aoqi@0 1174 pop_float();
aoqi@0 1175 pop_float();
aoqi@0 1176 push_int();
aoqi@0 1177 break;
aoqi@0 1178 }
aoqi@0 1179 case Bytecodes::_fconst_0:
aoqi@0 1180 case Bytecodes::_fconst_1:
aoqi@0 1181 case Bytecodes::_fconst_2:
aoqi@0 1182 {
aoqi@0 1183 push_float();
aoqi@0 1184 break;
aoqi@0 1185 }
aoqi@0 1186 case Bytecodes::_fload: load_local_float(str->get_index()); break;
aoqi@0 1187 case Bytecodes::_fload_0: load_local_float(0); break;
aoqi@0 1188 case Bytecodes::_fload_1: load_local_float(1); break;
aoqi@0 1189 case Bytecodes::_fload_2: load_local_float(2); break;
aoqi@0 1190 case Bytecodes::_fload_3: load_local_float(3); break;
aoqi@0 1191
aoqi@0 1192 case Bytecodes::_fneg:
aoqi@0 1193 {
aoqi@0 1194 pop_float();
aoqi@0 1195 push_float();
aoqi@0 1196 break;
aoqi@0 1197 }
aoqi@0 1198 case Bytecodes::_freturn:
aoqi@0 1199 {
aoqi@0 1200 pop_float();
aoqi@0 1201 break;
aoqi@0 1202 }
aoqi@0 1203 case Bytecodes::_fstore: store_local_float(str->get_index()); break;
aoqi@0 1204 case Bytecodes::_fstore_0: store_local_float(0); break;
aoqi@0 1205 case Bytecodes::_fstore_1: store_local_float(1); break;
aoqi@0 1206 case Bytecodes::_fstore_2: store_local_float(2); break;
aoqi@0 1207 case Bytecodes::_fstore_3: store_local_float(3); break;
aoqi@0 1208
aoqi@0 1209 case Bytecodes::_getfield: do_getfield(str); break;
aoqi@0 1210 case Bytecodes::_getstatic: do_getstatic(str); break;
aoqi@0 1211
aoqi@0 1212 case Bytecodes::_goto:
aoqi@0 1213 case Bytecodes::_goto_w:
aoqi@0 1214 case Bytecodes::_nop:
aoqi@0 1215 case Bytecodes::_return:
aoqi@0 1216 {
aoqi@0 1217 // do nothing.
aoqi@0 1218 break;
aoqi@0 1219 }
aoqi@0 1220 case Bytecodes::_i2b:
aoqi@0 1221 case Bytecodes::_i2c:
aoqi@0 1222 case Bytecodes::_i2s:
aoqi@0 1223 case Bytecodes::_ineg:
aoqi@0 1224 {
aoqi@0 1225 pop_int();
aoqi@0 1226 push_int();
aoqi@0 1227 break;
aoqi@0 1228 }
aoqi@0 1229 case Bytecodes::_i2d:
aoqi@0 1230 {
aoqi@0 1231 pop_int();
aoqi@0 1232 push_double();
aoqi@0 1233 break;
aoqi@0 1234 }
aoqi@0 1235 case Bytecodes::_i2f:
aoqi@0 1236 {
aoqi@0 1237 pop_int();
aoqi@0 1238 push_float();
aoqi@0 1239 break;
aoqi@0 1240 }
aoqi@0 1241 case Bytecodes::_i2l:
aoqi@0 1242 {
aoqi@0 1243 pop_int();
aoqi@0 1244 push_long();
aoqi@0 1245 break;
aoqi@0 1246 }
aoqi@0 1247 case Bytecodes::_iadd:
aoqi@0 1248 case Bytecodes::_iand:
aoqi@0 1249 case Bytecodes::_idiv:
aoqi@0 1250 case Bytecodes::_imul:
aoqi@0 1251 case Bytecodes::_ior:
aoqi@0 1252 case Bytecodes::_irem:
aoqi@0 1253 case Bytecodes::_ishl:
aoqi@0 1254 case Bytecodes::_ishr:
aoqi@0 1255 case Bytecodes::_isub:
aoqi@0 1256 case Bytecodes::_iushr:
aoqi@0 1257 case Bytecodes::_ixor:
aoqi@0 1258 {
aoqi@0 1259 pop_int();
aoqi@0 1260 pop_int();
aoqi@0 1261 push_int();
aoqi@0 1262 break;
aoqi@0 1263 }
aoqi@0 1264 case Bytecodes::_if_acmpeq:
aoqi@0 1265 case Bytecodes::_if_acmpne:
aoqi@0 1266 {
aoqi@0 1267 pop_object();
aoqi@0 1268 pop_object();
aoqi@0 1269 break;
aoqi@0 1270 }
aoqi@0 1271 case Bytecodes::_if_icmpeq:
aoqi@0 1272 case Bytecodes::_if_icmpge:
aoqi@0 1273 case Bytecodes::_if_icmpgt:
aoqi@0 1274 case Bytecodes::_if_icmple:
aoqi@0 1275 case Bytecodes::_if_icmplt:
aoqi@0 1276 case Bytecodes::_if_icmpne:
aoqi@0 1277 {
aoqi@0 1278 pop_int();
aoqi@0 1279 pop_int();
aoqi@0 1280 break;
aoqi@0 1281 }
aoqi@0 1282 case Bytecodes::_ifeq:
aoqi@0 1283 case Bytecodes::_ifle:
aoqi@0 1284 case Bytecodes::_iflt:
aoqi@0 1285 case Bytecodes::_ifge:
aoqi@0 1286 case Bytecodes::_ifgt:
aoqi@0 1287 case Bytecodes::_ifne:
aoqi@0 1288 case Bytecodes::_ireturn:
aoqi@0 1289 case Bytecodes::_lookupswitch:
aoqi@0 1290 case Bytecodes::_tableswitch:
aoqi@0 1291 {
aoqi@0 1292 pop_int();
aoqi@0 1293 break;
aoqi@0 1294 }
aoqi@0 1295 case Bytecodes::_iinc:
aoqi@0 1296 {
aoqi@0 1297 int lnum = str->get_index();
aoqi@0 1298 check_int(local(lnum));
aoqi@0 1299 store_to_local(lnum);
aoqi@0 1300 break;
aoqi@0 1301 }
aoqi@0 1302 case Bytecodes::_iload: load_local_int(str->get_index()); break;
aoqi@0 1303 case Bytecodes::_iload_0: load_local_int(0); break;
aoqi@0 1304 case Bytecodes::_iload_1: load_local_int(1); break;
aoqi@0 1305 case Bytecodes::_iload_2: load_local_int(2); break;
aoqi@0 1306 case Bytecodes::_iload_3: load_local_int(3); break;
aoqi@0 1307
aoqi@0 1308 case Bytecodes::_instanceof:
aoqi@0 1309 {
aoqi@0 1310 // Check for uncommon trap:
aoqi@0 1311 do_checkcast(str);
aoqi@0 1312 pop_object();
aoqi@0 1313 push_int();
aoqi@0 1314 break;
aoqi@0 1315 }
aoqi@0 1316 case Bytecodes::_invokeinterface: do_invoke(str, true); break;
aoqi@0 1317 case Bytecodes::_invokespecial: do_invoke(str, true); break;
aoqi@0 1318 case Bytecodes::_invokestatic: do_invoke(str, false); break;
aoqi@0 1319 case Bytecodes::_invokevirtual: do_invoke(str, true); break;
aoqi@0 1320 case Bytecodes::_invokedynamic: do_invoke(str, false); break;
aoqi@0 1321
aoqi@0 1322 case Bytecodes::_istore: store_local_int(str->get_index()); break;
aoqi@0 1323 case Bytecodes::_istore_0: store_local_int(0); break;
aoqi@0 1324 case Bytecodes::_istore_1: store_local_int(1); break;
aoqi@0 1325 case Bytecodes::_istore_2: store_local_int(2); break;
aoqi@0 1326 case Bytecodes::_istore_3: store_local_int(3); break;
aoqi@0 1327
aoqi@0 1328 case Bytecodes::_jsr:
aoqi@0 1329 case Bytecodes::_jsr_w: do_jsr(str); break;
aoqi@0 1330
aoqi@0 1331 case Bytecodes::_l2d:
aoqi@0 1332 {
aoqi@0 1333 pop_long();
aoqi@0 1334 push_double();
aoqi@0 1335 break;
aoqi@0 1336 }
aoqi@0 1337 case Bytecodes::_l2f:
aoqi@0 1338 {
aoqi@0 1339 pop_long();
aoqi@0 1340 push_float();
aoqi@0 1341 break;
aoqi@0 1342 }
aoqi@0 1343 case Bytecodes::_l2i:
aoqi@0 1344 {
aoqi@0 1345 pop_long();
aoqi@0 1346 push_int();
aoqi@0 1347 break;
aoqi@0 1348 }
aoqi@0 1349 case Bytecodes::_ladd:
aoqi@0 1350 case Bytecodes::_land:
aoqi@0 1351 case Bytecodes::_ldiv:
aoqi@0 1352 case Bytecodes::_lmul:
aoqi@0 1353 case Bytecodes::_lor:
aoqi@0 1354 case Bytecodes::_lrem:
aoqi@0 1355 case Bytecodes::_lsub:
aoqi@0 1356 case Bytecodes::_lxor:
aoqi@0 1357 {
aoqi@0 1358 pop_long();
aoqi@0 1359 pop_long();
aoqi@0 1360 push_long();
aoqi@0 1361 break;
aoqi@0 1362 }
aoqi@0 1363 case Bytecodes::_laload:
aoqi@0 1364 {
aoqi@0 1365 pop_int();
aoqi@0 1366 ciTypeArrayKlass* array_klass = pop_typeArray();
aoqi@0 1367 // Put assert here for right type?
aoqi@0 1368 push_long();
aoqi@0 1369 break;
aoqi@0 1370 }
aoqi@0 1371 case Bytecodes::_lastore:
aoqi@0 1372 {
aoqi@0 1373 pop_long();
aoqi@0 1374 pop_int();
aoqi@0 1375 pop_typeArray();
aoqi@0 1376 // assert here?
aoqi@0 1377 break;
aoqi@0 1378 }
aoqi@0 1379 case Bytecodes::_lcmp:
aoqi@0 1380 {
aoqi@0 1381 pop_long();
aoqi@0 1382 pop_long();
aoqi@0 1383 push_int();
aoqi@0 1384 break;
aoqi@0 1385 }
aoqi@0 1386 case Bytecodes::_lconst_0:
aoqi@0 1387 case Bytecodes::_lconst_1:
aoqi@0 1388 {
aoqi@0 1389 push_long();
aoqi@0 1390 break;
aoqi@0 1391 }
aoqi@0 1392 case Bytecodes::_ldc:
aoqi@0 1393 case Bytecodes::_ldc_w:
aoqi@0 1394 case Bytecodes::_ldc2_w:
aoqi@0 1395 {
aoqi@0 1396 do_ldc(str);
aoqi@0 1397 break;
aoqi@0 1398 }
aoqi@0 1399
aoqi@0 1400 case Bytecodes::_lload: load_local_long(str->get_index()); break;
aoqi@0 1401 case Bytecodes::_lload_0: load_local_long(0); break;
aoqi@0 1402 case Bytecodes::_lload_1: load_local_long(1); break;
aoqi@0 1403 case Bytecodes::_lload_2: load_local_long(2); break;
aoqi@0 1404 case Bytecodes::_lload_3: load_local_long(3); break;
aoqi@0 1405
aoqi@0 1406 case Bytecodes::_lneg:
aoqi@0 1407 {
aoqi@0 1408 pop_long();
aoqi@0 1409 push_long();
aoqi@0 1410 break;
aoqi@0 1411 }
aoqi@0 1412 case Bytecodes::_lreturn:
aoqi@0 1413 {
aoqi@0 1414 pop_long();
aoqi@0 1415 break;
aoqi@0 1416 }
aoqi@0 1417 case Bytecodes::_lshl:
aoqi@0 1418 case Bytecodes::_lshr:
aoqi@0 1419 case Bytecodes::_lushr:
aoqi@0 1420 {
aoqi@0 1421 pop_int();
aoqi@0 1422 pop_long();
aoqi@0 1423 push_long();
aoqi@0 1424 break;
aoqi@0 1425 }
aoqi@0 1426 case Bytecodes::_lstore: store_local_long(str->get_index()); break;
aoqi@0 1427 case Bytecodes::_lstore_0: store_local_long(0); break;
aoqi@0 1428 case Bytecodes::_lstore_1: store_local_long(1); break;
aoqi@0 1429 case Bytecodes::_lstore_2: store_local_long(2); break;
aoqi@0 1430 case Bytecodes::_lstore_3: store_local_long(3); break;
aoqi@0 1431
aoqi@0 1432 case Bytecodes::_multianewarray: do_multianewarray(str); break;
aoqi@0 1433
aoqi@0 1434 case Bytecodes::_new: do_new(str); break;
aoqi@0 1435
aoqi@0 1436 case Bytecodes::_newarray: do_newarray(str); break;
aoqi@0 1437
aoqi@0 1438 case Bytecodes::_pop:
aoqi@0 1439 {
aoqi@0 1440 pop();
aoqi@0 1441 break;
aoqi@0 1442 }
aoqi@0 1443 case Bytecodes::_pop2:
aoqi@0 1444 {
aoqi@0 1445 pop();
aoqi@0 1446 pop();
aoqi@0 1447 break;
aoqi@0 1448 }
aoqi@0 1449
aoqi@0 1450 case Bytecodes::_putfield: do_putfield(str); break;
aoqi@0 1451 case Bytecodes::_putstatic: do_putstatic(str); break;
aoqi@0 1452
aoqi@0 1453 case Bytecodes::_ret: do_ret(str); break;
aoqi@0 1454
aoqi@0 1455 case Bytecodes::_swap:
aoqi@0 1456 {
aoqi@0 1457 ciType* value1 = pop_value();
aoqi@0 1458 ciType* value2 = pop_value();
aoqi@0 1459 push(value1);
aoqi@0 1460 push(value2);
aoqi@0 1461 break;
aoqi@0 1462 }
aoqi@0 1463 case Bytecodes::_wide:
aoqi@0 1464 default:
aoqi@0 1465 {
aoqi@0 1466 // The iterator should skip this.
aoqi@0 1467 ShouldNotReachHere();
aoqi@0 1468 break;
aoqi@0 1469 }
aoqi@0 1470 }
aoqi@0 1471
aoqi@0 1472 if (CITraceTypeFlow) {
aoqi@0 1473 print_on(tty);
aoqi@0 1474 }
aoqi@0 1475
aoqi@0 1476 return (_trap_bci != -1);
aoqi@0 1477 }
aoqi@0 1478
aoqi@0 1479 #ifndef PRODUCT
aoqi@0 1480 // ------------------------------------------------------------------
aoqi@0 1481 // ciTypeFlow::StateVector::print_cell_on
aoqi@0 1482 void ciTypeFlow::StateVector::print_cell_on(outputStream* st, Cell c) const {
aoqi@0 1483 ciType* type = type_at(c);
aoqi@0 1484 if (type == top_type()) {
aoqi@0 1485 st->print("top");
aoqi@0 1486 } else if (type == bottom_type()) {
aoqi@0 1487 st->print("bottom");
aoqi@0 1488 } else if (type == null_type()) {
aoqi@0 1489 st->print("null");
aoqi@0 1490 } else if (type == long2_type()) {
aoqi@0 1491 st->print("long2");
aoqi@0 1492 } else if (type == double2_type()) {
aoqi@0 1493 st->print("double2");
aoqi@0 1494 } else if (is_int(type)) {
aoqi@0 1495 st->print("int");
aoqi@0 1496 } else if (is_long(type)) {
aoqi@0 1497 st->print("long");
aoqi@0 1498 } else if (is_float(type)) {
aoqi@0 1499 st->print("float");
aoqi@0 1500 } else if (is_double(type)) {
aoqi@0 1501 st->print("double");
aoqi@0 1502 } else if (type->is_return_address()) {
aoqi@0 1503 st->print("address(%d)", type->as_return_address()->bci());
aoqi@0 1504 } else {
aoqi@0 1505 if (type->is_klass()) {
aoqi@0 1506 type->as_klass()->name()->print_symbol_on(st);
aoqi@0 1507 } else {
aoqi@0 1508 st->print("UNEXPECTED TYPE");
aoqi@0 1509 type->print();
aoqi@0 1510 }
aoqi@0 1511 }
aoqi@0 1512 }
aoqi@0 1513
aoqi@0 1514 // ------------------------------------------------------------------
aoqi@0 1515 // ciTypeFlow::StateVector::print_on
aoqi@0 1516 void ciTypeFlow::StateVector::print_on(outputStream* st) const {
aoqi@0 1517 int num_locals = _outer->max_locals();
aoqi@0 1518 int num_stack = stack_size();
aoqi@0 1519 int num_monitors = monitor_count();
aoqi@0 1520 st->print_cr(" State : locals %d, stack %d, monitors %d", num_locals, num_stack, num_monitors);
aoqi@0 1521 if (num_stack >= 0) {
aoqi@0 1522 int i;
aoqi@0 1523 for (i = 0; i < num_locals; i++) {
aoqi@0 1524 st->print(" local %2d : ", i);
aoqi@0 1525 print_cell_on(st, local(i));
aoqi@0 1526 st->cr();
aoqi@0 1527 }
aoqi@0 1528 for (i = 0; i < num_stack; i++) {
aoqi@0 1529 st->print(" stack %2d : ", i);
aoqi@0 1530 print_cell_on(st, stack(i));
aoqi@0 1531 st->cr();
aoqi@0 1532 }
aoqi@0 1533 }
aoqi@0 1534 }
aoqi@0 1535 #endif
aoqi@0 1536
aoqi@0 1537
aoqi@0 1538 // ------------------------------------------------------------------
aoqi@0 1539 // ciTypeFlow::SuccIter::next
aoqi@0 1540 //
aoqi@0 1541 void ciTypeFlow::SuccIter::next() {
aoqi@0 1542 int succ_ct = _pred->successors()->length();
aoqi@0 1543 int next = _index + 1;
aoqi@0 1544 if (next < succ_ct) {
aoqi@0 1545 _index = next;
aoqi@0 1546 _succ = _pred->successors()->at(next);
aoqi@0 1547 return;
aoqi@0 1548 }
aoqi@0 1549 for (int i = next - succ_ct; i < _pred->exceptions()->length(); i++) {
aoqi@0 1550 // Do not compile any code for unloaded exception types.
aoqi@0 1551 // Following compiler passes are responsible for doing this also.
aoqi@0 1552 ciInstanceKlass* exception_klass = _pred->exc_klasses()->at(i);
aoqi@0 1553 if (exception_klass->is_loaded()) {
aoqi@0 1554 _index = next;
aoqi@0 1555 _succ = _pred->exceptions()->at(i);
aoqi@0 1556 return;
aoqi@0 1557 }
aoqi@0 1558 next++;
aoqi@0 1559 }
aoqi@0 1560 _index = -1;
aoqi@0 1561 _succ = NULL;
aoqi@0 1562 }
aoqi@0 1563
aoqi@0 1564 // ------------------------------------------------------------------
aoqi@0 1565 // ciTypeFlow::SuccIter::set_succ
aoqi@0 1566 //
aoqi@0 1567 void ciTypeFlow::SuccIter::set_succ(Block* succ) {
aoqi@0 1568 int succ_ct = _pred->successors()->length();
aoqi@0 1569 if (_index < succ_ct) {
aoqi@0 1570 _pred->successors()->at_put(_index, succ);
aoqi@0 1571 } else {
aoqi@0 1572 int idx = _index - succ_ct;
aoqi@0 1573 _pred->exceptions()->at_put(idx, succ);
aoqi@0 1574 }
aoqi@0 1575 }
aoqi@0 1576
aoqi@0 1577 // ciTypeFlow::Block
aoqi@0 1578 //
aoqi@0 1579 // A basic block.
aoqi@0 1580
aoqi@0 1581 // ------------------------------------------------------------------
aoqi@0 1582 // ciTypeFlow::Block::Block
aoqi@0 1583 ciTypeFlow::Block::Block(ciTypeFlow* outer,
aoqi@0 1584 ciBlock *ciblk,
aoqi@0 1585 ciTypeFlow::JsrSet* jsrs) {
aoqi@0 1586 _ciblock = ciblk;
aoqi@0 1587 _exceptions = NULL;
aoqi@0 1588 _exc_klasses = NULL;
aoqi@0 1589 _successors = NULL;
aoqi@0 1590 _state = new (outer->arena()) StateVector(outer);
aoqi@0 1591 JsrSet* new_jsrs =
aoqi@0 1592 new (outer->arena()) JsrSet(outer->arena(), jsrs->size());
aoqi@0 1593 jsrs->copy_into(new_jsrs);
aoqi@0 1594 _jsrs = new_jsrs;
aoqi@0 1595 _next = NULL;
aoqi@0 1596 _on_work_list = false;
aoqi@0 1597 _backedge_copy = false;
aoqi@0 1598 _has_monitorenter = false;
aoqi@0 1599 _trap_bci = -1;
aoqi@0 1600 _trap_index = 0;
aoqi@0 1601 df_init();
aoqi@0 1602
aoqi@0 1603 if (CITraceTypeFlow) {
aoqi@0 1604 tty->print_cr(">> Created new block");
aoqi@0 1605 print_on(tty);
aoqi@0 1606 }
aoqi@0 1607
aoqi@0 1608 assert(this->outer() == outer, "outer link set up");
aoqi@0 1609 assert(!outer->have_block_count(), "must not have mapped blocks yet");
aoqi@0 1610 }
aoqi@0 1611
aoqi@0 1612 // ------------------------------------------------------------------
aoqi@0 1613 // ciTypeFlow::Block::df_init
aoqi@0 1614 void ciTypeFlow::Block::df_init() {
aoqi@0 1615 _pre_order = -1; assert(!has_pre_order(), "");
aoqi@0 1616 _post_order = -1; assert(!has_post_order(), "");
aoqi@0 1617 _loop = NULL;
aoqi@0 1618 _irreducible_entry = false;
aoqi@0 1619 _rpo_next = NULL;
aoqi@0 1620 }
aoqi@0 1621
aoqi@0 1622 // ------------------------------------------------------------------
aoqi@0 1623 // ciTypeFlow::Block::successors
aoqi@0 1624 //
aoqi@0 1625 // Get the successors for this Block.
aoqi@0 1626 GrowableArray<ciTypeFlow::Block*>*
aoqi@0 1627 ciTypeFlow::Block::successors(ciBytecodeStream* str,
aoqi@0 1628 ciTypeFlow::StateVector* state,
aoqi@0 1629 ciTypeFlow::JsrSet* jsrs) {
aoqi@0 1630 if (_successors == NULL) {
aoqi@0 1631 if (CITraceTypeFlow) {
aoqi@0 1632 tty->print(">> Computing successors for block ");
aoqi@0 1633 print_value_on(tty);
aoqi@0 1634 tty->cr();
aoqi@0 1635 }
aoqi@0 1636
aoqi@0 1637 ciTypeFlow* analyzer = outer();
aoqi@0 1638 Arena* arena = analyzer->arena();
aoqi@0 1639 Block* block = NULL;
aoqi@0 1640 bool has_successor = !has_trap() &&
aoqi@0 1641 (control() != ciBlock::fall_through_bci || limit() < analyzer->code_size());
aoqi@0 1642 if (!has_successor) {
aoqi@0 1643 _successors =
aoqi@0 1644 new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
aoqi@0 1645 // No successors
aoqi@0 1646 } else if (control() == ciBlock::fall_through_bci) {
aoqi@0 1647 assert(str->cur_bci() == limit(), "bad block end");
aoqi@0 1648 // This block simply falls through to the next.
aoqi@0 1649 _successors =
aoqi@0 1650 new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
aoqi@0 1651
aoqi@0 1652 Block* block = analyzer->block_at(limit(), _jsrs);
aoqi@0 1653 assert(_successors->length() == FALL_THROUGH, "");
aoqi@0 1654 _successors->append(block);
aoqi@0 1655 } else {
aoqi@0 1656 int current_bci = str->cur_bci();
aoqi@0 1657 int next_bci = str->next_bci();
aoqi@0 1658 int branch_bci = -1;
aoqi@0 1659 Block* target = NULL;
aoqi@0 1660 assert(str->next_bci() == limit(), "bad block end");
aoqi@0 1661 // This block is not a simple fall-though. Interpret
aoqi@0 1662 // the current bytecode to find our successors.
aoqi@0 1663 switch (str->cur_bc()) {
aoqi@0 1664 case Bytecodes::_ifeq: case Bytecodes::_ifne:
aoqi@0 1665 case Bytecodes::_iflt: case Bytecodes::_ifge:
aoqi@0 1666 case Bytecodes::_ifgt: case Bytecodes::_ifle:
aoqi@0 1667 case Bytecodes::_if_icmpeq: case Bytecodes::_if_icmpne:
aoqi@0 1668 case Bytecodes::_if_icmplt: case Bytecodes::_if_icmpge:
aoqi@0 1669 case Bytecodes::_if_icmpgt: case Bytecodes::_if_icmple:
aoqi@0 1670 case Bytecodes::_if_acmpeq: case Bytecodes::_if_acmpne:
aoqi@0 1671 case Bytecodes::_ifnull: case Bytecodes::_ifnonnull:
aoqi@0 1672 // Our successors are the branch target and the next bci.
aoqi@0 1673 branch_bci = str->get_dest();
aoqi@0 1674 _successors =
aoqi@0 1675 new (arena) GrowableArray<Block*>(arena, 2, 0, NULL);
aoqi@0 1676 assert(_successors->length() == IF_NOT_TAKEN, "");
aoqi@0 1677 _successors->append(analyzer->block_at(next_bci, jsrs));
aoqi@0 1678 assert(_successors->length() == IF_TAKEN, "");
aoqi@0 1679 _successors->append(analyzer->block_at(branch_bci, jsrs));
aoqi@0 1680 break;
aoqi@0 1681
aoqi@0 1682 case Bytecodes::_goto:
aoqi@0 1683 branch_bci = str->get_dest();
aoqi@0 1684 _successors =
aoqi@0 1685 new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
aoqi@0 1686 assert(_successors->length() == GOTO_TARGET, "");
aoqi@0 1687 _successors->append(analyzer->block_at(branch_bci, jsrs));
aoqi@0 1688 break;
aoqi@0 1689
aoqi@0 1690 case Bytecodes::_jsr:
aoqi@0 1691 branch_bci = str->get_dest();
aoqi@0 1692 _successors =
aoqi@0 1693 new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
aoqi@0 1694 assert(_successors->length() == GOTO_TARGET, "");
aoqi@0 1695 _successors->append(analyzer->block_at(branch_bci, jsrs));
aoqi@0 1696 break;
aoqi@0 1697
aoqi@0 1698 case Bytecodes::_goto_w:
aoqi@0 1699 case Bytecodes::_jsr_w:
aoqi@0 1700 _successors =
aoqi@0 1701 new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
aoqi@0 1702 assert(_successors->length() == GOTO_TARGET, "");
aoqi@0 1703 _successors->append(analyzer->block_at(str->get_far_dest(), jsrs));
aoqi@0 1704 break;
aoqi@0 1705
aoqi@0 1706 case Bytecodes::_tableswitch: {
aoqi@0 1707 Bytecode_tableswitch tableswitch(str);
aoqi@0 1708
aoqi@0 1709 int len = tableswitch.length();
aoqi@0 1710 _successors =
aoqi@0 1711 new (arena) GrowableArray<Block*>(arena, len+1, 0, NULL);
aoqi@0 1712 int bci = current_bci + tableswitch.default_offset();
aoqi@0 1713 Block* block = analyzer->block_at(bci, jsrs);
aoqi@0 1714 assert(_successors->length() == SWITCH_DEFAULT, "");
aoqi@0 1715 _successors->append(block);
aoqi@0 1716 while (--len >= 0) {
aoqi@0 1717 int bci = current_bci + tableswitch.dest_offset_at(len);
aoqi@0 1718 block = analyzer->block_at(bci, jsrs);
aoqi@0 1719 assert(_successors->length() >= SWITCH_CASES, "");
aoqi@0 1720 _successors->append_if_missing(block);
aoqi@0 1721 }
aoqi@0 1722 break;
aoqi@0 1723 }
aoqi@0 1724
aoqi@0 1725 case Bytecodes::_lookupswitch: {
aoqi@0 1726 Bytecode_lookupswitch lookupswitch(str);
aoqi@0 1727
aoqi@0 1728 int npairs = lookupswitch.number_of_pairs();
aoqi@0 1729 _successors =
aoqi@0 1730 new (arena) GrowableArray<Block*>(arena, npairs+1, 0, NULL);
aoqi@0 1731 int bci = current_bci + lookupswitch.default_offset();
aoqi@0 1732 Block* block = analyzer->block_at(bci, jsrs);
aoqi@0 1733 assert(_successors->length() == SWITCH_DEFAULT, "");
aoqi@0 1734 _successors->append(block);
aoqi@0 1735 while(--npairs >= 0) {
aoqi@0 1736 LookupswitchPair pair = lookupswitch.pair_at(npairs);
aoqi@0 1737 int bci = current_bci + pair.offset();
aoqi@0 1738 Block* block = analyzer->block_at(bci, jsrs);
aoqi@0 1739 assert(_successors->length() >= SWITCH_CASES, "");
aoqi@0 1740 _successors->append_if_missing(block);
aoqi@0 1741 }
aoqi@0 1742 break;
aoqi@0 1743 }
aoqi@0 1744
aoqi@0 1745 case Bytecodes::_athrow: case Bytecodes::_ireturn:
aoqi@0 1746 case Bytecodes::_lreturn: case Bytecodes::_freturn:
aoqi@0 1747 case Bytecodes::_dreturn: case Bytecodes::_areturn:
aoqi@0 1748 case Bytecodes::_return:
aoqi@0 1749 _successors =
aoqi@0 1750 new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
aoqi@0 1751 // No successors
aoqi@0 1752 break;
aoqi@0 1753
aoqi@0 1754 case Bytecodes::_ret: {
aoqi@0 1755 _successors =
aoqi@0 1756 new (arena) GrowableArray<Block*>(arena, 1, 0, NULL);
aoqi@0 1757
aoqi@0 1758 Cell local = state->local(str->get_index());
aoqi@0 1759 ciType* return_address = state->type_at(local);
aoqi@0 1760 assert(return_address->is_return_address(), "verify: wrong type");
aoqi@0 1761 int bci = return_address->as_return_address()->bci();
aoqi@0 1762 assert(_successors->length() == GOTO_TARGET, "");
aoqi@0 1763 _successors->append(analyzer->block_at(bci, jsrs));
aoqi@0 1764 break;
aoqi@0 1765 }
aoqi@0 1766
aoqi@0 1767 case Bytecodes::_wide:
aoqi@0 1768 default:
aoqi@0 1769 ShouldNotReachHere();
aoqi@0 1770 break;
aoqi@0 1771 }
aoqi@0 1772 }
aoqi@0 1773 }
aoqi@0 1774 return _successors;
aoqi@0 1775 }
aoqi@0 1776
aoqi@0 1777 // ------------------------------------------------------------------
aoqi@0 1778 // ciTypeFlow::Block:compute_exceptions
aoqi@0 1779 //
aoqi@0 1780 // Compute the exceptional successors and types for this Block.
aoqi@0 1781 void ciTypeFlow::Block::compute_exceptions() {
aoqi@0 1782 assert(_exceptions == NULL && _exc_klasses == NULL, "repeat");
aoqi@0 1783
aoqi@0 1784 if (CITraceTypeFlow) {
aoqi@0 1785 tty->print(">> Computing exceptions for block ");
aoqi@0 1786 print_value_on(tty);
aoqi@0 1787 tty->cr();
aoqi@0 1788 }
aoqi@0 1789
aoqi@0 1790 ciTypeFlow* analyzer = outer();
aoqi@0 1791 Arena* arena = analyzer->arena();
aoqi@0 1792
aoqi@0 1793 // Any bci in the block will do.
aoqi@0 1794 ciExceptionHandlerStream str(analyzer->method(), start());
aoqi@0 1795
aoqi@0 1796 // Allocate our growable arrays.
aoqi@0 1797 int exc_count = str.count();
aoqi@0 1798 _exceptions = new (arena) GrowableArray<Block*>(arena, exc_count, 0, NULL);
aoqi@0 1799 _exc_klasses = new (arena) GrowableArray<ciInstanceKlass*>(arena, exc_count,
aoqi@0 1800 0, NULL);
aoqi@0 1801
aoqi@0 1802 for ( ; !str.is_done(); str.next()) {
aoqi@0 1803 ciExceptionHandler* handler = str.handler();
aoqi@0 1804 int bci = handler->handler_bci();
aoqi@0 1805 ciInstanceKlass* klass = NULL;
aoqi@0 1806 if (bci == -1) {
aoqi@0 1807 // There is no catch all. It is possible to exit the method.
aoqi@0 1808 break;
aoqi@0 1809 }
aoqi@0 1810 if (handler->is_catch_all()) {
aoqi@0 1811 klass = analyzer->env()->Throwable_klass();
aoqi@0 1812 } else {
aoqi@0 1813 klass = handler->catch_klass();
aoqi@0 1814 }
aoqi@0 1815 _exceptions->append(analyzer->block_at(bci, _jsrs));
aoqi@0 1816 _exc_klasses->append(klass);
aoqi@0 1817 }
aoqi@0 1818 }
aoqi@0 1819
aoqi@0 1820 // ------------------------------------------------------------------
aoqi@0 1821 // ciTypeFlow::Block::set_backedge_copy
aoqi@0 1822 // Use this only to make a pre-existing public block into a backedge copy.
aoqi@0 1823 void ciTypeFlow::Block::set_backedge_copy(bool z) {
aoqi@0 1824 assert(z || (z == is_backedge_copy()), "cannot make a backedge copy public");
aoqi@0 1825 _backedge_copy = z;
aoqi@0 1826 }
aoqi@0 1827
aoqi@0 1828 // ------------------------------------------------------------------
aoqi@0 1829 // ciTypeFlow::Block::is_clonable_exit
aoqi@0 1830 //
aoqi@0 1831 // At most 2 normal successors, one of which continues looping,
aoqi@0 1832 // and all exceptional successors must exit.
aoqi@0 1833 bool ciTypeFlow::Block::is_clonable_exit(ciTypeFlow::Loop* lp) {
aoqi@0 1834 int normal_cnt = 0;
aoqi@0 1835 int in_loop_cnt = 0;
aoqi@0 1836 for (SuccIter iter(this); !iter.done(); iter.next()) {
aoqi@0 1837 Block* succ = iter.succ();
aoqi@0 1838 if (iter.is_normal_ctrl()) {
aoqi@0 1839 if (++normal_cnt > 2) return false;
aoqi@0 1840 if (lp->contains(succ->loop())) {
aoqi@0 1841 if (++in_loop_cnt > 1) return false;
aoqi@0 1842 }
aoqi@0 1843 } else {
aoqi@0 1844 if (lp->contains(succ->loop())) return false;
aoqi@0 1845 }
aoqi@0 1846 }
aoqi@0 1847 return in_loop_cnt == 1;
aoqi@0 1848 }
aoqi@0 1849
aoqi@0 1850 // ------------------------------------------------------------------
aoqi@0 1851 // ciTypeFlow::Block::looping_succ
aoqi@0 1852 //
aoqi@0 1853 ciTypeFlow::Block* ciTypeFlow::Block::looping_succ(ciTypeFlow::Loop* lp) {
aoqi@0 1854 assert(successors()->length() <= 2, "at most 2 normal successors");
aoqi@0 1855 for (SuccIter iter(this); !iter.done(); iter.next()) {
aoqi@0 1856 Block* succ = iter.succ();
aoqi@0 1857 if (lp->contains(succ->loop())) {
aoqi@0 1858 return succ;
aoqi@0 1859 }
aoqi@0 1860 }
aoqi@0 1861 return NULL;
aoqi@0 1862 }
aoqi@0 1863
aoqi@0 1864 #ifndef PRODUCT
aoqi@0 1865 // ------------------------------------------------------------------
aoqi@0 1866 // ciTypeFlow::Block::print_value_on
aoqi@0 1867 void ciTypeFlow::Block::print_value_on(outputStream* st) const {
aoqi@0 1868 if (has_pre_order()) st->print("#%-2d ", pre_order());
aoqi@0 1869 if (has_rpo()) st->print("rpo#%-2d ", rpo());
aoqi@0 1870 st->print("[%d - %d)", start(), limit());
aoqi@0 1871 if (is_loop_head()) st->print(" lphd");
aoqi@0 1872 if (is_irreducible_entry()) st->print(" irred");
aoqi@0 1873 if (_jsrs->size() > 0) { st->print("/"); _jsrs->print_on(st); }
aoqi@0 1874 if (is_backedge_copy()) st->print("/backedge_copy");
aoqi@0 1875 }
aoqi@0 1876
aoqi@0 1877 // ------------------------------------------------------------------
aoqi@0 1878 // ciTypeFlow::Block::print_on
aoqi@0 1879 void ciTypeFlow::Block::print_on(outputStream* st) const {
aoqi@0 1880 if ((Verbose || WizardMode) && (limit() >= 0)) {
aoqi@0 1881 // Don't print 'dummy' blocks (i.e. blocks with limit() '-1')
aoqi@0 1882 outer()->method()->print_codes_on(start(), limit(), st);
aoqi@0 1883 }
aoqi@0 1884 st->print_cr(" ==================================================== ");
aoqi@0 1885 st->print (" ");
aoqi@0 1886 print_value_on(st);
aoqi@0 1887 st->print(" Stored locals: "); def_locals()->print_on(st, outer()->method()->max_locals()); tty->cr();
aoqi@0 1888 if (loop() && loop()->parent() != NULL) {
aoqi@0 1889 st->print(" loops:");
aoqi@0 1890 Loop* lp = loop();
aoqi@0 1891 do {
aoqi@0 1892 st->print(" %d<-%d", lp->head()->pre_order(),lp->tail()->pre_order());
aoqi@0 1893 if (lp->is_irreducible()) st->print("(ir)");
aoqi@0 1894 lp = lp->parent();
aoqi@0 1895 } while (lp->parent() != NULL);
aoqi@0 1896 }
aoqi@0 1897 st->cr();
aoqi@0 1898 _state->print_on(st);
aoqi@0 1899 if (_successors == NULL) {
aoqi@0 1900 st->print_cr(" No successor information");
aoqi@0 1901 } else {
aoqi@0 1902 int num_successors = _successors->length();
aoqi@0 1903 st->print_cr(" Successors : %d", num_successors);
aoqi@0 1904 for (int i = 0; i < num_successors; i++) {
aoqi@0 1905 Block* successor = _successors->at(i);
aoqi@0 1906 st->print(" ");
aoqi@0 1907 successor->print_value_on(st);
aoqi@0 1908 st->cr();
aoqi@0 1909 }
aoqi@0 1910 }
aoqi@0 1911 if (_exceptions == NULL) {
aoqi@0 1912 st->print_cr(" No exception information");
aoqi@0 1913 } else {
aoqi@0 1914 int num_exceptions = _exceptions->length();
aoqi@0 1915 st->print_cr(" Exceptions : %d", num_exceptions);
aoqi@0 1916 for (int i = 0; i < num_exceptions; i++) {
aoqi@0 1917 Block* exc_succ = _exceptions->at(i);
aoqi@0 1918 ciInstanceKlass* exc_klass = _exc_klasses->at(i);
aoqi@0 1919 st->print(" ");
aoqi@0 1920 exc_succ->print_value_on(st);
aoqi@0 1921 st->print(" -- ");
aoqi@0 1922 exc_klass->name()->print_symbol_on(st);
aoqi@0 1923 st->cr();
aoqi@0 1924 }
aoqi@0 1925 }
aoqi@0 1926 if (has_trap()) {
aoqi@0 1927 st->print_cr(" Traps on %d with trap index %d", trap_bci(), trap_index());
aoqi@0 1928 }
aoqi@0 1929 st->print_cr(" ==================================================== ");
aoqi@0 1930 }
aoqi@0 1931 #endif
aoqi@0 1932
aoqi@0 1933 #ifndef PRODUCT
aoqi@0 1934 // ------------------------------------------------------------------
aoqi@0 1935 // ciTypeFlow::LocalSet::print_on
aoqi@0 1936 void ciTypeFlow::LocalSet::print_on(outputStream* st, int limit) const {
aoqi@0 1937 st->print("{");
aoqi@0 1938 for (int i = 0; i < max; i++) {
aoqi@0 1939 if (test(i)) st->print(" %d", i);
aoqi@0 1940 }
aoqi@0 1941 if (limit > max) {
aoqi@0 1942 st->print(" %d..%d ", max, limit);
aoqi@0 1943 }
aoqi@0 1944 st->print(" }");
aoqi@0 1945 }
aoqi@0 1946 #endif
aoqi@0 1947
aoqi@0 1948 // ciTypeFlow
aoqi@0 1949 //
aoqi@0 1950 // This is a pass over the bytecodes which computes the following:
aoqi@0 1951 // basic block structure
aoqi@0 1952 // interpreter type-states (a la the verifier)
aoqi@0 1953
aoqi@0 1954 // ------------------------------------------------------------------
aoqi@0 1955 // ciTypeFlow::ciTypeFlow
aoqi@0 1956 ciTypeFlow::ciTypeFlow(ciEnv* env, ciMethod* method, int osr_bci) {
aoqi@0 1957 _env = env;
aoqi@0 1958 _method = method;
aoqi@0 1959 _methodBlocks = method->get_method_blocks();
aoqi@0 1960 _max_locals = method->max_locals();
aoqi@0 1961 _max_stack = method->max_stack();
aoqi@0 1962 _code_size = method->code_size();
aoqi@0 1963 _has_irreducible_entry = false;
aoqi@0 1964 _osr_bci = osr_bci;
aoqi@0 1965 _failure_reason = NULL;
aoqi@0 1966 assert(0 <= start_bci() && start_bci() < code_size() , err_msg("correct osr_bci argument: 0 <= %d < %d", start_bci(), code_size()));
aoqi@0 1967 _work_list = NULL;
aoqi@0 1968
aoqi@0 1969 _ciblock_count = _methodBlocks->num_blocks();
aoqi@0 1970 _idx_to_blocklist = NEW_ARENA_ARRAY(arena(), GrowableArray<Block*>*, _ciblock_count);
aoqi@0 1971 for (int i = 0; i < _ciblock_count; i++) {
aoqi@0 1972 _idx_to_blocklist[i] = NULL;
aoqi@0 1973 }
aoqi@0 1974 _block_map = NULL; // until all blocks are seen
aoqi@0 1975 _jsr_count = 0;
aoqi@0 1976 _jsr_records = NULL;
aoqi@0 1977 }
aoqi@0 1978
aoqi@0 1979 // ------------------------------------------------------------------
aoqi@0 1980 // ciTypeFlow::work_list_next
aoqi@0 1981 //
aoqi@0 1982 // Get the next basic block from our work list.
aoqi@0 1983 ciTypeFlow::Block* ciTypeFlow::work_list_next() {
aoqi@0 1984 assert(!work_list_empty(), "work list must not be empty");
aoqi@0 1985 Block* next_block = _work_list;
aoqi@0 1986 _work_list = next_block->next();
aoqi@0 1987 next_block->set_next(NULL);
aoqi@0 1988 next_block->set_on_work_list(false);
aoqi@0 1989 return next_block;
aoqi@0 1990 }
aoqi@0 1991
aoqi@0 1992 // ------------------------------------------------------------------
aoqi@0 1993 // ciTypeFlow::add_to_work_list
aoqi@0 1994 //
aoqi@0 1995 // Add a basic block to our work list.
aoqi@0 1996 // List is sorted by decreasing postorder sort (same as increasing RPO)
aoqi@0 1997 void ciTypeFlow::add_to_work_list(ciTypeFlow::Block* block) {
aoqi@0 1998 assert(!block->is_on_work_list(), "must not already be on work list");
aoqi@0 1999
aoqi@0 2000 if (CITraceTypeFlow) {
aoqi@0 2001 tty->print(">> Adding block ");
aoqi@0 2002 block->print_value_on(tty);
aoqi@0 2003 tty->print_cr(" to the work list : ");
aoqi@0 2004 }
aoqi@0 2005
aoqi@0 2006 block->set_on_work_list(true);
aoqi@0 2007
aoqi@0 2008 // decreasing post order sort
aoqi@0 2009
aoqi@0 2010 Block* prev = NULL;
aoqi@0 2011 Block* current = _work_list;
aoqi@0 2012 int po = block->post_order();
aoqi@0 2013 while (current != NULL) {
aoqi@0 2014 if (!current->has_post_order() || po > current->post_order())
aoqi@0 2015 break;
aoqi@0 2016 prev = current;
aoqi@0 2017 current = current->next();
aoqi@0 2018 }
aoqi@0 2019 if (prev == NULL) {
aoqi@0 2020 block->set_next(_work_list);
aoqi@0 2021 _work_list = block;
aoqi@0 2022 } else {
aoqi@0 2023 block->set_next(current);
aoqi@0 2024 prev->set_next(block);
aoqi@0 2025 }
aoqi@0 2026
aoqi@0 2027 if (CITraceTypeFlow) {
aoqi@0 2028 tty->cr();
aoqi@0 2029 }
aoqi@0 2030 }
aoqi@0 2031
aoqi@0 2032 // ------------------------------------------------------------------
aoqi@0 2033 // ciTypeFlow::block_at
aoqi@0 2034 //
aoqi@0 2035 // Return the block beginning at bci which has a JsrSet compatible
aoqi@0 2036 // with jsrs.
aoqi@0 2037 ciTypeFlow::Block* ciTypeFlow::block_at(int bci, ciTypeFlow::JsrSet* jsrs, CreateOption option) {
aoqi@0 2038 // First find the right ciBlock.
aoqi@0 2039 if (CITraceTypeFlow) {
aoqi@0 2040 tty->print(">> Requesting block for %d/", bci);
aoqi@0 2041 jsrs->print_on(tty);
aoqi@0 2042 tty->cr();
aoqi@0 2043 }
aoqi@0 2044
aoqi@0 2045 ciBlock* ciblk = _methodBlocks->block_containing(bci);
aoqi@0 2046 assert(ciblk->start_bci() == bci, "bad ciBlock boundaries");
aoqi@0 2047 Block* block = get_block_for(ciblk->index(), jsrs, option);
aoqi@0 2048
aoqi@0 2049 assert(block == NULL? (option == no_create): block->is_backedge_copy() == (option == create_backedge_copy), "create option consistent with result");
aoqi@0 2050
aoqi@0 2051 if (CITraceTypeFlow) {
aoqi@0 2052 if (block != NULL) {
aoqi@0 2053 tty->print(">> Found block ");
aoqi@0 2054 block->print_value_on(tty);
aoqi@0 2055 tty->cr();
aoqi@0 2056 } else {
aoqi@0 2057 tty->print_cr(">> No such block.");
aoqi@0 2058 }
aoqi@0 2059 }
aoqi@0 2060
aoqi@0 2061 return block;
aoqi@0 2062 }
aoqi@0 2063
aoqi@0 2064 // ------------------------------------------------------------------
aoqi@0 2065 // ciTypeFlow::make_jsr_record
aoqi@0 2066 //
aoqi@0 2067 // Make a JsrRecord for a given (entry, return) pair, if such a record
aoqi@0 2068 // does not already exist.
aoqi@0 2069 ciTypeFlow::JsrRecord* ciTypeFlow::make_jsr_record(int entry_address,
aoqi@0 2070 int return_address) {
aoqi@0 2071 if (_jsr_records == NULL) {
aoqi@0 2072 _jsr_records = new (arena()) GrowableArray<JsrRecord*>(arena(),
aoqi@0 2073 _jsr_count,
aoqi@0 2074 0,
aoqi@0 2075 NULL);
aoqi@0 2076 }
aoqi@0 2077 JsrRecord* record = NULL;
aoqi@0 2078 int len = _jsr_records->length();
aoqi@0 2079 for (int i = 0; i < len; i++) {
aoqi@0 2080 JsrRecord* record = _jsr_records->at(i);
aoqi@0 2081 if (record->entry_address() == entry_address &&
aoqi@0 2082 record->return_address() == return_address) {
aoqi@0 2083 return record;
aoqi@0 2084 }
aoqi@0 2085 }
aoqi@0 2086
aoqi@0 2087 record = new (arena()) JsrRecord(entry_address, return_address);
aoqi@0 2088 _jsr_records->append(record);
aoqi@0 2089 return record;
aoqi@0 2090 }
aoqi@0 2091
aoqi@0 2092 // ------------------------------------------------------------------
aoqi@0 2093 // ciTypeFlow::flow_exceptions
aoqi@0 2094 //
aoqi@0 2095 // Merge the current state into all exceptional successors at the
aoqi@0 2096 // current point in the code.
aoqi@0 2097 void ciTypeFlow::flow_exceptions(GrowableArray<ciTypeFlow::Block*>* exceptions,
aoqi@0 2098 GrowableArray<ciInstanceKlass*>* exc_klasses,
aoqi@0 2099 ciTypeFlow::StateVector* state) {
aoqi@0 2100 int len = exceptions->length();
aoqi@0 2101 assert(exc_klasses->length() == len, "must have same length");
aoqi@0 2102 for (int i = 0; i < len; i++) {
aoqi@0 2103 Block* block = exceptions->at(i);
aoqi@0 2104 ciInstanceKlass* exception_klass = exc_klasses->at(i);
aoqi@0 2105
aoqi@0 2106 if (!exception_klass->is_loaded()) {
aoqi@0 2107 // Do not compile any code for unloaded exception types.
aoqi@0 2108 // Following compiler passes are responsible for doing this also.
aoqi@0 2109 continue;
aoqi@0 2110 }
aoqi@0 2111
aoqi@0 2112 if (block->meet_exception(exception_klass, state)) {
aoqi@0 2113 // Block was modified and has PO. Add it to the work list.
aoqi@0 2114 if (block->has_post_order() &&
aoqi@0 2115 !block->is_on_work_list()) {
aoqi@0 2116 add_to_work_list(block);
aoqi@0 2117 }
aoqi@0 2118 }
aoqi@0 2119 }
aoqi@0 2120 }
aoqi@0 2121
aoqi@0 2122 // ------------------------------------------------------------------
aoqi@0 2123 // ciTypeFlow::flow_successors
aoqi@0 2124 //
aoqi@0 2125 // Merge the current state into all successors at the current point
aoqi@0 2126 // in the code.
aoqi@0 2127 void ciTypeFlow::flow_successors(GrowableArray<ciTypeFlow::Block*>* successors,
aoqi@0 2128 ciTypeFlow::StateVector* state) {
aoqi@0 2129 int len = successors->length();
aoqi@0 2130 for (int i = 0; i < len; i++) {
aoqi@0 2131 Block* block = successors->at(i);
aoqi@0 2132 if (block->meet(state)) {
aoqi@0 2133 // Block was modified and has PO. Add it to the work list.
aoqi@0 2134 if (block->has_post_order() &&
aoqi@0 2135 !block->is_on_work_list()) {
aoqi@0 2136 add_to_work_list(block);
aoqi@0 2137 }
aoqi@0 2138 }
aoqi@0 2139 }
aoqi@0 2140 }
aoqi@0 2141
aoqi@0 2142 // ------------------------------------------------------------------
aoqi@0 2143 // ciTypeFlow::can_trap
aoqi@0 2144 //
aoqi@0 2145 // Tells if a given instruction is able to generate an exception edge.
aoqi@0 2146 bool ciTypeFlow::can_trap(ciBytecodeStream& str) {
aoqi@0 2147 // Cf. GenerateOopMap::do_exception_edge.
aoqi@0 2148 if (!Bytecodes::can_trap(str.cur_bc())) return false;
aoqi@0 2149
aoqi@0 2150 switch (str.cur_bc()) {
aoqi@0 2151 // %%% FIXME: ldc of Class can generate an exception
aoqi@0 2152 case Bytecodes::_ldc:
aoqi@0 2153 case Bytecodes::_ldc_w:
aoqi@0 2154 case Bytecodes::_ldc2_w:
aoqi@0 2155 case Bytecodes::_aload_0:
aoqi@0 2156 // These bytecodes can trap for rewriting. We need to assume that
aoqi@0 2157 // they do not throw exceptions to make the monitor analysis work.
aoqi@0 2158 return false;
aoqi@0 2159
aoqi@0 2160 case Bytecodes::_ireturn:
aoqi@0 2161 case Bytecodes::_lreturn:
aoqi@0 2162 case Bytecodes::_freturn:
aoqi@0 2163 case Bytecodes::_dreturn:
aoqi@0 2164 case Bytecodes::_areturn:
aoqi@0 2165 case Bytecodes::_return:
aoqi@0 2166 // We can assume the monitor stack is empty in this analysis.
aoqi@0 2167 return false;
aoqi@0 2168
aoqi@0 2169 case Bytecodes::_monitorexit:
aoqi@0 2170 // We can assume monitors are matched in this analysis.
aoqi@0 2171 return false;
aoqi@0 2172 }
aoqi@0 2173
aoqi@0 2174 return true;
aoqi@0 2175 }
aoqi@0 2176
aoqi@0 2177 // ------------------------------------------------------------------
aoqi@0 2178 // ciTypeFlow::clone_loop_heads
aoqi@0 2179 //
aoqi@0 2180 // Clone the loop heads
aoqi@0 2181 bool ciTypeFlow::clone_loop_heads(Loop* lp, StateVector* temp_vector, JsrSet* temp_set) {
aoqi@0 2182 bool rslt = false;
aoqi@0 2183 for (PreorderLoops iter(loop_tree_root()); !iter.done(); iter.next()) {
aoqi@0 2184 lp = iter.current();
aoqi@0 2185 Block* head = lp->head();
aoqi@0 2186 if (lp == loop_tree_root() ||
aoqi@0 2187 lp->is_irreducible() ||
aoqi@0 2188 !head->is_clonable_exit(lp))
aoqi@0 2189 continue;
aoqi@0 2190
aoqi@0 2191 // Avoid BoxLock merge.
aoqi@0 2192 if (EliminateNestedLocks && head->has_monitorenter())
aoqi@0 2193 continue;
aoqi@0 2194
aoqi@0 2195 // check not already cloned
aoqi@0 2196 if (head->backedge_copy_count() != 0)
aoqi@0 2197 continue;
aoqi@0 2198
aoqi@0 2199 // Don't clone head of OSR loop to get correct types in start block.
aoqi@0 2200 if (is_osr_flow() && head->start() == start_bci())
aoqi@0 2201 continue;
aoqi@0 2202
aoqi@0 2203 // check _no_ shared head below us
aoqi@0 2204 Loop* ch;
aoqi@0 2205 for (ch = lp->child(); ch != NULL && ch->head() != head; ch = ch->sibling());
aoqi@0 2206 if (ch != NULL)
aoqi@0 2207 continue;
aoqi@0 2208
aoqi@0 2209 // Clone head
aoqi@0 2210 Block* new_head = head->looping_succ(lp);
aoqi@0 2211 Block* clone = clone_loop_head(lp, temp_vector, temp_set);
aoqi@0 2212 // Update lp's info
aoqi@0 2213 clone->set_loop(lp);
aoqi@0 2214 lp->set_head(new_head);
aoqi@0 2215 lp->set_tail(clone);
aoqi@0 2216 // And move original head into outer loop
aoqi@0 2217 head->set_loop(lp->parent());
aoqi@0 2218
aoqi@0 2219 rslt = true;
aoqi@0 2220 }
aoqi@0 2221 return rslt;
aoqi@0 2222 }
aoqi@0 2223
aoqi@0 2224 // ------------------------------------------------------------------
aoqi@0 2225 // ciTypeFlow::clone_loop_head
aoqi@0 2226 //
aoqi@0 2227 // Clone lp's head and replace tail's successors with clone.
aoqi@0 2228 //
aoqi@0 2229 // |
aoqi@0 2230 // v
aoqi@0 2231 // head <-> body
aoqi@0 2232 // |
aoqi@0 2233 // v
aoqi@0 2234 // exit
aoqi@0 2235 //
aoqi@0 2236 // new_head
aoqi@0 2237 //
aoqi@0 2238 // |
aoqi@0 2239 // v
aoqi@0 2240 // head ----------\
aoqi@0 2241 // | |
aoqi@0 2242 // | v
aoqi@0 2243 // | clone <-> body
aoqi@0 2244 // | |
aoqi@0 2245 // | /--/
aoqi@0 2246 // | |
aoqi@0 2247 // v v
aoqi@0 2248 // exit
aoqi@0 2249 //
aoqi@0 2250 ciTypeFlow::Block* ciTypeFlow::clone_loop_head(Loop* lp, StateVector* temp_vector, JsrSet* temp_set) {
aoqi@0 2251 Block* head = lp->head();
aoqi@0 2252 Block* tail = lp->tail();
aoqi@0 2253 if (CITraceTypeFlow) {
aoqi@0 2254 tty->print(">> Requesting clone of loop head "); head->print_value_on(tty);
aoqi@0 2255 tty->print(" for predecessor "); tail->print_value_on(tty);
aoqi@0 2256 tty->cr();
aoqi@0 2257 }
aoqi@0 2258 Block* clone = block_at(head->start(), head->jsrs(), create_backedge_copy);
aoqi@0 2259 assert(clone->backedge_copy_count() == 1, "one backedge copy for all back edges");
aoqi@0 2260
aoqi@0 2261 assert(!clone->has_pre_order(), "just created");
aoqi@0 2262 clone->set_next_pre_order();
aoqi@0 2263
aoqi@0 2264 // Insert clone after (orig) tail in reverse post order
aoqi@0 2265 clone->set_rpo_next(tail->rpo_next());
aoqi@0 2266 tail->set_rpo_next(clone);
aoqi@0 2267
aoqi@0 2268 // tail->head becomes tail->clone
aoqi@0 2269 for (SuccIter iter(tail); !iter.done(); iter.next()) {
aoqi@0 2270 if (iter.succ() == head) {
aoqi@0 2271 iter.set_succ(clone);
aoqi@0 2272 }
aoqi@0 2273 }
aoqi@0 2274 flow_block(tail, temp_vector, temp_set);
aoqi@0 2275 if (head == tail) {
aoqi@0 2276 // For self-loops, clone->head becomes clone->clone
aoqi@0 2277 flow_block(clone, temp_vector, temp_set);
aoqi@0 2278 for (SuccIter iter(clone); !iter.done(); iter.next()) {
aoqi@0 2279 if (iter.succ() == head) {
aoqi@0 2280 iter.set_succ(clone);
aoqi@0 2281 break;
aoqi@0 2282 }
aoqi@0 2283 }
aoqi@0 2284 }
aoqi@0 2285 flow_block(clone, temp_vector, temp_set);
aoqi@0 2286
aoqi@0 2287 return clone;
aoqi@0 2288 }
aoqi@0 2289
aoqi@0 2290 // ------------------------------------------------------------------
aoqi@0 2291 // ciTypeFlow::flow_block
aoqi@0 2292 //
aoqi@0 2293 // Interpret the effects of the bytecodes on the incoming state
aoqi@0 2294 // vector of a basic block. Push the changed state to succeeding
aoqi@0 2295 // basic blocks.
aoqi@0 2296 void ciTypeFlow::flow_block(ciTypeFlow::Block* block,
aoqi@0 2297 ciTypeFlow::StateVector* state,
aoqi@0 2298 ciTypeFlow::JsrSet* jsrs) {
aoqi@0 2299 if (CITraceTypeFlow) {
aoqi@0 2300 tty->print("\n>> ANALYZING BLOCK : ");
aoqi@0 2301 tty->cr();
aoqi@0 2302 block->print_on(tty);
aoqi@0 2303 }
aoqi@0 2304 assert(block->has_pre_order(), "pre-order is assigned before 1st flow");
aoqi@0 2305
aoqi@0 2306 int start = block->start();
aoqi@0 2307 int limit = block->limit();
aoqi@0 2308 int control = block->control();
aoqi@0 2309 if (control != ciBlock::fall_through_bci) {
aoqi@0 2310 limit = control;
aoqi@0 2311 }
aoqi@0 2312
aoqi@0 2313 // Grab the state from the current block.
aoqi@0 2314 block->copy_state_into(state);
aoqi@0 2315 state->def_locals()->clear();
aoqi@0 2316
aoqi@0 2317 GrowableArray<Block*>* exceptions = block->exceptions();
aoqi@0 2318 GrowableArray<ciInstanceKlass*>* exc_klasses = block->exc_klasses();
aoqi@0 2319 bool has_exceptions = exceptions->length() > 0;
aoqi@0 2320
aoqi@0 2321 bool exceptions_used = false;
aoqi@0 2322
aoqi@0 2323 ciBytecodeStream str(method());
aoqi@0 2324 str.reset_to_bci(start);
aoqi@0 2325 Bytecodes::Code code;
aoqi@0 2326 while ((code = str.next()) != ciBytecodeStream::EOBC() &&
aoqi@0 2327 str.cur_bci() < limit) {
aoqi@0 2328 // Check for exceptional control flow from this point.
aoqi@0 2329 if (has_exceptions && can_trap(str)) {
aoqi@0 2330 flow_exceptions(exceptions, exc_klasses, state);
aoqi@0 2331 exceptions_used = true;
aoqi@0 2332 }
aoqi@0 2333 // Apply the effects of the current bytecode to our state.
aoqi@0 2334 bool res = state->apply_one_bytecode(&str);
aoqi@0 2335
aoqi@0 2336 // Watch for bailouts.
aoqi@0 2337 if (failing()) return;
aoqi@0 2338
aoqi@0 2339 if (str.cur_bc() == Bytecodes::_monitorenter) {
aoqi@0 2340 block->set_has_monitorenter();
aoqi@0 2341 }
aoqi@0 2342
aoqi@0 2343 if (res) {
aoqi@0 2344
aoqi@0 2345 // We have encountered a trap. Record it in this block.
aoqi@0 2346 block->set_trap(state->trap_bci(), state->trap_index());
aoqi@0 2347
aoqi@0 2348 if (CITraceTypeFlow) {
aoqi@0 2349 tty->print_cr(">> Found trap");
aoqi@0 2350 block->print_on(tty);
aoqi@0 2351 }
aoqi@0 2352
aoqi@0 2353 // Save set of locals defined in this block
aoqi@0 2354 block->def_locals()->add(state->def_locals());
aoqi@0 2355
aoqi@0 2356 // Record (no) successors.
aoqi@0 2357 block->successors(&str, state, jsrs);
aoqi@0 2358
aoqi@0 2359 assert(!has_exceptions || exceptions_used, "Not removing exceptions");
aoqi@0 2360
aoqi@0 2361 // Discontinue interpretation of this Block.
aoqi@0 2362 return;
aoqi@0 2363 }
aoqi@0 2364 }
aoqi@0 2365
aoqi@0 2366 GrowableArray<Block*>* successors = NULL;
aoqi@0 2367 if (control != ciBlock::fall_through_bci) {
aoqi@0 2368 // Check for exceptional control flow from this point.
aoqi@0 2369 if (has_exceptions && can_trap(str)) {
aoqi@0 2370 flow_exceptions(exceptions, exc_klasses, state);
aoqi@0 2371 exceptions_used = true;
aoqi@0 2372 }
aoqi@0 2373
aoqi@0 2374 // Fix the JsrSet to reflect effect of the bytecode.
aoqi@0 2375 block->copy_jsrs_into(jsrs);
aoqi@0 2376 jsrs->apply_control(this, &str, state);
aoqi@0 2377
aoqi@0 2378 // Find successor edges based on old state and new JsrSet.
aoqi@0 2379 successors = block->successors(&str, state, jsrs);
aoqi@0 2380
aoqi@0 2381 // Apply the control changes to the state.
aoqi@0 2382 state->apply_one_bytecode(&str);
aoqi@0 2383 } else {
aoqi@0 2384 // Fall through control
aoqi@0 2385 successors = block->successors(&str, NULL, NULL);
aoqi@0 2386 }
aoqi@0 2387
aoqi@0 2388 // Save set of locals defined in this block
aoqi@0 2389 block->def_locals()->add(state->def_locals());
aoqi@0 2390
aoqi@0 2391 // Remove untaken exception paths
aoqi@0 2392 if (!exceptions_used)
aoqi@0 2393 exceptions->clear();
aoqi@0 2394
aoqi@0 2395 // Pass our state to successors.
aoqi@0 2396 flow_successors(successors, state);
aoqi@0 2397 }
aoqi@0 2398
aoqi@0 2399 // ------------------------------------------------------------------
aoqi@0 2400 // ciTypeFlow::PostOrderLoops::next
aoqi@0 2401 //
aoqi@0 2402 // Advance to next loop tree using a postorder, left-to-right traversal.
aoqi@0 2403 void ciTypeFlow::PostorderLoops::next() {
aoqi@0 2404 assert(!done(), "must not be done.");
aoqi@0 2405 if (_current->sibling() != NULL) {
aoqi@0 2406 _current = _current->sibling();
aoqi@0 2407 while (_current->child() != NULL) {
aoqi@0 2408 _current = _current->child();
aoqi@0 2409 }
aoqi@0 2410 } else {
aoqi@0 2411 _current = _current->parent();
aoqi@0 2412 }
aoqi@0 2413 }
aoqi@0 2414
aoqi@0 2415 // ------------------------------------------------------------------
aoqi@0 2416 // ciTypeFlow::PreOrderLoops::next
aoqi@0 2417 //
aoqi@0 2418 // Advance to next loop tree using a preorder, left-to-right traversal.
aoqi@0 2419 void ciTypeFlow::PreorderLoops::next() {
aoqi@0 2420 assert(!done(), "must not be done.");
aoqi@0 2421 if (_current->child() != NULL) {
aoqi@0 2422 _current = _current->child();
aoqi@0 2423 } else if (_current->sibling() != NULL) {
aoqi@0 2424 _current = _current->sibling();
aoqi@0 2425 } else {
aoqi@0 2426 while (_current != _root && _current->sibling() == NULL) {
aoqi@0 2427 _current = _current->parent();
aoqi@0 2428 }
aoqi@0 2429 if (_current == _root) {
aoqi@0 2430 _current = NULL;
aoqi@0 2431 assert(done(), "must be done.");
aoqi@0 2432 } else {
aoqi@0 2433 assert(_current->sibling() != NULL, "must be more to do");
aoqi@0 2434 _current = _current->sibling();
aoqi@0 2435 }
aoqi@0 2436 }
aoqi@0 2437 }
aoqi@0 2438
aoqi@0 2439 // ------------------------------------------------------------------
aoqi@0 2440 // ciTypeFlow::Loop::sorted_merge
aoqi@0 2441 //
aoqi@0 2442 // Merge the branch lp into this branch, sorting on the loop head
aoqi@0 2443 // pre_orders. Returns the leaf of the merged branch.
aoqi@0 2444 // Child and sibling pointers will be setup later.
aoqi@0 2445 // Sort is (looking from leaf towards the root)
aoqi@0 2446 // descending on primary key: loop head's pre_order, and
aoqi@0 2447 // ascending on secondary key: loop tail's pre_order.
aoqi@0 2448 ciTypeFlow::Loop* ciTypeFlow::Loop::sorted_merge(Loop* lp) {
aoqi@0 2449 Loop* leaf = this;
aoqi@0 2450 Loop* prev = NULL;
aoqi@0 2451 Loop* current = leaf;
aoqi@0 2452 while (lp != NULL) {
aoqi@0 2453 int lp_pre_order = lp->head()->pre_order();
aoqi@0 2454 // Find insertion point for "lp"
aoqi@0 2455 while (current != NULL) {
aoqi@0 2456 if (current == lp)
aoqi@0 2457 return leaf; // Already in list
aoqi@0 2458 if (current->head()->pre_order() < lp_pre_order)
aoqi@0 2459 break;
aoqi@0 2460 if (current->head()->pre_order() == lp_pre_order &&
aoqi@0 2461 current->tail()->pre_order() > lp->tail()->pre_order()) {
aoqi@0 2462 break;
aoqi@0 2463 }
aoqi@0 2464 prev = current;
aoqi@0 2465 current = current->parent();
aoqi@0 2466 }
aoqi@0 2467 Loop* next_lp = lp->parent(); // Save future list of items to insert
aoqi@0 2468 // Insert lp before current
aoqi@0 2469 lp->set_parent(current);
aoqi@0 2470 if (prev != NULL) {
aoqi@0 2471 prev->set_parent(lp);
aoqi@0 2472 } else {
aoqi@0 2473 leaf = lp;
aoqi@0 2474 }
aoqi@0 2475 prev = lp; // Inserted item is new prev[ious]
aoqi@0 2476 lp = next_lp; // Next item to insert
aoqi@0 2477 }
aoqi@0 2478 return leaf;
aoqi@0 2479 }
aoqi@0 2480
aoqi@0 2481 // ------------------------------------------------------------------
aoqi@0 2482 // ciTypeFlow::build_loop_tree
aoqi@0 2483 //
aoqi@0 2484 // Incrementally build loop tree.
aoqi@0 2485 void ciTypeFlow::build_loop_tree(Block* blk) {
aoqi@0 2486 assert(!blk->is_post_visited(), "precondition");
aoqi@0 2487 Loop* innermost = NULL; // merge of loop tree branches over all successors
aoqi@0 2488
aoqi@0 2489 for (SuccIter iter(blk); !iter.done(); iter.next()) {
aoqi@0 2490 Loop* lp = NULL;
aoqi@0 2491 Block* succ = iter.succ();
aoqi@0 2492 if (!succ->is_post_visited()) {
aoqi@0 2493 // Found backedge since predecessor post visited, but successor is not
aoqi@0 2494 assert(succ->pre_order() <= blk->pre_order(), "should be backedge");
aoqi@0 2495
aoqi@0 2496 // Create a LoopNode to mark this loop.
aoqi@0 2497 lp = new (arena()) Loop(succ, blk);
aoqi@0 2498 if (succ->loop() == NULL)
aoqi@0 2499 succ->set_loop(lp);
aoqi@0 2500 // succ->loop will be updated to innermost loop on a later call, when blk==succ
aoqi@0 2501
aoqi@0 2502 } else { // Nested loop
aoqi@0 2503 lp = succ->loop();
aoqi@0 2504
aoqi@0 2505 // If succ is loop head, find outer loop.
aoqi@0 2506 while (lp != NULL && lp->head() == succ) {
aoqi@0 2507 lp = lp->parent();
aoqi@0 2508 }
aoqi@0 2509 if (lp == NULL) {
aoqi@0 2510 // Infinite loop, it's parent is the root
aoqi@0 2511 lp = loop_tree_root();
aoqi@0 2512 }
aoqi@0 2513 }
aoqi@0 2514
aoqi@0 2515 // Check for irreducible loop.
aoqi@0 2516 // Successor has already been visited. If the successor's loop head
aoqi@0 2517 // has already been post-visited, then this is another entry into the loop.
aoqi@0 2518 while (lp->head()->is_post_visited() && lp != loop_tree_root()) {
aoqi@0 2519 _has_irreducible_entry = true;
aoqi@0 2520 lp->set_irreducible(succ);
aoqi@0 2521 if (!succ->is_on_work_list()) {
aoqi@0 2522 // Assume irreducible entries need more data flow
aoqi@0 2523 add_to_work_list(succ);
aoqi@0 2524 }
aoqi@0 2525 Loop* plp = lp->parent();
aoqi@0 2526 if (plp == NULL) {
aoqi@0 2527 // This only happens for some irreducible cases. The parent
aoqi@0 2528 // will be updated during a later pass.
aoqi@0 2529 break;
aoqi@0 2530 }
aoqi@0 2531 lp = plp;
aoqi@0 2532 }
aoqi@0 2533
aoqi@0 2534 // Merge loop tree branch for all successors.
aoqi@0 2535 innermost = innermost == NULL ? lp : innermost->sorted_merge(lp);
aoqi@0 2536
aoqi@0 2537 } // end loop
aoqi@0 2538
aoqi@0 2539 if (innermost == NULL) {
aoqi@0 2540 assert(blk->successors()->length() == 0, "CFG exit");
aoqi@0 2541 blk->set_loop(loop_tree_root());
aoqi@0 2542 } else if (innermost->head() == blk) {
aoqi@0 2543 // If loop header, complete the tree pointers
aoqi@0 2544 if (blk->loop() != innermost) {
aoqi@0 2545 #ifdef ASSERT
aoqi@0 2546 assert(blk->loop()->head() == innermost->head(), "same head");
aoqi@0 2547 Loop* dl;
aoqi@0 2548 for (dl = innermost; dl != NULL && dl != blk->loop(); dl = dl->parent());
aoqi@0 2549 assert(dl == blk->loop(), "blk->loop() already in innermost list");
aoqi@0 2550 #endif
aoqi@0 2551 blk->set_loop(innermost);
aoqi@0 2552 }
aoqi@0 2553 innermost->def_locals()->add(blk->def_locals());
aoqi@0 2554 Loop* l = innermost;
aoqi@0 2555 Loop* p = l->parent();
aoqi@0 2556 while (p && l->head() == blk) {
aoqi@0 2557 l->set_sibling(p->child()); // Put self on parents 'next child'
aoqi@0 2558 p->set_child(l); // Make self the first child of parent
aoqi@0 2559 p->def_locals()->add(l->def_locals());
aoqi@0 2560 l = p; // Walk up the parent chain
aoqi@0 2561 p = l->parent();
aoqi@0 2562 }
aoqi@0 2563 } else {
aoqi@0 2564 blk->set_loop(innermost);
aoqi@0 2565 innermost->def_locals()->add(blk->def_locals());
aoqi@0 2566 }
aoqi@0 2567 }
aoqi@0 2568
aoqi@0 2569 // ------------------------------------------------------------------
aoqi@0 2570 // ciTypeFlow::Loop::contains
aoqi@0 2571 //
aoqi@0 2572 // Returns true if lp is nested loop.
aoqi@0 2573 bool ciTypeFlow::Loop::contains(ciTypeFlow::Loop* lp) const {
aoqi@0 2574 assert(lp != NULL, "");
aoqi@0 2575 if (this == lp || head() == lp->head()) return true;
aoqi@0 2576 int depth1 = depth();
aoqi@0 2577 int depth2 = lp->depth();
aoqi@0 2578 if (depth1 > depth2)
aoqi@0 2579 return false;
aoqi@0 2580 while (depth1 < depth2) {
aoqi@0 2581 depth2--;
aoqi@0 2582 lp = lp->parent();
aoqi@0 2583 }
aoqi@0 2584 return this == lp;
aoqi@0 2585 }
aoqi@0 2586
aoqi@0 2587 // ------------------------------------------------------------------
aoqi@0 2588 // ciTypeFlow::Loop::depth
aoqi@0 2589 //
aoqi@0 2590 // Loop depth
aoqi@0 2591 int ciTypeFlow::Loop::depth() const {
aoqi@0 2592 int dp = 0;
aoqi@0 2593 for (Loop* lp = this->parent(); lp != NULL; lp = lp->parent())
aoqi@0 2594 dp++;
aoqi@0 2595 return dp;
aoqi@0 2596 }
aoqi@0 2597
aoqi@0 2598 #ifndef PRODUCT
aoqi@0 2599 // ------------------------------------------------------------------
aoqi@0 2600 // ciTypeFlow::Loop::print
aoqi@0 2601 void ciTypeFlow::Loop::print(outputStream* st, int indent) const {
aoqi@0 2602 for (int i = 0; i < indent; i++) st->print(" ");
aoqi@0 2603 st->print("%d<-%d %s",
aoqi@0 2604 is_root() ? 0 : this->head()->pre_order(),
aoqi@0 2605 is_root() ? 0 : this->tail()->pre_order(),
aoqi@0 2606 is_irreducible()?" irr":"");
aoqi@0 2607 st->print(" defs: ");
aoqi@0 2608 def_locals()->print_on(st, _head->outer()->method()->max_locals());
aoqi@0 2609 st->cr();
aoqi@0 2610 for (Loop* ch = child(); ch != NULL; ch = ch->sibling())
aoqi@0 2611 ch->print(st, indent+2);
aoqi@0 2612 }
aoqi@0 2613 #endif
aoqi@0 2614
aoqi@0 2615 // ------------------------------------------------------------------
aoqi@0 2616 // ciTypeFlow::df_flow_types
aoqi@0 2617 //
aoqi@0 2618 // Perform the depth first type flow analysis. Helper for flow_types.
aoqi@0 2619 void ciTypeFlow::df_flow_types(Block* start,
aoqi@0 2620 bool do_flow,
aoqi@0 2621 StateVector* temp_vector,
aoqi@0 2622 JsrSet* temp_set) {
aoqi@0 2623 int dft_len = 100;
aoqi@0 2624 GrowableArray<Block*> stk(dft_len);
aoqi@0 2625
aoqi@0 2626 ciBlock* dummy = _methodBlocks->make_dummy_block();
aoqi@0 2627 JsrSet* root_set = new JsrSet(NULL, 0);
aoqi@0 2628 Block* root_head = new (arena()) Block(this, dummy, root_set);
aoqi@0 2629 Block* root_tail = new (arena()) Block(this, dummy, root_set);
aoqi@0 2630 root_head->set_pre_order(0);
aoqi@0 2631 root_head->set_post_order(0);
aoqi@0 2632 root_tail->set_pre_order(max_jint);
aoqi@0 2633 root_tail->set_post_order(max_jint);
aoqi@0 2634 set_loop_tree_root(new (arena()) Loop(root_head, root_tail));
aoqi@0 2635
aoqi@0 2636 stk.push(start);
aoqi@0 2637
aoqi@0 2638 _next_pre_order = 0; // initialize pre_order counter
aoqi@0 2639 _rpo_list = NULL;
aoqi@0 2640 int next_po = 0; // initialize post_order counter
aoqi@0 2641
aoqi@0 2642 // Compute RPO and the control flow graph
aoqi@0 2643 int size;
aoqi@0 2644 while ((size = stk.length()) > 0) {
aoqi@0 2645 Block* blk = stk.top(); // Leave node on stack
aoqi@0 2646 if (!blk->is_visited()) {
aoqi@0 2647 // forward arc in graph
aoqi@0 2648 assert (!blk->has_pre_order(), "");
aoqi@0 2649 blk->set_next_pre_order();
aoqi@0 2650
vlivanov@7385 2651 if (_next_pre_order >= (int)Compile::current()->max_node_limit() / 2) {
aoqi@0 2652 // Too many basic blocks. Bail out.
aoqi@0 2653 // This can happen when try/finally constructs are nested to depth N,
aoqi@0 2654 // and there is O(2**N) cloning of jsr bodies. See bug 4697245!
aoqi@0 2655 // "MaxNodeLimit / 2" is used because probably the parser will
aoqi@0 2656 // generate at least twice that many nodes and bail out.
aoqi@0 2657 record_failure("too many basic blocks");
aoqi@0 2658 return;
aoqi@0 2659 }
aoqi@0 2660 if (do_flow) {
aoqi@0 2661 flow_block(blk, temp_vector, temp_set);
aoqi@0 2662 if (failing()) return; // Watch for bailouts.
aoqi@0 2663 }
aoqi@0 2664 } else if (!blk->is_post_visited()) {
aoqi@0 2665 // cross or back arc
aoqi@0 2666 for (SuccIter iter(blk); !iter.done(); iter.next()) {
aoqi@0 2667 Block* succ = iter.succ();
aoqi@0 2668 if (!succ->is_visited()) {
aoqi@0 2669 stk.push(succ);
aoqi@0 2670 }
aoqi@0 2671 }
aoqi@0 2672 if (stk.length() == size) {
aoqi@0 2673 // There were no additional children, post visit node now
aoqi@0 2674 stk.pop(); // Remove node from stack
aoqi@0 2675
aoqi@0 2676 build_loop_tree(blk);
aoqi@0 2677 blk->set_post_order(next_po++); // Assign post order
aoqi@0 2678 prepend_to_rpo_list(blk);
aoqi@0 2679 assert(blk->is_post_visited(), "");
aoqi@0 2680
aoqi@0 2681 if (blk->is_loop_head() && !blk->is_on_work_list()) {
aoqi@0 2682 // Assume loop heads need more data flow
aoqi@0 2683 add_to_work_list(blk);
aoqi@0 2684 }
aoqi@0 2685 }
aoqi@0 2686 } else {
aoqi@0 2687 stk.pop(); // Remove post-visited node from stack
aoqi@0 2688 }
aoqi@0 2689 }
aoqi@0 2690 }
aoqi@0 2691
aoqi@0 2692 // ------------------------------------------------------------------
aoqi@0 2693 // ciTypeFlow::flow_types
aoqi@0 2694 //
aoqi@0 2695 // Perform the type flow analysis, creating and cloning Blocks as
aoqi@0 2696 // necessary.
aoqi@0 2697 void ciTypeFlow::flow_types() {
aoqi@0 2698 ResourceMark rm;
aoqi@0 2699 StateVector* temp_vector = new StateVector(this);
aoqi@0 2700 JsrSet* temp_set = new JsrSet(NULL, 16);
aoqi@0 2701
aoqi@0 2702 // Create the method entry block.
aoqi@0 2703 Block* start = block_at(start_bci(), temp_set);
aoqi@0 2704
aoqi@0 2705 // Load the initial state into it.
aoqi@0 2706 const StateVector* start_state = get_start_state();
aoqi@0 2707 if (failing()) return;
aoqi@0 2708 start->meet(start_state);
aoqi@0 2709
aoqi@0 2710 // Depth first visit
aoqi@0 2711 df_flow_types(start, true /*do flow*/, temp_vector, temp_set);
aoqi@0 2712
aoqi@0 2713 if (failing()) return;
aoqi@0 2714 assert(_rpo_list == start, "must be start");
aoqi@0 2715
aoqi@0 2716 // Any loops found?
aoqi@0 2717 if (loop_tree_root()->child() != NULL &&
aoqi@0 2718 env()->comp_level() >= CompLevel_full_optimization) {
aoqi@0 2719 // Loop optimizations are not performed on Tier1 compiles.
aoqi@0 2720
aoqi@0 2721 bool changed = clone_loop_heads(loop_tree_root(), temp_vector, temp_set);
aoqi@0 2722
aoqi@0 2723 // If some loop heads were cloned, recompute postorder and loop tree
aoqi@0 2724 if (changed) {
aoqi@0 2725 loop_tree_root()->set_child(NULL);
aoqi@0 2726 for (Block* blk = _rpo_list; blk != NULL;) {
aoqi@0 2727 Block* next = blk->rpo_next();
aoqi@0 2728 blk->df_init();
aoqi@0 2729 blk = next;
aoqi@0 2730 }
aoqi@0 2731 df_flow_types(start, false /*no flow*/, temp_vector, temp_set);
aoqi@0 2732 }
aoqi@0 2733 }
aoqi@0 2734
aoqi@0 2735 if (CITraceTypeFlow) {
aoqi@0 2736 tty->print_cr("\nLoop tree");
aoqi@0 2737 loop_tree_root()->print();
aoqi@0 2738 }
aoqi@0 2739
aoqi@0 2740 // Continue flow analysis until fixed point reached
aoqi@0 2741
aoqi@0 2742 debug_only(int max_block = _next_pre_order;)
aoqi@0 2743
aoqi@0 2744 while (!work_list_empty()) {
aoqi@0 2745 Block* blk = work_list_next();
aoqi@0 2746 assert (blk->has_post_order(), "post order assigned above");
aoqi@0 2747
aoqi@0 2748 flow_block(blk, temp_vector, temp_set);
aoqi@0 2749
aoqi@0 2750 assert (max_block == _next_pre_order, "no new blocks");
aoqi@0 2751 assert (!failing(), "no more bailouts");
aoqi@0 2752 }
aoqi@0 2753 }
aoqi@0 2754
aoqi@0 2755 // ------------------------------------------------------------------
aoqi@0 2756 // ciTypeFlow::map_blocks
aoqi@0 2757 //
aoqi@0 2758 // Create the block map, which indexes blocks in reverse post-order.
aoqi@0 2759 void ciTypeFlow::map_blocks() {
aoqi@0 2760 assert(_block_map == NULL, "single initialization");
aoqi@0 2761 int block_ct = _next_pre_order;
aoqi@0 2762 _block_map = NEW_ARENA_ARRAY(arena(), Block*, block_ct);
aoqi@0 2763 assert(block_ct == block_count(), "");
aoqi@0 2764
aoqi@0 2765 Block* blk = _rpo_list;
aoqi@0 2766 for (int m = 0; m < block_ct; m++) {
aoqi@0 2767 int rpo = blk->rpo();
aoqi@0 2768 assert(rpo == m, "should be sequential");
aoqi@0 2769 _block_map[rpo] = blk;
aoqi@0 2770 blk = blk->rpo_next();
aoqi@0 2771 }
aoqi@0 2772 assert(blk == NULL, "should be done");
aoqi@0 2773
aoqi@0 2774 for (int j = 0; j < block_ct; j++) {
aoqi@0 2775 assert(_block_map[j] != NULL, "must not drop any blocks");
aoqi@0 2776 Block* block = _block_map[j];
aoqi@0 2777 // Remove dead blocks from successor lists:
aoqi@0 2778 for (int e = 0; e <= 1; e++) {
aoqi@0 2779 GrowableArray<Block*>* l = e? block->exceptions(): block->successors();
aoqi@0 2780 for (int k = 0; k < l->length(); k++) {
aoqi@0 2781 Block* s = l->at(k);
aoqi@0 2782 if (!s->has_post_order()) {
aoqi@0 2783 if (CITraceTypeFlow) {
aoqi@0 2784 tty->print("Removing dead %s successor of #%d: ", (e? "exceptional": "normal"), block->pre_order());
aoqi@0 2785 s->print_value_on(tty);
aoqi@0 2786 tty->cr();
aoqi@0 2787 }
aoqi@0 2788 l->remove(s);
aoqi@0 2789 --k;
aoqi@0 2790 }
aoqi@0 2791 }
aoqi@0 2792 }
aoqi@0 2793 }
aoqi@0 2794 }
aoqi@0 2795
aoqi@0 2796 // ------------------------------------------------------------------
aoqi@0 2797 // ciTypeFlow::get_block_for
aoqi@0 2798 //
aoqi@0 2799 // Find a block with this ciBlock which has a compatible JsrSet.
aoqi@0 2800 // If no such block exists, create it, unless the option is no_create.
aoqi@0 2801 // If the option is create_backedge_copy, always create a fresh backedge copy.
aoqi@0 2802 ciTypeFlow::Block* ciTypeFlow::get_block_for(int ciBlockIndex, ciTypeFlow::JsrSet* jsrs, CreateOption option) {
aoqi@0 2803 Arena* a = arena();
aoqi@0 2804 GrowableArray<Block*>* blocks = _idx_to_blocklist[ciBlockIndex];
aoqi@0 2805 if (blocks == NULL) {
aoqi@0 2806 // Query only?
aoqi@0 2807 if (option == no_create) return NULL;
aoqi@0 2808
aoqi@0 2809 // Allocate the growable array.
aoqi@0 2810 blocks = new (a) GrowableArray<Block*>(a, 4, 0, NULL);
aoqi@0 2811 _idx_to_blocklist[ciBlockIndex] = blocks;
aoqi@0 2812 }
aoqi@0 2813
aoqi@0 2814 if (option != create_backedge_copy) {
aoqi@0 2815 int len = blocks->length();
aoqi@0 2816 for (int i = 0; i < len; i++) {
aoqi@0 2817 Block* block = blocks->at(i);
aoqi@0 2818 if (!block->is_backedge_copy() && block->is_compatible_with(jsrs)) {
aoqi@0 2819 return block;
aoqi@0 2820 }
aoqi@0 2821 }
aoqi@0 2822 }
aoqi@0 2823
aoqi@0 2824 // Query only?
aoqi@0 2825 if (option == no_create) return NULL;
aoqi@0 2826
aoqi@0 2827 // We did not find a compatible block. Create one.
aoqi@0 2828 Block* new_block = new (a) Block(this, _methodBlocks->block(ciBlockIndex), jsrs);
aoqi@0 2829 if (option == create_backedge_copy) new_block->set_backedge_copy(true);
aoqi@0 2830 blocks->append(new_block);
aoqi@0 2831 return new_block;
aoqi@0 2832 }
aoqi@0 2833
aoqi@0 2834 // ------------------------------------------------------------------
aoqi@0 2835 // ciTypeFlow::backedge_copy_count
aoqi@0 2836 //
aoqi@0 2837 int ciTypeFlow::backedge_copy_count(int ciBlockIndex, ciTypeFlow::JsrSet* jsrs) const {
aoqi@0 2838 GrowableArray<Block*>* blocks = _idx_to_blocklist[ciBlockIndex];
aoqi@0 2839
aoqi@0 2840 if (blocks == NULL) {
aoqi@0 2841 return 0;
aoqi@0 2842 }
aoqi@0 2843
aoqi@0 2844 int count = 0;
aoqi@0 2845 int len = blocks->length();
aoqi@0 2846 for (int i = 0; i < len; i++) {
aoqi@0 2847 Block* block = blocks->at(i);
aoqi@0 2848 if (block->is_backedge_copy() && block->is_compatible_with(jsrs)) {
aoqi@0 2849 count++;
aoqi@0 2850 }
aoqi@0 2851 }
aoqi@0 2852
aoqi@0 2853 return count;
aoqi@0 2854 }
aoqi@0 2855
aoqi@0 2856 // ------------------------------------------------------------------
aoqi@0 2857 // ciTypeFlow::do_flow
aoqi@0 2858 //
aoqi@0 2859 // Perform type inference flow analysis.
aoqi@0 2860 void ciTypeFlow::do_flow() {
aoqi@0 2861 if (CITraceTypeFlow) {
aoqi@0 2862 tty->print_cr("\nPerforming flow analysis on method");
aoqi@0 2863 method()->print();
aoqi@0 2864 if (is_osr_flow()) tty->print(" at OSR bci %d", start_bci());
aoqi@0 2865 tty->cr();
aoqi@0 2866 method()->print_codes();
aoqi@0 2867 }
aoqi@0 2868 if (CITraceTypeFlow) {
aoqi@0 2869 tty->print_cr("Initial CI Blocks");
aoqi@0 2870 print_on(tty);
aoqi@0 2871 }
aoqi@0 2872 flow_types();
aoqi@0 2873 // Watch for bailouts.
aoqi@0 2874 if (failing()) {
aoqi@0 2875 return;
aoqi@0 2876 }
aoqi@0 2877
aoqi@0 2878 map_blocks();
aoqi@0 2879
aoqi@0 2880 if (CIPrintTypeFlow || CITraceTypeFlow) {
aoqi@0 2881 rpo_print_on(tty);
aoqi@0 2882 }
aoqi@0 2883 }
aoqi@0 2884
aoqi@0 2885 // ------------------------------------------------------------------
aoqi@0 2886 // ciTypeFlow::record_failure()
aoqi@0 2887 // The ciTypeFlow object keeps track of failure reasons separately from the ciEnv.
aoqi@0 2888 // This is required because there is not a 1-1 relation between the ciEnv and
aoqi@0 2889 // the TypeFlow passes within a compilation task. For example, if the compiler
aoqi@0 2890 // is considering inlining a method, it will request a TypeFlow. If that fails,
aoqi@0 2891 // the compilation as a whole may continue without the inlining. Some TypeFlow
aoqi@0 2892 // requests are not optional; if they fail the requestor is responsible for
aoqi@0 2893 // copying the failure reason up to the ciEnv. (See Parse::Parse.)
aoqi@0 2894 void ciTypeFlow::record_failure(const char* reason) {
aoqi@0 2895 if (env()->log() != NULL) {
aoqi@0 2896 env()->log()->elem("failure reason='%s' phase='typeflow'", reason);
aoqi@0 2897 }
aoqi@0 2898 if (_failure_reason == NULL) {
aoqi@0 2899 // Record the first failure reason.
aoqi@0 2900 _failure_reason = reason;
aoqi@0 2901 }
aoqi@0 2902 }
aoqi@0 2903
aoqi@0 2904 #ifndef PRODUCT
aoqi@0 2905 // ------------------------------------------------------------------
aoqi@0 2906 // ciTypeFlow::print_on
aoqi@0 2907 void ciTypeFlow::print_on(outputStream* st) const {
aoqi@0 2908 // Walk through CI blocks
aoqi@0 2909 st->print_cr("********************************************************");
aoqi@0 2910 st->print ("TypeFlow for ");
aoqi@0 2911 method()->name()->print_symbol_on(st);
aoqi@0 2912 int limit_bci = code_size();
aoqi@0 2913 st->print_cr(" %d bytes", limit_bci);
aoqi@0 2914 ciMethodBlocks *mblks = _methodBlocks;
aoqi@0 2915 ciBlock* current = NULL;
aoqi@0 2916 for (int bci = 0; bci < limit_bci; bci++) {
aoqi@0 2917 ciBlock* blk = mblks->block_containing(bci);
aoqi@0 2918 if (blk != NULL && blk != current) {
aoqi@0 2919 current = blk;
aoqi@0 2920 current->print_on(st);
aoqi@0 2921
aoqi@0 2922 GrowableArray<Block*>* blocks = _idx_to_blocklist[blk->index()];
aoqi@0 2923 int num_blocks = (blocks == NULL) ? 0 : blocks->length();
aoqi@0 2924
aoqi@0 2925 if (num_blocks == 0) {
aoqi@0 2926 st->print_cr(" No Blocks");
aoqi@0 2927 } else {
aoqi@0 2928 for (int i = 0; i < num_blocks; i++) {
aoqi@0 2929 Block* block = blocks->at(i);
aoqi@0 2930 block->print_on(st);
aoqi@0 2931 }
aoqi@0 2932 }
aoqi@0 2933 st->print_cr("--------------------------------------------------------");
aoqi@0 2934 st->cr();
aoqi@0 2935 }
aoqi@0 2936 }
aoqi@0 2937 st->print_cr("********************************************************");
aoqi@0 2938 st->cr();
aoqi@0 2939 }
aoqi@0 2940
aoqi@0 2941 void ciTypeFlow::rpo_print_on(outputStream* st) const {
aoqi@0 2942 st->print_cr("********************************************************");
aoqi@0 2943 st->print ("TypeFlow for ");
aoqi@0 2944 method()->name()->print_symbol_on(st);
aoqi@0 2945 int limit_bci = code_size();
aoqi@0 2946 st->print_cr(" %d bytes", limit_bci);
aoqi@0 2947 for (Block* blk = _rpo_list; blk != NULL; blk = blk->rpo_next()) {
aoqi@0 2948 blk->print_on(st);
aoqi@0 2949 st->print_cr("--------------------------------------------------------");
aoqi@0 2950 st->cr();
aoqi@0 2951 }
aoqi@0 2952 st->print_cr("********************************************************");
aoqi@0 2953 st->cr();
aoqi@0 2954 }
aoqi@0 2955 #endif

mercurial