3532 // "simple enough" to be folded into an object initialization. |
3532 // "simple enough" to be folded into an object initialization. |
3533 // Attempts to prove that a store's initial value 'n' can be captured |
3533 // Attempts to prove that a store's initial value 'n' can be captured |
3534 // within the initialization without creating a vicious cycle, such as: |
3534 // within the initialization without creating a vicious cycle, such as: |
3535 // { Foo p = new Foo(); p.next = p; } |
3535 // { Foo p = new Foo(); p.next = p; } |
3536 // True for constants and parameters and small combinations thereof. |
3536 // True for constants and parameters and small combinations thereof. |
3537 bool InitializeNode::detect_init_independence(Node* n, int& count) { |
3537 bool InitializeNode::detect_init_independence(Node* value, PhaseGVN* phase) { |
3538 if (n == NULL) return true; // (can this really happen?) |
3538 ResourceMark rm; |
3539 if (n->is_Proj()) n = n->in(0); |
3539 Unique_Node_List worklist; |
3540 if (n == this) return false; // found a cycle |
3540 worklist.push(value); |
3541 if (n->is_Con()) return true; |
3541 |
3542 if (n->is_Start()) return true; // params, etc., are OK |
3542 uint complexity_limit = 20; |
3543 if (n->is_Root()) return true; // even better |
3543 for (uint j = 0; j < worklist.size(); j++) { |
3544 |
3544 if (j >= complexity_limit) { |
3545 Node* ctl = n->in(0); |
3545 return false; // Bail out if processed too many nodes |
3546 if (ctl != NULL && !ctl->is_top()) { |
3546 } |
3547 if (ctl->is_Proj()) ctl = ctl->in(0); |
3547 |
3548 if (ctl == this) return false; |
3548 Node* n = worklist.at(j); |
3549 |
3549 if (n == NULL) continue; // (can this really happen?) |
3550 // If we already know that the enclosing memory op is pinned right after |
3550 if (n->is_Proj()) n = n->in(0); |
3551 // the init, then any control flow that the store has picked up |
3551 if (n == this) return false; // found a cycle |
3552 // must have preceded the init, or else be equal to the init. |
3552 if (n->is_Con()) continue; |
3553 // Even after loop optimizations (which might change control edges) |
3553 if (n->is_Start()) continue; // params, etc., are OK |
3554 // a store is never pinned *before* the availability of its inputs. |
3554 if (n->is_Root()) continue; // even better |
3555 if (!MemNode::all_controls_dominate(n, this)) |
3555 |
3556 return false; // failed to prove a good control |
3556 // There cannot be any dependency if 'n' is a CFG node that dominates the current allocation |
3557 } |
3557 if (n->is_CFG() && phase->is_dominator(n, allocation())) { |
3558 |
3558 continue; |
3559 // Check data edges for possible dependencies on 'this'. |
3559 } |
3560 if ((count += 1) > 20) return false; // complexity limit |
3560 |
3561 for (uint i = 1; i < n->req(); i++) { |
3561 Node* ctl = n->in(0); |
3562 Node* m = n->in(i); |
3562 if (ctl != NULL && !ctl->is_top()) { |
3563 if (m == NULL || m == n || m->is_top()) continue; |
3563 if (ctl->is_Proj()) ctl = ctl->in(0); |
3564 uint first_i = n->find_edge(m); |
3564 if (ctl == this) return false; |
3565 if (i != first_i) continue; // process duplicate edge just once |
3565 |
3566 if (!detect_init_independence(m, count)) { |
3566 // If we already know that the enclosing memory op is pinned right after |
3567 return false; |
3567 // the init, then any control flow that the store has picked up |
|
3568 // must have preceded the init, or else be equal to the init. |
|
3569 // Even after loop optimizations (which might change control edges) |
|
3570 // a store is never pinned *before* the availability of its inputs. |
|
3571 if (!MemNode::all_controls_dominate(n, this)) |
|
3572 return false; // failed to prove a good control |
|
3573 } |
|
3574 |
|
3575 // Check data edges for possible dependencies on 'this'. |
|
3576 for (uint i = 1; i < n->req(); i++) { |
|
3577 Node* m = n->in(i); |
|
3578 if (m == NULL || m == n || m->is_top()) continue; |
|
3579 |
|
3580 // Only process data inputs once |
|
3581 worklist.push(m); |
3568 } |
3582 } |
3569 } |
3583 } |
3570 |
3584 |
3571 return true; |
3585 return true; |
3572 } |
3586 } |
3573 |
3587 |
3574 // Here are all the checks a Store must pass before it can be moved into |
3588 // Here are all the checks a Store must pass before it can be moved into |
3575 // an initialization. Returns zero if a check fails. |
3589 // an initialization. Returns zero if a check fails. |
3576 // On success, returns the (constant) offset to which the store applies, |
3590 // On success, returns the (constant) offset to which the store applies, |
3577 // within the initialized memory. |
3591 // within the initialized memory. |
3578 intptr_t InitializeNode::can_capture_store(StoreNode* st, PhaseTransform* phase, bool can_reshape) { |
3592 intptr_t InitializeNode::can_capture_store(StoreNode* st, PhaseGVN* phase, bool can_reshape) { |
3579 const int FAIL = 0; |
3593 const int FAIL = 0; |
3580 if (st->req() != MemNode::ValueIn + 1) |
3594 if (st->req() != MemNode::ValueIn + 1) |
3581 return FAIL; // an inscrutable StoreNode (card mark?) |
3595 return FAIL; // an inscrutable StoreNode (card mark?) |
3582 Node* ctl = st->in(MemNode::Control); |
3596 Node* ctl = st->in(MemNode::Control); |
3583 if (!(ctl != NULL && ctl->is_Proj() && ctl->in(0) == this)) |
3597 if (!(ctl != NULL && ctl->is_Proj() && ctl->in(0) == this)) |
3794 // rawstore2 = (StoreC alloc.Control alloc.Memory (+ rawoop 14) 2) |
3808 // rawstore2 = (StoreC alloc.Control alloc.Memory (+ rawoop 14) 2) |
3795 // init = (Initialize alloc.Control alloc.Memory rawoop |
3809 // init = (Initialize alloc.Control alloc.Memory rawoop |
3796 // rawstore1 rawstore2) |
3810 // rawstore1 rawstore2) |
3797 // |
3811 // |
3798 Node* InitializeNode::capture_store(StoreNode* st, intptr_t start, |
3812 Node* InitializeNode::capture_store(StoreNode* st, intptr_t start, |
3799 PhaseTransform* phase, bool can_reshape) { |
3813 PhaseGVN* phase, bool can_reshape) { |
3800 assert(stores_are_sane(phase), ""); |
3814 assert(stores_are_sane(phase), ""); |
3801 |
3815 |
3802 if (start < 0) return NULL; |
3816 if (start < 0) return NULL; |
3803 assert(can_capture_store(st, phase, can_reshape) == start, "sanity"); |
3817 assert(can_capture_store(st, phase, can_reshape) == start, "sanity"); |
3804 |
3818 |