src/share/vm/ci/ciTypeFlow.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial