annotate src/share/vm/ci/ciTypeFlow.cpp @ 3586:7f813940ac35

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