src/share/vm/ci/ciTypeFlow.hpp

Mon, 07 Oct 2013 10:41:56 -0700

author
twisti
date
Mon, 07 Oct 2013 10:41:56 -0700
changeset 5907
c775af091fe9
parent 4153
b9a9ed0f8eeb
child 6876
710a3c8b516e
permissions
-rw-r--r--

8025566: EXCEPTION_ACCESS_VIOLATION in compiled by C1 String.valueOf method
Reviewed-by: kvn

duke@435 1 /*
mikael@4153 2 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. 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 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_CI_CITYPEFLOW_HPP
stefank@2314 26 #define SHARE_VM_CI_CITYPEFLOW_HPP
stefank@2314 27
stefank@2314 28 #ifdef COMPILER2
stefank@2314 29 #include "ci/ciEnv.hpp"
stefank@2314 30 #include "ci/ciKlass.hpp"
stefank@2314 31 #include "ci/ciMethodBlocks.hpp"
stefank@2314 32 #endif
stefank@2314 33 #ifdef SHARK
stefank@2314 34 #include "ci/ciEnv.hpp"
stefank@2314 35 #include "ci/ciKlass.hpp"
stefank@2314 36 #include "ci/ciMethodBlocks.hpp"
twisti@2729 37 #include "shark/shark_globals.hpp"
stefank@2314 38 #endif
stefank@2314 39
duke@435 40
duke@435 41 class ciTypeFlow : public ResourceObj {
duke@435 42 private:
duke@435 43 ciEnv* _env;
duke@435 44 ciMethod* _method;
duke@435 45 ciMethodBlocks* _methodBlocks;
duke@435 46 int _osr_bci;
duke@435 47
duke@435 48 // information cached from the method:
duke@435 49 int _max_locals;
duke@435 50 int _max_stack;
duke@435 51 int _code_size;
never@802 52 bool _has_irreducible_entry;
duke@435 53
duke@435 54 const char* _failure_reason;
duke@435 55
duke@435 56 public:
duke@435 57 class StateVector;
never@802 58 class Loop;
duke@435 59 class Block;
duke@435 60
duke@435 61 // Build a type flow analyzer
duke@435 62 // Do an OSR analysis if osr_bci >= 0.
duke@435 63 ciTypeFlow(ciEnv* env, ciMethod* method, int osr_bci = InvocationEntryBci);
duke@435 64
duke@435 65 // Accessors
duke@435 66 ciMethod* method() const { return _method; }
duke@435 67 ciEnv* env() { return _env; }
duke@435 68 Arena* arena() { return _env->arena(); }
duke@435 69 bool is_osr_flow() const{ return _osr_bci != InvocationEntryBci; }
duke@435 70 int start_bci() const { return is_osr_flow()? _osr_bci: 0; }
duke@435 71 int max_locals() const { return _max_locals; }
duke@435 72 int max_stack() const { return _max_stack; }
duke@435 73 int max_cells() const { return _max_locals + _max_stack; }
duke@435 74 int code_size() const { return _code_size; }
never@802 75 bool has_irreducible_entry() const { return _has_irreducible_entry; }
duke@435 76
duke@435 77 // Represents information about an "active" jsr call. This
duke@435 78 // class represents a call to the routine at some entry address
duke@435 79 // with some distinct return address.
duke@435 80 class JsrRecord : public ResourceObj {
duke@435 81 private:
duke@435 82 int _entry_address;
duke@435 83 int _return_address;
duke@435 84 public:
duke@435 85 JsrRecord(int entry_address, int return_address) {
duke@435 86 _entry_address = entry_address;
duke@435 87 _return_address = return_address;
duke@435 88 }
duke@435 89
duke@435 90 int entry_address() const { return _entry_address; }
duke@435 91 int return_address() const { return _return_address; }
duke@435 92
duke@435 93 void print_on(outputStream* st) const {
duke@435 94 #ifndef PRODUCT
duke@435 95 st->print("%d->%d", entry_address(), return_address());
duke@435 96 #endif
duke@435 97 }
duke@435 98 };
duke@435 99
duke@435 100 // A JsrSet represents some set of JsrRecords. This class
duke@435 101 // is used to record a set of all jsr routines which we permit
duke@435 102 // execution to return (ret) from.
duke@435 103 //
duke@435 104 // During abstract interpretation, JsrSets are used to determine
duke@435 105 // whether two paths which reach a given block are unique, and
duke@435 106 // should be cloned apart, or are compatible, and should merge
duke@435 107 // together.
duke@435 108 //
duke@435 109 // Note that different amounts of effort can be expended determining
duke@435 110 // if paths are compatible. <DISCUSSION>
duke@435 111 class JsrSet : public ResourceObj {
duke@435 112 private:
duke@435 113 GrowableArray<JsrRecord*>* _set;
duke@435 114
duke@435 115 JsrRecord* record_at(int i) {
duke@435 116 return _set->at(i);
duke@435 117 }
duke@435 118
duke@435 119 // Insert the given JsrRecord into the JsrSet, maintaining the order
duke@435 120 // of the set and replacing any element with the same entry address.
duke@435 121 void insert_jsr_record(JsrRecord* record);
duke@435 122
duke@435 123 // Remove the JsrRecord with the given return address from the JsrSet.
duke@435 124 void remove_jsr_record(int return_address);
duke@435 125
duke@435 126 public:
duke@435 127 JsrSet(Arena* arena, int default_len = 4);
duke@435 128
duke@435 129 // Copy this JsrSet.
duke@435 130 void copy_into(JsrSet* jsrs);
duke@435 131
duke@435 132 // Is this JsrSet compatible with some other JsrSet?
duke@435 133 bool is_compatible_with(JsrSet* other);
duke@435 134
duke@435 135 // Apply the effect of a single bytecode to the JsrSet.
duke@435 136 void apply_control(ciTypeFlow* analyzer,
duke@435 137 ciBytecodeStream* str,
duke@435 138 StateVector* state);
duke@435 139
duke@435 140 // What is the cardinality of this set?
duke@435 141 int size() const { return _set->length(); }
duke@435 142
duke@435 143 void print_on(outputStream* st) const PRODUCT_RETURN;
duke@435 144 };
duke@435 145
never@802 146 class LocalSet VALUE_OBJ_CLASS_SPEC {
never@802 147 private:
never@802 148 enum Constants { max = 63 };
never@802 149 uint64_t _bits;
never@802 150 public:
never@802 151 LocalSet() : _bits(0) {}
never@802 152 void add(uint32_t i) { if (i < (uint32_t)max) _bits |= (1LL << i); }
never@802 153 void add(LocalSet* ls) { _bits |= ls->_bits; }
never@802 154 bool test(uint32_t i) const { return i < (uint32_t)max ? (_bits>>i)&1U : true; }
never@802 155 void clear() { _bits = 0; }
never@802 156 void print_on(outputStream* st, int limit) const PRODUCT_RETURN;
never@802 157 };
never@802 158
duke@435 159 // Used as a combined index for locals and temps
duke@435 160 enum Cell {
never@738 161 Cell_0, Cell_max = INT_MAX
duke@435 162 };
duke@435 163
duke@435 164 // A StateVector summarizes the type information at some
duke@435 165 // point in the program
duke@435 166 class StateVector : public ResourceObj {
duke@435 167 private:
duke@435 168 ciType** _types;
duke@435 169 int _stack_size;
duke@435 170 int _monitor_count;
duke@435 171 ciTypeFlow* _outer;
duke@435 172
duke@435 173 int _trap_bci;
duke@435 174 int _trap_index;
duke@435 175
never@802 176 LocalSet _def_locals; // For entire block
never@802 177
duke@435 178 static ciType* type_meet_internal(ciType* t1, ciType* t2, ciTypeFlow* analyzer);
duke@435 179
duke@435 180 public:
duke@435 181 // Special elements in our type lattice.
duke@435 182 enum {
duke@435 183 T_TOP = T_VOID, // why not?
duke@435 184 T_BOTTOM = T_CONFLICT,
duke@435 185 T_LONG2 = T_SHORT, // 2nd word of T_LONG
duke@435 186 T_DOUBLE2 = T_CHAR, // 2nd word of T_DOUBLE
duke@435 187 T_NULL = T_BYTE // for now.
duke@435 188 };
duke@435 189 static ciType* top_type() { return ciType::make((BasicType)T_TOP); }
duke@435 190 static ciType* bottom_type() { return ciType::make((BasicType)T_BOTTOM); }
duke@435 191 static ciType* long2_type() { return ciType::make((BasicType)T_LONG2); }
duke@435 192 static ciType* double2_type(){ return ciType::make((BasicType)T_DOUBLE2); }
duke@435 193 static ciType* null_type() { return ciType::make((BasicType)T_NULL); }
duke@435 194
duke@435 195 static ciType* half_type(ciType* t) {
duke@435 196 switch (t->basic_type()) {
duke@435 197 case T_LONG: return long2_type();
duke@435 198 case T_DOUBLE: return double2_type();
duke@435 199 default: ShouldNotReachHere(); return NULL;
duke@435 200 }
duke@435 201 }
duke@435 202
duke@435 203 // The meet operation for our type lattice.
duke@435 204 ciType* type_meet(ciType* t1, ciType* t2) {
duke@435 205 return type_meet_internal(t1, t2, outer());
duke@435 206 }
duke@435 207
duke@435 208 // Accessors
duke@435 209 ciTypeFlow* outer() const { return _outer; }
duke@435 210
duke@435 211 int stack_size() const { return _stack_size; }
duke@435 212 void set_stack_size(int ss) { _stack_size = ss; }
duke@435 213
duke@435 214 int monitor_count() const { return _monitor_count; }
duke@435 215 void set_monitor_count(int mc) { _monitor_count = mc; }
duke@435 216
never@802 217 LocalSet* def_locals() { return &_def_locals; }
never@802 218 const LocalSet* def_locals() const { return &_def_locals; }
never@802 219
duke@435 220 static Cell start_cell() { return (Cell)0; }
duke@435 221 static Cell next_cell(Cell c) { return (Cell)(((int)c) + 1); }
duke@435 222 Cell limit_cell() const {
duke@435 223 return (Cell)(outer()->max_locals() + stack_size());
duke@435 224 }
duke@435 225
duke@435 226 // Cell creation
duke@435 227 Cell local(int lnum) const {
duke@435 228 assert(lnum < outer()->max_locals(), "index check");
duke@435 229 return (Cell)(lnum);
duke@435 230 }
duke@435 231
duke@435 232 Cell stack(int snum) const {
duke@435 233 assert(snum < stack_size(), "index check");
duke@435 234 return (Cell)(outer()->max_locals() + snum);
duke@435 235 }
duke@435 236
duke@435 237 Cell tos() const { return stack(stack_size()-1); }
duke@435 238
duke@435 239 // For external use only:
duke@435 240 ciType* local_type_at(int i) const { return type_at(local(i)); }
duke@435 241 ciType* stack_type_at(int i) const { return type_at(stack(i)); }
duke@435 242
duke@435 243 // Accessors for the type of some Cell c
duke@435 244 ciType* type_at(Cell c) const {
duke@435 245 assert(start_cell() <= c && c < limit_cell(), "out of bounds");
duke@435 246 return _types[c];
duke@435 247 }
duke@435 248
duke@435 249 void set_type_at(Cell c, ciType* type) {
duke@435 250 assert(start_cell() <= c && c < limit_cell(), "out of bounds");
duke@435 251 _types[c] = type;
duke@435 252 }
duke@435 253
duke@435 254 // Top-of-stack operations.
duke@435 255 void set_type_at_tos(ciType* type) { set_type_at(tos(), type); }
duke@435 256 ciType* type_at_tos() const { return type_at(tos()); }
duke@435 257
duke@435 258 void push(ciType* type) {
duke@435 259 _stack_size++;
duke@435 260 set_type_at_tos(type);
duke@435 261 }
duke@435 262 void pop() {
duke@435 263 debug_only(set_type_at_tos(bottom_type()));
duke@435 264 _stack_size--;
duke@435 265 }
duke@435 266 ciType* pop_value() {
duke@435 267 ciType* t = type_at_tos();
duke@435 268 pop();
duke@435 269 return t;
duke@435 270 }
duke@435 271
duke@435 272 // Convenience operations.
duke@435 273 bool is_reference(ciType* type) const {
duke@435 274 return type == null_type() || !type->is_primitive_type();
duke@435 275 }
duke@435 276 bool is_int(ciType* type) const {
duke@435 277 return type->basic_type() == T_INT;
duke@435 278 }
duke@435 279 bool is_long(ciType* type) const {
duke@435 280 return type->basic_type() == T_LONG;
duke@435 281 }
duke@435 282 bool is_float(ciType* type) const {
duke@435 283 return type->basic_type() == T_FLOAT;
duke@435 284 }
duke@435 285 bool is_double(ciType* type) const {
duke@435 286 return type->basic_type() == T_DOUBLE;
duke@435 287 }
duke@435 288
never@802 289 void store_to_local(int lnum) {
never@802 290 _def_locals.add((uint) lnum);
never@802 291 }
never@802 292
duke@435 293 void push_translate(ciType* type);
duke@435 294
duke@435 295 void push_int() {
duke@435 296 push(ciType::make(T_INT));
duke@435 297 }
duke@435 298 void pop_int() {
duke@435 299 assert(is_int(type_at_tos()), "must be integer");
duke@435 300 pop();
duke@435 301 }
duke@435 302 void check_int(Cell c) {
duke@435 303 assert(is_int(type_at(c)), "must be integer");
duke@435 304 }
duke@435 305 void push_double() {
duke@435 306 push(ciType::make(T_DOUBLE));
duke@435 307 push(double2_type());
duke@435 308 }
duke@435 309 void pop_double() {
duke@435 310 assert(type_at_tos() == double2_type(), "must be 2nd half");
duke@435 311 pop();
duke@435 312 assert(is_double(type_at_tos()), "must be double");
duke@435 313 pop();
duke@435 314 }
duke@435 315 void push_float() {
duke@435 316 push(ciType::make(T_FLOAT));
duke@435 317 }
duke@435 318 void pop_float() {
duke@435 319 assert(is_float(type_at_tos()), "must be float");
duke@435 320 pop();
duke@435 321 }
duke@435 322 void push_long() {
duke@435 323 push(ciType::make(T_LONG));
duke@435 324 push(long2_type());
duke@435 325 }
duke@435 326 void pop_long() {
duke@435 327 assert(type_at_tos() == long2_type(), "must be 2nd half");
duke@435 328 pop();
duke@435 329 assert(is_long(type_at_tos()), "must be long");
duke@435 330 pop();
duke@435 331 }
duke@435 332 void push_object(ciKlass* klass) {
duke@435 333 push(klass);
duke@435 334 }
duke@435 335 void pop_object() {
duke@435 336 assert(is_reference(type_at_tos()), "must be reference type");
duke@435 337 pop();
duke@435 338 }
duke@435 339 void pop_array() {
duke@435 340 assert(type_at_tos() == null_type() ||
duke@435 341 type_at_tos()->is_array_klass(), "must be array type");
duke@435 342 pop();
duke@435 343 }
duke@435 344 // pop_objArray and pop_typeArray narrow the tos to ciObjArrayKlass
duke@435 345 // or ciTypeArrayKlass (resp.). In the rare case that an explicit
duke@435 346 // null is popped from the stack, we return NULL. Caller beware.
duke@435 347 ciObjArrayKlass* pop_objArray() {
duke@435 348 ciType* array = pop_value();
duke@435 349 if (array == null_type()) return NULL;
duke@435 350 assert(array->is_obj_array_klass(), "must be object array type");
duke@435 351 return array->as_obj_array_klass();
duke@435 352 }
duke@435 353 ciTypeArrayKlass* pop_typeArray() {
duke@435 354 ciType* array = pop_value();
duke@435 355 if (array == null_type()) return NULL;
duke@435 356 assert(array->is_type_array_klass(), "must be prim array type");
duke@435 357 return array->as_type_array_klass();
duke@435 358 }
duke@435 359 void push_null() {
duke@435 360 push(null_type());
duke@435 361 }
duke@435 362 void do_null_assert(ciKlass* unloaded_klass);
duke@435 363
duke@435 364 // Helper convenience routines.
duke@435 365 void do_aaload(ciBytecodeStream* str);
duke@435 366 void do_checkcast(ciBytecodeStream* str);
duke@435 367 void do_getfield(ciBytecodeStream* str);
duke@435 368 void do_getstatic(ciBytecodeStream* str);
duke@435 369 void do_invoke(ciBytecodeStream* str, bool has_receiver);
duke@435 370 void do_jsr(ciBytecodeStream* str);
duke@435 371 void do_ldc(ciBytecodeStream* str);
duke@435 372 void do_multianewarray(ciBytecodeStream* str);
duke@435 373 void do_new(ciBytecodeStream* str);
duke@435 374 void do_newarray(ciBytecodeStream* str);
duke@435 375 void do_putfield(ciBytecodeStream* str);
duke@435 376 void do_putstatic(ciBytecodeStream* str);
duke@435 377 void do_ret(ciBytecodeStream* str);
duke@435 378
duke@435 379 void overwrite_local_double_long(int index) {
duke@435 380 // Invalidate the previous local if it contains first half of
duke@435 381 // a double or long value since it's seconf half is being overwritten.
duke@435 382 int prev_index = index - 1;
duke@435 383 if (prev_index >= 0 &&
duke@435 384 (is_double(type_at(local(prev_index))) ||
duke@435 385 is_long(type_at(local(prev_index))))) {
duke@435 386 set_type_at(local(prev_index), bottom_type());
duke@435 387 }
duke@435 388 }
duke@435 389
duke@435 390 void load_local_object(int index) {
duke@435 391 ciType* type = type_at(local(index));
duke@435 392 assert(is_reference(type), "must be reference type");
duke@435 393 push(type);
duke@435 394 }
duke@435 395 void store_local_object(int index) {
duke@435 396 ciType* type = pop_value();
duke@435 397 assert(is_reference(type) || type->is_return_address(),
duke@435 398 "must be reference type or return address");
duke@435 399 overwrite_local_double_long(index);
duke@435 400 set_type_at(local(index), type);
never@802 401 store_to_local(index);
duke@435 402 }
duke@435 403
duke@435 404 void load_local_double(int index) {
duke@435 405 ciType* type = type_at(local(index));
duke@435 406 ciType* type2 = type_at(local(index+1));
duke@435 407 assert(is_double(type), "must be double type");
duke@435 408 assert(type2 == double2_type(), "must be 2nd half");
duke@435 409 push(type);
duke@435 410 push(double2_type());
duke@435 411 }
duke@435 412 void store_local_double(int index) {
duke@435 413 ciType* type2 = pop_value();
duke@435 414 ciType* type = pop_value();
duke@435 415 assert(is_double(type), "must be double");
duke@435 416 assert(type2 == double2_type(), "must be 2nd half");
duke@435 417 overwrite_local_double_long(index);
duke@435 418 set_type_at(local(index), type);
duke@435 419 set_type_at(local(index+1), type2);
never@802 420 store_to_local(index);
never@802 421 store_to_local(index+1);
duke@435 422 }
duke@435 423
duke@435 424 void load_local_float(int index) {
duke@435 425 ciType* type = type_at(local(index));
duke@435 426 assert(is_float(type), "must be float type");
duke@435 427 push(type);
duke@435 428 }
duke@435 429 void store_local_float(int index) {
duke@435 430 ciType* type = pop_value();
duke@435 431 assert(is_float(type), "must be float type");
duke@435 432 overwrite_local_double_long(index);
duke@435 433 set_type_at(local(index), type);
never@802 434 store_to_local(index);
duke@435 435 }
duke@435 436
duke@435 437 void load_local_int(int index) {
duke@435 438 ciType* type = type_at(local(index));
duke@435 439 assert(is_int(type), "must be int type");
duke@435 440 push(type);
duke@435 441 }
duke@435 442 void store_local_int(int index) {
duke@435 443 ciType* type = pop_value();
duke@435 444 assert(is_int(type), "must be int type");
duke@435 445 overwrite_local_double_long(index);
duke@435 446 set_type_at(local(index), type);
never@802 447 store_to_local(index);
duke@435 448 }
duke@435 449
duke@435 450 void load_local_long(int index) {
duke@435 451 ciType* type = type_at(local(index));
duke@435 452 ciType* type2 = type_at(local(index+1));
duke@435 453 assert(is_long(type), "must be long type");
duke@435 454 assert(type2 == long2_type(), "must be 2nd half");
duke@435 455 push(type);
duke@435 456 push(long2_type());
duke@435 457 }
duke@435 458 void store_local_long(int index) {
duke@435 459 ciType* type2 = pop_value();
duke@435 460 ciType* type = pop_value();
duke@435 461 assert(is_long(type), "must be long");
duke@435 462 assert(type2 == long2_type(), "must be 2nd half");
duke@435 463 overwrite_local_double_long(index);
duke@435 464 set_type_at(local(index), type);
duke@435 465 set_type_at(local(index+1), type2);
never@802 466 store_to_local(index);
never@802 467 store_to_local(index+1);
duke@435 468 }
duke@435 469
duke@435 470 // Stop interpretation of this path with a trap.
duke@435 471 void trap(ciBytecodeStream* str, ciKlass* klass, int index);
duke@435 472
duke@435 473 public:
duke@435 474 StateVector(ciTypeFlow* outer);
duke@435 475
duke@435 476 // Copy our value into some other StateVector
duke@435 477 void copy_into(StateVector* copy) const;
duke@435 478
duke@435 479 // Meets this StateVector with another, destructively modifying this
duke@435 480 // one. Returns true if any modification takes place.
duke@435 481 bool meet(const StateVector* incoming);
duke@435 482
duke@435 483 // Ditto, except that the incoming state is coming from an exception.
duke@435 484 bool meet_exception(ciInstanceKlass* exc, const StateVector* incoming);
duke@435 485
duke@435 486 // Apply the effect of one bytecode to this StateVector
duke@435 487 bool apply_one_bytecode(ciBytecodeStream* stream);
duke@435 488
duke@435 489 // What is the bci of the trap?
duke@435 490 int trap_bci() { return _trap_bci; }
duke@435 491
duke@435 492 // What is the index associated with the trap?
duke@435 493 int trap_index() { return _trap_index; }
duke@435 494
duke@435 495 void print_cell_on(outputStream* st, Cell c) const PRODUCT_RETURN;
duke@435 496 void print_on(outputStream* st) const PRODUCT_RETURN;
duke@435 497 };
duke@435 498
duke@435 499 // Parameter for "find_block" calls:
never@802 500 // Describes the difference between a public and backedge copy.
duke@435 501 enum CreateOption {
duke@435 502 create_public_copy,
never@802 503 create_backedge_copy,
duke@435 504 no_create
duke@435 505 };
duke@435 506
never@802 507 // Successor iterator
never@802 508 class SuccIter : public StackObj {
never@802 509 private:
never@802 510 Block* _pred;
never@802 511 int _index;
never@802 512 Block* _succ;
never@802 513 public:
never@802 514 SuccIter() : _pred(NULL), _index(-1), _succ(NULL) {}
never@802 515 SuccIter(Block* pred) : _pred(pred), _index(-1), _succ(NULL) { next(); }
never@802 516 int index() { return _index; }
never@802 517 Block* pred() { return _pred; } // Return predecessor
never@802 518 bool done() { return _index < 0; } // Finished?
never@802 519 Block* succ() { return _succ; } // Return current successor
never@802 520 void next(); // Advance
never@802 521 void set_succ(Block* succ); // Update current successor
never@802 522 bool is_normal_ctrl() { return index() < _pred->successors()->length(); }
never@802 523 };
never@802 524
duke@435 525 // A basic block
duke@435 526 class Block : public ResourceObj {
duke@435 527 private:
duke@435 528 ciBlock* _ciblock;
duke@435 529 GrowableArray<Block*>* _exceptions;
duke@435 530 GrowableArray<ciInstanceKlass*>* _exc_klasses;
duke@435 531 GrowableArray<Block*>* _successors;
duke@435 532 StateVector* _state;
duke@435 533 JsrSet* _jsrs;
duke@435 534
duke@435 535 int _trap_bci;
duke@435 536 int _trap_index;
duke@435 537
never@802 538 // pre_order, assigned at first visit. Used as block ID and "visited" tag
duke@435 539 int _pre_order;
duke@435 540
never@802 541 // A post-order, used to compute the reverse post order (RPO) provided to the client
never@802 542 int _post_order; // used to compute rpo
never@802 543
never@802 544 // Has this block been cloned for a loop backedge?
never@802 545 bool _backedge_copy;
duke@435 546
kvn@3406 547 // This block is entry to irreducible loop.
kvn@3406 548 bool _irreducible_entry;
kvn@3406 549
kvn@3406 550 // This block has monitor entry point.
kvn@3406 551 bool _has_monitorenter;
kvn@3406 552
duke@435 553 // A pointer used for our internal work list
kvn@3406 554 bool _on_work_list; // on the work list
never@802 555 Block* _next;
never@802 556 Block* _rpo_next; // Reverse post order list
never@802 557
never@802 558 // Loop info
never@802 559 Loop* _loop; // nearest loop
duke@435 560
duke@435 561 ciBlock* ciblock() const { return _ciblock; }
duke@435 562 StateVector* state() const { return _state; }
duke@435 563
duke@435 564 // Compute the exceptional successors and types for this Block.
duke@435 565 void compute_exceptions();
duke@435 566
duke@435 567 public:
duke@435 568 // constructors
duke@435 569 Block(ciTypeFlow* outer, ciBlock* ciblk, JsrSet* jsrs);
duke@435 570
duke@435 571 void set_trap(int trap_bci, int trap_index) {
duke@435 572 _trap_bci = trap_bci;
duke@435 573 _trap_index = trap_index;
duke@435 574 assert(has_trap(), "");
duke@435 575 }
duke@435 576 bool has_trap() const { return _trap_bci != -1; }
duke@435 577 int trap_bci() const { assert(has_trap(), ""); return _trap_bci; }
duke@435 578 int trap_index() const { assert(has_trap(), ""); return _trap_index; }
duke@435 579
duke@435 580 // accessors
duke@435 581 ciTypeFlow* outer() const { return state()->outer(); }
duke@435 582 int start() const { return _ciblock->start_bci(); }
duke@435 583 int limit() const { return _ciblock->limit_bci(); }
duke@435 584 int control() const { return _ciblock->control_bci(); }
never@802 585 JsrSet* jsrs() const { return _jsrs; }
duke@435 586
never@802 587 bool is_backedge_copy() const { return _backedge_copy; }
never@802 588 void set_backedge_copy(bool z);
never@802 589 int backedge_copy_count() const { return outer()->backedge_copy_count(ciblock()->index(), _jsrs); }
duke@435 590
duke@435 591 // access to entry state
duke@435 592 int stack_size() const { return _state->stack_size(); }
duke@435 593 int monitor_count() const { return _state->monitor_count(); }
duke@435 594 ciType* local_type_at(int i) const { return _state->local_type_at(i); }
duke@435 595 ciType* stack_type_at(int i) const { return _state->stack_type_at(i); }
duke@435 596
never@802 597 // Data flow on locals
never@802 598 bool is_invariant_local(uint v) const {
never@802 599 assert(is_loop_head(), "only loop heads");
never@802 600 // Find outermost loop with same loop head
never@802 601 Loop* lp = loop();
never@802 602 while (lp->parent() != NULL) {
never@802 603 if (lp->parent()->head() != lp->head()) break;
never@802 604 lp = lp->parent();
never@802 605 }
never@802 606 return !lp->def_locals()->test(v);
never@802 607 }
never@802 608 LocalSet* def_locals() { return _state->def_locals(); }
never@802 609 const LocalSet* def_locals() const { return _state->def_locals(); }
never@802 610
duke@435 611 // Get the successors for this Block.
duke@435 612 GrowableArray<Block*>* successors(ciBytecodeStream* str,
duke@435 613 StateVector* state,
duke@435 614 JsrSet* jsrs);
duke@435 615 GrowableArray<Block*>* successors() {
duke@435 616 assert(_successors != NULL, "must be filled in");
duke@435 617 return _successors;
duke@435 618 }
duke@435 619
duke@435 620 // Get the exceptional successors for this Block.
duke@435 621 GrowableArray<Block*>* exceptions() {
duke@435 622 if (_exceptions == NULL) {
duke@435 623 compute_exceptions();
duke@435 624 }
duke@435 625 return _exceptions;
duke@435 626 }
duke@435 627
duke@435 628 // Get the exception klasses corresponding to the
duke@435 629 // exceptional successors for this Block.
duke@435 630 GrowableArray<ciInstanceKlass*>* exc_klasses() {
duke@435 631 if (_exc_klasses == NULL) {
duke@435 632 compute_exceptions();
duke@435 633 }
duke@435 634 return _exc_klasses;
duke@435 635 }
duke@435 636
duke@435 637 // Is this Block compatible with a given JsrSet?
duke@435 638 bool is_compatible_with(JsrSet* other) {
duke@435 639 return _jsrs->is_compatible_with(other);
duke@435 640 }
duke@435 641
duke@435 642 // Copy the value of our state vector into another.
duke@435 643 void copy_state_into(StateVector* copy) const {
duke@435 644 _state->copy_into(copy);
duke@435 645 }
duke@435 646
duke@435 647 // Copy the value of our JsrSet into another
duke@435 648 void copy_jsrs_into(JsrSet* copy) const {
duke@435 649 _jsrs->copy_into(copy);
duke@435 650 }
duke@435 651
duke@435 652 // Meets the start state of this block with another state, destructively
duke@435 653 // modifying this one. Returns true if any modification takes place.
duke@435 654 bool meet(const StateVector* incoming) {
duke@435 655 return state()->meet(incoming);
duke@435 656 }
duke@435 657
duke@435 658 // Ditto, except that the incoming state is coming from an
duke@435 659 // exception path. This means the stack is replaced by the
duke@435 660 // appropriate exception type.
duke@435 661 bool meet_exception(ciInstanceKlass* exc, const StateVector* incoming) {
duke@435 662 return state()->meet_exception(exc, incoming);
duke@435 663 }
duke@435 664
duke@435 665 // Work list manipulation
duke@435 666 void set_next(Block* block) { _next = block; }
duke@435 667 Block* next() const { return _next; }
duke@435 668
duke@435 669 void set_on_work_list(bool c) { _on_work_list = c; }
duke@435 670 bool is_on_work_list() const { return _on_work_list; }
duke@435 671
duke@435 672 bool has_pre_order() const { return _pre_order >= 0; }
never@802 673 void set_pre_order(int po) { assert(!has_pre_order(), ""); _pre_order = po; }
duke@435 674 int pre_order() const { assert(has_pre_order(), ""); return _pre_order; }
never@802 675 void set_next_pre_order() { set_pre_order(outer()->inc_next_pre_order()); }
duke@435 676 bool is_start() const { return _pre_order == outer()->start_block_num(); }
duke@435 677
never@802 678 // Reverse post order
never@802 679 void df_init();
never@802 680 bool has_post_order() const { return _post_order >= 0; }
never@802 681 void set_post_order(int po) { assert(!has_post_order() && po >= 0, ""); _post_order = po; }
never@802 682 void reset_post_order(int o){ _post_order = o; }
never@802 683 int post_order() const { assert(has_post_order(), ""); return _post_order; }
never@802 684
never@802 685 bool has_rpo() const { return has_post_order() && outer()->have_block_count(); }
never@802 686 int rpo() const { assert(has_rpo(), ""); return outer()->block_count() - post_order() - 1; }
never@802 687 void set_rpo_next(Block* b) { _rpo_next = b; }
never@802 688 Block* rpo_next() { return _rpo_next; }
never@802 689
never@802 690 // Loops
never@802 691 Loop* loop() const { return _loop; }
never@802 692 void set_loop(Loop* lp) { _loop = lp; }
never@802 693 bool is_loop_head() const { return _loop && _loop->head() == this; }
never@802 694 void set_irreducible_entry(bool c) { _irreducible_entry = c; }
never@802 695 bool is_irreducible_entry() const { return _irreducible_entry; }
kvn@3406 696 void set_has_monitorenter() { _has_monitorenter = true; }
kvn@3406 697 bool has_monitorenter() const { return _has_monitorenter; }
never@802 698 bool is_visited() const { return has_pre_order(); }
never@802 699 bool is_post_visited() const { return has_post_order(); }
never@802 700 bool is_clonable_exit(Loop* lp);
never@802 701 Block* looping_succ(Loop* lp); // Successor inside of loop
never@802 702 bool is_single_entry_loop_head() const {
never@802 703 if (!is_loop_head()) return false;
never@802 704 for (Loop* lp = loop(); lp != NULL && lp->head() == this; lp = lp->parent())
never@802 705 if (lp->is_irreducible()) return false;
never@802 706 return true;
never@802 707 }
duke@435 708
duke@435 709 void print_value_on(outputStream* st) const PRODUCT_RETURN;
duke@435 710 void print_on(outputStream* st) const PRODUCT_RETURN;
duke@435 711 };
duke@435 712
never@802 713 // Loop
never@802 714 class Loop : public ResourceObj {
never@802 715 private:
never@802 716 Loop* _parent;
never@802 717 Loop* _sibling; // List of siblings, null terminated
never@802 718 Loop* _child; // Head of child list threaded thru sibling pointer
never@802 719 Block* _head; // Head of loop
never@802 720 Block* _tail; // Tail of loop
never@802 721 bool _irreducible;
never@802 722 LocalSet _def_locals;
never@802 723
never@802 724 public:
never@802 725 Loop(Block* head, Block* tail) :
never@802 726 _head(head), _tail(tail),
never@802 727 _parent(NULL), _sibling(NULL), _child(NULL),
never@802 728 _irreducible(false), _def_locals() {}
never@802 729
never@802 730 Loop* parent() const { return _parent; }
never@802 731 Loop* sibling() const { return _sibling; }
never@802 732 Loop* child() const { return _child; }
never@802 733 Block* head() const { return _head; }
never@802 734 Block* tail() const { return _tail; }
never@802 735 void set_parent(Loop* p) { _parent = p; }
never@802 736 void set_sibling(Loop* s) { _sibling = s; }
never@802 737 void set_child(Loop* c) { _child = c; }
never@802 738 void set_head(Block* hd) { _head = hd; }
never@802 739 void set_tail(Block* tl) { _tail = tl; }
never@802 740
never@802 741 int depth() const; // nesting depth
never@802 742
never@802 743 // Returns true if lp is a nested loop or us.
never@802 744 bool contains(Loop* lp) const;
never@802 745 bool contains(Block* blk) const { return contains(blk->loop()); }
never@802 746
never@802 747 // Data flow on locals
never@802 748 LocalSet* def_locals() { return &_def_locals; }
never@802 749 const LocalSet* def_locals() const { return &_def_locals; }
never@802 750
never@802 751 // Merge the branch lp into this branch, sorting on the loop head
never@802 752 // pre_orders. Returns the new branch.
never@802 753 Loop* sorted_merge(Loop* lp);
never@802 754
never@802 755 // Mark non-single entry to loop
never@802 756 void set_irreducible(Block* entry) {
never@802 757 _irreducible = true;
never@802 758 entry->set_irreducible_entry(true);
never@802 759 }
never@802 760 bool is_irreducible() const { return _irreducible; }
never@802 761
never@802 762 bool is_root() const { return _tail->pre_order() == max_jint; }
never@802 763
never@802 764 void print(outputStream* st = tty, int indent = 0) const PRODUCT_RETURN;
never@802 765 };
never@802 766
never@802 767 // Postorder iteration over the loop tree.
never@802 768 class PostorderLoops : public StackObj {
never@802 769 private:
never@802 770 Loop* _root;
never@802 771 Loop* _current;
never@802 772 public:
never@802 773 PostorderLoops(Loop* root) : _root(root), _current(root) {
never@802 774 while (_current->child() != NULL) {
never@802 775 _current = _current->child();
never@802 776 }
never@802 777 }
never@802 778 bool done() { return _current == NULL; } // Finished iterating?
never@802 779 void next(); // Advance to next loop
never@802 780 Loop* current() { return _current; } // Return current loop.
never@802 781 };
never@802 782
never@802 783 // Preorder iteration over the loop tree.
never@802 784 class PreorderLoops : public StackObj {
never@802 785 private:
never@802 786 Loop* _root;
never@802 787 Loop* _current;
never@802 788 public:
never@802 789 PreorderLoops(Loop* root) : _root(root), _current(root) {}
never@802 790 bool done() { return _current == NULL; } // Finished iterating?
never@802 791 void next(); // Advance to next loop
never@802 792 Loop* current() { return _current; } // Return current loop.
never@802 793 };
never@802 794
duke@435 795 // Standard indexes of successors, for various bytecodes.
duke@435 796 enum {
duke@435 797 FALL_THROUGH = 0, // normal control
duke@435 798 IF_NOT_TAKEN = 0, // the not-taken branch of an if (i.e., fall-through)
duke@435 799 IF_TAKEN = 1, // the taken branch of an if
duke@435 800 GOTO_TARGET = 0, // unique successor for goto, jsr, or ret
duke@435 801 SWITCH_DEFAULT = 0, // default branch of a switch
duke@435 802 SWITCH_CASES = 1 // first index for any non-default switch branches
duke@435 803 // Unlike in other blocks, the successors of a switch are listed uniquely.
duke@435 804 };
duke@435 805
duke@435 806 private:
duke@435 807 // A mapping from pre_order to Blocks. This array is created
duke@435 808 // only at the end of the flow.
duke@435 809 Block** _block_map;
duke@435 810
duke@435 811 // For each ciBlock index, a list of Blocks which share this ciBlock.
duke@435 812 GrowableArray<Block*>** _idx_to_blocklist;
duke@435 813 // count of ciBlocks
duke@435 814 int _ciblock_count;
duke@435 815
duke@435 816 // Tells if a given instruction is able to generate an exception edge.
duke@435 817 bool can_trap(ciBytecodeStream& str);
duke@435 818
never@802 819 // Clone the loop heads. Returns true if any cloning occurred.
never@802 820 bool clone_loop_heads(Loop* lp, StateVector* temp_vector, JsrSet* temp_set);
never@802 821
never@802 822 // Clone lp's head and replace tail's successors with clone.
never@802 823 Block* clone_loop_head(Loop* lp, StateVector* temp_vector, JsrSet* temp_set);
never@802 824
duke@435 825 public:
duke@435 826 // Return the block beginning at bci which has a JsrSet compatible
duke@435 827 // with jsrs.
duke@435 828 Block* block_at(int bci, JsrSet* set, CreateOption option = create_public_copy);
duke@435 829
duke@435 830 // block factory
duke@435 831 Block* get_block_for(int ciBlockIndex, JsrSet* jsrs, CreateOption option = create_public_copy);
duke@435 832
never@802 833 // How many of the blocks have the backedge_copy bit set?
never@802 834 int backedge_copy_count(int ciBlockIndex, JsrSet* jsrs) const;
duke@435 835
duke@435 836 // Return an existing block containing bci which has a JsrSet compatible
duke@435 837 // with jsrs, or NULL if there is none.
duke@435 838 Block* existing_block_at(int bci, JsrSet* set) { return block_at(bci, set, no_create); }
duke@435 839
duke@435 840 // Tell whether the flow analysis has encountered an error of some sort.
duke@435 841 bool failing() { return env()->failing() || _failure_reason != NULL; }
duke@435 842
duke@435 843 // Reason this compilation is failing, such as "too many basic blocks".
duke@435 844 const char* failure_reason() { return _failure_reason; }
duke@435 845
duke@435 846 // Note a failure.
duke@435 847 void record_failure(const char* reason);
duke@435 848
duke@435 849 // Return the block of a given pre-order number.
duke@435 850 int have_block_count() const { return _block_map != NULL; }
duke@435 851 int block_count() const { assert(have_block_count(), "");
duke@435 852 return _next_pre_order; }
duke@435 853 Block* pre_order_at(int po) const { assert(0 <= po && po < block_count(), "out of bounds");
duke@435 854 return _block_map[po]; }
duke@435 855 Block* start_block() const { return pre_order_at(start_block_num()); }
duke@435 856 int start_block_num() const { return 0; }
never@802 857 Block* rpo_at(int rpo) const { assert(0 <= rpo && rpo < block_count(), "out of bounds");
never@802 858 return _block_map[rpo]; }
never@802 859 int next_pre_order() { return _next_pre_order; }
never@802 860 int inc_next_pre_order() { return _next_pre_order++; }
duke@435 861
duke@435 862 private:
duke@435 863 // A work list used during flow analysis.
duke@435 864 Block* _work_list;
duke@435 865
never@802 866 // List of blocks in reverse post order
never@802 867 Block* _rpo_list;
never@802 868
duke@435 869 // Next Block::_pre_order. After mapping, doubles as block_count.
duke@435 870 int _next_pre_order;
duke@435 871
duke@435 872 // Are there more blocks on the work list?
duke@435 873 bool work_list_empty() { return _work_list == NULL; }
duke@435 874
duke@435 875 // Get the next basic block from our work list.
duke@435 876 Block* work_list_next();
duke@435 877
duke@435 878 // Add a basic block to our work list.
duke@435 879 void add_to_work_list(Block* block);
duke@435 880
never@802 881 // Prepend a basic block to rpo list.
never@802 882 void prepend_to_rpo_list(Block* blk) {
never@802 883 blk->set_rpo_next(_rpo_list);
never@802 884 _rpo_list = blk;
never@802 885 }
never@802 886
never@802 887 // Root of the loop tree
never@802 888 Loop* _loop_tree_root;
never@802 889
duke@435 890 // State used for make_jsr_record
duke@435 891 int _jsr_count;
duke@435 892 GrowableArray<JsrRecord*>* _jsr_records;
duke@435 893
duke@435 894 public:
duke@435 895 // Make a JsrRecord for a given (entry, return) pair, if such a record
duke@435 896 // does not already exist.
duke@435 897 JsrRecord* make_jsr_record(int entry_address, int return_address);
duke@435 898
never@802 899 void set_loop_tree_root(Loop* ltr) { _loop_tree_root = ltr; }
never@802 900 Loop* loop_tree_root() { return _loop_tree_root; }
never@802 901
duke@435 902 private:
duke@435 903 // Get the initial state for start_bci:
duke@435 904 const StateVector* get_start_state();
duke@435 905
duke@435 906 // Merge the current state into all exceptional successors at the
duke@435 907 // current point in the code.
duke@435 908 void flow_exceptions(GrowableArray<Block*>* exceptions,
duke@435 909 GrowableArray<ciInstanceKlass*>* exc_klasses,
duke@435 910 StateVector* state);
duke@435 911
duke@435 912 // Merge the current state into all successors at the current point
duke@435 913 // in the code.
duke@435 914 void flow_successors(GrowableArray<Block*>* successors,
duke@435 915 StateVector* state);
duke@435 916
duke@435 917 // Interpret the effects of the bytecodes on the incoming state
duke@435 918 // vector of a basic block. Push the changed state to succeeding
duke@435 919 // basic blocks.
duke@435 920 void flow_block(Block* block,
duke@435 921 StateVector* scratch_state,
duke@435 922 JsrSet* scratch_jsrs);
duke@435 923
duke@435 924 // Perform the type flow analysis, creating and cloning Blocks as
duke@435 925 // necessary.
duke@435 926 void flow_types();
duke@435 927
never@802 928 // Perform the depth first type flow analysis. Helper for flow_types.
never@802 929 void df_flow_types(Block* start,
never@802 930 bool do_flow,
never@802 931 StateVector* temp_vector,
never@802 932 JsrSet* temp_set);
never@802 933
never@802 934 // Incrementally build loop tree.
never@802 935 void build_loop_tree(Block* blk);
never@802 936
duke@435 937 // Create the block map, which indexes blocks in pre_order.
duke@435 938 void map_blocks();
duke@435 939
duke@435 940 public:
duke@435 941 // Perform type inference flow analysis.
duke@435 942 void do_flow();
duke@435 943
duke@435 944 void print_on(outputStream* st) const PRODUCT_RETURN;
never@802 945
never@802 946 void rpo_print_on(outputStream* st) const PRODUCT_RETURN;
duke@435 947 };
stefank@2314 948
stefank@2314 949 #endif // SHARE_VM_CI_CITYPEFLOW_HPP

mercurial