src/share/vm/ci/ciTypeFlow.hpp

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 435
a61af66fc99e
child 738
fa4d1d240383
permissions
-rw-r--r--

Initial load

duke@435 1 /*
duke@435 2 * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25
duke@435 26 class ciTypeFlow : public ResourceObj {
duke@435 27 private:
duke@435 28 ciEnv* _env;
duke@435 29 ciMethod* _method;
duke@435 30 ciMethodBlocks* _methodBlocks;
duke@435 31 int _osr_bci;
duke@435 32
duke@435 33 // information cached from the method:
duke@435 34 int _max_locals;
duke@435 35 int _max_stack;
duke@435 36 int _code_size;
duke@435 37
duke@435 38 const char* _failure_reason;
duke@435 39
duke@435 40 public:
duke@435 41 class StateVector;
duke@435 42 class Block;
duke@435 43
duke@435 44 // Build a type flow analyzer
duke@435 45 // Do an OSR analysis if osr_bci >= 0.
duke@435 46 ciTypeFlow(ciEnv* env, ciMethod* method, int osr_bci = InvocationEntryBci);
duke@435 47
duke@435 48 // Accessors
duke@435 49 ciMethod* method() const { return _method; }
duke@435 50 ciEnv* env() { return _env; }
duke@435 51 Arena* arena() { return _env->arena(); }
duke@435 52 bool is_osr_flow() const{ return _osr_bci != InvocationEntryBci; }
duke@435 53 int start_bci() const { return is_osr_flow()? _osr_bci: 0; }
duke@435 54 int max_locals() const { return _max_locals; }
duke@435 55 int max_stack() const { return _max_stack; }
duke@435 56 int max_cells() const { return _max_locals + _max_stack; }
duke@435 57 int code_size() const { return _code_size; }
duke@435 58
duke@435 59 // Represents information about an "active" jsr call. This
duke@435 60 // class represents a call to the routine at some entry address
duke@435 61 // with some distinct return address.
duke@435 62 class JsrRecord : public ResourceObj {
duke@435 63 private:
duke@435 64 int _entry_address;
duke@435 65 int _return_address;
duke@435 66 public:
duke@435 67 JsrRecord(int entry_address, int return_address) {
duke@435 68 _entry_address = entry_address;
duke@435 69 _return_address = return_address;
duke@435 70 }
duke@435 71
duke@435 72 int entry_address() const { return _entry_address; }
duke@435 73 int return_address() const { return _return_address; }
duke@435 74
duke@435 75 void print_on(outputStream* st) const {
duke@435 76 #ifndef PRODUCT
duke@435 77 st->print("%d->%d", entry_address(), return_address());
duke@435 78 #endif
duke@435 79 }
duke@435 80 };
duke@435 81
duke@435 82 // A JsrSet represents some set of JsrRecords. This class
duke@435 83 // is used to record a set of all jsr routines which we permit
duke@435 84 // execution to return (ret) from.
duke@435 85 //
duke@435 86 // During abstract interpretation, JsrSets are used to determine
duke@435 87 // whether two paths which reach a given block are unique, and
duke@435 88 // should be cloned apart, or are compatible, and should merge
duke@435 89 // together.
duke@435 90 //
duke@435 91 // Note that different amounts of effort can be expended determining
duke@435 92 // if paths are compatible. <DISCUSSION>
duke@435 93 class JsrSet : public ResourceObj {
duke@435 94 private:
duke@435 95 GrowableArray<JsrRecord*>* _set;
duke@435 96
duke@435 97 JsrRecord* record_at(int i) {
duke@435 98 return _set->at(i);
duke@435 99 }
duke@435 100
duke@435 101 // Insert the given JsrRecord into the JsrSet, maintaining the order
duke@435 102 // of the set and replacing any element with the same entry address.
duke@435 103 void insert_jsr_record(JsrRecord* record);
duke@435 104
duke@435 105 // Remove the JsrRecord with the given return address from the JsrSet.
duke@435 106 void remove_jsr_record(int return_address);
duke@435 107
duke@435 108 public:
duke@435 109 JsrSet(Arena* arena, int default_len = 4);
duke@435 110
duke@435 111 // Copy this JsrSet.
duke@435 112 void copy_into(JsrSet* jsrs);
duke@435 113
duke@435 114 // Is this JsrSet compatible with some other JsrSet?
duke@435 115 bool is_compatible_with(JsrSet* other);
duke@435 116
duke@435 117 // Apply the effect of a single bytecode to the JsrSet.
duke@435 118 void apply_control(ciTypeFlow* analyzer,
duke@435 119 ciBytecodeStream* str,
duke@435 120 StateVector* state);
duke@435 121
duke@435 122 // What is the cardinality of this set?
duke@435 123 int size() const { return _set->length(); }
duke@435 124
duke@435 125 void print_on(outputStream* st) const PRODUCT_RETURN;
duke@435 126 };
duke@435 127
duke@435 128 // Used as a combined index for locals and temps
duke@435 129 enum Cell {
duke@435 130 Cell_0
duke@435 131 };
duke@435 132
duke@435 133 // A StateVector summarizes the type information at some
duke@435 134 // point in the program
duke@435 135 class StateVector : public ResourceObj {
duke@435 136 private:
duke@435 137 ciType** _types;
duke@435 138 int _stack_size;
duke@435 139 int _monitor_count;
duke@435 140 ciTypeFlow* _outer;
duke@435 141
duke@435 142 int _trap_bci;
duke@435 143 int _trap_index;
duke@435 144
duke@435 145 static ciType* type_meet_internal(ciType* t1, ciType* t2, ciTypeFlow* analyzer);
duke@435 146
duke@435 147 public:
duke@435 148 // Special elements in our type lattice.
duke@435 149 enum {
duke@435 150 T_TOP = T_VOID, // why not?
duke@435 151 T_BOTTOM = T_CONFLICT,
duke@435 152 T_LONG2 = T_SHORT, // 2nd word of T_LONG
duke@435 153 T_DOUBLE2 = T_CHAR, // 2nd word of T_DOUBLE
duke@435 154 T_NULL = T_BYTE // for now.
duke@435 155 };
duke@435 156 static ciType* top_type() { return ciType::make((BasicType)T_TOP); }
duke@435 157 static ciType* bottom_type() { return ciType::make((BasicType)T_BOTTOM); }
duke@435 158 static ciType* long2_type() { return ciType::make((BasicType)T_LONG2); }
duke@435 159 static ciType* double2_type(){ return ciType::make((BasicType)T_DOUBLE2); }
duke@435 160 static ciType* null_type() { return ciType::make((BasicType)T_NULL); }
duke@435 161
duke@435 162 static ciType* half_type(ciType* t) {
duke@435 163 switch (t->basic_type()) {
duke@435 164 case T_LONG: return long2_type();
duke@435 165 case T_DOUBLE: return double2_type();
duke@435 166 default: ShouldNotReachHere(); return NULL;
duke@435 167 }
duke@435 168 }
duke@435 169
duke@435 170 // The meet operation for our type lattice.
duke@435 171 ciType* type_meet(ciType* t1, ciType* t2) {
duke@435 172 return type_meet_internal(t1, t2, outer());
duke@435 173 }
duke@435 174
duke@435 175 // Accessors
duke@435 176 ciTypeFlow* outer() const { return _outer; }
duke@435 177
duke@435 178 int stack_size() const { return _stack_size; }
duke@435 179 void set_stack_size(int ss) { _stack_size = ss; }
duke@435 180
duke@435 181 int monitor_count() const { return _monitor_count; }
duke@435 182 void set_monitor_count(int mc) { _monitor_count = mc; }
duke@435 183
duke@435 184 static Cell start_cell() { return (Cell)0; }
duke@435 185 static Cell next_cell(Cell c) { return (Cell)(((int)c) + 1); }
duke@435 186 Cell limit_cell() const {
duke@435 187 return (Cell)(outer()->max_locals() + stack_size());
duke@435 188 }
duke@435 189
duke@435 190 // Cell creation
duke@435 191 Cell local(int lnum) const {
duke@435 192 assert(lnum < outer()->max_locals(), "index check");
duke@435 193 return (Cell)(lnum);
duke@435 194 }
duke@435 195
duke@435 196 Cell stack(int snum) const {
duke@435 197 assert(snum < stack_size(), "index check");
duke@435 198 return (Cell)(outer()->max_locals() + snum);
duke@435 199 }
duke@435 200
duke@435 201 Cell tos() const { return stack(stack_size()-1); }
duke@435 202
duke@435 203 // For external use only:
duke@435 204 ciType* local_type_at(int i) const { return type_at(local(i)); }
duke@435 205 ciType* stack_type_at(int i) const { return type_at(stack(i)); }
duke@435 206
duke@435 207 // Accessors for the type of some Cell c
duke@435 208 ciType* type_at(Cell c) const {
duke@435 209 assert(start_cell() <= c && c < limit_cell(), "out of bounds");
duke@435 210 return _types[c];
duke@435 211 }
duke@435 212
duke@435 213 void set_type_at(Cell c, ciType* type) {
duke@435 214 assert(start_cell() <= c && c < limit_cell(), "out of bounds");
duke@435 215 _types[c] = type;
duke@435 216 }
duke@435 217
duke@435 218 // Top-of-stack operations.
duke@435 219 void set_type_at_tos(ciType* type) { set_type_at(tos(), type); }
duke@435 220 ciType* type_at_tos() const { return type_at(tos()); }
duke@435 221
duke@435 222 void push(ciType* type) {
duke@435 223 _stack_size++;
duke@435 224 set_type_at_tos(type);
duke@435 225 }
duke@435 226 void pop() {
duke@435 227 debug_only(set_type_at_tos(bottom_type()));
duke@435 228 _stack_size--;
duke@435 229 }
duke@435 230 ciType* pop_value() {
duke@435 231 ciType* t = type_at_tos();
duke@435 232 pop();
duke@435 233 return t;
duke@435 234 }
duke@435 235
duke@435 236 // Convenience operations.
duke@435 237 bool is_reference(ciType* type) const {
duke@435 238 return type == null_type() || !type->is_primitive_type();
duke@435 239 }
duke@435 240 bool is_int(ciType* type) const {
duke@435 241 return type->basic_type() == T_INT;
duke@435 242 }
duke@435 243 bool is_long(ciType* type) const {
duke@435 244 return type->basic_type() == T_LONG;
duke@435 245 }
duke@435 246 bool is_float(ciType* type) const {
duke@435 247 return type->basic_type() == T_FLOAT;
duke@435 248 }
duke@435 249 bool is_double(ciType* type) const {
duke@435 250 return type->basic_type() == T_DOUBLE;
duke@435 251 }
duke@435 252
duke@435 253 void push_translate(ciType* type);
duke@435 254
duke@435 255 void push_int() {
duke@435 256 push(ciType::make(T_INT));
duke@435 257 }
duke@435 258 void pop_int() {
duke@435 259 assert(is_int(type_at_tos()), "must be integer");
duke@435 260 pop();
duke@435 261 }
duke@435 262 void check_int(Cell c) {
duke@435 263 assert(is_int(type_at(c)), "must be integer");
duke@435 264 }
duke@435 265 void push_double() {
duke@435 266 push(ciType::make(T_DOUBLE));
duke@435 267 push(double2_type());
duke@435 268 }
duke@435 269 void pop_double() {
duke@435 270 assert(type_at_tos() == double2_type(), "must be 2nd half");
duke@435 271 pop();
duke@435 272 assert(is_double(type_at_tos()), "must be double");
duke@435 273 pop();
duke@435 274 }
duke@435 275 void push_float() {
duke@435 276 push(ciType::make(T_FLOAT));
duke@435 277 }
duke@435 278 void pop_float() {
duke@435 279 assert(is_float(type_at_tos()), "must be float");
duke@435 280 pop();
duke@435 281 }
duke@435 282 void push_long() {
duke@435 283 push(ciType::make(T_LONG));
duke@435 284 push(long2_type());
duke@435 285 }
duke@435 286 void pop_long() {
duke@435 287 assert(type_at_tos() == long2_type(), "must be 2nd half");
duke@435 288 pop();
duke@435 289 assert(is_long(type_at_tos()), "must be long");
duke@435 290 pop();
duke@435 291 }
duke@435 292 void push_object(ciKlass* klass) {
duke@435 293 push(klass);
duke@435 294 }
duke@435 295 void pop_object() {
duke@435 296 assert(is_reference(type_at_tos()), "must be reference type");
duke@435 297 pop();
duke@435 298 }
duke@435 299 void pop_array() {
duke@435 300 assert(type_at_tos() == null_type() ||
duke@435 301 type_at_tos()->is_array_klass(), "must be array type");
duke@435 302 pop();
duke@435 303 }
duke@435 304 // pop_objArray and pop_typeArray narrow the tos to ciObjArrayKlass
duke@435 305 // or ciTypeArrayKlass (resp.). In the rare case that an explicit
duke@435 306 // null is popped from the stack, we return NULL. Caller beware.
duke@435 307 ciObjArrayKlass* pop_objArray() {
duke@435 308 ciType* array = pop_value();
duke@435 309 if (array == null_type()) return NULL;
duke@435 310 assert(array->is_obj_array_klass(), "must be object array type");
duke@435 311 return array->as_obj_array_klass();
duke@435 312 }
duke@435 313 ciTypeArrayKlass* pop_typeArray() {
duke@435 314 ciType* array = pop_value();
duke@435 315 if (array == null_type()) return NULL;
duke@435 316 assert(array->is_type_array_klass(), "must be prim array type");
duke@435 317 return array->as_type_array_klass();
duke@435 318 }
duke@435 319 void push_null() {
duke@435 320 push(null_type());
duke@435 321 }
duke@435 322 void do_null_assert(ciKlass* unloaded_klass);
duke@435 323
duke@435 324 // Helper convenience routines.
duke@435 325 void do_aaload(ciBytecodeStream* str);
duke@435 326 void do_checkcast(ciBytecodeStream* str);
duke@435 327 void do_getfield(ciBytecodeStream* str);
duke@435 328 void do_getstatic(ciBytecodeStream* str);
duke@435 329 void do_invoke(ciBytecodeStream* str, bool has_receiver);
duke@435 330 void do_jsr(ciBytecodeStream* str);
duke@435 331 void do_ldc(ciBytecodeStream* str);
duke@435 332 void do_multianewarray(ciBytecodeStream* str);
duke@435 333 void do_new(ciBytecodeStream* str);
duke@435 334 void do_newarray(ciBytecodeStream* str);
duke@435 335 void do_putfield(ciBytecodeStream* str);
duke@435 336 void do_putstatic(ciBytecodeStream* str);
duke@435 337 void do_ret(ciBytecodeStream* str);
duke@435 338
duke@435 339 void overwrite_local_double_long(int index) {
duke@435 340 // Invalidate the previous local if it contains first half of
duke@435 341 // a double or long value since it's seconf half is being overwritten.
duke@435 342 int prev_index = index - 1;
duke@435 343 if (prev_index >= 0 &&
duke@435 344 (is_double(type_at(local(prev_index))) ||
duke@435 345 is_long(type_at(local(prev_index))))) {
duke@435 346 set_type_at(local(prev_index), bottom_type());
duke@435 347 }
duke@435 348 }
duke@435 349
duke@435 350 void load_local_object(int index) {
duke@435 351 ciType* type = type_at(local(index));
duke@435 352 assert(is_reference(type), "must be reference type");
duke@435 353 push(type);
duke@435 354 }
duke@435 355 void store_local_object(int index) {
duke@435 356 ciType* type = pop_value();
duke@435 357 assert(is_reference(type) || type->is_return_address(),
duke@435 358 "must be reference type or return address");
duke@435 359 overwrite_local_double_long(index);
duke@435 360 set_type_at(local(index), type);
duke@435 361 }
duke@435 362
duke@435 363 void load_local_double(int index) {
duke@435 364 ciType* type = type_at(local(index));
duke@435 365 ciType* type2 = type_at(local(index+1));
duke@435 366 assert(is_double(type), "must be double type");
duke@435 367 assert(type2 == double2_type(), "must be 2nd half");
duke@435 368 push(type);
duke@435 369 push(double2_type());
duke@435 370 }
duke@435 371 void store_local_double(int index) {
duke@435 372 ciType* type2 = pop_value();
duke@435 373 ciType* type = pop_value();
duke@435 374 assert(is_double(type), "must be double");
duke@435 375 assert(type2 == double2_type(), "must be 2nd half");
duke@435 376 overwrite_local_double_long(index);
duke@435 377 set_type_at(local(index), type);
duke@435 378 set_type_at(local(index+1), type2);
duke@435 379 }
duke@435 380
duke@435 381 void load_local_float(int index) {
duke@435 382 ciType* type = type_at(local(index));
duke@435 383 assert(is_float(type), "must be float type");
duke@435 384 push(type);
duke@435 385 }
duke@435 386 void store_local_float(int index) {
duke@435 387 ciType* type = pop_value();
duke@435 388 assert(is_float(type), "must be float type");
duke@435 389 overwrite_local_double_long(index);
duke@435 390 set_type_at(local(index), type);
duke@435 391 }
duke@435 392
duke@435 393 void load_local_int(int index) {
duke@435 394 ciType* type = type_at(local(index));
duke@435 395 assert(is_int(type), "must be int type");
duke@435 396 push(type);
duke@435 397 }
duke@435 398 void store_local_int(int index) {
duke@435 399 ciType* type = pop_value();
duke@435 400 assert(is_int(type), "must be int type");
duke@435 401 overwrite_local_double_long(index);
duke@435 402 set_type_at(local(index), type);
duke@435 403 }
duke@435 404
duke@435 405 void load_local_long(int index) {
duke@435 406 ciType* type = type_at(local(index));
duke@435 407 ciType* type2 = type_at(local(index+1));
duke@435 408 assert(is_long(type), "must be long type");
duke@435 409 assert(type2 == long2_type(), "must be 2nd half");
duke@435 410 push(type);
duke@435 411 push(long2_type());
duke@435 412 }
duke@435 413 void store_local_long(int index) {
duke@435 414 ciType* type2 = pop_value();
duke@435 415 ciType* type = pop_value();
duke@435 416 assert(is_long(type), "must be long");
duke@435 417 assert(type2 == long2_type(), "must be 2nd half");
duke@435 418 overwrite_local_double_long(index);
duke@435 419 set_type_at(local(index), type);
duke@435 420 set_type_at(local(index+1), type2);
duke@435 421 }
duke@435 422
duke@435 423 // Stop interpretation of this path with a trap.
duke@435 424 void trap(ciBytecodeStream* str, ciKlass* klass, int index);
duke@435 425
duke@435 426 public:
duke@435 427 StateVector(ciTypeFlow* outer);
duke@435 428
duke@435 429 // Copy our value into some other StateVector
duke@435 430 void copy_into(StateVector* copy) const;
duke@435 431
duke@435 432 // Meets this StateVector with another, destructively modifying this
duke@435 433 // one. Returns true if any modification takes place.
duke@435 434 bool meet(const StateVector* incoming);
duke@435 435
duke@435 436 // Ditto, except that the incoming state is coming from an exception.
duke@435 437 bool meet_exception(ciInstanceKlass* exc, const StateVector* incoming);
duke@435 438
duke@435 439 // Apply the effect of one bytecode to this StateVector
duke@435 440 bool apply_one_bytecode(ciBytecodeStream* stream);
duke@435 441
duke@435 442 // What is the bci of the trap?
duke@435 443 int trap_bci() { return _trap_bci; }
duke@435 444
duke@435 445 // What is the index associated with the trap?
duke@435 446 int trap_index() { return _trap_index; }
duke@435 447
duke@435 448 void print_cell_on(outputStream* st, Cell c) const PRODUCT_RETURN;
duke@435 449 void print_on(outputStream* st) const PRODUCT_RETURN;
duke@435 450 };
duke@435 451
duke@435 452 // Parameter for "find_block" calls:
duke@435 453 // Describes the difference between a public and private copy.
duke@435 454 enum CreateOption {
duke@435 455 create_public_copy,
duke@435 456 create_private_copy,
duke@435 457 no_create
duke@435 458 };
duke@435 459
duke@435 460 // A basic block
duke@435 461 class Block : public ResourceObj {
duke@435 462 private:
duke@435 463 ciBlock* _ciblock;
duke@435 464 GrowableArray<Block*>* _exceptions;
duke@435 465 GrowableArray<ciInstanceKlass*>* _exc_klasses;
duke@435 466 GrowableArray<Block*>* _successors;
duke@435 467 StateVector* _state;
duke@435 468 JsrSet* _jsrs;
duke@435 469
duke@435 470 int _trap_bci;
duke@435 471 int _trap_index;
duke@435 472
duke@435 473 // A reasonable approximation to pre-order, provided.to the client.
duke@435 474 int _pre_order;
duke@435 475
duke@435 476 // Has this block been cloned for some special purpose?
duke@435 477 bool _private_copy;
duke@435 478
duke@435 479 // A pointer used for our internal work list
duke@435 480 Block* _next;
duke@435 481 bool _on_work_list;
duke@435 482
duke@435 483 ciBlock* ciblock() const { return _ciblock; }
duke@435 484 StateVector* state() const { return _state; }
duke@435 485
duke@435 486 // Compute the exceptional successors and types for this Block.
duke@435 487 void compute_exceptions();
duke@435 488
duke@435 489 public:
duke@435 490 // constructors
duke@435 491 Block(ciTypeFlow* outer, ciBlock* ciblk, JsrSet* jsrs);
duke@435 492
duke@435 493 void set_trap(int trap_bci, int trap_index) {
duke@435 494 _trap_bci = trap_bci;
duke@435 495 _trap_index = trap_index;
duke@435 496 assert(has_trap(), "");
duke@435 497 }
duke@435 498 bool has_trap() const { return _trap_bci != -1; }
duke@435 499 int trap_bci() const { assert(has_trap(), ""); return _trap_bci; }
duke@435 500 int trap_index() const { assert(has_trap(), ""); return _trap_index; }
duke@435 501
duke@435 502 // accessors
duke@435 503 ciTypeFlow* outer() const { return state()->outer(); }
duke@435 504 int start() const { return _ciblock->start_bci(); }
duke@435 505 int limit() const { return _ciblock->limit_bci(); }
duke@435 506 int control() const { return _ciblock->control_bci(); }
duke@435 507
duke@435 508 bool is_private_copy() const { return _private_copy; }
duke@435 509 void set_private_copy(bool z);
duke@435 510 int private_copy_count() const { return outer()->private_copy_count(ciblock()->index(), _jsrs); }
duke@435 511
duke@435 512 // access to entry state
duke@435 513 int stack_size() const { return _state->stack_size(); }
duke@435 514 int monitor_count() const { return _state->monitor_count(); }
duke@435 515 ciType* local_type_at(int i) const { return _state->local_type_at(i); }
duke@435 516 ciType* stack_type_at(int i) const { return _state->stack_type_at(i); }
duke@435 517
duke@435 518 // Get the successors for this Block.
duke@435 519 GrowableArray<Block*>* successors(ciBytecodeStream* str,
duke@435 520 StateVector* state,
duke@435 521 JsrSet* jsrs);
duke@435 522 GrowableArray<Block*>* successors() {
duke@435 523 assert(_successors != NULL, "must be filled in");
duke@435 524 return _successors;
duke@435 525 }
duke@435 526
duke@435 527 // Helper function for "successors" when making private copies of
duke@435 528 // loop heads for C2.
duke@435 529 Block * clone_loop_head(ciTypeFlow* analyzer,
duke@435 530 int branch_bci,
duke@435 531 Block* target,
duke@435 532 JsrSet* jsrs);
duke@435 533
duke@435 534 // Get the exceptional successors for this Block.
duke@435 535 GrowableArray<Block*>* exceptions() {
duke@435 536 if (_exceptions == NULL) {
duke@435 537 compute_exceptions();
duke@435 538 }
duke@435 539 return _exceptions;
duke@435 540 }
duke@435 541
duke@435 542 // Get the exception klasses corresponding to the
duke@435 543 // exceptional successors for this Block.
duke@435 544 GrowableArray<ciInstanceKlass*>* exc_klasses() {
duke@435 545 if (_exc_klasses == NULL) {
duke@435 546 compute_exceptions();
duke@435 547 }
duke@435 548 return _exc_klasses;
duke@435 549 }
duke@435 550
duke@435 551 // Is this Block compatible with a given JsrSet?
duke@435 552 bool is_compatible_with(JsrSet* other) {
duke@435 553 return _jsrs->is_compatible_with(other);
duke@435 554 }
duke@435 555
duke@435 556 // Copy the value of our state vector into another.
duke@435 557 void copy_state_into(StateVector* copy) const {
duke@435 558 _state->copy_into(copy);
duke@435 559 }
duke@435 560
duke@435 561 // Copy the value of our JsrSet into another
duke@435 562 void copy_jsrs_into(JsrSet* copy) const {
duke@435 563 _jsrs->copy_into(copy);
duke@435 564 }
duke@435 565
duke@435 566 // Meets the start state of this block with another state, destructively
duke@435 567 // modifying this one. Returns true if any modification takes place.
duke@435 568 bool meet(const StateVector* incoming) {
duke@435 569 return state()->meet(incoming);
duke@435 570 }
duke@435 571
duke@435 572 // Ditto, except that the incoming state is coming from an
duke@435 573 // exception path. This means the stack is replaced by the
duke@435 574 // appropriate exception type.
duke@435 575 bool meet_exception(ciInstanceKlass* exc, const StateVector* incoming) {
duke@435 576 return state()->meet_exception(exc, incoming);
duke@435 577 }
duke@435 578
duke@435 579 // Work list manipulation
duke@435 580 void set_next(Block* block) { _next = block; }
duke@435 581 Block* next() const { return _next; }
duke@435 582
duke@435 583 void set_on_work_list(bool c) { _on_work_list = c; }
duke@435 584 bool is_on_work_list() const { return _on_work_list; }
duke@435 585
duke@435 586 bool has_pre_order() const { return _pre_order >= 0; }
duke@435 587 void set_pre_order(int po) { assert(!has_pre_order() && po >= 0, ""); _pre_order = po; }
duke@435 588 int pre_order() const { assert(has_pre_order(), ""); return _pre_order; }
duke@435 589 bool is_start() const { return _pre_order == outer()->start_block_num(); }
duke@435 590
duke@435 591 // A ranking used in determining order within the work list.
duke@435 592 bool is_simpler_than(Block* other);
duke@435 593
duke@435 594 void print_value_on(outputStream* st) const PRODUCT_RETURN;
duke@435 595 void print_on(outputStream* st) const PRODUCT_RETURN;
duke@435 596 };
duke@435 597
duke@435 598 // Standard indexes of successors, for various bytecodes.
duke@435 599 enum {
duke@435 600 FALL_THROUGH = 0, // normal control
duke@435 601 IF_NOT_TAKEN = 0, // the not-taken branch of an if (i.e., fall-through)
duke@435 602 IF_TAKEN = 1, // the taken branch of an if
duke@435 603 GOTO_TARGET = 0, // unique successor for goto, jsr, or ret
duke@435 604 SWITCH_DEFAULT = 0, // default branch of a switch
duke@435 605 SWITCH_CASES = 1 // first index for any non-default switch branches
duke@435 606 // Unlike in other blocks, the successors of a switch are listed uniquely.
duke@435 607 };
duke@435 608
duke@435 609 private:
duke@435 610 // A mapping from pre_order to Blocks. This array is created
duke@435 611 // only at the end of the flow.
duke@435 612 Block** _block_map;
duke@435 613
duke@435 614 // For each ciBlock index, a list of Blocks which share this ciBlock.
duke@435 615 GrowableArray<Block*>** _idx_to_blocklist;
duke@435 616 // count of ciBlocks
duke@435 617 int _ciblock_count;
duke@435 618
duke@435 619 // Tells if a given instruction is able to generate an exception edge.
duke@435 620 bool can_trap(ciBytecodeStream& str);
duke@435 621
duke@435 622 public:
duke@435 623 // Return the block beginning at bci which has a JsrSet compatible
duke@435 624 // with jsrs.
duke@435 625 Block* block_at(int bci, JsrSet* set, CreateOption option = create_public_copy);
duke@435 626
duke@435 627 // block factory
duke@435 628 Block* get_block_for(int ciBlockIndex, JsrSet* jsrs, CreateOption option = create_public_copy);
duke@435 629
duke@435 630 // How many of the blocks have the private_copy bit set?
duke@435 631 int private_copy_count(int ciBlockIndex, JsrSet* jsrs) const;
duke@435 632
duke@435 633 // Return an existing block containing bci which has a JsrSet compatible
duke@435 634 // with jsrs, or NULL if there is none.
duke@435 635 Block* existing_block_at(int bci, JsrSet* set) { return block_at(bci, set, no_create); }
duke@435 636
duke@435 637 // Tell whether the flow analysis has encountered an error of some sort.
duke@435 638 bool failing() { return env()->failing() || _failure_reason != NULL; }
duke@435 639
duke@435 640 // Reason this compilation is failing, such as "too many basic blocks".
duke@435 641 const char* failure_reason() { return _failure_reason; }
duke@435 642
duke@435 643 // Note a failure.
duke@435 644 void record_failure(const char* reason);
duke@435 645
duke@435 646 // Return the block of a given pre-order number.
duke@435 647 int have_block_count() const { return _block_map != NULL; }
duke@435 648 int block_count() const { assert(have_block_count(), "");
duke@435 649 return _next_pre_order; }
duke@435 650 Block* pre_order_at(int po) const { assert(0 <= po && po < block_count(), "out of bounds");
duke@435 651 return _block_map[po]; }
duke@435 652 Block* start_block() const { return pre_order_at(start_block_num()); }
duke@435 653 int start_block_num() const { return 0; }
duke@435 654
duke@435 655 private:
duke@435 656 // A work list used during flow analysis.
duke@435 657 Block* _work_list;
duke@435 658
duke@435 659 // Next Block::_pre_order. After mapping, doubles as block_count.
duke@435 660 int _next_pre_order;
duke@435 661
duke@435 662 // Are there more blocks on the work list?
duke@435 663 bool work_list_empty() { return _work_list == NULL; }
duke@435 664
duke@435 665 // Get the next basic block from our work list.
duke@435 666 Block* work_list_next();
duke@435 667
duke@435 668 // Add a basic block to our work list.
duke@435 669 void add_to_work_list(Block* block);
duke@435 670
duke@435 671 // State used for make_jsr_record
duke@435 672 int _jsr_count;
duke@435 673 GrowableArray<JsrRecord*>* _jsr_records;
duke@435 674
duke@435 675 public:
duke@435 676 // Make a JsrRecord for a given (entry, return) pair, if such a record
duke@435 677 // does not already exist.
duke@435 678 JsrRecord* make_jsr_record(int entry_address, int return_address);
duke@435 679
duke@435 680 private:
duke@435 681 // Get the initial state for start_bci:
duke@435 682 const StateVector* get_start_state();
duke@435 683
duke@435 684 // Merge the current state into all exceptional successors at the
duke@435 685 // current point in the code.
duke@435 686 void flow_exceptions(GrowableArray<Block*>* exceptions,
duke@435 687 GrowableArray<ciInstanceKlass*>* exc_klasses,
duke@435 688 StateVector* state);
duke@435 689
duke@435 690 // Merge the current state into all successors at the current point
duke@435 691 // in the code.
duke@435 692 void flow_successors(GrowableArray<Block*>* successors,
duke@435 693 StateVector* state);
duke@435 694
duke@435 695 // Interpret the effects of the bytecodes on the incoming state
duke@435 696 // vector of a basic block. Push the changed state to succeeding
duke@435 697 // basic blocks.
duke@435 698 void flow_block(Block* block,
duke@435 699 StateVector* scratch_state,
duke@435 700 JsrSet* scratch_jsrs);
duke@435 701
duke@435 702 // Perform the type flow analysis, creating and cloning Blocks as
duke@435 703 // necessary.
duke@435 704 void flow_types();
duke@435 705
duke@435 706 // Create the block map, which indexes blocks in pre_order.
duke@435 707 void map_blocks();
duke@435 708
duke@435 709 public:
duke@435 710 // Perform type inference flow analysis.
duke@435 711 void do_flow();
duke@435 712
duke@435 713 void print_on(outputStream* st) const PRODUCT_RETURN;
duke@435 714 };

mercurial