/* * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
int Instruction::dominator_depth() { int result = -1; if (block()) {
result = block()->dominator_depth();
}
assert(result != -1 || this->as_Local(), "Only locals have dominator depth -1"); return result;
}
Instruction::Condition Instruction::mirror(Condition cond) { switch (cond) { case eql: return eql; case neq: return neq; case lss: return gtr; case leq: return geq; case gtr: return lss; case geq: return leq; case aeq: return beq; case beq: return aeq;
}
ShouldNotReachHere(); return eql;
}
Instruction::Condition Instruction::negate(Condition cond) { switch (cond) { case eql: return neq; case neq: return eql; case lss: return geq; case leq: return gtr; case gtr: return leq; case geq: return lss; case aeq: assert(false, "Above equal cannot be negated"); case beq: assert(false, "Below equal cannot be negated");
}
ShouldNotReachHere(); return eql;
}
// Prev without need to have BlockBegin
Instruction* Instruction::prev() {
Instruction* p = NULL;
Instruction* q = block(); while (q != this) {
assert(q != NULL, "this is not in the block's instruction list");
p = q; q = q->next();
} return p;
}
void Instruction::state_values_do(ValueVisitor* f) { if (state_before() != NULL) {
state_before()->values_do(f);
} if (exception_state() != NULL){
exception_state()->values_do(f);
}
}
bool ArithmeticOp::is_commutative() const { switch (op()) { case Bytecodes::_iadd: // fall through case Bytecodes::_ladd: // fall through case Bytecodes::_fadd: // fall through case Bytecodes::_dadd: // fall through case Bytecodes::_imul: // fall through case Bytecodes::_lmul: // fall through case Bytecodes::_fmul: // fall through case Bytecodes::_dmul: returntrue; default : returnfalse;
}
}
bool ArithmeticOp::can_trap() const { switch (op()) { case Bytecodes::_idiv: // fall through case Bytecodes::_ldiv: // fall through case Bytecodes::_irem: // fall through case Bytecodes::_lrem: returntrue; default : returnfalse;
}
}
// Implementation of LogicOp
bool LogicOp::is_commutative() const { #ifdef ASSERT switch (op()) { case Bytecodes::_iand: // fall through case Bytecodes::_land: // fall through case Bytecodes::_ior : // fall through case Bytecodes::_lor : // fall through case Bytecodes::_ixor: // fall through case Bytecodes::_lxor: break; default : ShouldNotReachHere(); break;
} #endif // all LogicOps are commutative returntrue;
}
// provide an initial guess of signature size.
_signature = new BasicTypeList(number_of_arguments() + (has_receiver() ? 1 : 0)); if (has_receiver()) {
_signature->append(as_BasicType(receiver()->type()));
} for (int i = 0; i < number_of_arguments(); i++) {
ValueType* t = argument_at(i)->type();
BasicType bt = as_BasicType(t);
_signature->append(bt);
}
}
void Invoke::state_values_do(ValueVisitor* f) {
StateSplit::state_values_do(f); if (state_before() != NULL) state_before()->values_do(f); if (state() != NULL) state()->values_do(f);
}
Constant::CompareResult Constant::compare(Instruction::Condition cond, Value right) const {
Constant* rc = right->as_Constant(); // other is not a constant if (rc == NULL) return not_comparable;
ValueType* lt = type();
ValueType* rt = rc->type(); // different types if (lt->base() != rt->base()) return not_comparable; switch (lt->tag()) { case intTag: { int x = lt->as_IntConstant()->value(); int y = rt->as_IntConstant()->value(); switch (cond) { caseIf::eql: return x == y ? cond_true : cond_false; caseIf::neq: return x != y ? cond_true : cond_false; caseIf::lss: return x < y ? cond_true : cond_false; caseIf::leq: return x <= y ? cond_true : cond_false; caseIf::gtr: return x > y ? cond_true : cond_false; caseIf::geq: return x >= y ? cond_true : cond_false; default : break;
} break;
} case longTag: {
jlong x = lt->as_LongConstant()->value();
jlong y = rt->as_LongConstant()->value(); switch (cond) { caseIf::eql: return x == y ? cond_true : cond_false; caseIf::neq: return x != y ? cond_true : cond_false; caseIf::lss: return x < y ? cond_true : cond_false; caseIf::leq: return x <= y ? cond_true : cond_false; caseIf::gtr: return x > y ? cond_true : cond_false; caseIf::geq: return x >= y ? cond_true : cond_false; default : break;
} break;
} case objectTag: {
ciObject* xvalue = lt->as_ObjectType()->constant_value();
ciObject* yvalue = rt->as_ObjectType()->constant_value();
assert(xvalue != NULL && yvalue != NULL, "not constants"); if (xvalue->is_loaded() && yvalue->is_loaded()) { switch (cond) { caseIf::eql: return xvalue == yvalue ? cond_true : cond_false; caseIf::neq: return xvalue != yvalue ? cond_true : cond_false; default : break;
}
} break;
} case metaDataTag: {
ciMetadata* xvalue = lt->as_MetadataType()->constant_value();
ciMetadata* yvalue = rt->as_MetadataType()->constant_value();
assert(xvalue != NULL && yvalue != NULL, "not constants"); if (xvalue->is_loaded() && yvalue->is_loaded()) { switch (cond) { caseIf::eql: return xvalue == yvalue ? cond_true : cond_false; caseIf::neq: return xvalue != yvalue ? cond_true : cond_false; default : break;
}
} break;
} default: break;
} return not_comparable;
}
// Implementation of BlockBegin
void BlockBegin::set_end(BlockEnd* new_end) { // Assumes that no predecessor of new_end still has it as its successor
assert(new_end != NULL, "Should not reset block new_end to NULL"); if (new_end == _end) return;
// Remove this block as predecessor of its current successors if (_end != NULL) { for (int i = 0; i < number_of_sux(); i++) {
sux_at(i)->remove_predecessor(this);
}
}
_end = new_end;
// Add this block as predecessor of its new successors for (int i = 0; i < number_of_sux(); i++) {
sux_at(i)->add_predecessor(this);
}
}
void BlockBegin::disconnect_edge(BlockBegin* from, BlockBegin* to) { // disconnect any edges between from and to #ifndef PRODUCT if (PrintIR && Verbose) {
tty->print_cr("Disconnected edge B%d -> B%d", from->block_id(), to->block_id());
} #endif for (int s = 0; s < from->number_of_sux();) {
BlockBegin* sux = from->sux_at(s); if (sux == to) { int index = sux->_predecessors.find(from); if (index >= 0) {
sux->_predecessors.remove_at(index);
}
from->end()->remove_sux_at(s);
} else {
s++;
}
}
}
void BlockBegin::substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux) { // modify predecessors before substituting successors for (int i = 0; i < number_of_sux(); i++) { if (sux_at(i) == old_sux) { // remove old predecessor before adding new predecessor // otherwise there is a dead predecessor in the list
new_sux->remove_predecessor(old_sux);
new_sux->add_predecessor(this);
}
}
old_sux->remove_predecessor(this);
end()->substitute_sux(old_sux, new_sux);
}
// In general it is not possible to calculate a value for the field "depth_first_number" // of the inserted block, without recomputing the values of the other blocks // in the CFG. Therefore the value of "depth_first_number" in BlockBegin becomes meaningless.
BlockBegin* BlockBegin::insert_block_between(BlockBegin* sux) { int bci = sux->bci(); // critical edge splitting may introduce a goto after a if and array // bound check elimination may insert a predicate between the if and // goto. The bci of the goto can't be the one of the if otherwise // the state and bci are inconsistent and a deoptimization triggered // by the predicate would lead to incorrect execution/a crash.
BlockBegin* new_sux = new BlockBegin(bci);
// mark this block (special treatment when block order is computed)
new_sux->set(critical_edge_split_flag);
// This goto is not a safepoint. Goto* e = newGoto(sux, false);
new_sux->set_next(e, bci);
new_sux->set_end(e); // setup states
ValueStack* s = end()->state();
new_sux->set_state(s->copy(s->kind(), bci));
e->set_state(s->copy(s->kind(), bci));
assert(new_sux->state()->locals_size() == s->locals_size(), "local size mismatch!");
assert(new_sux->state()->stack_size() == s->stack_size(), "stack size mismatch!");
assert(new_sux->state()->locks_size() == s->locks_size(), "locks size mismatch!");
// link predecessor to new block
end()->substitute_sux(sux, new_sux);
// The ordering needs to be the same, so remove the link that the // set_end call above added and substitute the new_sux for this // block.
sux->remove_predecessor(new_sux);
// the successor could be the target of a switch so it might have // multiple copies of this predecessor, so substitute the new_sux // for the first and delete the rest. bool assigned = false;
BlockList& list = sux->_predecessors; for (int i = 0; i < list.length(); i++) {
BlockBegin** b = list.adr_at(i); if (*b == this) { if (assigned) {
list.remove_at(i); // reprocess this index
i--;
} else {
assigned = true;
*b = new_sux;
} // link the new block back to it's predecessors.
new_sux->add_predecessor(this);
}
}
assert(assigned == true, "should have assigned at least once"); return new_sux;
}
void BlockBegin::remove_predecessor(BlockBegin* pred) { int idx; while ((idx = _predecessors.find(pred)) >= 0) {
_predecessors.remove_at(idx);
}
}
void BlockBegin::add_exception_handler(BlockBegin* b) {
assert(b != NULL && (b->is_set(exception_entry_flag)), "exception handler must exist"); // add only if not in the list already if (!_exception_handlers.contains(b)) _exception_handlers.append(b);
}
int BlockBegin::add_exception_state(ValueStack* state) {
assert(is_set(exception_entry_flag), "only for xhandlers"); if (_exception_states == NULL) {
_exception_states = new ValueStackStack(4);
}
_exception_states->append(state); return _exception_states->length() - 1;
}
void BlockBegin::iterate_preorder(boolArray& mark, BlockClosure* closure) { if (!mark.at(block_id())) {
mark.at_put(block_id(), true);
closure->block_do(this);
BlockEnd* e = end(); // must do this after block_do because block_do may change it!
{ for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_preorder(mark, closure); }
{ for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_preorder(mark, closure); }
}
}
void BlockBegin::iterate_postorder(boolArray& mark, BlockClosure* closure) { if (!mark.at(block_id())) {
mark.at_put(block_id(), true);
BlockEnd* e = end();
{ for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_postorder(mark, closure); }
{ for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_postorder(mark, closure); }
closure->block_do(this);
}
}
// local variables used for state iteration int index;
Value new_value, existing_value;
ValueStack* existing_state = state(); if (existing_state == NULL) {
TRACE_PHI(tty->print_cr("first call of try_merge for this block"));
if (is_set(BlockBegin::was_visited_flag)) { // this actually happens for complicated jsr/ret structures returnfalse; // BAILOUT in caller
}
// copy state because it is altered
new_state = new_state->copy(ValueStack::BlockBeginState, bci());
// Use method liveness to invalidate dead locals
MethodLivenessResult liveness = new_state->scope()->method()->liveness_at_bci(bci()); if (liveness.is_valid()) {
assert((int)liveness.size() == new_state->locals_size(), "error in use of liveness");
for_each_local_value(new_state, index, new_value) { if (!liveness.at(index) || new_value->type()->is_illegal()) {
new_state->invalidate_local(index);
TRACE_PHI(tty->print_cr("invalidating dead local %d", index));
}
}
}
if (is_set(BlockBegin::parser_loop_header_flag)) {
TRACE_PHI(tty->print_cr("loop header block, initializing phi functions"));
if (is_set(BlockBegin::was_visited_flag)) {
TRACE_PHI(tty->print_cr("loop header block, phis must be present"));
if (!is_set(BlockBegin::parser_loop_header_flag)) { // this actually happens for complicated jsr/ret structures returnfalse; // BAILOUT in caller
}
for_each_local_value(existing_state, index, existing_value) {
Value new_value = new_state->local_at(index); if (new_value == NULL || new_value->type()->tag() != existing_value->type()->tag()) {
Phi* existing_phi = existing_value->as_Phi(); if (existing_phi == NULL) { returnfalse; // BAILOUT in caller
} // Invalidate the phi function here. This case is very rare except for // JVMTI capability "can_access_local_variables". // In really rare cases we will bail out in LIRGenerator::move_to_phi.
existing_phi->make_illegal();
existing_state->invalidate_local(index);
TRACE_PHI(tty->print_cr("invalidating local %d because of type mismatch", index));
}
if (existing_value != new_state->local_at(index) && existing_value->as_Phi() == NULL) {
TRACE_PHI(tty->print_cr("required phi for local %d is missing, irreducible loop?", index)); returnfalse; // BAILOUT in caller
}
}
#ifdef ASSERT // check that all necessary phi functions are present
for_each_stack_value(existing_state, index, existing_value) {
assert(existing_value->as_Phi() != NULL && existing_value->as_Phi()->block() == this, "phi function required");
}
for_each_local_value(existing_state, index, existing_value) {
assert(existing_value == new_state->local_at(index) || (existing_value->as_Phi() != NULL && existing_value->as_Phi()->as_Phi()->block() == this), "phi function required");
} #endif
} else {
TRACE_PHI(tty->print_cr("creating phi functions on demand"));
// create necessary phi functions for stack
for_each_stack_value(existing_state, index, existing_value) {
Value new_value = new_state->stack_at(index);
Phi* existing_phi = existing_value->as_Phi();
// Normal phi functions take their operands from the last instruction of the // predecessor. Special handling is needed for xhanlder entries because there // the state of arbitrary instructions are needed.
Value Phi::operand_at(int i) const {
ValueStack* state; if (_block->is_set(BlockBegin::exception_entry_flag)) {
state = _block->exception_state_at(i);
} else {
state = _block->pred_at(i)->end()->state();
}
assert(state != NULL, "");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.