File: | jdk/src/hotspot/share/opto/memnode.cpp |
Warning: | line 4772, column 9 Value stored to 'phi_len' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* |
2 | * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. |
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | * |
5 | * This code is free software; you can redistribute it and/or modify it |
6 | * under the terms of the GNU General Public License version 2 only, as |
7 | * published by the Free Software Foundation. |
8 | * |
9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
12 | * version 2 for more details (a copy is included in the LICENSE file that |
13 | * accompanied this code). |
14 | * |
15 | * You should have received a copy of the GNU General Public License version |
16 | * 2 along with this work; if not, write to the Free Software Foundation, |
17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
18 | * |
19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 | * or visit www.oracle.com if you need additional information or have any |
21 | * questions. |
22 | * |
23 | */ |
24 | |
25 | #include "precompiled.hpp" |
26 | #include "classfile/javaClasses.hpp" |
27 | #include "compiler/compileLog.hpp" |
28 | #include "gc/shared/barrierSet.hpp" |
29 | #include "gc/shared/c2/barrierSetC2.hpp" |
30 | #include "gc/shared/tlab_globals.hpp" |
31 | #include "memory/allocation.inline.hpp" |
32 | #include "memory/resourceArea.hpp" |
33 | #include "oops/objArrayKlass.hpp" |
34 | #include "opto/addnode.hpp" |
35 | #include "opto/arraycopynode.hpp" |
36 | #include "opto/cfgnode.hpp" |
37 | #include "opto/regalloc.hpp" |
38 | #include "opto/compile.hpp" |
39 | #include "opto/connode.hpp" |
40 | #include "opto/convertnode.hpp" |
41 | #include "opto/loopnode.hpp" |
42 | #include "opto/machnode.hpp" |
43 | #include "opto/matcher.hpp" |
44 | #include "opto/memnode.hpp" |
45 | #include "opto/mulnode.hpp" |
46 | #include "opto/narrowptrnode.hpp" |
47 | #include "opto/phaseX.hpp" |
48 | #include "opto/regmask.hpp" |
49 | #include "opto/rootnode.hpp" |
50 | #include "opto/vectornode.hpp" |
51 | #include "utilities/align.hpp" |
52 | #include "utilities/copy.hpp" |
53 | #include "utilities/macros.hpp" |
54 | #include "utilities/powerOfTwo.hpp" |
55 | #include "utilities/vmError.hpp" |
56 | |
57 | // Portions of code courtesy of Clifford Click |
58 | |
59 | // Optimization - Graph Style |
60 | |
61 | static Node *step_through_mergemem(PhaseGVN *phase, MergeMemNode *mmem, const TypePtr *tp, const TypePtr *adr_check, outputStream *st); |
62 | |
63 | //============================================================================= |
64 | uint MemNode::size_of() const { return sizeof(*this); } |
65 | |
66 | const TypePtr *MemNode::adr_type() const { |
67 | Node* adr = in(Address); |
68 | if (adr == NULL__null) return NULL__null; // node is dead |
69 | const TypePtr* cross_check = NULL__null; |
70 | DEBUG_ONLY(cross_check = _adr_type)cross_check = _adr_type; |
71 | return calculate_adr_type(adr->bottom_type(), cross_check); |
72 | } |
73 | |
74 | bool MemNode::check_if_adr_maybe_raw(Node* adr) { |
75 | if (adr != NULL__null) { |
76 | if (adr->bottom_type()->base() == Type::RawPtr || adr->bottom_type()->base() == Type::AnyPtr) { |
77 | return true; |
78 | } |
79 | } |
80 | return false; |
81 | } |
82 | |
83 | #ifndef PRODUCT |
84 | void MemNode::dump_spec(outputStream *st) const { |
85 | if (in(Address) == NULL__null) return; // node is dead |
86 | #ifndef ASSERT1 |
87 | // fake the missing field |
88 | const TypePtr* _adr_type = NULL__null; |
89 | if (in(Address) != NULL__null) |
90 | _adr_type = in(Address)->bottom_type()->isa_ptr(); |
91 | #endif |
92 | dump_adr_type(this, _adr_type, st); |
93 | |
94 | Compile* C = Compile::current(); |
95 | if (C->alias_type(_adr_type)->is_volatile()) { |
96 | st->print(" Volatile!"); |
97 | } |
98 | if (_unaligned_access) { |
99 | st->print(" unaligned"); |
100 | } |
101 | if (_mismatched_access) { |
102 | st->print(" mismatched"); |
103 | } |
104 | if (_unsafe_access) { |
105 | st->print(" unsafe"); |
106 | } |
107 | } |
108 | |
109 | void MemNode::dump_adr_type(const Node* mem, const TypePtr* adr_type, outputStream *st) { |
110 | st->print(" @"); |
111 | if (adr_type == NULL__null) { |
112 | st->print("NULL"); |
113 | } else { |
114 | adr_type->dump_on(st); |
115 | Compile* C = Compile::current(); |
116 | Compile::AliasType* atp = NULL__null; |
117 | if (C->have_alias_type(adr_type)) atp = C->alias_type(adr_type); |
118 | if (atp == NULL__null) |
119 | st->print(", idx=?\?;"); |
120 | else if (atp->index() == Compile::AliasIdxBot) |
121 | st->print(", idx=Bot;"); |
122 | else if (atp->index() == Compile::AliasIdxTop) |
123 | st->print(", idx=Top;"); |
124 | else if (atp->index() == Compile::AliasIdxRaw) |
125 | st->print(", idx=Raw;"); |
126 | else { |
127 | ciField* field = atp->field(); |
128 | if (field) { |
129 | st->print(", name="); |
130 | field->print_name_on(st); |
131 | } |
132 | st->print(", idx=%d;", atp->index()); |
133 | } |
134 | } |
135 | } |
136 | |
137 | extern void print_alias_types(); |
138 | |
139 | #endif |
140 | |
141 | Node *MemNode::optimize_simple_memory_chain(Node *mchain, const TypeOopPtr *t_oop, Node *load, PhaseGVN *phase) { |
142 | assert((t_oop != NULL), "sanity")do { if (!((t_oop != __null))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 142, "assert(" "(t_oop != __null)" ") failed", "sanity"); :: breakpoint(); } } while (0); |
143 | bool is_instance = t_oop->is_known_instance_field(); |
144 | bool is_boxed_value_load = t_oop->is_ptr_to_boxed_value() && |
145 | (load != NULL__null) && load->is_Load() && |
146 | (phase->is_IterGVN() != NULL__null); |
147 | if (!(is_instance || is_boxed_value_load)) |
148 | return mchain; // don't try to optimize non-instance types |
149 | uint instance_id = t_oop->instance_id(); |
150 | Node *start_mem = phase->C->start()->proj_out_or_null(TypeFunc::Memory); |
151 | Node *prev = NULL__null; |
152 | Node *result = mchain; |
153 | while (prev != result) { |
154 | prev = result; |
155 | if (result == start_mem) |
156 | break; // hit one of our sentinels |
157 | // skip over a call which does not affect this memory slice |
158 | if (result->is_Proj() && result->as_Proj()->_con == TypeFunc::Memory) { |
159 | Node *proj_in = result->in(0); |
160 | if (proj_in->is_Allocate() && proj_in->_idx == instance_id) { |
161 | break; // hit one of our sentinels |
162 | } else if (proj_in->is_Call()) { |
163 | // ArrayCopyNodes processed here as well |
164 | CallNode *call = proj_in->as_Call(); |
165 | if (!call->may_modify(t_oop, phase)) { // returns false for instances |
166 | result = call->in(TypeFunc::Memory); |
167 | } |
168 | } else if (proj_in->is_Initialize()) { |
169 | AllocateNode* alloc = proj_in->as_Initialize()->allocation(); |
170 | // Stop if this is the initialization for the object instance which |
171 | // contains this memory slice, otherwise skip over it. |
172 | if ((alloc == NULL__null) || (alloc->_idx == instance_id)) { |
173 | break; |
174 | } |
175 | if (is_instance) { |
176 | result = proj_in->in(TypeFunc::Memory); |
177 | } else if (is_boxed_value_load) { |
178 | Node* klass = alloc->in(AllocateNode::KlassNode); |
179 | const TypeKlassPtr* tklass = phase->type(klass)->is_klassptr(); |
180 | if (tklass->klass_is_exact() && !tklass->klass()->equals(t_oop->klass())) { |
181 | result = proj_in->in(TypeFunc::Memory); // not related allocation |
182 | } |
183 | } |
184 | } else if (proj_in->is_MemBar()) { |
185 | ArrayCopyNode* ac = NULL__null; |
186 | if (ArrayCopyNode::may_modify(t_oop, proj_in->as_MemBar(), phase, ac)) { |
187 | break; |
188 | } |
189 | result = proj_in->in(TypeFunc::Memory); |
190 | } else { |
191 | assert(false, "unexpected projection")do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 191, "assert(" "false" ") failed", "unexpected projection") ; ::breakpoint(); } } while (0); |
192 | } |
193 | } else if (result->is_ClearArray()) { |
194 | if (!is_instance || !ClearArrayNode::step_through(&result, instance_id, phase)) { |
195 | // Can not bypass initialization of the instance |
196 | // we are looking for. |
197 | break; |
198 | } |
199 | // Otherwise skip it (the call updated 'result' value). |
200 | } else if (result->is_MergeMem()) { |
201 | result = step_through_mergemem(phase, result->as_MergeMem(), t_oop, NULL__null, tty); |
202 | } |
203 | } |
204 | return result; |
205 | } |
206 | |
207 | Node *MemNode::optimize_memory_chain(Node *mchain, const TypePtr *t_adr, Node *load, PhaseGVN *phase) { |
208 | const TypeOopPtr* t_oop = t_adr->isa_oopptr(); |
209 | if (t_oop == NULL__null) |
210 | return mchain; // don't try to optimize non-oop types |
211 | Node* result = optimize_simple_memory_chain(mchain, t_oop, load, phase); |
212 | bool is_instance = t_oop->is_known_instance_field(); |
213 | PhaseIterGVN *igvn = phase->is_IterGVN(); |
214 | if (is_instance && igvn != NULL__null && result->is_Phi()) { |
215 | PhiNode *mphi = result->as_Phi(); |
216 | assert(mphi->bottom_type() == Type::MEMORY, "memory phi required")do { if (!(mphi->bottom_type() == Type::MEMORY)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 216, "assert(" "mphi->bottom_type() == Type::MEMORY" ") failed" , "memory phi required"); ::breakpoint(); } } while (0); |
217 | const TypePtr *t = mphi->adr_type(); |
218 | if (t == TypePtr::BOTTOM || t == TypeRawPtr::BOTTOM || |
219 | (t->isa_oopptr() && !t->is_oopptr()->is_known_instance() && |
220 | t->is_oopptr()->cast_to_exactness(true) |
221 | ->is_oopptr()->cast_to_ptr_type(t_oop->ptr()) |
222 | ->is_oopptr()->cast_to_instance_id(t_oop->instance_id()) == t_oop)) { |
223 | // clone the Phi with our address type |
224 | result = mphi->split_out_instance(t_adr, igvn); |
225 | } else { |
226 | assert(phase->C->get_alias_index(t) == phase->C->get_alias_index(t_adr), "correct memory chain")do { if (!(phase->C->get_alias_index(t) == phase->C-> get_alias_index(t_adr))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 226, "assert(" "phase->C->get_alias_index(t) == phase->C->get_alias_index(t_adr)" ") failed", "correct memory chain"); ::breakpoint(); } } while (0); |
227 | } |
228 | } |
229 | return result; |
230 | } |
231 | |
232 | static Node *step_through_mergemem(PhaseGVN *phase, MergeMemNode *mmem, const TypePtr *tp, const TypePtr *adr_check, outputStream *st) { |
233 | uint alias_idx = phase->C->get_alias_index(tp); |
234 | Node *mem = mmem; |
235 | #ifdef ASSERT1 |
236 | { |
237 | // Check that current type is consistent with the alias index used during graph construction |
238 | assert(alias_idx >= Compile::AliasIdxRaw, "must not be a bad alias_idx")do { if (!(alias_idx >= Compile::AliasIdxRaw)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 238, "assert(" "alias_idx >= Compile::AliasIdxRaw" ") failed" , "must not be a bad alias_idx"); ::breakpoint(); } } while ( 0); |
239 | bool consistent = adr_check == NULL__null || adr_check->empty() || |
240 | phase->C->must_alias(adr_check, alias_idx ); |
241 | // Sometimes dead array references collapse to a[-1], a[-2], or a[-3] |
242 | if( !consistent && adr_check != NULL__null && !adr_check->empty() && |
243 | tp->isa_aryptr() && tp->offset() == Type::OffsetBot && |
244 | adr_check->isa_aryptr() && adr_check->offset() != Type::OffsetBot && |
245 | ( adr_check->offset() == arrayOopDesc::length_offset_in_bytes() || |
246 | adr_check->offset() == oopDesc::klass_offset_in_bytes() || |
247 | adr_check->offset() == oopDesc::mark_offset_in_bytes() ) ) { |
248 | // don't assert if it is dead code. |
249 | consistent = true; |
250 | } |
251 | if( !consistent ) { |
252 | st->print("alias_idx==%d, adr_check==", alias_idx); |
253 | if( adr_check == NULL__null ) { |
254 | st->print("NULL"); |
255 | } else { |
256 | adr_check->dump(); |
257 | } |
258 | st->cr(); |
259 | print_alias_types(); |
260 | assert(consistent, "adr_check must match alias idx")do { if (!(consistent)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 260, "assert(" "consistent" ") failed", "adr_check must match alias idx" ); ::breakpoint(); } } while (0); |
261 | } |
262 | } |
263 | #endif |
264 | // TypeOopPtr::NOTNULL+any is an OOP with unknown offset - generally |
265 | // means an array I have not precisely typed yet. Do not do any |
266 | // alias stuff with it any time soon. |
267 | const TypeOopPtr *toop = tp->isa_oopptr(); |
268 | if( tp->base() != Type::AnyPtr && |
269 | !(toop && |
270 | toop->klass() != NULL__null && |
271 | toop->klass()->is_java_lang_Object() && |
272 | toop->offset() == Type::OffsetBot) ) { |
273 | // compress paths and change unreachable cycles to TOP |
274 | // If not, we can update the input infinitely along a MergeMem cycle |
275 | // Equivalent code in PhiNode::Ideal |
276 | Node* m = phase->transform(mmem); |
277 | // If transformed to a MergeMem, get the desired slice |
278 | // Otherwise the returned node represents memory for every slice |
279 | mem = (m->is_MergeMem())? m->as_MergeMem()->memory_at(alias_idx) : m; |
280 | // Update input if it is progress over what we have now |
281 | } |
282 | return mem; |
283 | } |
284 | |
285 | //--------------------------Ideal_common--------------------------------------- |
286 | // Look for degenerate control and memory inputs. Bypass MergeMem inputs. |
287 | // Unhook non-raw memories from complete (macro-expanded) initializations. |
288 | Node *MemNode::Ideal_common(PhaseGVN *phase, bool can_reshape) { |
289 | // If our control input is a dead region, kill all below the region |
290 | Node *ctl = in(MemNode::Control); |
291 | if (ctl && remove_dead_region(phase, can_reshape)) |
292 | return this; |
293 | ctl = in(MemNode::Control); |
294 | // Don't bother trying to transform a dead node |
295 | if (ctl && ctl->is_top()) return NodeSentinel(Node*)-1; |
296 | |
297 | PhaseIterGVN *igvn = phase->is_IterGVN(); |
298 | // Wait if control on the worklist. |
299 | if (ctl && can_reshape && igvn != NULL__null) { |
300 | Node* bol = NULL__null; |
301 | Node* cmp = NULL__null; |
302 | if (ctl->in(0)->is_If()) { |
303 | assert(ctl->is_IfTrue() || ctl->is_IfFalse(), "sanity")do { if (!(ctl->is_IfTrue() || ctl->is_IfFalse())) { (* g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 303, "assert(" "ctl->is_IfTrue() || ctl->is_IfFalse()" ") failed", "sanity"); ::breakpoint(); } } while (0); |
304 | bol = ctl->in(0)->in(1); |
305 | if (bol->is_Bool()) |
306 | cmp = ctl->in(0)->in(1)->in(1); |
307 | } |
308 | if (igvn->_worklist.member(ctl) || |
309 | (bol != NULL__null && igvn->_worklist.member(bol)) || |
310 | (cmp != NULL__null && igvn->_worklist.member(cmp)) ) { |
311 | // This control path may be dead. |
312 | // Delay this memory node transformation until the control is processed. |
313 | igvn->_worklist.push(this); |
314 | return NodeSentinel(Node*)-1; // caller will return NULL |
315 | } |
316 | } |
317 | // Ignore if memory is dead, or self-loop |
318 | Node *mem = in(MemNode::Memory); |
319 | if (phase->type( mem ) == Type::TOP) return NodeSentinel(Node*)-1; // caller will return NULL |
320 | assert(mem != this, "dead loop in MemNode::Ideal")do { if (!(mem != this)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 320, "assert(" "mem != this" ") failed", "dead loop in MemNode::Ideal" ); ::breakpoint(); } } while (0); |
321 | |
322 | if (can_reshape && igvn != NULL__null && igvn->_worklist.member(mem)) { |
323 | // This memory slice may be dead. |
324 | // Delay this mem node transformation until the memory is processed. |
325 | igvn->_worklist.push(this); |
326 | return NodeSentinel(Node*)-1; // caller will return NULL |
327 | } |
328 | |
329 | Node *address = in(MemNode::Address); |
330 | const Type *t_adr = phase->type(address); |
331 | if (t_adr == Type::TOP) return NodeSentinel(Node*)-1; // caller will return NULL |
332 | |
333 | if (can_reshape && is_unsafe_access() && (t_adr == TypePtr::NULL_PTR)) { |
334 | // Unsafe off-heap access with zero address. Remove access and other control users |
335 | // to not confuse optimizations and add a HaltNode to fail if this is ever executed. |
336 | assert(ctl != NULL, "unsafe accesses should be control dependent")do { if (!(ctl != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 336, "assert(" "ctl != __null" ") failed", "unsafe accesses should be control dependent" ); ::breakpoint(); } } while (0); |
337 | for (DUIterator_Fast imax, i = ctl->fast_outs(imax); i < imax; i++) { |
338 | Node* u = ctl->fast_out(i); |
339 | if (u != ctl) { |
340 | igvn->rehash_node_delayed(u); |
341 | int nb = u->replace_edge(ctl, phase->C->top(), igvn); |
342 | --i, imax -= nb; |
343 | } |
344 | } |
345 | Node* frame = igvn->transform(new ParmNode(phase->C->start(), TypeFunc::FramePtr)); |
346 | Node* halt = igvn->transform(new HaltNode(ctl, frame, "unsafe off-heap access with zero address")); |
347 | phase->C->root()->add_req(halt); |
348 | return this; |
349 | } |
350 | |
351 | if (can_reshape && igvn != NULL__null && |
352 | (igvn->_worklist.member(address) || |
353 | (igvn->_worklist.size() > 0 && t_adr != adr_type())) ) { |
354 | // The address's base and type may change when the address is processed. |
355 | // Delay this mem node transformation until the address is processed. |
356 | igvn->_worklist.push(this); |
357 | return NodeSentinel(Node*)-1; // caller will return NULL |
358 | } |
359 | |
360 | // Do NOT remove or optimize the next lines: ensure a new alias index |
361 | // is allocated for an oop pointer type before Escape Analysis. |
362 | // Note: C++ will not remove it since the call has side effect. |
363 | if (t_adr->isa_oopptr()) { |
364 | int alias_idx = phase->C->get_alias_index(t_adr->is_ptr()); |
365 | } |
366 | |
367 | Node* base = NULL__null; |
368 | if (address->is_AddP()) { |
369 | base = address->in(AddPNode::Base); |
370 | } |
371 | if (base != NULL__null && phase->type(base)->higher_equal(TypePtr::NULL_PTR) && |
372 | !t_adr->isa_rawptr()) { |
373 | // Note: raw address has TOP base and top->higher_equal(TypePtr::NULL_PTR) is true. |
374 | // Skip this node optimization if its address has TOP base. |
375 | return NodeSentinel(Node*)-1; // caller will return NULL |
376 | } |
377 | |
378 | // Avoid independent memory operations |
379 | Node* old_mem = mem; |
380 | |
381 | // The code which unhooks non-raw memories from complete (macro-expanded) |
382 | // initializations was removed. After macro-expansion all stores catched |
383 | // by Initialize node became raw stores and there is no information |
384 | // which memory slices they modify. So it is unsafe to move any memory |
385 | // operation above these stores. Also in most cases hooked non-raw memories |
386 | // were already unhooked by using information from detect_ptr_independence() |
387 | // and find_previous_store(). |
388 | |
389 | if (mem->is_MergeMem()) { |
390 | MergeMemNode* mmem = mem->as_MergeMem(); |
391 | const TypePtr *tp = t_adr->is_ptr(); |
392 | |
393 | mem = step_through_mergemem(phase, mmem, tp, adr_type(), tty); |
394 | } |
395 | |
396 | if (mem != old_mem) { |
397 | set_req(MemNode::Memory, mem); |
398 | if (can_reshape && old_mem->outcnt() == 0 && igvn != NULL__null) { |
399 | igvn->_worklist.push(old_mem); |
400 | } |
401 | if (phase->type(mem) == Type::TOP) return NodeSentinel(Node*)-1; |
402 | return this; |
403 | } |
404 | |
405 | // let the subclass continue analyzing... |
406 | return NULL__null; |
407 | } |
408 | |
409 | // Helper function for proving some simple control dominations. |
410 | // Attempt to prove that all control inputs of 'dom' dominate 'sub'. |
411 | // Already assumes that 'dom' is available at 'sub', and that 'sub' |
412 | // is not a constant (dominated by the method's StartNode). |
413 | // Used by MemNode::find_previous_store to prove that the |
414 | // control input of a memory operation predates (dominates) |
415 | // an allocation it wants to look past. |
416 | bool MemNode::all_controls_dominate(Node* dom, Node* sub) { |
417 | if (dom == NULL__null || dom->is_top() || sub == NULL__null || sub->is_top()) |
418 | return false; // Conservative answer for dead code |
419 | |
420 | // Check 'dom'. Skip Proj and CatchProj nodes. |
421 | dom = dom->find_exact_control(dom); |
422 | if (dom == NULL__null || dom->is_top()) |
423 | return false; // Conservative answer for dead code |
424 | |
425 | if (dom == sub) { |
426 | // For the case when, for example, 'sub' is Initialize and the original |
427 | // 'dom' is Proj node of the 'sub'. |
428 | return false; |
429 | } |
430 | |
431 | if (dom->is_Con() || dom->is_Start() || dom->is_Root() || dom == sub) |
432 | return true; |
433 | |
434 | // 'dom' dominates 'sub' if its control edge and control edges |
435 | // of all its inputs dominate or equal to sub's control edge. |
436 | |
437 | // Currently 'sub' is either Allocate, Initialize or Start nodes. |
438 | // Or Region for the check in LoadNode::Ideal(); |
439 | // 'sub' should have sub->in(0) != NULL. |
440 | assert(sub->is_Allocate() || sub->is_Initialize() || sub->is_Start() ||do { if (!(sub->is_Allocate() || sub->is_Initialize() || sub->is_Start() || sub->is_Region() || sub->is_Call ())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 441, "assert(" "sub->is_Allocate() || sub->is_Initialize() || sub->is_Start() || sub->is_Region() || sub->is_Call()" ") failed", "expecting only these nodes"); ::breakpoint(); } } while (0) |
441 | sub->is_Region() || sub->is_Call(), "expecting only these nodes")do { if (!(sub->is_Allocate() || sub->is_Initialize() || sub->is_Start() || sub->is_Region() || sub->is_Call ())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 441, "assert(" "sub->is_Allocate() || sub->is_Initialize() || sub->is_Start() || sub->is_Region() || sub->is_Call()" ") failed", "expecting only these nodes"); ::breakpoint(); } } while (0); |
442 | |
443 | // Get control edge of 'sub'. |
444 | Node* orig_sub = sub; |
445 | sub = sub->find_exact_control(sub->in(0)); |
446 | if (sub == NULL__null || sub->is_top()) |
447 | return false; // Conservative answer for dead code |
448 | |
449 | assert(sub->is_CFG(), "expecting control")do { if (!(sub->is_CFG())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 449, "assert(" "sub->is_CFG()" ") failed", "expecting control" ); ::breakpoint(); } } while (0); |
450 | |
451 | if (sub == dom) |
452 | return true; |
453 | |
454 | if (sub->is_Start() || sub->is_Root()) |
455 | return false; |
456 | |
457 | { |
458 | // Check all control edges of 'dom'. |
459 | |
460 | ResourceMark rm; |
461 | Node_List nlist; |
462 | Unique_Node_List dom_list; |
463 | |
464 | dom_list.push(dom); |
465 | bool only_dominating_controls = false; |
466 | |
467 | for (uint next = 0; next < dom_list.size(); next++) { |
468 | Node* n = dom_list.at(next); |
469 | if (n == orig_sub) |
470 | return false; // One of dom's inputs dominated by sub. |
471 | if (!n->is_CFG() && n->pinned()) { |
472 | // Check only own control edge for pinned non-control nodes. |
473 | n = n->find_exact_control(n->in(0)); |
474 | if (n == NULL__null || n->is_top()) |
475 | return false; // Conservative answer for dead code |
476 | assert(n->is_CFG(), "expecting control")do { if (!(n->is_CFG())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 476, "assert(" "n->is_CFG()" ") failed", "expecting control" ); ::breakpoint(); } } while (0); |
477 | dom_list.push(n); |
478 | } else if (n->is_Con() || n->is_Start() || n->is_Root()) { |
479 | only_dominating_controls = true; |
480 | } else if (n->is_CFG()) { |
481 | if (n->dominates(sub, nlist)) |
482 | only_dominating_controls = true; |
483 | else |
484 | return false; |
485 | } else { |
486 | // First, own control edge. |
487 | Node* m = n->find_exact_control(n->in(0)); |
488 | if (m != NULL__null) { |
489 | if (m->is_top()) |
490 | return false; // Conservative answer for dead code |
491 | dom_list.push(m); |
492 | } |
493 | // Now, the rest of edges. |
494 | uint cnt = n->req(); |
495 | for (uint i = 1; i < cnt; i++) { |
496 | m = n->find_exact_control(n->in(i)); |
497 | if (m == NULL__null || m->is_top()) |
498 | continue; |
499 | dom_list.push(m); |
500 | } |
501 | } |
502 | } |
503 | return only_dominating_controls; |
504 | } |
505 | } |
506 | |
507 | //---------------------detect_ptr_independence--------------------------------- |
508 | // Used by MemNode::find_previous_store to prove that two base |
509 | // pointers are never equal. |
510 | // The pointers are accompanied by their associated allocations, |
511 | // if any, which have been previously discovered by the caller. |
512 | bool MemNode::detect_ptr_independence(Node* p1, AllocateNode* a1, |
513 | Node* p2, AllocateNode* a2, |
514 | PhaseTransform* phase) { |
515 | // Attempt to prove that these two pointers cannot be aliased. |
516 | // They may both manifestly be allocations, and they should differ. |
517 | // Or, if they are not both allocations, they can be distinct constants. |
518 | // Otherwise, one is an allocation and the other a pre-existing value. |
519 | if (a1 == NULL__null && a2 == NULL__null) { // neither an allocation |
520 | return (p1 != p2) && p1->is_Con() && p2->is_Con(); |
521 | } else if (a1 != NULL__null && a2 != NULL__null) { // both allocations |
522 | return (a1 != a2); |
523 | } else if (a1 != NULL__null) { // one allocation a1 |
524 | // (Note: p2->is_Con implies p2->in(0)->is_Root, which dominates.) |
525 | return all_controls_dominate(p2, a1); |
526 | } else { //(a2 != NULL) // one allocation a2 |
527 | return all_controls_dominate(p1, a2); |
528 | } |
529 | return false; |
530 | } |
531 | |
532 | |
533 | // Find an arraycopy ac that produces the memory state represented by parameter mem. |
534 | // Return ac if |
535 | // (a) can_see_stored_value=true and ac must have set the value for this load or if |
536 | // (b) can_see_stored_value=false and ac could have set the value for this load or if |
537 | // (c) can_see_stored_value=false and ac cannot have set the value for this load. |
538 | // In case (c) change the parameter mem to the memory input of ac to skip it |
539 | // when searching stored value. |
540 | // Otherwise return NULL. |
541 | Node* LoadNode::find_previous_arraycopy(PhaseTransform* phase, Node* ld_alloc, Node*& mem, bool can_see_stored_value) const { |
542 | ArrayCopyNode* ac = find_array_copy_clone(phase, ld_alloc, mem); |
543 | if (ac != NULL__null) { |
544 | Node* ld_addp = in(MemNode::Address); |
545 | Node* src = ac->in(ArrayCopyNode::Src); |
546 | const TypeAryPtr* ary_t = phase->type(src)->isa_aryptr(); |
547 | |
548 | // This is a load from a cloned array. The corresponding arraycopy ac must |
549 | // have set the value for the load and we can return ac but only if the load |
550 | // is known to be within bounds. This is checked below. |
551 | if (ary_t != NULL__null && ld_addp->is_AddP()) { |
552 | Node* ld_offs = ld_addp->in(AddPNode::Offset); |
553 | BasicType ary_elem = ary_t->klass()->as_array_klass()->element_type()->basic_type(); |
554 | jlong header = arrayOopDesc::base_offset_in_bytes(ary_elem); |
555 | jlong elemsize = type2aelembytes(ary_elem); |
556 | |
557 | const TypeXTypeLong* ld_offs_t = phase->type(ld_offs)->isa_intptr_tisa_long(); |
558 | const TypeInt* sizetype = ary_t->size(); |
559 | |
560 | if (ld_offs_t->_lo >= header && ld_offs_t->_hi < (sizetype->_lo * elemsize + header)) { |
561 | // The load is known to be within bounds. It receives its value from ac. |
562 | return ac; |
563 | } |
564 | // The load is known to be out-of-bounds. |
565 | } |
566 | // The load could be out-of-bounds. It must not be hoisted but must remain |
567 | // dependent on the runtime range check. This is achieved by returning NULL. |
568 | } else if (mem->is_Proj() && mem->in(0) != NULL__null && mem->in(0)->is_ArrayCopy()) { |
569 | ArrayCopyNode* ac = mem->in(0)->as_ArrayCopy(); |
570 | |
571 | if (ac->is_arraycopy_validated() || |
572 | ac->is_copyof_validated() || |
573 | ac->is_copyofrange_validated()) { |
574 | Node* ld_addp = in(MemNode::Address); |
575 | if (ld_addp->is_AddP()) { |
576 | Node* ld_base = ld_addp->in(AddPNode::Address); |
577 | Node* ld_offs = ld_addp->in(AddPNode::Offset); |
578 | |
579 | Node* dest = ac->in(ArrayCopyNode::Dest); |
580 | |
581 | if (dest == ld_base) { |
582 | const TypeXTypeLong *ld_offs_t = phase->type(ld_offs)->isa_intptr_tisa_long(); |
583 | if (ac->modifies(ld_offs_t->_lo, ld_offs_t->_hi, phase, can_see_stored_value)) { |
584 | return ac; |
585 | } |
586 | if (!can_see_stored_value) { |
587 | mem = ac->in(TypeFunc::Memory); |
588 | return ac; |
589 | } |
590 | } |
591 | } |
592 | } |
593 | } |
594 | return NULL__null; |
595 | } |
596 | |
597 | ArrayCopyNode* MemNode::find_array_copy_clone(PhaseTransform* phase, Node* ld_alloc, Node* mem) const { |
598 | if (mem->is_Proj() && mem->in(0) != NULL__null && (mem->in(0)->Opcode() == Op_MemBarStoreStore || |
599 | mem->in(0)->Opcode() == Op_MemBarCPUOrder)) { |
600 | if (ld_alloc != NULL__null) { |
601 | // Check if there is an array copy for a clone |
602 | Node* mb = mem->in(0); |
603 | ArrayCopyNode* ac = NULL__null; |
604 | if (mb->in(0) != NULL__null && mb->in(0)->is_Proj() && |
605 | mb->in(0)->in(0) != NULL__null && mb->in(0)->in(0)->is_ArrayCopy()) { |
606 | ac = mb->in(0)->in(0)->as_ArrayCopy(); |
607 | } else { |
608 | // Step over GC barrier when ReduceInitialCardMarks is disabled |
609 | BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2(); |
610 | Node* control_proj_ac = bs->step_over_gc_barrier(mb->in(0)); |
611 | |
612 | if (control_proj_ac->is_Proj() && control_proj_ac->in(0)->is_ArrayCopy()) { |
613 | ac = control_proj_ac->in(0)->as_ArrayCopy(); |
614 | } |
615 | } |
616 | |
617 | if (ac != NULL__null && ac->is_clonebasic()) { |
618 | AllocateNode* alloc = AllocateNode::Ideal_allocation(ac->in(ArrayCopyNode::Dest), phase); |
619 | if (alloc != NULL__null && alloc == ld_alloc) { |
620 | return ac; |
621 | } |
622 | } |
623 | } |
624 | } |
625 | return NULL__null; |
626 | } |
627 | |
628 | // The logic for reordering loads and stores uses four steps: |
629 | // (a) Walk carefully past stores and initializations which we |
630 | // can prove are independent of this load. |
631 | // (b) Observe that the next memory state makes an exact match |
632 | // with self (load or store), and locate the relevant store. |
633 | // (c) Ensure that, if we were to wire self directly to the store, |
634 | // the optimizer would fold it up somehow. |
635 | // (d) Do the rewiring, and return, depending on some other part of |
636 | // the optimizer to fold up the load. |
637 | // This routine handles steps (a) and (b). Steps (c) and (d) are |
638 | // specific to loads and stores, so they are handled by the callers. |
639 | // (Currently, only LoadNode::Ideal has steps (c), (d). More later.) |
640 | // |
641 | Node* MemNode::find_previous_store(PhaseTransform* phase) { |
642 | Node* ctrl = in(MemNode::Control); |
643 | Node* adr = in(MemNode::Address); |
644 | intptr_t offset = 0; |
645 | Node* base = AddPNode::Ideal_base_and_offset(adr, phase, offset); |
646 | AllocateNode* alloc = AllocateNode::Ideal_allocation(base, phase); |
647 | |
648 | if (offset == Type::OffsetBot) |
649 | return NULL__null; // cannot unalias unless there are precise offsets |
650 | |
651 | const bool adr_maybe_raw = check_if_adr_maybe_raw(adr); |
652 | const TypeOopPtr *addr_t = adr->bottom_type()->isa_oopptr(); |
653 | |
654 | intptr_t size_in_bytes = memory_size(); |
655 | |
656 | Node* mem = in(MemNode::Memory); // start searching here... |
657 | |
658 | int cnt = 50; // Cycle limiter |
659 | for (;;) { // While we can dance past unrelated stores... |
660 | if (--cnt < 0) break; // Caught in cycle or a complicated dance? |
661 | |
662 | Node* prev = mem; |
663 | if (mem->is_Store()) { |
664 | Node* st_adr = mem->in(MemNode::Address); |
665 | intptr_t st_offset = 0; |
666 | Node* st_base = AddPNode::Ideal_base_and_offset(st_adr, phase, st_offset); |
667 | if (st_base == NULL__null) |
668 | break; // inscrutable pointer |
669 | |
670 | // For raw accesses it's not enough to prove that constant offsets don't intersect. |
671 | // We need the bases to be the equal in order for the offset check to make sense. |
672 | if ((adr_maybe_raw || check_if_adr_maybe_raw(st_adr)) && st_base != base) { |
673 | break; |
674 | } |
675 | |
676 | if (st_offset != offset && st_offset != Type::OffsetBot) { |
677 | const int MAX_STORE = MAX2(BytesPerLong, (int)MaxVectorSize); |
678 | assert(mem->as_Store()->memory_size() <= MAX_STORE, "")do { if (!(mem->as_Store()->memory_size() <= MAX_STORE )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 678, "assert(" "mem->as_Store()->memory_size() <= MAX_STORE" ") failed", ""); ::breakpoint(); } } while (0); |
679 | if (st_offset >= offset + size_in_bytes || |
680 | st_offset <= offset - MAX_STORE || |
681 | st_offset <= offset - mem->as_Store()->memory_size()) { |
682 | // Success: The offsets are provably independent. |
683 | // (You may ask, why not just test st_offset != offset and be done? |
684 | // The answer is that stores of different sizes can co-exist |
685 | // in the same sequence of RawMem effects. We sometimes initialize |
686 | // a whole 'tile' of array elements with a single jint or jlong.) |
687 | mem = mem->in(MemNode::Memory); |
688 | continue; // (a) advance through independent store memory |
689 | } |
690 | } |
691 | if (st_base != base && |
692 | detect_ptr_independence(base, alloc, |
693 | st_base, |
694 | AllocateNode::Ideal_allocation(st_base, phase), |
695 | phase)) { |
696 | // Success: The bases are provably independent. |
697 | mem = mem->in(MemNode::Memory); |
698 | continue; // (a) advance through independent store memory |
699 | } |
700 | |
701 | // (b) At this point, if the bases or offsets do not agree, we lose, |
702 | // since we have not managed to prove 'this' and 'mem' independent. |
703 | if (st_base == base && st_offset == offset) { |
704 | return mem; // let caller handle steps (c), (d) |
705 | } |
706 | |
707 | } else if (mem->is_Proj() && mem->in(0)->is_Initialize()) { |
708 | InitializeNode* st_init = mem->in(0)->as_Initialize(); |
709 | AllocateNode* st_alloc = st_init->allocation(); |
710 | if (st_alloc == NULL__null) |
711 | break; // something degenerated |
712 | bool known_identical = false; |
713 | bool known_independent = false; |
714 | if (alloc == st_alloc) |
715 | known_identical = true; |
716 | else if (alloc != NULL__null) |
717 | known_independent = true; |
718 | else if (all_controls_dominate(this, st_alloc)) |
719 | known_independent = true; |
720 | |
721 | if (known_independent) { |
722 | // The bases are provably independent: Either they are |
723 | // manifestly distinct allocations, or else the control |
724 | // of this load dominates the store's allocation. |
725 | int alias_idx = phase->C->get_alias_index(adr_type()); |
726 | if (alias_idx == Compile::AliasIdxRaw) { |
727 | mem = st_alloc->in(TypeFunc::Memory); |
728 | } else { |
729 | mem = st_init->memory(alias_idx); |
730 | } |
731 | continue; // (a) advance through independent store memory |
732 | } |
733 | |
734 | // (b) at this point, if we are not looking at a store initializing |
735 | // the same allocation we are loading from, we lose. |
736 | if (known_identical) { |
737 | // From caller, can_see_stored_value will consult find_captured_store. |
738 | return mem; // let caller handle steps (c), (d) |
739 | } |
740 | |
741 | } else if (find_previous_arraycopy(phase, alloc, mem, false) != NULL__null) { |
742 | if (prev != mem) { |
743 | // Found an arraycopy but it doesn't affect that load |
744 | continue; |
745 | } |
746 | // Found an arraycopy that may affect that load |
747 | return mem; |
748 | } else if (addr_t != NULL__null && addr_t->is_known_instance_field()) { |
749 | // Can't use optimize_simple_memory_chain() since it needs PhaseGVN. |
750 | if (mem->is_Proj() && mem->in(0)->is_Call()) { |
751 | // ArrayCopyNodes processed here as well. |
752 | CallNode *call = mem->in(0)->as_Call(); |
753 | if (!call->may_modify(addr_t, phase)) { |
754 | mem = call->in(TypeFunc::Memory); |
755 | continue; // (a) advance through independent call memory |
756 | } |
757 | } else if (mem->is_Proj() && mem->in(0)->is_MemBar()) { |
758 | ArrayCopyNode* ac = NULL__null; |
759 | if (ArrayCopyNode::may_modify(addr_t, mem->in(0)->as_MemBar(), phase, ac)) { |
760 | break; |
761 | } |
762 | mem = mem->in(0)->in(TypeFunc::Memory); |
763 | continue; // (a) advance through independent MemBar memory |
764 | } else if (mem->is_ClearArray()) { |
765 | if (ClearArrayNode::step_through(&mem, (uint)addr_t->instance_id(), phase)) { |
766 | // (the call updated 'mem' value) |
767 | continue; // (a) advance through independent allocation memory |
768 | } else { |
769 | // Can not bypass initialization of the instance |
770 | // we are looking for. |
771 | return mem; |
772 | } |
773 | } else if (mem->is_MergeMem()) { |
774 | int alias_idx = phase->C->get_alias_index(adr_type()); |
775 | mem = mem->as_MergeMem()->memory_at(alias_idx); |
776 | continue; // (a) advance through independent MergeMem memory |
777 | } |
778 | } |
779 | |
780 | // Unless there is an explicit 'continue', we must bail out here, |
781 | // because 'mem' is an inscrutable memory state (e.g., a call). |
782 | break; |
783 | } |
784 | |
785 | return NULL__null; // bail out |
786 | } |
787 | |
788 | //----------------------calculate_adr_type------------------------------------- |
789 | // Helper function. Notices when the given type of address hits top or bottom. |
790 | // Also, asserts a cross-check of the type against the expected address type. |
791 | const TypePtr* MemNode::calculate_adr_type(const Type* t, const TypePtr* cross_check) { |
792 | if (t == Type::TOP) return NULL__null; // does not touch memory any more? |
793 | #ifdef ASSERT1 |
794 | if (!VerifyAliases || VMError::is_error_reported() || Node::in_dump()) cross_check = NULL__null; |
795 | #endif |
796 | const TypePtr* tp = t->isa_ptr(); |
797 | if (tp == NULL__null) { |
798 | assert(cross_check == NULL || cross_check == TypePtr::BOTTOM, "expected memory type must be wide")do { if (!(cross_check == __null || cross_check == TypePtr::BOTTOM )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 798, "assert(" "cross_check == __null || cross_check == TypePtr::BOTTOM" ") failed", "expected memory type must be wide"); ::breakpoint (); } } while (0); |
799 | return TypePtr::BOTTOM; // touches lots of memory |
800 | } else { |
801 | #ifdef ASSERT1 |
802 | // %%%% [phh] We don't check the alias index if cross_check is |
803 | // TypeRawPtr::BOTTOM. Needs to be investigated. |
804 | if (cross_check != NULL__null && |
805 | cross_check != TypePtr::BOTTOM && |
806 | cross_check != TypeRawPtr::BOTTOM) { |
807 | // Recheck the alias index, to see if it has changed (due to a bug). |
808 | Compile* C = Compile::current(); |
809 | assert(C->get_alias_index(cross_check) == C->get_alias_index(tp),do { if (!(C->get_alias_index(cross_check) == C->get_alias_index (tp))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 810, "assert(" "C->get_alias_index(cross_check) == C->get_alias_index(tp)" ") failed", "must stay in the original alias category"); ::breakpoint (); } } while (0) |
810 | "must stay in the original alias category")do { if (!(C->get_alias_index(cross_check) == C->get_alias_index (tp))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 810, "assert(" "C->get_alias_index(cross_check) == C->get_alias_index(tp)" ") failed", "must stay in the original alias category"); ::breakpoint (); } } while (0); |
811 | // The type of the address must be contained in the adr_type, |
812 | // disregarding "null"-ness. |
813 | // (We make an exception for TypeRawPtr::BOTTOM, which is a bit bucket.) |
814 | const TypePtr* tp_notnull = tp->join(TypePtr::NOTNULL)->is_ptr(); |
815 | assert(cross_check->meet(tp_notnull) == cross_check->remove_speculative(),do { if (!(cross_check->meet(tp_notnull) == cross_check-> remove_speculative())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 816, "assert(" "cross_check->meet(tp_notnull) == cross_check->remove_speculative()" ") failed", "real address must not escape from expected memory type" ); ::breakpoint(); } } while (0) |
816 | "real address must not escape from expected memory type")do { if (!(cross_check->meet(tp_notnull) == cross_check-> remove_speculative())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 816, "assert(" "cross_check->meet(tp_notnull) == cross_check->remove_speculative()" ") failed", "real address must not escape from expected memory type" ); ::breakpoint(); } } while (0); |
817 | } |
818 | #endif |
819 | return tp; |
820 | } |
821 | } |
822 | |
823 | //============================================================================= |
824 | // Should LoadNode::Ideal() attempt to remove control edges? |
825 | bool LoadNode::can_remove_control() const { |
826 | return true; |
827 | } |
828 | uint LoadNode::size_of() const { return sizeof(*this); } |
829 | bool LoadNode::cmp( const Node &n ) const |
830 | { return !Type::cmp( _type, ((LoadNode&)n)._type ); } |
831 | const Type *LoadNode::bottom_type() const { return _type; } |
832 | uint LoadNode::ideal_reg() const { |
833 | return _type->ideal_reg(); |
834 | } |
835 | |
836 | #ifndef PRODUCT |
837 | void LoadNode::dump_spec(outputStream *st) const { |
838 | MemNode::dump_spec(st); |
839 | if( !Verbose && !WizardMode ) { |
840 | // standard dump does this in Verbose and WizardMode |
841 | st->print(" #"); _type->dump_on(st); |
842 | } |
843 | if (!depends_only_on_test()) { |
844 | st->print(" (does not depend only on test)"); |
845 | } |
846 | } |
847 | #endif |
848 | |
849 | #ifdef ASSERT1 |
850 | //----------------------------is_immutable_value------------------------------- |
851 | // Helper function to allow a raw load without control edge for some cases |
852 | bool LoadNode::is_immutable_value(Node* adr) { |
853 | return (adr->is_AddP() && adr->in(AddPNode::Base)->is_top() && |
854 | adr->in(AddPNode::Address)->Opcode() == Op_ThreadLocal && |
855 | (adr->in(AddPNode::Offset)->find_intptr_t_confind_long_con(-1) == |
856 | in_bytes(JavaThread::osthread_offset()) || |
857 | adr->in(AddPNode::Offset)->find_intptr_t_confind_long_con(-1) == |
858 | in_bytes(JavaThread::threadObj_offset()))); |
859 | } |
860 | #endif |
861 | |
862 | //----------------------------LoadNode::make----------------------------------- |
863 | // Polymorphic factory method: |
864 | Node *LoadNode::make(PhaseGVN& gvn, Node *ctl, Node *mem, Node *adr, const TypePtr* adr_type, const Type *rt, BasicType bt, MemOrd mo, |
865 | ControlDependency control_dependency, bool unaligned, bool mismatched, bool unsafe, uint8_t barrier_data) { |
866 | Compile* C = gvn.C; |
867 | |
868 | // sanity check the alias category against the created node type |
869 | assert(!(adr_type->isa_oopptr() &&do { if (!(!(adr_type->isa_oopptr() && adr_type-> offset() == oopDesc::klass_offset_in_bytes()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 871, "assert(" "!(adr_type->isa_oopptr() && adr_type->offset() == oopDesc::klass_offset_in_bytes())" ") failed", "use LoadKlassNode instead"); ::breakpoint(); } } while (0) |
870 | adr_type->offset() == oopDesc::klass_offset_in_bytes()),do { if (!(!(adr_type->isa_oopptr() && adr_type-> offset() == oopDesc::klass_offset_in_bytes()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 871, "assert(" "!(adr_type->isa_oopptr() && adr_type->offset() == oopDesc::klass_offset_in_bytes())" ") failed", "use LoadKlassNode instead"); ::breakpoint(); } } while (0) |
871 | "use LoadKlassNode instead")do { if (!(!(adr_type->isa_oopptr() && adr_type-> offset() == oopDesc::klass_offset_in_bytes()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 871, "assert(" "!(adr_type->isa_oopptr() && adr_type->offset() == oopDesc::klass_offset_in_bytes())" ") failed", "use LoadKlassNode instead"); ::breakpoint(); } } while (0); |
872 | assert(!(adr_type->isa_aryptr() &&do { if (!(!(adr_type->isa_aryptr() && adr_type-> offset() == arrayOopDesc::length_offset_in_bytes()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 874, "assert(" "!(adr_type->isa_aryptr() && adr_type->offset() == arrayOopDesc::length_offset_in_bytes())" ") failed", "use LoadRangeNode instead"); ::breakpoint(); } } while (0) |
873 | adr_type->offset() == arrayOopDesc::length_offset_in_bytes()),do { if (!(!(adr_type->isa_aryptr() && adr_type-> offset() == arrayOopDesc::length_offset_in_bytes()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 874, "assert(" "!(adr_type->isa_aryptr() && adr_type->offset() == arrayOopDesc::length_offset_in_bytes())" ") failed", "use LoadRangeNode instead"); ::breakpoint(); } } while (0) |
874 | "use LoadRangeNode instead")do { if (!(!(adr_type->isa_aryptr() && adr_type-> offset() == arrayOopDesc::length_offset_in_bytes()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 874, "assert(" "!(adr_type->isa_aryptr() && adr_type->offset() == arrayOopDesc::length_offset_in_bytes())" ") failed", "use LoadRangeNode instead"); ::breakpoint(); } } while (0); |
875 | // Check control edge of raw loads |
876 | assert( ctl != NULL || C->get_alias_index(adr_type) != Compile::AliasIdxRaw ||do { if (!(ctl != __null || C->get_alias_index(adr_type) != Compile::AliasIdxRaw || rt->isa_oopptr() || is_immutable_value (adr))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 879, "assert(" "ctl != __null || C->get_alias_index(adr_type) != Compile::AliasIdxRaw || rt->isa_oopptr() || is_immutable_value(adr)" ") failed", "raw memory operations should have control edge" ); ::breakpoint(); } } while (0) |
877 | // oop will be recorded in oop map if load crosses safepointdo { if (!(ctl != __null || C->get_alias_index(adr_type) != Compile::AliasIdxRaw || rt->isa_oopptr() || is_immutable_value (adr))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 879, "assert(" "ctl != __null || C->get_alias_index(adr_type) != Compile::AliasIdxRaw || rt->isa_oopptr() || is_immutable_value(adr)" ") failed", "raw memory operations should have control edge" ); ::breakpoint(); } } while (0) |
878 | rt->isa_oopptr() || is_immutable_value(adr),do { if (!(ctl != __null || C->get_alias_index(adr_type) != Compile::AliasIdxRaw || rt->isa_oopptr() || is_immutable_value (adr))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 879, "assert(" "ctl != __null || C->get_alias_index(adr_type) != Compile::AliasIdxRaw || rt->isa_oopptr() || is_immutable_value(adr)" ") failed", "raw memory operations should have control edge" ); ::breakpoint(); } } while (0) |
879 | "raw memory operations should have control edge")do { if (!(ctl != __null || C->get_alias_index(adr_type) != Compile::AliasIdxRaw || rt->isa_oopptr() || is_immutable_value (adr))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 879, "assert(" "ctl != __null || C->get_alias_index(adr_type) != Compile::AliasIdxRaw || rt->isa_oopptr() || is_immutable_value(adr)" ") failed", "raw memory operations should have control edge" ); ::breakpoint(); } } while (0); |
880 | LoadNode* load = NULL__null; |
881 | switch (bt) { |
882 | case T_BOOLEAN: load = new LoadUBNode(ctl, mem, adr, adr_type, rt->is_int(), mo, control_dependency); break; |
883 | case T_BYTE: load = new LoadBNode (ctl, mem, adr, adr_type, rt->is_int(), mo, control_dependency); break; |
884 | case T_INT: load = new LoadINode (ctl, mem, adr, adr_type, rt->is_int(), mo, control_dependency); break; |
885 | case T_CHAR: load = new LoadUSNode(ctl, mem, adr, adr_type, rt->is_int(), mo, control_dependency); break; |
886 | case T_SHORT: load = new LoadSNode (ctl, mem, adr, adr_type, rt->is_int(), mo, control_dependency); break; |
887 | case T_LONG: load = new LoadLNode (ctl, mem, adr, adr_type, rt->is_long(), mo, control_dependency); break; |
888 | case T_FLOAT: load = new LoadFNode (ctl, mem, adr, adr_type, rt, mo, control_dependency); break; |
889 | case T_DOUBLE: load = new LoadDNode (ctl, mem, adr, adr_type, rt, mo, control_dependency); break; |
890 | case T_ADDRESS: load = new LoadPNode (ctl, mem, adr, adr_type, rt->is_ptr(), mo, control_dependency); break; |
891 | case T_OBJECT: |
892 | #ifdef _LP641 |
893 | if (adr->bottom_type()->is_ptr_to_narrowoop()) { |
894 | load = new LoadNNode(ctl, mem, adr, adr_type, rt->make_narrowoop(), mo, control_dependency); |
895 | } else |
896 | #endif |
897 | { |
898 | assert(!adr->bottom_type()->is_ptr_to_narrowoop() && !adr->bottom_type()->is_ptr_to_narrowklass(), "should have got back a narrow oop")do { if (!(!adr->bottom_type()->is_ptr_to_narrowoop() && !adr->bottom_type()->is_ptr_to_narrowklass())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 898, "assert(" "!adr->bottom_type()->is_ptr_to_narrowoop() && !adr->bottom_type()->is_ptr_to_narrowklass()" ") failed", "should have got back a narrow oop"); ::breakpoint (); } } while (0); |
899 | load = new LoadPNode(ctl, mem, adr, adr_type, rt->is_ptr(), mo, control_dependency); |
900 | } |
901 | break; |
902 | default: |
903 | ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here( "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 903); ::breakpoint(); } while (0); |
904 | break; |
905 | } |
906 | assert(load != NULL, "LoadNode should have been created")do { if (!(load != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 906, "assert(" "load != __null" ") failed", "LoadNode should have been created" ); ::breakpoint(); } } while (0); |
907 | if (unaligned) { |
908 | load->set_unaligned_access(); |
909 | } |
910 | if (mismatched) { |
911 | load->set_mismatched_access(); |
912 | } |
913 | if (unsafe) { |
914 | load->set_unsafe_access(); |
915 | } |
916 | load->set_barrier_data(barrier_data); |
917 | if (load->Opcode() == Op_LoadN) { |
918 | Node* ld = gvn.transform(load); |
919 | return new DecodeNNode(ld, ld->bottom_type()->make_ptr()); |
920 | } |
921 | |
922 | return load; |
923 | } |
924 | |
925 | LoadLNode* LoadLNode::make_atomic(Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, const Type* rt, MemOrd mo, |
926 | ControlDependency control_dependency, bool unaligned, bool mismatched, bool unsafe, uint8_t barrier_data) { |
927 | bool require_atomic = true; |
928 | LoadLNode* load = new LoadLNode(ctl, mem, adr, adr_type, rt->is_long(), mo, control_dependency, require_atomic); |
929 | if (unaligned) { |
930 | load->set_unaligned_access(); |
931 | } |
932 | if (mismatched) { |
933 | load->set_mismatched_access(); |
934 | } |
935 | if (unsafe) { |
936 | load->set_unsafe_access(); |
937 | } |
938 | load->set_barrier_data(barrier_data); |
939 | return load; |
940 | } |
941 | |
942 | LoadDNode* LoadDNode::make_atomic(Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, const Type* rt, MemOrd mo, |
943 | ControlDependency control_dependency, bool unaligned, bool mismatched, bool unsafe, uint8_t barrier_data) { |
944 | bool require_atomic = true; |
945 | LoadDNode* load = new LoadDNode(ctl, mem, adr, adr_type, rt, mo, control_dependency, require_atomic); |
946 | if (unaligned) { |
947 | load->set_unaligned_access(); |
948 | } |
949 | if (mismatched) { |
950 | load->set_mismatched_access(); |
951 | } |
952 | if (unsafe) { |
953 | load->set_unsafe_access(); |
954 | } |
955 | load->set_barrier_data(barrier_data); |
956 | return load; |
957 | } |
958 | |
959 | |
960 | |
961 | //------------------------------hash------------------------------------------- |
962 | uint LoadNode::hash() const { |
963 | // unroll addition of interesting fields |
964 | return (uintptr_t)in(Control) + (uintptr_t)in(Memory) + (uintptr_t)in(Address); |
965 | } |
966 | |
967 | static bool skip_through_membars(Compile::AliasType* atp, const TypeInstPtr* tp, bool eliminate_boxing) { |
968 | if ((atp != NULL__null) && (atp->index() >= Compile::AliasIdxRaw)) { |
969 | bool non_volatile = (atp->field() != NULL__null) && !atp->field()->is_volatile(); |
970 | bool is_stable_ary = FoldStableValues && |
971 | (tp != NULL__null) && (tp->isa_aryptr() != NULL__null) && |
972 | tp->isa_aryptr()->is_stable(); |
973 | |
974 | return (eliminate_boxing && non_volatile) || is_stable_ary; |
975 | } |
976 | |
977 | return false; |
978 | } |
979 | |
980 | // Is the value loaded previously stored by an arraycopy? If so return |
981 | // a load node that reads from the source array so we may be able to |
982 | // optimize out the ArrayCopy node later. |
983 | Node* LoadNode::can_see_arraycopy_value(Node* st, PhaseGVN* phase) const { |
984 | Node* ld_adr = in(MemNode::Address); |
985 | intptr_t ld_off = 0; |
986 | AllocateNode* ld_alloc = AllocateNode::Ideal_allocation(ld_adr, phase, ld_off); |
987 | Node* ac = find_previous_arraycopy(phase, ld_alloc, st, true); |
988 | if (ac != NULL__null) { |
989 | assert(ac->is_ArrayCopy(), "what kind of node can this be?")do { if (!(ac->is_ArrayCopy())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 989, "assert(" "ac->is_ArrayCopy()" ") failed", "what kind of node can this be?" ); ::breakpoint(); } } while (0); |
990 | |
991 | Node* mem = ac->in(TypeFunc::Memory); |
992 | Node* ctl = ac->in(0); |
993 | Node* src = ac->in(ArrayCopyNode::Src); |
994 | |
995 | if (!ac->as_ArrayCopy()->is_clonebasic() && !phase->type(src)->isa_aryptr()) { |
996 | return NULL__null; |
997 | } |
998 | |
999 | LoadNode* ld = clone()->as_Load(); |
1000 | Node* addp = in(MemNode::Address)->clone(); |
1001 | if (ac->as_ArrayCopy()->is_clonebasic()) { |
1002 | assert(ld_alloc != NULL, "need an alloc")do { if (!(ld_alloc != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1002, "assert(" "ld_alloc != __null" ") failed", "need an alloc" ); ::breakpoint(); } } while (0); |
1003 | assert(addp->is_AddP(), "address must be addp")do { if (!(addp->is_AddP())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1003, "assert(" "addp->is_AddP()" ") failed", "address must be addp" ); ::breakpoint(); } } while (0); |
1004 | BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2(); |
1005 | assert(bs->step_over_gc_barrier(addp->in(AddPNode::Base)) == bs->step_over_gc_barrier(ac->in(ArrayCopyNode::Dest)), "strange pattern")do { if (!(bs->step_over_gc_barrier(addp->in(AddPNode:: Base)) == bs->step_over_gc_barrier(ac->in(ArrayCopyNode ::Dest)))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1005, "assert(" "bs->step_over_gc_barrier(addp->in(AddPNode::Base)) == bs->step_over_gc_barrier(ac->in(ArrayCopyNode::Dest))" ") failed", "strange pattern"); ::breakpoint(); } } while (0 ); |
1006 | assert(bs->step_over_gc_barrier(addp->in(AddPNode::Address)) == bs->step_over_gc_barrier(ac->in(ArrayCopyNode::Dest)), "strange pattern")do { if (!(bs->step_over_gc_barrier(addp->in(AddPNode:: Address)) == bs->step_over_gc_barrier(ac->in(ArrayCopyNode ::Dest)))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1006, "assert(" "bs->step_over_gc_barrier(addp->in(AddPNode::Address)) == bs->step_over_gc_barrier(ac->in(ArrayCopyNode::Dest))" ") failed", "strange pattern"); ::breakpoint(); } } while (0 ); |
1007 | addp->set_req(AddPNode::Base, src); |
1008 | addp->set_req(AddPNode::Address, src); |
1009 | } else { |
1010 | assert(ac->as_ArrayCopy()->is_arraycopy_validated() ||do { if (!(ac->as_ArrayCopy()->is_arraycopy_validated() || ac->as_ArrayCopy()->is_copyof_validated() || ac-> as_ArrayCopy()->is_copyofrange_validated())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1012, "assert(" "ac->as_ArrayCopy()->is_arraycopy_validated() || ac->as_ArrayCopy()->is_copyof_validated() || ac->as_ArrayCopy()->is_copyofrange_validated()" ") failed", "only supported cases"); ::breakpoint(); } } while (0) |
1011 | ac->as_ArrayCopy()->is_copyof_validated() ||do { if (!(ac->as_ArrayCopy()->is_arraycopy_validated() || ac->as_ArrayCopy()->is_copyof_validated() || ac-> as_ArrayCopy()->is_copyofrange_validated())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1012, "assert(" "ac->as_ArrayCopy()->is_arraycopy_validated() || ac->as_ArrayCopy()->is_copyof_validated() || ac->as_ArrayCopy()->is_copyofrange_validated()" ") failed", "only supported cases"); ::breakpoint(); } } while (0) |
1012 | ac->as_ArrayCopy()->is_copyofrange_validated(), "only supported cases")do { if (!(ac->as_ArrayCopy()->is_arraycopy_validated() || ac->as_ArrayCopy()->is_copyof_validated() || ac-> as_ArrayCopy()->is_copyofrange_validated())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1012, "assert(" "ac->as_ArrayCopy()->is_arraycopy_validated() || ac->as_ArrayCopy()->is_copyof_validated() || ac->as_ArrayCopy()->is_copyofrange_validated()" ") failed", "only supported cases"); ::breakpoint(); } } while (0); |
1013 | assert(addp->in(AddPNode::Base) == addp->in(AddPNode::Address), "should be")do { if (!(addp->in(AddPNode::Base) == addp->in(AddPNode ::Address))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1013, "assert(" "addp->in(AddPNode::Base) == addp->in(AddPNode::Address)" ") failed", "should be"); ::breakpoint(); } } while (0); |
1014 | addp->set_req(AddPNode::Base, src); |
1015 | addp->set_req(AddPNode::Address, src); |
1016 | |
1017 | const TypeAryPtr* ary_t = phase->type(in(MemNode::Address))->isa_aryptr(); |
1018 | BasicType ary_elem = ary_t->klass()->as_array_klass()->element_type()->basic_type(); |
1019 | uint header = arrayOopDesc::base_offset_in_bytes(ary_elem); |
1020 | uint shift = exact_log2(type2aelembytes(ary_elem)); |
1021 | |
1022 | Node* diff = phase->transform(new SubINode(ac->in(ArrayCopyNode::SrcPos), ac->in(ArrayCopyNode::DestPos))); |
1023 | #ifdef _LP641 |
1024 | diff = phase->transform(new ConvI2LNode(diff)); |
1025 | #endif |
1026 | diff = phase->transform(new LShiftXNodeLShiftLNode(diff, phase->intcon(shift))); |
1027 | |
1028 | Node* offset = phase->transform(new AddXNodeAddLNode(addp->in(AddPNode::Offset), diff)); |
1029 | addp->set_req(AddPNode::Offset, offset); |
1030 | } |
1031 | addp = phase->transform(addp); |
1032 | #ifdef ASSERT1 |
1033 | const TypePtr* adr_type = phase->type(addp)->is_ptr(); |
1034 | ld->_adr_type = adr_type; |
1035 | #endif |
1036 | ld->set_req(MemNode::Address, addp); |
1037 | ld->set_req(0, ctl); |
1038 | ld->set_req(MemNode::Memory, mem); |
1039 | // load depends on the tests that validate the arraycopy |
1040 | ld->_control_dependency = UnknownControl; |
1041 | return ld; |
1042 | } |
1043 | return NULL__null; |
1044 | } |
1045 | |
1046 | |
1047 | //---------------------------can_see_stored_value------------------------------ |
1048 | // This routine exists to make sure this set of tests is done the same |
1049 | // everywhere. We need to make a coordinated change: first LoadNode::Ideal |
1050 | // will change the graph shape in a way which makes memory alive twice at the |
1051 | // same time (uses the Oracle model of aliasing), then some |
1052 | // LoadXNode::Identity will fold things back to the equivalence-class model |
1053 | // of aliasing. |
1054 | Node* MemNode::can_see_stored_value(Node* st, PhaseTransform* phase) const { |
1055 | Node* ld_adr = in(MemNode::Address); |
1056 | intptr_t ld_off = 0; |
1057 | Node* ld_base = AddPNode::Ideal_base_and_offset(ld_adr, phase, ld_off); |
1058 | Node* ld_alloc = AllocateNode::Ideal_allocation(ld_base, phase); |
1059 | const TypeInstPtr* tp = phase->type(ld_adr)->isa_instptr(); |
1060 | Compile::AliasType* atp = (tp != NULL__null) ? phase->C->alias_type(tp) : NULL__null; |
1061 | // This is more general than load from boxing objects. |
1062 | if (skip_through_membars(atp, tp, phase->C->eliminate_boxing())) { |
1063 | uint alias_idx = atp->index(); |
1064 | Node* result = NULL__null; |
1065 | Node* current = st; |
1066 | // Skip through chains of MemBarNodes checking the MergeMems for |
1067 | // new states for the slice of this load. Stop once any other |
1068 | // kind of node is encountered. Loads from final memory can skip |
1069 | // through any kind of MemBar but normal loads shouldn't skip |
1070 | // through MemBarAcquire since the could allow them to move out of |
1071 | // a synchronized region. It is not safe to step over MemBarCPUOrder, |
1072 | // because alias info above them may be inaccurate (e.g., due to |
1073 | // mixed/mismatched unsafe accesses). |
1074 | bool is_final_mem = !atp->is_rewritable(); |
1075 | while (current->is_Proj()) { |
1076 | int opc = current->in(0)->Opcode(); |
1077 | if ((is_final_mem && (opc == Op_MemBarAcquire || |
1078 | opc == Op_MemBarAcquireLock || |
1079 | opc == Op_LoadFence)) || |
1080 | opc == Op_MemBarRelease || |
1081 | opc == Op_StoreFence || |
1082 | opc == Op_MemBarReleaseLock || |
1083 | opc == Op_MemBarStoreStore || |
1084 | opc == Op_StoreStoreFence) { |
1085 | Node* mem = current->in(0)->in(TypeFunc::Memory); |
1086 | if (mem->is_MergeMem()) { |
1087 | MergeMemNode* merge = mem->as_MergeMem(); |
1088 | Node* new_st = merge->memory_at(alias_idx); |
1089 | if (new_st == merge->base_memory()) { |
1090 | // Keep searching |
1091 | current = new_st; |
1092 | continue; |
1093 | } |
1094 | // Save the new memory state for the slice and fall through |
1095 | // to exit. |
1096 | result = new_st; |
1097 | } |
1098 | } |
1099 | break; |
1100 | } |
1101 | if (result != NULL__null) { |
1102 | st = result; |
1103 | } |
1104 | } |
1105 | |
1106 | // Loop around twice in the case Load -> Initialize -> Store. |
1107 | // (See PhaseIterGVN::add_users_to_worklist, which knows about this case.) |
1108 | for (int trip = 0; trip <= 1; trip++) { |
1109 | |
1110 | if (st->is_Store()) { |
1111 | Node* st_adr = st->in(MemNode::Address); |
1112 | if (st_adr != ld_adr) { |
1113 | // Try harder before giving up. Unify base pointers with casts (e.g., raw/non-raw pointers). |
1114 | intptr_t st_off = 0; |
1115 | Node* st_base = AddPNode::Ideal_base_and_offset(st_adr, phase, st_off); |
1116 | if (ld_base == NULL__null) return NULL__null; |
1117 | if (st_base == NULL__null) return NULL__null; |
1118 | if (!ld_base->eqv_uncast(st_base, /*keep_deps=*/true)) return NULL__null; |
1119 | if (ld_off != st_off) return NULL__null; |
1120 | if (ld_off == Type::OffsetBot) return NULL__null; |
1121 | // Same base, same offset. |
1122 | // Possible improvement for arrays: check index value instead of absolute offset. |
1123 | |
1124 | // At this point we have proven something like this setup: |
1125 | // B = << base >> |
1126 | // L = LoadQ(AddP(Check/CastPP(B), #Off)) |
1127 | // S = StoreQ(AddP( B , #Off), V) |
1128 | // (Actually, we haven't yet proven the Q's are the same.) |
1129 | // In other words, we are loading from a casted version of |
1130 | // the same pointer-and-offset that we stored to. |
1131 | // Casted version may carry a dependency and it is respected. |
1132 | // Thus, we are able to replace L by V. |
1133 | } |
1134 | // Now prove that we have a LoadQ matched to a StoreQ, for some Q. |
1135 | if (store_Opcode() != st->Opcode()) { |
1136 | return NULL__null; |
1137 | } |
1138 | // LoadVector/StoreVector needs additional check to ensure the types match. |
1139 | if (st->is_StoreVector()) { |
1140 | const TypeVect* in_vt = st->as_StoreVector()->vect_type(); |
1141 | const TypeVect* out_vt = as_LoadVector()->vect_type(); |
1142 | if (in_vt != out_vt) { |
1143 | return NULL__null; |
1144 | } |
1145 | } |
1146 | return st->in(MemNode::ValueIn); |
1147 | } |
1148 | |
1149 | // A load from a freshly-created object always returns zero. |
1150 | // (This can happen after LoadNode::Ideal resets the load's memory input |
1151 | // to find_captured_store, which returned InitializeNode::zero_memory.) |
1152 | if (st->is_Proj() && st->in(0)->is_Allocate() && |
1153 | (st->in(0) == ld_alloc) && |
1154 | (ld_off >= st->in(0)->as_Allocate()->minimum_header_size())) { |
1155 | // return a zero value for the load's basic type |
1156 | // (This is one of the few places where a generic PhaseTransform |
1157 | // can create new nodes. Think of it as lazily manifesting |
1158 | // virtually pre-existing constants.) |
1159 | if (memory_type() != T_VOID) { |
1160 | if (ReduceBulkZeroing || find_array_copy_clone(phase, ld_alloc, in(MemNode::Memory)) == NULL__null) { |
1161 | // If ReduceBulkZeroing is disabled, we need to check if the allocation does not belong to an |
1162 | // ArrayCopyNode clone. If it does, then we cannot assume zero since the initialization is done |
1163 | // by the ArrayCopyNode. |
1164 | return phase->zerocon(memory_type()); |
1165 | } |
1166 | } else { |
1167 | // TODO: materialize all-zero vector constant |
1168 | assert(!isa_Load() || as_Load()->type()->isa_vect(), "")do { if (!(!isa_Load() || as_Load()->type()->isa_vect() )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1168, "assert(" "!isa_Load() || as_Load()->type()->isa_vect()" ") failed", ""); ::breakpoint(); } } while (0); |
1169 | } |
1170 | } |
1171 | |
1172 | // A load from an initialization barrier can match a captured store. |
1173 | if (st->is_Proj() && st->in(0)->is_Initialize()) { |
1174 | InitializeNode* init = st->in(0)->as_Initialize(); |
1175 | AllocateNode* alloc = init->allocation(); |
1176 | if ((alloc != NULL__null) && (alloc == ld_alloc)) { |
1177 | // examine a captured store value |
1178 | st = init->find_captured_store(ld_off, memory_size(), phase); |
1179 | if (st != NULL__null) { |
1180 | continue; // take one more trip around |
1181 | } |
1182 | } |
1183 | } |
1184 | |
1185 | // Load boxed value from result of valueOf() call is input parameter. |
1186 | if (this->is_Load() && ld_adr->is_AddP() && |
1187 | (tp != NULL__null) && tp->is_ptr_to_boxed_value()) { |
1188 | intptr_t ignore = 0; |
1189 | Node* base = AddPNode::Ideal_base_and_offset(ld_adr, phase, ignore); |
1190 | BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2(); |
1191 | base = bs->step_over_gc_barrier(base); |
1192 | if (base != NULL__null && base->is_Proj() && |
1193 | base->as_Proj()->_con == TypeFunc::Parms && |
1194 | base->in(0)->is_CallStaticJava() && |
1195 | base->in(0)->as_CallStaticJava()->is_boxing_method()) { |
1196 | return base->in(0)->in(TypeFunc::Parms); |
1197 | } |
1198 | } |
1199 | |
1200 | break; |
1201 | } |
1202 | |
1203 | return NULL__null; |
1204 | } |
1205 | |
1206 | //----------------------is_instance_field_load_with_local_phi------------------ |
1207 | bool LoadNode::is_instance_field_load_with_local_phi(Node* ctrl) { |
1208 | if( in(Memory)->is_Phi() && in(Memory)->in(0) == ctrl && |
1209 | in(Address)->is_AddP() ) { |
1210 | const TypeOopPtr* t_oop = in(Address)->bottom_type()->isa_oopptr(); |
1211 | // Only instances and boxed values. |
1212 | if( t_oop != NULL__null && |
1213 | (t_oop->is_ptr_to_boxed_value() || |
1214 | t_oop->is_known_instance_field()) && |
1215 | t_oop->offset() != Type::OffsetBot && |
1216 | t_oop->offset() != Type::OffsetTop) { |
1217 | return true; |
1218 | } |
1219 | } |
1220 | return false; |
1221 | } |
1222 | |
1223 | //------------------------------Identity--------------------------------------- |
1224 | // Loads are identity if previous store is to same address |
1225 | Node* LoadNode::Identity(PhaseGVN* phase) { |
1226 | // If the previous store-maker is the right kind of Store, and the store is |
1227 | // to the same address, then we are equal to the value stored. |
1228 | Node* mem = in(Memory); |
1229 | Node* value = can_see_stored_value(mem, phase); |
1230 | if( value ) { |
1231 | // byte, short & char stores truncate naturally. |
1232 | // A load has to load the truncated value which requires |
1233 | // some sort of masking operation and that requires an |
1234 | // Ideal call instead of an Identity call. |
1235 | if (memory_size() < BytesPerInt) { |
1236 | // If the input to the store does not fit with the load's result type, |
1237 | // it must be truncated via an Ideal call. |
1238 | if (!phase->type(value)->higher_equal(phase->type(this))) |
1239 | return this; |
1240 | } |
1241 | // (This works even when value is a Con, but LoadNode::Value |
1242 | // usually runs first, producing the singleton type of the Con.) |
1243 | return value; |
1244 | } |
1245 | |
1246 | // Search for an existing data phi which was generated before for the same |
1247 | // instance's field to avoid infinite generation of phis in a loop. |
1248 | Node *region = mem->in(0); |
1249 | if (is_instance_field_load_with_local_phi(region)) { |
1250 | const TypeOopPtr *addr_t = in(Address)->bottom_type()->isa_oopptr(); |
1251 | int this_index = phase->C->get_alias_index(addr_t); |
1252 | int this_offset = addr_t->offset(); |
1253 | int this_iid = addr_t->instance_id(); |
1254 | if (!addr_t->is_known_instance() && |
1255 | addr_t->is_ptr_to_boxed_value()) { |
1256 | // Use _idx of address base (could be Phi node) for boxed values. |
1257 | intptr_t ignore = 0; |
1258 | Node* base = AddPNode::Ideal_base_and_offset(in(Address), phase, ignore); |
1259 | if (base == NULL__null) { |
1260 | return this; |
1261 | } |
1262 | this_iid = base->_idx; |
1263 | } |
1264 | const Type* this_type = bottom_type(); |
1265 | for (DUIterator_Fast imax, i = region->fast_outs(imax); i < imax; i++) { |
1266 | Node* phi = region->fast_out(i); |
1267 | if (phi->is_Phi() && phi != mem && |
1268 | phi->as_Phi()->is_same_inst_field(this_type, (int)mem->_idx, this_iid, this_index, this_offset)) { |
1269 | return phi; |
1270 | } |
1271 | } |
1272 | } |
1273 | |
1274 | return this; |
1275 | } |
1276 | |
1277 | // Construct an equivalent unsigned load. |
1278 | Node* LoadNode::convert_to_unsigned_load(PhaseGVN& gvn) { |
1279 | BasicType bt = T_ILLEGAL; |
1280 | const Type* rt = NULL__null; |
1281 | switch (Opcode()) { |
1282 | case Op_LoadUB: return this; |
1283 | case Op_LoadUS: return this; |
1284 | case Op_LoadB: bt = T_BOOLEAN; rt = TypeInt::UBYTE; break; |
1285 | case Op_LoadS: bt = T_CHAR; rt = TypeInt::CHAR; break; |
1286 | default: |
1287 | assert(false, "no unsigned variant: %s", Name())do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1287, "assert(" "false" ") failed", "no unsigned variant: %s" , Name()); ::breakpoint(); } } while (0); |
1288 | return NULL__null; |
1289 | } |
1290 | return LoadNode::make(gvn, in(MemNode::Control), in(MemNode::Memory), in(MemNode::Address), |
1291 | raw_adr_type(), rt, bt, _mo, _control_dependency, |
1292 | is_unaligned_access(), is_mismatched_access()); |
1293 | } |
1294 | |
1295 | // Construct an equivalent signed load. |
1296 | Node* LoadNode::convert_to_signed_load(PhaseGVN& gvn) { |
1297 | BasicType bt = T_ILLEGAL; |
1298 | const Type* rt = NULL__null; |
1299 | switch (Opcode()) { |
1300 | case Op_LoadUB: bt = T_BYTE; rt = TypeInt::BYTE; break; |
1301 | case Op_LoadUS: bt = T_SHORT; rt = TypeInt::SHORT; break; |
1302 | case Op_LoadB: // fall through |
1303 | case Op_LoadS: // fall through |
1304 | case Op_LoadI: // fall through |
1305 | case Op_LoadL: return this; |
1306 | default: |
1307 | assert(false, "no signed variant: %s", Name())do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1307, "assert(" "false" ") failed", "no signed variant: %s" , Name()); ::breakpoint(); } } while (0); |
1308 | return NULL__null; |
1309 | } |
1310 | return LoadNode::make(gvn, in(MemNode::Control), in(MemNode::Memory), in(MemNode::Address), |
1311 | raw_adr_type(), rt, bt, _mo, _control_dependency, |
1312 | is_unaligned_access(), is_mismatched_access()); |
1313 | } |
1314 | |
1315 | bool LoadNode::has_reinterpret_variant(const Type* rt) { |
1316 | BasicType bt = rt->basic_type(); |
1317 | switch (Opcode()) { |
1318 | case Op_LoadI: return (bt == T_FLOAT); |
1319 | case Op_LoadL: return (bt == T_DOUBLE); |
1320 | case Op_LoadF: return (bt == T_INT); |
1321 | case Op_LoadD: return (bt == T_LONG); |
1322 | |
1323 | default: return false; |
1324 | } |
1325 | } |
1326 | |
1327 | Node* LoadNode::convert_to_reinterpret_load(PhaseGVN& gvn, const Type* rt) { |
1328 | BasicType bt = rt->basic_type(); |
1329 | assert(has_reinterpret_variant(rt), "no reinterpret variant: %s %s", Name(), type2name(bt))do { if (!(has_reinterpret_variant(rt))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1329, "assert(" "has_reinterpret_variant(rt)" ") failed", "no reinterpret variant: %s %s" , Name(), type2name(bt)); ::breakpoint(); } } while (0); |
1330 | bool is_mismatched = is_mismatched_access(); |
1331 | const TypeRawPtr* raw_type = gvn.type(in(MemNode::Memory))->isa_rawptr(); |
1332 | if (raw_type == NULL__null) { |
1333 | is_mismatched = true; // conservatively match all non-raw accesses as mismatched |
1334 | } |
1335 | return LoadNode::make(gvn, in(MemNode::Control), in(MemNode::Memory), in(MemNode::Address), |
1336 | raw_adr_type(), rt, bt, _mo, _control_dependency, |
1337 | is_unaligned_access(), is_mismatched); |
1338 | } |
1339 | |
1340 | bool StoreNode::has_reinterpret_variant(const Type* vt) { |
1341 | BasicType bt = vt->basic_type(); |
1342 | switch (Opcode()) { |
1343 | case Op_StoreI: return (bt == T_FLOAT); |
1344 | case Op_StoreL: return (bt == T_DOUBLE); |
1345 | case Op_StoreF: return (bt == T_INT); |
1346 | case Op_StoreD: return (bt == T_LONG); |
1347 | |
1348 | default: return false; |
1349 | } |
1350 | } |
1351 | |
1352 | Node* StoreNode::convert_to_reinterpret_store(PhaseGVN& gvn, Node* val, const Type* vt) { |
1353 | BasicType bt = vt->basic_type(); |
1354 | assert(has_reinterpret_variant(vt), "no reinterpret variant: %s %s", Name(), type2name(bt))do { if (!(has_reinterpret_variant(vt))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1354, "assert(" "has_reinterpret_variant(vt)" ") failed", "no reinterpret variant: %s %s" , Name(), type2name(bt)); ::breakpoint(); } } while (0); |
1355 | StoreNode* st = StoreNode::make(gvn, in(MemNode::Control), in(MemNode::Memory), in(MemNode::Address), raw_adr_type(), val, bt, _mo); |
1356 | |
1357 | bool is_mismatched = is_mismatched_access(); |
1358 | const TypeRawPtr* raw_type = gvn.type(in(MemNode::Memory))->isa_rawptr(); |
1359 | if (raw_type == NULL__null) { |
1360 | is_mismatched = true; // conservatively match all non-raw accesses as mismatched |
1361 | } |
1362 | if (is_mismatched) { |
1363 | st->set_mismatched_access(); |
1364 | } |
1365 | return st; |
1366 | } |
1367 | |
1368 | // We're loading from an object which has autobox behaviour. |
1369 | // If this object is result of a valueOf call we'll have a phi |
1370 | // merging a newly allocated object and a load from the cache. |
1371 | // We want to replace this load with the original incoming |
1372 | // argument to the valueOf call. |
1373 | Node* LoadNode::eliminate_autobox(PhaseIterGVN* igvn) { |
1374 | assert(igvn->C->eliminate_boxing(), "sanity")do { if (!(igvn->C->eliminate_boxing())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1374, "assert(" "igvn->C->eliminate_boxing()" ") failed" , "sanity"); ::breakpoint(); } } while (0); |
1375 | intptr_t ignore = 0; |
1376 | Node* base = AddPNode::Ideal_base_and_offset(in(Address), igvn, ignore); |
1377 | if ((base == NULL__null) || base->is_Phi()) { |
1378 | // Push the loads from the phi that comes from valueOf up |
1379 | // through it to allow elimination of the loads and the recovery |
1380 | // of the original value. It is done in split_through_phi(). |
1381 | return NULL__null; |
1382 | } else if (base->is_Load() || |
1383 | (base->is_DecodeN() && base->in(1)->is_Load())) { |
1384 | // Eliminate the load of boxed value for integer types from the cache |
1385 | // array by deriving the value from the index into the array. |
1386 | // Capture the offset of the load and then reverse the computation. |
1387 | |
1388 | // Get LoadN node which loads a boxing object from 'cache' array. |
1389 | if (base->is_DecodeN()) { |
1390 | base = base->in(1); |
1391 | } |
1392 | if (!base->in(Address)->is_AddP()) { |
1393 | return NULL__null; // Complex address |
1394 | } |
1395 | AddPNode* address = base->in(Address)->as_AddP(); |
1396 | Node* cache_base = address->in(AddPNode::Base); |
1397 | if ((cache_base != NULL__null) && cache_base->is_DecodeN()) { |
1398 | // Get ConP node which is static 'cache' field. |
1399 | cache_base = cache_base->in(1); |
1400 | } |
1401 | if ((cache_base != NULL__null) && cache_base->is_Con()) { |
1402 | const TypeAryPtr* base_type = cache_base->bottom_type()->isa_aryptr(); |
1403 | if ((base_type != NULL__null) && base_type->is_autobox_cache()) { |
1404 | Node* elements[4]; |
1405 | int shift = exact_log2(type2aelembytes(T_OBJECT)); |
1406 | int count = address->unpack_offsets(elements, ARRAY_SIZE(elements)sizeof(array_size_impl(elements))); |
1407 | if (count > 0 && elements[0]->is_Con() && |
1408 | (count == 1 || |
1409 | (count == 2 && elements[1]->Opcode() == Op_LShiftXOp_LShiftL && |
1410 | elements[1]->in(2) == igvn->intcon(shift)))) { |
1411 | ciObjArray* array = base_type->const_oop()->as_obj_array(); |
1412 | // Fetch the box object cache[0] at the base of the array and get its value |
1413 | ciInstance* box = array->obj_at(0)->as_instance(); |
1414 | ciInstanceKlass* ik = box->klass()->as_instance_klass(); |
1415 | assert(ik->is_box_klass(), "sanity")do { if (!(ik->is_box_klass())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1415, "assert(" "ik->is_box_klass()" ") failed", "sanity" ); ::breakpoint(); } } while (0); |
1416 | assert(ik->nof_nonstatic_fields() == 1, "change following code")do { if (!(ik->nof_nonstatic_fields() == 1)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1416, "assert(" "ik->nof_nonstatic_fields() == 1" ") failed" , "change following code"); ::breakpoint(); } } while (0); |
1417 | if (ik->nof_nonstatic_fields() == 1) { |
1418 | // This should be true nonstatic_field_at requires calling |
1419 | // nof_nonstatic_fields so check it anyway |
1420 | ciConstant c = box->field_value(ik->nonstatic_field_at(0)); |
1421 | BasicType bt = c.basic_type(); |
1422 | // Only integer types have boxing cache. |
1423 | assert(bt == T_BOOLEAN || bt == T_CHAR ||do { if (!(bt == T_BOOLEAN || bt == T_CHAR || bt == T_BYTE || bt == T_SHORT || bt == T_INT || bt == T_LONG)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1425, "assert(" "bt == T_BOOLEAN || bt == T_CHAR || bt == T_BYTE || bt == T_SHORT || bt == T_INT || bt == T_LONG" ") failed", "wrong type = %s", type2name(bt)); ::breakpoint( ); } } while (0) |
1424 | bt == T_BYTE || bt == T_SHORT ||do { if (!(bt == T_BOOLEAN || bt == T_CHAR || bt == T_BYTE || bt == T_SHORT || bt == T_INT || bt == T_LONG)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1425, "assert(" "bt == T_BOOLEAN || bt == T_CHAR || bt == T_BYTE || bt == T_SHORT || bt == T_INT || bt == T_LONG" ") failed", "wrong type = %s", type2name(bt)); ::breakpoint( ); } } while (0) |
1425 | bt == T_INT || bt == T_LONG, "wrong type = %s", type2name(bt))do { if (!(bt == T_BOOLEAN || bt == T_CHAR || bt == T_BYTE || bt == T_SHORT || bt == T_INT || bt == T_LONG)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1425, "assert(" "bt == T_BOOLEAN || bt == T_CHAR || bt == T_BYTE || bt == T_SHORT || bt == T_INT || bt == T_LONG" ") failed", "wrong type = %s", type2name(bt)); ::breakpoint( ); } } while (0); |
1426 | jlong cache_low = (bt == T_LONG) ? c.as_long() : c.as_int(); |
1427 | if (cache_low != (int)cache_low) { |
1428 | return NULL__null; // should not happen since cache is array indexed by value |
1429 | } |
1430 | jlong offset = arrayOopDesc::base_offset_in_bytes(T_OBJECT) - (cache_low << shift); |
1431 | if (offset != (int)offset) { |
1432 | return NULL__null; // should not happen since cache is array indexed by value |
1433 | } |
1434 | // Add up all the offsets making of the address of the load |
1435 | Node* result = elements[0]; |
1436 | for (int i = 1; i < count; i++) { |
1437 | result = igvn->transform(new AddXNodeAddLNode(result, elements[i])); |
1438 | } |
1439 | // Remove the constant offset from the address and then |
1440 | result = igvn->transform(new AddXNodeAddLNode(result, igvn->MakeConXlongcon(-(int)offset))); |
1441 | // remove the scaling of the offset to recover the original index. |
1442 | if (result->Opcode() == Op_LShiftXOp_LShiftL && result->in(2) == igvn->intcon(shift)) { |
1443 | // Peel the shift off directly but wrap it in a dummy node |
1444 | // since Ideal can't return existing nodes |
1445 | igvn->_worklist.push(result); // remove dead node later |
1446 | result = new RShiftXNodeRShiftLNode(result->in(1), igvn->intcon(0)); |
1447 | } else if (result->is_Add() && result->in(2)->is_Con() && |
1448 | result->in(1)->Opcode() == Op_LShiftXOp_LShiftL && |
1449 | result->in(1)->in(2) == igvn->intcon(shift)) { |
1450 | // We can't do general optimization: ((X<<Z) + Y) >> Z ==> X + (Y>>Z) |
1451 | // but for boxing cache access we know that X<<Z will not overflow |
1452 | // (there is range check) so we do this optimizatrion by hand here. |
1453 | igvn->_worklist.push(result); // remove dead node later |
1454 | Node* add_con = new RShiftXNodeRShiftLNode(result->in(2), igvn->intcon(shift)); |
1455 | result = new AddXNodeAddLNode(result->in(1)->in(1), igvn->transform(add_con)); |
1456 | } else { |
1457 | result = new RShiftXNodeRShiftLNode(result, igvn->intcon(shift)); |
1458 | } |
1459 | #ifdef _LP641 |
1460 | if (bt != T_LONG) { |
1461 | result = new ConvL2INode(igvn->transform(result)); |
1462 | } |
1463 | #else |
1464 | if (bt == T_LONG) { |
1465 | result = new ConvI2LNode(igvn->transform(result)); |
1466 | } |
1467 | #endif |
1468 | // Boxing/unboxing can be done from signed & unsigned loads (e.g. LoadUB -> ... -> LoadB pair). |
1469 | // Need to preserve unboxing load type if it is unsigned. |
1470 | switch(this->Opcode()) { |
1471 | case Op_LoadUB: |
1472 | result = new AndINode(igvn->transform(result), igvn->intcon(0xFF)); |
1473 | break; |
1474 | case Op_LoadUS: |
1475 | result = new AndINode(igvn->transform(result), igvn->intcon(0xFFFF)); |
1476 | break; |
1477 | } |
1478 | return result; |
1479 | } |
1480 | } |
1481 | } |
1482 | } |
1483 | } |
1484 | return NULL__null; |
1485 | } |
1486 | |
1487 | static bool stable_phi(PhiNode* phi, PhaseGVN *phase) { |
1488 | Node* region = phi->in(0); |
1489 | if (region == NULL__null) { |
1490 | return false; // Wait stable graph |
1491 | } |
1492 | uint cnt = phi->req(); |
1493 | for (uint i = 1; i < cnt; i++) { |
1494 | Node* rc = region->in(i); |
1495 | if (rc == NULL__null || phase->type(rc) == Type::TOP) |
1496 | return false; // Wait stable graph |
1497 | Node* in = phi->in(i); |
1498 | if (in == NULL__null || phase->type(in) == Type::TOP) |
1499 | return false; // Wait stable graph |
1500 | } |
1501 | return true; |
1502 | } |
1503 | //------------------------------split_through_phi------------------------------ |
1504 | // Split instance or boxed field load through Phi. |
1505 | Node *LoadNode::split_through_phi(PhaseGVN *phase) { |
1506 | Node* mem = in(Memory); |
1507 | Node* address = in(Address); |
1508 | const TypeOopPtr *t_oop = phase->type(address)->isa_oopptr(); |
1509 | |
1510 | assert((t_oop != NULL) &&do { if (!((t_oop != __null) && (t_oop->is_known_instance_field () || t_oop->is_ptr_to_boxed_value()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1512, "assert(" "(t_oop != __null) && (t_oop->is_known_instance_field() || t_oop->is_ptr_to_boxed_value())" ") failed", "invalide conditions"); ::breakpoint(); } } while (0) |
1511 | (t_oop->is_known_instance_field() ||do { if (!((t_oop != __null) && (t_oop->is_known_instance_field () || t_oop->is_ptr_to_boxed_value()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1512, "assert(" "(t_oop != __null) && (t_oop->is_known_instance_field() || t_oop->is_ptr_to_boxed_value())" ") failed", "invalide conditions"); ::breakpoint(); } } while (0) |
1512 | t_oop->is_ptr_to_boxed_value()), "invalide conditions")do { if (!((t_oop != __null) && (t_oop->is_known_instance_field () || t_oop->is_ptr_to_boxed_value()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1512, "assert(" "(t_oop != __null) && (t_oop->is_known_instance_field() || t_oop->is_ptr_to_boxed_value())" ") failed", "invalide conditions"); ::breakpoint(); } } while (0); |
1513 | |
1514 | Compile* C = phase->C; |
1515 | intptr_t ignore = 0; |
1516 | Node* base = AddPNode::Ideal_base_and_offset(address, phase, ignore); |
1517 | bool base_is_phi = (base != NULL__null) && base->is_Phi(); |
1518 | bool load_boxed_values = t_oop->is_ptr_to_boxed_value() && C->aggressive_unboxing() && |
1519 | (base != NULL__null) && (base == address->in(AddPNode::Base)) && |
1520 | phase->type(base)->higher_equal(TypePtr::NOTNULL); |
1521 | |
1522 | if (!((mem->is_Phi() || base_is_phi) && |
1523 | (load_boxed_values || t_oop->is_known_instance_field()))) { |
1524 | return NULL__null; // memory is not Phi |
1525 | } |
1526 | |
1527 | if (mem->is_Phi()) { |
1528 | if (!stable_phi(mem->as_Phi(), phase)) { |
1529 | return NULL__null; // Wait stable graph |
1530 | } |
1531 | uint cnt = mem->req(); |
1532 | // Check for loop invariant memory. |
1533 | if (cnt == 3) { |
1534 | for (uint i = 1; i < cnt; i++) { |
1535 | Node* in = mem->in(i); |
1536 | Node* m = optimize_memory_chain(in, t_oop, this, phase); |
1537 | if (m == mem) { |
1538 | if (i == 1) { |
1539 | // if the first edge was a loop, check second edge too. |
1540 | // If both are replaceable - we are in an infinite loop |
1541 | Node *n = optimize_memory_chain(mem->in(2), t_oop, this, phase); |
1542 | if (n == mem) { |
1543 | break; |
1544 | } |
1545 | } |
1546 | set_req(Memory, mem->in(cnt - i)); |
1547 | return this; // made change |
1548 | } |
1549 | } |
1550 | } |
1551 | } |
1552 | if (base_is_phi) { |
1553 | if (!stable_phi(base->as_Phi(), phase)) { |
1554 | return NULL__null; // Wait stable graph |
1555 | } |
1556 | uint cnt = base->req(); |
1557 | // Check for loop invariant memory. |
1558 | if (cnt == 3) { |
1559 | for (uint i = 1; i < cnt; i++) { |
1560 | if (base->in(i) == base) { |
1561 | return NULL__null; // Wait stable graph |
1562 | } |
1563 | } |
1564 | } |
1565 | } |
1566 | |
1567 | // Split through Phi (see original code in loopopts.cpp). |
1568 | assert(C->have_alias_type(t_oop), "instance should have alias type")do { if (!(C->have_alias_type(t_oop))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1568, "assert(" "C->have_alias_type(t_oop)" ") failed", "instance should have alias type" ); ::breakpoint(); } } while (0); |
1569 | |
1570 | // Do nothing here if Identity will find a value |
1571 | // (to avoid infinite chain of value phis generation). |
1572 | if (this != Identity(phase)) { |
1573 | return NULL__null; |
1574 | } |
1575 | |
1576 | // Select Region to split through. |
1577 | Node* region; |
1578 | if (!base_is_phi) { |
1579 | assert(mem->is_Phi(), "sanity")do { if (!(mem->is_Phi())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1579, "assert(" "mem->is_Phi()" ") failed", "sanity"); :: breakpoint(); } } while (0); |
1580 | region = mem->in(0); |
1581 | // Skip if the region dominates some control edge of the address. |
1582 | if (!MemNode::all_controls_dominate(address, region)) |
1583 | return NULL__null; |
1584 | } else if (!mem->is_Phi()) { |
1585 | assert(base_is_phi, "sanity")do { if (!(base_is_phi)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1585, "assert(" "base_is_phi" ") failed", "sanity"); ::breakpoint (); } } while (0); |
1586 | region = base->in(0); |
1587 | // Skip if the region dominates some control edge of the memory. |
1588 | if (!MemNode::all_controls_dominate(mem, region)) |
1589 | return NULL__null; |
1590 | } else if (base->in(0) != mem->in(0)) { |
1591 | assert(base_is_phi && mem->is_Phi(), "sanity")do { if (!(base_is_phi && mem->is_Phi())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1591, "assert(" "base_is_phi && mem->is_Phi()" ") failed" , "sanity"); ::breakpoint(); } } while (0); |
1592 | if (MemNode::all_controls_dominate(mem, base->in(0))) { |
1593 | region = base->in(0); |
1594 | } else if (MemNode::all_controls_dominate(address, mem->in(0))) { |
1595 | region = mem->in(0); |
1596 | } else { |
1597 | return NULL__null; // complex graph |
1598 | } |
1599 | } else { |
1600 | assert(base->in(0) == mem->in(0), "sanity")do { if (!(base->in(0) == mem->in(0))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1600, "assert(" "base->in(0) == mem->in(0)" ") failed" , "sanity"); ::breakpoint(); } } while (0); |
1601 | region = mem->in(0); |
1602 | } |
1603 | |
1604 | const Type* this_type = this->bottom_type(); |
1605 | int this_index = C->get_alias_index(t_oop); |
1606 | int this_offset = t_oop->offset(); |
1607 | int this_iid = t_oop->instance_id(); |
1608 | if (!t_oop->is_known_instance() && load_boxed_values) { |
1609 | // Use _idx of address base for boxed values. |
1610 | this_iid = base->_idx; |
1611 | } |
1612 | PhaseIterGVN* igvn = phase->is_IterGVN(); |
1613 | Node* phi = new PhiNode(region, this_type, NULL__null, mem->_idx, this_iid, this_index, this_offset); |
1614 | for (uint i = 1; i < region->req(); i++) { |
1615 | Node* x; |
1616 | Node* the_clone = NULL__null; |
1617 | Node* in = region->in(i); |
1618 | if (region->is_CountedLoop() && region->as_Loop()->is_strip_mined() && i == LoopNode::EntryControl && |
1619 | in != NULL__null && in->is_OuterStripMinedLoop()) { |
1620 | // No node should go in the outer strip mined loop |
1621 | in = in->in(LoopNode::EntryControl); |
1622 | } |
1623 | if (in == NULL__null || in == C->top()) { |
1624 | x = C->top(); // Dead path? Use a dead data op |
1625 | } else { |
1626 | x = this->clone(); // Else clone up the data op |
1627 | the_clone = x; // Remember for possible deletion. |
1628 | // Alter data node to use pre-phi inputs |
1629 | if (this->in(0) == region) { |
1630 | x->set_req(0, in); |
1631 | } else { |
1632 | x->set_req(0, NULL__null); |
1633 | } |
1634 | if (mem->is_Phi() && (mem->in(0) == region)) { |
1635 | x->set_req(Memory, mem->in(i)); // Use pre-Phi input for the clone. |
1636 | } |
1637 | if (address->is_Phi() && address->in(0) == region) { |
1638 | x->set_req(Address, address->in(i)); // Use pre-Phi input for the clone |
1639 | } |
1640 | if (base_is_phi && (base->in(0) == region)) { |
1641 | Node* base_x = base->in(i); // Clone address for loads from boxed objects. |
1642 | Node* adr_x = phase->transform(new AddPNode(base_x,base_x,address->in(AddPNode::Offset))); |
1643 | x->set_req(Address, adr_x); |
1644 | } |
1645 | } |
1646 | // Check for a 'win' on some paths |
1647 | const Type *t = x->Value(igvn); |
1648 | |
1649 | bool singleton = t->singleton(); |
1650 | |
1651 | // See comments in PhaseIdealLoop::split_thru_phi(). |
1652 | if (singleton && t == Type::TOP) { |
1653 | singleton &= region->is_Loop() && (i != LoopNode::EntryControl); |
1654 | } |
1655 | |
1656 | if (singleton) { |
1657 | x = igvn->makecon(t); |
1658 | } else { |
1659 | // We now call Identity to try to simplify the cloned node. |
1660 | // Note that some Identity methods call phase->type(this). |
1661 | // Make sure that the type array is big enough for |
1662 | // our new node, even though we may throw the node away. |
1663 | // (This tweaking with igvn only works because x is a new node.) |
1664 | igvn->set_type(x, t); |
1665 | // If x is a TypeNode, capture any more-precise type permanently into Node |
1666 | // otherwise it will be not updated during igvn->transform since |
1667 | // igvn->type(x) is set to x->Value() already. |
1668 | x->raise_bottom_type(t); |
1669 | Node* y = x->Identity(igvn); |
1670 | if (y != x) { |
1671 | x = y; |
1672 | } else { |
1673 | y = igvn->hash_find_insert(x); |
1674 | if (y) { |
1675 | x = y; |
1676 | } else { |
1677 | // Else x is a new node we are keeping |
1678 | // We do not need register_new_node_with_optimizer |
1679 | // because set_type has already been called. |
1680 | igvn->_worklist.push(x); |
1681 | } |
1682 | } |
1683 | } |
1684 | if (x != the_clone && the_clone != NULL__null) { |
1685 | igvn->remove_dead_node(the_clone); |
1686 | } |
1687 | phi->set_req(i, x); |
1688 | } |
1689 | // Record Phi |
1690 | igvn->register_new_node_with_optimizer(phi); |
1691 | return phi; |
1692 | } |
1693 | |
1694 | AllocateNode* LoadNode::is_new_object_mark_load(PhaseGVN *phase) const { |
1695 | if (Opcode() == Op_LoadXOp_LoadL) { |
1696 | Node* address = in(MemNode::Address); |
1697 | AllocateNode* alloc = AllocateNode::Ideal_allocation(address, phase); |
1698 | Node* mem = in(MemNode::Memory); |
1699 | if (alloc != NULL__null && mem->is_Proj() && |
1700 | mem->in(0) != NULL__null && |
1701 | mem->in(0) == alloc->initialization() && |
1702 | alloc->initialization()->proj_out_or_null(0) != NULL__null) { |
1703 | return alloc; |
1704 | } |
1705 | } |
1706 | return NULL__null; |
1707 | } |
1708 | |
1709 | |
1710 | //------------------------------Ideal------------------------------------------ |
1711 | // If the load is from Field memory and the pointer is non-null, it might be possible to |
1712 | // zero out the control input. |
1713 | // If the offset is constant and the base is an object allocation, |
1714 | // try to hook me up to the exact initializing store. |
1715 | Node *LoadNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
1716 | Node* p = MemNode::Ideal_common(phase, can_reshape); |
1717 | if (p) return (p == NodeSentinel(Node*)-1) ? NULL__null : p; |
1718 | |
1719 | Node* ctrl = in(MemNode::Control); |
1720 | Node* address = in(MemNode::Address); |
1721 | bool progress = false; |
1722 | |
1723 | bool addr_mark = ((phase->type(address)->isa_oopptr() || phase->type(address)->isa_narrowoop()) && |
1724 | phase->type(address)->is_ptr()->offset() == oopDesc::mark_offset_in_bytes()); |
1725 | |
1726 | // Skip up past a SafePoint control. Cannot do this for Stores because |
1727 | // pointer stores & cardmarks must stay on the same side of a SafePoint. |
1728 | if( ctrl != NULL__null && ctrl->Opcode() == Op_SafePoint && |
1729 | phase->C->get_alias_index(phase->type(address)->is_ptr()) != Compile::AliasIdxRaw && |
1730 | !addr_mark && |
1731 | (depends_only_on_test() || has_unknown_control_dependency())) { |
1732 | ctrl = ctrl->in(0); |
1733 | set_req(MemNode::Control,ctrl); |
1734 | progress = true; |
1735 | } |
1736 | |
1737 | intptr_t ignore = 0; |
1738 | Node* base = AddPNode::Ideal_base_and_offset(address, phase, ignore); |
1739 | if (base != NULL__null |
1740 | && phase->C->get_alias_index(phase->type(address)->is_ptr()) != Compile::AliasIdxRaw) { |
1741 | // Check for useless control edge in some common special cases |
1742 | if (in(MemNode::Control) != NULL__null |
1743 | && can_remove_control() |
1744 | && phase->type(base)->higher_equal(TypePtr::NOTNULL) |
1745 | && all_controls_dominate(base, phase->C->start())) { |
1746 | // A method-invariant, non-null address (constant or 'this' argument). |
1747 | set_req(MemNode::Control, NULL__null); |
1748 | progress = true; |
1749 | } |
1750 | } |
1751 | |
1752 | Node* mem = in(MemNode::Memory); |
1753 | const TypePtr *addr_t = phase->type(address)->isa_ptr(); |
1754 | |
1755 | if (can_reshape && (addr_t != NULL__null)) { |
1756 | // try to optimize our memory input |
1757 | Node* opt_mem = MemNode::optimize_memory_chain(mem, addr_t, this, phase); |
1758 | if (opt_mem != mem) { |
1759 | set_req_X(MemNode::Memory, opt_mem, phase); |
1760 | if (phase->type( opt_mem ) == Type::TOP) return NULL__null; |
1761 | return this; |
1762 | } |
1763 | const TypeOopPtr *t_oop = addr_t->isa_oopptr(); |
1764 | if ((t_oop != NULL__null) && |
1765 | (t_oop->is_known_instance_field() || |
1766 | t_oop->is_ptr_to_boxed_value())) { |
1767 | PhaseIterGVN *igvn = phase->is_IterGVN(); |
1768 | assert(igvn != NULL, "must be PhaseIterGVN when can_reshape is true")do { if (!(igvn != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1768, "assert(" "igvn != __null" ") failed", "must be PhaseIterGVN when can_reshape is true" ); ::breakpoint(); } } while (0); |
1769 | if (igvn->_worklist.member(opt_mem)) { |
1770 | // Delay this transformation until memory Phi is processed. |
1771 | igvn->_worklist.push(this); |
1772 | return NULL__null; |
1773 | } |
1774 | // Split instance field load through Phi. |
1775 | Node* result = split_through_phi(phase); |
1776 | if (result != NULL__null) return result; |
1777 | |
1778 | if (t_oop->is_ptr_to_boxed_value()) { |
1779 | Node* result = eliminate_autobox(igvn); |
1780 | if (result != NULL__null) return result; |
1781 | } |
1782 | } |
1783 | } |
1784 | |
1785 | // Is there a dominating load that loads the same value? Leave |
1786 | // anything that is not a load of a field/array element (like |
1787 | // barriers etc.) alone |
1788 | if (in(0) != NULL__null && !adr_type()->isa_rawptr() && can_reshape) { |
1789 | for (DUIterator_Fast imax, i = mem->fast_outs(imax); i < imax; i++) { |
1790 | Node *use = mem->fast_out(i); |
1791 | if (use != this && |
1792 | use->Opcode() == Opcode() && |
1793 | use->in(0) != NULL__null && |
1794 | use->in(0) != in(0) && |
1795 | use->in(Address) == in(Address)) { |
1796 | Node* ctl = in(0); |
1797 | for (int i = 0; i < 10 && ctl != NULL__null; i++) { |
1798 | ctl = IfNode::up_one_dom(ctl); |
1799 | if (ctl == use->in(0)) { |
1800 | set_req(0, use->in(0)); |
1801 | return this; |
1802 | } |
1803 | } |
1804 | } |
1805 | } |
1806 | } |
1807 | |
1808 | // Check for prior store with a different base or offset; make Load |
1809 | // independent. Skip through any number of them. Bail out if the stores |
1810 | // are in an endless dead cycle and report no progress. This is a key |
1811 | // transform for Reflection. However, if after skipping through the Stores |
1812 | // we can't then fold up against a prior store do NOT do the transform as |
1813 | // this amounts to using the 'Oracle' model of aliasing. It leaves the same |
1814 | // array memory alive twice: once for the hoisted Load and again after the |
1815 | // bypassed Store. This situation only works if EVERYBODY who does |
1816 | // anti-dependence work knows how to bypass. I.e. we need all |
1817 | // anti-dependence checks to ask the same Oracle. Right now, that Oracle is |
1818 | // the alias index stuff. So instead, peek through Stores and IFF we can |
1819 | // fold up, do so. |
1820 | Node* prev_mem = find_previous_store(phase); |
1821 | if (prev_mem != NULL__null) { |
1822 | Node* value = can_see_arraycopy_value(prev_mem, phase); |
1823 | if (value != NULL__null) { |
1824 | return value; |
1825 | } |
1826 | } |
1827 | // Steps (a), (b): Walk past independent stores to find an exact match. |
1828 | if (prev_mem != NULL__null && prev_mem != in(MemNode::Memory)) { |
1829 | // (c) See if we can fold up on the spot, but don't fold up here. |
1830 | // Fold-up might require truncation (for LoadB/LoadS/LoadUS) or |
1831 | // just return a prior value, which is done by Identity calls. |
1832 | if (can_see_stored_value(prev_mem, phase)) { |
1833 | // Make ready for step (d): |
1834 | set_req_X(MemNode::Memory, prev_mem, phase); |
1835 | return this; |
1836 | } |
1837 | } |
1838 | |
1839 | return progress ? this : NULL__null; |
1840 | } |
1841 | |
1842 | // Helper to recognize certain Klass fields which are invariant across |
1843 | // some group of array types (e.g., int[] or all T[] where T < Object). |
1844 | const Type* |
1845 | LoadNode::load_array_final_field(const TypeKlassPtr *tkls, |
1846 | ciKlass* klass) const { |
1847 | if (tkls->offset() == in_bytes(Klass::modifier_flags_offset())) { |
1848 | // The field is Klass::_modifier_flags. Return its (constant) value. |
1849 | // (Folds up the 2nd indirection in aClassConstant.getModifiers().) |
1850 | assert(this->Opcode() == Op_LoadI, "must load an int from _modifier_flags")do { if (!(this->Opcode() == Op_LoadI)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1850, "assert(" "this->Opcode() == Op_LoadI" ") failed", "must load an int from _modifier_flags"); ::breakpoint(); } } while (0); |
1851 | return TypeInt::make(klass->modifier_flags()); |
1852 | } |
1853 | if (tkls->offset() == in_bytes(Klass::access_flags_offset())) { |
1854 | // The field is Klass::_access_flags. Return its (constant) value. |
1855 | // (Folds up the 2nd indirection in Reflection.getClassAccessFlags(aClassConstant).) |
1856 | assert(this->Opcode() == Op_LoadI, "must load an int from _access_flags")do { if (!(this->Opcode() == Op_LoadI)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1856, "assert(" "this->Opcode() == Op_LoadI" ") failed", "must load an int from _access_flags"); ::breakpoint(); } } while (0); |
1857 | return TypeInt::make(klass->access_flags()); |
1858 | } |
1859 | if (tkls->offset() == in_bytes(Klass::layout_helper_offset())) { |
1860 | // The field is Klass::_layout_helper. Return its constant value if known. |
1861 | assert(this->Opcode() == Op_LoadI, "must load an int from _layout_helper")do { if (!(this->Opcode() == Op_LoadI)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1861, "assert(" "this->Opcode() == Op_LoadI" ") failed", "must load an int from _layout_helper"); ::breakpoint(); } } while (0); |
1862 | return TypeInt::make(klass->layout_helper()); |
1863 | } |
1864 | |
1865 | // No match. |
1866 | return NULL__null; |
1867 | } |
1868 | |
1869 | //------------------------------Value----------------------------------------- |
1870 | const Type* LoadNode::Value(PhaseGVN* phase) const { |
1871 | // Either input is TOP ==> the result is TOP |
1872 | Node* mem = in(MemNode::Memory); |
1873 | const Type *t1 = phase->type(mem); |
1874 | if (t1 == Type::TOP) return Type::TOP; |
1875 | Node* adr = in(MemNode::Address); |
1876 | const TypePtr* tp = phase->type(adr)->isa_ptr(); |
1877 | if (tp == NULL__null || tp->empty()) return Type::TOP; |
1878 | int off = tp->offset(); |
1879 | assert(off != Type::OffsetTop, "case covered by TypePtr::empty")do { if (!(off != Type::OffsetTop)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1879, "assert(" "off != Type::OffsetTop" ") failed", "case covered by TypePtr::empty" ); ::breakpoint(); } } while (0); |
1880 | Compile* C = phase->C; |
1881 | |
1882 | // Try to guess loaded type from pointer type |
1883 | if (tp->isa_aryptr()) { |
1884 | const TypeAryPtr* ary = tp->is_aryptr(); |
1885 | const Type* t = ary->elem(); |
1886 | |
1887 | // Determine whether the reference is beyond the header or not, by comparing |
1888 | // the offset against the offset of the start of the array's data. |
1889 | // Different array types begin at slightly different offsets (12 vs. 16). |
1890 | // We choose T_BYTE as an example base type that is least restrictive |
1891 | // as to alignment, which will therefore produce the smallest |
1892 | // possible base offset. |
1893 | const int min_base_off = arrayOopDesc::base_offset_in_bytes(T_BYTE); |
1894 | const bool off_beyond_header = (off >= min_base_off); |
1895 | |
1896 | // Try to constant-fold a stable array element. |
1897 | if (FoldStableValues && !is_mismatched_access() && ary->is_stable()) { |
1898 | // Make sure the reference is not into the header and the offset is constant |
1899 | ciObject* aobj = ary->const_oop(); |
1900 | if (aobj != NULL__null && off_beyond_header && adr->is_AddP() && off != Type::OffsetBot) { |
1901 | int stable_dimension = (ary->stable_dimension() > 0 ? ary->stable_dimension() - 1 : 0); |
1902 | const Type* con_type = Type::make_constant_from_array_element(aobj->as_array(), off, |
1903 | stable_dimension, |
1904 | memory_type(), is_unsigned()); |
1905 | if (con_type != NULL__null) { |
1906 | return con_type; |
1907 | } |
1908 | } |
1909 | } |
1910 | |
1911 | // Don't do this for integer types. There is only potential profit if |
1912 | // the element type t is lower than _type; that is, for int types, if _type is |
1913 | // more restrictive than t. This only happens here if one is short and the other |
1914 | // char (both 16 bits), and in those cases we've made an intentional decision |
1915 | // to use one kind of load over the other. See AndINode::Ideal and 4965907. |
1916 | // Also, do not try to narrow the type for a LoadKlass, regardless of offset. |
1917 | // |
1918 | // Yes, it is possible to encounter an expression like (LoadKlass p1:(AddP x x 8)) |
1919 | // where the _gvn.type of the AddP is wider than 8. This occurs when an earlier |
1920 | // copy p0 of (AddP x x 8) has been proven equal to p1, and the p0 has been |
1921 | // subsumed by p1. If p1 is on the worklist but has not yet been re-transformed, |
1922 | // it is possible that p1 will have a type like Foo*[int+]:NotNull*+any. |
1923 | // In fact, that could have been the original type of p1, and p1 could have |
1924 | // had an original form like p1:(AddP x x (LShiftL quux 3)), where the |
1925 | // expression (LShiftL quux 3) independently optimized to the constant 8. |
1926 | if ((t->isa_int() == NULL__null) && (t->isa_long() == NULL__null) |
1927 | && (_type->isa_vect() == NULL__null) |
1928 | && Opcode() != Op_LoadKlass && Opcode() != Op_LoadNKlass) { |
1929 | // t might actually be lower than _type, if _type is a unique |
1930 | // concrete subclass of abstract class t. |
1931 | if (off_beyond_header || off == Type::OffsetBot) { // is the offset beyond the header? |
1932 | const Type* jt = t->join_speculative(_type); |
1933 | // In any case, do not allow the join, per se, to empty out the type. |
1934 | if (jt->empty() && !t->empty()) { |
1935 | // This can happen if a interface-typed array narrows to a class type. |
1936 | jt = _type; |
1937 | } |
1938 | #ifdef ASSERT1 |
1939 | if (phase->C->eliminate_boxing() && adr->is_AddP()) { |
1940 | // The pointers in the autobox arrays are always non-null |
1941 | Node* base = adr->in(AddPNode::Base); |
1942 | if ((base != NULL__null) && base->is_DecodeN()) { |
1943 | // Get LoadN node which loads IntegerCache.cache field |
1944 | base = base->in(1); |
1945 | } |
1946 | if ((base != NULL__null) && base->is_Con()) { |
1947 | const TypeAryPtr* base_type = base->bottom_type()->isa_aryptr(); |
1948 | if ((base_type != NULL__null) && base_type->is_autobox_cache()) { |
1949 | // It could be narrow oop |
1950 | assert(jt->make_ptr()->ptr() == TypePtr::NotNull,"sanity")do { if (!(jt->make_ptr()->ptr() == TypePtr::NotNull)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1950, "assert(" "jt->make_ptr()->ptr() == TypePtr::NotNull" ") failed", "sanity"); ::breakpoint(); } } while (0); |
1951 | } |
1952 | } |
1953 | } |
1954 | #endif |
1955 | return jt; |
1956 | } |
1957 | } |
1958 | } else if (tp->base() == Type::InstPtr) { |
1959 | assert( off != Type::OffsetBot ||do { if (!(off != Type::OffsetBot || tp->is_oopptr()->klass ()->is_java_lang_Object() || C->has_unsafe_access())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1964, "assert(" "off != Type::OffsetBot || tp->is_oopptr()->klass()->is_java_lang_Object() || C->has_unsafe_access()" ") failed", "Field accesses must be precise"); ::breakpoint( ); } } while (0) |
1960 | // arrays can be cast to Objectsdo { if (!(off != Type::OffsetBot || tp->is_oopptr()->klass ()->is_java_lang_Object() || C->has_unsafe_access())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1964, "assert(" "off != Type::OffsetBot || tp->is_oopptr()->klass()->is_java_lang_Object() || C->has_unsafe_access()" ") failed", "Field accesses must be precise"); ::breakpoint( ); } } while (0) |
1961 | tp->is_oopptr()->klass()->is_java_lang_Object() ||do { if (!(off != Type::OffsetBot || tp->is_oopptr()->klass ()->is_java_lang_Object() || C->has_unsafe_access())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1964, "assert(" "off != Type::OffsetBot || tp->is_oopptr()->klass()->is_java_lang_Object() || C->has_unsafe_access()" ") failed", "Field accesses must be precise"); ::breakpoint( ); } } while (0) |
1962 | // unsafe field access may not have a constant offsetdo { if (!(off != Type::OffsetBot || tp->is_oopptr()->klass ()->is_java_lang_Object() || C->has_unsafe_access())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1964, "assert(" "off != Type::OffsetBot || tp->is_oopptr()->klass()->is_java_lang_Object() || C->has_unsafe_access()" ") failed", "Field accesses must be precise"); ::breakpoint( ); } } while (0) |
1963 | C->has_unsafe_access(),do { if (!(off != Type::OffsetBot || tp->is_oopptr()->klass ()->is_java_lang_Object() || C->has_unsafe_access())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1964, "assert(" "off != Type::OffsetBot || tp->is_oopptr()->klass()->is_java_lang_Object() || C->has_unsafe_access()" ") failed", "Field accesses must be precise"); ::breakpoint( ); } } while (0) |
1964 | "Field accesses must be precise" )do { if (!(off != Type::OffsetBot || tp->is_oopptr()->klass ()->is_java_lang_Object() || C->has_unsafe_access())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1964, "assert(" "off != Type::OffsetBot || tp->is_oopptr()->klass()->is_java_lang_Object() || C->has_unsafe_access()" ") failed", "Field accesses must be precise"); ::breakpoint( ); } } while (0); |
1965 | // For oop loads, we expect the _type to be precise. |
1966 | |
1967 | // Optimize loads from constant fields. |
1968 | const TypeInstPtr* tinst = tp->is_instptr(); |
1969 | ciObject* const_oop = tinst->const_oop(); |
1970 | if (!is_mismatched_access() && off != Type::OffsetBot && const_oop != NULL__null && const_oop->is_instance()) { |
1971 | const Type* con_type = Type::make_constant_from_field(const_oop->as_instance(), off, is_unsigned(), memory_type()); |
1972 | if (con_type != NULL__null) { |
1973 | return con_type; |
1974 | } |
1975 | } |
1976 | } else if (tp->base() == Type::KlassPtr || tp->base() == Type::InstKlassPtr || tp->base() == Type::AryKlassPtr) { |
1977 | assert( off != Type::OffsetBot ||do { if (!(off != Type::OffsetBot || tp->is_klassptr()-> klass()->is_java_lang_Object() || Opcode() == Op_LoadKlass )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1983, "assert(" "off != Type::OffsetBot || tp->is_klassptr()->klass()->is_java_lang_Object() || Opcode() == Op_LoadKlass" ") failed", "Field accesses must be precise"); ::breakpoint( ); } } while (0) |
1978 | // arrays can be cast to Objectsdo { if (!(off != Type::OffsetBot || tp->is_klassptr()-> klass()->is_java_lang_Object() || Opcode() == Op_LoadKlass )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1983, "assert(" "off != Type::OffsetBot || tp->is_klassptr()->klass()->is_java_lang_Object() || Opcode() == Op_LoadKlass" ") failed", "Field accesses must be precise"); ::breakpoint( ); } } while (0) |
1979 | tp->is_klassptr()->klass()->is_java_lang_Object() ||do { if (!(off != Type::OffsetBot || tp->is_klassptr()-> klass()->is_java_lang_Object() || Opcode() == Op_LoadKlass )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1983, "assert(" "off != Type::OffsetBot || tp->is_klassptr()->klass()->is_java_lang_Object() || Opcode() == Op_LoadKlass" ") failed", "Field accesses must be precise"); ::breakpoint( ); } } while (0) |
1980 | // also allow array-loading from the primary supertypedo { if (!(off != Type::OffsetBot || tp->is_klassptr()-> klass()->is_java_lang_Object() || Opcode() == Op_LoadKlass )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1983, "assert(" "off != Type::OffsetBot || tp->is_klassptr()->klass()->is_java_lang_Object() || Opcode() == Op_LoadKlass" ") failed", "Field accesses must be precise"); ::breakpoint( ); } } while (0) |
1981 | // array during subtype checksdo { if (!(off != Type::OffsetBot || tp->is_klassptr()-> klass()->is_java_lang_Object() || Opcode() == Op_LoadKlass )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1983, "assert(" "off != Type::OffsetBot || tp->is_klassptr()->klass()->is_java_lang_Object() || Opcode() == Op_LoadKlass" ") failed", "Field accesses must be precise"); ::breakpoint( ); } } while (0) |
1982 | Opcode() == Op_LoadKlass,do { if (!(off != Type::OffsetBot || tp->is_klassptr()-> klass()->is_java_lang_Object() || Opcode() == Op_LoadKlass )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1983, "assert(" "off != Type::OffsetBot || tp->is_klassptr()->klass()->is_java_lang_Object() || Opcode() == Op_LoadKlass" ") failed", "Field accesses must be precise"); ::breakpoint( ); } } while (0) |
1983 | "Field accesses must be precise" )do { if (!(off != Type::OffsetBot || tp->is_klassptr()-> klass()->is_java_lang_Object() || Opcode() == Op_LoadKlass )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1983, "assert(" "off != Type::OffsetBot || tp->is_klassptr()->klass()->is_java_lang_Object() || Opcode() == Op_LoadKlass" ") failed", "Field accesses must be precise"); ::breakpoint( ); } } while (0); |
1984 | // For klass/static loads, we expect the _type to be precise |
1985 | } else if (tp->base() == Type::RawPtr && adr->is_Load() && off == 0) { |
1986 | /* With mirrors being an indirect in the Klass* |
1987 | * the VM is now using two loads. LoadKlass(LoadP(LoadP(Klass, mirror_offset), zero_offset)) |
1988 | * The LoadP from the Klass has a RawPtr type (see LibraryCallKit::load_mirror_from_klass). |
1989 | * |
1990 | * So check the type and klass of the node before the LoadP. |
1991 | */ |
1992 | Node* adr2 = adr->in(MemNode::Address); |
1993 | const TypeKlassPtr* tkls = phase->type(adr2)->isa_klassptr(); |
1994 | if (tkls != NULL__null && !StressReflectiveCode) { |
1995 | ciKlass* klass = tkls->klass(); |
1996 | if (klass->is_loaded() && tkls->klass_is_exact() && tkls->offset() == in_bytes(Klass::java_mirror_offset())) { |
1997 | assert(adr->Opcode() == Op_LoadP, "must load an oop from _java_mirror")do { if (!(adr->Opcode() == Op_LoadP)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1997, "assert(" "adr->Opcode() == Op_LoadP" ") failed", "must load an oop from _java_mirror" ); ::breakpoint(); } } while (0); |
1998 | assert(Opcode() == Op_LoadP, "must load an oop from _java_mirror")do { if (!(Opcode() == Op_LoadP)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 1998, "assert(" "Opcode() == Op_LoadP" ") failed", "must load an oop from _java_mirror" ); ::breakpoint(); } } while (0); |
1999 | return TypeInstPtr::make(klass->java_mirror()); |
2000 | } |
2001 | } |
2002 | } |
2003 | |
2004 | const TypeKlassPtr *tkls = tp->isa_klassptr(); |
2005 | if (tkls != NULL__null && !StressReflectiveCode) { |
2006 | ciKlass* klass = tkls->klass(); |
2007 | if (klass->is_loaded() && tkls->klass_is_exact()) { |
2008 | // We are loading a field from a Klass metaobject whose identity |
2009 | // is known at compile time (the type is "exact" or "precise"). |
2010 | // Check for fields we know are maintained as constants by the VM. |
2011 | if (tkls->offset() == in_bytes(Klass::super_check_offset_offset())) { |
2012 | // The field is Klass::_super_check_offset. Return its (constant) value. |
2013 | // (Folds up type checking code.) |
2014 | assert(Opcode() == Op_LoadI, "must load an int from _super_check_offset")do { if (!(Opcode() == Op_LoadI)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2014, "assert(" "Opcode() == Op_LoadI" ") failed", "must load an int from _super_check_offset" ); ::breakpoint(); } } while (0); |
2015 | return TypeInt::make(klass->super_check_offset()); |
2016 | } |
2017 | // Compute index into primary_supers array |
2018 | juint depth = (tkls->offset() - in_bytes(Klass::primary_supers_offset())) / sizeof(Klass*); |
2019 | // Check for overflowing; use unsigned compare to handle the negative case. |
2020 | if( depth < ciKlass::primary_super_limit() ) { |
2021 | // The field is an element of Klass::_primary_supers. Return its (constant) value. |
2022 | // (Folds up type checking code.) |
2023 | assert(Opcode() == Op_LoadKlass, "must load a klass from _primary_supers")do { if (!(Opcode() == Op_LoadKlass)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2023, "assert(" "Opcode() == Op_LoadKlass" ") failed", "must load a klass from _primary_supers" ); ::breakpoint(); } } while (0); |
2024 | ciKlass *ss = klass->super_of_depth(depth); |
2025 | return ss ? TypeKlassPtr::make(ss) : TypePtr::NULL_PTR; |
2026 | } |
2027 | const Type* aift = load_array_final_field(tkls, klass); |
2028 | if (aift != NULL__null) return aift; |
2029 | } |
2030 | |
2031 | // We can still check if we are loading from the primary_supers array at a |
2032 | // shallow enough depth. Even though the klass is not exact, entries less |
2033 | // than or equal to its super depth are correct. |
2034 | if (klass->is_loaded() ) { |
2035 | ciType *inner = klass; |
2036 | while( inner->is_obj_array_klass() ) |
2037 | inner = inner->as_obj_array_klass()->base_element_type(); |
2038 | if( inner->is_instance_klass() && |
2039 | !inner->as_instance_klass()->flags().is_interface() ) { |
2040 | // Compute index into primary_supers array |
2041 | juint depth = (tkls->offset() - in_bytes(Klass::primary_supers_offset())) / sizeof(Klass*); |
2042 | // Check for overflowing; use unsigned compare to handle the negative case. |
2043 | if( depth < ciKlass::primary_super_limit() && |
2044 | depth <= klass->super_depth() ) { // allow self-depth checks to handle self-check case |
2045 | // The field is an element of Klass::_primary_supers. Return its (constant) value. |
2046 | // (Folds up type checking code.) |
2047 | assert(Opcode() == Op_LoadKlass, "must load a klass from _primary_supers")do { if (!(Opcode() == Op_LoadKlass)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2047, "assert(" "Opcode() == Op_LoadKlass" ") failed", "must load a klass from _primary_supers" ); ::breakpoint(); } } while (0); |
2048 | ciKlass *ss = klass->super_of_depth(depth); |
2049 | return ss ? TypeKlassPtr::make(ss) : TypePtr::NULL_PTR; |
2050 | } |
2051 | } |
2052 | } |
2053 | |
2054 | // If the type is enough to determine that the thing is not an array, |
2055 | // we can give the layout_helper a positive interval type. |
2056 | // This will help short-circuit some reflective code. |
2057 | if (tkls->offset() == in_bytes(Klass::layout_helper_offset()) |
2058 | && !klass->is_array_klass() // not directly typed as an array |
2059 | && !klass->is_interface() // specifically not Serializable & Cloneable |
2060 | && !klass->is_java_lang_Object() // not the supertype of all T[] |
2061 | ) { |
2062 | // Note: When interfaces are reliable, we can narrow the interface |
2063 | // test to (klass != Serializable && klass != Cloneable). |
2064 | assert(Opcode() == Op_LoadI, "must load an int from _layout_helper")do { if (!(Opcode() == Op_LoadI)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2064, "assert(" "Opcode() == Op_LoadI" ") failed", "must load an int from _layout_helper" ); ::breakpoint(); } } while (0); |
2065 | jint min_size = Klass::instance_layout_helper(oopDesc::header_size(), false); |
2066 | // The key property of this type is that it folds up tests |
2067 | // for array-ness, since it proves that the layout_helper is positive. |
2068 | // Thus, a generic value like the basic object layout helper works fine. |
2069 | return TypeInt::make(min_size, max_jint, Type::WidenMin); |
2070 | } |
2071 | } |
2072 | |
2073 | // If we are loading from a freshly-allocated object, produce a zero, |
2074 | // if the load is provably beyond the header of the object. |
2075 | // (Also allow a variable load from a fresh array to produce zero.) |
2076 | const TypeOopPtr *tinst = tp->isa_oopptr(); |
2077 | bool is_instance = (tinst != NULL__null) && tinst->is_known_instance_field(); |
2078 | bool is_boxed_value = (tinst != NULL__null) && tinst->is_ptr_to_boxed_value(); |
2079 | if (ReduceFieldZeroing || is_instance || is_boxed_value) { |
2080 | Node* value = can_see_stored_value(mem,phase); |
2081 | if (value != NULL__null && value->is_Con()) { |
2082 | assert(value->bottom_type()->higher_equal(_type),"sanity")do { if (!(value->bottom_type()->higher_equal(_type))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2082, "assert(" "value->bottom_type()->higher_equal(_type)" ") failed", "sanity"); ::breakpoint(); } } while (0); |
2083 | return value->bottom_type(); |
2084 | } |
2085 | } |
2086 | |
2087 | bool is_vect = (_type->isa_vect() != NULL__null); |
2088 | if (is_instance && !is_vect) { |
2089 | // If we have an instance type and our memory input is the |
2090 | // programs's initial memory state, there is no matching store, |
2091 | // so just return a zero of the appropriate type - |
2092 | // except if it is vectorized - then we have no zero constant. |
2093 | Node *mem = in(MemNode::Memory); |
2094 | if (mem->is_Parm() && mem->in(0)->is_Start()) { |
2095 | assert(mem->as_Parm()->_con == TypeFunc::Memory, "must be memory Parm")do { if (!(mem->as_Parm()->_con == TypeFunc::Memory)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2095, "assert(" "mem->as_Parm()->_con == TypeFunc::Memory" ") failed", "must be memory Parm"); ::breakpoint(); } } while (0); |
2096 | return Type::get_zero_type(_type->basic_type()); |
2097 | } |
2098 | } |
2099 | |
2100 | Node* alloc = is_new_object_mark_load(phase); |
2101 | if (alloc != NULL__null) { |
2102 | return TypeXTypeLong::make(markWord::prototype().value()); |
2103 | } |
2104 | |
2105 | return _type; |
2106 | } |
2107 | |
2108 | //------------------------------match_edge------------------------------------- |
2109 | // Do we Match on this edge index or not? Match only the address. |
2110 | uint LoadNode::match_edge(uint idx) const { |
2111 | return idx == MemNode::Address; |
2112 | } |
2113 | |
2114 | //--------------------------LoadBNode::Ideal-------------------------------------- |
2115 | // |
2116 | // If the previous store is to the same address as this load, |
2117 | // and the value stored was larger than a byte, replace this load |
2118 | // with the value stored truncated to a byte. If no truncation is |
2119 | // needed, the replacement is done in LoadNode::Identity(). |
2120 | // |
2121 | Node* LoadBNode::Ideal(PhaseGVN* phase, bool can_reshape) { |
2122 | Node* mem = in(MemNode::Memory); |
2123 | Node* value = can_see_stored_value(mem,phase); |
2124 | if (value != NULL__null) { |
2125 | Node* narrow = Compile::narrow_value(T_BYTE, value, _type, phase, false); |
2126 | if (narrow != value) { |
2127 | return narrow; |
2128 | } |
2129 | } |
2130 | // Identity call will handle the case where truncation is not needed. |
2131 | return LoadNode::Ideal(phase, can_reshape); |
2132 | } |
2133 | |
2134 | const Type* LoadBNode::Value(PhaseGVN* phase) const { |
2135 | Node* mem = in(MemNode::Memory); |
2136 | Node* value = can_see_stored_value(mem,phase); |
2137 | if (value != NULL__null && value->is_Con() && |
2138 | !value->bottom_type()->higher_equal(_type)) { |
2139 | // If the input to the store does not fit with the load's result type, |
2140 | // it must be truncated. We can't delay until Ideal call since |
2141 | // a singleton Value is needed for split_thru_phi optimization. |
2142 | int con = value->get_int(); |
2143 | return TypeInt::make((con << 24) >> 24); |
2144 | } |
2145 | return LoadNode::Value(phase); |
2146 | } |
2147 | |
2148 | //--------------------------LoadUBNode::Ideal------------------------------------- |
2149 | // |
2150 | // If the previous store is to the same address as this load, |
2151 | // and the value stored was larger than a byte, replace this load |
2152 | // with the value stored truncated to a byte. If no truncation is |
2153 | // needed, the replacement is done in LoadNode::Identity(). |
2154 | // |
2155 | Node* LoadUBNode::Ideal(PhaseGVN* phase, bool can_reshape) { |
2156 | Node* mem = in(MemNode::Memory); |
2157 | Node* value = can_see_stored_value(mem, phase); |
2158 | if (value != NULL__null) { |
2159 | Node* narrow = Compile::narrow_value(T_BOOLEAN, value, _type, phase, false); |
2160 | if (narrow != value) { |
2161 | return narrow; |
2162 | } |
2163 | } |
2164 | // Identity call will handle the case where truncation is not needed. |
2165 | return LoadNode::Ideal(phase, can_reshape); |
2166 | } |
2167 | |
2168 | const Type* LoadUBNode::Value(PhaseGVN* phase) const { |
2169 | Node* mem = in(MemNode::Memory); |
2170 | Node* value = can_see_stored_value(mem,phase); |
2171 | if (value != NULL__null && value->is_Con() && |
2172 | !value->bottom_type()->higher_equal(_type)) { |
2173 | // If the input to the store does not fit with the load's result type, |
2174 | // it must be truncated. We can't delay until Ideal call since |
2175 | // a singleton Value is needed for split_thru_phi optimization. |
2176 | int con = value->get_int(); |
2177 | return TypeInt::make(con & 0xFF); |
2178 | } |
2179 | return LoadNode::Value(phase); |
2180 | } |
2181 | |
2182 | //--------------------------LoadUSNode::Ideal------------------------------------- |
2183 | // |
2184 | // If the previous store is to the same address as this load, |
2185 | // and the value stored was larger than a char, replace this load |
2186 | // with the value stored truncated to a char. If no truncation is |
2187 | // needed, the replacement is done in LoadNode::Identity(). |
2188 | // |
2189 | Node* LoadUSNode::Ideal(PhaseGVN* phase, bool can_reshape) { |
2190 | Node* mem = in(MemNode::Memory); |
2191 | Node* value = can_see_stored_value(mem,phase); |
2192 | if (value != NULL__null) { |
2193 | Node* narrow = Compile::narrow_value(T_CHAR, value, _type, phase, false); |
2194 | if (narrow != value) { |
2195 | return narrow; |
2196 | } |
2197 | } |
2198 | // Identity call will handle the case where truncation is not needed. |
2199 | return LoadNode::Ideal(phase, can_reshape); |
2200 | } |
2201 | |
2202 | const Type* LoadUSNode::Value(PhaseGVN* phase) const { |
2203 | Node* mem = in(MemNode::Memory); |
2204 | Node* value = can_see_stored_value(mem,phase); |
2205 | if (value != NULL__null && value->is_Con() && |
2206 | !value->bottom_type()->higher_equal(_type)) { |
2207 | // If the input to the store does not fit with the load's result type, |
2208 | // it must be truncated. We can't delay until Ideal call since |
2209 | // a singleton Value is needed for split_thru_phi optimization. |
2210 | int con = value->get_int(); |
2211 | return TypeInt::make(con & 0xFFFF); |
2212 | } |
2213 | return LoadNode::Value(phase); |
2214 | } |
2215 | |
2216 | //--------------------------LoadSNode::Ideal-------------------------------------- |
2217 | // |
2218 | // If the previous store is to the same address as this load, |
2219 | // and the value stored was larger than a short, replace this load |
2220 | // with the value stored truncated to a short. If no truncation is |
2221 | // needed, the replacement is done in LoadNode::Identity(). |
2222 | // |
2223 | Node* LoadSNode::Ideal(PhaseGVN* phase, bool can_reshape) { |
2224 | Node* mem = in(MemNode::Memory); |
2225 | Node* value = can_see_stored_value(mem,phase); |
2226 | if (value != NULL__null) { |
2227 | Node* narrow = Compile::narrow_value(T_SHORT, value, _type, phase, false); |
2228 | if (narrow != value) { |
2229 | return narrow; |
2230 | } |
2231 | } |
2232 | // Identity call will handle the case where truncation is not needed. |
2233 | return LoadNode::Ideal(phase, can_reshape); |
2234 | } |
2235 | |
2236 | const Type* LoadSNode::Value(PhaseGVN* phase) const { |
2237 | Node* mem = in(MemNode::Memory); |
2238 | Node* value = can_see_stored_value(mem,phase); |
2239 | if (value != NULL__null && value->is_Con() && |
2240 | !value->bottom_type()->higher_equal(_type)) { |
2241 | // If the input to the store does not fit with the load's result type, |
2242 | // it must be truncated. We can't delay until Ideal call since |
2243 | // a singleton Value is needed for split_thru_phi optimization. |
2244 | int con = value->get_int(); |
2245 | return TypeInt::make((con << 16) >> 16); |
2246 | } |
2247 | return LoadNode::Value(phase); |
2248 | } |
2249 | |
2250 | //============================================================================= |
2251 | //----------------------------LoadKlassNode::make------------------------------ |
2252 | // Polymorphic factory method: |
2253 | Node* LoadKlassNode::make(PhaseGVN& gvn, Node* ctl, Node* mem, Node* adr, const TypePtr* at, const TypeKlassPtr* tk) { |
2254 | // sanity check the alias category against the created node type |
2255 | const TypePtr *adr_type = adr->bottom_type()->isa_ptr(); |
2256 | assert(adr_type != NULL, "expecting TypeKlassPtr")do { if (!(adr_type != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2256, "assert(" "adr_type != __null" ") failed", "expecting TypeKlassPtr" ); ::breakpoint(); } } while (0); |
2257 | #ifdef _LP641 |
2258 | if (adr_type->is_ptr_to_narrowklass()) { |
2259 | assert(UseCompressedClassPointers, "no compressed klasses")do { if (!(UseCompressedClassPointers)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2259, "assert(" "UseCompressedClassPointers" ") failed", "no compressed klasses" ); ::breakpoint(); } } while (0); |
2260 | Node* load_klass = gvn.transform(new LoadNKlassNode(ctl, mem, adr, at, tk->make_narrowklass(), MemNode::unordered)); |
2261 | return new DecodeNKlassNode(load_klass, load_klass->bottom_type()->make_ptr()); |
2262 | } |
2263 | #endif |
2264 | assert(!adr_type->is_ptr_to_narrowklass() && !adr_type->is_ptr_to_narrowoop(), "should have got back a narrow oop")do { if (!(!adr_type->is_ptr_to_narrowklass() && ! adr_type->is_ptr_to_narrowoop())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2264, "assert(" "!adr_type->is_ptr_to_narrowklass() && !adr_type->is_ptr_to_narrowoop()" ") failed", "should have got back a narrow oop"); ::breakpoint (); } } while (0); |
2265 | return new LoadKlassNode(ctl, mem, adr, at, tk, MemNode::unordered); |
2266 | } |
2267 | |
2268 | //------------------------------Value------------------------------------------ |
2269 | const Type* LoadKlassNode::Value(PhaseGVN* phase) const { |
2270 | return klass_value_common(phase); |
2271 | } |
2272 | |
2273 | // In most cases, LoadKlassNode does not have the control input set. If the control |
2274 | // input is set, it must not be removed (by LoadNode::Ideal()). |
2275 | bool LoadKlassNode::can_remove_control() const { |
2276 | return false; |
2277 | } |
2278 | |
2279 | const Type* LoadNode::klass_value_common(PhaseGVN* phase) const { |
2280 | // Either input is TOP ==> the result is TOP |
2281 | const Type *t1 = phase->type( in(MemNode::Memory) ); |
2282 | if (t1 == Type::TOP) return Type::TOP; |
2283 | Node *adr = in(MemNode::Address); |
2284 | const Type *t2 = phase->type( adr ); |
2285 | if (t2 == Type::TOP) return Type::TOP; |
2286 | const TypePtr *tp = t2->is_ptr(); |
2287 | if (TypePtr::above_centerline(tp->ptr()) || |
2288 | tp->ptr() == TypePtr::Null) return Type::TOP; |
2289 | |
2290 | // Return a more precise klass, if possible |
2291 | const TypeInstPtr *tinst = tp->isa_instptr(); |
2292 | if (tinst != NULL__null) { |
2293 | ciInstanceKlass* ik = tinst->klass()->as_instance_klass(); |
2294 | int offset = tinst->offset(); |
2295 | if (ik == phase->C->env()->Class_klass() |
2296 | && (offset == java_lang_Class::klass_offset() || |
2297 | offset == java_lang_Class::array_klass_offset())) { |
2298 | // We are loading a special hidden field from a Class mirror object, |
2299 | // the field which points to the VM's Klass metaobject. |
2300 | ciType* t = tinst->java_mirror_type(); |
2301 | // java_mirror_type returns non-null for compile-time Class constants. |
2302 | if (t != NULL__null) { |
2303 | // constant oop => constant klass |
2304 | if (offset == java_lang_Class::array_klass_offset()) { |
2305 | if (t->is_void()) { |
2306 | // We cannot create a void array. Since void is a primitive type return null |
2307 | // klass. Users of this result need to do a null check on the returned klass. |
2308 | return TypePtr::NULL_PTR; |
2309 | } |
2310 | return TypeKlassPtr::make(ciArrayKlass::make(t)); |
2311 | } |
2312 | if (!t->is_klass()) { |
2313 | // a primitive Class (e.g., int.class) has NULL for a klass field |
2314 | return TypePtr::NULL_PTR; |
2315 | } |
2316 | // (Folds up the 1st indirection in aClassConstant.getModifiers().) |
2317 | return TypeKlassPtr::make(t->as_klass()); |
2318 | } |
2319 | // non-constant mirror, so we can't tell what's going on |
2320 | } |
2321 | if( !ik->is_loaded() ) |
2322 | return _type; // Bail out if not loaded |
2323 | if (offset == oopDesc::klass_offset_in_bytes()) { |
2324 | if (tinst->klass_is_exact()) { |
2325 | return TypeKlassPtr::make(ik); |
2326 | } |
2327 | // See if we can become precise: no subklasses and no interface |
2328 | // (Note: We need to support verified interfaces.) |
2329 | if (!ik->is_interface() && !ik->has_subklass()) { |
2330 | // Add a dependence; if any subclass added we need to recompile |
2331 | if (!ik->is_final()) { |
2332 | // %%% should use stronger assert_unique_concrete_subtype instead |
2333 | phase->C->dependencies()->assert_leaf_type(ik); |
2334 | } |
2335 | // Return precise klass |
2336 | return TypeKlassPtr::make(ik); |
2337 | } |
2338 | |
2339 | // Return root of possible klass |
2340 | return TypeKlassPtr::make(TypePtr::NotNull, ik, 0/*offset*/); |
2341 | } |
2342 | } |
2343 | |
2344 | // Check for loading klass from an array |
2345 | const TypeAryPtr *tary = tp->isa_aryptr(); |
2346 | if( tary != NULL__null ) { |
2347 | ciKlass *tary_klass = tary->klass(); |
2348 | if (tary_klass != NULL__null // can be NULL when at BOTTOM or TOP |
2349 | && tary->offset() == oopDesc::klass_offset_in_bytes()) { |
2350 | if (tary->klass_is_exact()) { |
2351 | return TypeKlassPtr::make(tary_klass); |
2352 | } |
2353 | ciArrayKlass *ak = tary->klass()->as_array_klass(); |
2354 | // If the klass is an object array, we defer the question to the |
2355 | // array component klass. |
2356 | if( ak->is_obj_array_klass() ) { |
2357 | assert( ak->is_loaded(), "" )do { if (!(ak->is_loaded())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2357, "assert(" "ak->is_loaded()" ") failed", ""); ::breakpoint (); } } while (0); |
2358 | ciKlass *base_k = ak->as_obj_array_klass()->base_element_klass(); |
2359 | if( base_k->is_loaded() && base_k->is_instance_klass() ) { |
2360 | ciInstanceKlass* ik = base_k->as_instance_klass(); |
2361 | // See if we can become precise: no subklasses and no interface |
2362 | if (!ik->is_interface() && !ik->has_subklass()) { |
2363 | // Add a dependence; if any subclass added we need to recompile |
2364 | if (!ik->is_final()) { |
2365 | phase->C->dependencies()->assert_leaf_type(ik); |
2366 | } |
2367 | // Return precise array klass |
2368 | return TypeKlassPtr::make(ak); |
2369 | } |
2370 | } |
2371 | return TypeKlassPtr::make(TypePtr::NotNull, ak, 0/*offset*/); |
2372 | } else { // Found a type-array? |
2373 | assert( ak->is_type_array_klass(), "" )do { if (!(ak->is_type_array_klass())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2373, "assert(" "ak->is_type_array_klass()" ") failed", "" ); ::breakpoint(); } } while (0); |
2374 | return TypeKlassPtr::make(ak); // These are always precise |
2375 | } |
2376 | } |
2377 | } |
2378 | |
2379 | // Check for loading klass from an array klass |
2380 | const TypeKlassPtr *tkls = tp->isa_klassptr(); |
2381 | if (tkls != NULL__null && !StressReflectiveCode) { |
2382 | ciKlass* klass = tkls->klass(); |
2383 | if( !klass->is_loaded() ) |
2384 | return _type; // Bail out if not loaded |
2385 | if( klass->is_obj_array_klass() && |
2386 | tkls->offset() == in_bytes(ObjArrayKlass::element_klass_offset())) { |
2387 | ciKlass* elem = klass->as_obj_array_klass()->element_klass(); |
2388 | // // Always returning precise element type is incorrect, |
2389 | // // e.g., element type could be object and array may contain strings |
2390 | // return TypeKlassPtr::make(TypePtr::Constant, elem, 0); |
2391 | |
2392 | // The array's TypeKlassPtr was declared 'precise' or 'not precise' |
2393 | // according to the element type's subclassing. |
2394 | return TypeKlassPtr::make(tkls->ptr(), elem, 0/*offset*/); |
2395 | } |
2396 | if( klass->is_instance_klass() && tkls->klass_is_exact() && |
2397 | tkls->offset() == in_bytes(Klass::super_offset())) { |
2398 | ciKlass* sup = klass->as_instance_klass()->super(); |
2399 | // The field is Klass::_super. Return its (constant) value. |
2400 | // (Folds up the 2nd indirection in aClassConstant.getSuperClass().) |
2401 | return sup ? TypeKlassPtr::make(sup) : TypePtr::NULL_PTR; |
2402 | } |
2403 | } |
2404 | |
2405 | // Bailout case |
2406 | return LoadNode::Value(phase); |
2407 | } |
2408 | |
2409 | //------------------------------Identity--------------------------------------- |
2410 | // To clean up reflective code, simplify k.java_mirror.as_klass to plain k. |
2411 | // Also feed through the klass in Allocate(...klass...)._klass. |
2412 | Node* LoadKlassNode::Identity(PhaseGVN* phase) { |
2413 | return klass_identity_common(phase); |
2414 | } |
2415 | |
2416 | Node* LoadNode::klass_identity_common(PhaseGVN* phase) { |
2417 | Node* x = LoadNode::Identity(phase); |
2418 | if (x != this) return x; |
2419 | |
2420 | // Take apart the address into an oop and and offset. |
2421 | // Return 'this' if we cannot. |
2422 | Node* adr = in(MemNode::Address); |
2423 | intptr_t offset = 0; |
2424 | Node* base = AddPNode::Ideal_base_and_offset(adr, phase, offset); |
2425 | if (base == NULL__null) return this; |
2426 | const TypeOopPtr* toop = phase->type(adr)->isa_oopptr(); |
2427 | if (toop == NULL__null) return this; |
2428 | |
2429 | // Step over potential GC barrier for OopHandle resolve |
2430 | BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2(); |
2431 | if (bs->is_gc_barrier_node(base)) { |
2432 | base = bs->step_over_gc_barrier(base); |
2433 | } |
2434 | |
2435 | // We can fetch the klass directly through an AllocateNode. |
2436 | // This works even if the klass is not constant (clone or newArray). |
2437 | if (offset == oopDesc::klass_offset_in_bytes()) { |
2438 | Node* allocated_klass = AllocateNode::Ideal_klass(base, phase); |
2439 | if (allocated_klass != NULL__null) { |
2440 | return allocated_klass; |
2441 | } |
2442 | } |
2443 | |
2444 | // Simplify k.java_mirror.as_klass to plain k, where k is a Klass*. |
2445 | // See inline_native_Class_query for occurrences of these patterns. |
2446 | // Java Example: x.getClass().isAssignableFrom(y) |
2447 | // |
2448 | // This improves reflective code, often making the Class |
2449 | // mirror go completely dead. (Current exception: Class |
2450 | // mirrors may appear in debug info, but we could clean them out by |
2451 | // introducing a new debug info operator for Klass.java_mirror). |
2452 | |
2453 | if (toop->isa_instptr() && toop->klass() == phase->C->env()->Class_klass() |
2454 | && offset == java_lang_Class::klass_offset()) { |
2455 | if (base->is_Load()) { |
2456 | Node* base2 = base->in(MemNode::Address); |
2457 | if (base2->is_Load()) { /* direct load of a load which is the OopHandle */ |
2458 | Node* adr2 = base2->in(MemNode::Address); |
2459 | const TypeKlassPtr* tkls = phase->type(adr2)->isa_klassptr(); |
2460 | if (tkls != NULL__null && !tkls->empty() |
2461 | && (tkls->klass()->is_instance_klass() || |
2462 | tkls->klass()->is_array_klass()) |
2463 | && adr2->is_AddP() |
2464 | ) { |
2465 | int mirror_field = in_bytes(Klass::java_mirror_offset()); |
2466 | if (tkls->offset() == mirror_field) { |
2467 | return adr2->in(AddPNode::Base); |
2468 | } |
2469 | } |
2470 | } |
2471 | } |
2472 | } |
2473 | |
2474 | return this; |
2475 | } |
2476 | |
2477 | |
2478 | //------------------------------Value------------------------------------------ |
2479 | const Type* LoadNKlassNode::Value(PhaseGVN* phase) const { |
2480 | const Type *t = klass_value_common(phase); |
2481 | if (t == Type::TOP) |
2482 | return t; |
2483 | |
2484 | return t->make_narrowklass(); |
2485 | } |
2486 | |
2487 | //------------------------------Identity--------------------------------------- |
2488 | // To clean up reflective code, simplify k.java_mirror.as_klass to narrow k. |
2489 | // Also feed through the klass in Allocate(...klass...)._klass. |
2490 | Node* LoadNKlassNode::Identity(PhaseGVN* phase) { |
2491 | Node *x = klass_identity_common(phase); |
2492 | |
2493 | const Type *t = phase->type( x ); |
2494 | if( t == Type::TOP ) return x; |
2495 | if( t->isa_narrowklass()) return x; |
2496 | assert (!t->isa_narrowoop(), "no narrow oop here")do { if (!(!t->isa_narrowoop())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2496, "assert(" "!t->isa_narrowoop()" ") failed", "no narrow oop here" ); ::breakpoint(); } } while (0); |
2497 | |
2498 | return phase->transform(new EncodePKlassNode(x, t->make_narrowklass())); |
2499 | } |
2500 | |
2501 | //------------------------------Value----------------------------------------- |
2502 | const Type* LoadRangeNode::Value(PhaseGVN* phase) const { |
2503 | // Either input is TOP ==> the result is TOP |
2504 | const Type *t1 = phase->type( in(MemNode::Memory) ); |
2505 | if( t1 == Type::TOP ) return Type::TOP; |
2506 | Node *adr = in(MemNode::Address); |
2507 | const Type *t2 = phase->type( adr ); |
2508 | if( t2 == Type::TOP ) return Type::TOP; |
2509 | const TypePtr *tp = t2->is_ptr(); |
2510 | if (TypePtr::above_centerline(tp->ptr())) return Type::TOP; |
2511 | const TypeAryPtr *tap = tp->isa_aryptr(); |
2512 | if( !tap ) return _type; |
2513 | return tap->size(); |
2514 | } |
2515 | |
2516 | //-------------------------------Ideal--------------------------------------- |
2517 | // Feed through the length in AllocateArray(...length...)._length. |
2518 | Node *LoadRangeNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
2519 | Node* p = MemNode::Ideal_common(phase, can_reshape); |
2520 | if (p) return (p == NodeSentinel(Node*)-1) ? NULL__null : p; |
2521 | |
2522 | // Take apart the address into an oop and and offset. |
2523 | // Return 'this' if we cannot. |
2524 | Node* adr = in(MemNode::Address); |
2525 | intptr_t offset = 0; |
2526 | Node* base = AddPNode::Ideal_base_and_offset(adr, phase, offset); |
2527 | if (base == NULL__null) return NULL__null; |
2528 | const TypeAryPtr* tary = phase->type(adr)->isa_aryptr(); |
2529 | if (tary == NULL__null) return NULL__null; |
2530 | |
2531 | // We can fetch the length directly through an AllocateArrayNode. |
2532 | // This works even if the length is not constant (clone or newArray). |
2533 | if (offset == arrayOopDesc::length_offset_in_bytes()) { |
2534 | AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(base, phase); |
2535 | if (alloc != NULL__null) { |
2536 | Node* allocated_length = alloc->Ideal_length(); |
2537 | Node* len = alloc->make_ideal_length(tary, phase); |
2538 | if (allocated_length != len) { |
2539 | // New CastII improves on this. |
2540 | return len; |
2541 | } |
2542 | } |
2543 | } |
2544 | |
2545 | return NULL__null; |
2546 | } |
2547 | |
2548 | //------------------------------Identity--------------------------------------- |
2549 | // Feed through the length in AllocateArray(...length...)._length. |
2550 | Node* LoadRangeNode::Identity(PhaseGVN* phase) { |
2551 | Node* x = LoadINode::Identity(phase); |
2552 | if (x != this) return x; |
2553 | |
2554 | // Take apart the address into an oop and and offset. |
2555 | // Return 'this' if we cannot. |
2556 | Node* adr = in(MemNode::Address); |
2557 | intptr_t offset = 0; |
2558 | Node* base = AddPNode::Ideal_base_and_offset(adr, phase, offset); |
2559 | if (base == NULL__null) return this; |
2560 | const TypeAryPtr* tary = phase->type(adr)->isa_aryptr(); |
2561 | if (tary == NULL__null) return this; |
2562 | |
2563 | // We can fetch the length directly through an AllocateArrayNode. |
2564 | // This works even if the length is not constant (clone or newArray). |
2565 | if (offset == arrayOopDesc::length_offset_in_bytes()) { |
2566 | AllocateArrayNode* alloc = AllocateArrayNode::Ideal_array_allocation(base, phase); |
2567 | if (alloc != NULL__null) { |
2568 | Node* allocated_length = alloc->Ideal_length(); |
2569 | // Do not allow make_ideal_length to allocate a CastII node. |
2570 | Node* len = alloc->make_ideal_length(tary, phase, false); |
2571 | if (allocated_length == len) { |
2572 | // Return allocated_length only if it would not be improved by a CastII. |
2573 | return allocated_length; |
2574 | } |
2575 | } |
2576 | } |
2577 | |
2578 | return this; |
2579 | |
2580 | } |
2581 | |
2582 | //============================================================================= |
2583 | //---------------------------StoreNode::make----------------------------------- |
2584 | // Polymorphic factory method: |
2585 | StoreNode* StoreNode::make(PhaseGVN& gvn, Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, Node* val, BasicType bt, MemOrd mo) { |
2586 | assert((mo == unordered || mo == release), "unexpected")do { if (!((mo == unordered || mo == release))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2586, "assert(" "(mo == unordered || mo == release)" ") failed" , "unexpected"); ::breakpoint(); } } while (0); |
2587 | Compile* C = gvn.C; |
2588 | assert(C->get_alias_index(adr_type) != Compile::AliasIdxRaw ||do { if (!(C->get_alias_index(adr_type) != Compile::AliasIdxRaw || ctl != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2589, "assert(" "C->get_alias_index(adr_type) != Compile::AliasIdxRaw || ctl != __null" ") failed", "raw memory operations should have control edge" ); ::breakpoint(); } } while (0) |
2589 | ctl != NULL, "raw memory operations should have control edge")do { if (!(C->get_alias_index(adr_type) != Compile::AliasIdxRaw || ctl != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2589, "assert(" "C->get_alias_index(adr_type) != Compile::AliasIdxRaw || ctl != __null" ") failed", "raw memory operations should have control edge" ); ::breakpoint(); } } while (0); |
2590 | |
2591 | switch (bt) { |
2592 | case T_BOOLEAN: val = gvn.transform(new AndINode(val, gvn.intcon(0x1))); // Fall through to T_BYTE case |
2593 | case T_BYTE: return new StoreBNode(ctl, mem, adr, adr_type, val, mo); |
2594 | case T_INT: return new StoreINode(ctl, mem, adr, adr_type, val, mo); |
2595 | case T_CHAR: |
2596 | case T_SHORT: return new StoreCNode(ctl, mem, adr, adr_type, val, mo); |
2597 | case T_LONG: return new StoreLNode(ctl, mem, adr, adr_type, val, mo); |
2598 | case T_FLOAT: return new StoreFNode(ctl, mem, adr, adr_type, val, mo); |
2599 | case T_DOUBLE: return new StoreDNode(ctl, mem, adr, adr_type, val, mo); |
2600 | case T_METADATA: |
2601 | case T_ADDRESS: |
2602 | case T_OBJECT: |
2603 | #ifdef _LP641 |
2604 | if (adr->bottom_type()->is_ptr_to_narrowoop()) { |
2605 | val = gvn.transform(new EncodePNode(val, val->bottom_type()->make_narrowoop())); |
2606 | return new StoreNNode(ctl, mem, adr, adr_type, val, mo); |
2607 | } else if (adr->bottom_type()->is_ptr_to_narrowklass() || |
2608 | (UseCompressedClassPointers && val->bottom_type()->isa_klassptr() && |
2609 | adr->bottom_type()->isa_rawptr())) { |
2610 | val = gvn.transform(new EncodePKlassNode(val, val->bottom_type()->make_narrowklass())); |
2611 | return new StoreNKlassNode(ctl, mem, adr, adr_type, val, mo); |
2612 | } |
2613 | #endif |
2614 | { |
2615 | return new StorePNode(ctl, mem, adr, adr_type, val, mo); |
2616 | } |
2617 | default: |
2618 | ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here( "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2618); ::breakpoint(); } while (0); |
2619 | return (StoreNode*)NULL__null; |
2620 | } |
2621 | } |
2622 | |
2623 | StoreLNode* StoreLNode::make_atomic(Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, Node* val, MemOrd mo) { |
2624 | bool require_atomic = true; |
2625 | return new StoreLNode(ctl, mem, adr, adr_type, val, mo, require_atomic); |
2626 | } |
2627 | |
2628 | StoreDNode* StoreDNode::make_atomic(Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, Node* val, MemOrd mo) { |
2629 | bool require_atomic = true; |
2630 | return new StoreDNode(ctl, mem, adr, adr_type, val, mo, require_atomic); |
2631 | } |
2632 | |
2633 | |
2634 | //--------------------------bottom_type---------------------------------------- |
2635 | const Type *StoreNode::bottom_type() const { |
2636 | return Type::MEMORY; |
2637 | } |
2638 | |
2639 | //------------------------------hash------------------------------------------- |
2640 | uint StoreNode::hash() const { |
2641 | // unroll addition of interesting fields |
2642 | //return (uintptr_t)in(Control) + (uintptr_t)in(Memory) + (uintptr_t)in(Address) + (uintptr_t)in(ValueIn); |
2643 | |
2644 | // Since they are not commoned, do not hash them: |
2645 | return NO_HASH; |
2646 | } |
2647 | |
2648 | //------------------------------Ideal------------------------------------------ |
2649 | // Change back-to-back Store(, p, x) -> Store(m, p, y) to Store(m, p, x). |
2650 | // When a store immediately follows a relevant allocation/initialization, |
2651 | // try to capture it into the initialization, or hoist it above. |
2652 | Node *StoreNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
2653 | Node* p = MemNode::Ideal_common(phase, can_reshape); |
2654 | if (p) return (p == NodeSentinel(Node*)-1) ? NULL__null : p; |
2655 | |
2656 | Node* mem = in(MemNode::Memory); |
2657 | Node* address = in(MemNode::Address); |
2658 | Node* value = in(MemNode::ValueIn); |
2659 | // Back-to-back stores to same address? Fold em up. Generally |
2660 | // unsafe if I have intervening uses... Also disallowed for StoreCM |
2661 | // since they must follow each StoreP operation. Redundant StoreCMs |
2662 | // are eliminated just before matching in final_graph_reshape. |
2663 | { |
2664 | Node* st = mem; |
2665 | // If Store 'st' has more than one use, we cannot fold 'st' away. |
2666 | // For example, 'st' might be the final state at a conditional |
2667 | // return. Or, 'st' might be used by some node which is live at |
2668 | // the same time 'st' is live, which might be unschedulable. So, |
2669 | // require exactly ONE user until such time as we clone 'mem' for |
2670 | // each of 'mem's uses (thus making the exactly-1-user-rule hold |
2671 | // true). |
2672 | while (st->is_Store() && st->outcnt() == 1 && st->Opcode() != Op_StoreCM) { |
2673 | // Looking at a dead closed cycle of memory? |
2674 | assert(st != st->in(MemNode::Memory), "dead loop in StoreNode::Ideal")do { if (!(st != st->in(MemNode::Memory))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2674, "assert(" "st != st->in(MemNode::Memory)" ") failed" , "dead loop in StoreNode::Ideal"); ::breakpoint(); } } while (0); |
2675 | assert(Opcode() == st->Opcode() ||do { if (!(Opcode() == st->Opcode() || st->Opcode() == Op_StoreVector || Opcode() == Op_StoreVector || st->Opcode() == Op_StoreVectorScatter || Opcode() == Op_StoreVectorScatter || phase->C->get_alias_index (adr_type()) == Compile::AliasIdxRaw || (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI) || (Opcode() == Op_StoreI && st->Opcode() == Op_StoreL) || (is_mismatched_access () || st->as_Store()->is_mismatched_access()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2684, "assert(" "Opcode() == st->Opcode() || st->Opcode() == Op_StoreVector || Opcode() == Op_StoreVector || st->Opcode() == Op_StoreVectorScatter || Opcode() == Op_StoreVectorScatter || phase->C->get_alias_index(adr_type()) == Compile::AliasIdxRaw || (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI) || (Opcode() == Op_StoreI && st->Opcode() == Op_StoreL) || (is_mismatched_access() || st->as_Store()->is_mismatched_access())" ") failed", "no mismatched stores, except on raw memory: %s %s" , NodeClassNames[Opcode()], NodeClassNames[st->Opcode()]); ::breakpoint(); } } while (0) |
2676 | st->Opcode() == Op_StoreVector ||do { if (!(Opcode() == st->Opcode() || st->Opcode() == Op_StoreVector || Opcode() == Op_StoreVector || st->Opcode() == Op_StoreVectorScatter || Opcode() == Op_StoreVectorScatter || phase->C->get_alias_index (adr_type()) == Compile::AliasIdxRaw || (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI) || (Opcode() == Op_StoreI && st->Opcode() == Op_StoreL) || (is_mismatched_access () || st->as_Store()->is_mismatched_access()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2684, "assert(" "Opcode() == st->Opcode() || st->Opcode() == Op_StoreVector || Opcode() == Op_StoreVector || st->Opcode() == Op_StoreVectorScatter || Opcode() == Op_StoreVectorScatter || phase->C->get_alias_index(adr_type()) == Compile::AliasIdxRaw || (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI) || (Opcode() == Op_StoreI && st->Opcode() == Op_StoreL) || (is_mismatched_access() || st->as_Store()->is_mismatched_access())" ") failed", "no mismatched stores, except on raw memory: %s %s" , NodeClassNames[Opcode()], NodeClassNames[st->Opcode()]); ::breakpoint(); } } while (0) |
2677 | Opcode() == Op_StoreVector ||do { if (!(Opcode() == st->Opcode() || st->Opcode() == Op_StoreVector || Opcode() == Op_StoreVector || st->Opcode() == Op_StoreVectorScatter || Opcode() == Op_StoreVectorScatter || phase->C->get_alias_index (adr_type()) == Compile::AliasIdxRaw || (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI) || (Opcode() == Op_StoreI && st->Opcode() == Op_StoreL) || (is_mismatched_access () || st->as_Store()->is_mismatched_access()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2684, "assert(" "Opcode() == st->Opcode() || st->Opcode() == Op_StoreVector || Opcode() == Op_StoreVector || st->Opcode() == Op_StoreVectorScatter || Opcode() == Op_StoreVectorScatter || phase->C->get_alias_index(adr_type()) == Compile::AliasIdxRaw || (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI) || (Opcode() == Op_StoreI && st->Opcode() == Op_StoreL) || (is_mismatched_access() || st->as_Store()->is_mismatched_access())" ") failed", "no mismatched stores, except on raw memory: %s %s" , NodeClassNames[Opcode()], NodeClassNames[st->Opcode()]); ::breakpoint(); } } while (0) |
2678 | st->Opcode() == Op_StoreVectorScatter ||do { if (!(Opcode() == st->Opcode() || st->Opcode() == Op_StoreVector || Opcode() == Op_StoreVector || st->Opcode() == Op_StoreVectorScatter || Opcode() == Op_StoreVectorScatter || phase->C->get_alias_index (adr_type()) == Compile::AliasIdxRaw || (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI) || (Opcode() == Op_StoreI && st->Opcode() == Op_StoreL) || (is_mismatched_access () || st->as_Store()->is_mismatched_access()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2684, "assert(" "Opcode() == st->Opcode() || st->Opcode() == Op_StoreVector || Opcode() == Op_StoreVector || st->Opcode() == Op_StoreVectorScatter || Opcode() == Op_StoreVectorScatter || phase->C->get_alias_index(adr_type()) == Compile::AliasIdxRaw || (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI) || (Opcode() == Op_StoreI && st->Opcode() == Op_StoreL) || (is_mismatched_access() || st->as_Store()->is_mismatched_access())" ") failed", "no mismatched stores, except on raw memory: %s %s" , NodeClassNames[Opcode()], NodeClassNames[st->Opcode()]); ::breakpoint(); } } while (0) |
2679 | Opcode() == Op_StoreVectorScatter ||do { if (!(Opcode() == st->Opcode() || st->Opcode() == Op_StoreVector || Opcode() == Op_StoreVector || st->Opcode() == Op_StoreVectorScatter || Opcode() == Op_StoreVectorScatter || phase->C->get_alias_index (adr_type()) == Compile::AliasIdxRaw || (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI) || (Opcode() == Op_StoreI && st->Opcode() == Op_StoreL) || (is_mismatched_access () || st->as_Store()->is_mismatched_access()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2684, "assert(" "Opcode() == st->Opcode() || st->Opcode() == Op_StoreVector || Opcode() == Op_StoreVector || st->Opcode() == Op_StoreVectorScatter || Opcode() == Op_StoreVectorScatter || phase->C->get_alias_index(adr_type()) == Compile::AliasIdxRaw || (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI) || (Opcode() == Op_StoreI && st->Opcode() == Op_StoreL) || (is_mismatched_access() || st->as_Store()->is_mismatched_access())" ") failed", "no mismatched stores, except on raw memory: %s %s" , NodeClassNames[Opcode()], NodeClassNames[st->Opcode()]); ::breakpoint(); } } while (0) |
2680 | phase->C->get_alias_index(adr_type()) == Compile::AliasIdxRaw ||do { if (!(Opcode() == st->Opcode() || st->Opcode() == Op_StoreVector || Opcode() == Op_StoreVector || st->Opcode() == Op_StoreVectorScatter || Opcode() == Op_StoreVectorScatter || phase->C->get_alias_index (adr_type()) == Compile::AliasIdxRaw || (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI) || (Opcode() == Op_StoreI && st->Opcode() == Op_StoreL) || (is_mismatched_access () || st->as_Store()->is_mismatched_access()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2684, "assert(" "Opcode() == st->Opcode() || st->Opcode() == Op_StoreVector || Opcode() == Op_StoreVector || st->Opcode() == Op_StoreVectorScatter || Opcode() == Op_StoreVectorScatter || phase->C->get_alias_index(adr_type()) == Compile::AliasIdxRaw || (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI) || (Opcode() == Op_StoreI && st->Opcode() == Op_StoreL) || (is_mismatched_access() || st->as_Store()->is_mismatched_access())" ") failed", "no mismatched stores, except on raw memory: %s %s" , NodeClassNames[Opcode()], NodeClassNames[st->Opcode()]); ::breakpoint(); } } while (0) |
2681 | (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI) || // expanded ClearArrayNodedo { if (!(Opcode() == st->Opcode() || st->Opcode() == Op_StoreVector || Opcode() == Op_StoreVector || st->Opcode() == Op_StoreVectorScatter || Opcode() == Op_StoreVectorScatter || phase->C->get_alias_index (adr_type()) == Compile::AliasIdxRaw || (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI) || (Opcode() == Op_StoreI && st->Opcode() == Op_StoreL) || (is_mismatched_access () || st->as_Store()->is_mismatched_access()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2684, "assert(" "Opcode() == st->Opcode() || st->Opcode() == Op_StoreVector || Opcode() == Op_StoreVector || st->Opcode() == Op_StoreVectorScatter || Opcode() == Op_StoreVectorScatter || phase->C->get_alias_index(adr_type()) == Compile::AliasIdxRaw || (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI) || (Opcode() == Op_StoreI && st->Opcode() == Op_StoreL) || (is_mismatched_access() || st->as_Store()->is_mismatched_access())" ") failed", "no mismatched stores, except on raw memory: %s %s" , NodeClassNames[Opcode()], NodeClassNames[st->Opcode()]); ::breakpoint(); } } while (0) |
2682 | (Opcode() == Op_StoreI && st->Opcode() == Op_StoreL) || // initialization by arraycopydo { if (!(Opcode() == st->Opcode() || st->Opcode() == Op_StoreVector || Opcode() == Op_StoreVector || st->Opcode() == Op_StoreVectorScatter || Opcode() == Op_StoreVectorScatter || phase->C->get_alias_index (adr_type()) == Compile::AliasIdxRaw || (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI) || (Opcode() == Op_StoreI && st->Opcode() == Op_StoreL) || (is_mismatched_access () || st->as_Store()->is_mismatched_access()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2684, "assert(" "Opcode() == st->Opcode() || st->Opcode() == Op_StoreVector || Opcode() == Op_StoreVector || st->Opcode() == Op_StoreVectorScatter || Opcode() == Op_StoreVectorScatter || phase->C->get_alias_index(adr_type()) == Compile::AliasIdxRaw || (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI) || (Opcode() == Op_StoreI && st->Opcode() == Op_StoreL) || (is_mismatched_access() || st->as_Store()->is_mismatched_access())" ") failed", "no mismatched stores, except on raw memory: %s %s" , NodeClassNames[Opcode()], NodeClassNames[st->Opcode()]); ::breakpoint(); } } while (0) |
2683 | (is_mismatched_access() || st->as_Store()->is_mismatched_access()),do { if (!(Opcode() == st->Opcode() || st->Opcode() == Op_StoreVector || Opcode() == Op_StoreVector || st->Opcode() == Op_StoreVectorScatter || Opcode() == Op_StoreVectorScatter || phase->C->get_alias_index (adr_type()) == Compile::AliasIdxRaw || (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI) || (Opcode() == Op_StoreI && st->Opcode() == Op_StoreL) || (is_mismatched_access () || st->as_Store()->is_mismatched_access()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2684, "assert(" "Opcode() == st->Opcode() || st->Opcode() == Op_StoreVector || Opcode() == Op_StoreVector || st->Opcode() == Op_StoreVectorScatter || Opcode() == Op_StoreVectorScatter || phase->C->get_alias_index(adr_type()) == Compile::AliasIdxRaw || (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI) || (Opcode() == Op_StoreI && st->Opcode() == Op_StoreL) || (is_mismatched_access() || st->as_Store()->is_mismatched_access())" ") failed", "no mismatched stores, except on raw memory: %s %s" , NodeClassNames[Opcode()], NodeClassNames[st->Opcode()]); ::breakpoint(); } } while (0) |
2684 | "no mismatched stores, except on raw memory: %s %s", NodeClassNames[Opcode()], NodeClassNames[st->Opcode()])do { if (!(Opcode() == st->Opcode() || st->Opcode() == Op_StoreVector || Opcode() == Op_StoreVector || st->Opcode() == Op_StoreVectorScatter || Opcode() == Op_StoreVectorScatter || phase->C->get_alias_index (adr_type()) == Compile::AliasIdxRaw || (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI) || (Opcode() == Op_StoreI && st->Opcode() == Op_StoreL) || (is_mismatched_access () || st->as_Store()->is_mismatched_access()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2684, "assert(" "Opcode() == st->Opcode() || st->Opcode() == Op_StoreVector || Opcode() == Op_StoreVector || st->Opcode() == Op_StoreVectorScatter || Opcode() == Op_StoreVectorScatter || phase->C->get_alias_index(adr_type()) == Compile::AliasIdxRaw || (Opcode() == Op_StoreL && st->Opcode() == Op_StoreI) || (Opcode() == Op_StoreI && st->Opcode() == Op_StoreL) || (is_mismatched_access() || st->as_Store()->is_mismatched_access())" ") failed", "no mismatched stores, except on raw memory: %s %s" , NodeClassNames[Opcode()], NodeClassNames[st->Opcode()]); ::breakpoint(); } } while (0); |
2685 | |
2686 | if (st->in(MemNode::Address)->eqv_uncast(address) && |
2687 | st->as_Store()->memory_size() <= this->memory_size()) { |
2688 | Node* use = st->raw_out(0); |
2689 | if (phase->is_IterGVN()) { |
2690 | phase->is_IterGVN()->rehash_node_delayed(use); |
2691 | } |
2692 | // It's OK to do this in the parser, since DU info is always accurate, |
2693 | // and the parser always refers to nodes via SafePointNode maps. |
2694 | use->set_req_X(MemNode::Memory, st->in(MemNode::Memory), phase); |
2695 | return this; |
2696 | } |
2697 | st = st->in(MemNode::Memory); |
2698 | } |
2699 | } |
2700 | |
2701 | |
2702 | // Capture an unaliased, unconditional, simple store into an initializer. |
2703 | // Or, if it is independent of the allocation, hoist it above the allocation. |
2704 | if (ReduceFieldZeroing && /*can_reshape &&*/ |
2705 | mem->is_Proj() && mem->in(0)->is_Initialize()) { |
2706 | InitializeNode* init = mem->in(0)->as_Initialize(); |
2707 | intptr_t offset = init->can_capture_store(this, phase, can_reshape); |
2708 | if (offset > 0) { |
2709 | Node* moved = init->capture_store(this, offset, phase, can_reshape); |
2710 | // If the InitializeNode captured me, it made a raw copy of me, |
2711 | // and I need to disappear. |
2712 | if (moved != NULL__null) { |
2713 | // %%% hack to ensure that Ideal returns a new node: |
2714 | mem = MergeMemNode::make(mem); |
2715 | return mem; // fold me away |
2716 | } |
2717 | } |
2718 | } |
2719 | |
2720 | // Fold reinterpret cast into memory operation: |
2721 | // StoreX mem (MoveY2X v) => StoreY mem v |
2722 | if (value->is_Move()) { |
2723 | const Type* vt = value->in(1)->bottom_type(); |
2724 | if (has_reinterpret_variant(vt)) { |
2725 | if (phase->C->post_loop_opts_phase()) { |
2726 | return convert_to_reinterpret_store(*phase, value->in(1), vt); |
2727 | } else { |
2728 | phase->C->record_for_post_loop_opts_igvn(this); // attempt the transformation once loop opts are over |
2729 | } |
2730 | } |
2731 | } |
2732 | |
2733 | return NULL__null; // No further progress |
2734 | } |
2735 | |
2736 | //------------------------------Value----------------------------------------- |
2737 | const Type* StoreNode::Value(PhaseGVN* phase) const { |
2738 | // Either input is TOP ==> the result is TOP |
2739 | const Type *t1 = phase->type( in(MemNode::Memory) ); |
2740 | if( t1 == Type::TOP ) return Type::TOP; |
2741 | const Type *t2 = phase->type( in(MemNode::Address) ); |
2742 | if( t2 == Type::TOP ) return Type::TOP; |
2743 | const Type *t3 = phase->type( in(MemNode::ValueIn) ); |
2744 | if( t3 == Type::TOP ) return Type::TOP; |
2745 | return Type::MEMORY; |
2746 | } |
2747 | |
2748 | //------------------------------Identity--------------------------------------- |
2749 | // Remove redundant stores: |
2750 | // Store(m, p, Load(m, p)) changes to m. |
2751 | // Store(, p, x) -> Store(m, p, x) changes to Store(m, p, x). |
2752 | Node* StoreNode::Identity(PhaseGVN* phase) { |
2753 | Node* mem = in(MemNode::Memory); |
2754 | Node* adr = in(MemNode::Address); |
2755 | Node* val = in(MemNode::ValueIn); |
2756 | |
2757 | Node* result = this; |
2758 | |
2759 | // Load then Store? Then the Store is useless |
2760 | if (val->is_Load() && |
2761 | val->in(MemNode::Address)->eqv_uncast(adr) && |
2762 | val->in(MemNode::Memory )->eqv_uncast(mem) && |
2763 | val->as_Load()->store_Opcode() == Opcode()) { |
2764 | result = mem; |
2765 | } |
2766 | |
2767 | // Two stores in a row of the same value? |
2768 | if (result == this && |
2769 | mem->is_Store() && |
2770 | mem->in(MemNode::Address)->eqv_uncast(adr) && |
2771 | mem->in(MemNode::ValueIn)->eqv_uncast(val) && |
2772 | mem->Opcode() == Opcode()) { |
2773 | result = mem; |
2774 | } |
2775 | |
2776 | // Store of zero anywhere into a freshly-allocated object? |
2777 | // Then the store is useless. |
2778 | // (It must already have been captured by the InitializeNode.) |
2779 | if (result == this && |
2780 | ReduceFieldZeroing && phase->type(val)->is_zero_type()) { |
2781 | // a newly allocated object is already all-zeroes everywhere |
2782 | if (mem->is_Proj() && mem->in(0)->is_Allocate()) { |
2783 | result = mem; |
2784 | } |
2785 | |
2786 | if (result == this) { |
2787 | // the store may also apply to zero-bits in an earlier object |
2788 | Node* prev_mem = find_previous_store(phase); |
2789 | // Steps (a), (b): Walk past independent stores to find an exact match. |
2790 | if (prev_mem != NULL__null) { |
2791 | Node* prev_val = can_see_stored_value(prev_mem, phase); |
2792 | if (prev_val != NULL__null && prev_val == val) { |
2793 | // prev_val and val might differ by a cast; it would be good |
2794 | // to keep the more informative of the two. |
2795 | result = mem; |
2796 | } |
2797 | } |
2798 | } |
2799 | } |
2800 | |
2801 | PhaseIterGVN* igvn = phase->is_IterGVN(); |
2802 | if (result != this && igvn != NULL__null) { |
2803 | MemBarNode* trailing = trailing_membar(); |
2804 | if (trailing != NULL__null) { |
2805 | #ifdef ASSERT1 |
2806 | const TypeOopPtr* t_oop = phase->type(in(Address))->isa_oopptr(); |
2807 | assert(t_oop == NULL || t_oop->is_known_instance_field(), "only for non escaping objects")do { if (!(t_oop == __null || t_oop->is_known_instance_field ())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2807, "assert(" "t_oop == __null || t_oop->is_known_instance_field()" ") failed", "only for non escaping objects"); ::breakpoint() ; } } while (0); |
2808 | #endif |
2809 | trailing->remove(igvn); |
2810 | } |
2811 | } |
2812 | |
2813 | return result; |
2814 | } |
2815 | |
2816 | //------------------------------match_edge------------------------------------- |
2817 | // Do we Match on this edge index or not? Match only memory & value |
2818 | uint StoreNode::match_edge(uint idx) const { |
2819 | return idx == MemNode::Address || idx == MemNode::ValueIn; |
2820 | } |
2821 | |
2822 | //------------------------------cmp-------------------------------------------- |
2823 | // Do not common stores up together. They generally have to be split |
2824 | // back up anyways, so do not bother. |
2825 | bool StoreNode::cmp( const Node &n ) const { |
2826 | return (&n == this); // Always fail except on self |
2827 | } |
2828 | |
2829 | //------------------------------Ideal_masked_input----------------------------- |
2830 | // Check for a useless mask before a partial-word store |
2831 | // (StoreB ... (AndI valIn conIa) ) |
2832 | // If (conIa & mask == mask) this simplifies to |
2833 | // (StoreB ... (valIn) ) |
2834 | Node *StoreNode::Ideal_masked_input(PhaseGVN *phase, uint mask) { |
2835 | Node *val = in(MemNode::ValueIn); |
2836 | if( val->Opcode() == Op_AndI ) { |
2837 | const TypeInt *t = phase->type( val->in(2) )->isa_int(); |
2838 | if( t && t->is_con() && (t->get_con() & mask) == mask ) { |
2839 | set_req_X(MemNode::ValueIn, val->in(1), phase); |
2840 | return this; |
2841 | } |
2842 | } |
2843 | return NULL__null; |
2844 | } |
2845 | |
2846 | |
2847 | //------------------------------Ideal_sign_extended_input---------------------- |
2848 | // Check for useless sign-extension before a partial-word store |
2849 | // (StoreB ... (RShiftI _ (LShiftI _ valIn conIL ) conIR) ) |
2850 | // If (conIL == conIR && conIR <= num_bits) this simplifies to |
2851 | // (StoreB ... (valIn) ) |
2852 | Node *StoreNode::Ideal_sign_extended_input(PhaseGVN *phase, int num_bits) { |
2853 | Node *val = in(MemNode::ValueIn); |
2854 | if( val->Opcode() == Op_RShiftI ) { |
2855 | const TypeInt *t = phase->type( val->in(2) )->isa_int(); |
2856 | if( t && t->is_con() && (t->get_con() <= num_bits) ) { |
2857 | Node *shl = val->in(1); |
2858 | if( shl->Opcode() == Op_LShiftI ) { |
2859 | const TypeInt *t2 = phase->type( shl->in(2) )->isa_int(); |
2860 | if( t2 && t2->is_con() && (t2->get_con() == t->get_con()) ) { |
2861 | set_req_X(MemNode::ValueIn, shl->in(1), phase); |
2862 | return this; |
2863 | } |
2864 | } |
2865 | } |
2866 | } |
2867 | return NULL__null; |
2868 | } |
2869 | |
2870 | //------------------------------value_never_loaded----------------------------------- |
2871 | // Determine whether there are any possible loads of the value stored. |
2872 | // For simplicity, we actually check if there are any loads from the |
2873 | // address stored to, not just for loads of the value stored by this node. |
2874 | // |
2875 | bool StoreNode::value_never_loaded( PhaseTransform *phase) const { |
2876 | Node *adr = in(Address); |
2877 | const TypeOopPtr *adr_oop = phase->type(adr)->isa_oopptr(); |
2878 | if (adr_oop == NULL__null) |
2879 | return false; |
2880 | if (!adr_oop->is_known_instance_field()) |
2881 | return false; // if not a distinct instance, there may be aliases of the address |
2882 | for (DUIterator_Fast imax, i = adr->fast_outs(imax); i < imax; i++) { |
2883 | Node *use = adr->fast_out(i); |
2884 | if (use->is_Load() || use->is_LoadStore()) { |
2885 | return false; |
2886 | } |
2887 | } |
2888 | return true; |
2889 | } |
2890 | |
2891 | MemBarNode* StoreNode::trailing_membar() const { |
2892 | if (is_release()) { |
2893 | MemBarNode* trailing_mb = NULL__null; |
2894 | for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) { |
2895 | Node* u = fast_out(i); |
2896 | if (u->is_MemBar()) { |
2897 | if (u->as_MemBar()->trailing_store()) { |
2898 | assert(u->Opcode() == Op_MemBarVolatile, "")do { if (!(u->Opcode() == Op_MemBarVolatile)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2898, "assert(" "u->Opcode() == Op_MemBarVolatile" ") failed" , ""); ::breakpoint(); } } while (0); |
2899 | assert(trailing_mb == NULL, "only one")do { if (!(trailing_mb == __null)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2899, "assert(" "trailing_mb == __null" ") failed", "only one" ); ::breakpoint(); } } while (0); |
2900 | trailing_mb = u->as_MemBar(); |
2901 | #ifdef ASSERT1 |
2902 | Node* leading = u->as_MemBar()->leading_membar(); |
2903 | assert(leading->Opcode() == Op_MemBarRelease, "incorrect membar")do { if (!(leading->Opcode() == Op_MemBarRelease)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2903, "assert(" "leading->Opcode() == Op_MemBarRelease" ") failed" , "incorrect membar"); ::breakpoint(); } } while (0); |
2904 | assert(leading->as_MemBar()->leading_store(), "incorrect membar pair")do { if (!(leading->as_MemBar()->leading_store())) { (* g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2904, "assert(" "leading->as_MemBar()->leading_store()" ") failed", "incorrect membar pair"); ::breakpoint(); } } while (0); |
2905 | assert(leading->as_MemBar()->trailing_membar() == u, "incorrect membar pair")do { if (!(leading->as_MemBar()->trailing_membar() == u )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2905, "assert(" "leading->as_MemBar()->trailing_membar() == u" ") failed", "incorrect membar pair"); ::breakpoint(); } } while (0); |
2906 | #endif |
2907 | } else { |
2908 | assert(u->as_MemBar()->standalone(), "")do { if (!(u->as_MemBar()->standalone())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 2908, "assert(" "u->as_MemBar()->standalone()" ") failed" , ""); ::breakpoint(); } } while (0); |
2909 | } |
2910 | } |
2911 | } |
2912 | return trailing_mb; |
2913 | } |
2914 | return NULL__null; |
2915 | } |
2916 | |
2917 | |
2918 | //============================================================================= |
2919 | //------------------------------Ideal------------------------------------------ |
2920 | // If the store is from an AND mask that leaves the low bits untouched, then |
2921 | // we can skip the AND operation. If the store is from a sign-extension |
2922 | // (a left shift, then right shift) we can skip both. |
2923 | Node *StoreBNode::Ideal(PhaseGVN *phase, bool can_reshape){ |
2924 | Node *progress = StoreNode::Ideal_masked_input(phase, 0xFF); |
2925 | if( progress != NULL__null ) return progress; |
2926 | |
2927 | progress = StoreNode::Ideal_sign_extended_input(phase, 24); |
2928 | if( progress != NULL__null ) return progress; |
2929 | |
2930 | // Finally check the default case |
2931 | return StoreNode::Ideal(phase, can_reshape); |
2932 | } |
2933 | |
2934 | //============================================================================= |
2935 | //------------------------------Ideal------------------------------------------ |
2936 | // If the store is from an AND mask that leaves the low bits untouched, then |
2937 | // we can skip the AND operation |
2938 | Node *StoreCNode::Ideal(PhaseGVN *phase, bool can_reshape){ |
2939 | Node *progress = StoreNode::Ideal_masked_input(phase, 0xFFFF); |
2940 | if( progress != NULL__null ) return progress; |
2941 | |
2942 | progress = StoreNode::Ideal_sign_extended_input(phase, 16); |
2943 | if( progress != NULL__null ) return progress; |
2944 | |
2945 | // Finally check the default case |
2946 | return StoreNode::Ideal(phase, can_reshape); |
2947 | } |
2948 | |
2949 | //============================================================================= |
2950 | //------------------------------Identity--------------------------------------- |
2951 | Node* StoreCMNode::Identity(PhaseGVN* phase) { |
2952 | // No need to card mark when storing a null ptr |
2953 | Node* my_store = in(MemNode::OopStore); |
2954 | if (my_store->is_Store()) { |
2955 | const Type *t1 = phase->type( my_store->in(MemNode::ValueIn) ); |
2956 | if( t1 == TypePtr::NULL_PTR ) { |
2957 | return in(MemNode::Memory); |
2958 | } |
2959 | } |
2960 | return this; |
2961 | } |
2962 | |
2963 | //============================================================================= |
2964 | //------------------------------Ideal--------------------------------------- |
2965 | Node *StoreCMNode::Ideal(PhaseGVN *phase, bool can_reshape){ |
2966 | Node* progress = StoreNode::Ideal(phase, can_reshape); |
2967 | if (progress != NULL__null) return progress; |
2968 | |
2969 | Node* my_store = in(MemNode::OopStore); |
2970 | if (my_store->is_MergeMem()) { |
2971 | Node* mem = my_store->as_MergeMem()->memory_at(oop_alias_idx()); |
2972 | set_req_X(MemNode::OopStore, mem, phase); |
2973 | return this; |
2974 | } |
2975 | |
2976 | return NULL__null; |
2977 | } |
2978 | |
2979 | //------------------------------Value----------------------------------------- |
2980 | const Type* StoreCMNode::Value(PhaseGVN* phase) const { |
2981 | // Either input is TOP ==> the result is TOP (checked in StoreNode::Value). |
2982 | // If extra input is TOP ==> the result is TOP |
2983 | const Type* t = phase->type(in(MemNode::OopStore)); |
2984 | if (t == Type::TOP) { |
2985 | return Type::TOP; |
2986 | } |
2987 | return StoreNode::Value(phase); |
2988 | } |
2989 | |
2990 | |
2991 | //============================================================================= |
2992 | //----------------------------------SCMemProjNode------------------------------ |
2993 | const Type* SCMemProjNode::Value(PhaseGVN* phase) const |
2994 | { |
2995 | if (in(0) == NULL__null || phase->type(in(0)) == Type::TOP) { |
2996 | return Type::TOP; |
2997 | } |
2998 | return bottom_type(); |
2999 | } |
3000 | |
3001 | //============================================================================= |
3002 | //----------------------------------LoadStoreNode------------------------------ |
3003 | LoadStoreNode::LoadStoreNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at, const Type* rt, uint required ) |
3004 | : Node(required), |
3005 | _type(rt), |
3006 | _adr_type(at), |
3007 | _barrier_data(0) |
3008 | { |
3009 | init_req(MemNode::Control, c ); |
3010 | init_req(MemNode::Memory , mem); |
3011 | init_req(MemNode::Address, adr); |
3012 | init_req(MemNode::ValueIn, val); |
3013 | init_class_id(Class_LoadStore); |
3014 | } |
3015 | |
3016 | //------------------------------Value----------------------------------------- |
3017 | const Type* LoadStoreNode::Value(PhaseGVN* phase) const { |
3018 | // Either input is TOP ==> the result is TOP |
3019 | if (!in(MemNode::Control) || phase->type(in(MemNode::Control)) == Type::TOP) { |
3020 | return Type::TOP; |
3021 | } |
3022 | const Type* t = phase->type(in(MemNode::Memory)); |
3023 | if (t == Type::TOP) { |
3024 | return Type::TOP; |
3025 | } |
3026 | t = phase->type(in(MemNode::Address)); |
3027 | if (t == Type::TOP) { |
3028 | return Type::TOP; |
3029 | } |
3030 | t = phase->type(in(MemNode::ValueIn)); |
3031 | if (t == Type::TOP) { |
3032 | return Type::TOP; |
3033 | } |
3034 | return bottom_type(); |
3035 | } |
3036 | |
3037 | uint LoadStoreNode::ideal_reg() const { |
3038 | return _type->ideal_reg(); |
3039 | } |
3040 | |
3041 | bool LoadStoreNode::result_not_used() const { |
3042 | for( DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++ ) { |
3043 | Node *x = fast_out(i); |
3044 | if (x->Opcode() == Op_SCMemProj) continue; |
3045 | return false; |
3046 | } |
3047 | return true; |
3048 | } |
3049 | |
3050 | MemBarNode* LoadStoreNode::trailing_membar() const { |
3051 | MemBarNode* trailing = NULL__null; |
3052 | for (DUIterator_Fast imax, i = fast_outs(imax); i < imax; i++) { |
3053 | Node* u = fast_out(i); |
3054 | if (u->is_MemBar()) { |
3055 | if (u->as_MemBar()->trailing_load_store()) { |
3056 | assert(u->Opcode() == Op_MemBarAcquire, "")do { if (!(u->Opcode() == Op_MemBarAcquire)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3056, "assert(" "u->Opcode() == Op_MemBarAcquire" ") failed" , ""); ::breakpoint(); } } while (0); |
3057 | assert(trailing == NULL, "only one")do { if (!(trailing == __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3057, "assert(" "trailing == __null" ") failed", "only one" ); ::breakpoint(); } } while (0); |
3058 | trailing = u->as_MemBar(); |
3059 | #ifdef ASSERT1 |
3060 | Node* leading = trailing->leading_membar(); |
3061 | assert(support_IRIW_for_not_multiple_copy_atomic_cpu || leading->Opcode() == Op_MemBarRelease, "incorrect membar")do { if (!(support_IRIW_for_not_multiple_copy_atomic_cpu || leading ->Opcode() == Op_MemBarRelease)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3061, "assert(" "support_IRIW_for_not_multiple_copy_atomic_cpu || leading->Opcode() == Op_MemBarRelease" ") failed", "incorrect membar"); ::breakpoint(); } } while ( 0); |
3062 | assert(leading->as_MemBar()->leading_load_store(), "incorrect membar pair")do { if (!(leading->as_MemBar()->leading_load_store())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3062, "assert(" "leading->as_MemBar()->leading_load_store()" ") failed", "incorrect membar pair"); ::breakpoint(); } } while (0); |
3063 | assert(leading->as_MemBar()->trailing_membar() == trailing, "incorrect membar pair")do { if (!(leading->as_MemBar()->trailing_membar() == trailing )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3063, "assert(" "leading->as_MemBar()->trailing_membar() == trailing" ") failed", "incorrect membar pair"); ::breakpoint(); } } while (0); |
3064 | #endif |
3065 | } else { |
3066 | assert(u->as_MemBar()->standalone(), "wrong barrier kind")do { if (!(u->as_MemBar()->standalone())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3066, "assert(" "u->as_MemBar()->standalone()" ") failed" , "wrong barrier kind"); ::breakpoint(); } } while (0); |
3067 | } |
3068 | } |
3069 | } |
3070 | |
3071 | return trailing; |
3072 | } |
3073 | |
3074 | uint LoadStoreNode::size_of() const { return sizeof(*this); } |
3075 | |
3076 | //============================================================================= |
3077 | //----------------------------------LoadStoreConditionalNode-------------------- |
3078 | LoadStoreConditionalNode::LoadStoreConditionalNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex ) : LoadStoreNode(c, mem, adr, val, NULL__null, TypeInt::BOOL, 5) { |
3079 | init_req(ExpectedIn, ex ); |
3080 | } |
3081 | |
3082 | const Type* LoadStoreConditionalNode::Value(PhaseGVN* phase) const { |
3083 | // Either input is TOP ==> the result is TOP |
3084 | const Type* t = phase->type(in(ExpectedIn)); |
3085 | if (t == Type::TOP) { |
3086 | return Type::TOP; |
3087 | } |
3088 | return LoadStoreNode::Value(phase); |
3089 | } |
3090 | |
3091 | //============================================================================= |
3092 | //-------------------------------adr_type-------------------------------------- |
3093 | const TypePtr* ClearArrayNode::adr_type() const { |
3094 | Node *adr = in(3); |
3095 | if (adr == NULL__null) return NULL__null; // node is dead |
3096 | return MemNode::calculate_adr_type(adr->bottom_type()); |
3097 | } |
3098 | |
3099 | //------------------------------match_edge------------------------------------- |
3100 | // Do we Match on this edge index or not? Do not match memory |
3101 | uint ClearArrayNode::match_edge(uint idx) const { |
3102 | return idx > 1; |
3103 | } |
3104 | |
3105 | //------------------------------Identity--------------------------------------- |
3106 | // Clearing a zero length array does nothing |
3107 | Node* ClearArrayNode::Identity(PhaseGVN* phase) { |
3108 | return phase->type(in(2))->higher_equal(TypeXTypeLong::ZERO) ? in(1) : this; |
3109 | } |
3110 | |
3111 | //------------------------------Idealize--------------------------------------- |
3112 | // Clearing a short array is faster with stores |
3113 | Node *ClearArrayNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
3114 | // Already know this is a large node, do not try to ideal it |
3115 | if (!IdealizeClearArrayNode || _is_large) return NULL__null; |
3116 | |
3117 | const int unit = BytesPerLong; |
3118 | const TypeXTypeLong* t = phase->type(in(2))->isa_intptr_tisa_long(); |
3119 | if (!t) return NULL__null; |
3120 | if (!t->is_con()) return NULL__null; |
3121 | intptr_t raw_count = t->get_con(); |
3122 | intptr_t size = raw_count; |
3123 | if (!Matcher::init_array_count_is_in_bytes) size *= unit; |
3124 | // Clearing nothing uses the Identity call. |
3125 | // Negative clears are possible on dead ClearArrays |
3126 | // (see jck test stmt114.stmt11402.val). |
3127 | if (size <= 0 || size % unit != 0) return NULL__null; |
3128 | intptr_t count = size / unit; |
3129 | // Length too long; communicate this to matchers and assemblers. |
3130 | // Assemblers are responsible to produce fast hardware clears for it. |
3131 | if (size > InitArrayShortSize) { |
3132 | return new ClearArrayNode(in(0), in(1), in(2), in(3), true); |
3133 | } else if (size > 2 && Matcher::match_rule_supported_vector(Op_ClearArray, 4, T_LONG)) { |
3134 | return NULL__null; |
3135 | } |
3136 | Node *mem = in(1); |
3137 | if( phase->type(mem)==Type::TOP ) return NULL__null; |
3138 | Node *adr = in(3); |
3139 | const Type* at = phase->type(adr); |
3140 | if( at==Type::TOP ) return NULL__null; |
3141 | const TypePtr* atp = at->isa_ptr(); |
3142 | // adjust atp to be the correct array element address type |
3143 | if (atp == NULL__null) atp = TypePtr::BOTTOM; |
3144 | else atp = atp->add_offset(Type::OffsetBot); |
3145 | // Get base for derived pointer purposes |
3146 | if( adr->Opcode() != Op_AddP ) Unimplemented()do { (*g_assert_poison) = 'X';; report_unimplemented("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3146); ::breakpoint(); } while (0); |
3147 | Node *base = adr->in(1); |
3148 | |
3149 | Node *zero = phase->makecon(TypeLong::ZERO); |
3150 | Node *off = phase->MakeConXlongcon(BytesPerLong); |
3151 | mem = new StoreLNode(in(0),mem,adr,atp,zero,MemNode::unordered,false); |
3152 | count--; |
3153 | while( count-- ) { |
3154 | mem = phase->transform(mem); |
3155 | adr = phase->transform(new AddPNode(base,adr,off)); |
3156 | mem = new StoreLNode(in(0),mem,adr,atp,zero,MemNode::unordered,false); |
3157 | } |
3158 | return mem; |
3159 | } |
3160 | |
3161 | //----------------------------step_through---------------------------------- |
3162 | // Return allocation input memory edge if it is different instance |
3163 | // or itself if it is the one we are looking for. |
3164 | bool ClearArrayNode::step_through(Node** np, uint instance_id, PhaseTransform* phase) { |
3165 | Node* n = *np; |
3166 | assert(n->is_ClearArray(), "sanity")do { if (!(n->is_ClearArray())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3166, "assert(" "n->is_ClearArray()" ") failed", "sanity" ); ::breakpoint(); } } while (0); |
3167 | intptr_t offset; |
3168 | AllocateNode* alloc = AllocateNode::Ideal_allocation(n->in(3), phase, offset); |
3169 | // This method is called only before Allocate nodes are expanded |
3170 | // during macro nodes expansion. Before that ClearArray nodes are |
3171 | // only generated in PhaseMacroExpand::generate_arraycopy() (before |
3172 | // Allocate nodes are expanded) which follows allocations. |
3173 | assert(alloc != NULL, "should have allocation")do { if (!(alloc != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3173, "assert(" "alloc != __null" ") failed", "should have allocation" ); ::breakpoint(); } } while (0); |
3174 | if (alloc->_idx == instance_id) { |
3175 | // Can not bypass initialization of the instance we are looking for. |
3176 | return false; |
3177 | } |
3178 | // Otherwise skip it. |
3179 | InitializeNode* init = alloc->initialization(); |
3180 | if (init != NULL__null) |
3181 | *np = init->in(TypeFunc::Memory); |
3182 | else |
3183 | *np = alloc->in(TypeFunc::Memory); |
3184 | return true; |
3185 | } |
3186 | |
3187 | //----------------------------clear_memory------------------------------------- |
3188 | // Generate code to initialize object storage to zero. |
3189 | Node* ClearArrayNode::clear_memory(Node* ctl, Node* mem, Node* dest, |
3190 | intptr_t start_offset, |
3191 | Node* end_offset, |
3192 | PhaseGVN* phase) { |
3193 | intptr_t offset = start_offset; |
3194 | |
3195 | int unit = BytesPerLong; |
3196 | if ((offset % unit) != 0) { |
3197 | Node* adr = new AddPNode(dest, dest, phase->MakeConXlongcon(offset)); |
3198 | adr = phase->transform(adr); |
3199 | const TypePtr* atp = TypeRawPtr::BOTTOM; |
3200 | mem = StoreNode::make(*phase, ctl, mem, adr, atp, phase->zerocon(T_INT), T_INT, MemNode::unordered); |
3201 | mem = phase->transform(mem); |
3202 | offset += BytesPerInt; |
3203 | } |
3204 | assert((offset % unit) == 0, "")do { if (!((offset % unit) == 0)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3204, "assert(" "(offset % unit) == 0" ") failed", ""); ::breakpoint (); } } while (0); |
3205 | |
3206 | // Initialize the remaining stuff, if any, with a ClearArray. |
3207 | return clear_memory(ctl, mem, dest, phase->MakeConXlongcon(offset), end_offset, phase); |
3208 | } |
3209 | |
3210 | Node* ClearArrayNode::clear_memory(Node* ctl, Node* mem, Node* dest, |
3211 | Node* start_offset, |
3212 | Node* end_offset, |
3213 | PhaseGVN* phase) { |
3214 | if (start_offset == end_offset) { |
3215 | // nothing to do |
3216 | return mem; |
3217 | } |
3218 | |
3219 | int unit = BytesPerLong; |
3220 | Node* zbase = start_offset; |
3221 | Node* zend = end_offset; |
3222 | |
3223 | // Scale to the unit required by the CPU: |
3224 | if (!Matcher::init_array_count_is_in_bytes) { |
3225 | Node* shift = phase->intcon(exact_log2(unit)); |
3226 | zbase = phase->transform(new URShiftXNodeURShiftLNode(zbase, shift) ); |
3227 | zend = phase->transform(new URShiftXNodeURShiftLNode(zend, shift) ); |
3228 | } |
3229 | |
3230 | // Bulk clear double-words |
3231 | Node* zsize = phase->transform(new SubXNodeSubLNode(zend, zbase) ); |
3232 | Node* adr = phase->transform(new AddPNode(dest, dest, start_offset) ); |
3233 | mem = new ClearArrayNode(ctl, mem, zsize, adr, false); |
3234 | return phase->transform(mem); |
3235 | } |
3236 | |
3237 | Node* ClearArrayNode::clear_memory(Node* ctl, Node* mem, Node* dest, |
3238 | intptr_t start_offset, |
3239 | intptr_t end_offset, |
3240 | PhaseGVN* phase) { |
3241 | if (start_offset == end_offset) { |
3242 | // nothing to do |
3243 | return mem; |
3244 | } |
3245 | |
3246 | assert((end_offset % BytesPerInt) == 0, "odd end offset")do { if (!((end_offset % BytesPerInt) == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3246, "assert(" "(end_offset % BytesPerInt) == 0" ") failed" , "odd end offset"); ::breakpoint(); } } while (0); |
3247 | intptr_t done_offset = end_offset; |
3248 | if ((done_offset % BytesPerLong) != 0) { |
3249 | done_offset -= BytesPerInt; |
3250 | } |
3251 | if (done_offset > start_offset) { |
3252 | mem = clear_memory(ctl, mem, dest, |
3253 | start_offset, phase->MakeConXlongcon(done_offset), phase); |
3254 | } |
3255 | if (done_offset < end_offset) { // emit the final 32-bit store |
3256 | Node* adr = new AddPNode(dest, dest, phase->MakeConXlongcon(done_offset)); |
3257 | adr = phase->transform(adr); |
3258 | const TypePtr* atp = TypeRawPtr::BOTTOM; |
3259 | mem = StoreNode::make(*phase, ctl, mem, adr, atp, phase->zerocon(T_INT), T_INT, MemNode::unordered); |
3260 | mem = phase->transform(mem); |
3261 | done_offset += BytesPerInt; |
3262 | } |
3263 | assert(done_offset == end_offset, "")do { if (!(done_offset == end_offset)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3263, "assert(" "done_offset == end_offset" ") failed", "") ; ::breakpoint(); } } while (0); |
3264 | return mem; |
3265 | } |
3266 | |
3267 | //============================================================================= |
3268 | MemBarNode::MemBarNode(Compile* C, int alias_idx, Node* precedent) |
3269 | : MultiNode(TypeFunc::Parms + (precedent == NULL__null? 0: 1)), |
3270 | _adr_type(C->get_adr_type(alias_idx)), _kind(Standalone) |
3271 | #ifdef ASSERT1 |
3272 | , _pair_idx(0) |
3273 | #endif |
3274 | { |
3275 | init_class_id(Class_MemBar); |
3276 | Node* top = C->top(); |
3277 | init_req(TypeFunc::I_O,top); |
3278 | init_req(TypeFunc::FramePtr,top); |
3279 | init_req(TypeFunc::ReturnAdr,top); |
3280 | if (precedent != NULL__null) |
3281 | init_req(TypeFunc::Parms, precedent); |
3282 | } |
3283 | |
3284 | //------------------------------cmp-------------------------------------------- |
3285 | uint MemBarNode::hash() const { return NO_HASH; } |
3286 | bool MemBarNode::cmp( const Node &n ) const { |
3287 | return (&n == this); // Always fail except on self |
3288 | } |
3289 | |
3290 | //------------------------------make------------------------------------------- |
3291 | MemBarNode* MemBarNode::make(Compile* C, int opcode, int atp, Node* pn) { |
3292 | switch (opcode) { |
3293 | case Op_MemBarAcquire: return new MemBarAcquireNode(C, atp, pn); |
3294 | case Op_LoadFence: return new LoadFenceNode(C, atp, pn); |
3295 | case Op_MemBarRelease: return new MemBarReleaseNode(C, atp, pn); |
3296 | case Op_StoreFence: return new StoreFenceNode(C, atp, pn); |
3297 | case Op_MemBarStoreStore: return new MemBarStoreStoreNode(C, atp, pn); |
3298 | case Op_StoreStoreFence: return new StoreStoreFenceNode(C, atp, pn); |
3299 | case Op_MemBarAcquireLock: return new MemBarAcquireLockNode(C, atp, pn); |
3300 | case Op_MemBarReleaseLock: return new MemBarReleaseLockNode(C, atp, pn); |
3301 | case Op_MemBarVolatile: return new MemBarVolatileNode(C, atp, pn); |
3302 | case Op_MemBarCPUOrder: return new MemBarCPUOrderNode(C, atp, pn); |
3303 | case Op_OnSpinWait: return new OnSpinWaitNode(C, atp, pn); |
3304 | case Op_Initialize: return new InitializeNode(C, atp, pn); |
3305 | case Op_Blackhole: return new BlackholeNode(C, atp, pn); |
3306 | default: ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here( "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3306); ::breakpoint(); } while (0); return NULL__null; |
3307 | } |
3308 | } |
3309 | |
3310 | void MemBarNode::remove(PhaseIterGVN *igvn) { |
3311 | if (outcnt() != 2) { |
3312 | assert(Opcode() == Op_Initialize, "Only seen when there are no use of init memory")do { if (!(Opcode() == Op_Initialize)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3312, "assert(" "Opcode() == Op_Initialize" ") failed", "Only seen when there are no use of init memory" ); ::breakpoint(); } } while (0); |
3313 | assert(outcnt() == 1, "Only control then")do { if (!(outcnt() == 1)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3313, "assert(" "outcnt() == 1" ") failed", "Only control then" ); ::breakpoint(); } } while (0); |
3314 | } |
3315 | if (trailing_store() || trailing_load_store()) { |
3316 | MemBarNode* leading = leading_membar(); |
3317 | if (leading != NULL__null) { |
3318 | assert(leading->trailing_membar() == this, "inconsistent leading/trailing membars")do { if (!(leading->trailing_membar() == this)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3318, "assert(" "leading->trailing_membar() == this" ") failed" , "inconsistent leading/trailing membars"); ::breakpoint(); } } while (0); |
3319 | leading->remove(igvn); |
3320 | } |
3321 | } |
3322 | if (proj_out_or_null(TypeFunc::Memory) != NULL__null) { |
3323 | igvn->replace_node(proj_out(TypeFunc::Memory), in(TypeFunc::Memory)); |
3324 | } |
3325 | if (proj_out_or_null(TypeFunc::Control) != NULL__null) { |
3326 | igvn->replace_node(proj_out(TypeFunc::Control), in(TypeFunc::Control)); |
3327 | } |
3328 | } |
3329 | |
3330 | //------------------------------Ideal------------------------------------------ |
3331 | // Return a node which is more "ideal" than the current node. Strip out |
3332 | // control copies |
3333 | Node *MemBarNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
3334 | if (remove_dead_region(phase, can_reshape)) return this; |
3335 | // Don't bother trying to transform a dead node |
3336 | if (in(0) && in(0)->is_top()) { |
3337 | return NULL__null; |
3338 | } |
3339 | |
3340 | bool progress = false; |
3341 | // Eliminate volatile MemBars for scalar replaced objects. |
3342 | if (can_reshape && req() == (Precedent+1)) { |
3343 | bool eliminate = false; |
3344 | int opc = Opcode(); |
3345 | if ((opc == Op_MemBarAcquire || opc == Op_MemBarVolatile)) { |
3346 | // Volatile field loads and stores. |
3347 | Node* my_mem = in(MemBarNode::Precedent); |
3348 | // The MembarAquire may keep an unused LoadNode alive through the Precedent edge |
3349 | if ((my_mem != NULL__null) && (opc == Op_MemBarAcquire) && (my_mem->outcnt() == 1)) { |
3350 | // if the Precedent is a decodeN and its input (a Load) is used at more than one place, |
3351 | // replace this Precedent (decodeN) with the Load instead. |
3352 | if ((my_mem->Opcode() == Op_DecodeN) && (my_mem->in(1)->outcnt() > 1)) { |
3353 | Node* load_node = my_mem->in(1); |
3354 | set_req(MemBarNode::Precedent, load_node); |
3355 | phase->is_IterGVN()->_worklist.push(my_mem); |
3356 | my_mem = load_node; |
3357 | } else { |
3358 | assert(my_mem->unique_out() == this, "sanity")do { if (!(my_mem->unique_out() == this)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3358, "assert(" "my_mem->unique_out() == this" ") failed" , "sanity"); ::breakpoint(); } } while (0); |
3359 | del_req(Precedent); |
3360 | phase->is_IterGVN()->_worklist.push(my_mem); // remove dead node later |
3361 | my_mem = NULL__null; |
3362 | } |
3363 | progress = true; |
3364 | } |
3365 | if (my_mem != NULL__null && my_mem->is_Mem()) { |
3366 | const TypeOopPtr* t_oop = my_mem->in(MemNode::Address)->bottom_type()->isa_oopptr(); |
3367 | // Check for scalar replaced object reference. |
3368 | if( t_oop != NULL__null && t_oop->is_known_instance_field() && |
3369 | t_oop->offset() != Type::OffsetBot && |
3370 | t_oop->offset() != Type::OffsetTop) { |
3371 | eliminate = true; |
3372 | } |
3373 | } |
3374 | } else if (opc == Op_MemBarRelease) { |
3375 | // Final field stores. |
3376 | Node* alloc = AllocateNode::Ideal_allocation(in(MemBarNode::Precedent), phase); |
3377 | if ((alloc != NULL__null) && alloc->is_Allocate() && |
3378 | alloc->as_Allocate()->does_not_escape_thread()) { |
3379 | // The allocated object does not escape. |
3380 | eliminate = true; |
3381 | } |
3382 | } |
3383 | if (eliminate) { |
3384 | // Replace MemBar projections by its inputs. |
3385 | PhaseIterGVN* igvn = phase->is_IterGVN(); |
3386 | remove(igvn); |
3387 | // Must return either the original node (now dead) or a new node |
3388 | // (Do not return a top here, since that would break the uniqueness of top.) |
3389 | return new ConINode(TypeInt::ZERO); |
3390 | } |
3391 | } |
3392 | return progress ? this : NULL__null; |
3393 | } |
3394 | |
3395 | //------------------------------Value------------------------------------------ |
3396 | const Type* MemBarNode::Value(PhaseGVN* phase) const { |
3397 | if( !in(0) ) return Type::TOP; |
3398 | if( phase->type(in(0)) == Type::TOP ) |
3399 | return Type::TOP; |
3400 | return TypeTuple::MEMBAR; |
3401 | } |
3402 | |
3403 | //------------------------------match------------------------------------------ |
3404 | // Construct projections for memory. |
3405 | Node *MemBarNode::match( const ProjNode *proj, const Matcher *m ) { |
3406 | switch (proj->_con) { |
3407 | case TypeFunc::Control: |
3408 | case TypeFunc::Memory: |
3409 | return new MachProjNode(this,proj->_con,RegMask::Empty,MachProjNode::unmatched_proj); |
3410 | } |
3411 | ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here( "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3411); ::breakpoint(); } while (0); |
3412 | return NULL__null; |
3413 | } |
3414 | |
3415 | void MemBarNode::set_store_pair(MemBarNode* leading, MemBarNode* trailing) { |
3416 | trailing->_kind = TrailingStore; |
3417 | leading->_kind = LeadingStore; |
3418 | #ifdef ASSERT1 |
3419 | trailing->_pair_idx = leading->_idx; |
3420 | leading->_pair_idx = leading->_idx; |
3421 | #endif |
3422 | } |
3423 | |
3424 | void MemBarNode::set_load_store_pair(MemBarNode* leading, MemBarNode* trailing) { |
3425 | trailing->_kind = TrailingLoadStore; |
3426 | leading->_kind = LeadingLoadStore; |
3427 | #ifdef ASSERT1 |
3428 | trailing->_pair_idx = leading->_idx; |
3429 | leading->_pair_idx = leading->_idx; |
3430 | #endif |
3431 | } |
3432 | |
3433 | MemBarNode* MemBarNode::trailing_membar() const { |
3434 | ResourceMark rm; |
3435 | Node* trailing = (Node*)this; |
3436 | VectorSet seen; |
3437 | Node_Stack multis(0); |
3438 | do { |
3439 | Node* c = trailing; |
3440 | uint i = 0; |
3441 | do { |
3442 | trailing = NULL__null; |
3443 | for (; i < c->outcnt(); i++) { |
3444 | Node* next = c->raw_out(i); |
3445 | if (next != c && next->is_CFG()) { |
3446 | if (c->is_MultiBranch()) { |
3447 | if (multis.node() == c) { |
3448 | multis.set_index(i+1); |
3449 | } else { |
3450 | multis.push(c, i+1); |
3451 | } |
3452 | } |
3453 | trailing = next; |
3454 | break; |
3455 | } |
3456 | } |
3457 | if (trailing != NULL__null && !seen.test_set(trailing->_idx)) { |
3458 | break; |
3459 | } |
3460 | while (multis.size() > 0) { |
3461 | c = multis.node(); |
3462 | i = multis.index(); |
3463 | if (i < c->req()) { |
3464 | break; |
3465 | } |
3466 | multis.pop(); |
3467 | } |
3468 | } while (multis.size() > 0); |
3469 | } while (!trailing->is_MemBar() || !trailing->as_MemBar()->trailing()); |
3470 | |
3471 | MemBarNode* mb = trailing->as_MemBar(); |
3472 | assert((mb->_kind == TrailingStore && _kind == LeadingStore) ||do { if (!((mb->_kind == TrailingStore && _kind == LeadingStore) || (mb->_kind == TrailingLoadStore && _kind == LeadingLoadStore))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3473, "assert(" "(mb->_kind == TrailingStore && _kind == LeadingStore) || (mb->_kind == TrailingLoadStore && _kind == LeadingLoadStore)" ") failed", "bad trailing membar"); ::breakpoint(); } } while (0) |
3473 | (mb->_kind == TrailingLoadStore && _kind == LeadingLoadStore), "bad trailing membar")do { if (!((mb->_kind == TrailingStore && _kind == LeadingStore) || (mb->_kind == TrailingLoadStore && _kind == LeadingLoadStore))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3473, "assert(" "(mb->_kind == TrailingStore && _kind == LeadingStore) || (mb->_kind == TrailingLoadStore && _kind == LeadingLoadStore)" ") failed", "bad trailing membar"); ::breakpoint(); } } while (0); |
3474 | assert(mb->_pair_idx == _pair_idx, "bad trailing membar")do { if (!(mb->_pair_idx == _pair_idx)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3474, "assert(" "mb->_pair_idx == _pair_idx" ") failed", "bad trailing membar"); ::breakpoint(); } } while (0); |
3475 | return mb; |
3476 | } |
3477 | |
3478 | MemBarNode* MemBarNode::leading_membar() const { |
3479 | ResourceMark rm; |
3480 | VectorSet seen; |
3481 | Node_Stack regions(0); |
3482 | Node* leading = in(0); |
3483 | while (leading != NULL__null && (!leading->is_MemBar() || !leading->as_MemBar()->leading())) { |
3484 | while (leading == NULL__null || leading->is_top() || seen.test_set(leading->_idx)) { |
3485 | leading = NULL__null; |
3486 | while (regions.size() > 0 && leading == NULL__null) { |
3487 | Node* r = regions.node(); |
3488 | uint i = regions.index(); |
3489 | if (i < r->req()) { |
3490 | leading = r->in(i); |
3491 | regions.set_index(i+1); |
3492 | } else { |
3493 | regions.pop(); |
3494 | } |
3495 | } |
3496 | if (leading == NULL__null) { |
3497 | assert(regions.size() == 0, "all paths should have been tried")do { if (!(regions.size() == 0)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3497, "assert(" "regions.size() == 0" ") failed", "all paths should have been tried" ); ::breakpoint(); } } while (0); |
3498 | return NULL__null; |
3499 | } |
3500 | } |
3501 | if (leading->is_Region()) { |
3502 | regions.push(leading, 2); |
3503 | leading = leading->in(1); |
3504 | } else { |
3505 | leading = leading->in(0); |
3506 | } |
3507 | } |
3508 | #ifdef ASSERT1 |
3509 | Unique_Node_List wq; |
3510 | wq.push((Node*)this); |
3511 | uint found = 0; |
3512 | for (uint i = 0; i < wq.size(); i++) { |
3513 | Node* n = wq.at(i); |
3514 | if (n->is_Region()) { |
3515 | for (uint j = 1; j < n->req(); j++) { |
3516 | Node* in = n->in(j); |
3517 | if (in != NULL__null && !in->is_top()) { |
3518 | wq.push(in); |
3519 | } |
3520 | } |
3521 | } else { |
3522 | if (n->is_MemBar() && n->as_MemBar()->leading()) { |
3523 | assert(n == leading, "consistency check failed")do { if (!(n == leading)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3523, "assert(" "n == leading" ") failed", "consistency check failed" ); ::breakpoint(); } } while (0); |
3524 | found++; |
3525 | } else { |
3526 | Node* in = n->in(0); |
3527 | if (in != NULL__null && !in->is_top()) { |
3528 | wq.push(in); |
3529 | } |
3530 | } |
3531 | } |
3532 | } |
3533 | assert(found == 1 || (found == 0 && leading == NULL), "consistency check failed")do { if (!(found == 1 || (found == 0 && leading == __null ))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3533, "assert(" "found == 1 || (found == 0 && leading == __null)" ") failed", "consistency check failed"); ::breakpoint(); } } while (0); |
3534 | #endif |
3535 | if (leading == NULL__null) { |
3536 | return NULL__null; |
3537 | } |
3538 | MemBarNode* mb = leading->as_MemBar(); |
3539 | assert((mb->_kind == LeadingStore && _kind == TrailingStore) ||do { if (!((mb->_kind == LeadingStore && _kind == TrailingStore ) || (mb->_kind == LeadingLoadStore && _kind == TrailingLoadStore ))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3540, "assert(" "(mb->_kind == LeadingStore && _kind == TrailingStore) || (mb->_kind == LeadingLoadStore && _kind == TrailingLoadStore)" ") failed", "bad leading membar"); ::breakpoint(); } } while (0) |
3540 | (mb->_kind == LeadingLoadStore && _kind == TrailingLoadStore), "bad leading membar")do { if (!((mb->_kind == LeadingStore && _kind == TrailingStore ) || (mb->_kind == LeadingLoadStore && _kind == TrailingLoadStore ))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3540, "assert(" "(mb->_kind == LeadingStore && _kind == TrailingStore) || (mb->_kind == LeadingLoadStore && _kind == TrailingLoadStore)" ") failed", "bad leading membar"); ::breakpoint(); } } while (0); |
3541 | assert(mb->_pair_idx == _pair_idx, "bad leading membar")do { if (!(mb->_pair_idx == _pair_idx)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3541, "assert(" "mb->_pair_idx == _pair_idx" ") failed", "bad leading membar"); ::breakpoint(); } } while (0); |
3542 | return mb; |
3543 | } |
3544 | |
3545 | #ifndef PRODUCT |
3546 | void BlackholeNode::format(PhaseRegAlloc* ra, outputStream* st) const { |
3547 | st->print("blackhole "); |
3548 | bool first = true; |
3549 | for (uint i = 0; i < req(); i++) { |
3550 | Node* n = in(i); |
3551 | if (n != NULL__null && OptoReg::is_valid(ra->get_reg_first(n))) { |
3552 | if (first) { |
3553 | first = false; |
3554 | } else { |
3555 | st->print(", "); |
3556 | } |
3557 | char buf[128]; |
3558 | ra->dump_register(n, buf); |
3559 | st->print("%s", buf); |
3560 | } |
3561 | } |
3562 | st->cr(); |
3563 | } |
3564 | #endif |
3565 | |
3566 | //===========================InitializeNode==================================== |
3567 | // SUMMARY: |
3568 | // This node acts as a memory barrier on raw memory, after some raw stores. |
3569 | // The 'cooked' oop value feeds from the Initialize, not the Allocation. |
3570 | // The Initialize can 'capture' suitably constrained stores as raw inits. |
3571 | // It can coalesce related raw stores into larger units (called 'tiles'). |
3572 | // It can avoid zeroing new storage for memory units which have raw inits. |
3573 | // At macro-expansion, it is marked 'complete', and does not optimize further. |
3574 | // |
3575 | // EXAMPLE: |
3576 | // The object 'new short[2]' occupies 16 bytes in a 32-bit machine. |
3577 | // ctl = incoming control; mem* = incoming memory |
3578 | // (Note: A star * on a memory edge denotes I/O and other standard edges.) |
3579 | // First allocate uninitialized memory and fill in the header: |
3580 | // alloc = (Allocate ctl mem* 16 #short[].klass ...) |
3581 | // ctl := alloc.Control; mem* := alloc.Memory* |
3582 | // rawmem = alloc.Memory; rawoop = alloc.RawAddress |
3583 | // Then initialize to zero the non-header parts of the raw memory block: |
3584 | // init = (Initialize alloc.Control alloc.Memory* alloc.RawAddress) |
3585 | // ctl := init.Control; mem.SLICE(#short[*]) := init.Memory |
3586 | // After the initialize node executes, the object is ready for service: |
3587 | // oop := (CheckCastPP init.Control alloc.RawAddress #short[]) |
3588 | // Suppose its body is immediately initialized as {1,2}: |
3589 | // store1 = (StoreC init.Control init.Memory (+ oop 12) 1) |
3590 | // store2 = (StoreC init.Control store1 (+ oop 14) 2) |
3591 | // mem.SLICE(#short[*]) := store2 |
3592 | // |
3593 | // DETAILS: |
3594 | // An InitializeNode collects and isolates object initialization after |
3595 | // an AllocateNode and before the next possible safepoint. As a |
3596 | // memory barrier (MemBarNode), it keeps critical stores from drifting |
3597 | // down past any safepoint or any publication of the allocation. |
3598 | // Before this barrier, a newly-allocated object may have uninitialized bits. |
3599 | // After this barrier, it may be treated as a real oop, and GC is allowed. |
3600 | // |
3601 | // The semantics of the InitializeNode include an implicit zeroing of |
3602 | // the new object from object header to the end of the object. |
3603 | // (The object header and end are determined by the AllocateNode.) |
3604 | // |
3605 | // Certain stores may be added as direct inputs to the InitializeNode. |
3606 | // These stores must update raw memory, and they must be to addresses |
3607 | // derived from the raw address produced by AllocateNode, and with |
3608 | // a constant offset. They must be ordered by increasing offset. |
3609 | // The first one is at in(RawStores), the last at in(req()-1). |
3610 | // Unlike most memory operations, they are not linked in a chain, |
3611 | // but are displayed in parallel as users of the rawmem output of |
3612 | // the allocation. |
3613 | // |
3614 | // (See comments in InitializeNode::capture_store, which continue |
3615 | // the example given above.) |
3616 | // |
3617 | // When the associated Allocate is macro-expanded, the InitializeNode |
3618 | // may be rewritten to optimize collected stores. A ClearArrayNode |
3619 | // may also be created at that point to represent any required zeroing. |
3620 | // The InitializeNode is then marked 'complete', prohibiting further |
3621 | // capturing of nearby memory operations. |
3622 | // |
3623 | // During macro-expansion, all captured initializations which store |
3624 | // constant values of 32 bits or smaller are coalesced (if advantageous) |
3625 | // into larger 'tiles' 32 or 64 bits. This allows an object to be |
3626 | // initialized in fewer memory operations. Memory words which are |
3627 | // covered by neither tiles nor non-constant stores are pre-zeroed |
3628 | // by explicit stores of zero. (The code shape happens to do all |
3629 | // zeroing first, then all other stores, with both sequences occurring |
3630 | // in order of ascending offsets.) |
3631 | // |
3632 | // Alternatively, code may be inserted between an AllocateNode and its |
3633 | // InitializeNode, to perform arbitrary initialization of the new object. |
3634 | // E.g., the object copying intrinsics insert complex data transfers here. |
3635 | // The initialization must then be marked as 'complete' disable the |
3636 | // built-in zeroing semantics and the collection of initializing stores. |
3637 | // |
3638 | // While an InitializeNode is incomplete, reads from the memory state |
3639 | // produced by it are optimizable if they match the control edge and |
3640 | // new oop address associated with the allocation/initialization. |
3641 | // They return a stored value (if the offset matches) or else zero. |
3642 | // A write to the memory state, if it matches control and address, |
3643 | // and if it is to a constant offset, may be 'captured' by the |
3644 | // InitializeNode. It is cloned as a raw memory operation and rewired |
3645 | // inside the initialization, to the raw oop produced by the allocation. |
3646 | // Operations on addresses which are provably distinct (e.g., to |
3647 | // other AllocateNodes) are allowed to bypass the initialization. |
3648 | // |
3649 | // The effect of all this is to consolidate object initialization |
3650 | // (both arrays and non-arrays, both piecewise and bulk) into a |
3651 | // single location, where it can be optimized as a unit. |
3652 | // |
3653 | // Only stores with an offset less than TrackedInitializationLimit words |
3654 | // will be considered for capture by an InitializeNode. This puts a |
3655 | // reasonable limit on the complexity of optimized initializations. |
3656 | |
3657 | //---------------------------InitializeNode------------------------------------ |
3658 | InitializeNode::InitializeNode(Compile* C, int adr_type, Node* rawoop) |
3659 | : MemBarNode(C, adr_type, rawoop), |
3660 | _is_complete(Incomplete), _does_not_escape(false) |
3661 | { |
3662 | init_class_id(Class_Initialize); |
3663 | |
3664 | assert(adr_type == Compile::AliasIdxRaw, "only valid atp")do { if (!(adr_type == Compile::AliasIdxRaw)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3664, "assert(" "adr_type == Compile::AliasIdxRaw" ") failed" , "only valid atp"); ::breakpoint(); } } while (0); |
3665 | assert(in(RawAddress) == rawoop, "proper init")do { if (!(in(RawAddress) == rawoop)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3665, "assert(" "in(RawAddress) == rawoop" ") failed", "proper init" ); ::breakpoint(); } } while (0); |
3666 | // Note: allocation() can be NULL, for secondary initialization barriers |
3667 | } |
3668 | |
3669 | // Since this node is not matched, it will be processed by the |
3670 | // register allocator. Declare that there are no constraints |
3671 | // on the allocation of the RawAddress edge. |
3672 | const RegMask &InitializeNode::in_RegMask(uint idx) const { |
3673 | // This edge should be set to top, by the set_complete. But be conservative. |
3674 | if (idx == InitializeNode::RawAddress) |
3675 | return *(Compile::current()->matcher()->idealreg2spillmask[in(idx)->ideal_reg()]); |
3676 | return RegMask::Empty; |
3677 | } |
3678 | |
3679 | Node* InitializeNode::memory(uint alias_idx) { |
3680 | Node* mem = in(Memory); |
3681 | if (mem->is_MergeMem()) { |
3682 | return mem->as_MergeMem()->memory_at(alias_idx); |
3683 | } else { |
3684 | // incoming raw memory is not split |
3685 | return mem; |
3686 | } |
3687 | } |
3688 | |
3689 | bool InitializeNode::is_non_zero() { |
3690 | if (is_complete()) return false; |
3691 | remove_extra_zeroes(); |
3692 | return (req() > RawStores); |
3693 | } |
3694 | |
3695 | void InitializeNode::set_complete(PhaseGVN* phase) { |
3696 | assert(!is_complete(), "caller responsibility")do { if (!(!is_complete())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3696, "assert(" "!is_complete()" ") failed", "caller responsibility" ); ::breakpoint(); } } while (0); |
3697 | _is_complete = Complete; |
3698 | |
3699 | // After this node is complete, it contains a bunch of |
3700 | // raw-memory initializations. There is no need for |
3701 | // it to have anything to do with non-raw memory effects. |
3702 | // Therefore, tell all non-raw users to re-optimize themselves, |
3703 | // after skipping the memory effects of this initialization. |
3704 | PhaseIterGVN* igvn = phase->is_IterGVN(); |
3705 | if (igvn) igvn->add_users_to_worklist(this); |
3706 | } |
3707 | |
3708 | // convenience function |
3709 | // return false if the init contains any stores already |
3710 | bool AllocateNode::maybe_set_complete(PhaseGVN* phase) { |
3711 | InitializeNode* init = initialization(); |
3712 | if (init == NULL__null || init->is_complete()) return false; |
3713 | init->remove_extra_zeroes(); |
3714 | // for now, if this allocation has already collected any inits, bail: |
3715 | if (init->is_non_zero()) return false; |
3716 | init->set_complete(phase); |
3717 | return true; |
3718 | } |
3719 | |
3720 | void InitializeNode::remove_extra_zeroes() { |
3721 | if (req() == RawStores) return; |
3722 | Node* zmem = zero_memory(); |
3723 | uint fill = RawStores; |
3724 | for (uint i = fill; i < req(); i++) { |
3725 | Node* n = in(i); |
3726 | if (n->is_top() || n == zmem) continue; // skip |
3727 | if (fill < i) set_req(fill, n); // compact |
3728 | ++fill; |
3729 | } |
3730 | // delete any empty spaces created: |
3731 | while (fill < req()) { |
3732 | del_req(fill); |
3733 | } |
3734 | } |
3735 | |
3736 | // Helper for remembering which stores go with which offsets. |
3737 | intptr_t InitializeNode::get_store_offset(Node* st, PhaseTransform* phase) { |
3738 | if (!st->is_Store()) return -1; // can happen to dead code via subsume_node |
3739 | intptr_t offset = -1; |
3740 | Node* base = AddPNode::Ideal_base_and_offset(st->in(MemNode::Address), |
3741 | phase, offset); |
3742 | if (base == NULL__null) return -1; // something is dead, |
3743 | if (offset < 0) return -1; // dead, dead |
3744 | return offset; |
3745 | } |
3746 | |
3747 | // Helper for proving that an initialization expression is |
3748 | // "simple enough" to be folded into an object initialization. |
3749 | // Attempts to prove that a store's initial value 'n' can be captured |
3750 | // within the initialization without creating a vicious cycle, such as: |
3751 | // { Foo p = new Foo(); p.next = p; } |
3752 | // True for constants and parameters and small combinations thereof. |
3753 | bool InitializeNode::detect_init_independence(Node* value, PhaseGVN* phase) { |
3754 | ResourceMark rm; |
3755 | Unique_Node_List worklist; |
3756 | worklist.push(value); |
3757 | |
3758 | uint complexity_limit = 20; |
3759 | for (uint j = 0; j < worklist.size(); j++) { |
3760 | if (j >= complexity_limit) { |
3761 | return false; // Bail out if processed too many nodes |
3762 | } |
3763 | |
3764 | Node* n = worklist.at(j); |
3765 | if (n == NULL__null) continue; // (can this really happen?) |
3766 | if (n->is_Proj()) n = n->in(0); |
3767 | if (n == this) return false; // found a cycle |
3768 | if (n->is_Con()) continue; |
3769 | if (n->is_Start()) continue; // params, etc., are OK |
3770 | if (n->is_Root()) continue; // even better |
3771 | |
3772 | // There cannot be any dependency if 'n' is a CFG node that dominates the current allocation |
3773 | if (n->is_CFG() && phase->is_dominator(n, allocation())) { |
3774 | continue; |
3775 | } |
3776 | |
3777 | Node* ctl = n->in(0); |
3778 | if (ctl != NULL__null && !ctl->is_top()) { |
3779 | if (ctl->is_Proj()) ctl = ctl->in(0); |
3780 | if (ctl == this) return false; |
3781 | |
3782 | // If we already know that the enclosing memory op is pinned right after |
3783 | // the init, then any control flow that the store has picked up |
3784 | // must have preceded the init, or else be equal to the init. |
3785 | // Even after loop optimizations (which might change control edges) |
3786 | // a store is never pinned *before* the availability of its inputs. |
3787 | if (!MemNode::all_controls_dominate(n, this)) |
3788 | return false; // failed to prove a good control |
3789 | } |
3790 | |
3791 | // Check data edges for possible dependencies on 'this'. |
3792 | for (uint i = 1; i < n->req(); i++) { |
3793 | Node* m = n->in(i); |
3794 | if (m == NULL__null || m == n || m->is_top()) continue; |
3795 | |
3796 | // Only process data inputs once |
3797 | worklist.push(m); |
3798 | } |
3799 | } |
3800 | |
3801 | return true; |
3802 | } |
3803 | |
3804 | // Here are all the checks a Store must pass before it can be moved into |
3805 | // an initialization. Returns zero if a check fails. |
3806 | // On success, returns the (constant) offset to which the store applies, |
3807 | // within the initialized memory. |
3808 | intptr_t InitializeNode::can_capture_store(StoreNode* st, PhaseGVN* phase, bool can_reshape) { |
3809 | const int FAIL = 0; |
3810 | if (st->req() != MemNode::ValueIn + 1) |
3811 | return FAIL; // an inscrutable StoreNode (card mark?) |
3812 | Node* ctl = st->in(MemNode::Control); |
3813 | if (!(ctl != NULL__null && ctl->is_Proj() && ctl->in(0) == this)) |
3814 | return FAIL; // must be unconditional after the initialization |
3815 | Node* mem = st->in(MemNode::Memory); |
3816 | if (!(mem->is_Proj() && mem->in(0) == this)) |
3817 | return FAIL; // must not be preceded by other stores |
3818 | Node* adr = st->in(MemNode::Address); |
3819 | intptr_t offset; |
3820 | AllocateNode* alloc = AllocateNode::Ideal_allocation(adr, phase, offset); |
3821 | if (alloc == NULL__null) |
3822 | return FAIL; // inscrutable address |
3823 | if (alloc != allocation()) |
3824 | return FAIL; // wrong allocation! (store needs to float up) |
3825 | int size_in_bytes = st->memory_size(); |
3826 | if ((size_in_bytes != 0) && (offset % size_in_bytes) != 0) { |
3827 | return FAIL; // mismatched access |
3828 | } |
3829 | Node* val = st->in(MemNode::ValueIn); |
3830 | |
3831 | if (!detect_init_independence(val, phase)) |
3832 | return FAIL; // stored value must be 'simple enough' |
3833 | |
3834 | // The Store can be captured only if nothing after the allocation |
3835 | // and before the Store is using the memory location that the store |
3836 | // overwrites. |
3837 | bool failed = false; |
3838 | // If is_complete_with_arraycopy() is true the shape of the graph is |
3839 | // well defined and is safe so no need for extra checks. |
3840 | if (!is_complete_with_arraycopy()) { |
3841 | // We are going to look at each use of the memory state following |
3842 | // the allocation to make sure nothing reads the memory that the |
3843 | // Store writes. |
3844 | const TypePtr* t_adr = phase->type(adr)->isa_ptr(); |
3845 | int alias_idx = phase->C->get_alias_index(t_adr); |
3846 | ResourceMark rm; |
3847 | Unique_Node_List mems; |
3848 | mems.push(mem); |
3849 | Node* unique_merge = NULL__null; |
3850 | for (uint next = 0; next < mems.size(); ++next) { |
3851 | Node *m = mems.at(next); |
3852 | for (DUIterator_Fast jmax, j = m->fast_outs(jmax); j < jmax; j++) { |
3853 | Node *n = m->fast_out(j); |
3854 | if (n->outcnt() == 0) { |
3855 | continue; |
3856 | } |
3857 | if (n == st) { |
3858 | continue; |
3859 | } else if (n->in(0) != NULL__null && n->in(0) != ctl) { |
3860 | // If the control of this use is different from the control |
3861 | // of the Store which is right after the InitializeNode then |
3862 | // this node cannot be between the InitializeNode and the |
3863 | // Store. |
3864 | continue; |
3865 | } else if (n->is_MergeMem()) { |
3866 | if (n->as_MergeMem()->memory_at(alias_idx) == m) { |
3867 | // We can hit a MergeMemNode (that will likely go away |
3868 | // later) that is a direct use of the memory state |
3869 | // following the InitializeNode on the same slice as the |
3870 | // store node that we'd like to capture. We need to check |
3871 | // the uses of the MergeMemNode. |
3872 | mems.push(n); |
3873 | } |
3874 | } else if (n->is_Mem()) { |
3875 | Node* other_adr = n->in(MemNode::Address); |
3876 | if (other_adr == adr) { |
3877 | failed = true; |
3878 | break; |
3879 | } else { |
3880 | const TypePtr* other_t_adr = phase->type(other_adr)->isa_ptr(); |
3881 | if (other_t_adr != NULL__null) { |
3882 | int other_alias_idx = phase->C->get_alias_index(other_t_adr); |
3883 | if (other_alias_idx == alias_idx) { |
3884 | // A load from the same memory slice as the store right |
3885 | // after the InitializeNode. We check the control of the |
3886 | // object/array that is loaded from. If it's the same as |
3887 | // the store control then we cannot capture the store. |
3888 | assert(!n->is_Store(), "2 stores to same slice on same control?")do { if (!(!n->is_Store())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3888, "assert(" "!n->is_Store()" ") failed", "2 stores to same slice on same control?" ); ::breakpoint(); } } while (0); |
3889 | Node* base = other_adr; |
3890 | assert(base->is_AddP(), "should be addp but is %s", base->Name())do { if (!(base->is_AddP())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3890, "assert(" "base->is_AddP()" ") failed", "should be addp but is %s" , base->Name()); ::breakpoint(); } } while (0); |
3891 | base = base->in(AddPNode::Base); |
3892 | if (base != NULL__null) { |
3893 | base = base->uncast(); |
3894 | if (base->is_Proj() && base->in(0) == alloc) { |
3895 | failed = true; |
3896 | break; |
3897 | } |
3898 | } |
3899 | } |
3900 | } |
3901 | } |
3902 | } else { |
3903 | failed = true; |
3904 | break; |
3905 | } |
3906 | } |
3907 | } |
3908 | } |
3909 | if (failed) { |
3910 | if (!can_reshape) { |
3911 | // We decided we couldn't capture the store during parsing. We |
3912 | // should try again during the next IGVN once the graph is |
3913 | // cleaner. |
3914 | phase->C->record_for_igvn(st); |
3915 | } |
3916 | return FAIL; |
3917 | } |
3918 | |
3919 | return offset; // success |
3920 | } |
3921 | |
3922 | // Find the captured store in(i) which corresponds to the range |
3923 | // [start..start+size) in the initialized object. |
3924 | // If there is one, return its index i. If there isn't, return the |
3925 | // negative of the index where it should be inserted. |
3926 | // Return 0 if the queried range overlaps an initialization boundary |
3927 | // or if dead code is encountered. |
3928 | // If size_in_bytes is zero, do not bother with overlap checks. |
3929 | int InitializeNode::captured_store_insertion_point(intptr_t start, |
3930 | int size_in_bytes, |
3931 | PhaseTransform* phase) { |
3932 | const int FAIL = 0, MAX_STORE = MAX2(BytesPerLong, (int)MaxVectorSize); |
3933 | |
3934 | if (is_complete()) |
3935 | return FAIL; // arraycopy got here first; punt |
3936 | |
3937 | assert(allocation() != NULL, "must be present")do { if (!(allocation() != __null)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3937, "assert(" "allocation() != __null" ") failed", "must be present" ); ::breakpoint(); } } while (0); |
3938 | |
3939 | // no negatives, no header fields: |
3940 | if (start < (intptr_t) allocation()->minimum_header_size()) return FAIL; |
3941 | |
3942 | // after a certain size, we bail out on tracking all the stores: |
3943 | intptr_t ti_limit = (TrackedInitializationLimit * HeapWordSize); |
3944 | if (start >= ti_limit) return FAIL; |
3945 | |
3946 | for (uint i = InitializeNode::RawStores, limit = req(); ; ) { |
3947 | if (i >= limit) return -(int)i; // not found; here is where to put it |
3948 | |
3949 | Node* st = in(i); |
3950 | intptr_t st_off = get_store_offset(st, phase); |
3951 | if (st_off < 0) { |
3952 | if (st != zero_memory()) { |
3953 | return FAIL; // bail out if there is dead garbage |
3954 | } |
3955 | } else if (st_off > start) { |
3956 | // ...we are done, since stores are ordered |
3957 | if (st_off < start + size_in_bytes) { |
3958 | return FAIL; // the next store overlaps |
3959 | } |
3960 | return -(int)i; // not found; here is where to put it |
3961 | } else if (st_off < start) { |
3962 | assert(st->as_Store()->memory_size() <= MAX_STORE, "")do { if (!(st->as_Store()->memory_size() <= MAX_STORE )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3962, "assert(" "st->as_Store()->memory_size() <= MAX_STORE" ") failed", ""); ::breakpoint(); } } while (0); |
3963 | if (size_in_bytes != 0 && |
3964 | start < st_off + MAX_STORE && |
3965 | start < st_off + st->as_Store()->memory_size()) { |
3966 | return FAIL; // the previous store overlaps |
3967 | } |
3968 | } else { |
3969 | if (size_in_bytes != 0 && |
3970 | st->as_Store()->memory_size() != size_in_bytes) { |
3971 | return FAIL; // mismatched store size |
3972 | } |
3973 | return i; |
3974 | } |
3975 | |
3976 | ++i; |
3977 | } |
3978 | } |
3979 | |
3980 | // Look for a captured store which initializes at the offset 'start' |
3981 | // with the given size. If there is no such store, and no other |
3982 | // initialization interferes, then return zero_memory (the memory |
3983 | // projection of the AllocateNode). |
3984 | Node* InitializeNode::find_captured_store(intptr_t start, int size_in_bytes, |
3985 | PhaseTransform* phase) { |
3986 | assert(stores_are_sane(phase), "")do { if (!(stores_are_sane(phase))) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3986, "assert(" "stores_are_sane(phase)" ") failed", ""); :: breakpoint(); } } while (0); |
3987 | int i = captured_store_insertion_point(start, size_in_bytes, phase); |
3988 | if (i == 0) { |
3989 | return NULL__null; // something is dead |
3990 | } else if (i < 0) { |
3991 | return zero_memory(); // just primordial zero bits here |
3992 | } else { |
3993 | Node* st = in(i); // here is the store at this position |
3994 | assert(get_store_offset(st->as_Store(), phase) == start, "sanity")do { if (!(get_store_offset(st->as_Store(), phase) == start )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 3994, "assert(" "get_store_offset(st->as_Store(), phase) == start" ") failed", "sanity"); ::breakpoint(); } } while (0); |
3995 | return st; |
3996 | } |
3997 | } |
3998 | |
3999 | // Create, as a raw pointer, an address within my new object at 'offset'. |
4000 | Node* InitializeNode::make_raw_address(intptr_t offset, |
4001 | PhaseTransform* phase) { |
4002 | Node* addr = in(RawAddress); |
4003 | if (offset != 0) { |
4004 | Compile* C = phase->C; |
4005 | addr = phase->transform( new AddPNode(C->top(), addr, |
4006 | phase->MakeConXlongcon(offset)) ); |
4007 | } |
4008 | return addr; |
4009 | } |
4010 | |
4011 | // Clone the given store, converting it into a raw store |
4012 | // initializing a field or element of my new object. |
4013 | // Caller is responsible for retiring the original store, |
4014 | // with subsume_node or the like. |
4015 | // |
4016 | // From the example above InitializeNode::InitializeNode, |
4017 | // here are the old stores to be captured: |
4018 | // store1 = (StoreC init.Control init.Memory (+ oop 12) 1) |
4019 | // store2 = (StoreC init.Control store1 (+ oop 14) 2) |
4020 | // |
4021 | // Here is the changed code; note the extra edges on init: |
4022 | // alloc = (Allocate ...) |
4023 | // rawoop = alloc.RawAddress |
4024 | // rawstore1 = (StoreC alloc.Control alloc.Memory (+ rawoop 12) 1) |
4025 | // rawstore2 = (StoreC alloc.Control alloc.Memory (+ rawoop 14) 2) |
4026 | // init = (Initialize alloc.Control alloc.Memory rawoop |
4027 | // rawstore1 rawstore2) |
4028 | // |
4029 | Node* InitializeNode::capture_store(StoreNode* st, intptr_t start, |
4030 | PhaseGVN* phase, bool can_reshape) { |
4031 | assert(stores_are_sane(phase), "")do { if (!(stores_are_sane(phase))) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4031, "assert(" "stores_are_sane(phase)" ") failed", ""); :: breakpoint(); } } while (0); |
4032 | |
4033 | if (start < 0) return NULL__null; |
4034 | assert(can_capture_store(st, phase, can_reshape) == start, "sanity")do { if (!(can_capture_store(st, phase, can_reshape) == start )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4034, "assert(" "can_capture_store(st, phase, can_reshape) == start" ") failed", "sanity"); ::breakpoint(); } } while (0); |
4035 | |
4036 | Compile* C = phase->C; |
4037 | int size_in_bytes = st->memory_size(); |
4038 | int i = captured_store_insertion_point(start, size_in_bytes, phase); |
4039 | if (i == 0) return NULL__null; // bail out |
4040 | Node* prev_mem = NULL__null; // raw memory for the captured store |
4041 | if (i > 0) { |
4042 | prev_mem = in(i); // there is a pre-existing store under this one |
4043 | set_req(i, C->top()); // temporarily disconnect it |
4044 | // See StoreNode::Ideal 'st->outcnt() == 1' for the reason to disconnect. |
4045 | } else { |
4046 | i = -i; // no pre-existing store |
4047 | prev_mem = zero_memory(); // a slice of the newly allocated object |
4048 | if (i > InitializeNode::RawStores && in(i-1) == prev_mem) |
4049 | set_req(--i, C->top()); // reuse this edge; it has been folded away |
4050 | else |
4051 | ins_req(i, C->top()); // build a new edge |
4052 | } |
4053 | Node* new_st = st->clone(); |
4054 | new_st->set_req(MemNode::Control, in(Control)); |
4055 | new_st->set_req(MemNode::Memory, prev_mem); |
4056 | new_st->set_req(MemNode::Address, make_raw_address(start, phase)); |
4057 | new_st = phase->transform(new_st); |
4058 | |
4059 | // At this point, new_st might have swallowed a pre-existing store |
4060 | // at the same offset, or perhaps new_st might have disappeared, |
4061 | // if it redundantly stored the same value (or zero to fresh memory). |
4062 | |
4063 | // In any case, wire it in: |
4064 | PhaseIterGVN* igvn = phase->is_IterGVN(); |
4065 | if (igvn) { |
4066 | igvn->rehash_node_delayed(this); |
4067 | } |
4068 | set_req(i, new_st); |
4069 | |
4070 | // The caller may now kill the old guy. |
4071 | DEBUG_ONLY(Node* check_st = find_captured_store(start, size_in_bytes, phase))Node* check_st = find_captured_store(start, size_in_bytes, phase ); |
4072 | assert(check_st == new_st || check_st == NULL, "must be findable")do { if (!(check_st == new_st || check_st == __null)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4072, "assert(" "check_st == new_st || check_st == __null" ") failed" , "must be findable"); ::breakpoint(); } } while (0); |
4073 | assert(!is_complete(), "")do { if (!(!is_complete())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4073, "assert(" "!is_complete()" ") failed", ""); ::breakpoint (); } } while (0); |
4074 | return new_st; |
4075 | } |
4076 | |
4077 | static bool store_constant(jlong* tiles, int num_tiles, |
4078 | intptr_t st_off, int st_size, |
4079 | jlong con) { |
4080 | if ((st_off & (st_size-1)) != 0) |
4081 | return false; // strange store offset (assume size==2**N) |
4082 | address addr = (address)tiles + st_off; |
4083 | assert(st_off >= 0 && addr+st_size <= (address)&tiles[num_tiles], "oob")do { if (!(st_off >= 0 && addr+st_size <= (address )&tiles[num_tiles])) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4083, "assert(" "st_off >= 0 && addr+st_size <= (address)&tiles[num_tiles]" ") failed", "oob"); ::breakpoint(); } } while (0); |
4084 | switch (st_size) { |
4085 | case sizeof(jbyte): *(jbyte*) addr = (jbyte) con; break; |
4086 | case sizeof(jchar): *(jchar*) addr = (jchar) con; break; |
4087 | case sizeof(jint): *(jint*) addr = (jint) con; break; |
4088 | case sizeof(jlong): *(jlong*) addr = (jlong) con; break; |
4089 | default: return false; // strange store size (detect size!=2**N here) |
4090 | } |
4091 | return true; // return success to caller |
4092 | } |
4093 | |
4094 | // Coalesce subword constants into int constants and possibly |
4095 | // into long constants. The goal, if the CPU permits, |
4096 | // is to initialize the object with a small number of 64-bit tiles. |
4097 | // Also, convert floating-point constants to bit patterns. |
4098 | // Non-constants are not relevant to this pass. |
4099 | // |
4100 | // In terms of the running example on InitializeNode::InitializeNode |
4101 | // and InitializeNode::capture_store, here is the transformation |
4102 | // of rawstore1 and rawstore2 into rawstore12: |
4103 | // alloc = (Allocate ...) |
4104 | // rawoop = alloc.RawAddress |
4105 | // tile12 = 0x00010002 |
4106 | // rawstore12 = (StoreI alloc.Control alloc.Memory (+ rawoop 12) tile12) |
4107 | // init = (Initialize alloc.Control alloc.Memory rawoop rawstore12) |
4108 | // |
4109 | void |
4110 | InitializeNode::coalesce_subword_stores(intptr_t header_size, |
4111 | Node* size_in_bytes, |
4112 | PhaseGVN* phase) { |
4113 | Compile* C = phase->C; |
4114 | |
4115 | assert(stores_are_sane(phase), "")do { if (!(stores_are_sane(phase))) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4115, "assert(" "stores_are_sane(phase)" ") failed", ""); :: breakpoint(); } } while (0); |
4116 | // Note: After this pass, they are not completely sane, |
4117 | // since there may be some overlaps. |
4118 | |
4119 | int old_subword = 0, old_long = 0, new_int = 0, new_long = 0; |
4120 | |
4121 | intptr_t ti_limit = (TrackedInitializationLimit * HeapWordSize); |
4122 | intptr_t size_limit = phase->find_intptr_t_confind_long_con(size_in_bytes, ti_limit); |
4123 | size_limit = MIN2(size_limit, ti_limit); |
4124 | size_limit = align_up(size_limit, BytesPerLong); |
4125 | int num_tiles = size_limit / BytesPerLong; |
4126 | |
4127 | // allocate space for the tile map: |
4128 | const int small_len = DEBUG_ONLY(true ? 3 :)true ? 3 : 30; // keep stack frames small |
4129 | jlong tiles_buf[small_len]; |
4130 | Node* nodes_buf[small_len]; |
4131 | jlong inits_buf[small_len]; |
4132 | jlong* tiles = ((num_tiles <= small_len) ? &tiles_buf[0] |
4133 | : NEW_RESOURCE_ARRAY(jlong, num_tiles)(jlong*) resource_allocate_bytes((num_tiles) * sizeof(jlong))); |
4134 | Node** nodes = ((num_tiles <= small_len) ? &nodes_buf[0] |
4135 | : NEW_RESOURCE_ARRAY(Node*, num_tiles)(Node**) resource_allocate_bytes((num_tiles) * sizeof(Node*))); |
4136 | jlong* inits = ((num_tiles <= small_len) ? &inits_buf[0] |
4137 | : NEW_RESOURCE_ARRAY(jlong, num_tiles)(jlong*) resource_allocate_bytes((num_tiles) * sizeof(jlong))); |
4138 | // tiles: exact bitwise model of all primitive constants |
4139 | // nodes: last constant-storing node subsumed into the tiles model |
4140 | // inits: which bytes (in each tile) are touched by any initializations |
4141 | |
4142 | //// Pass A: Fill in the tile model with any relevant stores. |
4143 | |
4144 | Copy::zero_to_bytes(tiles, sizeof(tiles[0]) * num_tiles); |
4145 | Copy::zero_to_bytes(nodes, sizeof(nodes[0]) * num_tiles); |
4146 | Copy::zero_to_bytes(inits, sizeof(inits[0]) * num_tiles); |
4147 | Node* zmem = zero_memory(); // initially zero memory state |
4148 | for (uint i = InitializeNode::RawStores, limit = req(); i < limit; i++) { |
4149 | Node* st = in(i); |
4150 | intptr_t st_off = get_store_offset(st, phase); |
4151 | |
4152 | // Figure out the store's offset and constant value: |
4153 | if (st_off < header_size) continue; //skip (ignore header) |
4154 | if (st->in(MemNode::Memory) != zmem) continue; //skip (odd store chain) |
4155 | int st_size = st->as_Store()->memory_size(); |
4156 | if (st_off + st_size > size_limit) break; |
4157 | |
4158 | // Record which bytes are touched, whether by constant or not. |
4159 | if (!store_constant(inits, num_tiles, st_off, st_size, (jlong) -1)) |
4160 | continue; // skip (strange store size) |
4161 | |
4162 | const Type* val = phase->type(st->in(MemNode::ValueIn)); |
4163 | if (!val->singleton()) continue; //skip (non-con store) |
4164 | BasicType type = val->basic_type(); |
4165 | |
4166 | jlong con = 0; |
4167 | switch (type) { |
4168 | case T_INT: con = val->is_int()->get_con(); break; |
4169 | case T_LONG: con = val->is_long()->get_con(); break; |
4170 | case T_FLOAT: con = jint_cast(val->getf()); break; |
4171 | case T_DOUBLE: con = jlong_cast(val->getd()); break; |
4172 | default: continue; //skip (odd store type) |
4173 | } |
4174 | |
4175 | if (type == T_LONG && Matcher::isSimpleConstant64(con) && |
4176 | st->Opcode() == Op_StoreL) { |
4177 | continue; // This StoreL is already optimal. |
4178 | } |
4179 | |
4180 | // Store down the constant. |
4181 | store_constant(tiles, num_tiles, st_off, st_size, con); |
4182 | |
4183 | intptr_t j = st_off >> LogBytesPerLong; |
4184 | |
4185 | if (type == T_INT && st_size == BytesPerInt |
4186 | && (st_off & BytesPerInt) == BytesPerInt) { |
4187 | jlong lcon = tiles[j]; |
4188 | if (!Matcher::isSimpleConstant64(lcon) && |
4189 | st->Opcode() == Op_StoreI) { |
4190 | // This StoreI is already optimal by itself. |
4191 | jint* intcon = (jint*) &tiles[j]; |
4192 | intcon[1] = 0; // undo the store_constant() |
4193 | |
4194 | // If the previous store is also optimal by itself, back up and |
4195 | // undo the action of the previous loop iteration... if we can. |
4196 | // But if we can't, just let the previous half take care of itself. |
4197 | st = nodes[j]; |
4198 | st_off -= BytesPerInt; |
4199 | con = intcon[0]; |
4200 | if (con != 0 && st != NULL__null && st->Opcode() == Op_StoreI) { |
4201 | assert(st_off >= header_size, "still ignoring header")do { if (!(st_off >= header_size)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4201, "assert(" "st_off >= header_size" ") failed", "still ignoring header" ); ::breakpoint(); } } while (0); |
4202 | assert(get_store_offset(st, phase) == st_off, "must be")do { if (!(get_store_offset(st, phase) == st_off)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4202, "assert(" "get_store_offset(st, phase) == st_off" ") failed" , "must be"); ::breakpoint(); } } while (0); |
4203 | assert(in(i-1) == zmem, "must be")do { if (!(in(i-1) == zmem)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4203, "assert(" "in(i-1) == zmem" ") failed", "must be"); :: breakpoint(); } } while (0); |
4204 | DEBUG_ONLY(const Type* tcon = phase->type(st->in(MemNode::ValueIn)))const Type* tcon = phase->type(st->in(MemNode::ValueIn) ); |
4205 | assert(con == tcon->is_int()->get_con(), "must be")do { if (!(con == tcon->is_int()->get_con())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4205, "assert(" "con == tcon->is_int()->get_con()" ") failed" , "must be"); ::breakpoint(); } } while (0); |
4206 | // Undo the effects of the previous loop trip, which swallowed st: |
4207 | intcon[0] = 0; // undo store_constant() |
4208 | set_req(i-1, st); // undo set_req(i, zmem) |
4209 | nodes[j] = NULL__null; // undo nodes[j] = st |
4210 | --old_subword; // undo ++old_subword |
4211 | } |
4212 | continue; // This StoreI is already optimal. |
4213 | } |
4214 | } |
4215 | |
4216 | // This store is not needed. |
4217 | set_req(i, zmem); |
4218 | nodes[j] = st; // record for the moment |
4219 | if (st_size < BytesPerLong) // something has changed |
4220 | ++old_subword; // includes int/float, but who's counting... |
4221 | else ++old_long; |
4222 | } |
4223 | |
4224 | if ((old_subword + old_long) == 0) |
4225 | return; // nothing more to do |
4226 | |
4227 | //// Pass B: Convert any non-zero tiles into optimal constant stores. |
4228 | // Be sure to insert them before overlapping non-constant stores. |
4229 | // (E.g., byte[] x = { 1,2,y,4 } => x[int 0] = 0x01020004, x[2]=y.) |
4230 | for (int j = 0; j < num_tiles; j++) { |
4231 | jlong con = tiles[j]; |
4232 | jlong init = inits[j]; |
4233 | if (con == 0) continue; |
4234 | jint con0, con1; // split the constant, address-wise |
4235 | jint init0, init1; // split the init map, address-wise |
4236 | { union { jlong con; jint intcon[2]; } u; |
4237 | u.con = con; |
4238 | con0 = u.intcon[0]; |
4239 | con1 = u.intcon[1]; |
4240 | u.con = init; |
4241 | init0 = u.intcon[0]; |
4242 | init1 = u.intcon[1]; |
4243 | } |
4244 | |
4245 | Node* old = nodes[j]; |
4246 | assert(old != NULL, "need the prior store")do { if (!(old != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4246, "assert(" "old != __null" ") failed", "need the prior store" ); ::breakpoint(); } } while (0); |
4247 | intptr_t offset = (j * BytesPerLong); |
4248 | |
4249 | bool split = !Matcher::isSimpleConstant64(con); |
4250 | |
4251 | if (offset < header_size) { |
4252 | assert(offset + BytesPerInt >= header_size, "second int counts")do { if (!(offset + BytesPerInt >= header_size)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4252, "assert(" "offset + BytesPerInt >= header_size" ") failed" , "second int counts"); ::breakpoint(); } } while (0); |
4253 | assert(*(jint*)&tiles[j] == 0, "junk in header")do { if (!(*(jint*)&tiles[j] == 0)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4253, "assert(" "*(jint*)&tiles[j] == 0" ") failed", "junk in header" ); ::breakpoint(); } } while (0); |
4254 | split = true; // only the second word counts |
4255 | // Example: int a[] = { 42 ... } |
4256 | } else if (con0 == 0 && init0 == -1) { |
4257 | split = true; // first word is covered by full inits |
4258 | // Example: int a[] = { ... foo(), 42 ... } |
4259 | } else if (con1 == 0 && init1 == -1) { |
4260 | split = true; // second word is covered by full inits |
4261 | // Example: int a[] = { ... 42, foo() ... } |
4262 | } |
4263 | |
4264 | // Here's a case where init0 is neither 0 nor -1: |
4265 | // byte a[] = { ... 0,0,foo(),0, 0,0,0,42 ... } |
4266 | // Assuming big-endian memory, init0, init1 are 0x0000FF00, 0x000000FF. |
4267 | // In this case the tile is not split; it is (jlong)42. |
4268 | // The big tile is stored down, and then the foo() value is inserted. |
4269 | // (If there were foo(),foo() instead of foo(),0, init0 would be -1.) |
4270 | |
4271 | Node* ctl = old->in(MemNode::Control); |
4272 | Node* adr = make_raw_address(offset, phase); |
4273 | const TypePtr* atp = TypeRawPtr::BOTTOM; |
4274 | |
4275 | // One or two coalesced stores to plop down. |
4276 | Node* st[2]; |
4277 | intptr_t off[2]; |
4278 | int nst = 0; |
4279 | if (!split) { |
4280 | ++new_long; |
4281 | off[nst] = offset; |
4282 | st[nst++] = StoreNode::make(*phase, ctl, zmem, adr, atp, |
4283 | phase->longcon(con), T_LONG, MemNode::unordered); |
4284 | } else { |
4285 | // Omit either if it is a zero. |
4286 | if (con0 != 0) { |
4287 | ++new_int; |
4288 | off[nst] = offset; |
4289 | st[nst++] = StoreNode::make(*phase, ctl, zmem, adr, atp, |
4290 | phase->intcon(con0), T_INT, MemNode::unordered); |
4291 | } |
4292 | if (con1 != 0) { |
4293 | ++new_int; |
4294 | offset += BytesPerInt; |
4295 | adr = make_raw_address(offset, phase); |
4296 | off[nst] = offset; |
4297 | st[nst++] = StoreNode::make(*phase, ctl, zmem, adr, atp, |
4298 | phase->intcon(con1), T_INT, MemNode::unordered); |
4299 | } |
4300 | } |
4301 | |
4302 | // Insert second store first, then the first before the second. |
4303 | // Insert each one just before any overlapping non-constant stores. |
4304 | while (nst > 0) { |
4305 | Node* st1 = st[--nst]; |
4306 | C->copy_node_notes_to(st1, old); |
4307 | st1 = phase->transform(st1); |
4308 | offset = off[nst]; |
4309 | assert(offset >= header_size, "do not smash header")do { if (!(offset >= header_size)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4309, "assert(" "offset >= header_size" ") failed", "do not smash header" ); ::breakpoint(); } } while (0); |
4310 | int ins_idx = captured_store_insertion_point(offset, /*size:*/0, phase); |
4311 | guarantee(ins_idx != 0, "must re-insert constant store")do { if (!(ins_idx != 0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4311, "guarantee(" "ins_idx != 0" ") failed", "must re-insert constant store" ); ::breakpoint(); } } while (0); |
4312 | if (ins_idx < 0) ins_idx = -ins_idx; // never overlap |
4313 | if (ins_idx > InitializeNode::RawStores && in(ins_idx-1) == zmem) |
4314 | set_req(--ins_idx, st1); |
4315 | else |
4316 | ins_req(ins_idx, st1); |
4317 | } |
4318 | } |
4319 | |
4320 | if (PrintCompilation && WizardMode) |
4321 | tty->print_cr("Changed %d/%d subword/long constants into %d/%d int/long", |
4322 | old_subword, old_long, new_int, new_long); |
4323 | if (C->log() != NULL__null) |
4324 | C->log()->elem("comment that='%d/%d subword/long to %d/%d int/long'", |
4325 | old_subword, old_long, new_int, new_long); |
4326 | |
4327 | // Clean up any remaining occurrences of zmem: |
4328 | remove_extra_zeroes(); |
4329 | } |
4330 | |
4331 | // Explore forward from in(start) to find the first fully initialized |
4332 | // word, and return its offset. Skip groups of subword stores which |
4333 | // together initialize full words. If in(start) is itself part of a |
4334 | // fully initialized word, return the offset of in(start). If there |
4335 | // are no following full-word stores, or if something is fishy, return |
4336 | // a negative value. |
4337 | intptr_t InitializeNode::find_next_fullword_store(uint start, PhaseGVN* phase) { |
4338 | int int_map = 0; |
4339 | intptr_t int_map_off = 0; |
4340 | const int FULL_MAP = right_n_bits(BytesPerInt)((((BytesPerInt) >= BitsPerWord) ? 0 : (OneBit << (BytesPerInt ))) - 1); // the int_map we hope for |
4341 | |
4342 | for (uint i = start, limit = req(); i < limit; i++) { |
4343 | Node* st = in(i); |
4344 | |
4345 | intptr_t st_off = get_store_offset(st, phase); |
4346 | if (st_off < 0) break; // return conservative answer |
4347 | |
4348 | int st_size = st->as_Store()->memory_size(); |
4349 | if (st_size >= BytesPerInt && (st_off % BytesPerInt) == 0) { |
4350 | return st_off; // we found a complete word init |
4351 | } |
4352 | |
4353 | // update the map: |
4354 | |
4355 | intptr_t this_int_off = align_down(st_off, BytesPerInt); |
4356 | if (this_int_off != int_map_off) { |
4357 | // reset the map: |
4358 | int_map = 0; |
4359 | int_map_off = this_int_off; |
4360 | } |
4361 | |
4362 | int subword_off = st_off - this_int_off; |
4363 | int_map |= right_n_bits(st_size)((((st_size) >= BitsPerWord) ? 0 : (OneBit << (st_size ))) - 1) << subword_off; |
4364 | if ((int_map & FULL_MAP) == FULL_MAP) { |
4365 | return this_int_off; // we found a complete word init |
4366 | } |
4367 | |
4368 | // Did this store hit or cross the word boundary? |
4369 | intptr_t next_int_off = align_down(st_off + st_size, BytesPerInt); |
4370 | if (next_int_off == this_int_off + BytesPerInt) { |
4371 | // We passed the current int, without fully initializing it. |
4372 | int_map_off = next_int_off; |
4373 | int_map >>= BytesPerInt; |
4374 | } else if (next_int_off > this_int_off + BytesPerInt) { |
4375 | // We passed the current and next int. |
4376 | return this_int_off + BytesPerInt; |
4377 | } |
4378 | } |
4379 | |
4380 | return -1; |
4381 | } |
4382 | |
4383 | |
4384 | // Called when the associated AllocateNode is expanded into CFG. |
4385 | // At this point, we may perform additional optimizations. |
4386 | // Linearize the stores by ascending offset, to make memory |
4387 | // activity as coherent as possible. |
4388 | Node* InitializeNode::complete_stores(Node* rawctl, Node* rawmem, Node* rawptr, |
4389 | intptr_t header_size, |
4390 | Node* size_in_bytes, |
4391 | PhaseIterGVN* phase) { |
4392 | assert(!is_complete(), "not already complete")do { if (!(!is_complete())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4392, "assert(" "!is_complete()" ") failed", "not already complete" ); ::breakpoint(); } } while (0); |
4393 | assert(stores_are_sane(phase), "")do { if (!(stores_are_sane(phase))) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4393, "assert(" "stores_are_sane(phase)" ") failed", ""); :: breakpoint(); } } while (0); |
4394 | assert(allocation() != NULL, "must be present")do { if (!(allocation() != __null)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4394, "assert(" "allocation() != __null" ") failed", "must be present" ); ::breakpoint(); } } while (0); |
4395 | |
4396 | remove_extra_zeroes(); |
4397 | |
4398 | if (ReduceFieldZeroing || ReduceBulkZeroing) |
4399 | // reduce instruction count for common initialization patterns |
4400 | coalesce_subword_stores(header_size, size_in_bytes, phase); |
4401 | |
4402 | Node* zmem = zero_memory(); // initially zero memory state |
4403 | Node* inits = zmem; // accumulating a linearized chain of inits |
4404 | #ifdef ASSERT1 |
4405 | intptr_t first_offset = allocation()->minimum_header_size(); |
4406 | intptr_t last_init_off = first_offset; // previous init offset |
4407 | intptr_t last_init_end = first_offset; // previous init offset+size |
4408 | intptr_t last_tile_end = first_offset; // previous tile offset+size |
4409 | #endif |
4410 | intptr_t zeroes_done = header_size; |
4411 | |
4412 | bool do_zeroing = true; // we might give up if inits are very sparse |
4413 | int big_init_gaps = 0; // how many large gaps have we seen? |
4414 | |
4415 | if (UseTLAB && ZeroTLAB) do_zeroing = false; |
4416 | if (!ReduceFieldZeroing && !ReduceBulkZeroing) do_zeroing = false; |
4417 | |
4418 | for (uint i = InitializeNode::RawStores, limit = req(); i < limit; i++) { |
4419 | Node* st = in(i); |
4420 | intptr_t st_off = get_store_offset(st, phase); |
4421 | if (st_off < 0) |
4422 | break; // unknown junk in the inits |
4423 | if (st->in(MemNode::Memory) != zmem) |
4424 | break; // complicated store chains somehow in list |
4425 | |
4426 | int st_size = st->as_Store()->memory_size(); |
4427 | intptr_t next_init_off = st_off + st_size; |
4428 | |
4429 | if (do_zeroing && zeroes_done < next_init_off) { |
4430 | // See if this store needs a zero before it or under it. |
4431 | intptr_t zeroes_needed = st_off; |
4432 | |
4433 | if (st_size < BytesPerInt) { |
4434 | // Look for subword stores which only partially initialize words. |
4435 | // If we find some, we must lay down some word-level zeroes first, |
4436 | // underneath the subword stores. |
4437 | // |
4438 | // Examples: |
4439 | // byte[] a = { p,q,r,s } => a[0]=p,a[1]=q,a[2]=r,a[3]=s |
4440 | // byte[] a = { x,y,0,0 } => a[0..3] = 0, a[0]=x,a[1]=y |
4441 | // byte[] a = { 0,0,z,0 } => a[0..3] = 0, a[2]=z |
4442 | // |
4443 | // Note: coalesce_subword_stores may have already done this, |
4444 | // if it was prompted by constant non-zero subword initializers. |
4445 | // But this case can still arise with non-constant stores. |
4446 | |
4447 | intptr_t next_full_store = find_next_fullword_store(i, phase); |
4448 | |
4449 | // In the examples above: |
4450 | // in(i) p q r s x y z |
4451 | // st_off 12 13 14 15 12 13 14 |
4452 | // st_size 1 1 1 1 1 1 1 |
4453 | // next_full_s. 12 16 16 16 16 16 16 |
4454 | // z's_done 12 16 16 16 12 16 12 |
4455 | // z's_needed 12 16 16 16 16 16 16 |
4456 | // zsize 0 0 0 0 4 0 4 |
4457 | if (next_full_store < 0) { |
4458 | // Conservative tack: Zero to end of current word. |
4459 | zeroes_needed = align_up(zeroes_needed, BytesPerInt); |
4460 | } else { |
4461 | // Zero to beginning of next fully initialized word. |
4462 | // Or, don't zero at all, if we are already in that word. |
4463 | assert(next_full_store >= zeroes_needed, "must go forward")do { if (!(next_full_store >= zeroes_needed)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4463, "assert(" "next_full_store >= zeroes_needed" ") failed" , "must go forward"); ::breakpoint(); } } while (0); |
4464 | assert((next_full_store & (BytesPerInt-1)) == 0, "even boundary")do { if (!((next_full_store & (BytesPerInt-1)) == 0)) { ( *g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4464, "assert(" "(next_full_store & (BytesPerInt-1)) == 0" ") failed", "even boundary"); ::breakpoint(); } } while (0); |
4465 | zeroes_needed = next_full_store; |
4466 | } |
4467 | } |
4468 | |
4469 | if (zeroes_needed > zeroes_done) { |
4470 | intptr_t zsize = zeroes_needed - zeroes_done; |
4471 | // Do some incremental zeroing on rawmem, in parallel with inits. |
4472 | zeroes_done = align_down(zeroes_done, BytesPerInt); |
4473 | rawmem = ClearArrayNode::clear_memory(rawctl, rawmem, rawptr, |
4474 | zeroes_done, zeroes_needed, |
4475 | phase); |
4476 | zeroes_done = zeroes_needed; |
4477 | if (zsize > InitArrayShortSize && ++big_init_gaps > 2) |
4478 | do_zeroing = false; // leave the hole, next time |
4479 | } |
4480 | } |
4481 | |
4482 | // Collect the store and move on: |
4483 | phase->replace_input_of(st, MemNode::Memory, inits); |
4484 | inits = st; // put it on the linearized chain |
4485 | set_req(i, zmem); // unhook from previous position |
4486 | |
4487 | if (zeroes_done == st_off) |
4488 | zeroes_done = next_init_off; |
4489 | |
4490 | assert(!do_zeroing || zeroes_done >= next_init_off, "don't miss any")do { if (!(!do_zeroing || zeroes_done >= next_init_off)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4490, "assert(" "!do_zeroing || zeroes_done >= next_init_off" ") failed", "don't miss any"); ::breakpoint(); } } while (0); |
4491 | |
4492 | #ifdef ASSERT1 |
4493 | // Various order invariants. Weaker than stores_are_sane because |
4494 | // a large constant tile can be filled in by smaller non-constant stores. |
4495 | assert(st_off >= last_init_off, "inits do not reverse")do { if (!(st_off >= last_init_off)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4495, "assert(" "st_off >= last_init_off" ") failed", "inits do not reverse" ); ::breakpoint(); } } while (0); |
4496 | last_init_off = st_off; |
4497 | const Type* val = NULL__null; |
4498 | if (st_size >= BytesPerInt && |
4499 | (val = phase->type(st->in(MemNode::ValueIn)))->singleton() && |
4500 | (int)val->basic_type() < (int)T_OBJECT) { |
4501 | assert(st_off >= last_tile_end, "tiles do not overlap")do { if (!(st_off >= last_tile_end)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4501, "assert(" "st_off >= last_tile_end" ") failed", "tiles do not overlap" ); ::breakpoint(); } } while (0); |
4502 | assert(st_off >= last_init_end, "tiles do not overwrite inits")do { if (!(st_off >= last_init_end)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4502, "assert(" "st_off >= last_init_end" ") failed", "tiles do not overwrite inits" ); ::breakpoint(); } } while (0); |
4503 | last_tile_end = MAX2(last_tile_end, next_init_off); |
4504 | } else { |
4505 | intptr_t st_tile_end = align_up(next_init_off, BytesPerLong); |
4506 | assert(st_tile_end >= last_tile_end, "inits stay with tiles")do { if (!(st_tile_end >= last_tile_end)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4506, "assert(" "st_tile_end >= last_tile_end" ") failed" , "inits stay with tiles"); ::breakpoint(); } } while (0); |
4507 | assert(st_off >= last_init_end, "inits do not overlap")do { if (!(st_off >= last_init_end)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4507, "assert(" "st_off >= last_init_end" ") failed", "inits do not overlap" ); ::breakpoint(); } } while (0); |
4508 | last_init_end = next_init_off; // it's a non-tile |
4509 | } |
4510 | #endif //ASSERT |
4511 | } |
4512 | |
4513 | remove_extra_zeroes(); // clear out all the zmems left over |
4514 | add_req(inits); |
4515 | |
4516 | if (!(UseTLAB && ZeroTLAB)) { |
4517 | // If anything remains to be zeroed, zero it all now. |
4518 | zeroes_done = align_down(zeroes_done, BytesPerInt); |
4519 | // if it is the last unused 4 bytes of an instance, forget about it |
4520 | intptr_t size_limit = phase->find_intptr_t_confind_long_con(size_in_bytes, max_jint); |
4521 | if (zeroes_done + BytesPerLong >= size_limit) { |
4522 | AllocateNode* alloc = allocation(); |
4523 | assert(alloc != NULL, "must be present")do { if (!(alloc != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4523, "assert(" "alloc != __null" ") failed", "must be present" ); ::breakpoint(); } } while (0); |
4524 | if (alloc != NULL__null && alloc->Opcode() == Op_Allocate) { |
4525 | Node* klass_node = alloc->in(AllocateNode::KlassNode); |
4526 | ciKlass* k = phase->type(klass_node)->is_klassptr()->klass(); |
4527 | if (zeroes_done == k->layout_helper()) |
4528 | zeroes_done = size_limit; |
4529 | } |
4530 | } |
4531 | if (zeroes_done < size_limit) { |
4532 | rawmem = ClearArrayNode::clear_memory(rawctl, rawmem, rawptr, |
4533 | zeroes_done, size_in_bytes, phase); |
4534 | } |
4535 | } |
4536 | |
4537 | set_complete(phase); |
4538 | return rawmem; |
4539 | } |
4540 | |
4541 | |
4542 | #ifdef ASSERT1 |
4543 | bool InitializeNode::stores_are_sane(PhaseTransform* phase) { |
4544 | if (is_complete()) |
4545 | return true; // stores could be anything at this point |
4546 | assert(allocation() != NULL, "must be present")do { if (!(allocation() != __null)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4546, "assert(" "allocation() != __null" ") failed", "must be present" ); ::breakpoint(); } } while (0); |
4547 | intptr_t last_off = allocation()->minimum_header_size(); |
4548 | for (uint i = InitializeNode::RawStores; i < req(); i++) { |
4549 | Node* st = in(i); |
4550 | intptr_t st_off = get_store_offset(st, phase); |
4551 | if (st_off < 0) continue; // ignore dead garbage |
4552 | if (last_off > st_off) { |
4553 | tty->print_cr("*** bad store offset at %d: " INTX_FORMAT"%" "l" "d" " > " INTX_FORMAT"%" "l" "d", i, last_off, st_off); |
4554 | this->dump(2); |
4555 | assert(false, "ascending store offsets")do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4555, "assert(" "false" ") failed", "ascending store offsets" ); ::breakpoint(); } } while (0); |
4556 | return false; |
4557 | } |
4558 | last_off = st_off + st->as_Store()->memory_size(); |
4559 | } |
4560 | return true; |
4561 | } |
4562 | #endif //ASSERT |
4563 | |
4564 | |
4565 | |
4566 | |
4567 | //============================MergeMemNode===================================== |
4568 | // |
4569 | // SEMANTICS OF MEMORY MERGES: A MergeMem is a memory state assembled from several |
4570 | // contributing store or call operations. Each contributor provides the memory |
4571 | // state for a particular "alias type" (see Compile::alias_type). For example, |
4572 | // if a MergeMem has an input X for alias category #6, then any memory reference |
4573 | // to alias category #6 may use X as its memory state input, as an exact equivalent |
4574 | // to using the MergeMem as a whole. |
4575 | // Load<6>( MergeMem(<6>: X, ...), p ) <==> Load<6>(X,p) |
4576 | // |
4577 | // (Here, the <N> notation gives the index of the relevant adr_type.) |
4578 | // |
4579 | // In one special case (and more cases in the future), alias categories overlap. |
4580 | // The special alias category "Bot" (Compile::AliasIdxBot) includes all memory |
4581 | // states. Therefore, if a MergeMem has only one contributing input W for Bot, |
4582 | // it is exactly equivalent to that state W: |
4583 | // MergeMem(<Bot>: W) <==> W |
4584 | // |
4585 | // Usually, the merge has more than one input. In that case, where inputs |
4586 | // overlap (i.e., one is Bot), the narrower alias type determines the memory |
4587 | // state for that type, and the wider alias type (Bot) fills in everywhere else: |
4588 | // Load<5>( MergeMem(<Bot>: W, <6>: X), p ) <==> Load<5>(W,p) |
4589 | // Load<6>( MergeMem(<Bot>: W, <6>: X), p ) <==> Load<6>(X,p) |
4590 | // |
4591 | // A merge can take a "wide" memory state as one of its narrow inputs. |
4592 | // This simply means that the merge observes out only the relevant parts of |
4593 | // the wide input. That is, wide memory states arriving at narrow merge inputs |
4594 | // are implicitly "filtered" or "sliced" as necessary. (This is rare.) |
4595 | // |
4596 | // These rules imply that MergeMem nodes may cascade (via their <Bot> links), |
4597 | // and that memory slices "leak through": |
4598 | // MergeMem(<Bot>: MergeMem(<Bot>: W, <7>: Y)) <==> MergeMem(<Bot>: W, <7>: Y) |
4599 | // |
4600 | // But, in such a cascade, repeated memory slices can "block the leak": |
4601 | // MergeMem(<Bot>: MergeMem(<Bot>: W, <7>: Y), <7>: Y') <==> MergeMem(<Bot>: W, <7>: Y') |
4602 | // |
4603 | // In the last example, Y is not part of the combined memory state of the |
4604 | // outermost MergeMem. The system must, of course, prevent unschedulable |
4605 | // memory states from arising, so you can be sure that the state Y is somehow |
4606 | // a precursor to state Y'. |
4607 | // |
4608 | // |
4609 | // REPRESENTATION OF MEMORY MERGES: The indexes used to address the Node::in array |
4610 | // of each MergeMemNode array are exactly the numerical alias indexes, including |
4611 | // but not limited to AliasIdxTop, AliasIdxBot, and AliasIdxRaw. The functions |
4612 | // Compile::alias_type (and kin) produce and manage these indexes. |
4613 | // |
4614 | // By convention, the value of in(AliasIdxTop) (i.e., in(1)) is always the top node. |
4615 | // (Note that this provides quick access to the top node inside MergeMem methods, |
4616 | // without the need to reach out via TLS to Compile::current.) |
4617 | // |
4618 | // As a consequence of what was just described, a MergeMem that represents a full |
4619 | // memory state has an edge in(AliasIdxBot) which is a "wide" memory state, |
4620 | // containing all alias categories. |
4621 | // |
4622 | // MergeMem nodes never (?) have control inputs, so in(0) is NULL. |
4623 | // |
4624 | // All other edges in(N) (including in(AliasIdxRaw), which is in(3)) are either |
4625 | // a memory state for the alias type <N>, or else the top node, meaning that |
4626 | // there is no particular input for that alias type. Note that the length of |
4627 | // a MergeMem is variable, and may be extended at any time to accommodate new |
4628 | // memory states at larger alias indexes. When merges grow, they are of course |
4629 | // filled with "top" in the unused in() positions. |
4630 | // |
4631 | // This use of top is named "empty_memory()", or "empty_mem" (no-memory) as a variable. |
4632 | // (Top was chosen because it works smoothly with passes like GCM.) |
4633 | // |
4634 | // For convenience, we hardwire the alias index for TypeRawPtr::BOTTOM. (It is |
4635 | // the type of random VM bits like TLS references.) Since it is always the |
4636 | // first non-Bot memory slice, some low-level loops use it to initialize an |
4637 | // index variable: for (i = AliasIdxRaw; i < req(); i++). |
4638 | // |
4639 | // |
4640 | // ACCESSORS: There is a special accessor MergeMemNode::base_memory which returns |
4641 | // the distinguished "wide" state. The accessor MergeMemNode::memory_at(N) returns |
4642 | // the memory state for alias type <N>, or (if there is no particular slice at <N>, |
4643 | // it returns the base memory. To prevent bugs, memory_at does not accept <Top> |
4644 | // or <Bot> indexes. The iterator MergeMemStream provides robust iteration over |
4645 | // MergeMem nodes or pairs of such nodes, ensuring that the non-top edges are visited. |
4646 | // |
4647 | // %%%% We may get rid of base_memory as a separate accessor at some point; it isn't |
4648 | // really that different from the other memory inputs. An abbreviation called |
4649 | // "bot_memory()" for "memory_at(AliasIdxBot)" would keep code tidy. |
4650 | // |
4651 | // |
4652 | // PARTIAL MEMORY STATES: During optimization, MergeMem nodes may arise that represent |
4653 | // partial memory states. When a Phi splits through a MergeMem, the copy of the Phi |
4654 | // that "emerges though" the base memory will be marked as excluding the alias types |
4655 | // of the other (narrow-memory) copies which "emerged through" the narrow edges: |
4656 | // |
4657 | // Phi<Bot>(U, MergeMem(<Bot>: W, <8>: Y)) |
4658 | // ==Ideal=> MergeMem(<Bot>: Phi<Bot-8>(U, W), Phi<8>(U, Y)) |
4659 | // |
4660 | // This strange "subtraction" effect is necessary to ensure IGVN convergence. |
4661 | // (It is currently unimplemented.) As you can see, the resulting merge is |
4662 | // actually a disjoint union of memory states, rather than an overlay. |
4663 | // |
4664 | |
4665 | //------------------------------MergeMemNode----------------------------------- |
4666 | Node* MergeMemNode::make_empty_memory() { |
4667 | Node* empty_memory = (Node*) Compile::current()->top(); |
4668 | assert(empty_memory->is_top(), "correct sentinel identity")do { if (!(empty_memory->is_top())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4668, "assert(" "empty_memory->is_top()" ") failed", "correct sentinel identity" ); ::breakpoint(); } } while (0); |
4669 | return empty_memory; |
4670 | } |
4671 | |
4672 | MergeMemNode::MergeMemNode(Node *new_base) : Node(1+Compile::AliasIdxRaw) { |
4673 | init_class_id(Class_MergeMem); |
4674 | // all inputs are nullified in Node::Node(int) |
4675 | // set_input(0, NULL); // no control input |
4676 | |
4677 | // Initialize the edges uniformly to top, for starters. |
4678 | Node* empty_mem = make_empty_memory(); |
4679 | for (uint i = Compile::AliasIdxTop; i < req(); i++) { |
4680 | init_req(i,empty_mem); |
4681 | } |
4682 | assert(empty_memory() == empty_mem, "")do { if (!(empty_memory() == empty_mem)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4682, "assert(" "empty_memory() == empty_mem" ") failed", "" ); ::breakpoint(); } } while (0); |
4683 | |
4684 | if( new_base != NULL__null && new_base->is_MergeMem() ) { |
4685 | MergeMemNode* mdef = new_base->as_MergeMem(); |
4686 | assert(mdef->empty_memory() == empty_mem, "consistent sentinels")do { if (!(mdef->empty_memory() == empty_mem)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4686, "assert(" "mdef->empty_memory() == empty_mem" ") failed" , "consistent sentinels"); ::breakpoint(); } } while (0); |
4687 | for (MergeMemStream mms(this, mdef); mms.next_non_empty2(); ) { |
4688 | mms.set_memory(mms.memory2()); |
4689 | } |
4690 | assert(base_memory() == mdef->base_memory(), "")do { if (!(base_memory() == mdef->base_memory())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4690, "assert(" "base_memory() == mdef->base_memory()" ") failed" , ""); ::breakpoint(); } } while (0); |
4691 | } else { |
4692 | set_base_memory(new_base); |
4693 | } |
4694 | } |
4695 | |
4696 | // Make a new, untransformed MergeMem with the same base as 'mem'. |
4697 | // If mem is itself a MergeMem, populate the result with the same edges. |
4698 | MergeMemNode* MergeMemNode::make(Node* mem) { |
4699 | return new MergeMemNode(mem); |
4700 | } |
4701 | |
4702 | //------------------------------cmp-------------------------------------------- |
4703 | uint MergeMemNode::hash() const { return NO_HASH; } |
4704 | bool MergeMemNode::cmp( const Node &n ) const { |
4705 | return (&n == this); // Always fail except on self |
4706 | } |
4707 | |
4708 | //------------------------------Identity--------------------------------------- |
4709 | Node* MergeMemNode::Identity(PhaseGVN* phase) { |
4710 | // Identity if this merge point does not record any interesting memory |
4711 | // disambiguations. |
4712 | Node* base_mem = base_memory(); |
4713 | Node* empty_mem = empty_memory(); |
4714 | if (base_mem != empty_mem) { // Memory path is not dead? |
4715 | for (uint i = Compile::AliasIdxRaw; i < req(); i++) { |
4716 | Node* mem = in(i); |
4717 | if (mem != empty_mem && mem != base_mem) { |
4718 | return this; // Many memory splits; no change |
4719 | } |
4720 | } |
4721 | } |
4722 | return base_mem; // No memory splits; ID on the one true input |
4723 | } |
4724 | |
4725 | //------------------------------Ideal------------------------------------------ |
4726 | // This method is invoked recursively on chains of MergeMem nodes |
4727 | Node *MergeMemNode::Ideal(PhaseGVN *phase, bool can_reshape) { |
4728 | // Remove chain'd MergeMems |
4729 | // |
4730 | // This is delicate, because the each "in(i)" (i >= Raw) is interpreted |
4731 | // relative to the "in(Bot)". Since we are patching both at the same time, |
4732 | // we have to be careful to read each "in(i)" relative to the old "in(Bot)", |
4733 | // but rewrite each "in(i)" relative to the new "in(Bot)". |
4734 | Node *progress = NULL__null; |
4735 | |
4736 | |
4737 | Node* old_base = base_memory(); |
4738 | Node* empty_mem = empty_memory(); |
4739 | if (old_base == empty_mem) |
4740 | return NULL__null; // Dead memory path. |
4741 | |
4742 | MergeMemNode* old_mbase; |
4743 | if (old_base != NULL__null && old_base->is_MergeMem()) |
4744 | old_mbase = old_base->as_MergeMem(); |
4745 | else |
4746 | old_mbase = NULL__null; |
4747 | Node* new_base = old_base; |
4748 | |
4749 | // simplify stacked MergeMems in base memory |
4750 | if (old_mbase) new_base = old_mbase->base_memory(); |
4751 | |
4752 | // the base memory might contribute new slices beyond my req() |
4753 | if (old_mbase) grow_to_match(old_mbase); |
4754 | |
4755 | // Look carefully at the base node if it is a phi. |
4756 | PhiNode* phi_base; |
4757 | if (new_base != NULL__null && new_base->is_Phi()) |
4758 | phi_base = new_base->as_Phi(); |
4759 | else |
4760 | phi_base = NULL__null; |
4761 | |
4762 | Node* phi_reg = NULL__null; |
4763 | uint phi_len = (uint)-1; |
4764 | if (phi_base != NULL__null) { |
4765 | phi_reg = phi_base->region(); |
4766 | phi_len = phi_base->req(); |
4767 | // see if the phi is unfinished |
4768 | for (uint i = 1; i < phi_len; i++) { |
4769 | if (phi_base->in(i) == NULL__null) { |
4770 | // incomplete phi; do not look at it yet! |
4771 | phi_reg = NULL__null; |
4772 | phi_len = (uint)-1; |
Value stored to 'phi_len' is never read | |
4773 | break; |
4774 | } |
4775 | } |
4776 | } |
4777 | |
4778 | // Note: We do not call verify_sparse on entry, because inputs |
4779 | // can normalize to the base_memory via subsume_node or similar |
4780 | // mechanisms. This method repairs that damage. |
4781 | |
4782 | assert(!old_mbase || old_mbase->is_empty_memory(empty_mem), "consistent sentinels")do { if (!(!old_mbase || old_mbase->is_empty_memory(empty_mem ))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4782, "assert(" "!old_mbase || old_mbase->is_empty_memory(empty_mem)" ") failed", "consistent sentinels"); ::breakpoint(); } } while (0); |
4783 | |
4784 | // Look at each slice. |
4785 | for (uint i = Compile::AliasIdxRaw; i < req(); i++) { |
4786 | Node* old_in = in(i); |
4787 | // calculate the old memory value |
4788 | Node* old_mem = old_in; |
4789 | if (old_mem == empty_mem) old_mem = old_base; |
4790 | assert(old_mem == memory_at(i), "")do { if (!(old_mem == memory_at(i))) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4790, "assert(" "old_mem == memory_at(i)" ") failed", ""); :: breakpoint(); } } while (0); |
4791 | |
4792 | // maybe update (reslice) the old memory value |
4793 | |
4794 | // simplify stacked MergeMems |
4795 | Node* new_mem = old_mem; |
4796 | MergeMemNode* old_mmem; |
4797 | if (old_mem != NULL__null && old_mem->is_MergeMem()) |
4798 | old_mmem = old_mem->as_MergeMem(); |
4799 | else |
4800 | old_mmem = NULL__null; |
4801 | if (old_mmem == this) { |
4802 | // This can happen if loops break up and safepoints disappear. |
4803 | // A merge of BotPtr (default) with a RawPtr memory derived from a |
4804 | // safepoint can be rewritten to a merge of the same BotPtr with |
4805 | // the BotPtr phi coming into the loop. If that phi disappears |
4806 | // also, we can end up with a self-loop of the mergemem. |
4807 | // In general, if loops degenerate and memory effects disappear, |
4808 | // a mergemem can be left looking at itself. This simply means |
4809 | // that the mergemem's default should be used, since there is |
4810 | // no longer any apparent effect on this slice. |
4811 | // Note: If a memory slice is a MergeMem cycle, it is unreachable |
4812 | // from start. Update the input to TOP. |
4813 | new_mem = (new_base == this || new_base == empty_mem)? empty_mem : new_base; |
4814 | } |
4815 | else if (old_mmem != NULL__null) { |
4816 | new_mem = old_mmem->memory_at(i); |
4817 | } |
4818 | // else preceding memory was not a MergeMem |
4819 | |
4820 | // maybe store down a new value |
4821 | Node* new_in = new_mem; |
4822 | if (new_in == new_base) new_in = empty_mem; |
4823 | |
4824 | if (new_in != old_in) { |
4825 | // Warning: Do not combine this "if" with the previous "if" |
4826 | // A memory slice might have be be rewritten even if it is semantically |
4827 | // unchanged, if the base_memory value has changed. |
4828 | set_req_X(i, new_in, phase); |
4829 | progress = this; // Report progress |
4830 | } |
4831 | } |
4832 | |
4833 | if (new_base != old_base) { |
4834 | set_req_X(Compile::AliasIdxBot, new_base, phase); |
4835 | // Don't use set_base_memory(new_base), because we need to update du. |
4836 | assert(base_memory() == new_base, "")do { if (!(base_memory() == new_base)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4836, "assert(" "base_memory() == new_base" ") failed", "") ; ::breakpoint(); } } while (0); |
4837 | progress = this; |
4838 | } |
4839 | |
4840 | if( base_memory() == this ) { |
4841 | // a self cycle indicates this memory path is dead |
4842 | set_req(Compile::AliasIdxBot, empty_mem); |
4843 | } |
4844 | |
4845 | // Resolve external cycles by calling Ideal on a MergeMem base_memory |
4846 | // Recursion must occur after the self cycle check above |
4847 | if( base_memory()->is_MergeMem() ) { |
4848 | MergeMemNode *new_mbase = base_memory()->as_MergeMem(); |
4849 | Node *m = phase->transform(new_mbase); // Rollup any cycles |
4850 | if( m != NULL__null && |
4851 | (m->is_top() || |
4852 | (m->is_MergeMem() && m->as_MergeMem()->base_memory() == empty_mem)) ) { |
4853 | // propagate rollup of dead cycle to self |
4854 | set_req(Compile::AliasIdxBot, empty_mem); |
4855 | } |
4856 | } |
4857 | |
4858 | if( base_memory() == empty_mem ) { |
4859 | progress = this; |
4860 | // Cut inputs during Parse phase only. |
4861 | // During Optimize phase a dead MergeMem node will be subsumed by Top. |
4862 | if( !can_reshape ) { |
4863 | for (uint i = Compile::AliasIdxRaw; i < req(); i++) { |
4864 | if( in(i) != empty_mem ) { set_req(i, empty_mem); } |
4865 | } |
4866 | } |
4867 | } |
4868 | |
4869 | if( !progress && base_memory()->is_Phi() && can_reshape ) { |
4870 | // Check if PhiNode::Ideal's "Split phis through memory merges" |
4871 | // transform should be attempted. Look for this->phi->this cycle. |
4872 | uint merge_width = req(); |
4873 | if (merge_width > Compile::AliasIdxRaw) { |
4874 | PhiNode* phi = base_memory()->as_Phi(); |
4875 | for( uint i = 1; i < phi->req(); ++i ) {// For all paths in |
4876 | if (phi->in(i) == this) { |
4877 | phase->is_IterGVN()->_worklist.push(phi); |
4878 | break; |
4879 | } |
4880 | } |
4881 | } |
4882 | } |
4883 | |
4884 | assert(progress || verify_sparse(), "please, no dups of base")do { if (!(progress || verify_sparse())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4884, "assert(" "progress || verify_sparse()" ") failed", "please, no dups of base" ); ::breakpoint(); } } while (0); |
4885 | return progress; |
4886 | } |
4887 | |
4888 | //-------------------------set_base_memory------------------------------------- |
4889 | void MergeMemNode::set_base_memory(Node *new_base) { |
4890 | Node* empty_mem = empty_memory(); |
4891 | set_req(Compile::AliasIdxBot, new_base); |
4892 | assert(memory_at(req()) == new_base, "must set default memory")do { if (!(memory_at(req()) == new_base)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4892, "assert(" "memory_at(req()) == new_base" ") failed", "must set default memory" ); ::breakpoint(); } } while (0); |
4893 | // Clear out other occurrences of new_base: |
4894 | if (new_base != empty_mem) { |
4895 | for (uint i = Compile::AliasIdxRaw; i < req(); i++) { |
4896 | if (in(i) == new_base) set_req(i, empty_mem); |
4897 | } |
4898 | } |
4899 | } |
4900 | |
4901 | //------------------------------out_RegMask------------------------------------ |
4902 | const RegMask &MergeMemNode::out_RegMask() const { |
4903 | return RegMask::Empty; |
4904 | } |
4905 | |
4906 | //------------------------------dump_spec-------------------------------------- |
4907 | #ifndef PRODUCT |
4908 | void MergeMemNode::dump_spec(outputStream *st) const { |
4909 | st->print(" {"); |
4910 | Node* base_mem = base_memory(); |
4911 | for( uint i = Compile::AliasIdxRaw; i < req(); i++ ) { |
4912 | Node* mem = (in(i) != NULL__null) ? memory_at(i) : base_mem; |
4913 | if (mem == base_mem) { st->print(" -"); continue; } |
4914 | st->print( " N%d:", mem->_idx ); |
4915 | Compile::current()->get_adr_type(i)->dump_on(st); |
4916 | } |
4917 | st->print(" }"); |
4918 | } |
4919 | #endif // !PRODUCT |
4920 | |
4921 | |
4922 | #ifdef ASSERT1 |
4923 | static bool might_be_same(Node* a, Node* b) { |
4924 | if (a == b) return true; |
4925 | if (!(a->is_Phi() || b->is_Phi())) return false; |
4926 | // phis shift around during optimization |
4927 | return true; // pretty stupid... |
4928 | } |
4929 | |
4930 | // verify a narrow slice (either incoming or outgoing) |
4931 | static void verify_memory_slice(const MergeMemNode* m, int alias_idx, Node* n) { |
4932 | if (!VerifyAliases) return; // don't bother to verify unless requested |
4933 | if (VMError::is_error_reported()) return; // muzzle asserts when debugging an error |
4934 | if (Node::in_dump()) return; // muzzle asserts when printing |
4935 | assert(alias_idx >= Compile::AliasIdxRaw, "must not disturb base_memory or sentinel")do { if (!(alias_idx >= Compile::AliasIdxRaw)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4935, "assert(" "alias_idx >= Compile::AliasIdxRaw" ") failed" , "must not disturb base_memory or sentinel"); ::breakpoint() ; } } while (0); |
4936 | assert(n != NULL, "")do { if (!(n != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4936, "assert(" "n != __null" ") failed", ""); ::breakpoint (); } } while (0); |
4937 | // Elide intervening MergeMem's |
4938 | while (n->is_MergeMem()) { |
4939 | n = n->as_MergeMem()->memory_at(alias_idx); |
4940 | } |
4941 | Compile* C = Compile::current(); |
4942 | const TypePtr* n_adr_type = n->adr_type(); |
4943 | if (n == m->empty_memory()) { |
4944 | // Implicit copy of base_memory() |
4945 | } else if (n_adr_type != TypePtr::BOTTOM) { |
4946 | assert(n_adr_type != NULL, "new memory must have a well-defined adr_type")do { if (!(n_adr_type != __null)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4946, "assert(" "n_adr_type != __null" ") failed", "new memory must have a well-defined adr_type" ); ::breakpoint(); } } while (0); |
4947 | assert(C->must_alias(n_adr_type, alias_idx), "new memory must match selected slice")do { if (!(C->must_alias(n_adr_type, alias_idx))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4947, "assert(" "C->must_alias(n_adr_type, alias_idx)" ") failed" , "new memory must match selected slice"); ::breakpoint(); } } while (0); |
4948 | } else { |
4949 | // A few places like make_runtime_call "know" that VM calls are narrow, |
4950 | // and can be used to update only the VM bits stored as TypeRawPtr::BOTTOM. |
4951 | bool expected_wide_mem = false; |
4952 | if (n == m->base_memory()) { |
4953 | expected_wide_mem = true; |
4954 | } else if (alias_idx == Compile::AliasIdxRaw || |
4955 | n == m->memory_at(Compile::AliasIdxRaw)) { |
4956 | expected_wide_mem = true; |
4957 | } else if (!C->alias_type(alias_idx)->is_rewritable()) { |
4958 | // memory can "leak through" calls on channels that |
4959 | // are write-once. Allow this also. |
4960 | expected_wide_mem = true; |
4961 | } |
4962 | assert(expected_wide_mem, "expected narrow slice replacement")do { if (!(expected_wide_mem)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4962, "assert(" "expected_wide_mem" ") failed", "expected narrow slice replacement" ); ::breakpoint(); } } while (0); |
4963 | } |
4964 | } |
4965 | #else // !ASSERT |
4966 | #define verify_memory_slice(m,i,n) (void)(0) // PRODUCT version is no-op |
4967 | #endif |
4968 | |
4969 | |
4970 | //-----------------------------memory_at--------------------------------------- |
4971 | Node* MergeMemNode::memory_at(uint alias_idx) const { |
4972 | assert(alias_idx >= Compile::AliasIdxRaw ||do { if (!(alias_idx >= Compile::AliasIdxRaw || alias_idx == Compile::AliasIdxBot && Compile::current()->AliasLevel () == 0)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4974, "assert(" "alias_idx >= Compile::AliasIdxRaw || alias_idx == Compile::AliasIdxBot && Compile::current()->AliasLevel() == 0" ") failed", "must avoid base_memory and AliasIdxTop"); ::breakpoint (); } } while (0) |
4973 | alias_idx == Compile::AliasIdxBot && Compile::current()->AliasLevel() == 0,do { if (!(alias_idx >= Compile::AliasIdxRaw || alias_idx == Compile::AliasIdxBot && Compile::current()->AliasLevel () == 0)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4974, "assert(" "alias_idx >= Compile::AliasIdxRaw || alias_idx == Compile::AliasIdxBot && Compile::current()->AliasLevel() == 0" ") failed", "must avoid base_memory and AliasIdxTop"); ::breakpoint (); } } while (0) |
4974 | "must avoid base_memory and AliasIdxTop")do { if (!(alias_idx >= Compile::AliasIdxRaw || alias_idx == Compile::AliasIdxBot && Compile::current()->AliasLevel () == 0)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4974, "assert(" "alias_idx >= Compile::AliasIdxRaw || alias_idx == Compile::AliasIdxBot && Compile::current()->AliasLevel() == 0" ") failed", "must avoid base_memory and AliasIdxTop"); ::breakpoint (); } } while (0); |
4975 | |
4976 | // Otherwise, it is a narrow slice. |
4977 | Node* n = alias_idx < req() ? in(alias_idx) : empty_memory(); |
4978 | Compile *C = Compile::current(); |
4979 | if (is_empty_memory(n)) { |
4980 | // the array is sparse; empty slots are the "top" node |
4981 | n = base_memory(); |
4982 | assert(Node::in_dump()do { if (!(Node::in_dump() || n == __null || n->bottom_type () == Type::TOP || n->adr_type() == __null || n->adr_type () == TypePtr::BOTTOM || n->adr_type() == TypeRawPtr::BOTTOM || Compile::current()->AliasLevel() == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4988, "assert(" "Node::in_dump() || n == __null || n->bottom_type() == Type::TOP || n->adr_type() == __null || n->adr_type() == TypePtr::BOTTOM || n->adr_type() == TypeRawPtr::BOTTOM || Compile::current()->AliasLevel() == 0" ") failed", "must be a wide memory"); ::breakpoint(); } } while (0) |
4983 | || n == NULL || n->bottom_type() == Type::TOPdo { if (!(Node::in_dump() || n == __null || n->bottom_type () == Type::TOP || n->adr_type() == __null || n->adr_type () == TypePtr::BOTTOM || n->adr_type() == TypeRawPtr::BOTTOM || Compile::current()->AliasLevel() == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4988, "assert(" "Node::in_dump() || n == __null || n->bottom_type() == Type::TOP || n->adr_type() == __null || n->adr_type() == TypePtr::BOTTOM || n->adr_type() == TypeRawPtr::BOTTOM || Compile::current()->AliasLevel() == 0" ") failed", "must be a wide memory"); ::breakpoint(); } } while (0) |
4984 | || n->adr_type() == NULL // address is TOPdo { if (!(Node::in_dump() || n == __null || n->bottom_type () == Type::TOP || n->adr_type() == __null || n->adr_type () == TypePtr::BOTTOM || n->adr_type() == TypeRawPtr::BOTTOM || Compile::current()->AliasLevel() == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4988, "assert(" "Node::in_dump() || n == __null || n->bottom_type() == Type::TOP || n->adr_type() == __null || n->adr_type() == TypePtr::BOTTOM || n->adr_type() == TypeRawPtr::BOTTOM || Compile::current()->AliasLevel() == 0" ") failed", "must be a wide memory"); ::breakpoint(); } } while (0) |
4985 | || n->adr_type() == TypePtr::BOTTOMdo { if (!(Node::in_dump() || n == __null || n->bottom_type () == Type::TOP || n->adr_type() == __null || n->adr_type () == TypePtr::BOTTOM || n->adr_type() == TypeRawPtr::BOTTOM || Compile::current()->AliasLevel() == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4988, "assert(" "Node::in_dump() || n == __null || n->bottom_type() == Type::TOP || n->adr_type() == __null || n->adr_type() == TypePtr::BOTTOM || n->adr_type() == TypeRawPtr::BOTTOM || Compile::current()->AliasLevel() == 0" ") failed", "must be a wide memory"); ::breakpoint(); } } while (0) |
4986 | || n->adr_type() == TypeRawPtr::BOTTOMdo { if (!(Node::in_dump() || n == __null || n->bottom_type () == Type::TOP || n->adr_type() == __null || n->adr_type () == TypePtr::BOTTOM || n->adr_type() == TypeRawPtr::BOTTOM || Compile::current()->AliasLevel() == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4988, "assert(" "Node::in_dump() || n == __null || n->bottom_type() == Type::TOP || n->adr_type() == __null || n->adr_type() == TypePtr::BOTTOM || n->adr_type() == TypeRawPtr::BOTTOM || Compile::current()->AliasLevel() == 0" ") failed", "must be a wide memory"); ::breakpoint(); } } while (0) |
4987 | || Compile::current()->AliasLevel() == 0,do { if (!(Node::in_dump() || n == __null || n->bottom_type () == Type::TOP || n->adr_type() == __null || n->adr_type () == TypePtr::BOTTOM || n->adr_type() == TypeRawPtr::BOTTOM || Compile::current()->AliasLevel() == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4988, "assert(" "Node::in_dump() || n == __null || n->bottom_type() == Type::TOP || n->adr_type() == __null || n->adr_type() == TypePtr::BOTTOM || n->adr_type() == TypeRawPtr::BOTTOM || Compile::current()->AliasLevel() == 0" ") failed", "must be a wide memory"); ::breakpoint(); } } while (0) |
4988 | "must be a wide memory")do { if (!(Node::in_dump() || n == __null || n->bottom_type () == Type::TOP || n->adr_type() == __null || n->adr_type () == TypePtr::BOTTOM || n->adr_type() == TypeRawPtr::BOTTOM || Compile::current()->AliasLevel() == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 4988, "assert(" "Node::in_dump() || n == __null || n->bottom_type() == Type::TOP || n->adr_type() == __null || n->adr_type() == TypePtr::BOTTOM || n->adr_type() == TypeRawPtr::BOTTOM || Compile::current()->AliasLevel() == 0" ") failed", "must be a wide memory"); ::breakpoint(); } } while (0); |
4989 | // AliasLevel == 0 if we are organizing the memory states manually. |
4990 | // See verify_memory_slice for comments on TypeRawPtr::BOTTOM. |
4991 | } else { |
4992 | // make sure the stored slice is sane |
4993 | #ifdef ASSERT1 |
4994 | if (VMError::is_error_reported() || Node::in_dump()) { |
4995 | } else if (might_be_same(n, base_memory())) { |
4996 | // Give it a pass: It is a mostly harmless repetition of the base. |
4997 | // This can arise normally from node subsumption during optimization. |
4998 | } else { |
4999 | verify_memory_slice(this, alias_idx, n); |
5000 | } |
5001 | #endif |
5002 | } |
5003 | return n; |
5004 | } |
5005 | |
5006 | //---------------------------set_memory_at------------------------------------- |
5007 | void MergeMemNode::set_memory_at(uint alias_idx, Node *n) { |
5008 | verify_memory_slice(this, alias_idx, n); |
5009 | Node* empty_mem = empty_memory(); |
5010 | if (n == base_memory()) n = empty_mem; // collapse default |
5011 | uint need_req = alias_idx+1; |
5012 | if (req() < need_req) { |
5013 | if (n == empty_mem) return; // already the default, so do not grow me |
5014 | // grow the sparse array |
5015 | do { |
5016 | add_req(empty_mem); |
5017 | } while (req() < need_req); |
5018 | } |
5019 | set_req( alias_idx, n ); |
5020 | } |
5021 | |
5022 | |
5023 | |
5024 | //--------------------------iteration_setup------------------------------------ |
5025 | void MergeMemNode::iteration_setup(const MergeMemNode* other) { |
5026 | if (other != NULL__null) { |
5027 | grow_to_match(other); |
5028 | // invariant: the finite support of mm2 is within mm->req() |
5029 | #ifdef ASSERT1 |
5030 | for (uint i = req(); i < other->req(); i++) { |
5031 | assert(other->is_empty_memory(other->in(i)), "slice left uncovered")do { if (!(other->is_empty_memory(other->in(i)))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 5031, "assert(" "other->is_empty_memory(other->in(i))" ") failed", "slice left uncovered"); ::breakpoint(); } } while (0); |
5032 | } |
5033 | #endif |
5034 | } |
5035 | // Replace spurious copies of base_memory by top. |
5036 | Node* base_mem = base_memory(); |
5037 | if (base_mem != NULL__null && !base_mem->is_top()) { |
5038 | for (uint i = Compile::AliasIdxBot+1, imax = req(); i < imax; i++) { |
5039 | if (in(i) == base_mem) |
5040 | set_req(i, empty_memory()); |
5041 | } |
5042 | } |
5043 | } |
5044 | |
5045 | //---------------------------grow_to_match------------------------------------- |
5046 | void MergeMemNode::grow_to_match(const MergeMemNode* other) { |
5047 | Node* empty_mem = empty_memory(); |
5048 | assert(other->is_empty_memory(empty_mem), "consistent sentinels")do { if (!(other->is_empty_memory(empty_mem))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 5048, "assert(" "other->is_empty_memory(empty_mem)" ") failed" , "consistent sentinels"); ::breakpoint(); } } while (0); |
5049 | // look for the finite support of the other memory |
5050 | for (uint i = other->req(); --i >= req(); ) { |
5051 | if (other->in(i) != empty_mem) { |
5052 | uint new_len = i+1; |
5053 | while (req() < new_len) add_req(empty_mem); |
5054 | break; |
5055 | } |
5056 | } |
5057 | } |
5058 | |
5059 | //---------------------------verify_sparse------------------------------------- |
5060 | #ifndef PRODUCT |
5061 | bool MergeMemNode::verify_sparse() const { |
5062 | assert(is_empty_memory(make_empty_memory()), "sane sentinel")do { if (!(is_empty_memory(make_empty_memory()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 5062, "assert(" "is_empty_memory(make_empty_memory())" ") failed" , "sane sentinel"); ::breakpoint(); } } while (0); |
5063 | Node* base_mem = base_memory(); |
5064 | // The following can happen in degenerate cases, since empty==top. |
5065 | if (is_empty_memory(base_mem)) return true; |
5066 | for (uint i = Compile::AliasIdxRaw; i < req(); i++) { |
5067 | assert(in(i) != NULL, "sane slice")do { if (!(in(i) != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/memnode.cpp" , 5067, "assert(" "in(i) != __null" ") failed", "sane slice") ; ::breakpoint(); } } while (0); |
5068 | if (in(i) == base_mem) return false; // should have been the sentinel value! |
5069 | } |
5070 | return true; |
5071 | } |
5072 | |
5073 | bool MergeMemStream::match_memory(Node* mem, const MergeMemNode* mm, int idx) { |
5074 | Node* n; |
5075 | n = mm->in(idx); |
5076 | if (mem == n) return true; // might be empty_memory() |
5077 | n = (idx == Compile::AliasIdxBot)? mm->base_memory(): mm->memory_at(idx); |
5078 | if (mem == n) return true; |
5079 | return false; |
5080 | } |
5081 | #endif // !PRODUCT |