Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/c1/c1_Instruction.cpp
32285 views
/*1* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "c1/c1_IR.hpp"26#include "c1/c1_Instruction.hpp"27#include "c1/c1_InstructionPrinter.hpp"28#include "c1/c1_ValueStack.hpp"29#include "ci/ciObjArrayKlass.hpp"30#include "ci/ciTypeArrayKlass.hpp"313233// Implementation of Instruction343536int Instruction::dominator_depth() {37int result = -1;38if (block()) {39result = block()->dominator_depth();40}41assert(result != -1 || this->as_Local(), "Only locals have dominator depth -1");42return result;43}4445Instruction::Condition Instruction::mirror(Condition cond) {46switch (cond) {47case eql: return eql;48case neq: return neq;49case lss: return gtr;50case leq: return geq;51case gtr: return lss;52case geq: return leq;53case aeq: return beq;54case beq: return aeq;55}56ShouldNotReachHere();57return eql;58}596061Instruction::Condition Instruction::negate(Condition cond) {62switch (cond) {63case eql: return neq;64case neq: return eql;65case lss: return geq;66case leq: return gtr;67case gtr: return leq;68case geq: return lss;69case aeq: assert(false, "Above equal cannot be negated");70case beq: assert(false, "Below equal cannot be negated");71}72ShouldNotReachHere();73return eql;74}7576void Instruction::update_exception_state(ValueStack* state) {77if (state != NULL && (state->kind() == ValueStack::EmptyExceptionState || state->kind() == ValueStack::ExceptionState)) {78assert(state->kind() == ValueStack::EmptyExceptionState || Compilation::current()->env()->should_retain_local_variables(), "unexpected state kind");79_exception_state = state;80} else {81_exception_state = NULL;82}83}8485// Prev without need to have BlockBegin86Instruction* Instruction::prev() {87Instruction* p = NULL;88Instruction* q = block();89while (q != this) {90assert(q != NULL, "this is not in the block's instruction list");91p = q; q = q->next();92}93return p;94}959697void Instruction::state_values_do(ValueVisitor* f) {98if (state_before() != NULL) {99state_before()->values_do(f);100}101if (exception_state() != NULL){102exception_state()->values_do(f);103}104}105106ciType* Instruction::exact_type() const {107ciType* t = declared_type();108if (t != NULL && t->is_klass()) {109return t->as_klass()->exact_klass();110}111return NULL;112}113114115#ifndef PRODUCT116void Instruction::check_state(ValueStack* state) {117if (state != NULL) {118state->verify();119}120}121122123void Instruction::print() {124InstructionPrinter ip;125print(ip);126}127128129void Instruction::print_line() {130InstructionPrinter ip;131ip.print_line(this);132}133134135void Instruction::print(InstructionPrinter& ip) {136ip.print_head();137ip.print_line(this);138tty->cr();139}140#endif // PRODUCT141142143// perform constant and interval tests on index value144bool AccessIndexed::compute_needs_range_check() {145if (length()) {146Constant* clength = length()->as_Constant();147Constant* cindex = index()->as_Constant();148if (clength && cindex) {149IntConstant* l = clength->type()->as_IntConstant();150IntConstant* i = cindex->type()->as_IntConstant();151if (l && i && i->value() < l->value() && i->value() >= 0) {152return false;153}154}155}156157if (!this->check_flag(NeedsRangeCheckFlag)) {158return false;159}160161return true;162}163164165ciType* Constant::exact_type() const {166if (type()->is_object() && type()->as_ObjectType()->is_loaded()) {167return type()->as_ObjectType()->exact_type();168}169return NULL;170}171172ciType* LoadIndexed::exact_type() const {173ciType* array_type = array()->exact_type();174if (array_type != NULL) {175assert(array_type->is_array_klass(), "what else?");176ciArrayKlass* ak = (ciArrayKlass*)array_type;177178if (ak->element_type()->is_instance_klass()) {179ciInstanceKlass* ik = (ciInstanceKlass*)ak->element_type();180if (ik->is_loaded() && ik->is_final()) {181return ik;182}183}184}185return Instruction::exact_type();186}187188189ciType* LoadIndexed::declared_type() const {190ciType* array_type = array()->declared_type();191if (array_type == NULL || !array_type->is_loaded()) {192return NULL;193}194assert(array_type->is_array_klass(), "what else?");195ciArrayKlass* ak = (ciArrayKlass*)array_type;196return ak->element_type();197}198199200ciType* LoadField::declared_type() const {201return field()->type();202}203204205ciType* NewTypeArray::exact_type() const {206return ciTypeArrayKlass::make(elt_type());207}208209ciType* NewObjectArray::exact_type() const {210return ciObjArrayKlass::make(klass());211}212213ciType* NewArray::declared_type() const {214return exact_type();215}216217ciType* NewInstance::exact_type() const {218return klass();219}220221ciType* NewInstance::declared_type() const {222return exact_type();223}224225ciType* CheckCast::declared_type() const {226return klass();227}228229// Implementation of ArithmeticOp230231bool ArithmeticOp::is_commutative() const {232switch (op()) {233case Bytecodes::_iadd: // fall through234case Bytecodes::_ladd: // fall through235case Bytecodes::_fadd: // fall through236case Bytecodes::_dadd: // fall through237case Bytecodes::_imul: // fall through238case Bytecodes::_lmul: // fall through239case Bytecodes::_fmul: // fall through240case Bytecodes::_dmul: return true;241}242return false;243}244245246bool ArithmeticOp::can_trap() const {247switch (op()) {248case Bytecodes::_idiv: // fall through249case Bytecodes::_ldiv: // fall through250case Bytecodes::_irem: // fall through251case Bytecodes::_lrem: return true;252}253return false;254}255256257// Implementation of LogicOp258259bool LogicOp::is_commutative() const {260#ifdef ASSERT261switch (op()) {262case Bytecodes::_iand: // fall through263case Bytecodes::_land: // fall through264case Bytecodes::_ior : // fall through265case Bytecodes::_lor : // fall through266case Bytecodes::_ixor: // fall through267case Bytecodes::_lxor: break;268default : ShouldNotReachHere();269}270#endif271// all LogicOps are commutative272return true;273}274275276// Implementation of IfOp277278bool IfOp::is_commutative() const {279return cond() == eql || cond() == neq;280}281282283// Implementation of StateSplit284285void StateSplit::substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block) {286NOT_PRODUCT(bool assigned = false;)287for (int i = 0; i < list.length(); i++) {288BlockBegin** b = list.adr_at(i);289if (*b == old_block) {290*b = new_block;291NOT_PRODUCT(assigned = true;)292}293}294assert(assigned == true, "should have assigned at least once");295}296297298IRScope* StateSplit::scope() const {299return _state->scope();300}301302303void StateSplit::state_values_do(ValueVisitor* f) {304Instruction::state_values_do(f);305if (state() != NULL) state()->values_do(f);306}307308309void BlockBegin::state_values_do(ValueVisitor* f) {310StateSplit::state_values_do(f);311312if (is_set(BlockBegin::exception_entry_flag)) {313for (int i = 0; i < number_of_exception_states(); i++) {314exception_state_at(i)->values_do(f);315}316}317}318319320// Implementation of Invoke321322323Invoke::Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,324int vtable_index, ciMethod* target, ValueStack* state_before)325: StateSplit(result_type, state_before)326, _code(code)327, _recv(recv)328, _args(args)329, _vtable_index(vtable_index)330, _target(target)331{332set_flag(TargetIsLoadedFlag, target->is_loaded());333set_flag(TargetIsFinalFlag, target_is_loaded() && target->is_final_method());334set_flag(TargetIsStrictfpFlag, target_is_loaded() && target->is_strict());335336assert(args != NULL, "args must exist");337#ifdef ASSERT338AssertValues assert_value;339values_do(&assert_value);340#endif341342// provide an initial guess of signature size.343_signature = new BasicTypeList(number_of_arguments() + (has_receiver() ? 1 : 0));344if (has_receiver()) {345_signature->append(as_BasicType(receiver()->type()));346}347for (int i = 0; i < number_of_arguments(); i++) {348ValueType* t = argument_at(i)->type();349BasicType bt = as_BasicType(t);350_signature->append(bt);351}352}353354355void Invoke::state_values_do(ValueVisitor* f) {356StateSplit::state_values_do(f);357if (state_before() != NULL) state_before()->values_do(f);358if (state() != NULL) state()->values_do(f);359}360361ciType* Invoke::declared_type() const {362ciSignature* declared_signature = state()->scope()->method()->get_declared_signature_at_bci(state()->bci());363ciType *t = declared_signature->return_type();364assert(t->basic_type() != T_VOID, "need return value of void method?");365return t;366}367368// Implementation of Contant369intx Constant::hash() const {370if (state_before() == NULL) {371switch (type()->tag()) {372case intTag:373return HASH2(name(), type()->as_IntConstant()->value());374case addressTag:375return HASH2(name(), type()->as_AddressConstant()->value());376case longTag:377{378jlong temp = type()->as_LongConstant()->value();379return HASH3(name(), high(temp), low(temp));380}381case floatTag:382return HASH2(name(), jint_cast(type()->as_FloatConstant()->value()));383case doubleTag:384{385jlong temp = jlong_cast(type()->as_DoubleConstant()->value());386return HASH3(name(), high(temp), low(temp));387}388case objectTag:389assert(type()->as_ObjectType()->is_loaded(), "can't handle unloaded values");390return HASH2(name(), type()->as_ObjectType()->constant_value());391case metaDataTag:392assert(type()->as_MetadataType()->is_loaded(), "can't handle unloaded values");393return HASH2(name(), type()->as_MetadataType()->constant_value());394default:395ShouldNotReachHere();396}397}398return 0;399}400401bool Constant::is_equal(Value v) const {402if (v->as_Constant() == NULL) return false;403404switch (type()->tag()) {405case intTag:406{407IntConstant* t1 = type()->as_IntConstant();408IntConstant* t2 = v->type()->as_IntConstant();409return (t1 != NULL && t2 != NULL &&410t1->value() == t2->value());411}412case longTag:413{414LongConstant* t1 = type()->as_LongConstant();415LongConstant* t2 = v->type()->as_LongConstant();416return (t1 != NULL && t2 != NULL &&417t1->value() == t2->value());418}419case floatTag:420{421FloatConstant* t1 = type()->as_FloatConstant();422FloatConstant* t2 = v->type()->as_FloatConstant();423return (t1 != NULL && t2 != NULL &&424jint_cast(t1->value()) == jint_cast(t2->value()));425}426case doubleTag:427{428DoubleConstant* t1 = type()->as_DoubleConstant();429DoubleConstant* t2 = v->type()->as_DoubleConstant();430return (t1 != NULL && t2 != NULL &&431jlong_cast(t1->value()) == jlong_cast(t2->value()));432}433case objectTag:434{435ObjectType* t1 = type()->as_ObjectType();436ObjectType* t2 = v->type()->as_ObjectType();437return (t1 != NULL && t2 != NULL &&438t1->is_loaded() && t2->is_loaded() &&439t1->constant_value() == t2->constant_value());440}441case metaDataTag:442{443MetadataType* t1 = type()->as_MetadataType();444MetadataType* t2 = v->type()->as_MetadataType();445return (t1 != NULL && t2 != NULL &&446t1->is_loaded() && t2->is_loaded() &&447t1->constant_value() == t2->constant_value());448}449}450return false;451}452453Constant::CompareResult Constant::compare(Instruction::Condition cond, Value right) const {454Constant* rc = right->as_Constant();455// other is not a constant456if (rc == NULL) return not_comparable;457458ValueType* lt = type();459ValueType* rt = rc->type();460// different types461if (lt->base() != rt->base()) return not_comparable;462switch (lt->tag()) {463case intTag: {464int x = lt->as_IntConstant()->value();465int y = rt->as_IntConstant()->value();466switch (cond) {467case If::eql: return x == y ? cond_true : cond_false;468case If::neq: return x != y ? cond_true : cond_false;469case If::lss: return x < y ? cond_true : cond_false;470case If::leq: return x <= y ? cond_true : cond_false;471case If::gtr: return x > y ? cond_true : cond_false;472case If::geq: return x >= y ? cond_true : cond_false;473}474break;475}476case longTag: {477jlong x = lt->as_LongConstant()->value();478jlong y = rt->as_LongConstant()->value();479switch (cond) {480case If::eql: return x == y ? cond_true : cond_false;481case If::neq: return x != y ? cond_true : cond_false;482case If::lss: return x < y ? cond_true : cond_false;483case If::leq: return x <= y ? cond_true : cond_false;484case If::gtr: return x > y ? cond_true : cond_false;485case If::geq: return x >= y ? cond_true : cond_false;486}487break;488}489case objectTag: {490ciObject* xvalue = lt->as_ObjectType()->constant_value();491ciObject* yvalue = rt->as_ObjectType()->constant_value();492assert(xvalue != NULL && yvalue != NULL, "not constants");493if (xvalue->is_loaded() && yvalue->is_loaded()) {494switch (cond) {495case If::eql: return xvalue == yvalue ? cond_true : cond_false;496case If::neq: return xvalue != yvalue ? cond_true : cond_false;497}498}499break;500}501case metaDataTag: {502ciMetadata* xvalue = lt->as_MetadataType()->constant_value();503ciMetadata* yvalue = rt->as_MetadataType()->constant_value();504assert(xvalue != NULL && yvalue != NULL, "not constants");505if (xvalue->is_loaded() && yvalue->is_loaded()) {506switch (cond) {507case If::eql: return xvalue == yvalue ? cond_true : cond_false;508case If::neq: return xvalue != yvalue ? cond_true : cond_false;509}510}511break;512}513}514return not_comparable;515}516517518// Implementation of BlockBegin519520void BlockBegin::set_end(BlockEnd* end) {521assert(end != NULL, "should not reset block end to NULL");522if (end == _end) {523return;524}525clear_end();526527// Set the new end528_end = end;529530_successors.clear();531// Now reset successors list based on BlockEnd532for (int i = 0; i < end->number_of_sux(); i++) {533BlockBegin* sux = end->sux_at(i);534_successors.append(sux);535sux->_predecessors.append(this);536}537_end->set_begin(this);538}539540541void BlockBegin::clear_end() {542// Must make the predecessors/successors match up with the543// BlockEnd's notion.544if (_end != NULL) {545// disconnect from the old end546_end->set_begin(NULL);547548// disconnect this block from it's current successors549for (int i = 0; i < _successors.length(); i++) {550_successors.at(i)->remove_predecessor(this);551}552_end = NULL;553}554}555556557void BlockBegin::disconnect_edge(BlockBegin* from, BlockBegin* to) {558// disconnect any edges between from and to559#ifndef PRODUCT560if (PrintIR && Verbose) {561tty->print_cr("Disconnected edge B%d -> B%d", from->block_id(), to->block_id());562}563#endif564for (int s = 0; s < from->number_of_sux();) {565BlockBegin* sux = from->sux_at(s);566if (sux == to) {567int index = sux->_predecessors.index_of(from);568if (index >= 0) {569sux->_predecessors.remove_at(index);570}571from->_successors.remove_at(s);572} else {573s++;574}575}576}577578579void BlockBegin::disconnect_from_graph() {580// disconnect this block from all other blocks581for (int p = 0; p < number_of_preds(); p++) {582pred_at(p)->remove_successor(this);583}584for (int s = 0; s < number_of_sux(); s++) {585sux_at(s)->remove_predecessor(this);586}587}588589void BlockBegin::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) {590// modify predecessors before substituting successors591for (int i = 0; i < number_of_sux(); i++) {592if (sux_at(i) == old_sux) {593// remove old predecessor before adding new predecessor594// otherwise there is a dead predecessor in the list595new_sux->remove_predecessor(old_sux);596new_sux->add_predecessor(this);597}598}599old_sux->remove_predecessor(this);600end()->substitute_sux(old_sux, new_sux);601}602603604605// In general it is not possible to calculate a value for the field "depth_first_number"606// of the inserted block, without recomputing the values of the other blocks607// in the CFG. Therefore the value of "depth_first_number" in BlockBegin becomes meaningless.608BlockBegin* BlockBegin::insert_block_between(BlockBegin* sux) {609int bci = sux->bci();610// critical edge splitting may introduce a goto after a if and array611// bound check elimination may insert a predicate between the if and612// goto. The bci of the goto can't be the one of the if otherwise613// the state and bci are inconsistent and a deoptimization triggered614// by the predicate would lead to incorrect execution/a crash.615BlockBegin* new_sux = new BlockBegin(bci);616617// mark this block (special treatment when block order is computed)618new_sux->set(critical_edge_split_flag);619620// This goto is not a safepoint.621Goto* e = new Goto(sux, false);622new_sux->set_next(e, bci);623new_sux->set_end(e);624// setup states625ValueStack* s = end()->state();626new_sux->set_state(s->copy(s->kind(), bci));627e->set_state(s->copy(s->kind(), bci));628assert(new_sux->state()->locals_size() == s->locals_size(), "local size mismatch!");629assert(new_sux->state()->stack_size() == s->stack_size(), "stack size mismatch!");630assert(new_sux->state()->locks_size() == s->locks_size(), "locks size mismatch!");631632// link predecessor to new block633end()->substitute_sux(sux, new_sux);634635// The ordering needs to be the same, so remove the link that the636// set_end call above added and substitute the new_sux for this637// block.638sux->remove_predecessor(new_sux);639640// the successor could be the target of a switch so it might have641// multiple copies of this predecessor, so substitute the new_sux642// for the first and delete the rest.643bool assigned = false;644BlockList& list = sux->_predecessors;645for (int i = 0; i < list.length(); i++) {646BlockBegin** b = list.adr_at(i);647if (*b == this) {648if (assigned) {649list.remove_at(i);650// reprocess this index651i--;652} else {653assigned = true;654*b = new_sux;655}656// link the new block back to it's predecessors.657new_sux->add_predecessor(this);658}659}660assert(assigned == true, "should have assigned at least once");661return new_sux;662}663664665void BlockBegin::remove_successor(BlockBegin* pred) {666int idx;667while ((idx = _successors.index_of(pred)) >= 0) {668_successors.remove_at(idx);669}670}671672673void BlockBegin::add_predecessor(BlockBegin* pred) {674_predecessors.append(pred);675}676677678void BlockBegin::remove_predecessor(BlockBegin* pred) {679int idx;680while ((idx = _predecessors.index_of(pred)) >= 0) {681_predecessors.remove_at(idx);682}683}684685686void BlockBegin::add_exception_handler(BlockBegin* b) {687assert(b != NULL && (b->is_set(exception_entry_flag)), "exception handler must exist");688// add only if not in the list already689if (!_exception_handlers.contains(b)) _exception_handlers.append(b);690}691692int BlockBegin::add_exception_state(ValueStack* state) {693assert(is_set(exception_entry_flag), "only for xhandlers");694if (_exception_states == NULL) {695_exception_states = new ValueStackStack(4);696}697_exception_states->append(state);698return _exception_states->length() - 1;699}700701702void BlockBegin::iterate_preorder(boolArray& mark, BlockClosure* closure) {703if (!mark.at(block_id())) {704mark.at_put(block_id(), true);705closure->block_do(this);706BlockEnd* e = end(); // must do this after block_do because block_do may change it!707{ for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_preorder(mark, closure); }708{ for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_preorder(mark, closure); }709}710}711712713void BlockBegin::iterate_postorder(boolArray& mark, BlockClosure* closure) {714if (!mark.at(block_id())) {715mark.at_put(block_id(), true);716BlockEnd* e = end();717{ for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_postorder(mark, closure); }718{ for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_postorder(mark, closure); }719closure->block_do(this);720}721}722723724void BlockBegin::iterate_preorder(BlockClosure* closure) {725boolArray mark(number_of_blocks(), false);726iterate_preorder(mark, closure);727}728729730void BlockBegin::iterate_postorder(BlockClosure* closure) {731boolArray mark(number_of_blocks(), false);732iterate_postorder(mark, closure);733}734735736void BlockBegin::block_values_do(ValueVisitor* f) {737for (Instruction* n = this; n != NULL; n = n->next()) n->values_do(f);738}739740741#ifndef PRODUCT742#define TRACE_PHI(code) if (PrintPhiFunctions) { code; }743#else744#define TRACE_PHI(coce)745#endif746747748bool BlockBegin::try_merge(ValueStack* new_state) {749TRACE_PHI(tty->print_cr("********** try_merge for block B%d", block_id()));750751// local variables used for state iteration752int index;753Value new_value, existing_value;754755ValueStack* existing_state = state();756if (existing_state == NULL) {757TRACE_PHI(tty->print_cr("first call of try_merge for this block"));758759if (is_set(BlockBegin::was_visited_flag)) {760// this actually happens for complicated jsr/ret structures761return false; // BAILOUT in caller762}763764// copy state because it is altered765new_state = new_state->copy(ValueStack::BlockBeginState, bci());766767// Use method liveness to invalidate dead locals768MethodLivenessResult liveness = new_state->scope()->method()->liveness_at_bci(bci());769if (liveness.is_valid()) {770assert((int)liveness.size() == new_state->locals_size(), "error in use of liveness");771772for_each_local_value(new_state, index, new_value) {773if (!liveness.at(index) || new_value->type()->is_illegal()) {774new_state->invalidate_local(index);775TRACE_PHI(tty->print_cr("invalidating dead local %d", index));776}777}778}779780if (is_set(BlockBegin::parser_loop_header_flag)) {781TRACE_PHI(tty->print_cr("loop header block, initializing phi functions"));782783for_each_stack_value(new_state, index, new_value) {784new_state->setup_phi_for_stack(this, index);785TRACE_PHI(tty->print_cr("creating phi-function %c%d for stack %d", new_state->stack_at(index)->type()->tchar(), new_state->stack_at(index)->id(), index));786}787788BitMap requires_phi_function = new_state->scope()->requires_phi_function();789790for_each_local_value(new_state, index, new_value) {791bool requires_phi = requires_phi_function.at(index) || (new_value->type()->is_double_word() && requires_phi_function.at(index + 1));792if (requires_phi || !SelectivePhiFunctions) {793new_state->setup_phi_for_local(this, index);794TRACE_PHI(tty->print_cr("creating phi-function %c%d for local %d", new_state->local_at(index)->type()->tchar(), new_state->local_at(index)->id(), index));795}796}797}798799// initialize state of block800set_state(new_state);801802} else if (existing_state->is_same(new_state)) {803TRACE_PHI(tty->print_cr("exisiting state found"));804805assert(existing_state->scope() == new_state->scope(), "not matching");806assert(existing_state->locals_size() == new_state->locals_size(), "not matching");807assert(existing_state->stack_size() == new_state->stack_size(), "not matching");808809if (is_set(BlockBegin::was_visited_flag)) {810TRACE_PHI(tty->print_cr("loop header block, phis must be present"));811812if (!is_set(BlockBegin::parser_loop_header_flag)) {813// this actually happens for complicated jsr/ret structures814return false; // BAILOUT in caller815}816817for_each_local_value(existing_state, index, existing_value) {818Value new_value = new_state->local_at(index);819if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) {820// The old code invalidated the phi function here821// Because dead locals are replaced with NULL, this is a very rare case now, so simply bail out822return false; // BAILOUT in caller823}824}825826#ifdef ASSERT827// check that all necessary phi functions are present828for_each_stack_value(existing_state, index, existing_value) {829assert(existing_value->as_Phi() != NULL && existing_value->as_Phi()->block() == this, "phi function required");830}831for_each_local_value(existing_state, index, existing_value) {832assert(existing_value == new_state->local_at(index) || (existing_value->as_Phi() != NULL && existing_value->as_Phi()->as_Phi()->block() == this), "phi function required");833}834#endif835836} else {837TRACE_PHI(tty->print_cr("creating phi functions on demand"));838839// create necessary phi functions for stack840for_each_stack_value(existing_state, index, existing_value) {841Value new_value = new_state->stack_at(index);842Phi* existing_phi = existing_value->as_Phi();843844if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {845existing_state->setup_phi_for_stack(this, index);846TRACE_PHI(tty->print_cr("creating phi-function %c%d for stack %d", existing_state->stack_at(index)->type()->tchar(), existing_state->stack_at(index)->id(), index));847}848}849850// create necessary phi functions for locals851for_each_local_value(existing_state, index, existing_value) {852Value new_value = new_state->local_at(index);853Phi* existing_phi = existing_value->as_Phi();854855if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) {856existing_state->invalidate_local(index);857TRACE_PHI(tty->print_cr("invalidating local %d because of type mismatch", index));858} else if (new_value != existing_value && (existing_phi == NULL || existing_phi->block() != this)) {859existing_state->setup_phi_for_local(this, index);860TRACE_PHI(tty->print_cr("creating phi-function %c%d for local %d", existing_state->local_at(index)->type()->tchar(), existing_state->local_at(index)->id(), index));861}862}863}864865assert(existing_state->caller_state() == new_state->caller_state(), "caller states must be equal");866867} else {868assert(false, "stack or locks not matching (invalid bytecodes)");869return false;870}871872TRACE_PHI(tty->print_cr("********** try_merge for block B%d successful", block_id()));873874return true;875}876877878#ifndef PRODUCT879void BlockBegin::print_block() {880InstructionPrinter ip;881print_block(ip, false);882}883884885void BlockBegin::print_block(InstructionPrinter& ip, bool live_only) {886ip.print_instr(this); tty->cr();887ip.print_stack(this->state()); tty->cr();888ip.print_inline_level(this);889ip.print_head();890for (Instruction* n = next(); n != NULL; n = n->next()) {891if (!live_only || n->is_pinned() || n->use_count() > 0) {892ip.print_line(n);893}894}895tty->cr();896}897#endif // PRODUCT898899900// Implementation of BlockList901902void BlockList::iterate_forward (BlockClosure* closure) {903const int l = length();904for (int i = 0; i < l; i++) closure->block_do(at(i));905}906907908void BlockList::iterate_backward(BlockClosure* closure) {909for (int i = length() - 1; i >= 0; i--) closure->block_do(at(i));910}911912913void BlockList::blocks_do(void f(BlockBegin*)) {914for (int i = length() - 1; i >= 0; i--) f(at(i));915}916917918void BlockList::values_do(ValueVisitor* f) {919for (int i = length() - 1; i >= 0; i--) at(i)->block_values_do(f);920}921922923#ifndef PRODUCT924void BlockList::print(bool cfg_only, bool live_only) {925InstructionPrinter ip;926for (int i = 0; i < length(); i++) {927BlockBegin* block = at(i);928if (cfg_only) {929ip.print_instr(block); tty->cr();930} else {931block->print_block(ip, live_only);932}933}934}935#endif // PRODUCT936937938// Implementation of BlockEnd939940void BlockEnd::set_begin(BlockBegin* begin) {941BlockList* sux = NULL;942if (begin != NULL) {943sux = begin->successors();944} else if (this->begin() != NULL) {945// copy our sux list946BlockList* sux = new BlockList(this->begin()->number_of_sux());947for (int i = 0; i < this->begin()->number_of_sux(); i++) {948sux->append(this->begin()->sux_at(i));949}950}951_sux = sux;952}953954955void BlockEnd::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) {956substitute(*_sux, old_sux, new_sux);957}958959960// Implementation of Phi961962// Normal phi functions take their operands from the last instruction of the963// predecessor. Special handling is needed for xhanlder entries because there964// the state of arbitrary instructions are needed.965966Value Phi::operand_at(int i) const {967ValueStack* state;968if (_block->is_set(BlockBegin::exception_entry_flag)) {969state = _block->exception_state_at(i);970} else {971state = _block->pred_at(i)->end()->state();972}973assert(state != NULL, "");974975if (is_local()) {976return state->local_at(local_index());977} else {978return state->stack_at(stack_index());979}980}981982983int Phi::operand_count() const {984if (_block->is_set(BlockBegin::exception_entry_flag)) {985return _block->number_of_exception_states();986} else {987return _block->number_of_preds();988}989}990991#ifdef ASSERT992// Constructor of Assert993Assert::Assert(Value x, Condition cond, bool unordered_is_true, Value y) : Instruction(illegalType)994, _x(x)995, _cond(cond)996, _y(y)997{998set_flag(UnorderedIsTrueFlag, unordered_is_true);999assert(x->type()->tag() == y->type()->tag(), "types must match");1000pin();10011002stringStream strStream;1003Compilation::current()->method()->print_name(&strStream);10041005stringStream strStream1;1006InstructionPrinter ip1(1, &strStream1);1007ip1.print_instr(x);10081009stringStream strStream2;1010InstructionPrinter ip2(1, &strStream2);1011ip2.print_instr(y);10121013stringStream ss;1014ss.print("Assertion %s %s %s in method %s", strStream1.as_string(), ip2.cond_name(cond), strStream2.as_string(), strStream.as_string());10151016_message = ss.as_string();1017}1018#endif10191020void RangeCheckPredicate::check_state() {1021assert(state()->kind() != ValueStack::EmptyExceptionState && state()->kind() != ValueStack::ExceptionState, "will deopt with empty state");1022}10231024void ProfileInvoke::state_values_do(ValueVisitor* f) {1025if (state() != NULL) state()->values_do(f);1026}102710281029