/* * Copyright (c) 1997, 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. *
*/
uint ParmNode::ideal_reg() const { switch( _con ) { case TypeFunc::Control : // fall through case TypeFunc::I_O : // fall through case TypeFunc::Memory : return 0; case TypeFunc::FramePtr : // fall through case TypeFunc::ReturnAdr: return Op_RegP; default : assert( _con > TypeFunc::Parms, "" ); // fall through case TypeFunc::Parms : { // Type of argument being passed const Type *t = in(0)->as_Start()->_domain->field_at(_con); return t->ideal_reg();
}
}
ShouldNotReachHere(); return 0;
}
#ifndef PRODUCT void RethrowNode::dump_req(outputStream *st, DumpConfig* dc) const { // Dump the required inputs, after printing "exception"
uint i; // Exit value of loop for (i = 0; i < req(); i++) { // For all required inputs if (i == TypeFunc::Parms) st->print("exception ");
Node* p = in(i); if (p != nullptr) {
p->dump_idx(false, st, dc);
st->print(" ");
} else {
st->print("_ ");
}
}
} #endif
//============================================================================= // Do we Match on this edge index or not? Match only target address & method
uint TailCallNode::match_edge(uint idx) const { return TypeFunc::Parms <= idx && idx <= TypeFunc::Parms+1;
}
//============================================================================= // Do we Match on this edge index or not? Match only target address & oop
uint TailJumpNode::match_edge(uint idx) const { return TypeFunc::Parms <= idx && idx <= TypeFunc::Parms+1;
}
//-----------------------------same_calls_as----------------------------------- bool JVMState::same_calls_as(const JVMState* that) const { if (this == that) returntrue; if (this->depth() != that->depth()) returnfalse; const JVMState* p = this; const JVMState* q = that; for (;;) { if (p->_method != q->_method) returnfalse; if (p->_method == NULL) returntrue; // bci is irrelevant if (p->_bci != q->_bci) returnfalse; if (p->_reexecute != q->_reexecute) returnfalse;
p = p->caller();
q = q->caller(); if (p == q) returntrue;
assert(p != NULL && q != NULL, "depth check ensures we don't run off end");
}
}
//------------------------------debug_start------------------------------------
uint JVMState::debug_start() const {
debug_only(JVMState* jvmroot = of_depth(1));
assert(jvmroot->locoff() <= this->locoff(), "youngest JVMState must be last"); return of_depth(1)->locoff();
}
//-------------------------------debug_end-------------------------------------
uint JVMState::debug_end() const {
debug_only(JVMState* jvmroot = of_depth(1));
assert(jvmroot->endoff() <= this->endoff(), "youngest JVMState must be last"); return endoff();
}
//------------------------------debug_depth------------------------------------
uint JVMState::debug_depth() const {
uint total = 0; for (const JVMState* jvmp = this; jvmp != NULL; jvmp = jvmp->caller()) {
total += jvmp->debug_size();
} return total;
}
#ifndef PRODUCT
//------------------------------format_helper---------------------------------- // Given an allocation (a Chaitin object) and a Node decide if the Node carries // any defined value or not. If it does, print out the register or constant. staticvoid format_helper( PhaseRegAlloc *regalloc, outputStream* st, Node *n, constchar *msg, uint i, GrowableArray<SafePointScalarObjectNode*> *scobjs ) { if (n == NULL) { st->print(" NULL"); return; } if (n->is_SafePointScalarObject()) { // Scalar replacement.
SafePointScalarObjectNode* spobj = n->as_SafePointScalarObject();
scobjs->append_if_missing(spobj); int sco_n = scobjs->find(spobj);
assert(sco_n >= 0, "");
st->print(" %s%d]=#ScObj" INT32_FORMAT, msg, i, sco_n); return;
} if (regalloc->node_regs_max_index() > 0 &&
OptoReg::is_valid(regalloc->get_reg_first(n))) { // Check for undefined char buf[50];
regalloc->dump_register(n,buf);
st->print(" %s%d]=%s",msg,i,buf);
} else { // No register, but might be constant const Type *t = n->bottom_type(); switch (t->base()) { case Type::Int:
st->print(" %s%d]=#" INT32_FORMAT,msg,i,t->is_int()->get_con()); break; case Type::AnyPtr:
assert( t == TypePtr::NULL_PTR || n->in_dump(), "" );
st->print(" %s%d]=#NULL",msg,i); break; case Type::AryPtr: case Type::InstPtr:
st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->isa_oopptr()->const_oop())); break; case Type::KlassPtr: case Type::AryKlassPtr: case Type::InstKlassPtr:
st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->make_ptr()->isa_klassptr()->exact_klass())); break; case Type::MetadataPtr:
st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->make_ptr()->isa_metadataptr()->metadata())); break; case Type::NarrowOop:
st->print(" %s%d]=#Ptr" INTPTR_FORMAT,msg,i,p2i(t->make_ptr()->isa_oopptr()->const_oop())); break; case Type::RawPtr:
st->print(" %s%d]=#Raw" INTPTR_FORMAT,msg,i,p2i(t->is_rawptr())); break; case Type::DoubleCon:
st->print(" %s%d]=#%fD",msg,i,t->is_double_constant()->_d); break; case Type::FloatCon:
st->print(" %s%d]=#%fF",msg,i,t->is_float_constant()->_f); break; case Type::Long:
st->print(" %s%d]=#" INT64_FORMAT,msg,i,(int64_t)(t->is_long()->get_con())); break; case Type::Half: case Type::Top:
st->print(" %s%d]=_",msg,i); break; default: ShouldNotReachHere();
}
}
}
// Extra way to dump a jvms from the debugger, // to avoid a bug with C++ member function calls. void dump_jvms(JVMState* jvms) {
jvms->dump();
} #endif
//--------------------------clone_shallow--------------------------------------
JVMState* JVMState::clone_shallow(Compile* C) const {
JVMState* n = has_method() ? new (C) JVMState(_method, _caller) : new (C) JVMState(0);
n->set_bci(_bci);
n->_reexecute = _reexecute;
n->set_locoff(_locoff);
n->set_stkoff(_stkoff);
n->set_monoff(_monoff);
n->set_scloff(_scloff);
n->set_endoff(_endoff);
n->set_sp(_sp);
n->set_map(_map); return n;
}
//---------------------------clone_deep----------------------------------------
JVMState* JVMState::clone_deep(Compile* C) const {
JVMState* n = clone_shallow(C); for (JVMState* p = n; p->_caller != NULL; p = p->_caller) {
p->_caller = p->_caller->clone_shallow(C);
}
assert(n->depth() == depth(), "sanity");
assert(n->debug_depth() == debug_depth(), "sanity"); return n;
}
/** * Reset map for all callers
*/ void JVMState::set_map_deep(SafePointNode* map) { for (JVMState* p = this; p != NULL; p = p->_caller) {
p->set_map(map);
}
}
// unlike set_map(), this is two-way setting. void JVMState::bind_map(SafePointNode* map) {
set_map(map);
_map->set_jvms(this);
}
// Adapt offsets in in-array after adding or removing an edge. // Prerequisite is that the JVMState is used by only one node. void JVMState::adapt_position(int delta) { for (JVMState* jvms = this; jvms != NULL; jvms = jvms->caller()) {
jvms->set_locoff(jvms->locoff() + delta);
jvms->set_stkoff(jvms->stkoff() + delta);
jvms->set_monoff(jvms->monoff() + delta);
jvms->set_scloff(jvms->scloff() + delta);
jvms->set_endoff(jvms->endoff() + delta);
}
}
// Mirror the stack size calculation in the deopt code // How much stack space would we need at this point in the program in // case of deoptimization? int JVMState::interpreter_frame_size() const { const JVMState* jvms = this; int size = 0; int callee_parameters = 0; int callee_locals = 0; int extra_args = method()->max_stack() - stk_size();
while (jvms != NULL) { int locks = jvms->nof_monitors(); int temps = jvms->stk_size(); bool is_top_frame = (jvms == this);
ciMethod* method = jvms->method();
int frame_size = BytesPerWord * Interpreter::size_activation(method->max_stack(),
temps + callee_parameters,
extra_args,
locks,
callee_parameters,
callee_locals,
is_top_frame);
size += frame_size;
//------------------------------calling_convention----------------------------- void CallNode::calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const { // Use the standard compiler calling convention
SharedRuntime::java_calling_convention(sig_bt, parm_regs, argcnt);
}
//------------------------------match------------------------------------------ // Construct projections for control, I/O, memory-fields, ..., and // return result(s) along with their RegMask info
Node *CallNode::match( const ProjNode *proj, const Matcher *match ) { switch (proj->_con) { case TypeFunc::Control: case TypeFunc::I_O: case TypeFunc::Memory: returnnew MachProjNode(this,proj->_con,RegMask::Empty,MachProjNode::unmatched_proj);
case TypeFunc::Parms+1: // For LONG & DOUBLE returns
assert(tf()->range()->field_at(TypeFunc::Parms+1) == Type::HALF, ""); // 2nd half of doubles and longs returnnew MachProjNode(this,proj->_con, RegMask::Empty, (uint)OptoReg::Bad);
case TypeFunc::Parms: { // Normal returns
uint ideal_reg = tf()->range()->field_at(TypeFunc::Parms)->ideal_reg();
OptoRegPair regs = Opcode() == Op_CallLeafVector
? match->vector_return_value(ideal_reg) // Calls into assembly vector routine
: is_CallRuntime()
? match->c_return_value(ideal_reg) // Calls into C runtime
: match-> return_value(ideal_reg); // Calls into compiled Java code
RegMask rm = RegMask(regs.first());
if (Opcode() == Op_CallLeafVector) { // If the return is in vector, compute appropriate regmask taking into account the whole range if(ideal_reg >= Op_VecS && ideal_reg <= Op_VecZ) { if(OptoReg::is_valid(regs.second())) { for (OptoReg::Name r = regs.first(); r <= regs.second(); r = OptoReg::add(r, 1)) {
rm.Insert(r);
}
}
}
}
case TypeFunc::ReturnAdr: case TypeFunc::FramePtr: default:
ShouldNotReachHere();
} return NULL;
}
// Do we Match on this edge index or not? Match no edges
uint CallNode::match_edge(uint idx) const { return 0;
}
// // Determine whether the call could modify the field of the specified // instance at the specified offset. // bool CallNode::may_modify(const TypeOopPtr *t_oop, PhaseTransform *phase) {
assert((t_oop != NULL), "sanity"); if (is_call_to_arraycopystub() && strcmp(_name, "unsafe_arraycopy") != 0) { const TypeTuple* args = _tf->domain();
Node* dest = NULL; // Stubs that can be called once an ArrayCopyNode is expanded have // different signatures. Look for the second pointer argument, // that is the destination of the copy. for (uint i = TypeFunc::Parms, j = 0; i < args->cnt(); i++) { if (args->field_at(i)->isa_ptr()) {
j++; if (j == 2) {
dest = in(i); break;
}
}
}
guarantee(dest != NULL, "Call had only one ptr in, broken IR!"); if (!dest->is_top() && may_modify_arraycopy_helper(phase->type(dest)->is_oopptr(), t_oop, phase)) { returntrue;
} returnfalse;
} if (t_oop->is_known_instance()) { // The instance_id is set only for scalar-replaceable allocations which // are not passed as arguments according to Escape Analysis. returnfalse;
} if (t_oop->is_ptr_to_boxed_value()) {
ciKlass* boxing_klass = t_oop->is_instptr()->instance_klass(); if (is_CallStaticJava() && as_CallStaticJava()->is_boxing_method()) { // Skip unrelated boxing methods.
Node* proj = proj_out_or_null(TypeFunc::Parms); if ((proj == NULL) || (phase->type(proj)->is_instptr()->instance_klass() != boxing_klass)) { returnfalse;
}
} if (is_CallJava() && as_CallJava()->method() != NULL) {
ciMethod* meth = as_CallJava()->method(); if (meth->is_getter()) { returnfalse;
} // May modify (by reflection) if an boxing object is passed // as argument or returned.
Node* proj = returns_pointer() ? proj_out_or_null(TypeFunc::Parms) : NULL; if (proj != NULL) { const TypeInstPtr* inst_t = phase->type(proj)->isa_instptr(); if ((inst_t != NULL) && (!inst_t->klass_is_exact() ||
(inst_t->instance_klass() == boxing_klass))) { returntrue;
}
} const TypeTuple* d = tf()->domain(); for (uint i = TypeFunc::Parms; i < d->cnt(); i++) { const TypeInstPtr* inst_t = d->field_at(i)->isa_instptr(); if ((inst_t != NULL) && (!inst_t->klass_is_exact() ||
(inst_t->instance_klass() == boxing_klass))) { returntrue;
}
} returnfalse;
}
} returntrue;
}
// Does this call have a direct reference to n other than debug information? bool CallNode::has_non_debug_use(Node *n) { const TypeTuple * d = tf()->domain(); for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
Node *arg = in(i); if (arg == n) { returntrue;
}
} returnfalse;
}
// Returns the unique CheckCastPP of a call // or 'this' if there are several CheckCastPP or unexpected uses // or returns NULL if there is no one.
Node *CallNode::result_cast() {
Node *cast = NULL;
Node *p = proj_out_or_null(TypeFunc::Parms); if (p == NULL) return NULL;
for (DUIterator_Fast imax, i = p->fast_outs(imax); i < imax; i++) {
Node *use = p->fast_out(i); if (use->is_CheckCastPP()) { if (cast != NULL) { returnthis; // more than 1 CheckCastPP
}
cast = use;
} elseif (!use->is_Initialize() &&
!use->is_AddP() &&
use->Opcode() != Op_MemBarStoreStore) { // Expected uses are restricted to a CheckCastPP, an Initialize // node, a MemBarStoreStore (clone) and AddP nodes. If we // encounter any other use (a Phi node can be seen in rare // cases) return this to prevent incorrect optimizations. returnthis;
}
} return cast;
}
for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) {
ProjNode *pn = fast_out(i)->as_Proj(); if (pn->outcnt() == 0) continue; switch (pn->_con) { case TypeFunc::Control:
{ // For Control (fallthrough) and I_O (catch_all_index) we have CatchProj -> Catch -> Proj
projs->fallthrough_proj = pn; const Node* cn = pn->unique_ctrl_out_or_null(); if (cn != NULL && cn->is_Catch()) {
ProjNode *cpn = NULL; for (DUIterator_Fast kmax, k = cn->fast_outs(kmax); k < kmax; k++) {
cpn = cn->fast_out(k)->as_Proj();
assert(cpn->is_CatchProj(), "must be a CatchProjNode"); if (cpn->_con == CatchProjNode::fall_through_index)
projs->fallthrough_catchproj = cpn; else {
assert(cpn->_con == CatchProjNode::catch_all_index, "must be correct index.");
projs->catchall_catchproj = cpn;
}
}
} break;
} case TypeFunc::I_O: if (pn->_is_io_use)
projs->catchall_ioproj = pn; else
projs->fallthrough_ioproj = pn; for (DUIterator j = pn->outs(); pn->has_out(j); j++) {
Node* e = pn->out(j); if (e->Opcode() == Op_CreateEx && e->in(0)->is_CatchProj() && e->outcnt() > 0) {
assert(projs->exobj == NULL, "only one");
projs->exobj = e;
}
} break; case TypeFunc::Memory: if (pn->_is_io_use)
projs->catchall_memproj = pn; else
projs->fallthrough_memproj = pn; break; case TypeFunc::Parms:
projs->resproj = pn; break; default:
assert(false, "unexpected projection from allocation node.");
}
}
// The resproj may not exist because the result could be ignored // and the exception object may not exist if an exception handler // swallows the exception but all the other must exist and be found.
assert(projs->fallthrough_proj != NULL, "must be found");
do_asserts = do_asserts && !Compile::current()->inlining_incrementally();
assert(!do_asserts || projs->fallthrough_catchproj != NULL, "must be found");
assert(!do_asserts || projs->fallthrough_memproj != NULL, "must be found");
assert(!do_asserts || projs->fallthrough_ioproj != NULL, "must be found");
assert(!do_asserts || projs->catchall_catchproj != NULL, "must be found"); if (separate_io_proj) {
assert(!do_asserts || projs->catchall_memproj != NULL, "must be found");
assert(!do_asserts || projs->catchall_ioproj != NULL, "must be found");
}
}
void CallJavaNode::copy_call_debug_info(PhaseIterGVN* phase, SafePointNode* sfpt) { // Copy debug information and adjust JVMState information
uint old_dbg_start = sfpt->is_Call() ? sfpt->as_Call()->tf()->domain()->cnt() : (uint)TypeFunc::Parms+1;
uint new_dbg_start = tf()->domain()->cnt(); int jvms_adj = new_dbg_start - old_dbg_start;
assert (new_dbg_start == req(), "argument count mismatch");
Compile* C = phase->C;
// SafePointScalarObject node could be referenced several times in debug info. // Use Dict to record cloned nodes.
Dict* sosn_map = new Dict(cmpkey,hashkey); for (uint i = old_dbg_start; i < sfpt->req(); i++) {
Node* old_in = sfpt->in(i); // Clone old SafePointScalarObjectNodes, adjusting their field contents. if (old_in != NULL && old_in->is_SafePointScalarObject()) {
SafePointScalarObjectNode* old_sosn = old_in->as_SafePointScalarObject(); bool new_node;
Node* new_in = old_sosn->clone(sosn_map, new_node); if (new_node) { // New node?
new_in->set_req(0, C->root()); // reset control edge
new_in = phase->transform(new_in); // Register new node.
}
old_in = new_in;
}
add_req(old_in);
}
// JVMS may be shared so clone it before we modify it
set_jvms(sfpt->jvms() != NULL ? sfpt->jvms()->clone_deep(C) : NULL); for (JVMState *jvms = this->jvms(); jvms != NULL; jvms = jvms->caller()) {
jvms->set_map(this);
jvms->set_locoff(jvms->locoff()+jvms_adj);
jvms->set_stkoff(jvms->stkoff()+jvms_adj);
jvms->set_monoff(jvms->monoff()+jvms_adj);
jvms->set_scloff(jvms->scloff()+jvms_adj);
jvms->set_endoff(jvms->endoff()+jvms_adj);
}
}
#ifdef ASSERT bool CallJavaNode::validate_symbolic_info() const { if (method() == NULL) { returntrue; // call into runtime or uncommon trap
}
ciMethod* symbolic_info = jvms()->method()->get_method_at_bci(jvms()->bci());
ciMethod* callee = method(); if (symbolic_info->is_method_handle_intrinsic() && !callee->is_method_handle_intrinsic()) {
assert(override_symbolic_info(), "should be set");
}
assert(ciMethod::is_consistent_info(symbolic_info, callee), "inconsistent info"); returntrue;
} #endif
int not_used3; bool call_does_dispatch;
ciMethod* callee = phase->C->optimize_virtual_call(caller, klass, holder, orig_callee, receiver_type, true/*is_virtual*/,
call_does_dispatch, not_used3); // out-parameters if (!call_does_dispatch) { // Register for late inlining.
cg->set_callee_method(callee);
phase->C->prepend_late_inline(cg); // MH late inlining prepends to the list, so do the same
set_generator(NULL);
}
} return CallNode::Ideal(phase, can_reshape);
}
void SafePointNode::set_local(JVMState* jvms, uint idx, Node *c) {
assert(verify_jvms(jvms), "jvms must match"); int loc = jvms->locoff() + idx; if (in(loc)->is_top() && idx > 0 && !c->is_top() ) { // If current local idx is top then local idx - 1 could // be a long/double that needs to be killed since top could // represent the 2nd half of the long/double.
uint ideal = in(loc -1)->ideal_reg(); if (ideal == Op_RegD || ideal == Op_RegL) { // set other (low index) half to top
set_req(loc - 1, in(loc));
}
}
set_req(loc, c);
}
// If you have back to back safepoints, remove one if (in(TypeFunc::Control)->is_SafePoint()) {
Node* out_c = unique_ctrl_out_or_null(); // This can be the safepoint of an outer strip mined loop if the inner loop's backedge was removed. Replacing the // outer loop's safepoint could confuse removal of the outer loop. if (out_c != NULL && !out_c->is_OuterStripMinedLoopEnd()) { return in(TypeFunc::Control);
}
}
// Transforming long counted loops requires a safepoint node. Do not // eliminate a safepoint until loop opts are over. if (in(0)->is_Proj() && !phase->C->major_progress()) {
Node *n0 = in(0)->in(0); // Check if he is a call projection (except Leaf Call) if( n0->is_Catch() ) {
n0 = n0->in(0)->in(0);
assert( n0->is_Call(), "expect a call here" );
} if( n0->is_Call() && n0->as_Call()->guaranteed_safepoint() ) { // Don't remove a safepoint belonging to an OuterStripMinedLoopEndNode. // If the loop dies, they will be removed together. if (has_out_with(Op_OuterStripMinedLoopEnd)) { returnthis;
} // Useless Safepoint, so remove it return in(TypeFunc::Control);
}
}
returnthis;
}
//------------------------------Value------------------------------------------ const Type* SafePointNode::Value(PhaseGVN* phase) const { if (phase->type(in(0)) == Type::TOP) { return Type::TOP;
} if (in(0) == this) { return Type::TOP; // Dead infinite loop
} return Type::CONTROL;
}
void SafePointNode::grow_stack(JVMState* jvms, uint grow_by) {
assert((int)grow_by > 0, "sanity"); int monoff = jvms->monoff(); int scloff = jvms->scloff(); int endoff = jvms->endoff();
assert(endoff == (int)req(), "no other states or debug info after me");
Node* top = Compile::current()->top(); for (uint i = 0; i < grow_by; i++) {
ins_req(monoff, top);
}
jvms->set_monoff(monoff + grow_by);
jvms->set_scloff(scloff + grow_by);
jvms->set_endoff(endoff + grow_by);
}
void SafePointNode::push_monitor(const FastLockNode *lock) { // Add a LockNode, which points to both the original BoxLockNode (the // stack space for the monitor) and the Object being locked. constint MonitorEdges = 2;
assert(JVMState::logMonitorEdges == exact_log2(MonitorEdges), "correct MonitorEdges");
assert(req() == jvms()->endoff(), "correct sizing"); int nextmon = jvms()->scloff(); if (GenerateSynchronizationCode) {
ins_req(nextmon, lock->box_node());
ins_req(nextmon+1, lock->obj_node());
} else {
Node* top = Compile::current()->top();
ins_req(nextmon, top);
ins_req(nextmon, top);
}
jvms()->set_scloff(nextmon + MonitorEdges);
jvms()->set_endoff(req());
}
void SafePointNode::pop_monitor() { // Delete last monitor from debug info
debug_only(int num_before_pop = jvms()->nof_monitors()); constint MonitorEdges = 2;
assert(JVMState::logMonitorEdges == exact_log2(MonitorEdges), "correct MonitorEdges"); int scloff = jvms()->scloff(); int endoff = jvms()->endoff(); int new_scloff = scloff - MonitorEdges; int new_endoff = endoff - MonitorEdges;
jvms()->set_scloff(new_scloff);
jvms()->set_endoff(new_endoff); while (scloff > new_scloff) del_req_ordered(--scloff);
assert(jvms()->nof_monitors() == num_before_pop-1, "");
}
Node *SafePointNode::peek_monitor_box() const { int mon = jvms()->nof_monitors() - 1;
assert(mon >= 0, "must have a monitor"); return monitor_box(jvms(), mon);
}
Node *SafePointNode::peek_monitor_obj() const { int mon = jvms()->nof_monitors() - 1;
assert(mon >= 0, "must have a monitor"); return monitor_obj(jvms(), mon);
}
Node* SafePointNode::peek_operand(uint off) const {
assert(jvms()->sp() > 0, "must have an operand");
assert(off < jvms()->sp(), "off is out-of-range"); return stack(jvms(), jvms()->sp() - off - 1);
}
// Do we Match on this edge index or not? Match no edges
uint SafePointNode::match_edge(uint idx) const { return (TypeFunc::Parms == idx);
}
void SafePointNode::disconnect_from_root(PhaseIterGVN *igvn) {
assert(Opcode() == Op_SafePoint, "only value for safepoint in loops"); int nb = igvn->C->root()->find_prec_edge(this); if (nb != -1) {
igvn->delete_precedence_of(igvn->C->root(), nb);
}
}
// Allocation node is first parameter in its initializer if (analyzer->is_arg_stack(0) || analyzer->is_arg_local(0)) {
_is_allocation_MemBar_redundant = true;
}
}
Node *AllocateNode::make_ideal_mark(PhaseGVN *phase, Node* obj, Node* control, Node* mem) {
Node* mark_node = NULL; // For now only enable fast locking for non-array types
mark_node = phase->MakeConX(markWord::prototype().value()); return mark_node;
}
// Retrieve the length from the AllocateArrayNode. Narrow the type with a // CastII, if appropriate. If we are not allowed to create new nodes, and // a CastII is appropriate, return NULL.
Node *AllocateArrayNode::make_ideal_length(const TypeOopPtr* oop_type, PhaseTransform *phase, bool allow_new_nodes) {
Node *length = in(AllocateNode::ALength);
assert(length != NULL, "length is not null");
if (ary_type != NULL && length_type != NULL) { const TypeInt* narrow_length_type = ary_type->narrow_size_type(length_type); if (narrow_length_type != length_type) { // Assert one of: // - the narrow_length is 0 // - the narrow_length is not wider than length
assert(narrow_length_type == TypeInt::ZERO ||
length_type->is_con() && narrow_length_type->is_con() &&
(narrow_length_type->_hi <= length_type->_lo) ||
(narrow_length_type->_hi <= length_type->_hi &&
narrow_length_type->_lo >= length_type->_lo), "narrow type must be narrower than length type");
// Return NULL if new nodes are not allowed if (!allow_new_nodes) { return NULL;
} // Create a cast which is control dependent on the initialization to // propagate the fact that the array length must be positive.
InitializeNode* init = initialization(); if (init != NULL) {
length = new CastIINode(length, narrow_length_type);
length->set_req(TypeFunc::Control, init->proj_out_or_null(TypeFunc::Control));
}
}
}
// Redundant lock elimination // // There are various patterns of locking where we release and // immediately reacquire a lock in a piece of code where no operations // occur in between that would be observable. In those cases we can // skip releasing and reacquiring the lock without violating any // fairness requirements. Doing this around a loop could cause a lock // to be held for a very long time so we concentrate on non-looping // control flow. We also require that the operations are fully // redundant meaning that we don't introduce new lock operations on // some paths so to be able to eliminate it on others ala PRE. This // would probably require some more extensive graph manipulation to // guarantee that the memory edges were all handled correctly. // // Assuming p is a simple predicate which can't trap in any way and s // is a synchronized method consider this code: // // s(); // if (p) // s(); // else // s(); // s(); // // 1. The unlocks of the first call to s can be eliminated if the // locks inside the then and else branches are eliminated. // // 2. The unlocks of the then and else branches can be eliminated if // the lock of the final call to s is eliminated. // // Either of these cases subsumes the simple case of sequential control flow // // Additionally we can eliminate versions without the else case: // // s(); // if (p) // s(); // s(); // // 3. In this case we eliminate the unlock of the first s, the lock // and unlock in the then case and the lock in the final s. // // Note also that in all these cases the then/else pieces don't have // to be trivial as long as they begin and end with synchronization // operations. // // s(); // if (p) // s(); // f(); // s(); // s(); // // The code will work properly for this case, leaving in the unlock // before the call to f and the relock after it. // // A potentially interesting case which isn't handled here is when the // locking is partially redundant. // // s(); // if (p) // s(); // // This could be eliminated putting unlocking on the else case and // eliminating the first unlock and the lock in the then side. // Alternatively the unlock could be moved out of the then side so it // was after the merge and the first unlock and second lock // eliminated. This might require less manipulation of the memory // state to get correct. // // Additionally we might allow work between a unlock and lock before // giving up eliminating the locks. The current code disallows any // conditional control flow between these operations. A formulation // similar to partial redundancy elimination computing the // availability of unlocking and the anticipatability of locking at a // program point would allow detection of fully redundant locking with // some amount of work in between. I'm not sure how often I really // think that would occur though. Most of the cases I've seen // indicate it's likely non-trivial work would occur in between. // There may be other more complicated constructs where we could // eliminate locking but I haven't seen any others appear as hot or // interesting. // // Locking and unlocking have a canonical form in ideal that looks // roughly like this: // // <obj> // | \\------+ // | \ \ // | BoxLock \ // | | | \ // | | \ \ // | | FastLock // | | / // | | / // | | | // // Lock // | // Proj #0 // | // MembarAcquire // | // Proj #0 // // MembarRelease // | // Proj #0 // | // Unlock // | // Proj #0 // // // This code proceeds by processing Lock nodes during PhaseIterGVN // and searching back through its control for the proper code // patterns. Once it finds a set of lock and unlock operations to // eliminate they are marked as eliminatable which causes the // expansion of the Lock and Unlock macro nodes to make the operation a NOP // //=============================================================================
// // Utility function to skip over uninteresting control nodes. Nodes skipped are: // - copy regions. (These may not have been optimized away yet.) // - eliminated locking nodes // static Node *next_control(Node *ctrl) { if (ctrl == NULL) return NULL; while (1) { if (ctrl->is_Region()) {
RegionNode *r = ctrl->as_Region();
Node *n = r->is_copy(); if (n == NULL) break; // hit a region, return it else
ctrl = n;
} elseif (ctrl->is_Proj()) {
Node *in0 = ctrl->in(0); if (in0->is_AbstractLock() && in0->as_AbstractLock()->is_eliminated()) {
ctrl = in0->in(0);
} else { break;
}
} else { break; // found an interesting control
}
} return ctrl;
} // // Given a control, see if it's the control projection of an Unlock which // operating on the same object as lock. // bool AbstractLockNode::find_matching_unlock(const Node* ctrl, LockNode* lock,
GrowableArray<AbstractLockNode*> &lock_ops) {
ProjNode *ctrl_proj = (ctrl->is_Proj()) ? ctrl->as_Proj() : NULL; if (ctrl_proj != NULL && ctrl_proj->_con == TypeFunc::Control) {
Node *n = ctrl_proj->in(0); if (n != NULL && n->is_Unlock()) {
UnlockNode *unlock = n->as_Unlock();
BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());
Node* unlock_obj = bs->step_over_gc_barrier(unlock->obj_node()); if (lock_obj->eqv_uncast(unlock_obj) &&
BoxLockNode::same_slot(lock->box_node(), unlock->box_node()) &&
!unlock->is_eliminated()) {
lock_ops.append(unlock); returntrue;
}
}
} returnfalse;
}
// // Find the lock matching an unlock. Returns null if a safepoint // or complicated control is encountered first.
LockNode *AbstractLockNode::find_matching_lock(UnlockNode* unlock) {
LockNode *lock_result = NULL; // find the matching lock, or an intervening safepoint
Node *ctrl = next_control(unlock->in(0)); while (1) {
assert(ctrl != NULL, "invalid control graph");
assert(!ctrl->is_Start(), "missing lock for unlock"); if (ctrl->is_top()) break; // dead control path if (ctrl->is_Proj()) ctrl = ctrl->in(0); if (ctrl->is_SafePoint()) { break; // found a safepoint (may be the lock we are searching for)
} elseif (ctrl->is_Region()) { // Check for a simple diamond pattern. Punt on anything more complicated if (ctrl->req() == 3 && ctrl->in(1) != NULL && ctrl->in(2) != NULL) {
Node *in1 = next_control(ctrl->in(1));
Node *in2 = next_control(ctrl->in(2)); if (((in1->is_IfTrue() && in2->is_IfFalse()) ||
(in2->is_IfTrue() && in1->is_IfFalse())) && (in1->in(0) == in2->in(0))) {
ctrl = next_control(in1->in(0)->in(0));
} else { break;
}
} else { break;
}
} else {
ctrl = next_control(ctrl->in(0)); // keep searching
}
} if (ctrl->is_Lock()) {
LockNode *lock = ctrl->as_Lock();
BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());
Node* unlock_obj = bs->step_over_gc_barrier(unlock->obj_node()); if (lock_obj->eqv_uncast(unlock_obj) &&
BoxLockNode::same_slot(lock->box_node(), unlock->box_node())) {
lock_result = lock;
}
} return lock_result;
}
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 und die Messung sind noch experimentell.