duke@435: /* duke@435: * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: duke@435: class ciTypeFlow : public ResourceObj { duke@435: private: duke@435: ciEnv* _env; duke@435: ciMethod* _method; duke@435: ciMethodBlocks* _methodBlocks; duke@435: int _osr_bci; duke@435: duke@435: // information cached from the method: duke@435: int _max_locals; duke@435: int _max_stack; duke@435: int _code_size; duke@435: duke@435: const char* _failure_reason; duke@435: duke@435: public: duke@435: class StateVector; duke@435: class Block; duke@435: duke@435: // Build a type flow analyzer duke@435: // Do an OSR analysis if osr_bci >= 0. duke@435: ciTypeFlow(ciEnv* env, ciMethod* method, int osr_bci = InvocationEntryBci); duke@435: duke@435: // Accessors duke@435: ciMethod* method() const { return _method; } duke@435: ciEnv* env() { return _env; } duke@435: Arena* arena() { return _env->arena(); } duke@435: bool is_osr_flow() const{ return _osr_bci != InvocationEntryBci; } duke@435: int start_bci() const { return is_osr_flow()? _osr_bci: 0; } duke@435: int max_locals() const { return _max_locals; } duke@435: int max_stack() const { return _max_stack; } duke@435: int max_cells() const { return _max_locals + _max_stack; } duke@435: int code_size() const { return _code_size; } duke@435: duke@435: // Represents information about an "active" jsr call. This duke@435: // class represents a call to the routine at some entry address duke@435: // with some distinct return address. duke@435: class JsrRecord : public ResourceObj { duke@435: private: duke@435: int _entry_address; duke@435: int _return_address; duke@435: public: duke@435: JsrRecord(int entry_address, int return_address) { duke@435: _entry_address = entry_address; duke@435: _return_address = return_address; duke@435: } duke@435: duke@435: int entry_address() const { return _entry_address; } duke@435: int return_address() const { return _return_address; } duke@435: duke@435: void print_on(outputStream* st) const { duke@435: #ifndef PRODUCT duke@435: st->print("%d->%d", entry_address(), return_address()); duke@435: #endif duke@435: } duke@435: }; duke@435: duke@435: // A JsrSet represents some set of JsrRecords. This class duke@435: // is used to record a set of all jsr routines which we permit duke@435: // execution to return (ret) from. duke@435: // duke@435: // During abstract interpretation, JsrSets are used to determine duke@435: // whether two paths which reach a given block are unique, and duke@435: // should be cloned apart, or are compatible, and should merge duke@435: // together. duke@435: // duke@435: // Note that different amounts of effort can be expended determining duke@435: // if paths are compatible. duke@435: class JsrSet : public ResourceObj { duke@435: private: duke@435: GrowableArray* _set; duke@435: duke@435: JsrRecord* record_at(int i) { duke@435: return _set->at(i); duke@435: } duke@435: duke@435: // Insert the given JsrRecord into the JsrSet, maintaining the order duke@435: // of the set and replacing any element with the same entry address. duke@435: void insert_jsr_record(JsrRecord* record); duke@435: duke@435: // Remove the JsrRecord with the given return address from the JsrSet. duke@435: void remove_jsr_record(int return_address); duke@435: duke@435: public: duke@435: JsrSet(Arena* arena, int default_len = 4); duke@435: duke@435: // Copy this JsrSet. duke@435: void copy_into(JsrSet* jsrs); duke@435: duke@435: // Is this JsrSet compatible with some other JsrSet? duke@435: bool is_compatible_with(JsrSet* other); duke@435: duke@435: // Apply the effect of a single bytecode to the JsrSet. duke@435: void apply_control(ciTypeFlow* analyzer, duke@435: ciBytecodeStream* str, duke@435: StateVector* state); duke@435: duke@435: // What is the cardinality of this set? duke@435: int size() const { return _set->length(); } duke@435: duke@435: void print_on(outputStream* st) const PRODUCT_RETURN; duke@435: }; duke@435: duke@435: // Used as a combined index for locals and temps duke@435: enum Cell { duke@435: Cell_0 duke@435: }; duke@435: duke@435: // A StateVector summarizes the type information at some duke@435: // point in the program duke@435: class StateVector : public ResourceObj { duke@435: private: duke@435: ciType** _types; duke@435: int _stack_size; duke@435: int _monitor_count; duke@435: ciTypeFlow* _outer; duke@435: duke@435: int _trap_bci; duke@435: int _trap_index; duke@435: duke@435: static ciType* type_meet_internal(ciType* t1, ciType* t2, ciTypeFlow* analyzer); duke@435: duke@435: public: duke@435: // Special elements in our type lattice. duke@435: enum { duke@435: T_TOP = T_VOID, // why not? duke@435: T_BOTTOM = T_CONFLICT, duke@435: T_LONG2 = T_SHORT, // 2nd word of T_LONG duke@435: T_DOUBLE2 = T_CHAR, // 2nd word of T_DOUBLE duke@435: T_NULL = T_BYTE // for now. duke@435: }; duke@435: static ciType* top_type() { return ciType::make((BasicType)T_TOP); } duke@435: static ciType* bottom_type() { return ciType::make((BasicType)T_BOTTOM); } duke@435: static ciType* long2_type() { return ciType::make((BasicType)T_LONG2); } duke@435: static ciType* double2_type(){ return ciType::make((BasicType)T_DOUBLE2); } duke@435: static ciType* null_type() { return ciType::make((BasicType)T_NULL); } duke@435: duke@435: static ciType* half_type(ciType* t) { duke@435: switch (t->basic_type()) { duke@435: case T_LONG: return long2_type(); duke@435: case T_DOUBLE: return double2_type(); duke@435: default: ShouldNotReachHere(); return NULL; duke@435: } duke@435: } duke@435: duke@435: // The meet operation for our type lattice. duke@435: ciType* type_meet(ciType* t1, ciType* t2) { duke@435: return type_meet_internal(t1, t2, outer()); duke@435: } duke@435: duke@435: // Accessors duke@435: ciTypeFlow* outer() const { return _outer; } duke@435: duke@435: int stack_size() const { return _stack_size; } duke@435: void set_stack_size(int ss) { _stack_size = ss; } duke@435: duke@435: int monitor_count() const { return _monitor_count; } duke@435: void set_monitor_count(int mc) { _monitor_count = mc; } duke@435: duke@435: static Cell start_cell() { return (Cell)0; } duke@435: static Cell next_cell(Cell c) { return (Cell)(((int)c) + 1); } duke@435: Cell limit_cell() const { duke@435: return (Cell)(outer()->max_locals() + stack_size()); duke@435: } duke@435: duke@435: // Cell creation duke@435: Cell local(int lnum) const { duke@435: assert(lnum < outer()->max_locals(), "index check"); duke@435: return (Cell)(lnum); duke@435: } duke@435: duke@435: Cell stack(int snum) const { duke@435: assert(snum < stack_size(), "index check"); duke@435: return (Cell)(outer()->max_locals() + snum); duke@435: } duke@435: duke@435: Cell tos() const { return stack(stack_size()-1); } duke@435: duke@435: // For external use only: duke@435: ciType* local_type_at(int i) const { return type_at(local(i)); } duke@435: ciType* stack_type_at(int i) const { return type_at(stack(i)); } duke@435: duke@435: // Accessors for the type of some Cell c duke@435: ciType* type_at(Cell c) const { duke@435: assert(start_cell() <= c && c < limit_cell(), "out of bounds"); duke@435: return _types[c]; duke@435: } duke@435: duke@435: void set_type_at(Cell c, ciType* type) { duke@435: assert(start_cell() <= c && c < limit_cell(), "out of bounds"); duke@435: _types[c] = type; duke@435: } duke@435: duke@435: // Top-of-stack operations. duke@435: void set_type_at_tos(ciType* type) { set_type_at(tos(), type); } duke@435: ciType* type_at_tos() const { return type_at(tos()); } duke@435: duke@435: void push(ciType* type) { duke@435: _stack_size++; duke@435: set_type_at_tos(type); duke@435: } duke@435: void pop() { duke@435: debug_only(set_type_at_tos(bottom_type())); duke@435: _stack_size--; duke@435: } duke@435: ciType* pop_value() { duke@435: ciType* t = type_at_tos(); duke@435: pop(); duke@435: return t; duke@435: } duke@435: duke@435: // Convenience operations. duke@435: bool is_reference(ciType* type) const { duke@435: return type == null_type() || !type->is_primitive_type(); duke@435: } duke@435: bool is_int(ciType* type) const { duke@435: return type->basic_type() == T_INT; duke@435: } duke@435: bool is_long(ciType* type) const { duke@435: return type->basic_type() == T_LONG; duke@435: } duke@435: bool is_float(ciType* type) const { duke@435: return type->basic_type() == T_FLOAT; duke@435: } duke@435: bool is_double(ciType* type) const { duke@435: return type->basic_type() == T_DOUBLE; duke@435: } duke@435: duke@435: void push_translate(ciType* type); duke@435: duke@435: void push_int() { duke@435: push(ciType::make(T_INT)); duke@435: } duke@435: void pop_int() { duke@435: assert(is_int(type_at_tos()), "must be integer"); duke@435: pop(); duke@435: } duke@435: void check_int(Cell c) { duke@435: assert(is_int(type_at(c)), "must be integer"); duke@435: } duke@435: void push_double() { duke@435: push(ciType::make(T_DOUBLE)); duke@435: push(double2_type()); duke@435: } duke@435: void pop_double() { duke@435: assert(type_at_tos() == double2_type(), "must be 2nd half"); duke@435: pop(); duke@435: assert(is_double(type_at_tos()), "must be double"); duke@435: pop(); duke@435: } duke@435: void push_float() { duke@435: push(ciType::make(T_FLOAT)); duke@435: } duke@435: void pop_float() { duke@435: assert(is_float(type_at_tos()), "must be float"); duke@435: pop(); duke@435: } duke@435: void push_long() { duke@435: push(ciType::make(T_LONG)); duke@435: push(long2_type()); duke@435: } duke@435: void pop_long() { duke@435: assert(type_at_tos() == long2_type(), "must be 2nd half"); duke@435: pop(); duke@435: assert(is_long(type_at_tos()), "must be long"); duke@435: pop(); duke@435: } duke@435: void push_object(ciKlass* klass) { duke@435: push(klass); duke@435: } duke@435: void pop_object() { duke@435: assert(is_reference(type_at_tos()), "must be reference type"); duke@435: pop(); duke@435: } duke@435: void pop_array() { duke@435: assert(type_at_tos() == null_type() || duke@435: type_at_tos()->is_array_klass(), "must be array type"); duke@435: pop(); duke@435: } duke@435: // pop_objArray and pop_typeArray narrow the tos to ciObjArrayKlass duke@435: // or ciTypeArrayKlass (resp.). In the rare case that an explicit duke@435: // null is popped from the stack, we return NULL. Caller beware. duke@435: ciObjArrayKlass* pop_objArray() { duke@435: ciType* array = pop_value(); duke@435: if (array == null_type()) return NULL; duke@435: assert(array->is_obj_array_klass(), "must be object array type"); duke@435: return array->as_obj_array_klass(); duke@435: } duke@435: ciTypeArrayKlass* pop_typeArray() { duke@435: ciType* array = pop_value(); duke@435: if (array == null_type()) return NULL; duke@435: assert(array->is_type_array_klass(), "must be prim array type"); duke@435: return array->as_type_array_klass(); duke@435: } duke@435: void push_null() { duke@435: push(null_type()); duke@435: } duke@435: void do_null_assert(ciKlass* unloaded_klass); duke@435: duke@435: // Helper convenience routines. duke@435: void do_aaload(ciBytecodeStream* str); duke@435: void do_checkcast(ciBytecodeStream* str); duke@435: void do_getfield(ciBytecodeStream* str); duke@435: void do_getstatic(ciBytecodeStream* str); duke@435: void do_invoke(ciBytecodeStream* str, bool has_receiver); duke@435: void do_jsr(ciBytecodeStream* str); duke@435: void do_ldc(ciBytecodeStream* str); duke@435: void do_multianewarray(ciBytecodeStream* str); duke@435: void do_new(ciBytecodeStream* str); duke@435: void do_newarray(ciBytecodeStream* str); duke@435: void do_putfield(ciBytecodeStream* str); duke@435: void do_putstatic(ciBytecodeStream* str); duke@435: void do_ret(ciBytecodeStream* str); duke@435: duke@435: void overwrite_local_double_long(int index) { duke@435: // Invalidate the previous local if it contains first half of duke@435: // a double or long value since it's seconf half is being overwritten. duke@435: int prev_index = index - 1; duke@435: if (prev_index >= 0 && duke@435: (is_double(type_at(local(prev_index))) || duke@435: is_long(type_at(local(prev_index))))) { duke@435: set_type_at(local(prev_index), bottom_type()); duke@435: } duke@435: } duke@435: duke@435: void load_local_object(int index) { duke@435: ciType* type = type_at(local(index)); duke@435: assert(is_reference(type), "must be reference type"); duke@435: push(type); duke@435: } duke@435: void store_local_object(int index) { duke@435: ciType* type = pop_value(); duke@435: assert(is_reference(type) || type->is_return_address(), duke@435: "must be reference type or return address"); duke@435: overwrite_local_double_long(index); duke@435: set_type_at(local(index), type); duke@435: } duke@435: duke@435: void load_local_double(int index) { duke@435: ciType* type = type_at(local(index)); duke@435: ciType* type2 = type_at(local(index+1)); duke@435: assert(is_double(type), "must be double type"); duke@435: assert(type2 == double2_type(), "must be 2nd half"); duke@435: push(type); duke@435: push(double2_type()); duke@435: } duke@435: void store_local_double(int index) { duke@435: ciType* type2 = pop_value(); duke@435: ciType* type = pop_value(); duke@435: assert(is_double(type), "must be double"); duke@435: assert(type2 == double2_type(), "must be 2nd half"); duke@435: overwrite_local_double_long(index); duke@435: set_type_at(local(index), type); duke@435: set_type_at(local(index+1), type2); duke@435: } duke@435: duke@435: void load_local_float(int index) { duke@435: ciType* type = type_at(local(index)); duke@435: assert(is_float(type), "must be float type"); duke@435: push(type); duke@435: } duke@435: void store_local_float(int index) { duke@435: ciType* type = pop_value(); duke@435: assert(is_float(type), "must be float type"); duke@435: overwrite_local_double_long(index); duke@435: set_type_at(local(index), type); duke@435: } duke@435: duke@435: void load_local_int(int index) { duke@435: ciType* type = type_at(local(index)); duke@435: assert(is_int(type), "must be int type"); duke@435: push(type); duke@435: } duke@435: void store_local_int(int index) { duke@435: ciType* type = pop_value(); duke@435: assert(is_int(type), "must be int type"); duke@435: overwrite_local_double_long(index); duke@435: set_type_at(local(index), type); duke@435: } duke@435: duke@435: void load_local_long(int index) { duke@435: ciType* type = type_at(local(index)); duke@435: ciType* type2 = type_at(local(index+1)); duke@435: assert(is_long(type), "must be long type"); duke@435: assert(type2 == long2_type(), "must be 2nd half"); duke@435: push(type); duke@435: push(long2_type()); duke@435: } duke@435: void store_local_long(int index) { duke@435: ciType* type2 = pop_value(); duke@435: ciType* type = pop_value(); duke@435: assert(is_long(type), "must be long"); duke@435: assert(type2 == long2_type(), "must be 2nd half"); duke@435: overwrite_local_double_long(index); duke@435: set_type_at(local(index), type); duke@435: set_type_at(local(index+1), type2); duke@435: } duke@435: duke@435: // Stop interpretation of this path with a trap. duke@435: void trap(ciBytecodeStream* str, ciKlass* klass, int index); duke@435: duke@435: public: duke@435: StateVector(ciTypeFlow* outer); duke@435: duke@435: // Copy our value into some other StateVector duke@435: void copy_into(StateVector* copy) const; duke@435: duke@435: // Meets this StateVector with another, destructively modifying this duke@435: // one. Returns true if any modification takes place. duke@435: bool meet(const StateVector* incoming); duke@435: duke@435: // Ditto, except that the incoming state is coming from an exception. duke@435: bool meet_exception(ciInstanceKlass* exc, const StateVector* incoming); duke@435: duke@435: // Apply the effect of one bytecode to this StateVector duke@435: bool apply_one_bytecode(ciBytecodeStream* stream); duke@435: duke@435: // What is the bci of the trap? duke@435: int trap_bci() { return _trap_bci; } duke@435: duke@435: // What is the index associated with the trap? duke@435: int trap_index() { return _trap_index; } duke@435: duke@435: void print_cell_on(outputStream* st, Cell c) const PRODUCT_RETURN; duke@435: void print_on(outputStream* st) const PRODUCT_RETURN; duke@435: }; duke@435: duke@435: // Parameter for "find_block" calls: duke@435: // Describes the difference between a public and private copy. duke@435: enum CreateOption { duke@435: create_public_copy, duke@435: create_private_copy, duke@435: no_create duke@435: }; duke@435: duke@435: // A basic block duke@435: class Block : public ResourceObj { duke@435: private: duke@435: ciBlock* _ciblock; duke@435: GrowableArray* _exceptions; duke@435: GrowableArray* _exc_klasses; duke@435: GrowableArray* _successors; duke@435: StateVector* _state; duke@435: JsrSet* _jsrs; duke@435: duke@435: int _trap_bci; duke@435: int _trap_index; duke@435: duke@435: // A reasonable approximation to pre-order, provided.to the client. duke@435: int _pre_order; duke@435: duke@435: // Has this block been cloned for some special purpose? duke@435: bool _private_copy; duke@435: duke@435: // A pointer used for our internal work list duke@435: Block* _next; duke@435: bool _on_work_list; duke@435: duke@435: ciBlock* ciblock() const { return _ciblock; } duke@435: StateVector* state() const { return _state; } duke@435: duke@435: // Compute the exceptional successors and types for this Block. duke@435: void compute_exceptions(); duke@435: duke@435: public: duke@435: // constructors duke@435: Block(ciTypeFlow* outer, ciBlock* ciblk, JsrSet* jsrs); duke@435: duke@435: void set_trap(int trap_bci, int trap_index) { duke@435: _trap_bci = trap_bci; duke@435: _trap_index = trap_index; duke@435: assert(has_trap(), ""); duke@435: } duke@435: bool has_trap() const { return _trap_bci != -1; } duke@435: int trap_bci() const { assert(has_trap(), ""); return _trap_bci; } duke@435: int trap_index() const { assert(has_trap(), ""); return _trap_index; } duke@435: duke@435: // accessors duke@435: ciTypeFlow* outer() const { return state()->outer(); } duke@435: int start() const { return _ciblock->start_bci(); } duke@435: int limit() const { return _ciblock->limit_bci(); } duke@435: int control() const { return _ciblock->control_bci(); } duke@435: duke@435: bool is_private_copy() const { return _private_copy; } duke@435: void set_private_copy(bool z); duke@435: int private_copy_count() const { return outer()->private_copy_count(ciblock()->index(), _jsrs); } duke@435: duke@435: // access to entry state duke@435: int stack_size() const { return _state->stack_size(); } duke@435: int monitor_count() const { return _state->monitor_count(); } duke@435: ciType* local_type_at(int i) const { return _state->local_type_at(i); } duke@435: ciType* stack_type_at(int i) const { return _state->stack_type_at(i); } duke@435: duke@435: // Get the successors for this Block. duke@435: GrowableArray* successors(ciBytecodeStream* str, duke@435: StateVector* state, duke@435: JsrSet* jsrs); duke@435: GrowableArray* successors() { duke@435: assert(_successors != NULL, "must be filled in"); duke@435: return _successors; duke@435: } duke@435: duke@435: // Helper function for "successors" when making private copies of duke@435: // loop heads for C2. duke@435: Block * clone_loop_head(ciTypeFlow* analyzer, duke@435: int branch_bci, duke@435: Block* target, duke@435: JsrSet* jsrs); duke@435: duke@435: // Get the exceptional successors for this Block. duke@435: GrowableArray* exceptions() { duke@435: if (_exceptions == NULL) { duke@435: compute_exceptions(); duke@435: } duke@435: return _exceptions; duke@435: } duke@435: duke@435: // Get the exception klasses corresponding to the duke@435: // exceptional successors for this Block. duke@435: GrowableArray* exc_klasses() { duke@435: if (_exc_klasses == NULL) { duke@435: compute_exceptions(); duke@435: } duke@435: return _exc_klasses; duke@435: } duke@435: duke@435: // Is this Block compatible with a given JsrSet? duke@435: bool is_compatible_with(JsrSet* other) { duke@435: return _jsrs->is_compatible_with(other); duke@435: } duke@435: duke@435: // Copy the value of our state vector into another. duke@435: void copy_state_into(StateVector* copy) const { duke@435: _state->copy_into(copy); duke@435: } duke@435: duke@435: // Copy the value of our JsrSet into another duke@435: void copy_jsrs_into(JsrSet* copy) const { duke@435: _jsrs->copy_into(copy); duke@435: } duke@435: duke@435: // Meets the start state of this block with another state, destructively duke@435: // modifying this one. Returns true if any modification takes place. duke@435: bool meet(const StateVector* incoming) { duke@435: return state()->meet(incoming); duke@435: } duke@435: duke@435: // Ditto, except that the incoming state is coming from an duke@435: // exception path. This means the stack is replaced by the duke@435: // appropriate exception type. duke@435: bool meet_exception(ciInstanceKlass* exc, const StateVector* incoming) { duke@435: return state()->meet_exception(exc, incoming); duke@435: } duke@435: duke@435: // Work list manipulation duke@435: void set_next(Block* block) { _next = block; } duke@435: Block* next() const { return _next; } duke@435: duke@435: void set_on_work_list(bool c) { _on_work_list = c; } duke@435: bool is_on_work_list() const { return _on_work_list; } duke@435: duke@435: bool has_pre_order() const { return _pre_order >= 0; } duke@435: void set_pre_order(int po) { assert(!has_pre_order() && po >= 0, ""); _pre_order = po; } duke@435: int pre_order() const { assert(has_pre_order(), ""); return _pre_order; } duke@435: bool is_start() const { return _pre_order == outer()->start_block_num(); } duke@435: duke@435: // A ranking used in determining order within the work list. duke@435: bool is_simpler_than(Block* other); duke@435: duke@435: void print_value_on(outputStream* st) const PRODUCT_RETURN; duke@435: void print_on(outputStream* st) const PRODUCT_RETURN; duke@435: }; duke@435: duke@435: // Standard indexes of successors, for various bytecodes. duke@435: enum { duke@435: FALL_THROUGH = 0, // normal control duke@435: IF_NOT_TAKEN = 0, // the not-taken branch of an if (i.e., fall-through) duke@435: IF_TAKEN = 1, // the taken branch of an if duke@435: GOTO_TARGET = 0, // unique successor for goto, jsr, or ret duke@435: SWITCH_DEFAULT = 0, // default branch of a switch duke@435: SWITCH_CASES = 1 // first index for any non-default switch branches duke@435: // Unlike in other blocks, the successors of a switch are listed uniquely. duke@435: }; duke@435: duke@435: private: duke@435: // A mapping from pre_order to Blocks. This array is created duke@435: // only at the end of the flow. duke@435: Block** _block_map; duke@435: duke@435: // For each ciBlock index, a list of Blocks which share this ciBlock. duke@435: GrowableArray** _idx_to_blocklist; duke@435: // count of ciBlocks duke@435: int _ciblock_count; duke@435: duke@435: // Tells if a given instruction is able to generate an exception edge. duke@435: bool can_trap(ciBytecodeStream& str); duke@435: duke@435: public: duke@435: // Return the block beginning at bci which has a JsrSet compatible duke@435: // with jsrs. duke@435: Block* block_at(int bci, JsrSet* set, CreateOption option = create_public_copy); duke@435: duke@435: // block factory duke@435: Block* get_block_for(int ciBlockIndex, JsrSet* jsrs, CreateOption option = create_public_copy); duke@435: duke@435: // How many of the blocks have the private_copy bit set? duke@435: int private_copy_count(int ciBlockIndex, JsrSet* jsrs) const; duke@435: duke@435: // Return an existing block containing bci which has a JsrSet compatible duke@435: // with jsrs, or NULL if there is none. duke@435: Block* existing_block_at(int bci, JsrSet* set) { return block_at(bci, set, no_create); } duke@435: duke@435: // Tell whether the flow analysis has encountered an error of some sort. duke@435: bool failing() { return env()->failing() || _failure_reason != NULL; } duke@435: duke@435: // Reason this compilation is failing, such as "too many basic blocks". duke@435: const char* failure_reason() { return _failure_reason; } duke@435: duke@435: // Note a failure. duke@435: void record_failure(const char* reason); duke@435: duke@435: // Return the block of a given pre-order number. duke@435: int have_block_count() const { return _block_map != NULL; } duke@435: int block_count() const { assert(have_block_count(), ""); duke@435: return _next_pre_order; } duke@435: Block* pre_order_at(int po) const { assert(0 <= po && po < block_count(), "out of bounds"); duke@435: return _block_map[po]; } duke@435: Block* start_block() const { return pre_order_at(start_block_num()); } duke@435: int start_block_num() const { return 0; } duke@435: duke@435: private: duke@435: // A work list used during flow analysis. duke@435: Block* _work_list; duke@435: duke@435: // Next Block::_pre_order. After mapping, doubles as block_count. duke@435: int _next_pre_order; duke@435: duke@435: // Are there more blocks on the work list? duke@435: bool work_list_empty() { return _work_list == NULL; } duke@435: duke@435: // Get the next basic block from our work list. duke@435: Block* work_list_next(); duke@435: duke@435: // Add a basic block to our work list. duke@435: void add_to_work_list(Block* block); duke@435: duke@435: // State used for make_jsr_record duke@435: int _jsr_count; duke@435: GrowableArray* _jsr_records; duke@435: duke@435: public: duke@435: // Make a JsrRecord for a given (entry, return) pair, if such a record duke@435: // does not already exist. duke@435: JsrRecord* make_jsr_record(int entry_address, int return_address); duke@435: duke@435: private: duke@435: // Get the initial state for start_bci: duke@435: const StateVector* get_start_state(); duke@435: duke@435: // Merge the current state into all exceptional successors at the duke@435: // current point in the code. duke@435: void flow_exceptions(GrowableArray* exceptions, duke@435: GrowableArray* exc_klasses, duke@435: StateVector* state); duke@435: duke@435: // Merge the current state into all successors at the current point duke@435: // in the code. duke@435: void flow_successors(GrowableArray* successors, duke@435: StateVector* state); duke@435: duke@435: // Interpret the effects of the bytecodes on the incoming state duke@435: // vector of a basic block. Push the changed state to succeeding duke@435: // basic blocks. duke@435: void flow_block(Block* block, duke@435: StateVector* scratch_state, duke@435: JsrSet* scratch_jsrs); duke@435: duke@435: // Perform the type flow analysis, creating and cloning Blocks as duke@435: // necessary. duke@435: void flow_types(); duke@435: duke@435: // Create the block map, which indexes blocks in pre_order. duke@435: void map_blocks(); duke@435: duke@435: public: duke@435: // Perform type inference flow analysis. duke@435: void do_flow(); duke@435: duke@435: void print_on(outputStream* st) const PRODUCT_RETURN; duke@435: };