Mercurial > hg > truffle
comparison src/share/vm/opto/locknode.cpp @ 4777:e9a5e0a812c8
7125896: Eliminate nested locks
Summary: Nested locks elimination done before lock nodes expansion by looking for outer locks of the same object.
Reviewed-by: never, twisti
author | kvn |
---|---|
date | Sat, 07 Jan 2012 13:26:43 -0800 |
parents | f95d63e2154a |
children | 35acf8f0a2e4 |
comparison
equal
deleted
inserted
replaced
4776:5da7201222d5 | 4777:e9a5e0a812c8 |
---|---|
47 _inmask.Insert(reg); | 47 _inmask.Insert(reg); |
48 } | 48 } |
49 | 49 |
50 //-----------------------------hash-------------------------------------------- | 50 //-----------------------------hash-------------------------------------------- |
51 uint BoxLockNode::hash() const { | 51 uint BoxLockNode::hash() const { |
52 if (EliminateNestedLocks) | |
53 return NO_HASH; // Each locked region has own BoxLock node | |
52 return Node::hash() + _slot + (_is_eliminated ? Compile::current()->fixed_slots() : 0); | 54 return Node::hash() + _slot + (_is_eliminated ? Compile::current()->fixed_slots() : 0); |
53 } | 55 } |
54 | 56 |
55 //------------------------------cmp-------------------------------------------- | 57 //------------------------------cmp-------------------------------------------- |
56 uint BoxLockNode::cmp( const Node &n ) const { | 58 uint BoxLockNode::cmp( const Node &n ) const { |
59 if (EliminateNestedLocks) | |
60 return (&n == this); // Always fail except on self | |
57 const BoxLockNode &bn = (const BoxLockNode &)n; | 61 const BoxLockNode &bn = (const BoxLockNode &)n; |
58 return bn._slot == _slot && bn._is_eliminated == _is_eliminated; | 62 return bn._slot == _slot && bn._is_eliminated == _is_eliminated; |
59 } | 63 } |
60 | 64 |
61 OptoReg::Name BoxLockNode::stack_slot(Node* box_node) { | 65 BoxLockNode* BoxLockNode::box_node(Node* box) { |
62 // Chase down the BoxNode | 66 // Chase down the BoxNode |
63 while (!box_node->is_BoxLock()) { | 67 while (!box->is_BoxLock()) { |
64 // if (box_node->is_SpillCopy()) { | 68 // if (box_node->is_SpillCopy()) { |
65 // Node *m = box_node->in(1); | 69 // Node *m = box_node->in(1); |
66 // if (m->is_Mach() && m->as_Mach()->ideal_Opcode() == Op_StoreP) { | 70 // if (m->is_Mach() && m->as_Mach()->ideal_Opcode() == Op_StoreP) { |
67 // box_node = m->in(m->as_Mach()->operand_index(2)); | 71 // box_node = m->in(m->as_Mach()->operand_index(2)); |
68 // continue; | 72 // continue; |
69 // } | 73 // } |
70 // } | 74 // } |
71 assert(box_node->is_SpillCopy() || box_node->is_Phi(), "Bad spill of Lock."); | 75 assert(box->is_SpillCopy() || box->is_Phi(), "Bad spill of Lock."); |
72 box_node = box_node->in(1); | 76 // Only BoxLock nodes with the same stack slot are merged. |
73 } | 77 // So it is enough to trace one path to find the slot value. |
74 return box_node->in_RegMask(0).find_first_elem(); | 78 box = box->in(1); |
79 } | |
80 return box->as_BoxLock(); | |
81 } | |
82 | |
83 OptoReg::Name BoxLockNode::reg(Node* box) { | |
84 return box_node(box)->in_RegMask(0).find_first_elem(); | |
85 } | |
86 | |
87 bool BoxLockNode::same_slot(Node* box1, Node* box2) { | |
88 return box_node(box1)->_slot == box_node(box2)->_slot; | |
89 } | |
90 | |
91 // Is BoxLock node used for one simple lock region (same box and obj)? | |
92 bool BoxLockNode::is_simple_lock_region(LockNode** unique_lock, Node* obj) { | |
93 LockNode* lock = NULL; | |
94 bool has_one_lock = false; | |
95 for (uint i = 0; i < this->outcnt(); i++) { | |
96 Node* n = this->raw_out(i); | |
97 if (n->is_Phi()) | |
98 return false; // Merged regions | |
99 if (n->is_AbstractLock()) { | |
100 AbstractLockNode* alock = n->as_AbstractLock(); | |
101 // Check lock's box since box could be referenced by Lock's debug info. | |
102 if (alock->box_node() == this) { | |
103 if (alock->obj_node() == obj) { | |
104 if ((unique_lock != NULL) && alock->is_Lock()) { | |
105 if (lock == NULL) { | |
106 lock = alock->as_Lock(); | |
107 has_one_lock = true; | |
108 } else if (lock != alock->as_Lock()) { | |
109 has_one_lock = false; | |
110 } | |
111 } | |
112 } else { | |
113 return false; // Different objects | |
114 } | |
115 } | |
116 } | |
117 } | |
118 #ifdef ASSERT | |
119 // Verify that FastLock and Safepoint reference only this lock region. | |
120 for (uint i = 0; i < this->outcnt(); i++) { | |
121 Node* n = this->raw_out(i); | |
122 if (n->is_FastLock()) { | |
123 FastLockNode* flock = n->as_FastLock(); | |
124 assert((flock->box_node() == this) && (flock->obj_node() == obj),""); | |
125 } | |
126 if (n->is_SafePoint() && n->as_SafePoint()->jvms()) { | |
127 SafePointNode* sfn = n->as_SafePoint(); | |
128 JVMState* youngest_jvms = sfn->jvms(); | |
129 int max_depth = youngest_jvms->depth(); | |
130 for (int depth = 1; depth <= max_depth; depth++) { | |
131 JVMState* jvms = youngest_jvms->of_depth(depth); | |
132 int num_mon = jvms->nof_monitors(); | |
133 // Loop over monitors | |
134 for (int idx = 0; idx < num_mon; idx++) { | |
135 Node* obj_node = sfn->monitor_obj(jvms, idx); | |
136 Node* box_node = sfn->monitor_box(jvms, idx); | |
137 if (box_node == this) { | |
138 assert(obj_node == obj,""); | |
139 } | |
140 } | |
141 } | |
142 } | |
143 } | |
144 #endif | |
145 if (unique_lock != NULL && has_one_lock) { | |
146 *unique_lock = lock; | |
147 } | |
148 return true; | |
75 } | 149 } |
76 | 150 |
77 //============================================================================= | 151 //============================================================================= |
78 //-----------------------------hash-------------------------------------------- | 152 //-----------------------------hash-------------------------------------------- |
79 uint FastLockNode::hash() const { return NO_HASH; } | 153 uint FastLockNode::hash() const { return NO_HASH; } |