1 /*
2 * Copyright (c) 1997, 2011, 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 *
34 // Optimization - Graph Style
35
36
37 // This class defines a Type lattice. The lattice is used in the constant
38 // propagation algorithms, and for some type-checking of the iloc code.
39 // Basic types include RSD's (lower bound, upper bound, stride for integers),
40 // float & double precision constants, sets of data-labels and code-labels.
41 // The complete lattice is described below. Subtypes have no relationship to
42 // up or down in the lattice; that is entirely determined by the behavior of
43 // the MEET/JOIN functions.
44
45 class Dict;
46 class Type;
47 class TypeD;
48 class TypeF;
49 class TypeInt;
50 class TypeLong;
51 class TypeNarrowOop;
52 class TypeAry;
53 class TypeTuple;
54 class TypePtr;
55 class TypeRawPtr;
56 class TypeOopPtr;
57 class TypeInstPtr;
58 class TypeAryPtr;
59 class TypeKlassPtr;
60
61 //------------------------------Type-------------------------------------------
62 // Basic Type object, represents a set of primitive Values.
63 // Types are hash-cons'd into a private class dictionary, so only one of each
64 // different kind of Type exists. Types are never modified after creation, so
65 // all their interesting fields are constant.
66 class Type {
67 friend class VMStructs;
68
69 public:
70 enum TYPES {
71 Bad=0, // Type check
72 Control, // Control of code (not in lattice)
73 Top, // Top of the lattice
74 Int, // Integer range (lo-hi)
75 Long, // Long integer range (lo-hi)
76 Half, // Placeholder half of doubleword
77 NarrowOop, // Compressed oop pointer
78
79 Tuple, // Method signature or object layout
80 Array, // Array types
81
82 AnyPtr, // Any old raw, klass, inst, or array pointer
83 RawPtr, // Raw (non-oop) pointers
84 OopPtr, // Any and all Java heap entities
85 InstPtr, // Instance pointers (non-array objects)
86 AryPtr, // Array pointers
87 KlassPtr, // Klass pointers
88 // (Ptr order matters: See is_ptr, isa_ptr, is_oopptr, isa_oopptr.)
89
90 Function, // Function signature
91 Abio, // Abstract I/O
92 Return_Address, // Subroutine return address
93 Memory, // Abstract store
94 FloatTop, // No float value
95 FloatCon, // Floating point constant
96 FloatBot, // Any float value
97 DoubleTop, // No double value
98 DoubleCon, // Double precision constant
99 DoubleBot, // Any double value
100 Bottom, // Bottom of lattice
205 #endif
206
207 // Returns true if this pointer points at memory which contains a
208 // compressed oop references.
209 bool is_ptr_to_narrowoop() const;
210
211 // Convenience access
212 float getf() const;
213 double getd() const;
214
215 const TypeInt *is_int() const;
216 const TypeInt *isa_int() const; // Returns NULL if not an Int
217 const TypeLong *is_long() const;
218 const TypeLong *isa_long() const; // Returns NULL if not a Long
219 const TypeD *is_double_constant() const; // Asserts it is a DoubleCon
220 const TypeD *isa_double_constant() const; // Returns NULL if not a DoubleCon
221 const TypeF *is_float_constant() const; // Asserts it is a FloatCon
222 const TypeF *isa_float_constant() const; // Returns NULL if not a FloatCon
223 const TypeTuple *is_tuple() const; // Collection of fields, NOT a pointer
224 const TypeAry *is_ary() const; // Array, NOT array pointer
225 const TypePtr *is_ptr() const; // Asserts it is a ptr type
226 const TypePtr *isa_ptr() const; // Returns NULL if not ptr type
227 const TypeRawPtr *isa_rawptr() const; // NOT Java oop
228 const TypeRawPtr *is_rawptr() const; // Asserts is rawptr
229 const TypeNarrowOop *is_narrowoop() const; // Java-style GC'd pointer
230 const TypeNarrowOop *isa_narrowoop() const; // Returns NULL if not oop ptr type
231 const TypeOopPtr *isa_oopptr() const; // Returns NULL if not oop ptr type
232 const TypeOopPtr *is_oopptr() const; // Java-style GC'd pointer
233 const TypeKlassPtr *isa_klassptr() const; // Returns NULL if not KlassPtr
234 const TypeKlassPtr *is_klassptr() const; // assert if not KlassPtr
235 const TypeInstPtr *isa_instptr() const; // Returns NULL if not InstPtr
236 const TypeInstPtr *is_instptr() const; // Instance
237 const TypeAryPtr *isa_aryptr() const; // Returns NULL if not AryPtr
238 const TypeAryPtr *is_aryptr() const; // Array oop
239 virtual bool is_finite() const; // Has a finite value
240 virtual bool is_nan() const; // Is not a number (NaN)
241
242 // Returns this ptr type or the equivalent ptr type for this compressed pointer.
243 const TypePtr* make_ptr() const;
244
557 private:
558 const Type *_elem; // Element type of array
559 const TypeInt *_size; // Elements in array
560 friend class TypeAryPtr;
561
562 public:
563 static const TypeAry *make( const Type *elem, const TypeInt *size);
564
565 virtual const Type *xmeet( const Type *t ) const;
566 virtual const Type *xdual() const; // Compute dual right now.
567 bool ary_must_be_exact() const; // true if arrays of such are never generic
568 #ifdef ASSERT
569 // One type is interface, the other is oop
570 virtual bool interface_vs_oop(const Type *t) const;
571 #endif
572 #ifndef PRODUCT
573 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
574 #endif
575 };
576
577 //------------------------------TypePtr----------------------------------------
578 // Class of machine Pointer Types: raw data, instances or arrays.
579 // If the _base enum is AnyPtr, then this refers to all of the above.
580 // Otherwise the _base will indicate which subset of pointers is affected,
581 // and the class will be inherited from.
582 class TypePtr : public Type {
583 friend class TypeNarrowOop;
584 public:
585 enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
586 protected:
587 TypePtr( TYPES t, PTR ptr, int offset ) : Type(t), _ptr(ptr), _offset(offset) {}
588 virtual bool eq( const Type *t ) const;
589 virtual int hash() const; // Type specific hashing
590 static const PTR ptr_meet[lastPTR][lastPTR];
591 static const PTR ptr_dual[lastPTR];
592 static const char * const ptr_msg[lastPTR];
593
594 public:
595 const int _offset; // Offset into oop, with TOP & BOT
596 const PTR _ptr; // Pointer equivalence class
1096
1097 inline const TypeLong *Type::is_long() const {
1098 assert( _base == Long, "Not a Long" );
1099 return (TypeLong*)this;
1100 }
1101
1102 inline const TypeLong *Type::isa_long() const {
1103 return ( _base == Long ? (TypeLong*)this : NULL);
1104 }
1105
1106 inline const TypeTuple *Type::is_tuple() const {
1107 assert( _base == Tuple, "Not a Tuple" );
1108 return (TypeTuple*)this;
1109 }
1110
1111 inline const TypeAry *Type::is_ary() const {
1112 assert( _base == Array , "Not an Array" );
1113 return (TypeAry*)this;
1114 }
1115
1116 inline const TypePtr *Type::is_ptr() const {
1117 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
1118 assert(_base >= AnyPtr && _base <= KlassPtr, "Not a pointer");
1119 return (TypePtr*)this;
1120 }
1121
1122 inline const TypePtr *Type::isa_ptr() const {
1123 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
1124 return (_base >= AnyPtr && _base <= KlassPtr) ? (TypePtr*)this : NULL;
1125 }
1126
1127 inline const TypeOopPtr *Type::is_oopptr() const {
1128 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1129 assert(_base >= OopPtr && _base <= KlassPtr, "Not a Java pointer" ) ;
1130 return (TypeOopPtr*)this;
1131 }
1132
1133 inline const TypeOopPtr *Type::isa_oopptr() const {
1134 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1135 return (_base >= OopPtr && _base <= KlassPtr) ? (TypeOopPtr*)this : NULL;
|
1 /*
2 * Copyright (c) 1997, 2012, 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 *
34 // Optimization - Graph Style
35
36
37 // This class defines a Type lattice. The lattice is used in the constant
38 // propagation algorithms, and for some type-checking of the iloc code.
39 // Basic types include RSD's (lower bound, upper bound, stride for integers),
40 // float & double precision constants, sets of data-labels and code-labels.
41 // The complete lattice is described below. Subtypes have no relationship to
42 // up or down in the lattice; that is entirely determined by the behavior of
43 // the MEET/JOIN functions.
44
45 class Dict;
46 class Type;
47 class TypeD;
48 class TypeF;
49 class TypeInt;
50 class TypeLong;
51 class TypeNarrowOop;
52 class TypeAry;
53 class TypeTuple;
54 class TypeVect;
55 class TypeVectS;
56 class TypeVectD;
57 class TypeVectX;
58 class TypeVectY;
59 class TypePtr;
60 class TypeRawPtr;
61 class TypeOopPtr;
62 class TypeInstPtr;
63 class TypeAryPtr;
64 class TypeKlassPtr;
65
66 //------------------------------Type-------------------------------------------
67 // Basic Type object, represents a set of primitive Values.
68 // Types are hash-cons'd into a private class dictionary, so only one of each
69 // different kind of Type exists. Types are never modified after creation, so
70 // all their interesting fields are constant.
71 class Type {
72 friend class VMStructs;
73
74 public:
75 enum TYPES {
76 Bad=0, // Type check
77 Control, // Control of code (not in lattice)
78 Top, // Top of the lattice
79 Int, // Integer range (lo-hi)
80 Long, // Long integer range (lo-hi)
81 Half, // Placeholder half of doubleword
82 NarrowOop, // Compressed oop pointer
83
84 Tuple, // Method signature or object layout
85 Array, // Array types
86 VectorS, // 32bit Vector types
87 VectorD, // 64bit Vector types
88 VectorX, // 128bit Vector types
89 VectorY, // 256bit Vector types
90
91 AnyPtr, // Any old raw, klass, inst, or array pointer
92 RawPtr, // Raw (non-oop) pointers
93 OopPtr, // Any and all Java heap entities
94 InstPtr, // Instance pointers (non-array objects)
95 AryPtr, // Array pointers
96 KlassPtr, // Klass pointers
97 // (Ptr order matters: See is_ptr, isa_ptr, is_oopptr, isa_oopptr.)
98
99 Function, // Function signature
100 Abio, // Abstract I/O
101 Return_Address, // Subroutine return address
102 Memory, // Abstract store
103 FloatTop, // No float value
104 FloatCon, // Floating point constant
105 FloatBot, // Any float value
106 DoubleTop, // No double value
107 DoubleCon, // Double precision constant
108 DoubleBot, // Any double value
109 Bottom, // Bottom of lattice
214 #endif
215
216 // Returns true if this pointer points at memory which contains a
217 // compressed oop references.
218 bool is_ptr_to_narrowoop() const;
219
220 // Convenience access
221 float getf() const;
222 double getd() const;
223
224 const TypeInt *is_int() const;
225 const TypeInt *isa_int() const; // Returns NULL if not an Int
226 const TypeLong *is_long() const;
227 const TypeLong *isa_long() const; // Returns NULL if not a Long
228 const TypeD *is_double_constant() const; // Asserts it is a DoubleCon
229 const TypeD *isa_double_constant() const; // Returns NULL if not a DoubleCon
230 const TypeF *is_float_constant() const; // Asserts it is a FloatCon
231 const TypeF *isa_float_constant() const; // Returns NULL if not a FloatCon
232 const TypeTuple *is_tuple() const; // Collection of fields, NOT a pointer
233 const TypeAry *is_ary() const; // Array, NOT array pointer
234 const TypeVect *is_vect() const; // Vector
235 const TypeVect *isa_vect() const; // Returns NULL if not a Vector
236 const TypePtr *is_ptr() const; // Asserts it is a ptr type
237 const TypePtr *isa_ptr() const; // Returns NULL if not ptr type
238 const TypeRawPtr *isa_rawptr() const; // NOT Java oop
239 const TypeRawPtr *is_rawptr() const; // Asserts is rawptr
240 const TypeNarrowOop *is_narrowoop() const; // Java-style GC'd pointer
241 const TypeNarrowOop *isa_narrowoop() const; // Returns NULL if not oop ptr type
242 const TypeOopPtr *isa_oopptr() const; // Returns NULL if not oop ptr type
243 const TypeOopPtr *is_oopptr() const; // Java-style GC'd pointer
244 const TypeKlassPtr *isa_klassptr() const; // Returns NULL if not KlassPtr
245 const TypeKlassPtr *is_klassptr() const; // assert if not KlassPtr
246 const TypeInstPtr *isa_instptr() const; // Returns NULL if not InstPtr
247 const TypeInstPtr *is_instptr() const; // Instance
248 const TypeAryPtr *isa_aryptr() const; // Returns NULL if not AryPtr
249 const TypeAryPtr *is_aryptr() const; // Array oop
250 virtual bool is_finite() const; // Has a finite value
251 virtual bool is_nan() const; // Is not a number (NaN)
252
253 // Returns this ptr type or the equivalent ptr type for this compressed pointer.
254 const TypePtr* make_ptr() const;
255
568 private:
569 const Type *_elem; // Element type of array
570 const TypeInt *_size; // Elements in array
571 friend class TypeAryPtr;
572
573 public:
574 static const TypeAry *make( const Type *elem, const TypeInt *size);
575
576 virtual const Type *xmeet( const Type *t ) const;
577 virtual const Type *xdual() const; // Compute dual right now.
578 bool ary_must_be_exact() const; // true if arrays of such are never generic
579 #ifdef ASSERT
580 // One type is interface, the other is oop
581 virtual bool interface_vs_oop(const Type *t) const;
582 #endif
583 #ifndef PRODUCT
584 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
585 #endif
586 };
587
588 //------------------------------TypeVect---------------------------------------
589 // Class of Vector Types
590 class TypeVect : public Type {
591 const Type* _elem; // Vector's element type
592 const uint _length; // Elements in vector (power of 2)
593
594 protected:
595 TypeVect(TYPES t, const Type* elem, uint length) : Type(t),
596 _elem(elem), _length(length) {}
597
598 public:
599 const Type* element_type() const { return _elem; }
600 BasicType element_basic_type() const { return _elem->array_element_basic_type(); }
601 uint length() const { return _length; }
602 uint length_in_bytes() const {
603 return _length * type2aelembytes(element_basic_type());
604 }
605
606 virtual bool eq(const Type *t) const;
607 virtual int hash() const; // Type specific hashing
608 virtual bool singleton(void) const; // TRUE if type is a singleton
609 virtual bool empty(void) const; // TRUE if type is vacuous
610
611 static const TypeVect *make(const BasicType elem_bt, uint length) {
612 // Use bottom primitive type.
613 return make(get_const_basic_type(elem_bt), length);
614 }
615 // Used directly by Replicate nodes to construct singleton vector.
616 static const TypeVect *make(const Type* elem, uint length);
617
618 virtual const Type *xmeet( const Type *t) const;
619 virtual const Type *xdual() const; // Compute dual right now.
620
621 static const TypeVect *VECTS;
622 static const TypeVect *VECTD;
623 static const TypeVect *VECTX;
624 static const TypeVect *VECTY;
625
626 #ifndef PRODUCT
627 virtual void dump2(Dict &d, uint, outputStream *st) const; // Specialized per-Type dumping
628 #endif
629 };
630
631 class TypeVectS : public TypeVect {
632 friend class TypeVect;
633 TypeVectS(const Type* elem, uint length) : TypeVect(VectorS, elem, length) {}
634 };
635
636 class TypeVectD : public TypeVect {
637 friend class TypeVect;
638 TypeVectD(const Type* elem, uint length) : TypeVect(VectorD, elem, length) {}
639 };
640
641 class TypeVectX : public TypeVect {
642 friend class TypeVect;
643 TypeVectX(const Type* elem, uint length) : TypeVect(VectorX, elem, length) {}
644 };
645
646 class TypeVectY : public TypeVect {
647 friend class TypeVect;
648 TypeVectY(const Type* elem, uint length) : TypeVect(VectorY, elem, length) {}
649 };
650
651 //------------------------------TypePtr----------------------------------------
652 // Class of machine Pointer Types: raw data, instances or arrays.
653 // If the _base enum is AnyPtr, then this refers to all of the above.
654 // Otherwise the _base will indicate which subset of pointers is affected,
655 // and the class will be inherited from.
656 class TypePtr : public Type {
657 friend class TypeNarrowOop;
658 public:
659 enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
660 protected:
661 TypePtr( TYPES t, PTR ptr, int offset ) : Type(t), _ptr(ptr), _offset(offset) {}
662 virtual bool eq( const Type *t ) const;
663 virtual int hash() const; // Type specific hashing
664 static const PTR ptr_meet[lastPTR][lastPTR];
665 static const PTR ptr_dual[lastPTR];
666 static const char * const ptr_msg[lastPTR];
667
668 public:
669 const int _offset; // Offset into oop, with TOP & BOT
670 const PTR _ptr; // Pointer equivalence class
1170
1171 inline const TypeLong *Type::is_long() const {
1172 assert( _base == Long, "Not a Long" );
1173 return (TypeLong*)this;
1174 }
1175
1176 inline const TypeLong *Type::isa_long() const {
1177 return ( _base == Long ? (TypeLong*)this : NULL);
1178 }
1179
1180 inline const TypeTuple *Type::is_tuple() const {
1181 assert( _base == Tuple, "Not a Tuple" );
1182 return (TypeTuple*)this;
1183 }
1184
1185 inline const TypeAry *Type::is_ary() const {
1186 assert( _base == Array , "Not an Array" );
1187 return (TypeAry*)this;
1188 }
1189
1190 inline const TypeVect *Type::is_vect() const {
1191 assert( _base >= VectorS && _base <= VectorY, "Not a Vector" );
1192 return (TypeVect*)this;
1193 }
1194
1195 inline const TypeVect *Type::isa_vect() const {
1196 return (_base >= VectorS && _base <= VectorY) ? (TypeVect*)this : NULL;
1197 }
1198
1199 inline const TypePtr *Type::is_ptr() const {
1200 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
1201 assert(_base >= AnyPtr && _base <= KlassPtr, "Not a pointer");
1202 return (TypePtr*)this;
1203 }
1204
1205 inline const TypePtr *Type::isa_ptr() const {
1206 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
1207 return (_base >= AnyPtr && _base <= KlassPtr) ? (TypePtr*)this : NULL;
1208 }
1209
1210 inline const TypeOopPtr *Type::is_oopptr() const {
1211 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1212 assert(_base >= OopPtr && _base <= KlassPtr, "Not a Java pointer" ) ;
1213 return (TypeOopPtr*)this;
1214 }
1215
1216 inline const TypeOopPtr *Type::isa_oopptr() const {
1217 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1218 return (_base >= OopPtr && _base <= KlassPtr) ? (TypeOopPtr*)this : NULL;
|