annotate src/share/vm/opto/locknode.cpp @ 10408:836a62f43af9

Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author Doug Simon <doug.simon@oracle.com>
date Wed, 19 Jun 2013 10:45:56 +0200
parents beebba0acc11
children 606acabe7b5c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6842
b9a9ed0f8eeb 7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents: 4792
diff changeset
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 605
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 605
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 605
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "opto/locknode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "opto/parse.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "opto/rootnode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "opto/runtime.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
32 const RegMask &BoxLockNode::in_RegMask(uint i) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
33 return _inmask;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 }
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 const RegMask &BoxLockNode::out_RegMask() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
37 return *Matcher::idealreg2regmask[Op_RegP];
a61af66fc99e Initial load
duke
parents:
diff changeset
38 }
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 uint BoxLockNode::size_of() const { return sizeof(*this); }
a61af66fc99e Initial load
duke
parents:
diff changeset
41
66
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 0
diff changeset
42 BoxLockNode::BoxLockNode( int slot ) : Node( Compile::current()->root() ),
6dbf1a175d6b 6672848: (Escape Analysis) improve lock elimination with EA
kvn
parents: 0
diff changeset
43 _slot(slot), _is_eliminated(false) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
44 init_class_id(Class_BoxLock);
a61af66fc99e Initial load
duke
parents:
diff changeset
45 init_flags(Flag_rematerialize);
a61af66fc99e Initial load
duke
parents:
diff changeset
46 OptoReg::Name reg = OptoReg::stack2reg(_slot);
a61af66fc99e Initial load
duke
parents:
diff changeset
47 _inmask.Insert(reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
48 }
a61af66fc99e Initial load
duke
parents:
diff changeset
49
460
424f9bfe6b96 6775880: EA +DeoptimizeALot: assert(mon_info->owner()->is_locked(),"object must be locked now")
kvn
parents: 196
diff changeset
50 //-----------------------------hash--------------------------------------------
424f9bfe6b96 6775880: EA +DeoptimizeALot: assert(mon_info->owner()->is_locked(),"object must be locked now")
kvn
parents: 196
diff changeset
51 uint BoxLockNode::hash() const {
4777
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
52 if (EliminateNestedLocks)
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
53 return NO_HASH; // Each locked region has own BoxLock node
460
424f9bfe6b96 6775880: EA +DeoptimizeALot: assert(mon_info->owner()->is_locked(),"object must be locked now")
kvn
parents: 196
diff changeset
54 return Node::hash() + _slot + (_is_eliminated ? Compile::current()->fixed_slots() : 0);
424f9bfe6b96 6775880: EA +DeoptimizeALot: assert(mon_info->owner()->is_locked(),"object must be locked now")
kvn
parents: 196
diff changeset
55 }
424f9bfe6b96 6775880: EA +DeoptimizeALot: assert(mon_info->owner()->is_locked(),"object must be locked now")
kvn
parents: 196
diff changeset
56
0
a61af66fc99e Initial load
duke
parents:
diff changeset
57 //------------------------------cmp--------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
58 uint BoxLockNode::cmp( const Node &n ) const {
4777
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
59 if (EliminateNestedLocks)
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
60 return (&n == this); // Always fail except on self
0
a61af66fc99e Initial load
duke
parents:
diff changeset
61 const BoxLockNode &bn = (const BoxLockNode &)n;
460
424f9bfe6b96 6775880: EA +DeoptimizeALot: assert(mon_info->owner()->is_locked(),"object must be locked now")
kvn
parents: 196
diff changeset
62 return bn._slot == _slot && bn._is_eliminated == _is_eliminated;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
63 }
a61af66fc99e Initial load
duke
parents:
diff changeset
64
4777
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
65 BoxLockNode* BoxLockNode::box_node(Node* box) {
4790
b0ff910edfc9 7128355: assert(!nocreate) failed: Cannot build a phi for a block already parsed
kvn
parents: 4778
diff changeset
66 // Chase down the BoxNode after RA which may spill box nodes.
4777
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
67 while (!box->is_BoxLock()) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // if (box_node->is_SpillCopy()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // Node *m = box_node->in(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // if (m->is_Mach() && m->as_Mach()->ideal_Opcode() == Op_StoreP) {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // box_node = m->in(m->as_Mach()->operand_index(2));
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
74 // }
4777
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
75 assert(box->is_SpillCopy() || box->is_Phi(), "Bad spill of Lock.");
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
76 // Only BoxLock nodes with the same stack slot are merged.
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
77 // So it is enough to trace one path to find the slot value.
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
78 box = box->in(1);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
4777
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
80 return box->as_BoxLock();
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
81 }
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
82
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
83 OptoReg::Name BoxLockNode::reg(Node* box) {
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
84 return box_node(box)->in_RegMask(0).find_first_elem();
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
85 }
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
86
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
87 // Is BoxLock node used for one simple lock region (same box and obj)?
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
88 bool BoxLockNode::is_simple_lock_region(LockNode** unique_lock, Node* obj) {
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
89 LockNode* lock = NULL;
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
90 bool has_one_lock = false;
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
91 for (uint i = 0; i < this->outcnt(); i++) {
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
92 Node* n = this->raw_out(i);
4790
b0ff910edfc9 7128355: assert(!nocreate) failed: Cannot build a phi for a block already parsed
kvn
parents: 4778
diff changeset
93 assert(!n->is_Phi(), "should not merge BoxLock nodes");
4777
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
94 if (n->is_AbstractLock()) {
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
95 AbstractLockNode* alock = n->as_AbstractLock();
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
96 // Check lock's box since box could be referenced by Lock's debug info.
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
97 if (alock->box_node() == this) {
4778
35acf8f0a2e4 7128352: assert(obj_node == obj) failed
kvn
parents: 4777
diff changeset
98 if (alock->obj_node()->eqv_uncast(obj)) {
4777
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
99 if ((unique_lock != NULL) && alock->is_Lock()) {
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
100 if (lock == NULL) {
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
101 lock = alock->as_Lock();
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
102 has_one_lock = true;
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
103 } else if (lock != alock->as_Lock()) {
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
104 has_one_lock = false;
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
105 }
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
106 }
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
107 } else {
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
108 return false; // Different objects
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
109 }
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
110 }
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
111 }
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
112 }
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
113 #ifdef ASSERT
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
114 // Verify that FastLock and Safepoint reference only this lock region.
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
115 for (uint i = 0; i < this->outcnt(); i++) {
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
116 Node* n = this->raw_out(i);
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
117 if (n->is_FastLock()) {
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
118 FastLockNode* flock = n->as_FastLock();
4778
35acf8f0a2e4 7128352: assert(obj_node == obj) failed
kvn
parents: 4777
diff changeset
119 assert((flock->box_node() == this) && flock->obj_node()->eqv_uncast(obj),"");
4777
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
120 }
4792
89d0a5d40008 7129618: assert(obj_node->eqv_uncast(obj),"");
kvn
parents: 4790
diff changeset
121 // Don't check monitor info in safepoints since the referenced object could
89d0a5d40008 7129618: assert(obj_node->eqv_uncast(obj),"");
kvn
parents: 4790
diff changeset
122 // be different from the locked object. It could be Phi node of different
89d0a5d40008 7129618: assert(obj_node->eqv_uncast(obj),"");
kvn
parents: 4790
diff changeset
123 // cast nodes which point to this locked object.
89d0a5d40008 7129618: assert(obj_node->eqv_uncast(obj),"");
kvn
parents: 4790
diff changeset
124 // We assume that no other objects could be referenced in monitor info
89d0a5d40008 7129618: assert(obj_node->eqv_uncast(obj),"");
kvn
parents: 4790
diff changeset
125 // associated with this BoxLock node because all associated locks and
89d0a5d40008 7129618: assert(obj_node->eqv_uncast(obj),"");
kvn
parents: 4790
diff changeset
126 // unlocks are reference only this one object.
4777
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
127 }
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
128 #endif
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
129 if (unique_lock != NULL && has_one_lock) {
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
130 *unique_lock = lock;
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
131 }
e9a5e0a812c8 7125896: Eliminate nested locks
kvn
parents: 1972
diff changeset
132 return true;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134
a61af66fc99e Initial load
duke
parents:
diff changeset
135 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
136 //-----------------------------hash--------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
137 uint FastLockNode::hash() const { return NO_HASH; }
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 //------------------------------cmp--------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
140 uint FastLockNode::cmp( const Node &n ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 return (&n == this); // Always fail except on self
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
145 //-----------------------------hash--------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
146 uint FastUnlockNode::hash() const { return NO_HASH; }
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 //------------------------------cmp--------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
149 uint FastUnlockNode::cmp( const Node &n ) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 return (&n == this); // Always fail except on self
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 //
a61af66fc99e Initial load
duke
parents:
diff changeset
154 // Create a counter which counts the number of times this lock is acquired
a61af66fc99e Initial load
duke
parents:
diff changeset
155 //
a61af66fc99e Initial load
duke
parents:
diff changeset
156 void FastLockNode::create_lock_counter(JVMState* state) {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 BiasedLockingNamedCounter* blnc = (BiasedLockingNamedCounter*)
a61af66fc99e Initial load
duke
parents:
diff changeset
158 OptoRuntime::new_named_counter(state, NamedCounter::BiasedLockingCounter);
a61af66fc99e Initial load
duke
parents:
diff changeset
159 _counters = blnc->counters();
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 //=============================================================================
a61af66fc99e Initial load
duke
parents:
diff changeset
163 //------------------------------do_monitor_enter-------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
164 void Parse::do_monitor_enter() {
a61af66fc99e Initial load
duke
parents:
diff changeset
165 kill_dead_locals();
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 // Null check; get casted pointer.
7194
beebba0acc11 7172640: C2: instrinsic implementations in LibraryCallKit should use argument() instead of pop()
twisti
parents: 6842
diff changeset
168 Node* obj = null_check(peek());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
169 // Check for locking null object
a61af66fc99e Initial load
duke
parents:
diff changeset
170 if (stopped()) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
171
a61af66fc99e Initial load
duke
parents:
diff changeset
172 // the monitor object is not part of debug info expression stack
a61af66fc99e Initial load
duke
parents:
diff changeset
173 pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // Insert a FastLockNode which takes as arguments the current thread pointer,
a61af66fc99e Initial load
duke
parents:
diff changeset
176 // the obj pointer & the address of the stack slot pair used for the lock.
a61af66fc99e Initial load
duke
parents:
diff changeset
177 shared_lock(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180 //------------------------------do_monitor_exit--------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
181 void Parse::do_monitor_exit() {
a61af66fc99e Initial load
duke
parents:
diff changeset
182 kill_dead_locals();
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184 pop(); // Pop oop to unlock
605
98cb887364d3 6810672: Comment typos
twisti
parents: 460
diff changeset
185 // Because monitors are guaranteed paired (else we bail out), we know
0
a61af66fc99e Initial load
duke
parents:
diff changeset
186 // the matching Lock for this Unlock. Hence we know there is no need
a61af66fc99e Initial load
duke
parents:
diff changeset
187 // for a null check on Unlock.
a61af66fc99e Initial load
duke
parents:
diff changeset
188 shared_unlock(map()->peek_monitor_box(), map()->peek_monitor_obj());
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }