1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/ci/ciTypeFlow.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,2953 @@ 1.4 +/* 1.5 + * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "ci/ciConstant.hpp" 1.30 +#include "ci/ciField.hpp" 1.31 +#include "ci/ciMethod.hpp" 1.32 +#include "ci/ciMethodData.hpp" 1.33 +#include "ci/ciObjArrayKlass.hpp" 1.34 +#include "ci/ciStreams.hpp" 1.35 +#include "ci/ciTypeArrayKlass.hpp" 1.36 +#include "ci/ciTypeFlow.hpp" 1.37 +#include "compiler/compileLog.hpp" 1.38 +#include "interpreter/bytecode.hpp" 1.39 +#include "interpreter/bytecodes.hpp" 1.40 +#include "memory/allocation.inline.hpp" 1.41 +#include "runtime/deoptimization.hpp" 1.42 +#include "utilities/growableArray.hpp" 1.43 + 1.44 +// ciTypeFlow::JsrSet 1.45 +// 1.46 +// A JsrSet represents some set of JsrRecords. This class 1.47 +// is used to record a set of all jsr routines which we permit 1.48 +// execution to return (ret) from. 1.49 +// 1.50 +// During abstract interpretation, JsrSets are used to determine 1.51 +// whether two paths which reach a given block are unique, and 1.52 +// should be cloned apart, or are compatible, and should merge 1.53 +// together. 1.54 + 1.55 +// ------------------------------------------------------------------ 1.56 +// ciTypeFlow::JsrSet::JsrSet 1.57 +ciTypeFlow::JsrSet::JsrSet(Arena* arena, int default_len) { 1.58 + if (arena != NULL) { 1.59 + // Allocate growable array in Arena. 1.60 + _set = new (arena) GrowableArray<JsrRecord*>(arena, default_len, 0, NULL); 1.61 + } else { 1.62 + // Allocate growable array in current ResourceArea. 1.63 + _set = new GrowableArray<JsrRecord*>(4, 0, NULL, false); 1.64 + } 1.65 +} 1.66 + 1.67 +// ------------------------------------------------------------------ 1.68 +// ciTypeFlow::JsrSet::copy_into 1.69 +void ciTypeFlow::JsrSet::copy_into(JsrSet* jsrs) { 1.70 + int len = size(); 1.71 + jsrs->_set->clear(); 1.72 + for (int i = 0; i < len; i++) { 1.73 + jsrs->_set->append(_set->at(i)); 1.74 + } 1.75 +} 1.76 + 1.77 +// ------------------------------------------------------------------ 1.78 +// ciTypeFlow::JsrSet::is_compatible_with 1.79 +// 1.80 +// !!!! MISGIVINGS ABOUT THIS... disregard 1.81 +// 1.82 +// Is this JsrSet compatible with some other JsrSet? 1.83 +// 1.84 +// In set-theoretic terms, a JsrSet can be viewed as a partial function 1.85 +// from entry addresses to return addresses. Two JsrSets A and B are 1.86 +// compatible iff 1.87 +// 1.88 +// For any x, 1.89 +// A(x) defined and B(x) defined implies A(x) == B(x) 1.90 +// 1.91 +// Less formally, two JsrSets are compatible when they have identical 1.92 +// return addresses for any entry addresses they share in common. 1.93 +bool ciTypeFlow::JsrSet::is_compatible_with(JsrSet* other) { 1.94 + // Walk through both sets in parallel. If the same entry address 1.95 + // appears in both sets, then the return address must match for 1.96 + // the sets to be compatible. 1.97 + int size1 = size(); 1.98 + int size2 = other->size(); 1.99 + 1.100 + // Special case. If nothing is on the jsr stack, then there can 1.101 + // be no ret. 1.102 + if (size2 == 0) { 1.103 + return true; 1.104 + } else if (size1 != size2) { 1.105 + return false; 1.106 + } else { 1.107 + for (int i = 0; i < size1; i++) { 1.108 + JsrRecord* record1 = record_at(i); 1.109 + JsrRecord* record2 = other->record_at(i); 1.110 + if (record1->entry_address() != record2->entry_address() || 1.111 + record1->return_address() != record2->return_address()) { 1.112 + return false; 1.113 + } 1.114 + } 1.115 + return true; 1.116 + } 1.117 + 1.118 +#if 0 1.119 + int pos1 = 0; 1.120 + int pos2 = 0; 1.121 + int size1 = size(); 1.122 + int size2 = other->size(); 1.123 + while (pos1 < size1 && pos2 < size2) { 1.124 + JsrRecord* record1 = record_at(pos1); 1.125 + JsrRecord* record2 = other->record_at(pos2); 1.126 + int entry1 = record1->entry_address(); 1.127 + int entry2 = record2->entry_address(); 1.128 + if (entry1 < entry2) { 1.129 + pos1++; 1.130 + } else if (entry1 > entry2) { 1.131 + pos2++; 1.132 + } else { 1.133 + if (record1->return_address() == record2->return_address()) { 1.134 + pos1++; 1.135 + pos2++; 1.136 + } else { 1.137 + // These two JsrSets are incompatible. 1.138 + return false; 1.139 + } 1.140 + } 1.141 + } 1.142 + // The two JsrSets agree. 1.143 + return true; 1.144 +#endif 1.145 +} 1.146 + 1.147 +// ------------------------------------------------------------------ 1.148 +// ciTypeFlow::JsrSet::insert_jsr_record 1.149 +// 1.150 +// Insert the given JsrRecord into the JsrSet, maintaining the order 1.151 +// of the set and replacing any element with the same entry address. 1.152 +void ciTypeFlow::JsrSet::insert_jsr_record(JsrRecord* record) { 1.153 + int len = size(); 1.154 + int entry = record->entry_address(); 1.155 + int pos = 0; 1.156 + for ( ; pos < len; pos++) { 1.157 + JsrRecord* current = record_at(pos); 1.158 + if (entry == current->entry_address()) { 1.159 + // Stomp over this entry. 1.160 + _set->at_put(pos, record); 1.161 + assert(size() == len, "must be same size"); 1.162 + return; 1.163 + } else if (entry < current->entry_address()) { 1.164 + break; 1.165 + } 1.166 + } 1.167 + 1.168 + // Insert the record into the list. 1.169 + JsrRecord* swap = record; 1.170 + JsrRecord* temp = NULL; 1.171 + for ( ; pos < len; pos++) { 1.172 + temp = _set->at(pos); 1.173 + _set->at_put(pos, swap); 1.174 + swap = temp; 1.175 + } 1.176 + _set->append(swap); 1.177 + assert(size() == len+1, "must be larger"); 1.178 +} 1.179 + 1.180 +// ------------------------------------------------------------------ 1.181 +// ciTypeFlow::JsrSet::remove_jsr_record 1.182 +// 1.183 +// Remove the JsrRecord with the given return address from the JsrSet. 1.184 +void ciTypeFlow::JsrSet::remove_jsr_record(int return_address) { 1.185 + int len = size(); 1.186 + for (int i = 0; i < len; i++) { 1.187 + if (record_at(i)->return_address() == return_address) { 1.188 + // We have found the proper entry. Remove it from the 1.189 + // JsrSet and exit. 1.190 + for (int j = i+1; j < len ; j++) { 1.191 + _set->at_put(j-1, _set->at(j)); 1.192 + } 1.193 + _set->trunc_to(len-1); 1.194 + assert(size() == len-1, "must be smaller"); 1.195 + return; 1.196 + } 1.197 + } 1.198 + assert(false, "verify: returning from invalid subroutine"); 1.199 +} 1.200 + 1.201 +// ------------------------------------------------------------------ 1.202 +// ciTypeFlow::JsrSet::apply_control 1.203 +// 1.204 +// Apply the effect of a control-flow bytecode on the JsrSet. The 1.205 +// only bytecodes that modify the JsrSet are jsr and ret. 1.206 +void ciTypeFlow::JsrSet::apply_control(ciTypeFlow* analyzer, 1.207 + ciBytecodeStream* str, 1.208 + ciTypeFlow::StateVector* state) { 1.209 + Bytecodes::Code code = str->cur_bc(); 1.210 + if (code == Bytecodes::_jsr) { 1.211 + JsrRecord* record = 1.212 + analyzer->make_jsr_record(str->get_dest(), str->next_bci()); 1.213 + insert_jsr_record(record); 1.214 + } else if (code == Bytecodes::_jsr_w) { 1.215 + JsrRecord* record = 1.216 + analyzer->make_jsr_record(str->get_far_dest(), str->next_bci()); 1.217 + insert_jsr_record(record); 1.218 + } else if (code == Bytecodes::_ret) { 1.219 + Cell local = state->local(str->get_index()); 1.220 + ciType* return_address = state->type_at(local); 1.221 + assert(return_address->is_return_address(), "verify: wrong type"); 1.222 + if (size() == 0) { 1.223 + // Ret-state underflow: Hit a ret w/o any previous jsrs. Bail out. 1.224 + // This can happen when a loop is inside a finally clause (4614060). 1.225 + analyzer->record_failure("OSR in finally clause"); 1.226 + return; 1.227 + } 1.228 + remove_jsr_record(return_address->as_return_address()->bci()); 1.229 + } 1.230 +} 1.231 + 1.232 +#ifndef PRODUCT 1.233 +// ------------------------------------------------------------------ 1.234 +// ciTypeFlow::JsrSet::print_on 1.235 +void ciTypeFlow::JsrSet::print_on(outputStream* st) const { 1.236 + st->print("{ "); 1.237 + int num_elements = size(); 1.238 + if (num_elements > 0) { 1.239 + int i = 0; 1.240 + for( ; i < num_elements - 1; i++) { 1.241 + _set->at(i)->print_on(st); 1.242 + st->print(", "); 1.243 + } 1.244 + _set->at(i)->print_on(st); 1.245 + st->print(" "); 1.246 + } 1.247 + st->print("}"); 1.248 +} 1.249 +#endif 1.250 + 1.251 +// ciTypeFlow::StateVector 1.252 +// 1.253 +// A StateVector summarizes the type information at some point in 1.254 +// the program. 1.255 + 1.256 +// ------------------------------------------------------------------ 1.257 +// ciTypeFlow::StateVector::type_meet 1.258 +// 1.259 +// Meet two types. 1.260 +// 1.261 +// The semi-lattice of types use by this analysis are modeled on those 1.262 +// of the verifier. The lattice is as follows: 1.263 +// 1.264 +// top_type() >= all non-extremal types >= bottom_type 1.265 +// and 1.266 +// Every primitive type is comparable only with itself. The meet of 1.267 +// reference types is determined by their kind: instance class, 1.268 +// interface, or array class. The meet of two types of the same 1.269 +// kind is their least common ancestor. The meet of two types of 1.270 +// different kinds is always java.lang.Object. 1.271 +ciType* ciTypeFlow::StateVector::type_meet_internal(ciType* t1, ciType* t2, ciTypeFlow* analyzer) { 1.272 + assert(t1 != t2, "checked in caller"); 1.273 + if (t1->equals(top_type())) { 1.274 + return t2; 1.275 + } else if (t2->equals(top_type())) { 1.276 + return t1; 1.277 + } else if (t1->is_primitive_type() || t2->is_primitive_type()) { 1.278 + // Special case null_type. null_type meet any reference type T 1.279 + // is T. null_type meet null_type is null_type. 1.280 + if (t1->equals(null_type())) { 1.281 + if (!t2->is_primitive_type() || t2->equals(null_type())) { 1.282 + return t2; 1.283 + } 1.284 + } else if (t2->equals(null_type())) { 1.285 + if (!t1->is_primitive_type()) { 1.286 + return t1; 1.287 + } 1.288 + } 1.289 + 1.290 + // At least one of the two types is a non-top primitive type. 1.291 + // The other type is not equal to it. Fall to bottom. 1.292 + return bottom_type(); 1.293 + } else { 1.294 + // Both types are non-top non-primitive types. That is, 1.295 + // both types are either instanceKlasses or arrayKlasses. 1.296 + ciKlass* object_klass = analyzer->env()->Object_klass(); 1.297 + ciKlass* k1 = t1->as_klass(); 1.298 + ciKlass* k2 = t2->as_klass(); 1.299 + if (k1->equals(object_klass) || k2->equals(object_klass)) { 1.300 + return object_klass; 1.301 + } else if (!k1->is_loaded() || !k2->is_loaded()) { 1.302 + // Unloaded classes fall to java.lang.Object at a merge. 1.303 + return object_klass; 1.304 + } else if (k1->is_interface() != k2->is_interface()) { 1.305 + // When an interface meets a non-interface, we get Object; 1.306 + // This is what the verifier does. 1.307 + return object_klass; 1.308 + } else if (k1->is_array_klass() || k2->is_array_klass()) { 1.309 + // When an array meets a non-array, we get Object. 1.310 + // When objArray meets typeArray, we also get Object. 1.311 + // And when typeArray meets different typeArray, we again get Object. 1.312 + // But when objArray meets objArray, we look carefully at element types. 1.313 + if (k1->is_obj_array_klass() && k2->is_obj_array_klass()) { 1.314 + // Meet the element types, then construct the corresponding array type. 1.315 + ciKlass* elem1 = k1->as_obj_array_klass()->element_klass(); 1.316 + ciKlass* elem2 = k2->as_obj_array_klass()->element_klass(); 1.317 + ciKlass* elem = type_meet_internal(elem1, elem2, analyzer)->as_klass(); 1.318 + // Do an easy shortcut if one type is a super of the other. 1.319 + if (elem == elem1) { 1.320 + assert(k1 == ciObjArrayKlass::make(elem), "shortcut is OK"); 1.321 + return k1; 1.322 + } else if (elem == elem2) { 1.323 + assert(k2 == ciObjArrayKlass::make(elem), "shortcut is OK"); 1.324 + return k2; 1.325 + } else { 1.326 + return ciObjArrayKlass::make(elem); 1.327 + } 1.328 + } else { 1.329 + return object_klass; 1.330 + } 1.331 + } else { 1.332 + // Must be two plain old instance klasses. 1.333 + assert(k1->is_instance_klass(), "previous cases handle non-instances"); 1.334 + assert(k2->is_instance_klass(), "previous cases handle non-instances"); 1.335 + return k1->least_common_ancestor(k2); 1.336 + } 1.337 + } 1.338 +} 1.339 + 1.340 + 1.341 +// ------------------------------------------------------------------ 1.342 +// ciTypeFlow::StateVector::StateVector 1.343 +// 1.344 +// Build a new state vector 1.345 +ciTypeFlow::StateVector::StateVector(ciTypeFlow* analyzer) { 1.346 + _outer = analyzer; 1.347 + _stack_size = -1; 1.348 + _monitor_count = -1; 1.349 + // Allocate the _types array 1.350 + int max_cells = analyzer->max_cells(); 1.351 + _types = (ciType**)analyzer->arena()->Amalloc(sizeof(ciType*) * max_cells); 1.352 + for (int i=0; i<max_cells; i++) { 1.353 + _types[i] = top_type(); 1.354 + } 1.355 + _trap_bci = -1; 1.356 + _trap_index = 0; 1.357 + _def_locals.clear(); 1.358 +} 1.359 + 1.360 + 1.361 +// ------------------------------------------------------------------ 1.362 +// ciTypeFlow::get_start_state 1.363 +// 1.364 +// Set this vector to the method entry state. 1.365 +const ciTypeFlow::StateVector* ciTypeFlow::get_start_state() { 1.366 + StateVector* state = new StateVector(this); 1.367 + if (is_osr_flow()) { 1.368 + ciTypeFlow* non_osr_flow = method()->get_flow_analysis(); 1.369 + if (non_osr_flow->failing()) { 1.370 + record_failure(non_osr_flow->failure_reason()); 1.371 + return NULL; 1.372 + } 1.373 + JsrSet* jsrs = new JsrSet(NULL, 16); 1.374 + Block* non_osr_block = non_osr_flow->existing_block_at(start_bci(), jsrs); 1.375 + if (non_osr_block == NULL) { 1.376 + record_failure("cannot reach OSR point"); 1.377 + return NULL; 1.378 + } 1.379 + // load up the non-OSR state at this point 1.380 + non_osr_block->copy_state_into(state); 1.381 + int non_osr_start = non_osr_block->start(); 1.382 + if (non_osr_start != start_bci()) { 1.383 + // must flow forward from it 1.384 + if (CITraceTypeFlow) { 1.385 + tty->print_cr(">> Interpreting pre-OSR block %d:", non_osr_start); 1.386 + } 1.387 + Block* block = block_at(non_osr_start, jsrs); 1.388 + assert(block->limit() == start_bci(), "must flow forward to start"); 1.389 + flow_block(block, state, jsrs); 1.390 + } 1.391 + return state; 1.392 + // Note: The code below would be an incorrect for an OSR flow, 1.393 + // even if it were possible for an OSR entry point to be at bci zero. 1.394 + } 1.395 + // "Push" the method signature into the first few locals. 1.396 + state->set_stack_size(-max_locals()); 1.397 + if (!method()->is_static()) { 1.398 + state->push(method()->holder()); 1.399 + assert(state->tos() == state->local(0), ""); 1.400 + } 1.401 + for (ciSignatureStream str(method()->signature()); 1.402 + !str.at_return_type(); 1.403 + str.next()) { 1.404 + state->push_translate(str.type()); 1.405 + } 1.406 + // Set the rest of the locals to bottom. 1.407 + Cell cell = state->next_cell(state->tos()); 1.408 + state->set_stack_size(0); 1.409 + int limit = state->limit_cell(); 1.410 + for (; cell < limit; cell = state->next_cell(cell)) { 1.411 + state->set_type_at(cell, state->bottom_type()); 1.412 + } 1.413 + // Lock an object, if necessary. 1.414 + state->set_monitor_count(method()->is_synchronized() ? 1 : 0); 1.415 + return state; 1.416 +} 1.417 + 1.418 +// ------------------------------------------------------------------ 1.419 +// ciTypeFlow::StateVector::copy_into 1.420 +// 1.421 +// Copy our value into some other StateVector 1.422 +void ciTypeFlow::StateVector::copy_into(ciTypeFlow::StateVector* copy) 1.423 +const { 1.424 + copy->set_stack_size(stack_size()); 1.425 + copy->set_monitor_count(monitor_count()); 1.426 + Cell limit = limit_cell(); 1.427 + for (Cell c = start_cell(); c < limit; c = next_cell(c)) { 1.428 + copy->set_type_at(c, type_at(c)); 1.429 + } 1.430 +} 1.431 + 1.432 +// ------------------------------------------------------------------ 1.433 +// ciTypeFlow::StateVector::meet 1.434 +// 1.435 +// Meets this StateVector with another, destructively modifying this 1.436 +// one. Returns true if any modification takes place. 1.437 +bool ciTypeFlow::StateVector::meet(const ciTypeFlow::StateVector* incoming) { 1.438 + if (monitor_count() == -1) { 1.439 + set_monitor_count(incoming->monitor_count()); 1.440 + } 1.441 + assert(monitor_count() == incoming->monitor_count(), "monitors must match"); 1.442 + 1.443 + if (stack_size() == -1) { 1.444 + set_stack_size(incoming->stack_size()); 1.445 + Cell limit = limit_cell(); 1.446 + #ifdef ASSERT 1.447 + { for (Cell c = start_cell(); c < limit; c = next_cell(c)) { 1.448 + assert(type_at(c) == top_type(), ""); 1.449 + } } 1.450 + #endif 1.451 + // Make a simple copy of the incoming state. 1.452 + for (Cell c = start_cell(); c < limit; c = next_cell(c)) { 1.453 + set_type_at(c, incoming->type_at(c)); 1.454 + } 1.455 + return true; // it is always different the first time 1.456 + } 1.457 +#ifdef ASSERT 1.458 + if (stack_size() != incoming->stack_size()) { 1.459 + _outer->method()->print_codes(); 1.460 + tty->print_cr("!!!! Stack size conflict"); 1.461 + tty->print_cr("Current state:"); 1.462 + print_on(tty); 1.463 + tty->print_cr("Incoming state:"); 1.464 + ((StateVector*)incoming)->print_on(tty); 1.465 + } 1.466 +#endif 1.467 + assert(stack_size() == incoming->stack_size(), "sanity"); 1.468 + 1.469 + bool different = false; 1.470 + Cell limit = limit_cell(); 1.471 + for (Cell c = start_cell(); c < limit; c = next_cell(c)) { 1.472 + ciType* t1 = type_at(c); 1.473 + ciType* t2 = incoming->type_at(c); 1.474 + if (!t1->equals(t2)) { 1.475 + ciType* new_type = type_meet(t1, t2); 1.476 + if (!t1->equals(new_type)) { 1.477 + set_type_at(c, new_type); 1.478 + different = true; 1.479 + } 1.480 + } 1.481 + } 1.482 + return different; 1.483 +} 1.484 + 1.485 +// ------------------------------------------------------------------ 1.486 +// ciTypeFlow::StateVector::meet_exception 1.487 +// 1.488 +// Meets this StateVector with another, destructively modifying this 1.489 +// one. The incoming state is coming via an exception. Returns true 1.490 +// if any modification takes place. 1.491 +bool ciTypeFlow::StateVector::meet_exception(ciInstanceKlass* exc, 1.492 + const ciTypeFlow::StateVector* incoming) { 1.493 + if (monitor_count() == -1) { 1.494 + set_monitor_count(incoming->monitor_count()); 1.495 + } 1.496 + assert(monitor_count() == incoming->monitor_count(), "monitors must match"); 1.497 + 1.498 + if (stack_size() == -1) { 1.499 + set_stack_size(1); 1.500 + } 1.501 + 1.502 + assert(stack_size() == 1, "must have one-element stack"); 1.503 + 1.504 + bool different = false; 1.505 + 1.506 + // Meet locals from incoming array. 1.507 + Cell limit = local(_outer->max_locals()-1); 1.508 + for (Cell c = start_cell(); c <= limit; c = next_cell(c)) { 1.509 + ciType* t1 = type_at(c); 1.510 + ciType* t2 = incoming->type_at(c); 1.511 + if (!t1->equals(t2)) { 1.512 + ciType* new_type = type_meet(t1, t2); 1.513 + if (!t1->equals(new_type)) { 1.514 + set_type_at(c, new_type); 1.515 + different = true; 1.516 + } 1.517 + } 1.518 + } 1.519 + 1.520 + // Handle stack separately. When an exception occurs, the 1.521 + // only stack entry is the exception instance. 1.522 + ciType* tos_type = type_at_tos(); 1.523 + if (!tos_type->equals(exc)) { 1.524 + ciType* new_type = type_meet(tos_type, exc); 1.525 + if (!tos_type->equals(new_type)) { 1.526 + set_type_at_tos(new_type); 1.527 + different = true; 1.528 + } 1.529 + } 1.530 + 1.531 + return different; 1.532 +} 1.533 + 1.534 +// ------------------------------------------------------------------ 1.535 +// ciTypeFlow::StateVector::push_translate 1.536 +void ciTypeFlow::StateVector::push_translate(ciType* type) { 1.537 + BasicType basic_type = type->basic_type(); 1.538 + if (basic_type == T_BOOLEAN || basic_type == T_CHAR || 1.539 + basic_type == T_BYTE || basic_type == T_SHORT) { 1.540 + push_int(); 1.541 + } else { 1.542 + push(type); 1.543 + if (type->is_two_word()) { 1.544 + push(half_type(type)); 1.545 + } 1.546 + } 1.547 +} 1.548 + 1.549 +// ------------------------------------------------------------------ 1.550 +// ciTypeFlow::StateVector::do_aaload 1.551 +void ciTypeFlow::StateVector::do_aaload(ciBytecodeStream* str) { 1.552 + pop_int(); 1.553 + ciObjArrayKlass* array_klass = pop_objArray(); 1.554 + if (array_klass == NULL) { 1.555 + // Did aaload on a null reference; push a null and ignore the exception. 1.556 + // This instruction will never continue normally. All we have to do 1.557 + // is report a value that will meet correctly with any downstream 1.558 + // reference types on paths that will truly be executed. This null type 1.559 + // meets with any reference type to yield that same reference type. 1.560 + // (The compiler will generate an unconditional exception here.) 1.561 + push(null_type()); 1.562 + return; 1.563 + } 1.564 + if (!array_klass->is_loaded()) { 1.565 + // Only fails for some -Xcomp runs 1.566 + trap(str, array_klass, 1.567 + Deoptimization::make_trap_request 1.568 + (Deoptimization::Reason_unloaded, 1.569 + Deoptimization::Action_reinterpret)); 1.570 + return; 1.571 + } 1.572 + ciKlass* element_klass = array_klass->element_klass(); 1.573 + if (!element_klass->is_loaded() && element_klass->is_instance_klass()) { 1.574 + Untested("unloaded array element class in ciTypeFlow"); 1.575 + trap(str, element_klass, 1.576 + Deoptimization::make_trap_request 1.577 + (Deoptimization::Reason_unloaded, 1.578 + Deoptimization::Action_reinterpret)); 1.579 + } else { 1.580 + push_object(element_klass); 1.581 + } 1.582 +} 1.583 + 1.584 + 1.585 +// ------------------------------------------------------------------ 1.586 +// ciTypeFlow::StateVector::do_checkcast 1.587 +void ciTypeFlow::StateVector::do_checkcast(ciBytecodeStream* str) { 1.588 + bool will_link; 1.589 + ciKlass* klass = str->get_klass(will_link); 1.590 + if (!will_link) { 1.591 + // VM's interpreter will not load 'klass' if object is NULL. 1.592 + // Type flow after this block may still be needed in two situations: 1.593 + // 1) C2 uses do_null_assert() and continues compilation for later blocks 1.594 + // 2) C2 does an OSR compile in a later block (see bug 4778368). 1.595 + pop_object(); 1.596 + do_null_assert(klass); 1.597 + } else { 1.598 + pop_object(); 1.599 + push_object(klass); 1.600 + } 1.601 +} 1.602 + 1.603 +// ------------------------------------------------------------------ 1.604 +// ciTypeFlow::StateVector::do_getfield 1.605 +void ciTypeFlow::StateVector::do_getfield(ciBytecodeStream* str) { 1.606 + // could add assert here for type of object. 1.607 + pop_object(); 1.608 + do_getstatic(str); 1.609 +} 1.610 + 1.611 +// ------------------------------------------------------------------ 1.612 +// ciTypeFlow::StateVector::do_getstatic 1.613 +void ciTypeFlow::StateVector::do_getstatic(ciBytecodeStream* str) { 1.614 + bool will_link; 1.615 + ciField* field = str->get_field(will_link); 1.616 + if (!will_link) { 1.617 + trap(str, field->holder(), str->get_field_holder_index()); 1.618 + } else { 1.619 + ciType* field_type = field->type(); 1.620 + if (!field_type->is_loaded()) { 1.621 + // Normally, we need the field's type to be loaded if we are to 1.622 + // do anything interesting with its value. 1.623 + // We used to do this: trap(str, str->get_field_signature_index()); 1.624 + // 1.625 + // There is one good reason not to trap here. Execution can 1.626 + // get past this "getfield" or "getstatic" if the value of 1.627 + // the field is null. As long as the value is null, the class 1.628 + // does not need to be loaded! The compiler must assume that 1.629 + // the value of the unloaded class reference is null; if the code 1.630 + // ever sees a non-null value, loading has occurred. 1.631 + // 1.632 + // This actually happens often enough to be annoying. If the 1.633 + // compiler throws an uncommon trap at this bytecode, you can 1.634 + // get an endless loop of recompilations, when all the code 1.635 + // needs to do is load a series of null values. Also, a trap 1.636 + // here can make an OSR entry point unreachable, triggering the 1.637 + // assert on non_osr_block in ciTypeFlow::get_start_state. 1.638 + // (See bug 4379915.) 1.639 + do_null_assert(field_type->as_klass()); 1.640 + } else { 1.641 + push_translate(field_type); 1.642 + } 1.643 + } 1.644 +} 1.645 + 1.646 +// ------------------------------------------------------------------ 1.647 +// ciTypeFlow::StateVector::do_invoke 1.648 +void ciTypeFlow::StateVector::do_invoke(ciBytecodeStream* str, 1.649 + bool has_receiver) { 1.650 + bool will_link; 1.651 + ciSignature* declared_signature = NULL; 1.652 + ciMethod* callee = str->get_method(will_link, &declared_signature); 1.653 + assert(declared_signature != NULL, "cannot be null"); 1.654 + if (!will_link) { 1.655 + // We weren't able to find the method. 1.656 + if (str->cur_bc() == Bytecodes::_invokedynamic) { 1.657 + trap(str, NULL, 1.658 + Deoptimization::make_trap_request 1.659 + (Deoptimization::Reason_uninitialized, 1.660 + Deoptimization::Action_reinterpret)); 1.661 + } else { 1.662 + ciKlass* unloaded_holder = callee->holder(); 1.663 + trap(str, unloaded_holder, str->get_method_holder_index()); 1.664 + } 1.665 + } else { 1.666 + // We are using the declared signature here because it might be 1.667 + // different from the callee signature (Cf. invokedynamic and 1.668 + // invokehandle). 1.669 + ciSignatureStream sigstr(declared_signature); 1.670 + const int arg_size = declared_signature->size(); 1.671 + const int stack_base = stack_size() - arg_size; 1.672 + int i = 0; 1.673 + for( ; !sigstr.at_return_type(); sigstr.next()) { 1.674 + ciType* type = sigstr.type(); 1.675 + ciType* stack_type = type_at(stack(stack_base + i++)); 1.676 + // Do I want to check this type? 1.677 + // assert(stack_type->is_subtype_of(type), "bad type for field value"); 1.678 + if (type->is_two_word()) { 1.679 + ciType* stack_type2 = type_at(stack(stack_base + i++)); 1.680 + assert(stack_type2->equals(half_type(type)), "must be 2nd half"); 1.681 + } 1.682 + } 1.683 + assert(arg_size == i, "must match"); 1.684 + for (int j = 0; j < arg_size; j++) { 1.685 + pop(); 1.686 + } 1.687 + if (has_receiver) { 1.688 + // Check this? 1.689 + pop_object(); 1.690 + } 1.691 + assert(!sigstr.is_done(), "must have return type"); 1.692 + ciType* return_type = sigstr.type(); 1.693 + if (!return_type->is_void()) { 1.694 + if (!return_type->is_loaded()) { 1.695 + // As in do_getstatic(), generally speaking, we need the return type to 1.696 + // be loaded if we are to do anything interesting with its value. 1.697 + // We used to do this: trap(str, str->get_method_signature_index()); 1.698 + // 1.699 + // We do not trap here since execution can get past this invoke if 1.700 + // the return value is null. As long as the value is null, the class 1.701 + // does not need to be loaded! The compiler must assume that 1.702 + // the value of the unloaded class reference is null; if the code 1.703 + // ever sees a non-null value, loading has occurred. 1.704 + // 1.705 + // See do_getstatic() for similar explanation, as well as bug 4684993. 1.706 + do_null_assert(return_type->as_klass()); 1.707 + } else { 1.708 + push_translate(return_type); 1.709 + } 1.710 + } 1.711 + } 1.712 +} 1.713 + 1.714 +// ------------------------------------------------------------------ 1.715 +// ciTypeFlow::StateVector::do_jsr 1.716 +void ciTypeFlow::StateVector::do_jsr(ciBytecodeStream* str) { 1.717 + push(ciReturnAddress::make(str->next_bci())); 1.718 +} 1.719 + 1.720 +// ------------------------------------------------------------------ 1.721 +// ciTypeFlow::StateVector::do_ldc 1.722 +void ciTypeFlow::StateVector::do_ldc(ciBytecodeStream* str) { 1.723 + ciConstant con = str->get_constant(); 1.724 + BasicType basic_type = con.basic_type(); 1.725 + if (basic_type == T_ILLEGAL) { 1.726 + // OutOfMemoryError in the CI while loading constant 1.727 + push_null(); 1.728 + outer()->record_failure("ldc did not link"); 1.729 + return; 1.730 + } 1.731 + if (basic_type == T_OBJECT || basic_type == T_ARRAY) { 1.732 + ciObject* obj = con.as_object(); 1.733 + if (obj->is_null_object()) { 1.734 + push_null(); 1.735 + } else { 1.736 + assert(obj->is_instance(), "must be java_mirror of klass"); 1.737 + push_object(obj->klass()); 1.738 + } 1.739 + } else { 1.740 + push_translate(ciType::make(basic_type)); 1.741 + } 1.742 +} 1.743 + 1.744 +// ------------------------------------------------------------------ 1.745 +// ciTypeFlow::StateVector::do_multianewarray 1.746 +void ciTypeFlow::StateVector::do_multianewarray(ciBytecodeStream* str) { 1.747 + int dimensions = str->get_dimensions(); 1.748 + bool will_link; 1.749 + ciArrayKlass* array_klass = str->get_klass(will_link)->as_array_klass(); 1.750 + if (!will_link) { 1.751 + trap(str, array_klass, str->get_klass_index()); 1.752 + } else { 1.753 + for (int i = 0; i < dimensions; i++) { 1.754 + pop_int(); 1.755 + } 1.756 + push_object(array_klass); 1.757 + } 1.758 +} 1.759 + 1.760 +// ------------------------------------------------------------------ 1.761 +// ciTypeFlow::StateVector::do_new 1.762 +void ciTypeFlow::StateVector::do_new(ciBytecodeStream* str) { 1.763 + bool will_link; 1.764 + ciKlass* klass = str->get_klass(will_link); 1.765 + if (!will_link || str->is_unresolved_klass()) { 1.766 + trap(str, klass, str->get_klass_index()); 1.767 + } else { 1.768 + push_object(klass); 1.769 + } 1.770 +} 1.771 + 1.772 +// ------------------------------------------------------------------ 1.773 +// ciTypeFlow::StateVector::do_newarray 1.774 +void ciTypeFlow::StateVector::do_newarray(ciBytecodeStream* str) { 1.775 + pop_int(); 1.776 + ciKlass* klass = ciTypeArrayKlass::make((BasicType)str->get_index()); 1.777 + push_object(klass); 1.778 +} 1.779 + 1.780 +// ------------------------------------------------------------------ 1.781 +// ciTypeFlow::StateVector::do_putfield 1.782 +void ciTypeFlow::StateVector::do_putfield(ciBytecodeStream* str) { 1.783 + do_putstatic(str); 1.784 + if (_trap_bci != -1) return; // unloaded field holder, etc. 1.785 + // could add assert here for type of object. 1.786 + pop_object(); 1.787 +} 1.788 + 1.789 +// ------------------------------------------------------------------ 1.790 +// ciTypeFlow::StateVector::do_putstatic 1.791 +void ciTypeFlow::StateVector::do_putstatic(ciBytecodeStream* str) { 1.792 + bool will_link; 1.793 + ciField* field = str->get_field(will_link); 1.794 + if (!will_link) { 1.795 + trap(str, field->holder(), str->get_field_holder_index()); 1.796 + } else { 1.797 + ciType* field_type = field->type(); 1.798 + ciType* type = pop_value(); 1.799 + // Do I want to check this type? 1.800 + // assert(type->is_subtype_of(field_type), "bad type for field value"); 1.801 + if (field_type->is_two_word()) { 1.802 + ciType* type2 = pop_value(); 1.803 + assert(type2->is_two_word(), "must be 2nd half"); 1.804 + assert(type == half_type(type2), "must be 2nd half"); 1.805 + } 1.806 + } 1.807 +} 1.808 + 1.809 +// ------------------------------------------------------------------ 1.810 +// ciTypeFlow::StateVector::do_ret 1.811 +void ciTypeFlow::StateVector::do_ret(ciBytecodeStream* str) { 1.812 + Cell index = local(str->get_index()); 1.813 + 1.814 + ciType* address = type_at(index); 1.815 + assert(address->is_return_address(), "bad return address"); 1.816 + set_type_at(index, bottom_type()); 1.817 +} 1.818 + 1.819 +// ------------------------------------------------------------------ 1.820 +// ciTypeFlow::StateVector::trap 1.821 +// 1.822 +// Stop interpretation of this path with a trap. 1.823 +void ciTypeFlow::StateVector::trap(ciBytecodeStream* str, ciKlass* klass, int index) { 1.824 + _trap_bci = str->cur_bci(); 1.825 + _trap_index = index; 1.826 + 1.827 + // Log information about this trap: 1.828 + CompileLog* log = outer()->env()->log(); 1.829 + if (log != NULL) { 1.830 + int mid = log->identify(outer()->method()); 1.831 + int kid = (klass == NULL)? -1: log->identify(klass); 1.832 + log->begin_elem("uncommon_trap method='%d' bci='%d'", mid, str->cur_bci()); 1.833 + char buf[100]; 1.834 + log->print(" %s", Deoptimization::format_trap_request(buf, sizeof(buf), 1.835 + index)); 1.836 + if (kid >= 0) 1.837 + log->print(" klass='%d'", kid); 1.838 + log->end_elem(); 1.839 + } 1.840 +} 1.841 + 1.842 +// ------------------------------------------------------------------ 1.843 +// ciTypeFlow::StateVector::do_null_assert 1.844 +// Corresponds to graphKit::do_null_assert. 1.845 +void ciTypeFlow::StateVector::do_null_assert(ciKlass* unloaded_klass) { 1.846 + if (unloaded_klass->is_loaded()) { 1.847 + // We failed to link, but we can still compute with this class, 1.848 + // since it is loaded somewhere. The compiler will uncommon_trap 1.849 + // if the object is not null, but the typeflow pass can not assume 1.850 + // that the object will be null, otherwise it may incorrectly tell 1.851 + // the parser that an object is known to be null. 4761344, 4807707 1.852 + push_object(unloaded_klass); 1.853 + } else { 1.854 + // The class is not loaded anywhere. It is safe to model the 1.855 + // null in the typestates, because we can compile in a null check 1.856 + // which will deoptimize us if someone manages to load the 1.857 + // class later. 1.858 + push_null(); 1.859 + } 1.860 +} 1.861 + 1.862 + 1.863 +// ------------------------------------------------------------------ 1.864 +// ciTypeFlow::StateVector::apply_one_bytecode 1.865 +// 1.866 +// Apply the effect of one bytecode to this StateVector 1.867 +bool ciTypeFlow::StateVector::apply_one_bytecode(ciBytecodeStream* str) { 1.868 + _trap_bci = -1; 1.869 + _trap_index = 0; 1.870 + 1.871 + if (CITraceTypeFlow) { 1.872 + tty->print_cr(">> Interpreting bytecode %d:%s", str->cur_bci(), 1.873 + Bytecodes::name(str->cur_bc())); 1.874 + } 1.875 + 1.876 + switch(str->cur_bc()) { 1.877 + case Bytecodes::_aaload: do_aaload(str); break; 1.878 + 1.879 + case Bytecodes::_aastore: 1.880 + { 1.881 + pop_object(); 1.882 + pop_int(); 1.883 + pop_objArray(); 1.884 + break; 1.885 + } 1.886 + case Bytecodes::_aconst_null: 1.887 + { 1.888 + push_null(); 1.889 + break; 1.890 + } 1.891 + case Bytecodes::_aload: load_local_object(str->get_index()); break; 1.892 + case Bytecodes::_aload_0: load_local_object(0); break; 1.893 + case Bytecodes::_aload_1: load_local_object(1); break; 1.894 + case Bytecodes::_aload_2: load_local_object(2); break; 1.895 + case Bytecodes::_aload_3: load_local_object(3); break; 1.896 + 1.897 + case Bytecodes::_anewarray: 1.898 + { 1.899 + pop_int(); 1.900 + bool will_link; 1.901 + ciKlass* element_klass = str->get_klass(will_link); 1.902 + if (!will_link) { 1.903 + trap(str, element_klass, str->get_klass_index()); 1.904 + } else { 1.905 + push_object(ciObjArrayKlass::make(element_klass)); 1.906 + } 1.907 + break; 1.908 + } 1.909 + case Bytecodes::_areturn: 1.910 + case Bytecodes::_ifnonnull: 1.911 + case Bytecodes::_ifnull: 1.912 + { 1.913 + pop_object(); 1.914 + break; 1.915 + } 1.916 + case Bytecodes::_monitorenter: 1.917 + { 1.918 + pop_object(); 1.919 + set_monitor_count(monitor_count() + 1); 1.920 + break; 1.921 + } 1.922 + case Bytecodes::_monitorexit: 1.923 + { 1.924 + pop_object(); 1.925 + assert(monitor_count() > 0, "must be a monitor to exit from"); 1.926 + set_monitor_count(monitor_count() - 1); 1.927 + break; 1.928 + } 1.929 + case Bytecodes::_arraylength: 1.930 + { 1.931 + pop_array(); 1.932 + push_int(); 1.933 + break; 1.934 + } 1.935 + case Bytecodes::_astore: store_local_object(str->get_index()); break; 1.936 + case Bytecodes::_astore_0: store_local_object(0); break; 1.937 + case Bytecodes::_astore_1: store_local_object(1); break; 1.938 + case Bytecodes::_astore_2: store_local_object(2); break; 1.939 + case Bytecodes::_astore_3: store_local_object(3); break; 1.940 + 1.941 + case Bytecodes::_athrow: 1.942 + { 1.943 + NEEDS_CLEANUP; 1.944 + pop_object(); 1.945 + break; 1.946 + } 1.947 + case Bytecodes::_baload: 1.948 + case Bytecodes::_caload: 1.949 + case Bytecodes::_iaload: 1.950 + case Bytecodes::_saload: 1.951 + { 1.952 + pop_int(); 1.953 + ciTypeArrayKlass* array_klass = pop_typeArray(); 1.954 + // Put assert here for right type? 1.955 + push_int(); 1.956 + break; 1.957 + } 1.958 + case Bytecodes::_bastore: 1.959 + case Bytecodes::_castore: 1.960 + case Bytecodes::_iastore: 1.961 + case Bytecodes::_sastore: 1.962 + { 1.963 + pop_int(); 1.964 + pop_int(); 1.965 + pop_typeArray(); 1.966 + // assert here? 1.967 + break; 1.968 + } 1.969 + case Bytecodes::_bipush: 1.970 + case Bytecodes::_iconst_m1: 1.971 + case Bytecodes::_iconst_0: 1.972 + case Bytecodes::_iconst_1: 1.973 + case Bytecodes::_iconst_2: 1.974 + case Bytecodes::_iconst_3: 1.975 + case Bytecodes::_iconst_4: 1.976 + case Bytecodes::_iconst_5: 1.977 + case Bytecodes::_sipush: 1.978 + { 1.979 + push_int(); 1.980 + break; 1.981 + } 1.982 + case Bytecodes::_checkcast: do_checkcast(str); break; 1.983 + 1.984 + case Bytecodes::_d2f: 1.985 + { 1.986 + pop_double(); 1.987 + push_float(); 1.988 + break; 1.989 + } 1.990 + case Bytecodes::_d2i: 1.991 + { 1.992 + pop_double(); 1.993 + push_int(); 1.994 + break; 1.995 + } 1.996 + case Bytecodes::_d2l: 1.997 + { 1.998 + pop_double(); 1.999 + push_long(); 1.1000 + break; 1.1001 + } 1.1002 + case Bytecodes::_dadd: 1.1003 + case Bytecodes::_ddiv: 1.1004 + case Bytecodes::_dmul: 1.1005 + case Bytecodes::_drem: 1.1006 + case Bytecodes::_dsub: 1.1007 + { 1.1008 + pop_double(); 1.1009 + pop_double(); 1.1010 + push_double(); 1.1011 + break; 1.1012 + } 1.1013 + case Bytecodes::_daload: 1.1014 + { 1.1015 + pop_int(); 1.1016 + ciTypeArrayKlass* array_klass = pop_typeArray(); 1.1017 + // Put assert here for right type? 1.1018 + push_double(); 1.1019 + break; 1.1020 + } 1.1021 + case Bytecodes::_dastore: 1.1022 + { 1.1023 + pop_double(); 1.1024 + pop_int(); 1.1025 + pop_typeArray(); 1.1026 + // assert here? 1.1027 + break; 1.1028 + } 1.1029 + case Bytecodes::_dcmpg: 1.1030 + case Bytecodes::_dcmpl: 1.1031 + { 1.1032 + pop_double(); 1.1033 + pop_double(); 1.1034 + push_int(); 1.1035 + break; 1.1036 + } 1.1037 + case Bytecodes::_dconst_0: 1.1038 + case Bytecodes::_dconst_1: 1.1039 + { 1.1040 + push_double(); 1.1041 + break; 1.1042 + } 1.1043 + case Bytecodes::_dload: load_local_double(str->get_index()); break; 1.1044 + case Bytecodes::_dload_0: load_local_double(0); break; 1.1045 + case Bytecodes::_dload_1: load_local_double(1); break; 1.1046 + case Bytecodes::_dload_2: load_local_double(2); break; 1.1047 + case Bytecodes::_dload_3: load_local_double(3); break; 1.1048 + 1.1049 + case Bytecodes::_dneg: 1.1050 + { 1.1051 + pop_double(); 1.1052 + push_double(); 1.1053 + break; 1.1054 + } 1.1055 + case Bytecodes::_dreturn: 1.1056 + { 1.1057 + pop_double(); 1.1058 + break; 1.1059 + } 1.1060 + case Bytecodes::_dstore: store_local_double(str->get_index()); break; 1.1061 + case Bytecodes::_dstore_0: store_local_double(0); break; 1.1062 + case Bytecodes::_dstore_1: store_local_double(1); break; 1.1063 + case Bytecodes::_dstore_2: store_local_double(2); break; 1.1064 + case Bytecodes::_dstore_3: store_local_double(3); break; 1.1065 + 1.1066 + case Bytecodes::_dup: 1.1067 + { 1.1068 + push(type_at_tos()); 1.1069 + break; 1.1070 + } 1.1071 + case Bytecodes::_dup_x1: 1.1072 + { 1.1073 + ciType* value1 = pop_value(); 1.1074 + ciType* value2 = pop_value(); 1.1075 + push(value1); 1.1076 + push(value2); 1.1077 + push(value1); 1.1078 + break; 1.1079 + } 1.1080 + case Bytecodes::_dup_x2: 1.1081 + { 1.1082 + ciType* value1 = pop_value(); 1.1083 + ciType* value2 = pop_value(); 1.1084 + ciType* value3 = pop_value(); 1.1085 + push(value1); 1.1086 + push(value3); 1.1087 + push(value2); 1.1088 + push(value1); 1.1089 + break; 1.1090 + } 1.1091 + case Bytecodes::_dup2: 1.1092 + { 1.1093 + ciType* value1 = pop_value(); 1.1094 + ciType* value2 = pop_value(); 1.1095 + push(value2); 1.1096 + push(value1); 1.1097 + push(value2); 1.1098 + push(value1); 1.1099 + break; 1.1100 + } 1.1101 + case Bytecodes::_dup2_x1: 1.1102 + { 1.1103 + ciType* value1 = pop_value(); 1.1104 + ciType* value2 = pop_value(); 1.1105 + ciType* value3 = pop_value(); 1.1106 + push(value2); 1.1107 + push(value1); 1.1108 + push(value3); 1.1109 + push(value2); 1.1110 + push(value1); 1.1111 + break; 1.1112 + } 1.1113 + case Bytecodes::_dup2_x2: 1.1114 + { 1.1115 + ciType* value1 = pop_value(); 1.1116 + ciType* value2 = pop_value(); 1.1117 + ciType* value3 = pop_value(); 1.1118 + ciType* value4 = pop_value(); 1.1119 + push(value2); 1.1120 + push(value1); 1.1121 + push(value4); 1.1122 + push(value3); 1.1123 + push(value2); 1.1124 + push(value1); 1.1125 + break; 1.1126 + } 1.1127 + case Bytecodes::_f2d: 1.1128 + { 1.1129 + pop_float(); 1.1130 + push_double(); 1.1131 + break; 1.1132 + } 1.1133 + case Bytecodes::_f2i: 1.1134 + { 1.1135 + pop_float(); 1.1136 + push_int(); 1.1137 + break; 1.1138 + } 1.1139 + case Bytecodes::_f2l: 1.1140 + { 1.1141 + pop_float(); 1.1142 + push_long(); 1.1143 + break; 1.1144 + } 1.1145 + case Bytecodes::_fadd: 1.1146 + case Bytecodes::_fdiv: 1.1147 + case Bytecodes::_fmul: 1.1148 + case Bytecodes::_frem: 1.1149 + case Bytecodes::_fsub: 1.1150 + { 1.1151 + pop_float(); 1.1152 + pop_float(); 1.1153 + push_float(); 1.1154 + break; 1.1155 + } 1.1156 + case Bytecodes::_faload: 1.1157 + { 1.1158 + pop_int(); 1.1159 + ciTypeArrayKlass* array_klass = pop_typeArray(); 1.1160 + // Put assert here. 1.1161 + push_float(); 1.1162 + break; 1.1163 + } 1.1164 + case Bytecodes::_fastore: 1.1165 + { 1.1166 + pop_float(); 1.1167 + pop_int(); 1.1168 + ciTypeArrayKlass* array_klass = pop_typeArray(); 1.1169 + // Put assert here. 1.1170 + break; 1.1171 + } 1.1172 + case Bytecodes::_fcmpg: 1.1173 + case Bytecodes::_fcmpl: 1.1174 + { 1.1175 + pop_float(); 1.1176 + pop_float(); 1.1177 + push_int(); 1.1178 + break; 1.1179 + } 1.1180 + case Bytecodes::_fconst_0: 1.1181 + case Bytecodes::_fconst_1: 1.1182 + case Bytecodes::_fconst_2: 1.1183 + { 1.1184 + push_float(); 1.1185 + break; 1.1186 + } 1.1187 + case Bytecodes::_fload: load_local_float(str->get_index()); break; 1.1188 + case Bytecodes::_fload_0: load_local_float(0); break; 1.1189 + case Bytecodes::_fload_1: load_local_float(1); break; 1.1190 + case Bytecodes::_fload_2: load_local_float(2); break; 1.1191 + case Bytecodes::_fload_3: load_local_float(3); break; 1.1192 + 1.1193 + case Bytecodes::_fneg: 1.1194 + { 1.1195 + pop_float(); 1.1196 + push_float(); 1.1197 + break; 1.1198 + } 1.1199 + case Bytecodes::_freturn: 1.1200 + { 1.1201 + pop_float(); 1.1202 + break; 1.1203 + } 1.1204 + case Bytecodes::_fstore: store_local_float(str->get_index()); break; 1.1205 + case Bytecodes::_fstore_0: store_local_float(0); break; 1.1206 + case Bytecodes::_fstore_1: store_local_float(1); break; 1.1207 + case Bytecodes::_fstore_2: store_local_float(2); break; 1.1208 + case Bytecodes::_fstore_3: store_local_float(3); break; 1.1209 + 1.1210 + case Bytecodes::_getfield: do_getfield(str); break; 1.1211 + case Bytecodes::_getstatic: do_getstatic(str); break; 1.1212 + 1.1213 + case Bytecodes::_goto: 1.1214 + case Bytecodes::_goto_w: 1.1215 + case Bytecodes::_nop: 1.1216 + case Bytecodes::_return: 1.1217 + { 1.1218 + // do nothing. 1.1219 + break; 1.1220 + } 1.1221 + case Bytecodes::_i2b: 1.1222 + case Bytecodes::_i2c: 1.1223 + case Bytecodes::_i2s: 1.1224 + case Bytecodes::_ineg: 1.1225 + { 1.1226 + pop_int(); 1.1227 + push_int(); 1.1228 + break; 1.1229 + } 1.1230 + case Bytecodes::_i2d: 1.1231 + { 1.1232 + pop_int(); 1.1233 + push_double(); 1.1234 + break; 1.1235 + } 1.1236 + case Bytecodes::_i2f: 1.1237 + { 1.1238 + pop_int(); 1.1239 + push_float(); 1.1240 + break; 1.1241 + } 1.1242 + case Bytecodes::_i2l: 1.1243 + { 1.1244 + pop_int(); 1.1245 + push_long(); 1.1246 + break; 1.1247 + } 1.1248 + case Bytecodes::_iadd: 1.1249 + case Bytecodes::_iand: 1.1250 + case Bytecodes::_idiv: 1.1251 + case Bytecodes::_imul: 1.1252 + case Bytecodes::_ior: 1.1253 + case Bytecodes::_irem: 1.1254 + case Bytecodes::_ishl: 1.1255 + case Bytecodes::_ishr: 1.1256 + case Bytecodes::_isub: 1.1257 + case Bytecodes::_iushr: 1.1258 + case Bytecodes::_ixor: 1.1259 + { 1.1260 + pop_int(); 1.1261 + pop_int(); 1.1262 + push_int(); 1.1263 + break; 1.1264 + } 1.1265 + case Bytecodes::_if_acmpeq: 1.1266 + case Bytecodes::_if_acmpne: 1.1267 + { 1.1268 + pop_object(); 1.1269 + pop_object(); 1.1270 + break; 1.1271 + } 1.1272 + case Bytecodes::_if_icmpeq: 1.1273 + case Bytecodes::_if_icmpge: 1.1274 + case Bytecodes::_if_icmpgt: 1.1275 + case Bytecodes::_if_icmple: 1.1276 + case Bytecodes::_if_icmplt: 1.1277 + case Bytecodes::_if_icmpne: 1.1278 + { 1.1279 + pop_int(); 1.1280 + pop_int(); 1.1281 + break; 1.1282 + } 1.1283 + case Bytecodes::_ifeq: 1.1284 + case Bytecodes::_ifle: 1.1285 + case Bytecodes::_iflt: 1.1286 + case Bytecodes::_ifge: 1.1287 + case Bytecodes::_ifgt: 1.1288 + case Bytecodes::_ifne: 1.1289 + case Bytecodes::_ireturn: 1.1290 + case Bytecodes::_lookupswitch: 1.1291 + case Bytecodes::_tableswitch: 1.1292 + { 1.1293 + pop_int(); 1.1294 + break; 1.1295 + } 1.1296 + case Bytecodes::_iinc: 1.1297 + { 1.1298 + int lnum = str->get_index(); 1.1299 + check_int(local(lnum)); 1.1300 + store_to_local(lnum); 1.1301 + break; 1.1302 + } 1.1303 + case Bytecodes::_iload: load_local_int(str->get_index()); break; 1.1304 + case Bytecodes::_iload_0: load_local_int(0); break; 1.1305 + case Bytecodes::_iload_1: load_local_int(1); break; 1.1306 + case Bytecodes::_iload_2: load_local_int(2); break; 1.1307 + case Bytecodes::_iload_3: load_local_int(3); break; 1.1308 + 1.1309 + case Bytecodes::_instanceof: 1.1310 + { 1.1311 + // Check for uncommon trap: 1.1312 + do_checkcast(str); 1.1313 + pop_object(); 1.1314 + push_int(); 1.1315 + break; 1.1316 + } 1.1317 + case Bytecodes::_invokeinterface: do_invoke(str, true); break; 1.1318 + case Bytecodes::_invokespecial: do_invoke(str, true); break; 1.1319 + case Bytecodes::_invokestatic: do_invoke(str, false); break; 1.1320 + case Bytecodes::_invokevirtual: do_invoke(str, true); break; 1.1321 + case Bytecodes::_invokedynamic: do_invoke(str, false); break; 1.1322 + 1.1323 + case Bytecodes::_istore: store_local_int(str->get_index()); break; 1.1324 + case Bytecodes::_istore_0: store_local_int(0); break; 1.1325 + case Bytecodes::_istore_1: store_local_int(1); break; 1.1326 + case Bytecodes::_istore_2: store_local_int(2); break; 1.1327 + case Bytecodes::_istore_3: store_local_int(3); break; 1.1328 + 1.1329 + case Bytecodes::_jsr: 1.1330 + case Bytecodes::_jsr_w: do_jsr(str); break; 1.1331 + 1.1332 + case Bytecodes::_l2d: 1.1333 + { 1.1334 + pop_long(); 1.1335 + push_double(); 1.1336 + break; 1.1337 + } 1.1338 + case Bytecodes::_l2f: 1.1339 + { 1.1340 + pop_long(); 1.1341 + push_float(); 1.1342 + break; 1.1343 + } 1.1344 + case Bytecodes::_l2i: 1.1345 + { 1.1346 + pop_long(); 1.1347 + push_int(); 1.1348 + break; 1.1349 + } 1.1350 + case Bytecodes::_ladd: 1.1351 + case Bytecodes::_land: 1.1352 + case Bytecodes::_ldiv: 1.1353 + case Bytecodes::_lmul: 1.1354 + case Bytecodes::_lor: 1.1355 + case Bytecodes::_lrem: 1.1356 + case Bytecodes::_lsub: 1.1357 + case Bytecodes::_lxor: 1.1358 + { 1.1359 + pop_long(); 1.1360 + pop_long(); 1.1361 + push_long(); 1.1362 + break; 1.1363 + } 1.1364 + case Bytecodes::_laload: 1.1365 + { 1.1366 + pop_int(); 1.1367 + ciTypeArrayKlass* array_klass = pop_typeArray(); 1.1368 + // Put assert here for right type? 1.1369 + push_long(); 1.1370 + break; 1.1371 + } 1.1372 + case Bytecodes::_lastore: 1.1373 + { 1.1374 + pop_long(); 1.1375 + pop_int(); 1.1376 + pop_typeArray(); 1.1377 + // assert here? 1.1378 + break; 1.1379 + } 1.1380 + case Bytecodes::_lcmp: 1.1381 + { 1.1382 + pop_long(); 1.1383 + pop_long(); 1.1384 + push_int(); 1.1385 + break; 1.1386 + } 1.1387 + case Bytecodes::_lconst_0: 1.1388 + case Bytecodes::_lconst_1: 1.1389 + { 1.1390 + push_long(); 1.1391 + break; 1.1392 + } 1.1393 + case Bytecodes::_ldc: 1.1394 + case Bytecodes::_ldc_w: 1.1395 + case Bytecodes::_ldc2_w: 1.1396 + { 1.1397 + do_ldc(str); 1.1398 + break; 1.1399 + } 1.1400 + 1.1401 + case Bytecodes::_lload: load_local_long(str->get_index()); break; 1.1402 + case Bytecodes::_lload_0: load_local_long(0); break; 1.1403 + case Bytecodes::_lload_1: load_local_long(1); break; 1.1404 + case Bytecodes::_lload_2: load_local_long(2); break; 1.1405 + case Bytecodes::_lload_3: load_local_long(3); break; 1.1406 + 1.1407 + case Bytecodes::_lneg: 1.1408 + { 1.1409 + pop_long(); 1.1410 + push_long(); 1.1411 + break; 1.1412 + } 1.1413 + case Bytecodes::_lreturn: 1.1414 + { 1.1415 + pop_long(); 1.1416 + break; 1.1417 + } 1.1418 + case Bytecodes::_lshl: 1.1419 + case Bytecodes::_lshr: 1.1420 + case Bytecodes::_lushr: 1.1421 + { 1.1422 + pop_int(); 1.1423 + pop_long(); 1.1424 + push_long(); 1.1425 + break; 1.1426 + } 1.1427 + case Bytecodes::_lstore: store_local_long(str->get_index()); break; 1.1428 + case Bytecodes::_lstore_0: store_local_long(0); break; 1.1429 + case Bytecodes::_lstore_1: store_local_long(1); break; 1.1430 + case Bytecodes::_lstore_2: store_local_long(2); break; 1.1431 + case Bytecodes::_lstore_3: store_local_long(3); break; 1.1432 + 1.1433 + case Bytecodes::_multianewarray: do_multianewarray(str); break; 1.1434 + 1.1435 + case Bytecodes::_new: do_new(str); break; 1.1436 + 1.1437 + case Bytecodes::_newarray: do_newarray(str); break; 1.1438 + 1.1439 + case Bytecodes::_pop: 1.1440 + { 1.1441 + pop(); 1.1442 + break; 1.1443 + } 1.1444 + case Bytecodes::_pop2: 1.1445 + { 1.1446 + pop(); 1.1447 + pop(); 1.1448 + break; 1.1449 + } 1.1450 + 1.1451 + case Bytecodes::_putfield: do_putfield(str); break; 1.1452 + case Bytecodes::_putstatic: do_putstatic(str); break; 1.1453 + 1.1454 + case Bytecodes::_ret: do_ret(str); break; 1.1455 + 1.1456 + case Bytecodes::_swap: 1.1457 + { 1.1458 + ciType* value1 = pop_value(); 1.1459 + ciType* value2 = pop_value(); 1.1460 + push(value1); 1.1461 + push(value2); 1.1462 + break; 1.1463 + } 1.1464 + case Bytecodes::_wide: 1.1465 + default: 1.1466 + { 1.1467 + // The iterator should skip this. 1.1468 + ShouldNotReachHere(); 1.1469 + break; 1.1470 + } 1.1471 + } 1.1472 + 1.1473 + if (CITraceTypeFlow) { 1.1474 + print_on(tty); 1.1475 + } 1.1476 + 1.1477 + return (_trap_bci != -1); 1.1478 +} 1.1479 + 1.1480 +#ifndef PRODUCT 1.1481 +// ------------------------------------------------------------------ 1.1482 +// ciTypeFlow::StateVector::print_cell_on 1.1483 +void ciTypeFlow::StateVector::print_cell_on(outputStream* st, Cell c) const { 1.1484 + ciType* type = type_at(c); 1.1485 + if (type == top_type()) { 1.1486 + st->print("top"); 1.1487 + } else if (type == bottom_type()) { 1.1488 + st->print("bottom"); 1.1489 + } else if (type == null_type()) { 1.1490 + st->print("null"); 1.1491 + } else if (type == long2_type()) { 1.1492 + st->print("long2"); 1.1493 + } else if (type == double2_type()) { 1.1494 + st->print("double2"); 1.1495 + } else if (is_int(type)) { 1.1496 + st->print("int"); 1.1497 + } else if (is_long(type)) { 1.1498 + st->print("long"); 1.1499 + } else if (is_float(type)) { 1.1500 + st->print("float"); 1.1501 + } else if (is_double(type)) { 1.1502 + st->print("double"); 1.1503 + } else if (type->is_return_address()) { 1.1504 + st->print("address(%d)", type->as_return_address()->bci()); 1.1505 + } else { 1.1506 + if (type->is_klass()) { 1.1507 + type->as_klass()->name()->print_symbol_on(st); 1.1508 + } else { 1.1509 + st->print("UNEXPECTED TYPE"); 1.1510 + type->print(); 1.1511 + } 1.1512 + } 1.1513 +} 1.1514 + 1.1515 +// ------------------------------------------------------------------ 1.1516 +// ciTypeFlow::StateVector::print_on 1.1517 +void ciTypeFlow::StateVector::print_on(outputStream* st) const { 1.1518 + int num_locals = _outer->max_locals(); 1.1519 + int num_stack = stack_size(); 1.1520 + int num_monitors = monitor_count(); 1.1521 + st->print_cr(" State : locals %d, stack %d, monitors %d", num_locals, num_stack, num_monitors); 1.1522 + if (num_stack >= 0) { 1.1523 + int i; 1.1524 + for (i = 0; i < num_locals; i++) { 1.1525 + st->print(" local %2d : ", i); 1.1526 + print_cell_on(st, local(i)); 1.1527 + st->cr(); 1.1528 + } 1.1529 + for (i = 0; i < num_stack; i++) { 1.1530 + st->print(" stack %2d : ", i); 1.1531 + print_cell_on(st, stack(i)); 1.1532 + st->cr(); 1.1533 + } 1.1534 + } 1.1535 +} 1.1536 +#endif 1.1537 + 1.1538 + 1.1539 +// ------------------------------------------------------------------ 1.1540 +// ciTypeFlow::SuccIter::next 1.1541 +// 1.1542 +void ciTypeFlow::SuccIter::next() { 1.1543 + int succ_ct = _pred->successors()->length(); 1.1544 + int next = _index + 1; 1.1545 + if (next < succ_ct) { 1.1546 + _index = next; 1.1547 + _succ = _pred->successors()->at(next); 1.1548 + return; 1.1549 + } 1.1550 + for (int i = next - succ_ct; i < _pred->exceptions()->length(); i++) { 1.1551 + // Do not compile any code for unloaded exception types. 1.1552 + // Following compiler passes are responsible for doing this also. 1.1553 + ciInstanceKlass* exception_klass = _pred->exc_klasses()->at(i); 1.1554 + if (exception_klass->is_loaded()) { 1.1555 + _index = next; 1.1556 + _succ = _pred->exceptions()->at(i); 1.1557 + return; 1.1558 + } 1.1559 + next++; 1.1560 + } 1.1561 + _index = -1; 1.1562 + _succ = NULL; 1.1563 +} 1.1564 + 1.1565 +// ------------------------------------------------------------------ 1.1566 +// ciTypeFlow::SuccIter::set_succ 1.1567 +// 1.1568 +void ciTypeFlow::SuccIter::set_succ(Block* succ) { 1.1569 + int succ_ct = _pred->successors()->length(); 1.1570 + if (_index < succ_ct) { 1.1571 + _pred->successors()->at_put(_index, succ); 1.1572 + } else { 1.1573 + int idx = _index - succ_ct; 1.1574 + _pred->exceptions()->at_put(idx, succ); 1.1575 + } 1.1576 +} 1.1577 + 1.1578 +// ciTypeFlow::Block 1.1579 +// 1.1580 +// A basic block. 1.1581 + 1.1582 +// ------------------------------------------------------------------ 1.1583 +// ciTypeFlow::Block::Block 1.1584 +ciTypeFlow::Block::Block(ciTypeFlow* outer, 1.1585 + ciBlock *ciblk, 1.1586 + ciTypeFlow::JsrSet* jsrs) { 1.1587 + _ciblock = ciblk; 1.1588 + _exceptions = NULL; 1.1589 + _exc_klasses = NULL; 1.1590 + _successors = NULL; 1.1591 + _state = new (outer->arena()) StateVector(outer); 1.1592 + JsrSet* new_jsrs = 1.1593 + new (outer->arena()) JsrSet(outer->arena(), jsrs->size()); 1.1594 + jsrs->copy_into(new_jsrs); 1.1595 + _jsrs = new_jsrs; 1.1596 + _next = NULL; 1.1597 + _on_work_list = false; 1.1598 + _backedge_copy = false; 1.1599 + _has_monitorenter = false; 1.1600 + _trap_bci = -1; 1.1601 + _trap_index = 0; 1.1602 + df_init(); 1.1603 + 1.1604 + if (CITraceTypeFlow) { 1.1605 + tty->print_cr(">> Created new block"); 1.1606 + print_on(tty); 1.1607 + } 1.1608 + 1.1609 + assert(this->outer() == outer, "outer link set up"); 1.1610 + assert(!outer->have_block_count(), "must not have mapped blocks yet"); 1.1611 +} 1.1612 + 1.1613 +// ------------------------------------------------------------------ 1.1614 +// ciTypeFlow::Block::df_init 1.1615 +void ciTypeFlow::Block::df_init() { 1.1616 + _pre_order = -1; assert(!has_pre_order(), ""); 1.1617 + _post_order = -1; assert(!has_post_order(), ""); 1.1618 + _loop = NULL; 1.1619 + _irreducible_entry = false; 1.1620 + _rpo_next = NULL; 1.1621 +} 1.1622 + 1.1623 +// ------------------------------------------------------------------ 1.1624 +// ciTypeFlow::Block::successors 1.1625 +// 1.1626 +// Get the successors for this Block. 1.1627 +GrowableArray<ciTypeFlow::Block*>* 1.1628 +ciTypeFlow::Block::successors(ciBytecodeStream* str, 1.1629 + ciTypeFlow::StateVector* state, 1.1630 + ciTypeFlow::JsrSet* jsrs) { 1.1631 + if (_successors == NULL) { 1.1632 + if (CITraceTypeFlow) { 1.1633 + tty->print(">> Computing successors for block "); 1.1634 + print_value_on(tty); 1.1635 + tty->cr(); 1.1636 + } 1.1637 + 1.1638 + ciTypeFlow* analyzer = outer(); 1.1639 + Arena* arena = analyzer->arena(); 1.1640 + Block* block = NULL; 1.1641 + bool has_successor = !has_trap() && 1.1642 + (control() != ciBlock::fall_through_bci || limit() < analyzer->code_size()); 1.1643 + if (!has_successor) { 1.1644 + _successors = 1.1645 + new (arena) GrowableArray<Block*>(arena, 1, 0, NULL); 1.1646 + // No successors 1.1647 + } else if (control() == ciBlock::fall_through_bci) { 1.1648 + assert(str->cur_bci() == limit(), "bad block end"); 1.1649 + // This block simply falls through to the next. 1.1650 + _successors = 1.1651 + new (arena) GrowableArray<Block*>(arena, 1, 0, NULL); 1.1652 + 1.1653 + Block* block = analyzer->block_at(limit(), _jsrs); 1.1654 + assert(_successors->length() == FALL_THROUGH, ""); 1.1655 + _successors->append(block); 1.1656 + } else { 1.1657 + int current_bci = str->cur_bci(); 1.1658 + int next_bci = str->next_bci(); 1.1659 + int branch_bci = -1; 1.1660 + Block* target = NULL; 1.1661 + assert(str->next_bci() == limit(), "bad block end"); 1.1662 + // This block is not a simple fall-though. Interpret 1.1663 + // the current bytecode to find our successors. 1.1664 + switch (str->cur_bc()) { 1.1665 + case Bytecodes::_ifeq: case Bytecodes::_ifne: 1.1666 + case Bytecodes::_iflt: case Bytecodes::_ifge: 1.1667 + case Bytecodes::_ifgt: case Bytecodes::_ifle: 1.1668 + case Bytecodes::_if_icmpeq: case Bytecodes::_if_icmpne: 1.1669 + case Bytecodes::_if_icmplt: case Bytecodes::_if_icmpge: 1.1670 + case Bytecodes::_if_icmpgt: case Bytecodes::_if_icmple: 1.1671 + case Bytecodes::_if_acmpeq: case Bytecodes::_if_acmpne: 1.1672 + case Bytecodes::_ifnull: case Bytecodes::_ifnonnull: 1.1673 + // Our successors are the branch target and the next bci. 1.1674 + branch_bci = str->get_dest(); 1.1675 + _successors = 1.1676 + new (arena) GrowableArray<Block*>(arena, 2, 0, NULL); 1.1677 + assert(_successors->length() == IF_NOT_TAKEN, ""); 1.1678 + _successors->append(analyzer->block_at(next_bci, jsrs)); 1.1679 + assert(_successors->length() == IF_TAKEN, ""); 1.1680 + _successors->append(analyzer->block_at(branch_bci, jsrs)); 1.1681 + break; 1.1682 + 1.1683 + case Bytecodes::_goto: 1.1684 + branch_bci = str->get_dest(); 1.1685 + _successors = 1.1686 + new (arena) GrowableArray<Block*>(arena, 1, 0, NULL); 1.1687 + assert(_successors->length() == GOTO_TARGET, ""); 1.1688 + _successors->append(analyzer->block_at(branch_bci, jsrs)); 1.1689 + break; 1.1690 + 1.1691 + case Bytecodes::_jsr: 1.1692 + branch_bci = str->get_dest(); 1.1693 + _successors = 1.1694 + new (arena) GrowableArray<Block*>(arena, 1, 0, NULL); 1.1695 + assert(_successors->length() == GOTO_TARGET, ""); 1.1696 + _successors->append(analyzer->block_at(branch_bci, jsrs)); 1.1697 + break; 1.1698 + 1.1699 + case Bytecodes::_goto_w: 1.1700 + case Bytecodes::_jsr_w: 1.1701 + _successors = 1.1702 + new (arena) GrowableArray<Block*>(arena, 1, 0, NULL); 1.1703 + assert(_successors->length() == GOTO_TARGET, ""); 1.1704 + _successors->append(analyzer->block_at(str->get_far_dest(), jsrs)); 1.1705 + break; 1.1706 + 1.1707 + case Bytecodes::_tableswitch: { 1.1708 + Bytecode_tableswitch tableswitch(str); 1.1709 + 1.1710 + int len = tableswitch.length(); 1.1711 + _successors = 1.1712 + new (arena) GrowableArray<Block*>(arena, len+1, 0, NULL); 1.1713 + int bci = current_bci + tableswitch.default_offset(); 1.1714 + Block* block = analyzer->block_at(bci, jsrs); 1.1715 + assert(_successors->length() == SWITCH_DEFAULT, ""); 1.1716 + _successors->append(block); 1.1717 + while (--len >= 0) { 1.1718 + int bci = current_bci + tableswitch.dest_offset_at(len); 1.1719 + block = analyzer->block_at(bci, jsrs); 1.1720 + assert(_successors->length() >= SWITCH_CASES, ""); 1.1721 + _successors->append_if_missing(block); 1.1722 + } 1.1723 + break; 1.1724 + } 1.1725 + 1.1726 + case Bytecodes::_lookupswitch: { 1.1727 + Bytecode_lookupswitch lookupswitch(str); 1.1728 + 1.1729 + int npairs = lookupswitch.number_of_pairs(); 1.1730 + _successors = 1.1731 + new (arena) GrowableArray<Block*>(arena, npairs+1, 0, NULL); 1.1732 + int bci = current_bci + lookupswitch.default_offset(); 1.1733 + Block* block = analyzer->block_at(bci, jsrs); 1.1734 + assert(_successors->length() == SWITCH_DEFAULT, ""); 1.1735 + _successors->append(block); 1.1736 + while(--npairs >= 0) { 1.1737 + LookupswitchPair pair = lookupswitch.pair_at(npairs); 1.1738 + int bci = current_bci + pair.offset(); 1.1739 + Block* block = analyzer->block_at(bci, jsrs); 1.1740 + assert(_successors->length() >= SWITCH_CASES, ""); 1.1741 + _successors->append_if_missing(block); 1.1742 + } 1.1743 + break; 1.1744 + } 1.1745 + 1.1746 + case Bytecodes::_athrow: case Bytecodes::_ireturn: 1.1747 + case Bytecodes::_lreturn: case Bytecodes::_freturn: 1.1748 + case Bytecodes::_dreturn: case Bytecodes::_areturn: 1.1749 + case Bytecodes::_return: 1.1750 + _successors = 1.1751 + new (arena) GrowableArray<Block*>(arena, 1, 0, NULL); 1.1752 + // No successors 1.1753 + break; 1.1754 + 1.1755 + case Bytecodes::_ret: { 1.1756 + _successors = 1.1757 + new (arena) GrowableArray<Block*>(arena, 1, 0, NULL); 1.1758 + 1.1759 + Cell local = state->local(str->get_index()); 1.1760 + ciType* return_address = state->type_at(local); 1.1761 + assert(return_address->is_return_address(), "verify: wrong type"); 1.1762 + int bci = return_address->as_return_address()->bci(); 1.1763 + assert(_successors->length() == GOTO_TARGET, ""); 1.1764 + _successors->append(analyzer->block_at(bci, jsrs)); 1.1765 + break; 1.1766 + } 1.1767 + 1.1768 + case Bytecodes::_wide: 1.1769 + default: 1.1770 + ShouldNotReachHere(); 1.1771 + break; 1.1772 + } 1.1773 + } 1.1774 + } 1.1775 + return _successors; 1.1776 +} 1.1777 + 1.1778 +// ------------------------------------------------------------------ 1.1779 +// ciTypeFlow::Block:compute_exceptions 1.1780 +// 1.1781 +// Compute the exceptional successors and types for this Block. 1.1782 +void ciTypeFlow::Block::compute_exceptions() { 1.1783 + assert(_exceptions == NULL && _exc_klasses == NULL, "repeat"); 1.1784 + 1.1785 + if (CITraceTypeFlow) { 1.1786 + tty->print(">> Computing exceptions for block "); 1.1787 + print_value_on(tty); 1.1788 + tty->cr(); 1.1789 + } 1.1790 + 1.1791 + ciTypeFlow* analyzer = outer(); 1.1792 + Arena* arena = analyzer->arena(); 1.1793 + 1.1794 + // Any bci in the block will do. 1.1795 + ciExceptionHandlerStream str(analyzer->method(), start()); 1.1796 + 1.1797 + // Allocate our growable arrays. 1.1798 + int exc_count = str.count(); 1.1799 + _exceptions = new (arena) GrowableArray<Block*>(arena, exc_count, 0, NULL); 1.1800 + _exc_klasses = new (arena) GrowableArray<ciInstanceKlass*>(arena, exc_count, 1.1801 + 0, NULL); 1.1802 + 1.1803 + for ( ; !str.is_done(); str.next()) { 1.1804 + ciExceptionHandler* handler = str.handler(); 1.1805 + int bci = handler->handler_bci(); 1.1806 + ciInstanceKlass* klass = NULL; 1.1807 + if (bci == -1) { 1.1808 + // There is no catch all. It is possible to exit the method. 1.1809 + break; 1.1810 + } 1.1811 + if (handler->is_catch_all()) { 1.1812 + klass = analyzer->env()->Throwable_klass(); 1.1813 + } else { 1.1814 + klass = handler->catch_klass(); 1.1815 + } 1.1816 + _exceptions->append(analyzer->block_at(bci, _jsrs)); 1.1817 + _exc_klasses->append(klass); 1.1818 + } 1.1819 +} 1.1820 + 1.1821 +// ------------------------------------------------------------------ 1.1822 +// ciTypeFlow::Block::set_backedge_copy 1.1823 +// Use this only to make a pre-existing public block into a backedge copy. 1.1824 +void ciTypeFlow::Block::set_backedge_copy(bool z) { 1.1825 + assert(z || (z == is_backedge_copy()), "cannot make a backedge copy public"); 1.1826 + _backedge_copy = z; 1.1827 +} 1.1828 + 1.1829 +// ------------------------------------------------------------------ 1.1830 +// ciTypeFlow::Block::is_clonable_exit 1.1831 +// 1.1832 +// At most 2 normal successors, one of which continues looping, 1.1833 +// and all exceptional successors must exit. 1.1834 +bool ciTypeFlow::Block::is_clonable_exit(ciTypeFlow::Loop* lp) { 1.1835 + int normal_cnt = 0; 1.1836 + int in_loop_cnt = 0; 1.1837 + for (SuccIter iter(this); !iter.done(); iter.next()) { 1.1838 + Block* succ = iter.succ(); 1.1839 + if (iter.is_normal_ctrl()) { 1.1840 + if (++normal_cnt > 2) return false; 1.1841 + if (lp->contains(succ->loop())) { 1.1842 + if (++in_loop_cnt > 1) return false; 1.1843 + } 1.1844 + } else { 1.1845 + if (lp->contains(succ->loop())) return false; 1.1846 + } 1.1847 + } 1.1848 + return in_loop_cnt == 1; 1.1849 +} 1.1850 + 1.1851 +// ------------------------------------------------------------------ 1.1852 +// ciTypeFlow::Block::looping_succ 1.1853 +// 1.1854 +ciTypeFlow::Block* ciTypeFlow::Block::looping_succ(ciTypeFlow::Loop* lp) { 1.1855 + assert(successors()->length() <= 2, "at most 2 normal successors"); 1.1856 + for (SuccIter iter(this); !iter.done(); iter.next()) { 1.1857 + Block* succ = iter.succ(); 1.1858 + if (lp->contains(succ->loop())) { 1.1859 + return succ; 1.1860 + } 1.1861 + } 1.1862 + return NULL; 1.1863 +} 1.1864 + 1.1865 +#ifndef PRODUCT 1.1866 +// ------------------------------------------------------------------ 1.1867 +// ciTypeFlow::Block::print_value_on 1.1868 +void ciTypeFlow::Block::print_value_on(outputStream* st) const { 1.1869 + if (has_pre_order()) st->print("#%-2d ", pre_order()); 1.1870 + if (has_rpo()) st->print("rpo#%-2d ", rpo()); 1.1871 + st->print("[%d - %d)", start(), limit()); 1.1872 + if (is_loop_head()) st->print(" lphd"); 1.1873 + if (is_irreducible_entry()) st->print(" irred"); 1.1874 + if (_jsrs->size() > 0) { st->print("/"); _jsrs->print_on(st); } 1.1875 + if (is_backedge_copy()) st->print("/backedge_copy"); 1.1876 +} 1.1877 + 1.1878 +// ------------------------------------------------------------------ 1.1879 +// ciTypeFlow::Block::print_on 1.1880 +void ciTypeFlow::Block::print_on(outputStream* st) const { 1.1881 + if ((Verbose || WizardMode) && (limit() >= 0)) { 1.1882 + // Don't print 'dummy' blocks (i.e. blocks with limit() '-1') 1.1883 + outer()->method()->print_codes_on(start(), limit(), st); 1.1884 + } 1.1885 + st->print_cr(" ==================================================== "); 1.1886 + st->print (" "); 1.1887 + print_value_on(st); 1.1888 + st->print(" Stored locals: "); def_locals()->print_on(st, outer()->method()->max_locals()); tty->cr(); 1.1889 + if (loop() && loop()->parent() != NULL) { 1.1890 + st->print(" loops:"); 1.1891 + Loop* lp = loop(); 1.1892 + do { 1.1893 + st->print(" %d<-%d", lp->head()->pre_order(),lp->tail()->pre_order()); 1.1894 + if (lp->is_irreducible()) st->print("(ir)"); 1.1895 + lp = lp->parent(); 1.1896 + } while (lp->parent() != NULL); 1.1897 + } 1.1898 + st->cr(); 1.1899 + _state->print_on(st); 1.1900 + if (_successors == NULL) { 1.1901 + st->print_cr(" No successor information"); 1.1902 + } else { 1.1903 + int num_successors = _successors->length(); 1.1904 + st->print_cr(" Successors : %d", num_successors); 1.1905 + for (int i = 0; i < num_successors; i++) { 1.1906 + Block* successor = _successors->at(i); 1.1907 + st->print(" "); 1.1908 + successor->print_value_on(st); 1.1909 + st->cr(); 1.1910 + } 1.1911 + } 1.1912 + if (_exceptions == NULL) { 1.1913 + st->print_cr(" No exception information"); 1.1914 + } else { 1.1915 + int num_exceptions = _exceptions->length(); 1.1916 + st->print_cr(" Exceptions : %d", num_exceptions); 1.1917 + for (int i = 0; i < num_exceptions; i++) { 1.1918 + Block* exc_succ = _exceptions->at(i); 1.1919 + ciInstanceKlass* exc_klass = _exc_klasses->at(i); 1.1920 + st->print(" "); 1.1921 + exc_succ->print_value_on(st); 1.1922 + st->print(" -- "); 1.1923 + exc_klass->name()->print_symbol_on(st); 1.1924 + st->cr(); 1.1925 + } 1.1926 + } 1.1927 + if (has_trap()) { 1.1928 + st->print_cr(" Traps on %d with trap index %d", trap_bci(), trap_index()); 1.1929 + } 1.1930 + st->print_cr(" ==================================================== "); 1.1931 +} 1.1932 +#endif 1.1933 + 1.1934 +#ifndef PRODUCT 1.1935 +// ------------------------------------------------------------------ 1.1936 +// ciTypeFlow::LocalSet::print_on 1.1937 +void ciTypeFlow::LocalSet::print_on(outputStream* st, int limit) const { 1.1938 + st->print("{"); 1.1939 + for (int i = 0; i < max; i++) { 1.1940 + if (test(i)) st->print(" %d", i); 1.1941 + } 1.1942 + if (limit > max) { 1.1943 + st->print(" %d..%d ", max, limit); 1.1944 + } 1.1945 + st->print(" }"); 1.1946 +} 1.1947 +#endif 1.1948 + 1.1949 +// ciTypeFlow 1.1950 +// 1.1951 +// This is a pass over the bytecodes which computes the following: 1.1952 +// basic block structure 1.1953 +// interpreter type-states (a la the verifier) 1.1954 + 1.1955 +// ------------------------------------------------------------------ 1.1956 +// ciTypeFlow::ciTypeFlow 1.1957 +ciTypeFlow::ciTypeFlow(ciEnv* env, ciMethod* method, int osr_bci) { 1.1958 + _env = env; 1.1959 + _method = method; 1.1960 + _methodBlocks = method->get_method_blocks(); 1.1961 + _max_locals = method->max_locals(); 1.1962 + _max_stack = method->max_stack(); 1.1963 + _code_size = method->code_size(); 1.1964 + _has_irreducible_entry = false; 1.1965 + _osr_bci = osr_bci; 1.1966 + _failure_reason = NULL; 1.1967 + assert(0 <= start_bci() && start_bci() < code_size() , err_msg("correct osr_bci argument: 0 <= %d < %d", start_bci(), code_size())); 1.1968 + _work_list = NULL; 1.1969 + 1.1970 + _ciblock_count = _methodBlocks->num_blocks(); 1.1971 + _idx_to_blocklist = NEW_ARENA_ARRAY(arena(), GrowableArray<Block*>*, _ciblock_count); 1.1972 + for (int i = 0; i < _ciblock_count; i++) { 1.1973 + _idx_to_blocklist[i] = NULL; 1.1974 + } 1.1975 + _block_map = NULL; // until all blocks are seen 1.1976 + _jsr_count = 0; 1.1977 + _jsr_records = NULL; 1.1978 +} 1.1979 + 1.1980 +// ------------------------------------------------------------------ 1.1981 +// ciTypeFlow::work_list_next 1.1982 +// 1.1983 +// Get the next basic block from our work list. 1.1984 +ciTypeFlow::Block* ciTypeFlow::work_list_next() { 1.1985 + assert(!work_list_empty(), "work list must not be empty"); 1.1986 + Block* next_block = _work_list; 1.1987 + _work_list = next_block->next(); 1.1988 + next_block->set_next(NULL); 1.1989 + next_block->set_on_work_list(false); 1.1990 + return next_block; 1.1991 +} 1.1992 + 1.1993 +// ------------------------------------------------------------------ 1.1994 +// ciTypeFlow::add_to_work_list 1.1995 +// 1.1996 +// Add a basic block to our work list. 1.1997 +// List is sorted by decreasing postorder sort (same as increasing RPO) 1.1998 +void ciTypeFlow::add_to_work_list(ciTypeFlow::Block* block) { 1.1999 + assert(!block->is_on_work_list(), "must not already be on work list"); 1.2000 + 1.2001 + if (CITraceTypeFlow) { 1.2002 + tty->print(">> Adding block "); 1.2003 + block->print_value_on(tty); 1.2004 + tty->print_cr(" to the work list : "); 1.2005 + } 1.2006 + 1.2007 + block->set_on_work_list(true); 1.2008 + 1.2009 + // decreasing post order sort 1.2010 + 1.2011 + Block* prev = NULL; 1.2012 + Block* current = _work_list; 1.2013 + int po = block->post_order(); 1.2014 + while (current != NULL) { 1.2015 + if (!current->has_post_order() || po > current->post_order()) 1.2016 + break; 1.2017 + prev = current; 1.2018 + current = current->next(); 1.2019 + } 1.2020 + if (prev == NULL) { 1.2021 + block->set_next(_work_list); 1.2022 + _work_list = block; 1.2023 + } else { 1.2024 + block->set_next(current); 1.2025 + prev->set_next(block); 1.2026 + } 1.2027 + 1.2028 + if (CITraceTypeFlow) { 1.2029 + tty->cr(); 1.2030 + } 1.2031 +} 1.2032 + 1.2033 +// ------------------------------------------------------------------ 1.2034 +// ciTypeFlow::block_at 1.2035 +// 1.2036 +// Return the block beginning at bci which has a JsrSet compatible 1.2037 +// with jsrs. 1.2038 +ciTypeFlow::Block* ciTypeFlow::block_at(int bci, ciTypeFlow::JsrSet* jsrs, CreateOption option) { 1.2039 + // First find the right ciBlock. 1.2040 + if (CITraceTypeFlow) { 1.2041 + tty->print(">> Requesting block for %d/", bci); 1.2042 + jsrs->print_on(tty); 1.2043 + tty->cr(); 1.2044 + } 1.2045 + 1.2046 + ciBlock* ciblk = _methodBlocks->block_containing(bci); 1.2047 + assert(ciblk->start_bci() == bci, "bad ciBlock boundaries"); 1.2048 + Block* block = get_block_for(ciblk->index(), jsrs, option); 1.2049 + 1.2050 + assert(block == NULL? (option == no_create): block->is_backedge_copy() == (option == create_backedge_copy), "create option consistent with result"); 1.2051 + 1.2052 + if (CITraceTypeFlow) { 1.2053 + if (block != NULL) { 1.2054 + tty->print(">> Found block "); 1.2055 + block->print_value_on(tty); 1.2056 + tty->cr(); 1.2057 + } else { 1.2058 + tty->print_cr(">> No such block."); 1.2059 + } 1.2060 + } 1.2061 + 1.2062 + return block; 1.2063 +} 1.2064 + 1.2065 +// ------------------------------------------------------------------ 1.2066 +// ciTypeFlow::make_jsr_record 1.2067 +// 1.2068 +// Make a JsrRecord for a given (entry, return) pair, if such a record 1.2069 +// does not already exist. 1.2070 +ciTypeFlow::JsrRecord* ciTypeFlow::make_jsr_record(int entry_address, 1.2071 + int return_address) { 1.2072 + if (_jsr_records == NULL) { 1.2073 + _jsr_records = new (arena()) GrowableArray<JsrRecord*>(arena(), 1.2074 + _jsr_count, 1.2075 + 0, 1.2076 + NULL); 1.2077 + } 1.2078 + JsrRecord* record = NULL; 1.2079 + int len = _jsr_records->length(); 1.2080 + for (int i = 0; i < len; i++) { 1.2081 + JsrRecord* record = _jsr_records->at(i); 1.2082 + if (record->entry_address() == entry_address && 1.2083 + record->return_address() == return_address) { 1.2084 + return record; 1.2085 + } 1.2086 + } 1.2087 + 1.2088 + record = new (arena()) JsrRecord(entry_address, return_address); 1.2089 + _jsr_records->append(record); 1.2090 + return record; 1.2091 +} 1.2092 + 1.2093 +// ------------------------------------------------------------------ 1.2094 +// ciTypeFlow::flow_exceptions 1.2095 +// 1.2096 +// Merge the current state into all exceptional successors at the 1.2097 +// current point in the code. 1.2098 +void ciTypeFlow::flow_exceptions(GrowableArray<ciTypeFlow::Block*>* exceptions, 1.2099 + GrowableArray<ciInstanceKlass*>* exc_klasses, 1.2100 + ciTypeFlow::StateVector* state) { 1.2101 + int len = exceptions->length(); 1.2102 + assert(exc_klasses->length() == len, "must have same length"); 1.2103 + for (int i = 0; i < len; i++) { 1.2104 + Block* block = exceptions->at(i); 1.2105 + ciInstanceKlass* exception_klass = exc_klasses->at(i); 1.2106 + 1.2107 + if (!exception_klass->is_loaded()) { 1.2108 + // Do not compile any code for unloaded exception types. 1.2109 + // Following compiler passes are responsible for doing this also. 1.2110 + continue; 1.2111 + } 1.2112 + 1.2113 + if (block->meet_exception(exception_klass, state)) { 1.2114 + // Block was modified and has PO. Add it to the work list. 1.2115 + if (block->has_post_order() && 1.2116 + !block->is_on_work_list()) { 1.2117 + add_to_work_list(block); 1.2118 + } 1.2119 + } 1.2120 + } 1.2121 +} 1.2122 + 1.2123 +// ------------------------------------------------------------------ 1.2124 +// ciTypeFlow::flow_successors 1.2125 +// 1.2126 +// Merge the current state into all successors at the current point 1.2127 +// in the code. 1.2128 +void ciTypeFlow::flow_successors(GrowableArray<ciTypeFlow::Block*>* successors, 1.2129 + ciTypeFlow::StateVector* state) { 1.2130 + int len = successors->length(); 1.2131 + for (int i = 0; i < len; i++) { 1.2132 + Block* block = successors->at(i); 1.2133 + if (block->meet(state)) { 1.2134 + // Block was modified and has PO. Add it to the work list. 1.2135 + if (block->has_post_order() && 1.2136 + !block->is_on_work_list()) { 1.2137 + add_to_work_list(block); 1.2138 + } 1.2139 + } 1.2140 + } 1.2141 +} 1.2142 + 1.2143 +// ------------------------------------------------------------------ 1.2144 +// ciTypeFlow::can_trap 1.2145 +// 1.2146 +// Tells if a given instruction is able to generate an exception edge. 1.2147 +bool ciTypeFlow::can_trap(ciBytecodeStream& str) { 1.2148 + // Cf. GenerateOopMap::do_exception_edge. 1.2149 + if (!Bytecodes::can_trap(str.cur_bc())) return false; 1.2150 + 1.2151 + switch (str.cur_bc()) { 1.2152 + // %%% FIXME: ldc of Class can generate an exception 1.2153 + case Bytecodes::_ldc: 1.2154 + case Bytecodes::_ldc_w: 1.2155 + case Bytecodes::_ldc2_w: 1.2156 + case Bytecodes::_aload_0: 1.2157 + // These bytecodes can trap for rewriting. We need to assume that 1.2158 + // they do not throw exceptions to make the monitor analysis work. 1.2159 + return false; 1.2160 + 1.2161 + case Bytecodes::_ireturn: 1.2162 + case Bytecodes::_lreturn: 1.2163 + case Bytecodes::_freturn: 1.2164 + case Bytecodes::_dreturn: 1.2165 + case Bytecodes::_areturn: 1.2166 + case Bytecodes::_return: 1.2167 + // We can assume the monitor stack is empty in this analysis. 1.2168 + return false; 1.2169 + 1.2170 + case Bytecodes::_monitorexit: 1.2171 + // We can assume monitors are matched in this analysis. 1.2172 + return false; 1.2173 + } 1.2174 + 1.2175 + return true; 1.2176 +} 1.2177 + 1.2178 +// ------------------------------------------------------------------ 1.2179 +// ciTypeFlow::clone_loop_heads 1.2180 +// 1.2181 +// Clone the loop heads 1.2182 +bool ciTypeFlow::clone_loop_heads(Loop* lp, StateVector* temp_vector, JsrSet* temp_set) { 1.2183 + bool rslt = false; 1.2184 + for (PreorderLoops iter(loop_tree_root()); !iter.done(); iter.next()) { 1.2185 + lp = iter.current(); 1.2186 + Block* head = lp->head(); 1.2187 + if (lp == loop_tree_root() || 1.2188 + lp->is_irreducible() || 1.2189 + !head->is_clonable_exit(lp)) 1.2190 + continue; 1.2191 + 1.2192 + // Avoid BoxLock merge. 1.2193 + if (EliminateNestedLocks && head->has_monitorenter()) 1.2194 + continue; 1.2195 + 1.2196 + // check not already cloned 1.2197 + if (head->backedge_copy_count() != 0) 1.2198 + continue; 1.2199 + 1.2200 + // Don't clone head of OSR loop to get correct types in start block. 1.2201 + if (is_osr_flow() && head->start() == start_bci()) 1.2202 + continue; 1.2203 + 1.2204 + // check _no_ shared head below us 1.2205 + Loop* ch; 1.2206 + for (ch = lp->child(); ch != NULL && ch->head() != head; ch = ch->sibling()); 1.2207 + if (ch != NULL) 1.2208 + continue; 1.2209 + 1.2210 + // Clone head 1.2211 + Block* new_head = head->looping_succ(lp); 1.2212 + Block* clone = clone_loop_head(lp, temp_vector, temp_set); 1.2213 + // Update lp's info 1.2214 + clone->set_loop(lp); 1.2215 + lp->set_head(new_head); 1.2216 + lp->set_tail(clone); 1.2217 + // And move original head into outer loop 1.2218 + head->set_loop(lp->parent()); 1.2219 + 1.2220 + rslt = true; 1.2221 + } 1.2222 + return rslt; 1.2223 +} 1.2224 + 1.2225 +// ------------------------------------------------------------------ 1.2226 +// ciTypeFlow::clone_loop_head 1.2227 +// 1.2228 +// Clone lp's head and replace tail's successors with clone. 1.2229 +// 1.2230 +// | 1.2231 +// v 1.2232 +// head <-> body 1.2233 +// | 1.2234 +// v 1.2235 +// exit 1.2236 +// 1.2237 +// new_head 1.2238 +// 1.2239 +// | 1.2240 +// v 1.2241 +// head ----------\ 1.2242 +// | | 1.2243 +// | v 1.2244 +// | clone <-> body 1.2245 +// | | 1.2246 +// | /--/ 1.2247 +// | | 1.2248 +// v v 1.2249 +// exit 1.2250 +// 1.2251 +ciTypeFlow::Block* ciTypeFlow::clone_loop_head(Loop* lp, StateVector* temp_vector, JsrSet* temp_set) { 1.2252 + Block* head = lp->head(); 1.2253 + Block* tail = lp->tail(); 1.2254 + if (CITraceTypeFlow) { 1.2255 + tty->print(">> Requesting clone of loop head "); head->print_value_on(tty); 1.2256 + tty->print(" for predecessor "); tail->print_value_on(tty); 1.2257 + tty->cr(); 1.2258 + } 1.2259 + Block* clone = block_at(head->start(), head->jsrs(), create_backedge_copy); 1.2260 + assert(clone->backedge_copy_count() == 1, "one backedge copy for all back edges"); 1.2261 + 1.2262 + assert(!clone->has_pre_order(), "just created"); 1.2263 + clone->set_next_pre_order(); 1.2264 + 1.2265 + // Insert clone after (orig) tail in reverse post order 1.2266 + clone->set_rpo_next(tail->rpo_next()); 1.2267 + tail->set_rpo_next(clone); 1.2268 + 1.2269 + // tail->head becomes tail->clone 1.2270 + for (SuccIter iter(tail); !iter.done(); iter.next()) { 1.2271 + if (iter.succ() == head) { 1.2272 + iter.set_succ(clone); 1.2273 + } 1.2274 + } 1.2275 + flow_block(tail, temp_vector, temp_set); 1.2276 + if (head == tail) { 1.2277 + // For self-loops, clone->head becomes clone->clone 1.2278 + flow_block(clone, temp_vector, temp_set); 1.2279 + for (SuccIter iter(clone); !iter.done(); iter.next()) { 1.2280 + if (iter.succ() == head) { 1.2281 + iter.set_succ(clone); 1.2282 + break; 1.2283 + } 1.2284 + } 1.2285 + } 1.2286 + flow_block(clone, temp_vector, temp_set); 1.2287 + 1.2288 + return clone; 1.2289 +} 1.2290 + 1.2291 +// ------------------------------------------------------------------ 1.2292 +// ciTypeFlow::flow_block 1.2293 +// 1.2294 +// Interpret the effects of the bytecodes on the incoming state 1.2295 +// vector of a basic block. Push the changed state to succeeding 1.2296 +// basic blocks. 1.2297 +void ciTypeFlow::flow_block(ciTypeFlow::Block* block, 1.2298 + ciTypeFlow::StateVector* state, 1.2299 + ciTypeFlow::JsrSet* jsrs) { 1.2300 + if (CITraceTypeFlow) { 1.2301 + tty->print("\n>> ANALYZING BLOCK : "); 1.2302 + tty->cr(); 1.2303 + block->print_on(tty); 1.2304 + } 1.2305 + assert(block->has_pre_order(), "pre-order is assigned before 1st flow"); 1.2306 + 1.2307 + int start = block->start(); 1.2308 + int limit = block->limit(); 1.2309 + int control = block->control(); 1.2310 + if (control != ciBlock::fall_through_bci) { 1.2311 + limit = control; 1.2312 + } 1.2313 + 1.2314 + // Grab the state from the current block. 1.2315 + block->copy_state_into(state); 1.2316 + state->def_locals()->clear(); 1.2317 + 1.2318 + GrowableArray<Block*>* exceptions = block->exceptions(); 1.2319 + GrowableArray<ciInstanceKlass*>* exc_klasses = block->exc_klasses(); 1.2320 + bool has_exceptions = exceptions->length() > 0; 1.2321 + 1.2322 + bool exceptions_used = false; 1.2323 + 1.2324 + ciBytecodeStream str(method()); 1.2325 + str.reset_to_bci(start); 1.2326 + Bytecodes::Code code; 1.2327 + while ((code = str.next()) != ciBytecodeStream::EOBC() && 1.2328 + str.cur_bci() < limit) { 1.2329 + // Check for exceptional control flow from this point. 1.2330 + if (has_exceptions && can_trap(str)) { 1.2331 + flow_exceptions(exceptions, exc_klasses, state); 1.2332 + exceptions_used = true; 1.2333 + } 1.2334 + // Apply the effects of the current bytecode to our state. 1.2335 + bool res = state->apply_one_bytecode(&str); 1.2336 + 1.2337 + // Watch for bailouts. 1.2338 + if (failing()) return; 1.2339 + 1.2340 + if (str.cur_bc() == Bytecodes::_monitorenter) { 1.2341 + block->set_has_monitorenter(); 1.2342 + } 1.2343 + 1.2344 + if (res) { 1.2345 + 1.2346 + // We have encountered a trap. Record it in this block. 1.2347 + block->set_trap(state->trap_bci(), state->trap_index()); 1.2348 + 1.2349 + if (CITraceTypeFlow) { 1.2350 + tty->print_cr(">> Found trap"); 1.2351 + block->print_on(tty); 1.2352 + } 1.2353 + 1.2354 + // Save set of locals defined in this block 1.2355 + block->def_locals()->add(state->def_locals()); 1.2356 + 1.2357 + // Record (no) successors. 1.2358 + block->successors(&str, state, jsrs); 1.2359 + 1.2360 + assert(!has_exceptions || exceptions_used, "Not removing exceptions"); 1.2361 + 1.2362 + // Discontinue interpretation of this Block. 1.2363 + return; 1.2364 + } 1.2365 + } 1.2366 + 1.2367 + GrowableArray<Block*>* successors = NULL; 1.2368 + if (control != ciBlock::fall_through_bci) { 1.2369 + // Check for exceptional control flow from this point. 1.2370 + if (has_exceptions && can_trap(str)) { 1.2371 + flow_exceptions(exceptions, exc_klasses, state); 1.2372 + exceptions_used = true; 1.2373 + } 1.2374 + 1.2375 + // Fix the JsrSet to reflect effect of the bytecode. 1.2376 + block->copy_jsrs_into(jsrs); 1.2377 + jsrs->apply_control(this, &str, state); 1.2378 + 1.2379 + // Find successor edges based on old state and new JsrSet. 1.2380 + successors = block->successors(&str, state, jsrs); 1.2381 + 1.2382 + // Apply the control changes to the state. 1.2383 + state->apply_one_bytecode(&str); 1.2384 + } else { 1.2385 + // Fall through control 1.2386 + successors = block->successors(&str, NULL, NULL); 1.2387 + } 1.2388 + 1.2389 + // Save set of locals defined in this block 1.2390 + block->def_locals()->add(state->def_locals()); 1.2391 + 1.2392 + // Remove untaken exception paths 1.2393 + if (!exceptions_used) 1.2394 + exceptions->clear(); 1.2395 + 1.2396 + // Pass our state to successors. 1.2397 + flow_successors(successors, state); 1.2398 +} 1.2399 + 1.2400 +// ------------------------------------------------------------------ 1.2401 +// ciTypeFlow::PostOrderLoops::next 1.2402 +// 1.2403 +// Advance to next loop tree using a postorder, left-to-right traversal. 1.2404 +void ciTypeFlow::PostorderLoops::next() { 1.2405 + assert(!done(), "must not be done."); 1.2406 + if (_current->sibling() != NULL) { 1.2407 + _current = _current->sibling(); 1.2408 + while (_current->child() != NULL) { 1.2409 + _current = _current->child(); 1.2410 + } 1.2411 + } else { 1.2412 + _current = _current->parent(); 1.2413 + } 1.2414 +} 1.2415 + 1.2416 +// ------------------------------------------------------------------ 1.2417 +// ciTypeFlow::PreOrderLoops::next 1.2418 +// 1.2419 +// Advance to next loop tree using a preorder, left-to-right traversal. 1.2420 +void ciTypeFlow::PreorderLoops::next() { 1.2421 + assert(!done(), "must not be done."); 1.2422 + if (_current->child() != NULL) { 1.2423 + _current = _current->child(); 1.2424 + } else if (_current->sibling() != NULL) { 1.2425 + _current = _current->sibling(); 1.2426 + } else { 1.2427 + while (_current != _root && _current->sibling() == NULL) { 1.2428 + _current = _current->parent(); 1.2429 + } 1.2430 + if (_current == _root) { 1.2431 + _current = NULL; 1.2432 + assert(done(), "must be done."); 1.2433 + } else { 1.2434 + assert(_current->sibling() != NULL, "must be more to do"); 1.2435 + _current = _current->sibling(); 1.2436 + } 1.2437 + } 1.2438 +} 1.2439 + 1.2440 +// ------------------------------------------------------------------ 1.2441 +// ciTypeFlow::Loop::sorted_merge 1.2442 +// 1.2443 +// Merge the branch lp into this branch, sorting on the loop head 1.2444 +// pre_orders. Returns the leaf of the merged branch. 1.2445 +// Child and sibling pointers will be setup later. 1.2446 +// Sort is (looking from leaf towards the root) 1.2447 +// descending on primary key: loop head's pre_order, and 1.2448 +// ascending on secondary key: loop tail's pre_order. 1.2449 +ciTypeFlow::Loop* ciTypeFlow::Loop::sorted_merge(Loop* lp) { 1.2450 + Loop* leaf = this; 1.2451 + Loop* prev = NULL; 1.2452 + Loop* current = leaf; 1.2453 + while (lp != NULL) { 1.2454 + int lp_pre_order = lp->head()->pre_order(); 1.2455 + // Find insertion point for "lp" 1.2456 + while (current != NULL) { 1.2457 + if (current == lp) 1.2458 + return leaf; // Already in list 1.2459 + if (current->head()->pre_order() < lp_pre_order) 1.2460 + break; 1.2461 + if (current->head()->pre_order() == lp_pre_order && 1.2462 + current->tail()->pre_order() > lp->tail()->pre_order()) { 1.2463 + break; 1.2464 + } 1.2465 + prev = current; 1.2466 + current = current->parent(); 1.2467 + } 1.2468 + Loop* next_lp = lp->parent(); // Save future list of items to insert 1.2469 + // Insert lp before current 1.2470 + lp->set_parent(current); 1.2471 + if (prev != NULL) { 1.2472 + prev->set_parent(lp); 1.2473 + } else { 1.2474 + leaf = lp; 1.2475 + } 1.2476 + prev = lp; // Inserted item is new prev[ious] 1.2477 + lp = next_lp; // Next item to insert 1.2478 + } 1.2479 + return leaf; 1.2480 +} 1.2481 + 1.2482 +// ------------------------------------------------------------------ 1.2483 +// ciTypeFlow::build_loop_tree 1.2484 +// 1.2485 +// Incrementally build loop tree. 1.2486 +void ciTypeFlow::build_loop_tree(Block* blk) { 1.2487 + assert(!blk->is_post_visited(), "precondition"); 1.2488 + Loop* innermost = NULL; // merge of loop tree branches over all successors 1.2489 + 1.2490 + for (SuccIter iter(blk); !iter.done(); iter.next()) { 1.2491 + Loop* lp = NULL; 1.2492 + Block* succ = iter.succ(); 1.2493 + if (!succ->is_post_visited()) { 1.2494 + // Found backedge since predecessor post visited, but successor is not 1.2495 + assert(succ->pre_order() <= blk->pre_order(), "should be backedge"); 1.2496 + 1.2497 + // Create a LoopNode to mark this loop. 1.2498 + lp = new (arena()) Loop(succ, blk); 1.2499 + if (succ->loop() == NULL) 1.2500 + succ->set_loop(lp); 1.2501 + // succ->loop will be updated to innermost loop on a later call, when blk==succ 1.2502 + 1.2503 + } else { // Nested loop 1.2504 + lp = succ->loop(); 1.2505 + 1.2506 + // If succ is loop head, find outer loop. 1.2507 + while (lp != NULL && lp->head() == succ) { 1.2508 + lp = lp->parent(); 1.2509 + } 1.2510 + if (lp == NULL) { 1.2511 + // Infinite loop, it's parent is the root 1.2512 + lp = loop_tree_root(); 1.2513 + } 1.2514 + } 1.2515 + 1.2516 + // Check for irreducible loop. 1.2517 + // Successor has already been visited. If the successor's loop head 1.2518 + // has already been post-visited, then this is another entry into the loop. 1.2519 + while (lp->head()->is_post_visited() && lp != loop_tree_root()) { 1.2520 + _has_irreducible_entry = true; 1.2521 + lp->set_irreducible(succ); 1.2522 + if (!succ->is_on_work_list()) { 1.2523 + // Assume irreducible entries need more data flow 1.2524 + add_to_work_list(succ); 1.2525 + } 1.2526 + Loop* plp = lp->parent(); 1.2527 + if (plp == NULL) { 1.2528 + // This only happens for some irreducible cases. The parent 1.2529 + // will be updated during a later pass. 1.2530 + break; 1.2531 + } 1.2532 + lp = plp; 1.2533 + } 1.2534 + 1.2535 + // Merge loop tree branch for all successors. 1.2536 + innermost = innermost == NULL ? lp : innermost->sorted_merge(lp); 1.2537 + 1.2538 + } // end loop 1.2539 + 1.2540 + if (innermost == NULL) { 1.2541 + assert(blk->successors()->length() == 0, "CFG exit"); 1.2542 + blk->set_loop(loop_tree_root()); 1.2543 + } else if (innermost->head() == blk) { 1.2544 + // If loop header, complete the tree pointers 1.2545 + if (blk->loop() != innermost) { 1.2546 +#ifdef ASSERT 1.2547 + assert(blk->loop()->head() == innermost->head(), "same head"); 1.2548 + Loop* dl; 1.2549 + for (dl = innermost; dl != NULL && dl != blk->loop(); dl = dl->parent()); 1.2550 + assert(dl == blk->loop(), "blk->loop() already in innermost list"); 1.2551 +#endif 1.2552 + blk->set_loop(innermost); 1.2553 + } 1.2554 + innermost->def_locals()->add(blk->def_locals()); 1.2555 + Loop* l = innermost; 1.2556 + Loop* p = l->parent(); 1.2557 + while (p && l->head() == blk) { 1.2558 + l->set_sibling(p->child()); // Put self on parents 'next child' 1.2559 + p->set_child(l); // Make self the first child of parent 1.2560 + p->def_locals()->add(l->def_locals()); 1.2561 + l = p; // Walk up the parent chain 1.2562 + p = l->parent(); 1.2563 + } 1.2564 + } else { 1.2565 + blk->set_loop(innermost); 1.2566 + innermost->def_locals()->add(blk->def_locals()); 1.2567 + } 1.2568 +} 1.2569 + 1.2570 +// ------------------------------------------------------------------ 1.2571 +// ciTypeFlow::Loop::contains 1.2572 +// 1.2573 +// Returns true if lp is nested loop. 1.2574 +bool ciTypeFlow::Loop::contains(ciTypeFlow::Loop* lp) const { 1.2575 + assert(lp != NULL, ""); 1.2576 + if (this == lp || head() == lp->head()) return true; 1.2577 + int depth1 = depth(); 1.2578 + int depth2 = lp->depth(); 1.2579 + if (depth1 > depth2) 1.2580 + return false; 1.2581 + while (depth1 < depth2) { 1.2582 + depth2--; 1.2583 + lp = lp->parent(); 1.2584 + } 1.2585 + return this == lp; 1.2586 +} 1.2587 + 1.2588 +// ------------------------------------------------------------------ 1.2589 +// ciTypeFlow::Loop::depth 1.2590 +// 1.2591 +// Loop depth 1.2592 +int ciTypeFlow::Loop::depth() const { 1.2593 + int dp = 0; 1.2594 + for (Loop* lp = this->parent(); lp != NULL; lp = lp->parent()) 1.2595 + dp++; 1.2596 + return dp; 1.2597 +} 1.2598 + 1.2599 +#ifndef PRODUCT 1.2600 +// ------------------------------------------------------------------ 1.2601 +// ciTypeFlow::Loop::print 1.2602 +void ciTypeFlow::Loop::print(outputStream* st, int indent) const { 1.2603 + for (int i = 0; i < indent; i++) st->print(" "); 1.2604 + st->print("%d<-%d %s", 1.2605 + is_root() ? 0 : this->head()->pre_order(), 1.2606 + is_root() ? 0 : this->tail()->pre_order(), 1.2607 + is_irreducible()?" irr":""); 1.2608 + st->print(" defs: "); 1.2609 + def_locals()->print_on(st, _head->outer()->method()->max_locals()); 1.2610 + st->cr(); 1.2611 + for (Loop* ch = child(); ch != NULL; ch = ch->sibling()) 1.2612 + ch->print(st, indent+2); 1.2613 +} 1.2614 +#endif 1.2615 + 1.2616 +// ------------------------------------------------------------------ 1.2617 +// ciTypeFlow::df_flow_types 1.2618 +// 1.2619 +// Perform the depth first type flow analysis. Helper for flow_types. 1.2620 +void ciTypeFlow::df_flow_types(Block* start, 1.2621 + bool do_flow, 1.2622 + StateVector* temp_vector, 1.2623 + JsrSet* temp_set) { 1.2624 + int dft_len = 100; 1.2625 + GrowableArray<Block*> stk(dft_len); 1.2626 + 1.2627 + ciBlock* dummy = _methodBlocks->make_dummy_block(); 1.2628 + JsrSet* root_set = new JsrSet(NULL, 0); 1.2629 + Block* root_head = new (arena()) Block(this, dummy, root_set); 1.2630 + Block* root_tail = new (arena()) Block(this, dummy, root_set); 1.2631 + root_head->set_pre_order(0); 1.2632 + root_head->set_post_order(0); 1.2633 + root_tail->set_pre_order(max_jint); 1.2634 + root_tail->set_post_order(max_jint); 1.2635 + set_loop_tree_root(new (arena()) Loop(root_head, root_tail)); 1.2636 + 1.2637 + stk.push(start); 1.2638 + 1.2639 + _next_pre_order = 0; // initialize pre_order counter 1.2640 + _rpo_list = NULL; 1.2641 + int next_po = 0; // initialize post_order counter 1.2642 + 1.2643 + // Compute RPO and the control flow graph 1.2644 + int size; 1.2645 + while ((size = stk.length()) > 0) { 1.2646 + Block* blk = stk.top(); // Leave node on stack 1.2647 + if (!blk->is_visited()) { 1.2648 + // forward arc in graph 1.2649 + assert (!blk->has_pre_order(), ""); 1.2650 + blk->set_next_pre_order(); 1.2651 + 1.2652 + if (_next_pre_order >= MaxNodeLimit / 2) { 1.2653 + // Too many basic blocks. Bail out. 1.2654 + // This can happen when try/finally constructs are nested to depth N, 1.2655 + // and there is O(2**N) cloning of jsr bodies. See bug 4697245! 1.2656 + // "MaxNodeLimit / 2" is used because probably the parser will 1.2657 + // generate at least twice that many nodes and bail out. 1.2658 + record_failure("too many basic blocks"); 1.2659 + return; 1.2660 + } 1.2661 + if (do_flow) { 1.2662 + flow_block(blk, temp_vector, temp_set); 1.2663 + if (failing()) return; // Watch for bailouts. 1.2664 + } 1.2665 + } else if (!blk->is_post_visited()) { 1.2666 + // cross or back arc 1.2667 + for (SuccIter iter(blk); !iter.done(); iter.next()) { 1.2668 + Block* succ = iter.succ(); 1.2669 + if (!succ->is_visited()) { 1.2670 + stk.push(succ); 1.2671 + } 1.2672 + } 1.2673 + if (stk.length() == size) { 1.2674 + // There were no additional children, post visit node now 1.2675 + stk.pop(); // Remove node from stack 1.2676 + 1.2677 + build_loop_tree(blk); 1.2678 + blk->set_post_order(next_po++); // Assign post order 1.2679 + prepend_to_rpo_list(blk); 1.2680 + assert(blk->is_post_visited(), ""); 1.2681 + 1.2682 + if (blk->is_loop_head() && !blk->is_on_work_list()) { 1.2683 + // Assume loop heads need more data flow 1.2684 + add_to_work_list(blk); 1.2685 + } 1.2686 + } 1.2687 + } else { 1.2688 + stk.pop(); // Remove post-visited node from stack 1.2689 + } 1.2690 + } 1.2691 +} 1.2692 + 1.2693 +// ------------------------------------------------------------------ 1.2694 +// ciTypeFlow::flow_types 1.2695 +// 1.2696 +// Perform the type flow analysis, creating and cloning Blocks as 1.2697 +// necessary. 1.2698 +void ciTypeFlow::flow_types() { 1.2699 + ResourceMark rm; 1.2700 + StateVector* temp_vector = new StateVector(this); 1.2701 + JsrSet* temp_set = new JsrSet(NULL, 16); 1.2702 + 1.2703 + // Create the method entry block. 1.2704 + Block* start = block_at(start_bci(), temp_set); 1.2705 + 1.2706 + // Load the initial state into it. 1.2707 + const StateVector* start_state = get_start_state(); 1.2708 + if (failing()) return; 1.2709 + start->meet(start_state); 1.2710 + 1.2711 + // Depth first visit 1.2712 + df_flow_types(start, true /*do flow*/, temp_vector, temp_set); 1.2713 + 1.2714 + if (failing()) return; 1.2715 + assert(_rpo_list == start, "must be start"); 1.2716 + 1.2717 + // Any loops found? 1.2718 + if (loop_tree_root()->child() != NULL && 1.2719 + env()->comp_level() >= CompLevel_full_optimization) { 1.2720 + // Loop optimizations are not performed on Tier1 compiles. 1.2721 + 1.2722 + bool changed = clone_loop_heads(loop_tree_root(), temp_vector, temp_set); 1.2723 + 1.2724 + // If some loop heads were cloned, recompute postorder and loop tree 1.2725 + if (changed) { 1.2726 + loop_tree_root()->set_child(NULL); 1.2727 + for (Block* blk = _rpo_list; blk != NULL;) { 1.2728 + Block* next = blk->rpo_next(); 1.2729 + blk->df_init(); 1.2730 + blk = next; 1.2731 + } 1.2732 + df_flow_types(start, false /*no flow*/, temp_vector, temp_set); 1.2733 + } 1.2734 + } 1.2735 + 1.2736 + if (CITraceTypeFlow) { 1.2737 + tty->print_cr("\nLoop tree"); 1.2738 + loop_tree_root()->print(); 1.2739 + } 1.2740 + 1.2741 + // Continue flow analysis until fixed point reached 1.2742 + 1.2743 + debug_only(int max_block = _next_pre_order;) 1.2744 + 1.2745 + while (!work_list_empty()) { 1.2746 + Block* blk = work_list_next(); 1.2747 + assert (blk->has_post_order(), "post order assigned above"); 1.2748 + 1.2749 + flow_block(blk, temp_vector, temp_set); 1.2750 + 1.2751 + assert (max_block == _next_pre_order, "no new blocks"); 1.2752 + assert (!failing(), "no more bailouts"); 1.2753 + } 1.2754 +} 1.2755 + 1.2756 +// ------------------------------------------------------------------ 1.2757 +// ciTypeFlow::map_blocks 1.2758 +// 1.2759 +// Create the block map, which indexes blocks in reverse post-order. 1.2760 +void ciTypeFlow::map_blocks() { 1.2761 + assert(_block_map == NULL, "single initialization"); 1.2762 + int block_ct = _next_pre_order; 1.2763 + _block_map = NEW_ARENA_ARRAY(arena(), Block*, block_ct); 1.2764 + assert(block_ct == block_count(), ""); 1.2765 + 1.2766 + Block* blk = _rpo_list; 1.2767 + for (int m = 0; m < block_ct; m++) { 1.2768 + int rpo = blk->rpo(); 1.2769 + assert(rpo == m, "should be sequential"); 1.2770 + _block_map[rpo] = blk; 1.2771 + blk = blk->rpo_next(); 1.2772 + } 1.2773 + assert(blk == NULL, "should be done"); 1.2774 + 1.2775 + for (int j = 0; j < block_ct; j++) { 1.2776 + assert(_block_map[j] != NULL, "must not drop any blocks"); 1.2777 + Block* block = _block_map[j]; 1.2778 + // Remove dead blocks from successor lists: 1.2779 + for (int e = 0; e <= 1; e++) { 1.2780 + GrowableArray<Block*>* l = e? block->exceptions(): block->successors(); 1.2781 + for (int k = 0; k < l->length(); k++) { 1.2782 + Block* s = l->at(k); 1.2783 + if (!s->has_post_order()) { 1.2784 + if (CITraceTypeFlow) { 1.2785 + tty->print("Removing dead %s successor of #%d: ", (e? "exceptional": "normal"), block->pre_order()); 1.2786 + s->print_value_on(tty); 1.2787 + tty->cr(); 1.2788 + } 1.2789 + l->remove(s); 1.2790 + --k; 1.2791 + } 1.2792 + } 1.2793 + } 1.2794 + } 1.2795 +} 1.2796 + 1.2797 +// ------------------------------------------------------------------ 1.2798 +// ciTypeFlow::get_block_for 1.2799 +// 1.2800 +// Find a block with this ciBlock which has a compatible JsrSet. 1.2801 +// If no such block exists, create it, unless the option is no_create. 1.2802 +// If the option is create_backedge_copy, always create a fresh backedge copy. 1.2803 +ciTypeFlow::Block* ciTypeFlow::get_block_for(int ciBlockIndex, ciTypeFlow::JsrSet* jsrs, CreateOption option) { 1.2804 + Arena* a = arena(); 1.2805 + GrowableArray<Block*>* blocks = _idx_to_blocklist[ciBlockIndex]; 1.2806 + if (blocks == NULL) { 1.2807 + // Query only? 1.2808 + if (option == no_create) return NULL; 1.2809 + 1.2810 + // Allocate the growable array. 1.2811 + blocks = new (a) GrowableArray<Block*>(a, 4, 0, NULL); 1.2812 + _idx_to_blocklist[ciBlockIndex] = blocks; 1.2813 + } 1.2814 + 1.2815 + if (option != create_backedge_copy) { 1.2816 + int len = blocks->length(); 1.2817 + for (int i = 0; i < len; i++) { 1.2818 + Block* block = blocks->at(i); 1.2819 + if (!block->is_backedge_copy() && block->is_compatible_with(jsrs)) { 1.2820 + return block; 1.2821 + } 1.2822 + } 1.2823 + } 1.2824 + 1.2825 + // Query only? 1.2826 + if (option == no_create) return NULL; 1.2827 + 1.2828 + // We did not find a compatible block. Create one. 1.2829 + Block* new_block = new (a) Block(this, _methodBlocks->block(ciBlockIndex), jsrs); 1.2830 + if (option == create_backedge_copy) new_block->set_backedge_copy(true); 1.2831 + blocks->append(new_block); 1.2832 + return new_block; 1.2833 +} 1.2834 + 1.2835 +// ------------------------------------------------------------------ 1.2836 +// ciTypeFlow::backedge_copy_count 1.2837 +// 1.2838 +int ciTypeFlow::backedge_copy_count(int ciBlockIndex, ciTypeFlow::JsrSet* jsrs) const { 1.2839 + GrowableArray<Block*>* blocks = _idx_to_blocklist[ciBlockIndex]; 1.2840 + 1.2841 + if (blocks == NULL) { 1.2842 + return 0; 1.2843 + } 1.2844 + 1.2845 + int count = 0; 1.2846 + int len = blocks->length(); 1.2847 + for (int i = 0; i < len; i++) { 1.2848 + Block* block = blocks->at(i); 1.2849 + if (block->is_backedge_copy() && block->is_compatible_with(jsrs)) { 1.2850 + count++; 1.2851 + } 1.2852 + } 1.2853 + 1.2854 + return count; 1.2855 +} 1.2856 + 1.2857 +// ------------------------------------------------------------------ 1.2858 +// ciTypeFlow::do_flow 1.2859 +// 1.2860 +// Perform type inference flow analysis. 1.2861 +void ciTypeFlow::do_flow() { 1.2862 + if (CITraceTypeFlow) { 1.2863 + tty->print_cr("\nPerforming flow analysis on method"); 1.2864 + method()->print(); 1.2865 + if (is_osr_flow()) tty->print(" at OSR bci %d", start_bci()); 1.2866 + tty->cr(); 1.2867 + method()->print_codes(); 1.2868 + } 1.2869 + if (CITraceTypeFlow) { 1.2870 + tty->print_cr("Initial CI Blocks"); 1.2871 + print_on(tty); 1.2872 + } 1.2873 + flow_types(); 1.2874 + // Watch for bailouts. 1.2875 + if (failing()) { 1.2876 + return; 1.2877 + } 1.2878 + 1.2879 + map_blocks(); 1.2880 + 1.2881 + if (CIPrintTypeFlow || CITraceTypeFlow) { 1.2882 + rpo_print_on(tty); 1.2883 + } 1.2884 +} 1.2885 + 1.2886 +// ------------------------------------------------------------------ 1.2887 +// ciTypeFlow::record_failure() 1.2888 +// The ciTypeFlow object keeps track of failure reasons separately from the ciEnv. 1.2889 +// This is required because there is not a 1-1 relation between the ciEnv and 1.2890 +// the TypeFlow passes within a compilation task. For example, if the compiler 1.2891 +// is considering inlining a method, it will request a TypeFlow. If that fails, 1.2892 +// the compilation as a whole may continue without the inlining. Some TypeFlow 1.2893 +// requests are not optional; if they fail the requestor is responsible for 1.2894 +// copying the failure reason up to the ciEnv. (See Parse::Parse.) 1.2895 +void ciTypeFlow::record_failure(const char* reason) { 1.2896 + if (env()->log() != NULL) { 1.2897 + env()->log()->elem("failure reason='%s' phase='typeflow'", reason); 1.2898 + } 1.2899 + if (_failure_reason == NULL) { 1.2900 + // Record the first failure reason. 1.2901 + _failure_reason = reason; 1.2902 + } 1.2903 +} 1.2904 + 1.2905 +#ifndef PRODUCT 1.2906 +// ------------------------------------------------------------------ 1.2907 +// ciTypeFlow::print_on 1.2908 +void ciTypeFlow::print_on(outputStream* st) const { 1.2909 + // Walk through CI blocks 1.2910 + st->print_cr("********************************************************"); 1.2911 + st->print ("TypeFlow for "); 1.2912 + method()->name()->print_symbol_on(st); 1.2913 + int limit_bci = code_size(); 1.2914 + st->print_cr(" %d bytes", limit_bci); 1.2915 + ciMethodBlocks *mblks = _methodBlocks; 1.2916 + ciBlock* current = NULL; 1.2917 + for (int bci = 0; bci < limit_bci; bci++) { 1.2918 + ciBlock* blk = mblks->block_containing(bci); 1.2919 + if (blk != NULL && blk != current) { 1.2920 + current = blk; 1.2921 + current->print_on(st); 1.2922 + 1.2923 + GrowableArray<Block*>* blocks = _idx_to_blocklist[blk->index()]; 1.2924 + int num_blocks = (blocks == NULL) ? 0 : blocks->length(); 1.2925 + 1.2926 + if (num_blocks == 0) { 1.2927 + st->print_cr(" No Blocks"); 1.2928 + } else { 1.2929 + for (int i = 0; i < num_blocks; i++) { 1.2930 + Block* block = blocks->at(i); 1.2931 + block->print_on(st); 1.2932 + } 1.2933 + } 1.2934 + st->print_cr("--------------------------------------------------------"); 1.2935 + st->cr(); 1.2936 + } 1.2937 + } 1.2938 + st->print_cr("********************************************************"); 1.2939 + st->cr(); 1.2940 +} 1.2941 + 1.2942 +void ciTypeFlow::rpo_print_on(outputStream* st) const { 1.2943 + st->print_cr("********************************************************"); 1.2944 + st->print ("TypeFlow for "); 1.2945 + method()->name()->print_symbol_on(st); 1.2946 + int limit_bci = code_size(); 1.2947 + st->print_cr(" %d bytes", limit_bci); 1.2948 + for (Block* blk = _rpo_list; blk != NULL; blk = blk->rpo_next()) { 1.2949 + blk->print_on(st); 1.2950 + st->print_cr("--------------------------------------------------------"); 1.2951 + st->cr(); 1.2952 + } 1.2953 + st->print_cr("********************************************************"); 1.2954 + st->cr(); 1.2955 +} 1.2956 +#endif