Wed, 09 Nov 2011 06:14:32 -0800
7109887: java/util/Arrays/CopyMethods.java fails with -XX:+DeoptimizeALot
Summary: zero array when compiled code is deoptimized.
Reviewed-by: never, twisti
1 /*
2 * Copyright (c) 1997, 2010, 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 */
25 #ifndef SHARE_VM_OPTO_SUBNODE_HPP
26 #define SHARE_VM_OPTO_SUBNODE_HPP
28 #include "opto/node.hpp"
29 #include "opto/opcodes.hpp"
30 #include "opto/type.hpp"
32 // Portions of code courtesy of Clifford Click
34 //------------------------------SUBNode----------------------------------------
35 // Class SUBTRACTION functionality. This covers all the usual 'subtract'
36 // behaviors. Subtract-integer, -float, -double, binary xor, compare-integer,
37 // -float, and -double are all inherited from this class. The compare
38 // functions behave like subtract functions, except that all negative answers
39 // are compressed into -1, and all positive answers compressed to 1.
40 class SubNode : public Node {
41 public:
42 SubNode( Node *in1, Node *in2 ) : Node(0,in1,in2) {
43 init_class_id(Class_Sub);
44 }
46 // Handle algebraic identities here. If we have an identity, return the Node
47 // we are equivalent to. We look for "add of zero" as an identity.
48 virtual Node *Identity( PhaseTransform *phase );
50 // Compute a new Type for this node. Basically we just do the pre-check,
51 // then call the virtual add() to set the type.
52 virtual const Type *Value( PhaseTransform *phase ) const;
54 // Supplied function returns the subtractend of the inputs.
55 // This also type-checks the inputs for sanity. Guaranteed never to
56 // be passed a TOP or BOTTOM type, these are filtered out by a pre-check.
57 virtual const Type *sub( const Type *, const Type * ) const = 0;
59 // Supplied function to return the additive identity type.
60 // This is returned whenever the subtracts inputs are the same.
61 virtual const Type *add_id() const = 0;
63 };
66 // NOTE: SubINode should be taken away and replaced by add and negate
67 //------------------------------SubINode---------------------------------------
68 // Subtract 2 integers
69 class SubINode : public SubNode {
70 public:
71 SubINode( Node *in1, Node *in2 ) : SubNode(in1,in2) {}
72 virtual int Opcode() const;
73 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
74 virtual const Type *sub( const Type *, const Type * ) const;
75 const Type *add_id() const { return TypeInt::ZERO; }
76 const Type *bottom_type() const { return TypeInt::INT; }
77 virtual uint ideal_reg() const { return Op_RegI; }
78 };
80 //------------------------------SubLNode---------------------------------------
81 // Subtract 2 integers
82 class SubLNode : public SubNode {
83 public:
84 SubLNode( Node *in1, Node *in2 ) : SubNode(in1,in2) {}
85 virtual int Opcode() const;
86 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
87 virtual const Type *sub( const Type *, const Type * ) const;
88 const Type *add_id() const { return TypeLong::ZERO; }
89 const Type *bottom_type() const { return TypeLong::LONG; }
90 virtual uint ideal_reg() const { return Op_RegL; }
91 };
93 // NOTE: SubFPNode should be taken away and replaced by add and negate
94 //------------------------------SubFPNode--------------------------------------
95 // Subtract 2 floats or doubles
96 class SubFPNode : public SubNode {
97 protected:
98 SubFPNode( Node *in1, Node *in2 ) : SubNode(in1,in2) {}
99 public:
100 const Type *Value( PhaseTransform *phase ) const;
101 };
103 // NOTE: SubFNode should be taken away and replaced by add and negate
104 //------------------------------SubFNode---------------------------------------
105 // Subtract 2 doubles
106 class SubFNode : public SubFPNode {
107 public:
108 SubFNode( Node *in1, Node *in2 ) : SubFPNode(in1,in2) {}
109 virtual int Opcode() const;
110 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
111 virtual const Type *sub( const Type *, const Type * ) const;
112 const Type *add_id() const { return TypeF::ZERO; }
113 const Type *bottom_type() const { return Type::FLOAT; }
114 virtual uint ideal_reg() const { return Op_RegF; }
115 };
117 // NOTE: SubDNode should be taken away and replaced by add and negate
118 //------------------------------SubDNode---------------------------------------
119 // Subtract 2 doubles
120 class SubDNode : public SubFPNode {
121 public:
122 SubDNode( Node *in1, Node *in2 ) : SubFPNode(in1,in2) {}
123 virtual int Opcode() const;
124 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
125 virtual const Type *sub( const Type *, const Type * ) const;
126 const Type *add_id() const { return TypeD::ZERO; }
127 const Type *bottom_type() const { return Type::DOUBLE; }
128 virtual uint ideal_reg() const { return Op_RegD; }
129 };
131 //------------------------------CmpNode---------------------------------------
132 // Compare 2 values, returning condition codes (-1, 0 or 1).
133 class CmpNode : public SubNode {
134 public:
135 CmpNode( Node *in1, Node *in2 ) : SubNode(in1,in2) {
136 init_class_id(Class_Cmp);
137 }
138 virtual Node *Identity( PhaseTransform *phase );
139 const Type *add_id() const { return TypeInt::ZERO; }
140 const Type *bottom_type() const { return TypeInt::CC; }
141 virtual uint ideal_reg() const { return Op_RegFlags; }
142 };
144 //------------------------------CmpINode---------------------------------------
145 // Compare 2 signed values, returning condition codes (-1, 0 or 1).
146 class CmpINode : public CmpNode {
147 public:
148 CmpINode( Node *in1, Node *in2 ) : CmpNode(in1,in2) {}
149 virtual int Opcode() const;
150 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
151 virtual const Type *sub( const Type *, const Type * ) const;
152 };
154 //------------------------------CmpUNode---------------------------------------
155 // Compare 2 unsigned values (integer or pointer), returning condition codes (-1, 0 or 1).
156 class CmpUNode : public CmpNode {
157 public:
158 CmpUNode( Node *in1, Node *in2 ) : CmpNode(in1,in2) {}
159 virtual int Opcode() const;
160 virtual const Type *sub( const Type *, const Type * ) const;
161 };
163 //------------------------------CmpPNode---------------------------------------
164 // Compare 2 pointer values, returning condition codes (-1, 0 or 1).
165 class CmpPNode : public CmpNode {
166 public:
167 CmpPNode( Node *in1, Node *in2 ) : CmpNode(in1,in2) {}
168 virtual int Opcode() const;
169 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
170 virtual const Type *sub( const Type *, const Type * ) const;
171 };
173 //------------------------------CmpNNode--------------------------------------
174 // Compare 2 narrow oop values, returning condition codes (-1, 0 or 1).
175 class CmpNNode : public CmpNode {
176 public:
177 CmpNNode( Node *in1, Node *in2 ) : CmpNode(in1,in2) {}
178 virtual int Opcode() const;
179 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
180 virtual const Type *sub( const Type *, const Type * ) const;
181 };
183 //------------------------------CmpLNode---------------------------------------
184 // Compare 2 long values, returning condition codes (-1, 0 or 1).
185 class CmpLNode : public CmpNode {
186 public:
187 CmpLNode( Node *in1, Node *in2 ) : CmpNode(in1,in2) {}
188 virtual int Opcode() const;
189 virtual const Type *sub( const Type *, const Type * ) const;
190 };
192 //------------------------------CmpL3Node--------------------------------------
193 // Compare 2 long values, returning integer value (-1, 0 or 1).
194 class CmpL3Node : public CmpLNode {
195 public:
196 CmpL3Node( Node *in1, Node *in2 ) : CmpLNode(in1,in2) {
197 // Since it is not consumed by Bools, it is not really a Cmp.
198 init_class_id(Class_Sub);
199 }
200 virtual int Opcode() const;
201 virtual uint ideal_reg() const { return Op_RegI; }
202 };
204 //------------------------------CmpFNode---------------------------------------
205 // Compare 2 float values, returning condition codes (-1, 0 or 1).
206 // This implements the Java bytecode fcmpl, so unordered returns -1.
207 // Operands may not commute.
208 class CmpFNode : public CmpNode {
209 public:
210 CmpFNode( Node *in1, Node *in2 ) : CmpNode(in1,in2) {}
211 virtual int Opcode() const;
212 virtual const Type *sub( const Type *, const Type * ) const { ShouldNotReachHere(); return NULL; }
213 const Type *Value( PhaseTransform *phase ) const;
214 };
216 //------------------------------CmpF3Node--------------------------------------
217 // Compare 2 float values, returning integer value (-1, 0 or 1).
218 // This implements the Java bytecode fcmpl, so unordered returns -1.
219 // Operands may not commute.
220 class CmpF3Node : public CmpFNode {
221 public:
222 CmpF3Node( Node *in1, Node *in2 ) : CmpFNode(in1,in2) {
223 // Since it is not consumed by Bools, it is not really a Cmp.
224 init_class_id(Class_Sub);
225 }
226 virtual int Opcode() const;
227 // Since it is not consumed by Bools, it is not really a Cmp.
228 virtual uint ideal_reg() const { return Op_RegI; }
229 };
232 //------------------------------CmpDNode---------------------------------------
233 // Compare 2 double values, returning condition codes (-1, 0 or 1).
234 // This implements the Java bytecode dcmpl, so unordered returns -1.
235 // Operands may not commute.
236 class CmpDNode : public CmpNode {
237 public:
238 CmpDNode( Node *in1, Node *in2 ) : CmpNode(in1,in2) {}
239 virtual int Opcode() const;
240 virtual const Type *sub( const Type *, const Type * ) const { ShouldNotReachHere(); return NULL; }
241 const Type *Value( PhaseTransform *phase ) const;
242 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
243 };
245 //------------------------------CmpD3Node--------------------------------------
246 // Compare 2 double values, returning integer value (-1, 0 or 1).
247 // This implements the Java bytecode dcmpl, so unordered returns -1.
248 // Operands may not commute.
249 class CmpD3Node : public CmpDNode {
250 public:
251 CmpD3Node( Node *in1, Node *in2 ) : CmpDNode(in1,in2) {
252 // Since it is not consumed by Bools, it is not really a Cmp.
253 init_class_id(Class_Sub);
254 }
255 virtual int Opcode() const;
256 virtual uint ideal_reg() const { return Op_RegI; }
257 };
260 //------------------------------BoolTest---------------------------------------
261 // Convert condition codes to a boolean test value (0 or -1).
262 // We pick the values as 3 bits; the low order 2 bits we compare against the
263 // condition codes, the high bit flips the sense of the result.
264 struct BoolTest VALUE_OBJ_CLASS_SPEC {
265 enum mask { eq = 0, ne = 4, le = 5, ge = 7, lt = 3, gt = 1, illegal = 8 };
266 mask _test;
267 BoolTest( mask btm ) : _test(btm) {}
268 const Type *cc2logical( const Type *CC ) const;
269 // Commute the test. I use a small table lookup. The table is created as
270 // a simple char array where each element is the ASCII version of a 'mask'
271 // enum from above.
272 mask commute( ) const { return mask("038147858"[_test]-'0'); }
273 mask negate( ) const { return mask(_test^4); }
274 bool is_canonical( ) const { return (_test == BoolTest::ne || _test == BoolTest::lt || _test == BoolTest::le); }
275 #ifndef PRODUCT
276 void dump_on(outputStream *st) const;
277 #endif
278 };
280 //------------------------------BoolNode---------------------------------------
281 // A Node to convert a Condition Codes to a Logical result.
282 class BoolNode : public Node {
283 virtual uint hash() const;
284 virtual uint cmp( const Node &n ) const;
285 virtual uint size_of() const;
286 public:
287 const BoolTest _test;
288 BoolNode( Node *cc, BoolTest::mask t): _test(t), Node(0,cc) {
289 init_class_id(Class_Bool);
290 }
291 // Convert an arbitrary int value to a Bool or other suitable predicate.
292 static Node* make_predicate(Node* test_value, PhaseGVN* phase);
293 // Convert self back to an integer value.
294 Node* as_int_value(PhaseGVN* phase);
295 // Invert sense of self, returning new Bool.
296 BoolNode* negate(PhaseGVN* phase);
297 virtual int Opcode() const;
298 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
299 virtual const Type *Value( PhaseTransform *phase ) const;
300 virtual const Type *bottom_type() const { return TypeInt::BOOL; }
301 uint match_edge(uint idx) const { return 0; }
302 virtual uint ideal_reg() const { return Op_RegI; }
304 bool is_counted_loop_exit_test();
305 #ifndef PRODUCT
306 virtual void dump_spec(outputStream *st) const;
307 #endif
308 };
310 //------------------------------AbsNode----------------------------------------
311 // Abstract class for absolute value. Mostly used to get a handy wrapper
312 // for finding this pattern in the graph.
313 class AbsNode : public Node {
314 public:
315 AbsNode( Node *value ) : Node(0,value) {}
316 };
318 //------------------------------AbsINode---------------------------------------
319 // Absolute value an integer. Since a naive graph involves control flow, we
320 // "match" it in the ideal world (so the control flow can be removed).
321 class AbsINode : public AbsNode {
322 public:
323 AbsINode( Node *in1 ) : AbsNode(in1) {}
324 virtual int Opcode() const;
325 const Type *bottom_type() const { return TypeInt::INT; }
326 virtual uint ideal_reg() const { return Op_RegI; }
327 };
329 //------------------------------AbsFNode---------------------------------------
330 // Absolute value a float, a common float-point idiom with a cheap hardware
331 // implemention on most chips. Since a naive graph involves control flow, we
332 // "match" it in the ideal world (so the control flow can be removed).
333 class AbsFNode : public AbsNode {
334 public:
335 AbsFNode( Node *in1 ) : AbsNode(in1) {}
336 virtual int Opcode() const;
337 const Type *bottom_type() const { return Type::FLOAT; }
338 virtual uint ideal_reg() const { return Op_RegF; }
339 };
341 //------------------------------AbsDNode---------------------------------------
342 // Absolute value a double, a common float-point idiom with a cheap hardware
343 // implemention on most chips. Since a naive graph involves control flow, we
344 // "match" it in the ideal world (so the control flow can be removed).
345 class AbsDNode : public AbsNode {
346 public:
347 AbsDNode( Node *in1 ) : AbsNode(in1) {}
348 virtual int Opcode() const;
349 const Type *bottom_type() const { return Type::DOUBLE; }
350 virtual uint ideal_reg() const { return Op_RegD; }
351 };
354 //------------------------------CmpLTMaskNode----------------------------------
355 // If p < q, return -1 else return 0. Nice for flow-free idioms.
356 class CmpLTMaskNode : public Node {
357 public:
358 CmpLTMaskNode( Node *p, Node *q ) : Node(0, p, q) {}
359 virtual int Opcode() const;
360 const Type *bottom_type() const { return TypeInt::INT; }
361 virtual uint ideal_reg() const { return Op_RegI; }
362 };
365 //------------------------------NegNode----------------------------------------
366 class NegNode : public Node {
367 public:
368 NegNode( Node *in1 ) : Node(0,in1) {}
369 };
371 //------------------------------NegFNode---------------------------------------
372 // Negate value a float. Negating 0.0 returns -0.0, but subtracting from
373 // zero returns +0.0 (per JVM spec on 'fneg' bytecode). As subtraction
374 // cannot be used to replace negation we have to implement negation as ideal
375 // node; note that negation and addition can replace subtraction.
376 class NegFNode : public NegNode {
377 public:
378 NegFNode( Node *in1 ) : NegNode(in1) {}
379 virtual int Opcode() const;
380 const Type *bottom_type() const { return Type::FLOAT; }
381 virtual uint ideal_reg() const { return Op_RegF; }
382 };
384 //------------------------------NegDNode---------------------------------------
385 // Negate value a double. Negating 0.0 returns -0.0, but subtracting from
386 // zero returns +0.0 (per JVM spec on 'dneg' bytecode). As subtraction
387 // cannot be used to replace negation we have to implement negation as ideal
388 // node; note that negation and addition can replace subtraction.
389 class NegDNode : public NegNode {
390 public:
391 NegDNode( Node *in1 ) : NegNode(in1) {}
392 virtual int Opcode() const;
393 const Type *bottom_type() const { return Type::DOUBLE; }
394 virtual uint ideal_reg() const { return Op_RegD; }
395 };
397 //------------------------------CosDNode---------------------------------------
398 // Cosinus of a double
399 class CosDNode : public Node {
400 public:
401 CosDNode( Node *in1 ) : Node(0, in1) {}
402 virtual int Opcode() const;
403 const Type *bottom_type() const { return Type::DOUBLE; }
404 virtual uint ideal_reg() const { return Op_RegD; }
405 virtual const Type *Value( PhaseTransform *phase ) const;
406 };
408 //------------------------------CosDNode---------------------------------------
409 // Sinus of a double
410 class SinDNode : public Node {
411 public:
412 SinDNode( Node *in1 ) : Node(0, in1) {}
413 virtual int Opcode() const;
414 const Type *bottom_type() const { return Type::DOUBLE; }
415 virtual uint ideal_reg() const { return Op_RegD; }
416 virtual const Type *Value( PhaseTransform *phase ) const;
417 };
420 //------------------------------TanDNode---------------------------------------
421 // tangens of a double
422 class TanDNode : public Node {
423 public:
424 TanDNode(Node *in1 ) : Node(0, in1) {}
425 virtual int Opcode() const;
426 const Type *bottom_type() const { return Type::DOUBLE; }
427 virtual uint ideal_reg() const { return Op_RegD; }
428 virtual const Type *Value( PhaseTransform *phase ) const;
429 };
432 //------------------------------AtanDNode--------------------------------------
433 // arcus tangens of a double
434 class AtanDNode : public Node {
435 public:
436 AtanDNode(Node *c, Node *in1, Node *in2 ) : Node(c, in1, in2) {}
437 virtual int Opcode() const;
438 const Type *bottom_type() const { return Type::DOUBLE; }
439 virtual uint ideal_reg() const { return Op_RegD; }
440 };
443 //------------------------------SqrtDNode--------------------------------------
444 // square root a double
445 class SqrtDNode : public Node {
446 public:
447 SqrtDNode(Node *c, Node *in1 ) : Node(c, in1) {}
448 virtual int Opcode() const;
449 const Type *bottom_type() const { return Type::DOUBLE; }
450 virtual uint ideal_reg() const { return Op_RegD; }
451 virtual const Type *Value( PhaseTransform *phase ) const;
452 };
454 //------------------------------ExpDNode---------------------------------------
455 // Exponentiate a double
456 class ExpDNode : public Node {
457 public:
458 ExpDNode( Node *c, Node *in1 ) : Node(c, in1) {}
459 virtual int Opcode() const;
460 const Type *bottom_type() const { return Type::DOUBLE; }
461 virtual uint ideal_reg() const { return Op_RegD; }
462 virtual const Type *Value( PhaseTransform *phase ) const;
463 };
465 //------------------------------LogDNode---------------------------------------
466 // Log_e of a double
467 class LogDNode : public Node {
468 public:
469 LogDNode( Node *in1 ) : Node(0, in1) {}
470 virtual int Opcode() const;
471 const Type *bottom_type() const { return Type::DOUBLE; }
472 virtual uint ideal_reg() const { return Op_RegD; }
473 virtual const Type *Value( PhaseTransform *phase ) const;
474 };
476 //------------------------------Log10DNode---------------------------------------
477 // Log_10 of a double
478 class Log10DNode : public Node {
479 public:
480 Log10DNode( Node *in1 ) : Node(0, in1) {}
481 virtual int Opcode() const;
482 const Type *bottom_type() const { return Type::DOUBLE; }
483 virtual uint ideal_reg() const { return Op_RegD; }
484 virtual const Type *Value( PhaseTransform *phase ) const;
485 };
487 //------------------------------PowDNode---------------------------------------
488 // Raise a double to a double power
489 class PowDNode : public Node {
490 public:
491 PowDNode(Node *c, Node *in1, Node *in2 ) : Node(c, in1, in2) {}
492 virtual int Opcode() const;
493 const Type *bottom_type() const { return Type::DOUBLE; }
494 virtual uint ideal_reg() const { return Op_RegD; }
495 virtual const Type *Value( PhaseTransform *phase ) const;
496 };
498 //-------------------------------ReverseBytesINode--------------------------------
499 // reverse bytes of an integer
500 class ReverseBytesINode : public Node {
501 public:
502 ReverseBytesINode(Node *c, Node *in1) : Node(c, in1) {}
503 virtual int Opcode() const;
504 const Type *bottom_type() const { return TypeInt::INT; }
505 virtual uint ideal_reg() const { return Op_RegI; }
506 };
508 //-------------------------------ReverseBytesLNode--------------------------------
509 // reverse bytes of a long
510 class ReverseBytesLNode : public Node {
511 public:
512 ReverseBytesLNode(Node *c, Node *in1) : Node(c, in1) {}
513 virtual int Opcode() const;
514 const Type *bottom_type() const { return TypeLong::LONG; }
515 virtual uint ideal_reg() const { return Op_RegL; }
516 };
518 //-------------------------------ReverseBytesUSNode--------------------------------
519 // reverse bytes of an unsigned short / char
520 class ReverseBytesUSNode : public Node {
521 public:
522 ReverseBytesUSNode(Node *c, Node *in1) : Node(c, in1) {}
523 virtual int Opcode() const;
524 const Type *bottom_type() const { return TypeInt::CHAR; }
525 virtual uint ideal_reg() const { return Op_RegI; }
526 };
528 //-------------------------------ReverseBytesSNode--------------------------------
529 // reverse bytes of a short
530 class ReverseBytesSNode : public Node {
531 public:
532 ReverseBytesSNode(Node *c, Node *in1) : Node(c, in1) {}
533 virtual int Opcode() const;
534 const Type *bottom_type() const { return TypeInt::SHORT; }
535 virtual uint ideal_reg() const { return Op_RegI; }
536 };
538 #endif // SHARE_VM_OPTO_SUBNODE_HPP