0
|
1 /*
|
|
2 * Copyright 1997-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 * have any questions.
|
|
22 *
|
|
23 */
|
|
24
|
|
25 // Portions of code courtesy of Clifford Click
|
|
26
|
|
27 // Optimization - Graph Style
|
|
28
|
|
29 #include "incls/_precompiled.incl"
|
|
30 #include "incls/_type.cpp.incl"
|
|
31
|
|
32 // Dictionary of types shared among compilations.
|
|
33 Dict* Type::_shared_type_dict = NULL;
|
|
34
|
|
35 // Array which maps compiler types to Basic Types
|
|
36 const BasicType Type::_basic_type[Type::lastype] = {
|
|
37 T_ILLEGAL, // Bad
|
|
38 T_ILLEGAL, // Control
|
|
39 T_VOID, // Top
|
|
40 T_INT, // Int
|
|
41 T_LONG, // Long
|
|
42 T_VOID, // Half
|
|
43
|
|
44 T_ILLEGAL, // Tuple
|
|
45 T_ARRAY, // Array
|
|
46
|
|
47 T_ADDRESS, // AnyPtr // shows up in factory methods for NULL_PTR
|
|
48 T_ADDRESS, // RawPtr
|
|
49 T_OBJECT, // OopPtr
|
|
50 T_OBJECT, // InstPtr
|
|
51 T_OBJECT, // AryPtr
|
|
52 T_OBJECT, // KlassPtr
|
|
53
|
|
54 T_OBJECT, // Function
|
|
55 T_ILLEGAL, // Abio
|
|
56 T_ADDRESS, // Return_Address
|
|
57 T_ILLEGAL, // Memory
|
|
58 T_FLOAT, // FloatTop
|
|
59 T_FLOAT, // FloatCon
|
|
60 T_FLOAT, // FloatBot
|
|
61 T_DOUBLE, // DoubleTop
|
|
62 T_DOUBLE, // DoubleCon
|
|
63 T_DOUBLE, // DoubleBot
|
|
64 T_ILLEGAL, // Bottom
|
|
65 };
|
|
66
|
|
67 // Map ideal registers (machine types) to ideal types
|
|
68 const Type *Type::mreg2type[_last_machine_leaf];
|
|
69
|
|
70 // Map basic types to canonical Type* pointers.
|
|
71 const Type* Type:: _const_basic_type[T_CONFLICT+1];
|
|
72
|
|
73 // Map basic types to constant-zero Types.
|
|
74 const Type* Type:: _zero_type[T_CONFLICT+1];
|
|
75
|
|
76 // Map basic types to array-body alias types.
|
|
77 const TypeAryPtr* TypeAryPtr::_array_body_type[T_CONFLICT+1];
|
|
78
|
|
79 //=============================================================================
|
|
80 // Convenience common pre-built types.
|
|
81 const Type *Type::ABIO; // State-of-machine only
|
|
82 const Type *Type::BOTTOM; // All values
|
|
83 const Type *Type::CONTROL; // Control only
|
|
84 const Type *Type::DOUBLE; // All doubles
|
|
85 const Type *Type::FLOAT; // All floats
|
|
86 const Type *Type::HALF; // Placeholder half of doublewide type
|
|
87 const Type *Type::MEMORY; // Abstract store only
|
|
88 const Type *Type::RETURN_ADDRESS;
|
|
89 const Type *Type::TOP; // No values in set
|
|
90
|
|
91 //------------------------------get_const_type---------------------------
|
|
92 const Type* Type::get_const_type(ciType* type) {
|
|
93 if (type == NULL) {
|
|
94 return NULL;
|
|
95 } else if (type->is_primitive_type()) {
|
|
96 return get_const_basic_type(type->basic_type());
|
|
97 } else {
|
|
98 return TypeOopPtr::make_from_klass(type->as_klass());
|
|
99 }
|
|
100 }
|
|
101
|
|
102 //---------------------------array_element_basic_type---------------------------------
|
|
103 // Mapping to the array element's basic type.
|
|
104 BasicType Type::array_element_basic_type() const {
|
|
105 BasicType bt = basic_type();
|
|
106 if (bt == T_INT) {
|
|
107 if (this == TypeInt::INT) return T_INT;
|
|
108 if (this == TypeInt::CHAR) return T_CHAR;
|
|
109 if (this == TypeInt::BYTE) return T_BYTE;
|
|
110 if (this == TypeInt::BOOL) return T_BOOLEAN;
|
|
111 if (this == TypeInt::SHORT) return T_SHORT;
|
|
112 return T_VOID;
|
|
113 }
|
|
114 return bt;
|
|
115 }
|
|
116
|
|
117 //---------------------------get_typeflow_type---------------------------------
|
|
118 // Import a type produced by ciTypeFlow.
|
|
119 const Type* Type::get_typeflow_type(ciType* type) {
|
|
120 switch (type->basic_type()) {
|
|
121
|
|
122 case ciTypeFlow::StateVector::T_BOTTOM:
|
|
123 assert(type == ciTypeFlow::StateVector::bottom_type(), "");
|
|
124 return Type::BOTTOM;
|
|
125
|
|
126 case ciTypeFlow::StateVector::T_TOP:
|
|
127 assert(type == ciTypeFlow::StateVector::top_type(), "");
|
|
128 return Type::TOP;
|
|
129
|
|
130 case ciTypeFlow::StateVector::T_NULL:
|
|
131 assert(type == ciTypeFlow::StateVector::null_type(), "");
|
|
132 return TypePtr::NULL_PTR;
|
|
133
|
|
134 case ciTypeFlow::StateVector::T_LONG2:
|
|
135 // The ciTypeFlow pass pushes a long, then the half.
|
|
136 // We do the same.
|
|
137 assert(type == ciTypeFlow::StateVector::long2_type(), "");
|
|
138 return TypeInt::TOP;
|
|
139
|
|
140 case ciTypeFlow::StateVector::T_DOUBLE2:
|
|
141 // The ciTypeFlow pass pushes double, then the half.
|
|
142 // Our convention is the same.
|
|
143 assert(type == ciTypeFlow::StateVector::double2_type(), "");
|
|
144 return Type::TOP;
|
|
145
|
|
146 case T_ADDRESS:
|
|
147 assert(type->is_return_address(), "");
|
|
148 return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
|
|
149
|
|
150 default:
|
|
151 // make sure we did not mix up the cases:
|
|
152 assert(type != ciTypeFlow::StateVector::bottom_type(), "");
|
|
153 assert(type != ciTypeFlow::StateVector::top_type(), "");
|
|
154 assert(type != ciTypeFlow::StateVector::null_type(), "");
|
|
155 assert(type != ciTypeFlow::StateVector::long2_type(), "");
|
|
156 assert(type != ciTypeFlow::StateVector::double2_type(), "");
|
|
157 assert(!type->is_return_address(), "");
|
|
158
|
|
159 return Type::get_const_type(type);
|
|
160 }
|
|
161 }
|
|
162
|
|
163
|
|
164 //------------------------------make-------------------------------------------
|
|
165 // Create a simple Type, with default empty symbol sets. Then hashcons it
|
|
166 // and look for an existing copy in the type dictionary.
|
|
167 const Type *Type::make( enum TYPES t ) {
|
|
168 return (new Type(t))->hashcons();
|
|
169 }
|
|
170
|
|
171 //------------------------------cmp--------------------------------------------
|
|
172 int Type::cmp( const Type *const t1, const Type *const t2 ) {
|
|
173 if( t1->_base != t2->_base )
|
|
174 return 1; // Missed badly
|
|
175 assert(t1 != t2 || t1->eq(t2), "eq must be reflexive");
|
|
176 return !t1->eq(t2); // Return ZERO if equal
|
|
177 }
|
|
178
|
|
179 //------------------------------hash-------------------------------------------
|
|
180 int Type::uhash( const Type *const t ) {
|
|
181 return t->hash();
|
|
182 }
|
|
183
|
|
184 //--------------------------Initialize_shared----------------------------------
|
|
185 void Type::Initialize_shared(Compile* current) {
|
|
186 // This method does not need to be locked because the first system
|
|
187 // compilations (stub compilations) occur serially. If they are
|
|
188 // changed to proceed in parallel, then this section will need
|
|
189 // locking.
|
|
190
|
|
191 Arena* save = current->type_arena();
|
|
192 Arena* shared_type_arena = new Arena();
|
|
193
|
|
194 current->set_type_arena(shared_type_arena);
|
|
195 _shared_type_dict =
|
|
196 new (shared_type_arena) Dict( (CmpKey)Type::cmp, (Hash)Type::uhash,
|
|
197 shared_type_arena, 128 );
|
|
198 current->set_type_dict(_shared_type_dict);
|
|
199
|
|
200 // Make shared pre-built types.
|
|
201 CONTROL = make(Control); // Control only
|
|
202 TOP = make(Top); // No values in set
|
|
203 MEMORY = make(Memory); // Abstract store only
|
|
204 ABIO = make(Abio); // State-of-machine only
|
|
205 RETURN_ADDRESS=make(Return_Address);
|
|
206 FLOAT = make(FloatBot); // All floats
|
|
207 DOUBLE = make(DoubleBot); // All doubles
|
|
208 BOTTOM = make(Bottom); // Everything
|
|
209 HALF = make(Half); // Placeholder half of doublewide type
|
|
210
|
|
211 TypeF::ZERO = TypeF::make(0.0); // Float 0 (positive zero)
|
|
212 TypeF::ONE = TypeF::make(1.0); // Float 1
|
|
213
|
|
214 TypeD::ZERO = TypeD::make(0.0); // Double 0 (positive zero)
|
|
215 TypeD::ONE = TypeD::make(1.0); // Double 1
|
|
216
|
|
217 TypeInt::MINUS_1 = TypeInt::make(-1); // -1
|
|
218 TypeInt::ZERO = TypeInt::make( 0); // 0
|
|
219 TypeInt::ONE = TypeInt::make( 1); // 1
|
|
220 TypeInt::BOOL = TypeInt::make(0,1, WidenMin); // 0 or 1, FALSE or TRUE.
|
|
221 TypeInt::CC = TypeInt::make(-1, 1, WidenMin); // -1, 0 or 1, condition codes
|
|
222 TypeInt::CC_LT = TypeInt::make(-1,-1, WidenMin); // == TypeInt::MINUS_1
|
|
223 TypeInt::CC_GT = TypeInt::make( 1, 1, WidenMin); // == TypeInt::ONE
|
|
224 TypeInt::CC_EQ = TypeInt::make( 0, 0, WidenMin); // == TypeInt::ZERO
|
|
225 TypeInt::CC_LE = TypeInt::make(-1, 0, WidenMin);
|
|
226 TypeInt::CC_GE = TypeInt::make( 0, 1, WidenMin); // == TypeInt::BOOL
|
|
227 TypeInt::BYTE = TypeInt::make(-128,127, WidenMin); // Bytes
|
|
228 TypeInt::CHAR = TypeInt::make(0,65535, WidenMin); // Java chars
|
|
229 TypeInt::SHORT = TypeInt::make(-32768,32767, WidenMin); // Java shorts
|
|
230 TypeInt::POS = TypeInt::make(0,max_jint, WidenMin); // Non-neg values
|
|
231 TypeInt::POS1 = TypeInt::make(1,max_jint, WidenMin); // Positive values
|
|
232 TypeInt::INT = TypeInt::make(min_jint,max_jint, WidenMax); // 32-bit integers
|
|
233 TypeInt::SYMINT = TypeInt::make(-max_jint,max_jint,WidenMin); // symmetric range
|
|
234 // CmpL is overloaded both as the bytecode computation returning
|
|
235 // a trinary (-1,0,+1) integer result AND as an efficient long
|
|
236 // compare returning optimizer ideal-type flags.
|
|
237 assert( TypeInt::CC_LT == TypeInt::MINUS_1, "types must match for CmpL to work" );
|
|
238 assert( TypeInt::CC_GT == TypeInt::ONE, "types must match for CmpL to work" );
|
|
239 assert( TypeInt::CC_EQ == TypeInt::ZERO, "types must match for CmpL to work" );
|
|
240 assert( TypeInt::CC_GE == TypeInt::BOOL, "types must match for CmpL to work" );
|
|
241
|
|
242 TypeLong::MINUS_1 = TypeLong::make(-1); // -1
|
|
243 TypeLong::ZERO = TypeLong::make( 0); // 0
|
|
244 TypeLong::ONE = TypeLong::make( 1); // 1
|
|
245 TypeLong::POS = TypeLong::make(0,max_jlong, WidenMin); // Non-neg values
|
|
246 TypeLong::LONG = TypeLong::make(min_jlong,max_jlong,WidenMax); // 64-bit integers
|
|
247 TypeLong::INT = TypeLong::make((jlong)min_jint,(jlong)max_jint,WidenMin);
|
|
248 TypeLong::UINT = TypeLong::make(0,(jlong)max_juint,WidenMin);
|
|
249
|
|
250 const Type **fboth =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
|
|
251 fboth[0] = Type::CONTROL;
|
|
252 fboth[1] = Type::CONTROL;
|
|
253 TypeTuple::IFBOTH = TypeTuple::make( 2, fboth );
|
|
254
|
|
255 const Type **ffalse =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
|
|
256 ffalse[0] = Type::CONTROL;
|
|
257 ffalse[1] = Type::TOP;
|
|
258 TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
|
|
259
|
|
260 const Type **fneither =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
|
|
261 fneither[0] = Type::TOP;
|
|
262 fneither[1] = Type::TOP;
|
|
263 TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
|
|
264
|
|
265 const Type **ftrue =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
|
|
266 ftrue[0] = Type::TOP;
|
|
267 ftrue[1] = Type::CONTROL;
|
|
268 TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
|
|
269
|
|
270 const Type **floop =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
|
|
271 floop[0] = Type::CONTROL;
|
|
272 floop[1] = TypeInt::INT;
|
|
273 TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
|
|
274
|
|
275 TypePtr::NULL_PTR= TypePtr::make( AnyPtr, TypePtr::Null, 0 );
|
|
276 TypePtr::NOTNULL = TypePtr::make( AnyPtr, TypePtr::NotNull, OffsetBot );
|
|
277 TypePtr::BOTTOM = TypePtr::make( AnyPtr, TypePtr::BotPTR, OffsetBot );
|
|
278
|
|
279 TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
|
|
280 TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
|
|
281
|
|
282 mreg2type[Op_Node] = Type::BOTTOM;
|
|
283 mreg2type[Op_Set ] = 0;
|
|
284 mreg2type[Op_RegI] = TypeInt::INT;
|
|
285 mreg2type[Op_RegP] = TypePtr::BOTTOM;
|
|
286 mreg2type[Op_RegF] = Type::FLOAT;
|
|
287 mreg2type[Op_RegD] = Type::DOUBLE;
|
|
288 mreg2type[Op_RegL] = TypeLong::LONG;
|
|
289 mreg2type[Op_RegFlags] = TypeInt::CC;
|
|
290
|
|
291 const Type **fmembar = TypeTuple::fields(0);
|
|
292 TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
|
|
293
|
|
294 const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
|
|
295 fsc[0] = TypeInt::CC;
|
|
296 fsc[1] = Type::MEMORY;
|
|
297 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
|
|
298
|
|
299 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
|
|
300 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
|
|
301 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
|
|
302 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
|
|
303 false, 0, oopDesc::mark_offset_in_bytes());
|
|
304 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
|
|
305 false, 0, oopDesc::klass_offset_in_bytes());
|
|
306 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot);
|
|
307
|
|
308 TypeAryPtr::RANGE = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), current->env()->Object_klass(), false, arrayOopDesc::length_offset_in_bytes());
|
|
309 // There is no shared klass for Object[]. See note in TypeAryPtr::klass().
|
|
310 TypeAryPtr::OOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
|
|
311 TypeAryPtr::BYTES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE), true, Type::OffsetBot);
|
|
312 TypeAryPtr::SHORTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT), true, Type::OffsetBot);
|
|
313 TypeAryPtr::CHARS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR), true, Type::OffsetBot);
|
|
314 TypeAryPtr::INTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT ,TypeInt::POS), ciTypeArrayKlass::make(T_INT), true, Type::OffsetBot);
|
|
315 TypeAryPtr::LONGS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG), true, Type::OffsetBot);
|
|
316 TypeAryPtr::FLOATS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT), true, Type::OffsetBot);
|
|
317 TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true, Type::OffsetBot);
|
|
318
|
|
319 TypeAryPtr::_array_body_type[T_OBJECT] = TypeAryPtr::OOPS;
|
|
320 TypeAryPtr::_array_body_type[T_ARRAY] = TypeAryPtr::OOPS; // arrays are stored in oop arrays
|
|
321 TypeAryPtr::_array_body_type[T_BYTE] = TypeAryPtr::BYTES;
|
|
322 TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES; // boolean[] is a byte array
|
|
323 TypeAryPtr::_array_body_type[T_SHORT] = TypeAryPtr::SHORTS;
|
|
324 TypeAryPtr::_array_body_type[T_CHAR] = TypeAryPtr::CHARS;
|
|
325 TypeAryPtr::_array_body_type[T_INT] = TypeAryPtr::INTS;
|
|
326 TypeAryPtr::_array_body_type[T_LONG] = TypeAryPtr::LONGS;
|
|
327 TypeAryPtr::_array_body_type[T_FLOAT] = TypeAryPtr::FLOATS;
|
|
328 TypeAryPtr::_array_body_type[T_DOUBLE] = TypeAryPtr::DOUBLES;
|
|
329
|
|
330 TypeKlassPtr::OBJECT = TypeKlassPtr::make( TypePtr::NotNull, current->env()->Object_klass(), 0 );
|
|
331 TypeKlassPtr::OBJECT_OR_NULL = TypeKlassPtr::make( TypePtr::BotPTR, current->env()->Object_klass(), 0 );
|
|
332
|
|
333 const Type **fi2c = TypeTuple::fields(2);
|
|
334 fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // methodOop
|
|
335 fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
|
|
336 TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
|
|
337
|
|
338 const Type **intpair = TypeTuple::fields(2);
|
|
339 intpair[0] = TypeInt::INT;
|
|
340 intpair[1] = TypeInt::INT;
|
|
341 TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
|
|
342
|
|
343 const Type **longpair = TypeTuple::fields(2);
|
|
344 longpair[0] = TypeLong::LONG;
|
|
345 longpair[1] = TypeLong::LONG;
|
|
346 TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
|
|
347
|
|
348 _const_basic_type[T_BOOLEAN] = TypeInt::BOOL;
|
|
349 _const_basic_type[T_CHAR] = TypeInt::CHAR;
|
|
350 _const_basic_type[T_BYTE] = TypeInt::BYTE;
|
|
351 _const_basic_type[T_SHORT] = TypeInt::SHORT;
|
|
352 _const_basic_type[T_INT] = TypeInt::INT;
|
|
353 _const_basic_type[T_LONG] = TypeLong::LONG;
|
|
354 _const_basic_type[T_FLOAT] = Type::FLOAT;
|
|
355 _const_basic_type[T_DOUBLE] = Type::DOUBLE;
|
|
356 _const_basic_type[T_OBJECT] = TypeInstPtr::BOTTOM;
|
|
357 _const_basic_type[T_ARRAY] = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
|
|
358 _const_basic_type[T_VOID] = TypePtr::NULL_PTR; // reflection represents void this way
|
|
359 _const_basic_type[T_ADDRESS] = TypeRawPtr::BOTTOM; // both interpreter return addresses & random raw ptrs
|
|
360 _const_basic_type[T_CONFLICT]= Type::BOTTOM; // why not?
|
|
361
|
|
362 _zero_type[T_BOOLEAN] = TypeInt::ZERO; // false == 0
|
|
363 _zero_type[T_CHAR] = TypeInt::ZERO; // '\0' == 0
|
|
364 _zero_type[T_BYTE] = TypeInt::ZERO; // 0x00 == 0
|
|
365 _zero_type[T_SHORT] = TypeInt::ZERO; // 0x0000 == 0
|
|
366 _zero_type[T_INT] = TypeInt::ZERO;
|
|
367 _zero_type[T_LONG] = TypeLong::ZERO;
|
|
368 _zero_type[T_FLOAT] = TypeF::ZERO;
|
|
369 _zero_type[T_DOUBLE] = TypeD::ZERO;
|
|
370 _zero_type[T_OBJECT] = TypePtr::NULL_PTR;
|
|
371 _zero_type[T_ARRAY] = TypePtr::NULL_PTR; // null array is null oop
|
|
372 _zero_type[T_ADDRESS] = TypePtr::NULL_PTR; // raw pointers use the same null
|
|
373 _zero_type[T_VOID] = Type::TOP; // the only void value is no value at all
|
|
374
|
|
375 // get_zero_type() should not happen for T_CONFLICT
|
|
376 _zero_type[T_CONFLICT]= NULL;
|
|
377
|
|
378 // Restore working type arena.
|
|
379 current->set_type_arena(save);
|
|
380 current->set_type_dict(NULL);
|
|
381 }
|
|
382
|
|
383 //------------------------------Initialize-------------------------------------
|
|
384 void Type::Initialize(Compile* current) {
|
|
385 assert(current->type_arena() != NULL, "must have created type arena");
|
|
386
|
|
387 if (_shared_type_dict == NULL) {
|
|
388 Initialize_shared(current);
|
|
389 }
|
|
390
|
|
391 Arena* type_arena = current->type_arena();
|
|
392
|
|
393 // Create the hash-cons'ing dictionary with top-level storage allocation
|
|
394 Dict *tdic = new (type_arena) Dict( (CmpKey)Type::cmp,(Hash)Type::uhash, type_arena, 128 );
|
|
395 current->set_type_dict(tdic);
|
|
396
|
|
397 // Transfer the shared types.
|
|
398 DictI i(_shared_type_dict);
|
|
399 for( ; i.test(); ++i ) {
|
|
400 Type* t = (Type*)i._value;
|
|
401 tdic->Insert(t,t); // New Type, insert into Type table
|
|
402 }
|
|
403 }
|
|
404
|
|
405 //------------------------------hashcons---------------------------------------
|
|
406 // Do the hash-cons trick. If the Type already exists in the type table,
|
|
407 // delete the current Type and return the existing Type. Otherwise stick the
|
|
408 // current Type in the Type table.
|
|
409 const Type *Type::hashcons(void) {
|
|
410 debug_only(base()); // Check the assertion in Type::base().
|
|
411 // Look up the Type in the Type dictionary
|
|
412 Dict *tdic = type_dict();
|
|
413 Type* old = (Type*)(tdic->Insert(this, this, false));
|
|
414 if( old ) { // Pre-existing Type?
|
|
415 if( old != this ) // Yes, this guy is not the pre-existing?
|
|
416 delete this; // Yes, Nuke this guy
|
|
417 assert( old->_dual, "" );
|
|
418 return old; // Return pre-existing
|
|
419 }
|
|
420
|
|
421 // Every type has a dual (to make my lattice symmetric).
|
|
422 // Since we just discovered a new Type, compute its dual right now.
|
|
423 assert( !_dual, "" ); // No dual yet
|
|
424 _dual = xdual(); // Compute the dual
|
|
425 if( cmp(this,_dual)==0 ) { // Handle self-symmetric
|
|
426 _dual = this;
|
|
427 return this;
|
|
428 }
|
|
429 assert( !_dual->_dual, "" ); // No reverse dual yet
|
|
430 assert( !(*tdic)[_dual], "" ); // Dual not in type system either
|
|
431 // New Type, insert into Type table
|
|
432 tdic->Insert((void*)_dual,(void*)_dual);
|
|
433 ((Type*)_dual)->_dual = this; // Finish up being symmetric
|
|
434 #ifdef ASSERT
|
|
435 Type *dual_dual = (Type*)_dual->xdual();
|
|
436 assert( eq(dual_dual), "xdual(xdual()) should be identity" );
|
|
437 delete dual_dual;
|
|
438 #endif
|
|
439 return this; // Return new Type
|
|
440 }
|
|
441
|
|
442 //------------------------------eq---------------------------------------------
|
|
443 // Structural equality check for Type representations
|
|
444 bool Type::eq( const Type * ) const {
|
|
445 return true; // Nothing else can go wrong
|
|
446 }
|
|
447
|
|
448 //------------------------------hash-------------------------------------------
|
|
449 // Type-specific hashing function.
|
|
450 int Type::hash(void) const {
|
|
451 return _base;
|
|
452 }
|
|
453
|
|
454 //------------------------------is_finite--------------------------------------
|
|
455 // Has a finite value
|
|
456 bool Type::is_finite() const {
|
|
457 return false;
|
|
458 }
|
|
459
|
|
460 //------------------------------is_nan-----------------------------------------
|
|
461 // Is not a number (NaN)
|
|
462 bool Type::is_nan() const {
|
|
463 return false;
|
|
464 }
|
|
465
|
|
466 //------------------------------meet-------------------------------------------
|
|
467 // Compute the MEET of two types. NOT virtual. It enforces that meet is
|
|
468 // commutative and the lattice is symmetric.
|
|
469 const Type *Type::meet( const Type *t ) const {
|
|
470 const Type *mt = xmeet(t);
|
|
471 #ifdef ASSERT
|
|
472 assert( mt == t->xmeet(this), "meet not commutative" );
|
|
473 const Type* dual_join = mt->_dual;
|
|
474 const Type *t2t = dual_join->xmeet(t->_dual);
|
|
475 const Type *t2this = dual_join->xmeet( _dual);
|
|
476
|
|
477 // Interface meet Oop is Not Symmetric:
|
|
478 // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
|
|
479 // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
|
|
480 const TypeInstPtr* this_inst = this->isa_instptr();
|
|
481 const TypeInstPtr* t_inst = t->isa_instptr();
|
|
482 bool interface_vs_oop = false;
|
|
483 if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) {
|
|
484 bool this_interface = this_inst->klass()->is_interface();
|
|
485 bool t_interface = t_inst->klass()->is_interface();
|
|
486 interface_vs_oop = this_interface ^ t_interface;
|
|
487 }
|
|
488 const Type *tdual = t->_dual;
|
|
489 const Type *thisdual = _dual;
|
|
490 // strip out instances
|
|
491 if (t2t->isa_oopptr() != NULL) {
|
|
492 t2t = t2t->isa_oopptr()->cast_to_instance(TypeOopPtr::UNKNOWN_INSTANCE);
|
|
493 }
|
|
494 if (t2this->isa_oopptr() != NULL) {
|
|
495 t2this = t2this->isa_oopptr()->cast_to_instance(TypeOopPtr::UNKNOWN_INSTANCE);
|
|
496 }
|
|
497 if (tdual->isa_oopptr() != NULL) {
|
|
498 tdual = tdual->isa_oopptr()->cast_to_instance(TypeOopPtr::UNKNOWN_INSTANCE);
|
|
499 }
|
|
500 if (thisdual->isa_oopptr() != NULL) {
|
|
501 thisdual = thisdual->isa_oopptr()->cast_to_instance(TypeOopPtr::UNKNOWN_INSTANCE);
|
|
502 }
|
|
503
|
|
504 if( !interface_vs_oop && (t2t != tdual || t2this != thisdual) ) {
|
|
505 tty->print_cr("=== Meet Not Symmetric ===");
|
|
506 tty->print("t = "); t->dump(); tty->cr();
|
|
507 tty->print("this= "); dump(); tty->cr();
|
|
508 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr();
|
|
509
|
|
510 tty->print("t_dual= "); t->_dual->dump(); tty->cr();
|
|
511 tty->print("this_dual= "); _dual->dump(); tty->cr();
|
|
512 tty->print("mt_dual= "); mt->_dual->dump(); tty->cr();
|
|
513
|
|
514 tty->print("mt_dual meet t_dual= "); t2t ->dump(); tty->cr();
|
|
515 tty->print("mt_dual meet this_dual= "); t2this ->dump(); tty->cr();
|
|
516
|
|
517 fatal("meet not symmetric" );
|
|
518 }
|
|
519 #endif
|
|
520 return mt;
|
|
521 }
|
|
522
|
|
523 //------------------------------xmeet------------------------------------------
|
|
524 // Compute the MEET of two types. It returns a new Type object.
|
|
525 const Type *Type::xmeet( const Type *t ) const {
|
|
526 // Perform a fast test for common case; meeting the same types together.
|
|
527 if( this == t ) return this; // Meeting same type-rep?
|
|
528
|
|
529 // Meeting TOP with anything?
|
|
530 if( _base == Top ) return t;
|
|
531
|
|
532 // Meeting BOTTOM with anything?
|
|
533 if( _base == Bottom ) return BOTTOM;
|
|
534
|
|
535 // Current "this->_base" is one of: Bad, Multi, Control, Top,
|
|
536 // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype.
|
|
537 switch (t->base()) { // Switch on original type
|
|
538
|
|
539 // Cut in half the number of cases I must handle. Only need cases for when
|
|
540 // the given enum "t->type" is less than or equal to the local enum "type".
|
|
541 case FloatCon:
|
|
542 case DoubleCon:
|
|
543 case Int:
|
|
544 case Long:
|
|
545 return t->xmeet(this);
|
|
546
|
|
547 case OopPtr:
|
|
548 return t->xmeet(this);
|
|
549
|
|
550 case InstPtr:
|
|
551 return t->xmeet(this);
|
|
552
|
|
553 case KlassPtr:
|
|
554 return t->xmeet(this);
|
|
555
|
|
556 case AryPtr:
|
|
557 return t->xmeet(this);
|
|
558
|
|
559 case Bad: // Type check
|
|
560 default: // Bogus type not in lattice
|
|
561 typerr(t);
|
|
562 return Type::BOTTOM;
|
|
563
|
|
564 case Bottom: // Ye Olde Default
|
|
565 return t;
|
|
566
|
|
567 case FloatTop:
|
|
568 if( _base == FloatTop ) return this;
|
|
569 case FloatBot: // Float
|
|
570 if( _base == FloatBot || _base == FloatTop ) return FLOAT;
|
|
571 if( _base == DoubleTop || _base == DoubleBot ) return Type::BOTTOM;
|
|
572 typerr(t);
|
|
573 return Type::BOTTOM;
|
|
574
|
|
575 case DoubleTop:
|
|
576 if( _base == DoubleTop ) return this;
|
|
577 case DoubleBot: // Double
|
|
578 if( _base == DoubleBot || _base == DoubleTop ) return DOUBLE;
|
|
579 if( _base == FloatTop || _base == FloatBot ) return Type::BOTTOM;
|
|
580 typerr(t);
|
|
581 return Type::BOTTOM;
|
|
582
|
|
583 // These next few cases must match exactly or it is a compile-time error.
|
|
584 case Control: // Control of code
|
|
585 case Abio: // State of world outside of program
|
|
586 case Memory:
|
|
587 if( _base == t->_base ) return this;
|
|
588 typerr(t);
|
|
589 return Type::BOTTOM;
|
|
590
|
|
591 case Top: // Top of the lattice
|
|
592 return this;
|
|
593 }
|
|
594
|
|
595 // The type is unchanged
|
|
596 return this;
|
|
597 }
|
|
598
|
|
599 //-----------------------------filter------------------------------------------
|
|
600 const Type *Type::filter( const Type *kills ) const {
|
|
601 const Type* ft = join(kills);
|
|
602 if (ft->empty())
|
|
603 return Type::TOP; // Canonical empty value
|
|
604 return ft;
|
|
605 }
|
|
606
|
|
607 //------------------------------xdual------------------------------------------
|
|
608 // Compute dual right now.
|
|
609 const Type::TYPES Type::dual_type[Type::lastype] = {
|
|
610 Bad, // Bad
|
|
611 Control, // Control
|
|
612 Bottom, // Top
|
|
613 Bad, // Int - handled in v-call
|
|
614 Bad, // Long - handled in v-call
|
|
615 Half, // Half
|
|
616
|
|
617 Bad, // Tuple - handled in v-call
|
|
618 Bad, // Array - handled in v-call
|
|
619
|
|
620 Bad, // AnyPtr - handled in v-call
|
|
621 Bad, // RawPtr - handled in v-call
|
|
622 Bad, // OopPtr - handled in v-call
|
|
623 Bad, // InstPtr - handled in v-call
|
|
624 Bad, // AryPtr - handled in v-call
|
|
625 Bad, // KlassPtr - handled in v-call
|
|
626
|
|
627 Bad, // Function - handled in v-call
|
|
628 Abio, // Abio
|
|
629 Return_Address,// Return_Address
|
|
630 Memory, // Memory
|
|
631 FloatBot, // FloatTop
|
|
632 FloatCon, // FloatCon
|
|
633 FloatTop, // FloatBot
|
|
634 DoubleBot, // DoubleTop
|
|
635 DoubleCon, // DoubleCon
|
|
636 DoubleTop, // DoubleBot
|
|
637 Top // Bottom
|
|
638 };
|
|
639
|
|
640 const Type *Type::xdual() const {
|
|
641 // Note: the base() accessor asserts the sanity of _base.
|
|
642 assert(dual_type[base()] != Bad, "implement with v-call");
|
|
643 return new Type(dual_type[_base]);
|
|
644 }
|
|
645
|
|
646 //------------------------------has_memory-------------------------------------
|
|
647 bool Type::has_memory() const {
|
|
648 Type::TYPES tx = base();
|
|
649 if (tx == Memory) return true;
|
|
650 if (tx == Tuple) {
|
|
651 const TypeTuple *t = is_tuple();
|
|
652 for (uint i=0; i < t->cnt(); i++) {
|
|
653 tx = t->field_at(i)->base();
|
|
654 if (tx == Memory) return true;
|
|
655 }
|
|
656 }
|
|
657 return false;
|
|
658 }
|
|
659
|
|
660 #ifndef PRODUCT
|
|
661 //------------------------------dump2------------------------------------------
|
|
662 void Type::dump2( Dict &d, uint depth, outputStream *st ) const {
|
|
663 st->print(msg[_base]);
|
|
664 }
|
|
665
|
|
666 //------------------------------dump-------------------------------------------
|
|
667 void Type::dump_on(outputStream *st) const {
|
|
668 ResourceMark rm;
|
|
669 Dict d(cmpkey,hashkey); // Stop recursive type dumping
|
|
670 dump2(d,1, st);
|
|
671 }
|
|
672
|
|
673 //------------------------------data-------------------------------------------
|
|
674 const char * const Type::msg[Type::lastype] = {
|
|
675 "bad","control","top","int:","long:","half",
|
|
676 "tuple:", "aryptr",
|
|
677 "anyptr:", "rawptr:", "java:", "inst:", "ary:", "klass:",
|
|
678 "func", "abIO", "return_address", "memory",
|
|
679 "float_top", "ftcon:", "float",
|
|
680 "double_top", "dblcon:", "double",
|
|
681 "bottom"
|
|
682 };
|
|
683 #endif
|
|
684
|
|
685 //------------------------------singleton--------------------------------------
|
|
686 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
|
|
687 // constants (Ldi nodes). Singletons are integer, float or double constants.
|
|
688 bool Type::singleton(void) const {
|
|
689 return _base == Top || _base == Half;
|
|
690 }
|
|
691
|
|
692 //------------------------------empty------------------------------------------
|
|
693 // TRUE if Type is a type with no values, FALSE otherwise.
|
|
694 bool Type::empty(void) const {
|
|
695 switch (_base) {
|
|
696 case DoubleTop:
|
|
697 case FloatTop:
|
|
698 case Top:
|
|
699 return true;
|
|
700
|
|
701 case Half:
|
|
702 case Abio:
|
|
703 case Return_Address:
|
|
704 case Memory:
|
|
705 case Bottom:
|
|
706 case FloatBot:
|
|
707 case DoubleBot:
|
|
708 return false; // never a singleton, therefore never empty
|
|
709 }
|
|
710
|
|
711 ShouldNotReachHere();
|
|
712 return false;
|
|
713 }
|
|
714
|
|
715 //------------------------------dump_stats-------------------------------------
|
|
716 // Dump collected statistics to stderr
|
|
717 #ifndef PRODUCT
|
|
718 void Type::dump_stats() {
|
|
719 tty->print("Types made: %d\n", type_dict()->Size());
|
|
720 }
|
|
721 #endif
|
|
722
|
|
723 //------------------------------typerr-----------------------------------------
|
|
724 void Type::typerr( const Type *t ) const {
|
|
725 #ifndef PRODUCT
|
|
726 tty->print("\nError mixing types: ");
|
|
727 dump();
|
|
728 tty->print(" and ");
|
|
729 t->dump();
|
|
730 tty->print("\n");
|
|
731 #endif
|
|
732 ShouldNotReachHere();
|
|
733 }
|
|
734
|
|
735 //------------------------------isa_oop_ptr------------------------------------
|
|
736 // Return true if type is an oop pointer type. False for raw pointers.
|
|
737 static char isa_oop_ptr_tbl[Type::lastype] = {
|
|
738 0,0,0,0,0,0,0/*tuple*/, 0/*ary*/,
|
|
739 0/*anyptr*/,0/*rawptr*/,1/*OopPtr*/,1/*InstPtr*/,1/*AryPtr*/,1/*KlassPtr*/,
|
|
740 0/*func*/,0,0/*return_address*/,0,
|
|
741 /*floats*/0,0,0, /*doubles*/0,0,0,
|
|
742 0
|
|
743 };
|
|
744 bool Type::isa_oop_ptr() const {
|
|
745 return isa_oop_ptr_tbl[_base] != 0;
|
|
746 }
|
|
747
|
|
748 //------------------------------dump_stats-------------------------------------
|
|
749 // // Check that arrays match type enum
|
|
750 #ifndef PRODUCT
|
|
751 void Type::verify_lastype() {
|
|
752 // Check that arrays match enumeration
|
|
753 assert( Type::dual_type [Type::lastype - 1] == Type::Top, "did not update array");
|
|
754 assert( strcmp(Type::msg [Type::lastype - 1],"bottom") == 0, "did not update array");
|
|
755 // assert( PhiNode::tbl [Type::lastype - 1] == NULL, "did not update array");
|
|
756 assert( Matcher::base2reg[Type::lastype - 1] == 0, "did not update array");
|
|
757 assert( isa_oop_ptr_tbl [Type::lastype - 1] == (char)0, "did not update array");
|
|
758 }
|
|
759 #endif
|
|
760
|
|
761 //=============================================================================
|
|
762 // Convenience common pre-built types.
|
|
763 const TypeF *TypeF::ZERO; // Floating point zero
|
|
764 const TypeF *TypeF::ONE; // Floating point one
|
|
765
|
|
766 //------------------------------make-------------------------------------------
|
|
767 // Create a float constant
|
|
768 const TypeF *TypeF::make(float f) {
|
|
769 return (TypeF*)(new TypeF(f))->hashcons();
|
|
770 }
|
|
771
|
|
772 //------------------------------meet-------------------------------------------
|
|
773 // Compute the MEET of two types. It returns a new Type object.
|
|
774 const Type *TypeF::xmeet( const Type *t ) const {
|
|
775 // Perform a fast test for common case; meeting the same types together.
|
|
776 if( this == t ) return this; // Meeting same type-rep?
|
|
777
|
|
778 // Current "this->_base" is FloatCon
|
|
779 switch (t->base()) { // Switch on original type
|
|
780 case AnyPtr: // Mixing with oops happens when javac
|
|
781 case RawPtr: // reuses local variables
|
|
782 case OopPtr:
|
|
783 case InstPtr:
|
|
784 case KlassPtr:
|
|
785 case AryPtr:
|
|
786 case Int:
|
|
787 case Long:
|
|
788 case DoubleTop:
|
|
789 case DoubleCon:
|
|
790 case DoubleBot:
|
|
791 case Bottom: // Ye Olde Default
|
|
792 return Type::BOTTOM;
|
|
793
|
|
794 case FloatBot:
|
|
795 return t;
|
|
796
|
|
797 default: // All else is a mistake
|
|
798 typerr(t);
|
|
799
|
|
800 case FloatCon: // Float-constant vs Float-constant?
|
|
801 if( jint_cast(_f) != jint_cast(t->getf()) ) // unequal constants?
|
|
802 // must compare bitwise as positive zero, negative zero and NaN have
|
|
803 // all the same representation in C++
|
|
804 return FLOAT; // Return generic float
|
|
805 // Equal constants
|
|
806 case Top:
|
|
807 case FloatTop:
|
|
808 break; // Return the float constant
|
|
809 }
|
|
810 return this; // Return the float constant
|
|
811 }
|
|
812
|
|
813 //------------------------------xdual------------------------------------------
|
|
814 // Dual: symmetric
|
|
815 const Type *TypeF::xdual() const {
|
|
816 return this;
|
|
817 }
|
|
818
|
|
819 //------------------------------eq---------------------------------------------
|
|
820 // Structural equality check for Type representations
|
|
821 bool TypeF::eq( const Type *t ) const {
|
|
822 if( g_isnan(_f) ||
|
|
823 g_isnan(t->getf()) ) {
|
|
824 // One or both are NANs. If both are NANs return true, else false.
|
|
825 return (g_isnan(_f) && g_isnan(t->getf()));
|
|
826 }
|
|
827 if (_f == t->getf()) {
|
|
828 // (NaN is impossible at this point, since it is not equal even to itself)
|
|
829 if (_f == 0.0) {
|
|
830 // difference between positive and negative zero
|
|
831 if (jint_cast(_f) != jint_cast(t->getf())) return false;
|
|
832 }
|
|
833 return true;
|
|
834 }
|
|
835 return false;
|
|
836 }
|
|
837
|
|
838 //------------------------------hash-------------------------------------------
|
|
839 // Type-specific hashing function.
|
|
840 int TypeF::hash(void) const {
|
|
841 return *(int*)(&_f);
|
|
842 }
|
|
843
|
|
844 //------------------------------is_finite--------------------------------------
|
|
845 // Has a finite value
|
|
846 bool TypeF::is_finite() const {
|
|
847 return g_isfinite(getf()) != 0;
|
|
848 }
|
|
849
|
|
850 //------------------------------is_nan-----------------------------------------
|
|
851 // Is not a number (NaN)
|
|
852 bool TypeF::is_nan() const {
|
|
853 return g_isnan(getf()) != 0;
|
|
854 }
|
|
855
|
|
856 //------------------------------dump2------------------------------------------
|
|
857 // Dump float constant Type
|
|
858 #ifndef PRODUCT
|
|
859 void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const {
|
|
860 Type::dump2(d,depth, st);
|
|
861 st->print("%f", _f);
|
|
862 }
|
|
863 #endif
|
|
864
|
|
865 //------------------------------singleton--------------------------------------
|
|
866 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
|
|
867 // constants (Ldi nodes). Singletons are integer, float or double constants
|
|
868 // or a single symbol.
|
|
869 bool TypeF::singleton(void) const {
|
|
870 return true; // Always a singleton
|
|
871 }
|
|
872
|
|
873 bool TypeF::empty(void) const {
|
|
874 return false; // always exactly a singleton
|
|
875 }
|
|
876
|
|
877 //=============================================================================
|
|
878 // Convenience common pre-built types.
|
|
879 const TypeD *TypeD::ZERO; // Floating point zero
|
|
880 const TypeD *TypeD::ONE; // Floating point one
|
|
881
|
|
882 //------------------------------make-------------------------------------------
|
|
883 const TypeD *TypeD::make(double d) {
|
|
884 return (TypeD*)(new TypeD(d))->hashcons();
|
|
885 }
|
|
886
|
|
887 //------------------------------meet-------------------------------------------
|
|
888 // Compute the MEET of two types. It returns a new Type object.
|
|
889 const Type *TypeD::xmeet( const Type *t ) const {
|
|
890 // Perform a fast test for common case; meeting the same types together.
|
|
891 if( this == t ) return this; // Meeting same type-rep?
|
|
892
|
|
893 // Current "this->_base" is DoubleCon
|
|
894 switch (t->base()) { // Switch on original type
|
|
895 case AnyPtr: // Mixing with oops happens when javac
|
|
896 case RawPtr: // reuses local variables
|
|
897 case OopPtr:
|
|
898 case InstPtr:
|
|
899 case KlassPtr:
|
|
900 case AryPtr:
|
|
901 case Int:
|
|
902 case Long:
|
|
903 case FloatTop:
|
|
904 case FloatCon:
|
|
905 case FloatBot:
|
|
906 case Bottom: // Ye Olde Default
|
|
907 return Type::BOTTOM;
|
|
908
|
|
909 case DoubleBot:
|
|
910 return t;
|
|
911
|
|
912 default: // All else is a mistake
|
|
913 typerr(t);
|
|
914
|
|
915 case DoubleCon: // Double-constant vs Double-constant?
|
|
916 if( jlong_cast(_d) != jlong_cast(t->getd()) ) // unequal constants? (see comment in TypeF::xmeet)
|
|
917 return DOUBLE; // Return generic double
|
|
918 case Top:
|
|
919 case DoubleTop:
|
|
920 break;
|
|
921 }
|
|
922 return this; // Return the double constant
|
|
923 }
|
|
924
|
|
925 //------------------------------xdual------------------------------------------
|
|
926 // Dual: symmetric
|
|
927 const Type *TypeD::xdual() const {
|
|
928 return this;
|
|
929 }
|
|
930
|
|
931 //------------------------------eq---------------------------------------------
|
|
932 // Structural equality check for Type representations
|
|
933 bool TypeD::eq( const Type *t ) const {
|
|
934 if( g_isnan(_d) ||
|
|
935 g_isnan(t->getd()) ) {
|
|
936 // One or both are NANs. If both are NANs return true, else false.
|
|
937 return (g_isnan(_d) && g_isnan(t->getd()));
|
|
938 }
|
|
939 if (_d == t->getd()) {
|
|
940 // (NaN is impossible at this point, since it is not equal even to itself)
|
|
941 if (_d == 0.0) {
|
|
942 // difference between positive and negative zero
|
|
943 if (jlong_cast(_d) != jlong_cast(t->getd())) return false;
|
|
944 }
|
|
945 return true;
|
|
946 }
|
|
947 return false;
|
|
948 }
|
|
949
|
|
950 //------------------------------hash-------------------------------------------
|
|
951 // Type-specific hashing function.
|
|
952 int TypeD::hash(void) const {
|
|
953 return *(int*)(&_d);
|
|
954 }
|
|
955
|
|
956 //------------------------------is_finite--------------------------------------
|
|
957 // Has a finite value
|
|
958 bool TypeD::is_finite() const {
|
|
959 return g_isfinite(getd()) != 0;
|
|
960 }
|
|
961
|
|
962 //------------------------------is_nan-----------------------------------------
|
|
963 // Is not a number (NaN)
|
|
964 bool TypeD::is_nan() const {
|
|
965 return g_isnan(getd()) != 0;
|
|
966 }
|
|
967
|
|
968 //------------------------------dump2------------------------------------------
|
|
969 // Dump double constant Type
|
|
970 #ifndef PRODUCT
|
|
971 void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const {
|
|
972 Type::dump2(d,depth,st);
|
|
973 st->print("%f", _d);
|
|
974 }
|
|
975 #endif
|
|
976
|
|
977 //------------------------------singleton--------------------------------------
|
|
978 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
|
|
979 // constants (Ldi nodes). Singletons are integer, float or double constants
|
|
980 // or a single symbol.
|
|
981 bool TypeD::singleton(void) const {
|
|
982 return true; // Always a singleton
|
|
983 }
|
|
984
|
|
985 bool TypeD::empty(void) const {
|
|
986 return false; // always exactly a singleton
|
|
987 }
|
|
988
|
|
989 //=============================================================================
|
|
990 // Convience common pre-built types.
|
|
991 const TypeInt *TypeInt::MINUS_1;// -1
|
|
992 const TypeInt *TypeInt::ZERO; // 0
|
|
993 const TypeInt *TypeInt::ONE; // 1
|
|
994 const TypeInt *TypeInt::BOOL; // 0 or 1, FALSE or TRUE.
|
|
995 const TypeInt *TypeInt::CC; // -1,0 or 1, condition codes
|
|
996 const TypeInt *TypeInt::CC_LT; // [-1] == MINUS_1
|
|
997 const TypeInt *TypeInt::CC_GT; // [1] == ONE
|
|
998 const TypeInt *TypeInt::CC_EQ; // [0] == ZERO
|
|
999 const TypeInt *TypeInt::CC_LE; // [-1,0]
|
|
1000 const TypeInt *TypeInt::CC_GE; // [0,1] == BOOL (!)
|
|
1001 const TypeInt *TypeInt::BYTE; // Bytes, -128 to 127
|
|
1002 const TypeInt *TypeInt::CHAR; // Java chars, 0-65535
|
|
1003 const TypeInt *TypeInt::SHORT; // Java shorts, -32768-32767
|
|
1004 const TypeInt *TypeInt::POS; // Positive 32-bit integers or zero
|
|
1005 const TypeInt *TypeInt::POS1; // Positive 32-bit integers
|
|
1006 const TypeInt *TypeInt::INT; // 32-bit integers
|
|
1007 const TypeInt *TypeInt::SYMINT; // symmetric range [-max_jint..max_jint]
|
|
1008
|
|
1009 //------------------------------TypeInt----------------------------------------
|
|
1010 TypeInt::TypeInt( jint lo, jint hi, int w ) : Type(Int), _lo(lo), _hi(hi), _widen(w) {
|
|
1011 }
|
|
1012
|
|
1013 //------------------------------make-------------------------------------------
|
|
1014 const TypeInt *TypeInt::make( jint lo ) {
|
|
1015 return (TypeInt*)(new TypeInt(lo,lo,WidenMin))->hashcons();
|
|
1016 }
|
|
1017
|
|
1018 #define SMALLINT ((juint)3) // a value too insignificant to consider widening
|
|
1019
|
|
1020 const TypeInt *TypeInt::make( jint lo, jint hi, int w ) {
|
|
1021 // Certain normalizations keep us sane when comparing types.
|
|
1022 // The 'SMALLINT' covers constants and also CC and its relatives.
|
|
1023 assert(CC == NULL || (juint)(CC->_hi - CC->_lo) <= SMALLINT, "CC is truly small");
|
|
1024 if (lo <= hi) {
|
|
1025 if ((juint)(hi - lo) <= SMALLINT) w = Type::WidenMin;
|
|
1026 if ((juint)(hi - lo) >= max_juint) w = Type::WidenMax; // plain int
|
|
1027 }
|
|
1028 return (TypeInt*)(new TypeInt(lo,hi,w))->hashcons();
|
|
1029 }
|
|
1030
|
|
1031 //------------------------------meet-------------------------------------------
|
|
1032 // Compute the MEET of two types. It returns a new Type representation object
|
|
1033 // with reference count equal to the number of Types pointing at it.
|
|
1034 // Caller should wrap a Types around it.
|
|
1035 const Type *TypeInt::xmeet( const Type *t ) const {
|
|
1036 // Perform a fast test for common case; meeting the same types together.
|
|
1037 if( this == t ) return this; // Meeting same type?
|
|
1038
|
|
1039 // Currently "this->_base" is a TypeInt
|
|
1040 switch (t->base()) { // Switch on original type
|
|
1041 case AnyPtr: // Mixing with oops happens when javac
|
|
1042 case RawPtr: // reuses local variables
|
|
1043 case OopPtr:
|
|
1044 case InstPtr:
|
|
1045 case KlassPtr:
|
|
1046 case AryPtr:
|
|
1047 case Long:
|
|
1048 case FloatTop:
|
|
1049 case FloatCon:
|
|
1050 case FloatBot:
|
|
1051 case DoubleTop:
|
|
1052 case DoubleCon:
|
|
1053 case DoubleBot:
|
|
1054 case Bottom: // Ye Olde Default
|
|
1055 return Type::BOTTOM;
|
|
1056 default: // All else is a mistake
|
|
1057 typerr(t);
|
|
1058 case Top: // No change
|
|
1059 return this;
|
|
1060 case Int: // Int vs Int?
|
|
1061 break;
|
|
1062 }
|
|
1063
|
|
1064 // Expand covered set
|
|
1065 const TypeInt *r = t->is_int();
|
|
1066 // (Avoid TypeInt::make, to avoid the argument normalizations it enforces.)
|
|
1067 return (new TypeInt( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) ))->hashcons();
|
|
1068 }
|
|
1069
|
|
1070 //------------------------------xdual------------------------------------------
|
|
1071 // Dual: reverse hi & lo; flip widen
|
|
1072 const Type *TypeInt::xdual() const {
|
|
1073 return new TypeInt(_hi,_lo,WidenMax-_widen);
|
|
1074 }
|
|
1075
|
|
1076 //------------------------------widen------------------------------------------
|
|
1077 // Only happens for optimistic top-down optimizations.
|
|
1078 const Type *TypeInt::widen( const Type *old ) const {
|
|
1079 // Coming from TOP or such; no widening
|
|
1080 if( old->base() != Int ) return this;
|
|
1081 const TypeInt *ot = old->is_int();
|
|
1082
|
|
1083 // If new guy is equal to old guy, no widening
|
|
1084 if( _lo == ot->_lo && _hi == ot->_hi )
|
|
1085 return old;
|
|
1086
|
|
1087 // If new guy contains old, then we widened
|
|
1088 if( _lo <= ot->_lo && _hi >= ot->_hi ) {
|
|
1089 // New contains old
|
|
1090 // If new guy is already wider than old, no widening
|
|
1091 if( _widen > ot->_widen ) return this;
|
|
1092 // If old guy was a constant, do not bother
|
|
1093 if (ot->_lo == ot->_hi) return this;
|
|
1094 // Now widen new guy.
|
|
1095 // Check for widening too far
|
|
1096 if (_widen == WidenMax) {
|
|
1097 if (min_jint < _lo && _hi < max_jint) {
|
|
1098 // If neither endpoint is extremal yet, push out the endpoint
|
|
1099 // which is closer to its respective limit.
|
|
1100 if (_lo >= 0 || // easy common case
|
|
1101 (juint)(_lo - min_jint) >= (juint)(max_jint - _hi)) {
|
|
1102 // Try to widen to an unsigned range type of 31 bits:
|
|
1103 return make(_lo, max_jint, WidenMax);
|
|
1104 } else {
|
|
1105 return make(min_jint, _hi, WidenMax);
|
|
1106 }
|
|
1107 }
|
|
1108 return TypeInt::INT;
|
|
1109 }
|
|
1110 // Returned widened new guy
|
|
1111 return make(_lo,_hi,_widen+1);
|
|
1112 }
|
|
1113
|
|
1114 // If old guy contains new, then we probably widened too far & dropped to
|
|
1115 // bottom. Return the wider fellow.
|
|
1116 if ( ot->_lo <= _lo && ot->_hi >= _hi )
|
|
1117 return old;
|
|
1118
|
|
1119 //fatal("Integer value range is not subset");
|
|
1120 //return this;
|
|
1121 return TypeInt::INT;
|
|
1122 }
|
|
1123
|
|
1124 //------------------------------narrow---------------------------------------
|
|
1125 // Only happens for pessimistic optimizations.
|
|
1126 const Type *TypeInt::narrow( const Type *old ) const {
|
|
1127 if (_lo >= _hi) return this; // already narrow enough
|
|
1128 if (old == NULL) return this;
|
|
1129 const TypeInt* ot = old->isa_int();
|
|
1130 if (ot == NULL) return this;
|
|
1131 jint olo = ot->_lo;
|
|
1132 jint ohi = ot->_hi;
|
|
1133
|
|
1134 // If new guy is equal to old guy, no narrowing
|
|
1135 if (_lo == olo && _hi == ohi) return old;
|
|
1136
|
|
1137 // If old guy was maximum range, allow the narrowing
|
|
1138 if (olo == min_jint && ohi == max_jint) return this;
|
|
1139
|
|
1140 if (_lo < olo || _hi > ohi)
|
|
1141 return this; // doesn't narrow; pretty wierd
|
|
1142
|
|
1143 // The new type narrows the old type, so look for a "death march".
|
|
1144 // See comments on PhaseTransform::saturate.
|
|
1145 juint nrange = _hi - _lo;
|
|
1146 juint orange = ohi - olo;
|
|
1147 if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
|
|
1148 // Use the new type only if the range shrinks a lot.
|
|
1149 // We do not want the optimizer computing 2^31 point by point.
|
|
1150 return old;
|
|
1151 }
|
|
1152
|
|
1153 return this;
|
|
1154 }
|
|
1155
|
|
1156 //-----------------------------filter------------------------------------------
|
|
1157 const Type *TypeInt::filter( const Type *kills ) const {
|
|
1158 const TypeInt* ft = join(kills)->isa_int();
|
|
1159 if (ft == NULL || ft->_lo > ft->_hi)
|
|
1160 return Type::TOP; // Canonical empty value
|
|
1161 if (ft->_widen < this->_widen) {
|
|
1162 // Do not allow the value of kill->_widen to affect the outcome.
|
|
1163 // The widen bits must be allowed to run freely through the graph.
|
|
1164 ft = TypeInt::make(ft->_lo, ft->_hi, this->_widen);
|
|
1165 }
|
|
1166 return ft;
|
|
1167 }
|
|
1168
|
|
1169 //------------------------------eq---------------------------------------------
|
|
1170 // Structural equality check for Type representations
|
|
1171 bool TypeInt::eq( const Type *t ) const {
|
|
1172 const TypeInt *r = t->is_int(); // Handy access
|
|
1173 return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
|
|
1174 }
|
|
1175
|
|
1176 //------------------------------hash-------------------------------------------
|
|
1177 // Type-specific hashing function.
|
|
1178 int TypeInt::hash(void) const {
|
|
1179 return _lo+_hi+_widen+(int)Type::Int;
|
|
1180 }
|
|
1181
|
|
1182 //------------------------------is_finite--------------------------------------
|
|
1183 // Has a finite value
|
|
1184 bool TypeInt::is_finite() const {
|
|
1185 return true;
|
|
1186 }
|
|
1187
|
|
1188 //------------------------------dump2------------------------------------------
|
|
1189 // Dump TypeInt
|
|
1190 #ifndef PRODUCT
|
|
1191 static const char* intname(char* buf, jint n) {
|
|
1192 if (n == min_jint)
|
|
1193 return "min";
|
|
1194 else if (n < min_jint + 10000)
|
|
1195 sprintf(buf, "min+" INT32_FORMAT, n - min_jint);
|
|
1196 else if (n == max_jint)
|
|
1197 return "max";
|
|
1198 else if (n > max_jint - 10000)
|
|
1199 sprintf(buf, "max-" INT32_FORMAT, max_jint - n);
|
|
1200 else
|
|
1201 sprintf(buf, INT32_FORMAT, n);
|
|
1202 return buf;
|
|
1203 }
|
|
1204
|
|
1205 void TypeInt::dump2( Dict &d, uint depth, outputStream *st ) const {
|
|
1206 char buf[40], buf2[40];
|
|
1207 if (_lo == min_jint && _hi == max_jint)
|
|
1208 st->print("int");
|
|
1209 else if (is_con())
|
|
1210 st->print("int:%s", intname(buf, get_con()));
|
|
1211 else if (_lo == BOOL->_lo && _hi == BOOL->_hi)
|
|
1212 st->print("bool");
|
|
1213 else if (_lo == BYTE->_lo && _hi == BYTE->_hi)
|
|
1214 st->print("byte");
|
|
1215 else if (_lo == CHAR->_lo && _hi == CHAR->_hi)
|
|
1216 st->print("char");
|
|
1217 else if (_lo == SHORT->_lo && _hi == SHORT->_hi)
|
|
1218 st->print("short");
|
|
1219 else if (_hi == max_jint)
|
|
1220 st->print("int:>=%s", intname(buf, _lo));
|
|
1221 else if (_lo == min_jint)
|
|
1222 st->print("int:<=%s", intname(buf, _hi));
|
|
1223 else
|
|
1224 st->print("int:%s..%s", intname(buf, _lo), intname(buf2, _hi));
|
|
1225
|
|
1226 if (_widen != 0 && this != TypeInt::INT)
|
|
1227 st->print(":%.*s", _widen, "wwww");
|
|
1228 }
|
|
1229 #endif
|
|
1230
|
|
1231 //------------------------------singleton--------------------------------------
|
|
1232 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
|
|
1233 // constants.
|
|
1234 bool TypeInt::singleton(void) const {
|
|
1235 return _lo >= _hi;
|
|
1236 }
|
|
1237
|
|
1238 bool TypeInt::empty(void) const {
|
|
1239 return _lo > _hi;
|
|
1240 }
|
|
1241
|
|
1242 //=============================================================================
|
|
1243 // Convenience common pre-built types.
|
|
1244 const TypeLong *TypeLong::MINUS_1;// -1
|
|
1245 const TypeLong *TypeLong::ZERO; // 0
|
|
1246 const TypeLong *TypeLong::ONE; // 1
|
|
1247 const TypeLong *TypeLong::POS; // >=0
|
|
1248 const TypeLong *TypeLong::LONG; // 64-bit integers
|
|
1249 const TypeLong *TypeLong::INT; // 32-bit subrange
|
|
1250 const TypeLong *TypeLong::UINT; // 32-bit unsigned subrange
|
|
1251
|
|
1252 //------------------------------TypeLong---------------------------------------
|
|
1253 TypeLong::TypeLong( jlong lo, jlong hi, int w ) : Type(Long), _lo(lo), _hi(hi), _widen(w) {
|
|
1254 }
|
|
1255
|
|
1256 //------------------------------make-------------------------------------------
|
|
1257 const TypeLong *TypeLong::make( jlong lo ) {
|
|
1258 return (TypeLong*)(new TypeLong(lo,lo,WidenMin))->hashcons();
|
|
1259 }
|
|
1260
|
|
1261 const TypeLong *TypeLong::make( jlong lo, jlong hi, int w ) {
|
|
1262 // Certain normalizations keep us sane when comparing types.
|
|
1263 // The '1' covers constants.
|
|
1264 if (lo <= hi) {
|
|
1265 if ((julong)(hi - lo) <= SMALLINT) w = Type::WidenMin;
|
|
1266 if ((julong)(hi - lo) >= max_julong) w = Type::WidenMax; // plain long
|
|
1267 }
|
|
1268 return (TypeLong*)(new TypeLong(lo,hi,w))->hashcons();
|
|
1269 }
|
|
1270
|
|
1271
|
|
1272 //------------------------------meet-------------------------------------------
|
|
1273 // Compute the MEET of two types. It returns a new Type representation object
|
|
1274 // with reference count equal to the number of Types pointing at it.
|
|
1275 // Caller should wrap a Types around it.
|
|
1276 const Type *TypeLong::xmeet( const Type *t ) const {
|
|
1277 // Perform a fast test for common case; meeting the same types together.
|
|
1278 if( this == t ) return this; // Meeting same type?
|
|
1279
|
|
1280 // Currently "this->_base" is a TypeLong
|
|
1281 switch (t->base()) { // Switch on original type
|
|
1282 case AnyPtr: // Mixing with oops happens when javac
|
|
1283 case RawPtr: // reuses local variables
|
|
1284 case OopPtr:
|
|
1285 case InstPtr:
|
|
1286 case KlassPtr:
|
|
1287 case AryPtr:
|
|
1288 case Int:
|
|
1289 case FloatTop:
|
|
1290 case FloatCon:
|
|
1291 case FloatBot:
|
|
1292 case DoubleTop:
|
|
1293 case DoubleCon:
|
|
1294 case DoubleBot:
|
|
1295 case Bottom: // Ye Olde Default
|
|
1296 return Type::BOTTOM;
|
|
1297 default: // All else is a mistake
|
|
1298 typerr(t);
|
|
1299 case Top: // No change
|
|
1300 return this;
|
|
1301 case Long: // Long vs Long?
|
|
1302 break;
|
|
1303 }
|
|
1304
|
|
1305 // Expand covered set
|
|
1306 const TypeLong *r = t->is_long(); // Turn into a TypeLong
|
|
1307 // (Avoid TypeLong::make, to avoid the argument normalizations it enforces.)
|
|
1308 return (new TypeLong( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) ))->hashcons();
|
|
1309 }
|
|
1310
|
|
1311 //------------------------------xdual------------------------------------------
|
|
1312 // Dual: reverse hi & lo; flip widen
|
|
1313 const Type *TypeLong::xdual() const {
|
|
1314 return new TypeLong(_hi,_lo,WidenMax-_widen);
|
|
1315 }
|
|
1316
|
|
1317 //------------------------------widen------------------------------------------
|
|
1318 // Only happens for optimistic top-down optimizations.
|
|
1319 const Type *TypeLong::widen( const Type *old ) const {
|
|
1320 // Coming from TOP or such; no widening
|
|
1321 if( old->base() != Long ) return this;
|
|
1322 const TypeLong *ot = old->is_long();
|
|
1323
|
|
1324 // If new guy is equal to old guy, no widening
|
|
1325 if( _lo == ot->_lo && _hi == ot->_hi )
|
|
1326 return old;
|
|
1327
|
|
1328 // If new guy contains old, then we widened
|
|
1329 if( _lo <= ot->_lo && _hi >= ot->_hi ) {
|
|
1330 // New contains old
|
|
1331 // If new guy is already wider than old, no widening
|
|
1332 if( _widen > ot->_widen ) return this;
|
|
1333 // If old guy was a constant, do not bother
|
|
1334 if (ot->_lo == ot->_hi) return this;
|
|
1335 // Now widen new guy.
|
|
1336 // Check for widening too far
|
|
1337 if (_widen == WidenMax) {
|
|
1338 if (min_jlong < _lo && _hi < max_jlong) {
|
|
1339 // If neither endpoint is extremal yet, push out the endpoint
|
|
1340 // which is closer to its respective limit.
|
|
1341 if (_lo >= 0 || // easy common case
|
|
1342 (julong)(_lo - min_jlong) >= (julong)(max_jlong - _hi)) {
|
|
1343 // Try to widen to an unsigned range type of 32/63 bits:
|
|
1344 if (_hi < max_juint)
|
|
1345 return make(_lo, max_juint, WidenMax);
|
|
1346 else
|
|
1347 return make(_lo, max_jlong, WidenMax);
|
|
1348 } else {
|
|
1349 return make(min_jlong, _hi, WidenMax);
|
|
1350 }
|
|
1351 }
|
|
1352 return TypeLong::LONG;
|
|
1353 }
|
|
1354 // Returned widened new guy
|
|
1355 return make(_lo,_hi,_widen+1);
|
|
1356 }
|
|
1357
|
|
1358 // If old guy contains new, then we probably widened too far & dropped to
|
|
1359 // bottom. Return the wider fellow.
|
|
1360 if ( ot->_lo <= _lo && ot->_hi >= _hi )
|
|
1361 return old;
|
|
1362
|
|
1363 // fatal("Long value range is not subset");
|
|
1364 // return this;
|
|
1365 return TypeLong::LONG;
|
|
1366 }
|
|
1367
|
|
1368 //------------------------------narrow----------------------------------------
|
|
1369 // Only happens for pessimistic optimizations.
|
|
1370 const Type *TypeLong::narrow( const Type *old ) const {
|
|
1371 if (_lo >= _hi) return this; // already narrow enough
|
|
1372 if (old == NULL) return this;
|
|
1373 const TypeLong* ot = old->isa_long();
|
|
1374 if (ot == NULL) return this;
|
|
1375 jlong olo = ot->_lo;
|
|
1376 jlong ohi = ot->_hi;
|
|
1377
|
|
1378 // If new guy is equal to old guy, no narrowing
|
|
1379 if (_lo == olo && _hi == ohi) return old;
|
|
1380
|
|
1381 // If old guy was maximum range, allow the narrowing
|
|
1382 if (olo == min_jlong && ohi == max_jlong) return this;
|
|
1383
|
|
1384 if (_lo < olo || _hi > ohi)
|
|
1385 return this; // doesn't narrow; pretty wierd
|
|
1386
|
|
1387 // The new type narrows the old type, so look for a "death march".
|
|
1388 // See comments on PhaseTransform::saturate.
|
|
1389 julong nrange = _hi - _lo;
|
|
1390 julong orange = ohi - olo;
|
|
1391 if (nrange < max_julong - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
|
|
1392 // Use the new type only if the range shrinks a lot.
|
|
1393 // We do not want the optimizer computing 2^31 point by point.
|
|
1394 return old;
|
|
1395 }
|
|
1396
|
|
1397 return this;
|
|
1398 }
|
|
1399
|
|
1400 //-----------------------------filter------------------------------------------
|
|
1401 const Type *TypeLong::filter( const Type *kills ) const {
|
|
1402 const TypeLong* ft = join(kills)->isa_long();
|
|
1403 if (ft == NULL || ft->_lo > ft->_hi)
|
|
1404 return Type::TOP; // Canonical empty value
|
|
1405 if (ft->_widen < this->_widen) {
|
|
1406 // Do not allow the value of kill->_widen to affect the outcome.
|
|
1407 // The widen bits must be allowed to run freely through the graph.
|
|
1408 ft = TypeLong::make(ft->_lo, ft->_hi, this->_widen);
|
|
1409 }
|
|
1410 return ft;
|
|
1411 }
|
|
1412
|
|
1413 //------------------------------eq---------------------------------------------
|
|
1414 // Structural equality check for Type representations
|
|
1415 bool TypeLong::eq( const Type *t ) const {
|
|
1416 const TypeLong *r = t->is_long(); // Handy access
|
|
1417 return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
|
|
1418 }
|
|
1419
|
|
1420 //------------------------------hash-------------------------------------------
|
|
1421 // Type-specific hashing function.
|
|
1422 int TypeLong::hash(void) const {
|
|
1423 return (int)(_lo+_hi+_widen+(int)Type::Long);
|
|
1424 }
|
|
1425
|
|
1426 //------------------------------is_finite--------------------------------------
|
|
1427 // Has a finite value
|
|
1428 bool TypeLong::is_finite() const {
|
|
1429 return true;
|
|
1430 }
|
|
1431
|
|
1432 //------------------------------dump2------------------------------------------
|
|
1433 // Dump TypeLong
|
|
1434 #ifndef PRODUCT
|
|
1435 static const char* longnamenear(jlong x, const char* xname, char* buf, jlong n) {
|
|
1436 if (n > x) {
|
|
1437 if (n >= x + 10000) return NULL;
|
|
1438 sprintf(buf, "%s+" INT64_FORMAT, xname, n - x);
|
|
1439 } else if (n < x) {
|
|
1440 if (n <= x - 10000) return NULL;
|
|
1441 sprintf(buf, "%s-" INT64_FORMAT, xname, x - n);
|
|
1442 } else {
|
|
1443 return xname;
|
|
1444 }
|
|
1445 return buf;
|
|
1446 }
|
|
1447
|
|
1448 static const char* longname(char* buf, jlong n) {
|
|
1449 const char* str;
|
|
1450 if (n == min_jlong)
|
|
1451 return "min";
|
|
1452 else if (n < min_jlong + 10000)
|
|
1453 sprintf(buf, "min+" INT64_FORMAT, n - min_jlong);
|
|
1454 else if (n == max_jlong)
|
|
1455 return "max";
|
|
1456 else if (n > max_jlong - 10000)
|
|
1457 sprintf(buf, "max-" INT64_FORMAT, max_jlong - n);
|
|
1458 else if ((str = longnamenear(max_juint, "maxuint", buf, n)) != NULL)
|
|
1459 return str;
|
|
1460 else if ((str = longnamenear(max_jint, "maxint", buf, n)) != NULL)
|
|
1461 return str;
|
|
1462 else if ((str = longnamenear(min_jint, "minint", buf, n)) != NULL)
|
|
1463 return str;
|
|
1464 else
|
|
1465 sprintf(buf, INT64_FORMAT, n);
|
|
1466 return buf;
|
|
1467 }
|
|
1468
|
|
1469 void TypeLong::dump2( Dict &d, uint depth, outputStream *st ) const {
|
|
1470 char buf[80], buf2[80];
|
|
1471 if (_lo == min_jlong && _hi == max_jlong)
|
|
1472 st->print("long");
|
|
1473 else if (is_con())
|
|
1474 st->print("long:%s", longname(buf, get_con()));
|
|
1475 else if (_hi == max_jlong)
|
|
1476 st->print("long:>=%s", longname(buf, _lo));
|
|
1477 else if (_lo == min_jlong)
|
|
1478 st->print("long:<=%s", longname(buf, _hi));
|
|
1479 else
|
|
1480 st->print("long:%s..%s", longname(buf, _lo), longname(buf2, _hi));
|
|
1481
|
|
1482 if (_widen != 0 && this != TypeLong::LONG)
|
|
1483 st->print(":%.*s", _widen, "wwww");
|
|
1484 }
|
|
1485 #endif
|
|
1486
|
|
1487 //------------------------------singleton--------------------------------------
|
|
1488 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
|
|
1489 // constants
|
|
1490 bool TypeLong::singleton(void) const {
|
|
1491 return _lo >= _hi;
|
|
1492 }
|
|
1493
|
|
1494 bool TypeLong::empty(void) const {
|
|
1495 return _lo > _hi;
|
|
1496 }
|
|
1497
|
|
1498 //=============================================================================
|
|
1499 // Convenience common pre-built types.
|
|
1500 const TypeTuple *TypeTuple::IFBOTH; // Return both arms of IF as reachable
|
|
1501 const TypeTuple *TypeTuple::IFFALSE;
|
|
1502 const TypeTuple *TypeTuple::IFTRUE;
|
|
1503 const TypeTuple *TypeTuple::IFNEITHER;
|
|
1504 const TypeTuple *TypeTuple::LOOPBODY;
|
|
1505 const TypeTuple *TypeTuple::MEMBAR;
|
|
1506 const TypeTuple *TypeTuple::STORECONDITIONAL;
|
|
1507 const TypeTuple *TypeTuple::START_I2C;
|
|
1508 const TypeTuple *TypeTuple::INT_PAIR;
|
|
1509 const TypeTuple *TypeTuple::LONG_PAIR;
|
|
1510
|
|
1511
|
|
1512 //------------------------------make-------------------------------------------
|
|
1513 // Make a TypeTuple from the range of a method signature
|
|
1514 const TypeTuple *TypeTuple::make_range(ciSignature* sig) {
|
|
1515 ciType* return_type = sig->return_type();
|
|
1516 uint total_fields = TypeFunc::Parms + return_type->size();
|
|
1517 const Type **field_array = fields(total_fields);
|
|
1518 switch (return_type->basic_type()) {
|
|
1519 case T_LONG:
|
|
1520 field_array[TypeFunc::Parms] = TypeLong::LONG;
|
|
1521 field_array[TypeFunc::Parms+1] = Type::HALF;
|
|
1522 break;
|
|
1523 case T_DOUBLE:
|
|
1524 field_array[TypeFunc::Parms] = Type::DOUBLE;
|
|
1525 field_array[TypeFunc::Parms+1] = Type::HALF;
|
|
1526 break;
|
|
1527 case T_OBJECT:
|
|
1528 case T_ARRAY:
|
|
1529 case T_BOOLEAN:
|
|
1530 case T_CHAR:
|
|
1531 case T_FLOAT:
|
|
1532 case T_BYTE:
|
|
1533 case T_SHORT:
|
|
1534 case T_INT:
|
|
1535 field_array[TypeFunc::Parms] = get_const_type(return_type);
|
|
1536 break;
|
|
1537 case T_VOID:
|
|
1538 break;
|
|
1539 default:
|
|
1540 ShouldNotReachHere();
|
|
1541 }
|
|
1542 return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
|
|
1543 }
|
|
1544
|
|
1545 // Make a TypeTuple from the domain of a method signature
|
|
1546 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig) {
|
|
1547 uint total_fields = TypeFunc::Parms + sig->size();
|
|
1548
|
|
1549 uint pos = TypeFunc::Parms;
|
|
1550 const Type **field_array;
|
|
1551 if (recv != NULL) {
|
|
1552 total_fields++;
|
|
1553 field_array = fields(total_fields);
|
|
1554 // Use get_const_type here because it respects UseUniqueSubclasses:
|
|
1555 field_array[pos++] = get_const_type(recv)->join(TypePtr::NOTNULL);
|
|
1556 } else {
|
|
1557 field_array = fields(total_fields);
|
|
1558 }
|
|
1559
|
|
1560 int i = 0;
|
|
1561 while (pos < total_fields) {
|
|
1562 ciType* type = sig->type_at(i);
|
|
1563
|
|
1564 switch (type->basic_type()) {
|
|
1565 case T_LONG:
|
|
1566 field_array[pos++] = TypeLong::LONG;
|
|
1567 field_array[pos++] = Type::HALF;
|
|
1568 break;
|
|
1569 case T_DOUBLE:
|
|
1570 field_array[pos++] = Type::DOUBLE;
|
|
1571 field_array[pos++] = Type::HALF;
|
|
1572 break;
|
|
1573 case T_OBJECT:
|
|
1574 case T_ARRAY:
|
|
1575 case T_BOOLEAN:
|
|
1576 case T_CHAR:
|
|
1577 case T_FLOAT:
|
|
1578 case T_BYTE:
|
|
1579 case T_SHORT:
|
|
1580 case T_INT:
|
|
1581 field_array[pos++] = get_const_type(type);
|
|
1582 break;
|
|
1583 default:
|
|
1584 ShouldNotReachHere();
|
|
1585 }
|
|
1586 i++;
|
|
1587 }
|
|
1588 return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
|
|
1589 }
|
|
1590
|
|
1591 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
|
|
1592 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
|
|
1593 }
|
|
1594
|
|
1595 //------------------------------fields-----------------------------------------
|
|
1596 // Subroutine call type with space allocated for argument types
|
|
1597 const Type **TypeTuple::fields( uint arg_cnt ) {
|
|
1598 const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
|
|
1599 flds[TypeFunc::Control ] = Type::CONTROL;
|
|
1600 flds[TypeFunc::I_O ] = Type::ABIO;
|
|
1601 flds[TypeFunc::Memory ] = Type::MEMORY;
|
|
1602 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
|
|
1603 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
|
|
1604
|
|
1605 return flds;
|
|
1606 }
|
|
1607
|
|
1608 //------------------------------meet-------------------------------------------
|
|
1609 // Compute the MEET of two types. It returns a new Type object.
|
|
1610 const Type *TypeTuple::xmeet( const Type *t ) const {
|
|
1611 // Perform a fast test for common case; meeting the same types together.
|
|
1612 if( this == t ) return this; // Meeting same type-rep?
|
|
1613
|
|
1614 // Current "this->_base" is Tuple
|
|
1615 switch (t->base()) { // switch on original type
|
|
1616
|
|
1617 case Bottom: // Ye Olde Default
|
|
1618 return t;
|
|
1619
|
|
1620 default: // All else is a mistake
|
|
1621 typerr(t);
|
|
1622
|
|
1623 case Tuple: { // Meeting 2 signatures?
|
|
1624 const TypeTuple *x = t->is_tuple();
|
|
1625 assert( _cnt == x->_cnt, "" );
|
|
1626 const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
|
|
1627 for( uint i=0; i<_cnt; i++ )
|
|
1628 fields[i] = field_at(i)->xmeet( x->field_at(i) );
|
|
1629 return TypeTuple::make(_cnt,fields);
|
|
1630 }
|
|
1631 case Top:
|
|
1632 break;
|
|
1633 }
|
|
1634 return this; // Return the double constant
|
|
1635 }
|
|
1636
|
|
1637 //------------------------------xdual------------------------------------------
|
|
1638 // Dual: compute field-by-field dual
|
|
1639 const Type *TypeTuple::xdual() const {
|
|
1640 const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
|
|
1641 for( uint i=0; i<_cnt; i++ )
|
|
1642 fields[i] = _fields[i]->dual();
|
|
1643 return new TypeTuple(_cnt,fields);
|
|
1644 }
|
|
1645
|
|
1646 //------------------------------eq---------------------------------------------
|
|
1647 // Structural equality check for Type representations
|
|
1648 bool TypeTuple::eq( const Type *t ) const {
|
|
1649 const TypeTuple *s = (const TypeTuple *)t;
|
|
1650 if (_cnt != s->_cnt) return false; // Unequal field counts
|
|
1651 for (uint i = 0; i < _cnt; i++)
|
|
1652 if (field_at(i) != s->field_at(i)) // POINTER COMPARE! NO RECURSION!
|
|
1653 return false; // Missed
|
|
1654 return true;
|
|
1655 }
|
|
1656
|
|
1657 //------------------------------hash-------------------------------------------
|
|
1658 // Type-specific hashing function.
|
|
1659 int TypeTuple::hash(void) const {
|
|
1660 intptr_t sum = _cnt;
|
|
1661 for( uint i=0; i<_cnt; i++ )
|
|
1662 sum += (intptr_t)_fields[i]; // Hash on pointers directly
|
|
1663 return sum;
|
|
1664 }
|
|
1665
|
|
1666 //------------------------------dump2------------------------------------------
|
|
1667 // Dump signature Type
|
|
1668 #ifndef PRODUCT
|
|
1669 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
|
|
1670 st->print("{");
|
|
1671 if( !depth || d[this] ) { // Check for recursive print
|
|
1672 st->print("...}");
|
|
1673 return;
|
|
1674 }
|
|
1675 d.Insert((void*)this, (void*)this); // Stop recursion
|
|
1676 if( _cnt ) {
|
|
1677 uint i;
|
|
1678 for( i=0; i<_cnt-1; i++ ) {
|
|
1679 st->print("%d:", i);
|
|
1680 _fields[i]->dump2(d, depth-1, st);
|
|
1681 st->print(", ");
|
|
1682 }
|
|
1683 st->print("%d:", i);
|
|
1684 _fields[i]->dump2(d, depth-1, st);
|
|
1685 }
|
|
1686 st->print("}");
|
|
1687 }
|
|
1688 #endif
|
|
1689
|
|
1690 //------------------------------singleton--------------------------------------
|
|
1691 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
|
|
1692 // constants (Ldi nodes). Singletons are integer, float or double constants
|
|
1693 // or a single symbol.
|
|
1694 bool TypeTuple::singleton(void) const {
|
|
1695 return false; // Never a singleton
|
|
1696 }
|
|
1697
|
|
1698 bool TypeTuple::empty(void) const {
|
|
1699 for( uint i=0; i<_cnt; i++ ) {
|
|
1700 if (_fields[i]->empty()) return true;
|
|
1701 }
|
|
1702 return false;
|
|
1703 }
|
|
1704
|
|
1705 //=============================================================================
|
|
1706 // Convenience common pre-built types.
|
|
1707
|
|
1708 inline const TypeInt* normalize_array_size(const TypeInt* size) {
|
|
1709 // Certain normalizations keep us sane when comparing types.
|
|
1710 // We do not want arrayOop variables to differ only by the wideness
|
|
1711 // of their index types. Pick minimum wideness, since that is the
|
|
1712 // forced wideness of small ranges anyway.
|
|
1713 if (size->_widen != Type::WidenMin)
|
|
1714 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
|
|
1715 else
|
|
1716 return size;
|
|
1717 }
|
|
1718
|
|
1719 //------------------------------make-------------------------------------------
|
|
1720 const TypeAry *TypeAry::make( const Type *elem, const TypeInt *size) {
|
|
1721 size = normalize_array_size(size);
|
|
1722 return (TypeAry*)(new TypeAry(elem,size))->hashcons();
|
|
1723 }
|
|
1724
|
|
1725 //------------------------------meet-------------------------------------------
|
|
1726 // Compute the MEET of two types. It returns a new Type object.
|
|
1727 const Type *TypeAry::xmeet( const Type *t ) const {
|
|
1728 // Perform a fast test for common case; meeting the same types together.
|
|
1729 if( this == t ) return this; // Meeting same type-rep?
|
|
1730
|
|
1731 // Current "this->_base" is Ary
|
|
1732 switch (t->base()) { // switch on original type
|
|
1733
|
|
1734 case Bottom: // Ye Olde Default
|
|
1735 return t;
|
|
1736
|
|
1737 default: // All else is a mistake
|
|
1738 typerr(t);
|
|
1739
|
|
1740 case Array: { // Meeting 2 arrays?
|
|
1741 const TypeAry *a = t->is_ary();
|
|
1742 return TypeAry::make(_elem->meet(a->_elem),
|
|
1743 _size->xmeet(a->_size)->is_int());
|
|
1744 }
|
|
1745 case Top:
|
|
1746 break;
|
|
1747 }
|
|
1748 return this; // Return the double constant
|
|
1749 }
|
|
1750
|
|
1751 //------------------------------xdual------------------------------------------
|
|
1752 // Dual: compute field-by-field dual
|
|
1753 const Type *TypeAry::xdual() const {
|
|
1754 const TypeInt* size_dual = _size->dual()->is_int();
|
|
1755 size_dual = normalize_array_size(size_dual);
|
|
1756 return new TypeAry( _elem->dual(), size_dual);
|
|
1757 }
|
|
1758
|
|
1759 //------------------------------eq---------------------------------------------
|
|
1760 // Structural equality check for Type representations
|
|
1761 bool TypeAry::eq( const Type *t ) const {
|
|
1762 const TypeAry *a = (const TypeAry*)t;
|
|
1763 return _elem == a->_elem &&
|
|
1764 _size == a->_size;
|
|
1765 }
|
|
1766
|
|
1767 //------------------------------hash-------------------------------------------
|
|
1768 // Type-specific hashing function.
|
|
1769 int TypeAry::hash(void) const {
|
|
1770 return (intptr_t)_elem + (intptr_t)_size;
|
|
1771 }
|
|
1772
|
|
1773 //------------------------------dump2------------------------------------------
|
|
1774 #ifndef PRODUCT
|
|
1775 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
|
|
1776 _elem->dump2(d, depth, st);
|
|
1777 st->print("[");
|
|
1778 _size->dump2(d, depth, st);
|
|
1779 st->print("]");
|
|
1780 }
|
|
1781 #endif
|
|
1782
|
|
1783 //------------------------------singleton--------------------------------------
|
|
1784 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
|
|
1785 // constants (Ldi nodes). Singletons are integer, float or double constants
|
|
1786 // or a single symbol.
|
|
1787 bool TypeAry::singleton(void) const {
|
|
1788 return false; // Never a singleton
|
|
1789 }
|
|
1790
|
|
1791 bool TypeAry::empty(void) const {
|
|
1792 return _elem->empty() || _size->empty();
|
|
1793 }
|
|
1794
|
|
1795 //--------------------------ary_must_be_exact----------------------------------
|
|
1796 bool TypeAry::ary_must_be_exact() const {
|
|
1797 if (!UseExactTypes) return false;
|
|
1798 // This logic looks at the element type of an array, and returns true
|
|
1799 // if the element type is either a primitive or a final instance class.
|
|
1800 // In such cases, an array built on this ary must have no subclasses.
|
|
1801 if (_elem == BOTTOM) return false; // general array not exact
|
|
1802 if (_elem == TOP ) return false; // inverted general array not exact
|
|
1803 const TypeOopPtr* toop = _elem->isa_oopptr();
|
|
1804 if (!toop) return true; // a primitive type, like int
|
|
1805 ciKlass* tklass = toop->klass();
|
|
1806 if (tklass == NULL) return false; // unloaded class
|
|
1807 if (!tklass->is_loaded()) return false; // unloaded class
|
|
1808 const TypeInstPtr* tinst = _elem->isa_instptr();
|
|
1809 if (tinst) return tklass->as_instance_klass()->is_final();
|
|
1810 const TypeAryPtr* tap = _elem->isa_aryptr();
|
|
1811 if (tap) return tap->ary()->ary_must_be_exact();
|
|
1812 return false;
|
|
1813 }
|
|
1814
|
|
1815 //=============================================================================
|
|
1816 // Convenience common pre-built types.
|
|
1817 const TypePtr *TypePtr::NULL_PTR;
|
|
1818 const TypePtr *TypePtr::NOTNULL;
|
|
1819 const TypePtr *TypePtr::BOTTOM;
|
|
1820
|
|
1821 //------------------------------meet-------------------------------------------
|
|
1822 // Meet over the PTR enum
|
|
1823 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
|
|
1824 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,
|
|
1825 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,},
|
|
1826 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,},
|
|
1827 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,},
|
|
1828 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,},
|
|
1829 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,},
|
|
1830 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,}
|
|
1831 };
|
|
1832
|
|
1833 //------------------------------make-------------------------------------------
|
|
1834 const TypePtr *TypePtr::make( TYPES t, enum PTR ptr, int offset ) {
|
|
1835 return (TypePtr*)(new TypePtr(t,ptr,offset))->hashcons();
|
|
1836 }
|
|
1837
|
|
1838 //------------------------------cast_to_ptr_type-------------------------------
|
|
1839 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
|
|
1840 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
|
|
1841 if( ptr == _ptr ) return this;
|
|
1842 return make(_base, ptr, _offset);
|
|
1843 }
|
|
1844
|
|
1845 //------------------------------get_con----------------------------------------
|
|
1846 intptr_t TypePtr::get_con() const {
|
|
1847 assert( _ptr == Null, "" );
|
|
1848 return _offset;
|
|
1849 }
|
|
1850
|
|
1851 //------------------------------meet-------------------------------------------
|
|
1852 // Compute the MEET of two types. It returns a new Type object.
|
|
1853 const Type *TypePtr::xmeet( const Type *t ) const {
|
|
1854 // Perform a fast test for common case; meeting the same types together.
|
|
1855 if( this == t ) return this; // Meeting same type-rep?
|
|
1856
|
|
1857 // Current "this->_base" is AnyPtr
|
|
1858 switch (t->base()) { // switch on original type
|
|
1859 case Int: // Mixing ints & oops happens when javac
|
|
1860 case Long: // reuses local variables
|
|
1861 case FloatTop:
|
|
1862 case FloatCon:
|
|
1863 case FloatBot:
|
|
1864 case DoubleTop:
|
|
1865 case DoubleCon:
|
|
1866 case DoubleBot:
|
|
1867 case Bottom: // Ye Olde Default
|
|
1868 return Type::BOTTOM;
|
|
1869 case Top:
|
|
1870 return this;
|
|
1871
|
|
1872 case AnyPtr: { // Meeting to AnyPtrs
|
|
1873 const TypePtr *tp = t->is_ptr();
|
|
1874 return make( AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()) );
|
|
1875 }
|
|
1876 case RawPtr: // For these, flip the call around to cut down
|
|
1877 case OopPtr:
|
|
1878 case InstPtr: // on the cases I have to handle.
|
|
1879 case KlassPtr:
|
|
1880 case AryPtr:
|
|
1881 return t->xmeet(this); // Call in reverse direction
|
|
1882 default: // All else is a mistake
|
|
1883 typerr(t);
|
|
1884
|
|
1885 }
|
|
1886 return this;
|
|
1887 }
|
|
1888
|
|
1889 //------------------------------meet_offset------------------------------------
|
|
1890 int TypePtr::meet_offset( int offset ) const {
|
|
1891 // Either is 'TOP' offset? Return the other offset!
|
|
1892 if( _offset == OffsetTop ) return offset;
|
|
1893 if( offset == OffsetTop ) return _offset;
|
|
1894 // If either is different, return 'BOTTOM' offset
|
|
1895 if( _offset != offset ) return OffsetBot;
|
|
1896 return _offset;
|
|
1897 }
|
|
1898
|
|
1899 //------------------------------dual_offset------------------------------------
|
|
1900 int TypePtr::dual_offset( ) const {
|
|
1901 if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
|
|
1902 if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
|
|
1903 return _offset; // Map everything else into self
|
|
1904 }
|
|
1905
|
|
1906 //------------------------------xdual------------------------------------------
|
|
1907 // Dual: compute field-by-field dual
|
|
1908 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
|
|
1909 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
|
|
1910 };
|
|
1911 const Type *TypePtr::xdual() const {
|
|
1912 return new TypePtr( AnyPtr, dual_ptr(), dual_offset() );
|
|
1913 }
|
|
1914
|
|
1915 //------------------------------add_offset-------------------------------------
|
|
1916 const TypePtr *TypePtr::add_offset( int offset ) const {
|
|
1917 if( offset == 0 ) return this; // No change
|
|
1918 if( _offset == OffsetBot ) return this;
|
|
1919 if( offset == OffsetBot ) offset = OffsetBot;
|
|
1920 else if( _offset == OffsetTop || offset == OffsetTop ) offset = OffsetTop;
|
|
1921 else offset += _offset;
|
|
1922 return make( AnyPtr, _ptr, offset );
|
|
1923 }
|
|
1924
|
|
1925 //------------------------------eq---------------------------------------------
|
|
1926 // Structural equality check for Type representations
|
|
1927 bool TypePtr::eq( const Type *t ) const {
|
|
1928 const TypePtr *a = (const TypePtr*)t;
|
|
1929 return _ptr == a->ptr() && _offset == a->offset();
|
|
1930 }
|
|
1931
|
|
1932 //------------------------------hash-------------------------------------------
|
|
1933 // Type-specific hashing function.
|
|
1934 int TypePtr::hash(void) const {
|
|
1935 return _ptr + _offset;
|
|
1936 }
|
|
1937
|
|
1938 //------------------------------dump2------------------------------------------
|
|
1939 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
|
|
1940 "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
|
|
1941 };
|
|
1942
|
|
1943 #ifndef PRODUCT
|
|
1944 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
|
|
1945 if( _ptr == Null ) st->print("NULL");
|
|
1946 else st->print("%s *", ptr_msg[_ptr]);
|
|
1947 if( _offset == OffsetTop ) st->print("+top");
|
|
1948 else if( _offset == OffsetBot ) st->print("+bot");
|
|
1949 else if( _offset ) st->print("+%d", _offset);
|
|
1950 }
|
|
1951 #endif
|
|
1952
|
|
1953 //------------------------------singleton--------------------------------------
|
|
1954 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
|
|
1955 // constants
|
|
1956 bool TypePtr::singleton(void) const {
|
|
1957 // TopPTR, Null, AnyNull, Constant are all singletons
|
|
1958 return (_offset != OffsetBot) && !below_centerline(_ptr);
|
|
1959 }
|
|
1960
|
|
1961 bool TypePtr::empty(void) const {
|
|
1962 return (_offset == OffsetTop) || above_centerline(_ptr);
|
|
1963 }
|
|
1964
|
|
1965 //=============================================================================
|
|
1966 // Convenience common pre-built types.
|
|
1967 const TypeRawPtr *TypeRawPtr::BOTTOM;
|
|
1968 const TypeRawPtr *TypeRawPtr::NOTNULL;
|
|
1969
|
|
1970 //------------------------------make-------------------------------------------
|
|
1971 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
|
|
1972 assert( ptr != Constant, "what is the constant?" );
|
|
1973 assert( ptr != Null, "Use TypePtr for NULL" );
|
|
1974 return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
|
|
1975 }
|
|
1976
|
|
1977 const TypeRawPtr *TypeRawPtr::make( address bits ) {
|
|
1978 assert( bits, "Use TypePtr for NULL" );
|
|
1979 return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
|
|
1980 }
|
|
1981
|
|
1982 //------------------------------cast_to_ptr_type-------------------------------
|
|
1983 const Type *TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
|
|
1984 assert( ptr != Constant, "what is the constant?" );
|
|
1985 assert( ptr != Null, "Use TypePtr for NULL" );
|
|
1986 assert( _bits==0, "Why cast a constant address?");
|
|
1987 if( ptr == _ptr ) return this;
|
|
1988 return make(ptr);
|
|
1989 }
|
|
1990
|
|
1991 //------------------------------get_con----------------------------------------
|
|
1992 intptr_t TypeRawPtr::get_con() const {
|
|
1993 assert( _ptr == Null || _ptr == Constant, "" );
|
|
1994 return (intptr_t)_bits;
|
|
1995 }
|
|
1996
|
|
1997 //------------------------------meet-------------------------------------------
|
|
1998 // Compute the MEET of two types. It returns a new Type object.
|
|
1999 const Type *TypeRawPtr::xmeet( const Type *t ) const {
|
|
2000 // Perform a fast test for common case; meeting the same types together.
|
|
2001 if( this == t ) return this; // Meeting same type-rep?
|
|
2002
|
|
2003 // Current "this->_base" is RawPtr
|
|
2004 switch( t->base() ) { // switch on original type
|
|
2005 case Bottom: // Ye Olde Default
|
|
2006 return t;
|
|
2007 case Top:
|
|
2008 return this;
|
|
2009 case AnyPtr: // Meeting to AnyPtrs
|
|
2010 break;
|
|
2011 case RawPtr: { // might be top, bot, any/not or constant
|
|
2012 enum PTR tptr = t->is_ptr()->ptr();
|
|
2013 enum PTR ptr = meet_ptr( tptr );
|
|
2014 if( ptr == Constant ) { // Cannot be equal constants, so...
|
|
2015 if( tptr == Constant && _ptr != Constant) return t;
|
|
2016 if( _ptr == Constant && tptr != Constant) return this;
|
|
2017 ptr = NotNull; // Fall down in lattice
|
|
2018 }
|
|
2019 return make( ptr );
|
|
2020 }
|
|
2021
|
|
2022 case OopPtr:
|
|
2023 case InstPtr:
|
|
2024 case KlassPtr:
|
|
2025 case AryPtr:
|
|
2026 return TypePtr::BOTTOM; // Oop meet raw is not well defined
|
|
2027 default: // All else is a mistake
|
|
2028 typerr(t);
|
|
2029 }
|
|
2030
|
|
2031 // Found an AnyPtr type vs self-RawPtr type
|
|
2032 const TypePtr *tp = t->is_ptr();
|
|
2033 switch (tp->ptr()) {
|
|
2034 case TypePtr::TopPTR: return this;
|
|
2035 case TypePtr::BotPTR: return t;
|
|
2036 case TypePtr::Null:
|
|
2037 if( _ptr == TypePtr::TopPTR ) return t;
|
|
2038 return TypeRawPtr::BOTTOM;
|
|
2039 case TypePtr::NotNull: return TypePtr::make( AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0) );
|
|
2040 case TypePtr::AnyNull:
|
|
2041 if( _ptr == TypePtr::Constant) return this;
|
|
2042 return make( meet_ptr(TypePtr::AnyNull) );
|
|
2043 default: ShouldNotReachHere();
|
|
2044 }
|
|
2045 return this;
|
|
2046 }
|
|
2047
|
|
2048 //------------------------------xdual------------------------------------------
|
|
2049 // Dual: compute field-by-field dual
|
|
2050 const Type *TypeRawPtr::xdual() const {
|
|
2051 return new TypeRawPtr( dual_ptr(), _bits );
|
|
2052 }
|
|
2053
|
|
2054 //------------------------------add_offset-------------------------------------
|
|
2055 const TypePtr *TypeRawPtr::add_offset( int offset ) const {
|
|
2056 if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
|
|
2057 if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
|
|
2058 if( offset == 0 ) return this; // No change
|
|
2059 switch (_ptr) {
|
|
2060 case TypePtr::TopPTR:
|
|
2061 case TypePtr::BotPTR:
|
|
2062 case TypePtr::NotNull:
|
|
2063 return this;
|
|
2064 case TypePtr::Null:
|
|
2065 case TypePtr::Constant:
|
|
2066 return make( _bits+offset );
|
|
2067 default: ShouldNotReachHere();
|
|
2068 }
|
|
2069 return NULL; // Lint noise
|
|
2070 }
|
|
2071
|
|
2072 //------------------------------eq---------------------------------------------
|
|
2073 // Structural equality check for Type representations
|
|
2074 bool TypeRawPtr::eq( const Type *t ) const {
|
|
2075 const TypeRawPtr *a = (const TypeRawPtr*)t;
|
|
2076 return _bits == a->_bits && TypePtr::eq(t);
|
|
2077 }
|
|
2078
|
|
2079 //------------------------------hash-------------------------------------------
|
|
2080 // Type-specific hashing function.
|
|
2081 int TypeRawPtr::hash(void) const {
|
|
2082 return (intptr_t)_bits + TypePtr::hash();
|
|
2083 }
|
|
2084
|
|
2085 //------------------------------dump2------------------------------------------
|
|
2086 #ifndef PRODUCT
|
|
2087 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
|
|
2088 if( _ptr == Constant )
|
|
2089 st->print(INTPTR_FORMAT, _bits);
|
|
2090 else
|
|
2091 st->print("rawptr:%s", ptr_msg[_ptr]);
|
|
2092 }
|
|
2093 #endif
|
|
2094
|
|
2095 //=============================================================================
|
|
2096 // Convenience common pre-built type.
|
|
2097 const TypeOopPtr *TypeOopPtr::BOTTOM;
|
|
2098
|
|
2099 //------------------------------make-------------------------------------------
|
|
2100 const TypeOopPtr *TypeOopPtr::make(PTR ptr,
|
|
2101 int offset) {
|
|
2102 assert(ptr != Constant, "no constant generic pointers");
|
|
2103 ciKlass* k = ciKlassKlass::make();
|
|
2104 bool xk = false;
|
|
2105 ciObject* o = NULL;
|
|
2106 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, UNKNOWN_INSTANCE))->hashcons();
|
|
2107 }
|
|
2108
|
|
2109
|
|
2110 //------------------------------cast_to_ptr_type-------------------------------
|
|
2111 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
|
|
2112 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
|
|
2113 if( ptr == _ptr ) return this;
|
|
2114 return make(ptr, _offset);
|
|
2115 }
|
|
2116
|
|
2117 //-----------------------------cast_to_instance-------------------------------
|
|
2118 const TypeOopPtr *TypeOopPtr::cast_to_instance(int instance_id) const {
|
|
2119 // There are no instances of a general oop.
|
|
2120 // Return self unchanged.
|
|
2121 return this;
|
|
2122 }
|
|
2123
|
|
2124 //-----------------------------cast_to_exactness-------------------------------
|
|
2125 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
|
|
2126 // There is no such thing as an exact general oop.
|
|
2127 // Return self unchanged.
|
|
2128 return this;
|
|
2129 }
|
|
2130
|
|
2131
|
|
2132 //------------------------------as_klass_type----------------------------------
|
|
2133 // Return the klass type corresponding to this instance or array type.
|
|
2134 // It is the type that is loaded from an object of this type.
|
|
2135 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
|
|
2136 ciKlass* k = klass();
|
|
2137 bool xk = klass_is_exact();
|
|
2138 if (k == NULL || !k->is_java_klass())
|
|
2139 return TypeKlassPtr::OBJECT;
|
|
2140 else
|
|
2141 return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
|
|
2142 }
|
|
2143
|
|
2144
|
|
2145 //------------------------------meet-------------------------------------------
|
|
2146 // Compute the MEET of two types. It returns a new Type object.
|
|
2147 const Type *TypeOopPtr::xmeet( const Type *t ) const {
|
|
2148 // Perform a fast test for common case; meeting the same types together.
|
|
2149 if( this == t ) return this; // Meeting same type-rep?
|
|
2150
|
|
2151 // Current "this->_base" is OopPtr
|
|
2152 switch (t->base()) { // switch on original type
|
|
2153
|
|
2154 case Int: // Mixing ints & oops happens when javac
|
|
2155 case Long: // reuses local variables
|
|
2156 case FloatTop:
|
|
2157 case FloatCon:
|
|
2158 case FloatBot:
|
|
2159 case DoubleTop:
|
|
2160 case DoubleCon:
|
|
2161 case DoubleBot:
|
|
2162 case Bottom: // Ye Olde Default
|
|
2163 return Type::BOTTOM;
|
|
2164 case Top:
|
|
2165 return this;
|
|
2166
|
|
2167 default: // All else is a mistake
|
|
2168 typerr(t);
|
|
2169
|
|
2170 case RawPtr:
|
|
2171 return TypePtr::BOTTOM; // Oop meet raw is not well defined
|
|
2172
|
|
2173 case AnyPtr: {
|
|
2174 // Found an AnyPtr type vs self-OopPtr type
|
|
2175 const TypePtr *tp = t->is_ptr();
|
|
2176 int offset = meet_offset(tp->offset());
|
|
2177 PTR ptr = meet_ptr(tp->ptr());
|
|
2178 switch (tp->ptr()) {
|
|
2179 case Null:
|
|
2180 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset);
|
|
2181 // else fall through:
|
|
2182 case TopPTR:
|
|
2183 case AnyNull:
|
|
2184 return make(ptr, offset);
|
|
2185 case BotPTR:
|
|
2186 case NotNull:
|
|
2187 return TypePtr::make(AnyPtr, ptr, offset);
|
|
2188 default: typerr(t);
|
|
2189 }
|
|
2190 }
|
|
2191
|
|
2192 case OopPtr: { // Meeting to other OopPtrs
|
|
2193 const TypeOopPtr *tp = t->is_oopptr();
|
|
2194 return make( meet_ptr(tp->ptr()), meet_offset(tp->offset()) );
|
|
2195 }
|
|
2196
|
|
2197 case InstPtr: // For these, flip the call around to cut down
|
|
2198 case KlassPtr: // on the cases I have to handle.
|
|
2199 case AryPtr:
|
|
2200 return t->xmeet(this); // Call in reverse direction
|
|
2201
|
|
2202 } // End of switch
|
|
2203 return this; // Return the double constant
|
|
2204 }
|
|
2205
|
|
2206
|
|
2207 //------------------------------xdual------------------------------------------
|
|
2208 // Dual of a pure heap pointer. No relevant klass or oop information.
|
|
2209 const Type *TypeOopPtr::xdual() const {
|
|
2210 assert(klass() == ciKlassKlass::make(), "no klasses here");
|
|
2211 assert(const_oop() == NULL, "no constants here");
|
|
2212 return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance() );
|
|
2213 }
|
|
2214
|
|
2215 //--------------------------make_from_klass_common-----------------------------
|
|
2216 // Computes the element-type given a klass.
|
|
2217 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
|
|
2218 assert(klass->is_java_klass(), "must be java language klass");
|
|
2219 if (klass->is_instance_klass()) {
|
|
2220 Compile* C = Compile::current();
|
|
2221 Dependencies* deps = C->dependencies();
|
|
2222 assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
|
|
2223 // Element is an instance
|
|
2224 bool klass_is_exact = false;
|
|
2225 if (klass->is_loaded()) {
|
|
2226 // Try to set klass_is_exact.
|
|
2227 ciInstanceKlass* ik = klass->as_instance_klass();
|
|
2228 klass_is_exact = ik->is_final();
|
|
2229 if (!klass_is_exact && klass_change
|
|
2230 && deps != NULL && UseUniqueSubclasses) {
|
|
2231 ciInstanceKlass* sub = ik->unique_concrete_subklass();
|
|
2232 if (sub != NULL) {
|
|
2233 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
|
|
2234 klass = ik = sub;
|
|
2235 klass_is_exact = sub->is_final();
|
|
2236 }
|
|
2237 }
|
|
2238 if (!klass_is_exact && try_for_exact
|
|
2239 && deps != NULL && UseExactTypes) {
|
|
2240 if (!ik->is_interface() && !ik->has_subklass()) {
|
|
2241 // Add a dependence; if concrete subclass added we need to recompile
|
|
2242 deps->assert_leaf_type(ik);
|
|
2243 klass_is_exact = true;
|
|
2244 }
|
|
2245 }
|
|
2246 }
|
|
2247 return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0);
|
|
2248 } else if (klass->is_obj_array_klass()) {
|
|
2249 // Element is an object array. Recursively call ourself.
|
|
2250 const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact);
|
|
2251 bool xk = etype->klass_is_exact();
|
|
2252 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
|
|
2253 // We used to pass NotNull in here, asserting that the sub-arrays
|
|
2254 // are all not-null. This is not true in generally, as code can
|
|
2255 // slam NULLs down in the subarrays.
|
|
2256 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0);
|
|
2257 return arr;
|
|
2258 } else if (klass->is_type_array_klass()) {
|
|
2259 // Element is an typeArray
|
|
2260 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
|
|
2261 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
|
|
2262 // We used to pass NotNull in here, asserting that the array pointer
|
|
2263 // is not-null. That was not true in general.
|
|
2264 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
|
|
2265 return arr;
|
|
2266 } else {
|
|
2267 ShouldNotReachHere();
|
|
2268 return NULL;
|
|
2269 }
|
|
2270 }
|
|
2271
|
|
2272 //------------------------------make_from_constant-----------------------------
|
|
2273 // Make a java pointer from an oop constant
|
|
2274 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o) {
|
|
2275 if (o->is_method_data() || o->is_method()) {
|
|
2276 // Treat much like a typeArray of bytes, like below, but fake the type...
|
|
2277 assert(o->has_encoding(), "must be a perm space object");
|
|
2278 const Type* etype = (Type*)get_const_basic_type(T_BYTE);
|
|
2279 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
|
|
2280 ciKlass *klass = ciTypeArrayKlass::make((BasicType) T_BYTE);
|
|
2281 assert(o->has_encoding(), "method data oops should be tenured");
|
|
2282 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
|
|
2283 return arr;
|
|
2284 } else {
|
|
2285 assert(o->is_java_object(), "must be java language object");
|
|
2286 assert(!o->is_null_object(), "null object not yet handled here.");
|
|
2287 ciKlass *klass = o->klass();
|
|
2288 if (klass->is_instance_klass()) {
|
|
2289 // Element is an instance
|
|
2290 if (!o->has_encoding()) { // not a perm-space constant
|
|
2291 // %%% remove this restriction by rewriting non-perm ConPNodes in a later phase
|
|
2292 return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
|
|
2293 }
|
|
2294 return TypeInstPtr::make(o);
|
|
2295 } else if (klass->is_obj_array_klass()) {
|
|
2296 // Element is an object array. Recursively call ourself.
|
|
2297 const Type *etype =
|
|
2298 TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
|
|
2299 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
|
|
2300 // We used to pass NotNull in here, asserting that the sub-arrays
|
|
2301 // are all not-null. This is not true in generally, as code can
|
|
2302 // slam NULLs down in the subarrays.
|
|
2303 if (!o->has_encoding()) { // not a perm-space constant
|
|
2304 // %%% remove this restriction by rewriting non-perm ConPNodes in a later phase
|
|
2305 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
|
|
2306 }
|
|
2307 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
|
|
2308 return arr;
|
|
2309 } else if (klass->is_type_array_klass()) {
|
|
2310 // Element is an typeArray
|
|
2311 const Type* etype =
|
|
2312 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
|
|
2313 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
|
|
2314 // We used to pass NotNull in here, asserting that the array pointer
|
|
2315 // is not-null. That was not true in general.
|
|
2316 if (!o->has_encoding()) { // not a perm-space constant
|
|
2317 // %%% remove this restriction by rewriting non-perm ConPNodes in a later phase
|
|
2318 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
|
|
2319 }
|
|
2320 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
|
|
2321 return arr;
|
|
2322 }
|
|
2323 }
|
|
2324
|
|
2325 ShouldNotReachHere();
|
|
2326 return NULL;
|
|
2327 }
|
|
2328
|
|
2329 //------------------------------get_con----------------------------------------
|
|
2330 intptr_t TypeOopPtr::get_con() const {
|
|
2331 assert( _ptr == Null || _ptr == Constant, "" );
|
|
2332 assert( _offset >= 0, "" );
|
|
2333
|
|
2334 if (_offset != 0) {
|
|
2335 // After being ported to the compiler interface, the compiler no longer
|
|
2336 // directly manipulates the addresses of oops. Rather, it only has a pointer
|
|
2337 // to a handle at compile time. This handle is embedded in the generated
|
|
2338 // code and dereferenced at the time the nmethod is made. Until that time,
|
|
2339 // it is not reasonable to do arithmetic with the addresses of oops (we don't
|
|
2340 // have access to the addresses!). This does not seem to currently happen,
|
|
2341 // but this assertion here is to help prevent its occurrance.
|
|
2342 tty->print_cr("Found oop constant with non-zero offset");
|
|
2343 ShouldNotReachHere();
|
|
2344 }
|
|
2345
|
|
2346 return (intptr_t)const_oop()->encoding();
|
|
2347 }
|
|
2348
|
|
2349
|
|
2350 //-----------------------------filter------------------------------------------
|
|
2351 // Do not allow interface-vs.-noninterface joins to collapse to top.
|
|
2352 const Type *TypeOopPtr::filter( const Type *kills ) const {
|
|
2353
|
|
2354 const Type* ft = join(kills);
|
|
2355 const TypeInstPtr* ftip = ft->isa_instptr();
|
|
2356 const TypeInstPtr* ktip = kills->isa_instptr();
|
|
2357
|
|
2358 if (ft->empty()) {
|
|
2359 // Check for evil case of 'this' being a class and 'kills' expecting an
|
|
2360 // interface. This can happen because the bytecodes do not contain
|
|
2361 // enough type info to distinguish a Java-level interface variable
|
|
2362 // from a Java-level object variable. If we meet 2 classes which
|
|
2363 // both implement interface I, but their meet is at 'j/l/O' which
|
|
2364 // doesn't implement I, we have no way to tell if the result should
|
|
2365 // be 'I' or 'j/l/O'. Thus we'll pick 'j/l/O'. If this then flows
|
|
2366 // into a Phi which "knows" it's an Interface type we'll have to
|
|
2367 // uplift the type.
|
|
2368 if (!empty() && ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface())
|
|
2369 return kills; // Uplift to interface
|
|
2370
|
|
2371 return Type::TOP; // Canonical empty value
|
|
2372 }
|
|
2373
|
|
2374 // If we have an interface-typed Phi or cast and we narrow to a class type,
|
|
2375 // the join should report back the class. However, if we have a J/L/Object
|
|
2376 // class-typed Phi and an interface flows in, it's possible that the meet &
|
|
2377 // join report an interface back out. This isn't possible but happens
|
|
2378 // because the type system doesn't interact well with interfaces.
|
|
2379 if (ftip != NULL && ktip != NULL &&
|
|
2380 ftip->is_loaded() && ftip->klass()->is_interface() &&
|
|
2381 ktip->is_loaded() && !ktip->klass()->is_interface()) {
|
|
2382 // Happens in a CTW of rt.jar, 320-341, no extra flags
|
|
2383 return ktip->cast_to_ptr_type(ftip->ptr());
|
|
2384 }
|
|
2385
|
|
2386 return ft;
|
|
2387 }
|
|
2388
|
|
2389 //------------------------------eq---------------------------------------------
|
|
2390 // Structural equality check for Type representations
|
|
2391 bool TypeOopPtr::eq( const Type *t ) const {
|
|
2392 const TypeOopPtr *a = (const TypeOopPtr*)t;
|
|
2393 if (_klass_is_exact != a->_klass_is_exact ||
|
|
2394 _instance_id != a->_instance_id) return false;
|
|
2395 ciObject* one = const_oop();
|
|
2396 ciObject* two = a->const_oop();
|
|
2397 if (one == NULL || two == NULL) {
|
|
2398 return (one == two) && TypePtr::eq(t);
|
|
2399 } else {
|
|
2400 return one->equals(two) && TypePtr::eq(t);
|
|
2401 }
|
|
2402 }
|
|
2403
|
|
2404 //------------------------------hash-------------------------------------------
|
|
2405 // Type-specific hashing function.
|
|
2406 int TypeOopPtr::hash(void) const {
|
|
2407 return
|
|
2408 (const_oop() ? const_oop()->hash() : 0) +
|
|
2409 _klass_is_exact +
|
|
2410 _instance_id +
|
|
2411 TypePtr::hash();
|
|
2412 }
|
|
2413
|
|
2414 //------------------------------dump2------------------------------------------
|
|
2415 #ifndef PRODUCT
|
|
2416 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
|
|
2417 st->print("oopptr:%s", ptr_msg[_ptr]);
|
|
2418 if( _klass_is_exact ) st->print(":exact");
|
|
2419 if( const_oop() ) st->print(INTPTR_FORMAT, const_oop());
|
|
2420 switch( _offset ) {
|
|
2421 case OffsetTop: st->print("+top"); break;
|
|
2422 case OffsetBot: st->print("+any"); break;
|
|
2423 case 0: break;
|
|
2424 default: st->print("+%d",_offset); break;
|
|
2425 }
|
|
2426 if (_instance_id != UNKNOWN_INSTANCE)
|
|
2427 st->print(",iid=%d",_instance_id);
|
|
2428 }
|
|
2429 #endif
|
|
2430
|
|
2431 //------------------------------singleton--------------------------------------
|
|
2432 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
|
|
2433 // constants
|
|
2434 bool TypeOopPtr::singleton(void) const {
|
|
2435 // detune optimizer to not generate constant oop + constant offset as a constant!
|
|
2436 // TopPTR, Null, AnyNull, Constant are all singletons
|
|
2437 return (_offset == 0) && !below_centerline(_ptr);
|
|
2438 }
|
|
2439
|
|
2440 //------------------------------xadd_offset------------------------------------
|
|
2441 int TypeOopPtr::xadd_offset( int offset ) const {
|
|
2442 // Adding to 'TOP' offset? Return 'TOP'!
|
|
2443 if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
|
|
2444 // Adding to 'BOTTOM' offset? Return 'BOTTOM'!
|
|
2445 if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
|
|
2446
|
|
2447 // assert( _offset >= 0 && _offset+offset >= 0, "" );
|
|
2448 // It is possible to construct a negative offset during PhaseCCP
|
|
2449
|
|
2450 return _offset+offset; // Sum valid offsets
|
|
2451 }
|
|
2452
|
|
2453 //------------------------------add_offset-------------------------------------
|
|
2454 const TypePtr *TypeOopPtr::add_offset( int offset ) const {
|
|
2455 return make( _ptr, xadd_offset(offset) );
|
|
2456 }
|
|
2457
|
|
2458 int TypeOopPtr::meet_instance(int iid) const {
|
|
2459 if (iid == 0) {
|
|
2460 return (_instance_id < 0) ? _instance_id : UNKNOWN_INSTANCE;
|
|
2461 } else if (_instance_id == UNKNOWN_INSTANCE) {
|
|
2462 return (iid < 0) ? iid : UNKNOWN_INSTANCE;
|
|
2463 } else {
|
|
2464 return (_instance_id == iid) ? iid : UNKNOWN_INSTANCE;
|
|
2465 }
|
|
2466 }
|
|
2467
|
|
2468 //=============================================================================
|
|
2469 // Convenience common pre-built types.
|
|
2470 const TypeInstPtr *TypeInstPtr::NOTNULL;
|
|
2471 const TypeInstPtr *TypeInstPtr::BOTTOM;
|
|
2472 const TypeInstPtr *TypeInstPtr::MIRROR;
|
|
2473 const TypeInstPtr *TypeInstPtr::MARK;
|
|
2474 const TypeInstPtr *TypeInstPtr::KLASS;
|
|
2475
|
|
2476 //------------------------------TypeInstPtr-------------------------------------
|
|
2477 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off, int instance_id)
|
|
2478 : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id), _name(k->name()) {
|
|
2479 assert(k != NULL &&
|
|
2480 (k->is_loaded() || o == NULL),
|
|
2481 "cannot have constants with non-loaded klass");
|
|
2482 };
|
|
2483
|
|
2484 //------------------------------make-------------------------------------------
|
|
2485 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
|
|
2486 ciKlass* k,
|
|
2487 bool xk,
|
|
2488 ciObject* o,
|
|
2489 int offset,
|
|
2490 int instance_id) {
|
|
2491 assert( !k->is_loaded() || k->is_instance_klass() ||
|
|
2492 k->is_method_klass(), "Must be for instance or method");
|
|
2493 // Either const_oop() is NULL or else ptr is Constant
|
|
2494 assert( (!o && ptr != Constant) || (o && ptr == Constant),
|
|
2495 "constant pointers must have a value supplied" );
|
|
2496 // Ptr is never Null
|
|
2497 assert( ptr != Null, "NULL pointers are not typed" );
|
|
2498
|
|
2499 if (instance_id != UNKNOWN_INSTANCE)
|
|
2500 xk = true; // instances are always exactly typed
|
|
2501 if (!UseExactTypes) xk = false;
|
|
2502 if (ptr == Constant) {
|
|
2503 // Note: This case includes meta-object constants, such as methods.
|
|
2504 xk = true;
|
|
2505 } else if (k->is_loaded()) {
|
|
2506 ciInstanceKlass* ik = k->as_instance_klass();
|
|
2507 if (!xk && ik->is_final()) xk = true; // no inexact final klass
|
|
2508 if (xk && ik->is_interface()) xk = false; // no exact interface
|
|
2509 }
|
|
2510
|
|
2511 // Now hash this baby
|
|
2512 TypeInstPtr *result =
|
|
2513 (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id))->hashcons();
|
|
2514
|
|
2515 return result;
|
|
2516 }
|
|
2517
|
|
2518
|
|
2519 //------------------------------cast_to_ptr_type-------------------------------
|
|
2520 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
|
|
2521 if( ptr == _ptr ) return this;
|
|
2522 // Reconstruct _sig info here since not a problem with later lazy
|
|
2523 // construction, _sig will show up on demand.
|
|
2524 return make(ptr, klass(), klass_is_exact(), const_oop(), _offset);
|
|
2525 }
|
|
2526
|
|
2527
|
|
2528 //-----------------------------cast_to_exactness-------------------------------
|
|
2529 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
|
|
2530 if( klass_is_exact == _klass_is_exact ) return this;
|
|
2531 if (!UseExactTypes) return this;
|
|
2532 if (!_klass->is_loaded()) return this;
|
|
2533 ciInstanceKlass* ik = _klass->as_instance_klass();
|
|
2534 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
|
|
2535 if( ik->is_interface() ) return this; // cannot set xk
|
|
2536 return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id);
|
|
2537 }
|
|
2538
|
|
2539 //-----------------------------cast_to_instance-------------------------------
|
|
2540 const TypeOopPtr *TypeInstPtr::cast_to_instance(int instance_id) const {
|
|
2541 if( instance_id == _instance_id) return this;
|
|
2542 bool exact = (instance_id == UNKNOWN_INSTANCE) ? _klass_is_exact : true;
|
|
2543
|
|
2544 return make(ptr(), klass(), exact, const_oop(), _offset, instance_id);
|
|
2545 }
|
|
2546
|
|
2547 //------------------------------xmeet_unloaded---------------------------------
|
|
2548 // Compute the MEET of two InstPtrs when at least one is unloaded.
|
|
2549 // Assume classes are different since called after check for same name/class-loader
|
|
2550 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
|
|
2551 int off = meet_offset(tinst->offset());
|
|
2552 PTR ptr = meet_ptr(tinst->ptr());
|
|
2553
|
|
2554 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
|
|
2555 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
|
|
2556 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
|
|
2557 //
|
|
2558 // Meet unloaded class with java/lang/Object
|
|
2559 //
|
|
2560 // Meet
|
|
2561 // | Unloaded Class
|
|
2562 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
|
|
2563 // ===================================================================
|
|
2564 // TOP | ..........................Unloaded......................|
|
|
2565 // AnyNull | U-AN |................Unloaded......................|
|
|
2566 // Constant | ... O-NN .................................. | O-BOT |
|
|
2567 // NotNull | ... O-NN .................................. | O-BOT |
|
|
2568 // BOTTOM | ........................Object-BOTTOM ..................|
|
|
2569 //
|
|
2570 assert(loaded->ptr() != TypePtr::Null, "insanity check");
|
|
2571 //
|
|
2572 if( loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
|
|
2573 else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make( ptr, unloaded->klass() ); }
|
|
2574 else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
|
|
2575 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
|
|
2576 if (unloaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
|
|
2577 else { return TypeInstPtr::NOTNULL; }
|
|
2578 }
|
|
2579 else if( unloaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
|
|
2580
|
|
2581 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
|
|
2582 }
|
|
2583
|
|
2584 // Both are unloaded, not the same class, not Object
|
|
2585 // Or meet unloaded with a different loaded class, not java/lang/Object
|
|
2586 if( ptr != TypePtr::BotPTR ) {
|
|
2587 return TypeInstPtr::NOTNULL;
|
|
2588 }
|
|
2589 return TypeInstPtr::BOTTOM;
|
|
2590 }
|
|
2591
|
|
2592
|
|
2593 //------------------------------meet-------------------------------------------
|
|
2594 // Compute the MEET of two types. It returns a new Type object.
|
|
2595 const Type *TypeInstPtr::xmeet( const Type *t ) const {
|
|
2596 // Perform a fast test for common case; meeting the same types together.
|
|
2597 if( this == t ) return this; // Meeting same type-rep?
|
|
2598
|
|
2599 // Current "this->_base" is Pointer
|
|
2600 switch (t->base()) { // switch on original type
|
|
2601
|
|
2602 case Int: // Mixing ints & oops happens when javac
|
|
2603 case Long: // reuses local variables
|
|
2604 case FloatTop:
|
|
2605 case FloatCon:
|
|
2606 case FloatBot:
|
|
2607 case DoubleTop:
|
|
2608 case DoubleCon:
|
|
2609 case DoubleBot:
|
|
2610 case Bottom: // Ye Olde Default
|
|
2611 return Type::BOTTOM;
|
|
2612 case Top:
|
|
2613 return this;
|
|
2614
|
|
2615 default: // All else is a mistake
|
|
2616 typerr(t);
|
|
2617
|
|
2618 case RawPtr: return TypePtr::BOTTOM;
|
|
2619
|
|
2620 case AryPtr: { // All arrays inherit from Object class
|
|
2621 const TypeAryPtr *tp = t->is_aryptr();
|
|
2622 int offset = meet_offset(tp->offset());
|
|
2623 PTR ptr = meet_ptr(tp->ptr());
|
|
2624 int iid = meet_instance(tp->instance_id());
|
|
2625 switch (ptr) {
|
|
2626 case TopPTR:
|
|
2627 case AnyNull: // Fall 'down' to dual of object klass
|
|
2628 if (klass()->equals(ciEnv::current()->Object_klass())) {
|
|
2629 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, iid);
|
|
2630 } else {
|
|
2631 // cannot subclass, so the meet has to fall badly below the centerline
|
|
2632 ptr = NotNull;
|
|
2633 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, iid);
|
|
2634 }
|
|
2635 case Constant:
|
|
2636 case NotNull:
|
|
2637 case BotPTR: // Fall down to object klass
|
|
2638 // LCA is object_klass, but if we subclass from the top we can do better
|
|
2639 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
|
|
2640 // If 'this' (InstPtr) is above the centerline and it is Object class
|
|
2641 // then we can subclass in the Java class heirarchy.
|
|
2642 if (klass()->equals(ciEnv::current()->Object_klass())) {
|
|
2643 // that is, tp's array type is a subtype of my klass
|
|
2644 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, iid);
|
|
2645 }
|
|
2646 }
|
|
2647 // The other case cannot happen, since I cannot be a subtype of an array.
|
|
2648 // The meet falls down to Object class below centerline.
|
|
2649 if( ptr == Constant )
|
|
2650 ptr = NotNull;
|
|
2651 return make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, iid );
|
|
2652 default: typerr(t);
|
|
2653 }
|
|
2654 }
|
|
2655
|
|
2656 case OopPtr: { // Meeting to OopPtrs
|
|
2657 // Found a OopPtr type vs self-InstPtr type
|
|
2658 const TypePtr *tp = t->is_oopptr();
|
|
2659 int offset = meet_offset(tp->offset());
|
|
2660 PTR ptr = meet_ptr(tp->ptr());
|
|
2661 switch (tp->ptr()) {
|
|
2662 case TopPTR:
|
|
2663 case AnyNull:
|
|
2664 return make(ptr, klass(), klass_is_exact(),
|
|
2665 (ptr == Constant ? const_oop() : NULL), offset);
|
|
2666 case NotNull:
|
|
2667 case BotPTR:
|
|
2668 return TypeOopPtr::make(ptr, offset);
|
|
2669 default: typerr(t);
|
|
2670 }
|
|
2671 }
|
|
2672
|
|
2673 case AnyPtr: { // Meeting to AnyPtrs
|
|
2674 // Found an AnyPtr type vs self-InstPtr type
|
|
2675 const TypePtr *tp = t->is_ptr();
|
|
2676 int offset = meet_offset(tp->offset());
|
|
2677 PTR ptr = meet_ptr(tp->ptr());
|
|
2678 switch (tp->ptr()) {
|
|
2679 case Null:
|
|
2680 if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset );
|
|
2681 case TopPTR:
|
|
2682 case AnyNull:
|
|
2683 return make( ptr, klass(), klass_is_exact(),
|
|
2684 (ptr == Constant ? const_oop() : NULL), offset );
|
|
2685 case NotNull:
|
|
2686 case BotPTR:
|
|
2687 return TypePtr::make( AnyPtr, ptr, offset );
|
|
2688 default: typerr(t);
|
|
2689 }
|
|
2690 }
|
|
2691
|
|
2692 /*
|
|
2693 A-top }
|
|
2694 / | \ } Tops
|
|
2695 B-top A-any C-top }
|
|
2696 | / | \ | } Any-nulls
|
|
2697 B-any | C-any }
|
|
2698 | | |
|
|
2699 B-con A-con C-con } constants; not comparable across classes
|
|
2700 | | |
|
|
2701 B-not | C-not }
|
|
2702 | \ | / | } not-nulls
|
|
2703 B-bot A-not C-bot }
|
|
2704 \ | / } Bottoms
|
|
2705 A-bot }
|
|
2706 */
|
|
2707
|
|
2708 case InstPtr: { // Meeting 2 Oops?
|
|
2709 // Found an InstPtr sub-type vs self-InstPtr type
|
|
2710 const TypeInstPtr *tinst = t->is_instptr();
|
|
2711 int off = meet_offset( tinst->offset() );
|
|
2712 PTR ptr = meet_ptr( tinst->ptr() );
|
|
2713 int instance_id = meet_instance(tinst->instance_id());
|
|
2714
|
|
2715 // Check for easy case; klasses are equal (and perhaps not loaded!)
|
|
2716 // If we have constants, then we created oops so classes are loaded
|
|
2717 // and we can handle the constants further down. This case handles
|
|
2718 // both-not-loaded or both-loaded classes
|
|
2719 if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
|
|
2720 return make( ptr, klass(), klass_is_exact(), NULL, off, instance_id );
|
|
2721 }
|
|
2722
|
|
2723 // Classes require inspection in the Java klass hierarchy. Must be loaded.
|
|
2724 ciKlass* tinst_klass = tinst->klass();
|
|
2725 ciKlass* this_klass = this->klass();
|
|
2726 bool tinst_xk = tinst->klass_is_exact();
|
|
2727 bool this_xk = this->klass_is_exact();
|
|
2728 if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
|
|
2729 // One of these classes has not been loaded
|
|
2730 const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
|
|
2731 #ifndef PRODUCT
|
|
2732 if( PrintOpto && Verbose ) {
|
|
2733 tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
|
|
2734 tty->print(" this == "); this->dump(); tty->cr();
|
|
2735 tty->print(" tinst == "); tinst->dump(); tty->cr();
|
|
2736 }
|
|
2737 #endif
|
|
2738 return unloaded_meet;
|
|
2739 }
|
|
2740
|
|
2741 // Handle mixing oops and interfaces first.
|
|
2742 if( this_klass->is_interface() && !tinst_klass->is_interface() ) {
|
|
2743 ciKlass *tmp = tinst_klass; // Swap interface around
|
|
2744 tinst_klass = this_klass;
|
|
2745 this_klass = tmp;
|
|
2746 bool tmp2 = tinst_xk;
|
|
2747 tinst_xk = this_xk;
|
|
2748 this_xk = tmp2;
|
|
2749 }
|
|
2750 if (tinst_klass->is_interface() &&
|
|
2751 !(this_klass->is_interface() ||
|
|
2752 // Treat java/lang/Object as an honorary interface,
|
|
2753 // because we need a bottom for the interface hierarchy.
|
|
2754 this_klass == ciEnv::current()->Object_klass())) {
|
|
2755 // Oop meets interface!
|
|
2756
|
|
2757 // See if the oop subtypes (implements) interface.
|
|
2758 ciKlass *k;
|
|
2759 bool xk;
|
|
2760 if( this_klass->is_subtype_of( tinst_klass ) ) {
|
|
2761 // Oop indeed subtypes. Now keep oop or interface depending
|
|
2762 // on whether we are both above the centerline or either is
|
|
2763 // below the centerline. If we are on the centerline
|
|
2764 // (e.g., Constant vs. AnyNull interface), use the constant.
|
|
2765 k = below_centerline(ptr) ? tinst_klass : this_klass;
|
|
2766 // If we are keeping this_klass, keep its exactness too.
|
|
2767 xk = below_centerline(ptr) ? tinst_xk : this_xk;
|
|
2768 } else { // Does not implement, fall to Object
|
|
2769 // Oop does not implement interface, so mixing falls to Object
|
|
2770 // just like the verifier does (if both are above the
|
|
2771 // centerline fall to interface)
|
|
2772 k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
|
|
2773 xk = above_centerline(ptr) ? tinst_xk : false;
|
|
2774 // Watch out for Constant vs. AnyNull interface.
|
|
2775 if (ptr == Constant) ptr = NotNull; // forget it was a constant
|
|
2776 }
|
|
2777 ciObject* o = NULL; // the Constant value, if any
|
|
2778 if (ptr == Constant) {
|
|
2779 // Find out which constant.
|
|
2780 o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
|
|
2781 }
|
|
2782 return make( ptr, k, xk, o, off );
|
|
2783 }
|
|
2784
|
|
2785 // Either oop vs oop or interface vs interface or interface vs Object
|
|
2786
|
|
2787 // !!! Here's how the symmetry requirement breaks down into invariants:
|
|
2788 // If we split one up & one down AND they subtype, take the down man.
|
|
2789 // If we split one up & one down AND they do NOT subtype, "fall hard".
|
|
2790 // If both are up and they subtype, take the subtype class.
|
|
2791 // If both are up and they do NOT subtype, "fall hard".
|
|
2792 // If both are down and they subtype, take the supertype class.
|
|
2793 // If both are down and they do NOT subtype, "fall hard".
|
|
2794 // Constants treated as down.
|
|
2795
|
|
2796 // Now, reorder the above list; observe that both-down+subtype is also
|
|
2797 // "fall hard"; "fall hard" becomes the default case:
|
|
2798 // If we split one up & one down AND they subtype, take the down man.
|
|
2799 // If both are up and they subtype, take the subtype class.
|
|
2800
|
|
2801 // If both are down and they subtype, "fall hard".
|
|
2802 // If both are down and they do NOT subtype, "fall hard".
|
|
2803 // If both are up and they do NOT subtype, "fall hard".
|
|
2804 // If we split one up & one down AND they do NOT subtype, "fall hard".
|
|
2805
|
|
2806 // If a proper subtype is exact, and we return it, we return it exactly.
|
|
2807 // If a proper supertype is exact, there can be no subtyping relationship!
|
|
2808 // If both types are equal to the subtype, exactness is and-ed below the
|
|
2809 // centerline and or-ed above it. (N.B. Constants are always exact.)
|
|
2810
|
|
2811 // Check for subtyping:
|
|
2812 ciKlass *subtype = NULL;
|
|
2813 bool subtype_exact = false;
|
|
2814 if( tinst_klass->equals(this_klass) ) {
|
|
2815 subtype = this_klass;
|
|
2816 subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk);
|
|
2817 } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) {
|
|
2818 subtype = this_klass; // Pick subtyping class
|
|
2819 subtype_exact = this_xk;
|
|
2820 } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) {
|
|
2821 subtype = tinst_klass; // Pick subtyping class
|
|
2822 subtype_exact = tinst_xk;
|
|
2823 }
|
|
2824
|
|
2825 if( subtype ) {
|
|
2826 if( above_centerline(ptr) ) { // both are up?
|
|
2827 this_klass = tinst_klass = subtype;
|
|
2828 this_xk = tinst_xk = subtype_exact;
|
|
2829 } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) {
|
|
2830 this_klass = tinst_klass; // tinst is down; keep down man
|
|
2831 this_xk = tinst_xk;
|
|
2832 } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) {
|
|
2833 tinst_klass = this_klass; // this is down; keep down man
|
|
2834 tinst_xk = this_xk;
|
|
2835 } else {
|
|
2836 this_xk = subtype_exact; // either they are equal, or we'll do an LCA
|
|
2837 }
|
|
2838 }
|
|
2839
|
|
2840 // Check for classes now being equal
|
|
2841 if (tinst_klass->equals(this_klass)) {
|
|
2842 // If the klasses are equal, the constants may still differ. Fall to
|
|
2843 // NotNull if they do (neither constant is NULL; that is a special case
|
|
2844 // handled elsewhere).
|
|
2845 ciObject* o = NULL; // Assume not constant when done
|
|
2846 ciObject* this_oop = const_oop();
|
|
2847 ciObject* tinst_oop = tinst->const_oop();
|
|
2848 if( ptr == Constant ) {
|
|
2849 if (this_oop != NULL && tinst_oop != NULL &&
|
|
2850 this_oop->equals(tinst_oop) )
|
|
2851 o = this_oop;
|
|
2852 else if (above_centerline(this ->_ptr))
|
|
2853 o = tinst_oop;
|
|
2854 else if (above_centerline(tinst ->_ptr))
|
|
2855 o = this_oop;
|
|
2856 else
|
|
2857 ptr = NotNull;
|
|
2858 }
|
|
2859 return make( ptr, this_klass, this_xk, o, off, instance_id );
|
|
2860 } // Else classes are not equal
|
|
2861
|
|
2862 // Since klasses are different, we require a LCA in the Java
|
|
2863 // class hierarchy - which means we have to fall to at least NotNull.
|
|
2864 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
|
|
2865 ptr = NotNull;
|
|
2866
|
|
2867 // Now we find the LCA of Java classes
|
|
2868 ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
|
|
2869 return make( ptr, k, false, NULL, off );
|
|
2870 } // End of case InstPtr
|
|
2871
|
|
2872 case KlassPtr:
|
|
2873 return TypeInstPtr::BOTTOM;
|
|
2874
|
|
2875 } // End of switch
|
|
2876 return this; // Return the double constant
|
|
2877 }
|
|
2878
|
|
2879
|
|
2880 //------------------------java_mirror_type--------------------------------------
|
|
2881 ciType* TypeInstPtr::java_mirror_type() const {
|
|
2882 // must be a singleton type
|
|
2883 if( const_oop() == NULL ) return NULL;
|
|
2884
|
|
2885 // must be of type java.lang.Class
|
|
2886 if( klass() != ciEnv::current()->Class_klass() ) return NULL;
|
|
2887
|
|
2888 return const_oop()->as_instance()->java_mirror_type();
|
|
2889 }
|
|
2890
|
|
2891
|
|
2892 //------------------------------xdual------------------------------------------
|
|
2893 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
|
|
2894 // inheritence mechanism.
|
|
2895 const Type *TypeInstPtr::xdual() const {
|
|
2896 return new TypeInstPtr( dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance() );
|
|
2897 }
|
|
2898
|
|
2899 //------------------------------eq---------------------------------------------
|
|
2900 // Structural equality check for Type representations
|
|
2901 bool TypeInstPtr::eq( const Type *t ) const {
|
|
2902 const TypeInstPtr *p = t->is_instptr();
|
|
2903 return
|
|
2904 klass()->equals(p->klass()) &&
|
|
2905 TypeOopPtr::eq(p); // Check sub-type stuff
|
|
2906 }
|
|
2907
|
|
2908 //------------------------------hash-------------------------------------------
|
|
2909 // Type-specific hashing function.
|
|
2910 int TypeInstPtr::hash(void) const {
|
|
2911 int hash = klass()->hash() + TypeOopPtr::hash();
|
|
2912 return hash;
|
|
2913 }
|
|
2914
|
|
2915 //------------------------------dump2------------------------------------------
|
|
2916 // Dump oop Type
|
|
2917 #ifndef PRODUCT
|
|
2918 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
|
|
2919 // Print the name of the klass.
|
|
2920 klass()->print_name_on(st);
|
|
2921
|
|
2922 switch( _ptr ) {
|
|
2923 case Constant:
|
|
2924 // TO DO: Make CI print the hex address of the underlying oop.
|
|
2925 if (WizardMode || Verbose) {
|
|
2926 const_oop()->print_oop(st);
|
|
2927 }
|
|
2928 case BotPTR:
|
|
2929 if (!WizardMode && !Verbose) {
|
|
2930 if( _klass_is_exact ) st->print(":exact");
|
|
2931 break;
|
|
2932 }
|
|
2933 case TopPTR:
|
|
2934 case AnyNull:
|
|
2935 case NotNull:
|
|
2936 st->print(":%s", ptr_msg[_ptr]);
|
|
2937 if( _klass_is_exact ) st->print(":exact");
|
|
2938 break;
|
|
2939 }
|
|
2940
|
|
2941 if( _offset ) { // Dump offset, if any
|
|
2942 if( _offset == OffsetBot ) st->print("+any");
|
|
2943 else if( _offset == OffsetTop ) st->print("+unknown");
|
|
2944 else st->print("+%d", _offset);
|
|
2945 }
|
|
2946
|
|
2947 st->print(" *");
|
|
2948 if (_instance_id != UNKNOWN_INSTANCE)
|
|
2949 st->print(",iid=%d",_instance_id);
|
|
2950 }
|
|
2951 #endif
|
|
2952
|
|
2953 //------------------------------add_offset-------------------------------------
|
|
2954 const TypePtr *TypeInstPtr::add_offset( int offset ) const {
|
|
2955 return make( _ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), _instance_id );
|
|
2956 }
|
|
2957
|
|
2958 //=============================================================================
|
|
2959 // Convenience common pre-built types.
|
|
2960 const TypeAryPtr *TypeAryPtr::RANGE;
|
|
2961 const TypeAryPtr *TypeAryPtr::OOPS;
|
|
2962 const TypeAryPtr *TypeAryPtr::BYTES;
|
|
2963 const TypeAryPtr *TypeAryPtr::SHORTS;
|
|
2964 const TypeAryPtr *TypeAryPtr::CHARS;
|
|
2965 const TypeAryPtr *TypeAryPtr::INTS;
|
|
2966 const TypeAryPtr *TypeAryPtr::LONGS;
|
|
2967 const TypeAryPtr *TypeAryPtr::FLOATS;
|
|
2968 const TypeAryPtr *TypeAryPtr::DOUBLES;
|
|
2969
|
|
2970 //------------------------------make-------------------------------------------
|
|
2971 const TypeAryPtr *TypeAryPtr::make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) {
|
|
2972 assert(!(k == NULL && ary->_elem->isa_int()),
|
|
2973 "integral arrays must be pre-equipped with a class");
|
|
2974 if (!xk) xk = ary->ary_must_be_exact();
|
|
2975 if (instance_id != UNKNOWN_INSTANCE)
|
|
2976 xk = true; // instances are always exactly typed
|
|
2977 if (!UseExactTypes) xk = (ptr == Constant);
|
|
2978 return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id))->hashcons();
|
|
2979 }
|
|
2980
|
|
2981 //------------------------------make-------------------------------------------
|
|
2982 const TypeAryPtr *TypeAryPtr::make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) {
|
|
2983 assert(!(k == NULL && ary->_elem->isa_int()),
|
|
2984 "integral arrays must be pre-equipped with a class");
|
|
2985 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
|
|
2986 if (!xk) xk = (o != NULL) || ary->ary_must_be_exact();
|
|
2987 if (instance_id != UNKNOWN_INSTANCE)
|
|
2988 xk = true; // instances are always exactly typed
|
|
2989 if (!UseExactTypes) xk = (ptr == Constant);
|
|
2990 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id))->hashcons();
|
|
2991 }
|
|
2992
|
|
2993 //------------------------------cast_to_ptr_type-------------------------------
|
|
2994 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
|
|
2995 if( ptr == _ptr ) return this;
|
|
2996 return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset);
|
|
2997 }
|
|
2998
|
|
2999
|
|
3000 //-----------------------------cast_to_exactness-------------------------------
|
|
3001 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
|
|
3002 if( klass_is_exact == _klass_is_exact ) return this;
|
|
3003 if (!UseExactTypes) return this;
|
|
3004 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
|
|
3005 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id);
|
|
3006 }
|
|
3007
|
|
3008 //-----------------------------cast_to_instance-------------------------------
|
|
3009 const TypeOopPtr *TypeAryPtr::cast_to_instance(int instance_id) const {
|
|
3010 if( instance_id == _instance_id) return this;
|
|
3011 bool exact = (instance_id == UNKNOWN_INSTANCE) ? _klass_is_exact : true;
|
|
3012 return make(ptr(), const_oop(), _ary, klass(), exact, _offset, instance_id);
|
|
3013 }
|
|
3014
|
|
3015 //-----------------------------narrow_size_type-------------------------------
|
|
3016 // Local cache for arrayOopDesc::max_array_length(etype),
|
|
3017 // which is kind of slow (and cached elsewhere by other users).
|
|
3018 static jint max_array_length_cache[T_CONFLICT+1];
|
|
3019 static jint max_array_length(BasicType etype) {
|
|
3020 jint& cache = max_array_length_cache[etype];
|
|
3021 jint res = cache;
|
|
3022 if (res == 0) {
|
|
3023 switch (etype) {
|
|
3024 case T_CONFLICT:
|
|
3025 case T_ILLEGAL:
|
|
3026 case T_VOID:
|
|
3027 etype = T_BYTE; // will produce conservatively high value
|
|
3028 }
|
|
3029 cache = res = arrayOopDesc::max_array_length(etype);
|
|
3030 }
|
|
3031 return res;
|
|
3032 }
|
|
3033
|
|
3034 // Narrow the given size type to the index range for the given array base type.
|
|
3035 // Return NULL if the resulting int type becomes empty.
|
|
3036 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size, BasicType elem) {
|
|
3037 jint hi = size->_hi;
|
|
3038 jint lo = size->_lo;
|
|
3039 jint min_lo = 0;
|
|
3040 jint max_hi = max_array_length(elem);
|
|
3041 //if (index_not_size) --max_hi; // type of a valid array index, FTR
|
|
3042 bool chg = false;
|
|
3043 if (lo < min_lo) { lo = min_lo; chg = true; }
|
|
3044 if (hi > max_hi) { hi = max_hi; chg = true; }
|
|
3045 if (lo > hi)
|
|
3046 return NULL;
|
|
3047 if (!chg)
|
|
3048 return size;
|
|
3049 return TypeInt::make(lo, hi, Type::WidenMin);
|
|
3050 }
|
|
3051
|
|
3052 //-------------------------------cast_to_size----------------------------------
|
|
3053 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
|
|
3054 assert(new_size != NULL, "");
|
|
3055 new_size = narrow_size_type(new_size, elem()->basic_type());
|
|
3056 if (new_size == NULL) // Negative length arrays will produce weird
|
|
3057 new_size = TypeInt::ZERO; // intermediate dead fast-path goo
|
|
3058 if (new_size == size()) return this;
|
|
3059 const TypeAry* new_ary = TypeAry::make(elem(), new_size);
|
|
3060 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset);
|
|
3061 }
|
|
3062
|
|
3063
|
|
3064 //------------------------------eq---------------------------------------------
|
|
3065 // Structural equality check for Type representations
|
|
3066 bool TypeAryPtr::eq( const Type *t ) const {
|
|
3067 const TypeAryPtr *p = t->is_aryptr();
|
|
3068 return
|
|
3069 _ary == p->_ary && // Check array
|
|
3070 TypeOopPtr::eq(p); // Check sub-parts
|
|
3071 }
|
|
3072
|
|
3073 //------------------------------hash-------------------------------------------
|
|
3074 // Type-specific hashing function.
|
|
3075 int TypeAryPtr::hash(void) const {
|
|
3076 return (intptr_t)_ary + TypeOopPtr::hash();
|
|
3077 }
|
|
3078
|
|
3079 //------------------------------meet-------------------------------------------
|
|
3080 // Compute the MEET of two types. It returns a new Type object.
|
|
3081 const Type *TypeAryPtr::xmeet( const Type *t ) const {
|
|
3082 // Perform a fast test for common case; meeting the same types together.
|
|
3083 if( this == t ) return this; // Meeting same type-rep?
|
|
3084 // Current "this->_base" is Pointer
|
|
3085 switch (t->base()) { // switch on original type
|
|
3086
|
|
3087 // Mixing ints & oops happens when javac reuses local variables
|
|
3088 case Int:
|
|
3089 case Long:
|
|
3090 case FloatTop:
|
|
3091 case FloatCon:
|
|
3092 case FloatBot:
|
|
3093 case DoubleTop:
|
|
3094 case DoubleCon:
|
|
3095 case DoubleBot:
|
|
3096 case Bottom: // Ye Olde Default
|
|
3097 return Type::BOTTOM;
|
|
3098 case Top:
|
|
3099 return this;
|
|
3100
|
|
3101 default: // All else is a mistake
|
|
3102 typerr(t);
|
|
3103
|
|
3104 case OopPtr: { // Meeting to OopPtrs
|
|
3105 // Found a OopPtr type vs self-AryPtr type
|
|
3106 const TypePtr *tp = t->is_oopptr();
|
|
3107 int offset = meet_offset(tp->offset());
|
|
3108 PTR ptr = meet_ptr(tp->ptr());
|
|
3109 switch (tp->ptr()) {
|
|
3110 case TopPTR:
|
|
3111 case AnyNull:
|
|
3112 return make(ptr, (ptr == Constant ? const_oop() : NULL), _ary, _klass, _klass_is_exact, offset);
|
|
3113 case BotPTR:
|
|
3114 case NotNull:
|
|
3115 return TypeOopPtr::make(ptr, offset);
|
|
3116 default: ShouldNotReachHere();
|
|
3117 }
|
|
3118 }
|
|
3119
|
|
3120 case AnyPtr: { // Meeting two AnyPtrs
|
|
3121 // Found an AnyPtr type vs self-AryPtr type
|
|
3122 const TypePtr *tp = t->is_ptr();
|
|
3123 int offset = meet_offset(tp->offset());
|
|
3124 PTR ptr = meet_ptr(tp->ptr());
|
|
3125 switch (tp->ptr()) {
|
|
3126 case TopPTR:
|
|
3127 return this;
|
|
3128 case BotPTR:
|
|
3129 case NotNull:
|
|
3130 return TypePtr::make(AnyPtr, ptr, offset);
|
|
3131 case Null:
|
|
3132 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
|
|
3133 case AnyNull:
|
|
3134 return make( ptr, (ptr == Constant ? const_oop() : NULL), _ary, _klass, _klass_is_exact, offset );
|
|
3135 default: ShouldNotReachHere();
|
|
3136 }
|
|
3137 }
|
|
3138
|
|
3139 case RawPtr: return TypePtr::BOTTOM;
|
|
3140
|
|
3141 case AryPtr: { // Meeting 2 references?
|
|
3142 const TypeAryPtr *tap = t->is_aryptr();
|
|
3143 int off = meet_offset(tap->offset());
|
|
3144 const TypeAry *tary = _ary->meet(tap->_ary)->is_ary();
|
|
3145 PTR ptr = meet_ptr(tap->ptr());
|
|
3146 int iid = meet_instance(tap->instance_id());
|
|
3147 ciKlass* lazy_klass = NULL;
|
|
3148 if (tary->_elem->isa_int()) {
|
|
3149 // Integral array element types have irrelevant lattice relations.
|
|
3150 // It is the klass that determines array layout, not the element type.
|
|
3151 if (_klass == NULL)
|
|
3152 lazy_klass = tap->_klass;
|
|
3153 else if (tap->_klass == NULL || tap->_klass == _klass) {
|
|
3154 lazy_klass = _klass;
|
|
3155 } else {
|
|
3156 // Something like byte[int+] meets char[int+].
|
|
3157 // This must fall to bottom, not (int[-128..65535])[int+].
|
|
3158 tary = TypeAry::make(Type::BOTTOM, tary->_size);
|
|
3159 }
|
|
3160 }
|
|
3161 bool xk;
|
|
3162 switch (tap->ptr()) {
|
|
3163 case AnyNull:
|
|
3164 case TopPTR:
|
|
3165 // Compute new klass on demand, do not use tap->_klass
|
|
3166 xk = (tap->_klass_is_exact | this->_klass_is_exact);
|
|
3167 return make( ptr, const_oop(), tary, lazy_klass, xk, off );
|
|
3168 case Constant: {
|
|
3169 ciObject* o = const_oop();
|
|
3170 if( _ptr == Constant ) {
|
|
3171 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
|
|
3172 ptr = NotNull;
|
|
3173 o = NULL;
|
|
3174 }
|
|
3175 } else if( above_centerline(_ptr) ) {
|
|
3176 o = tap->const_oop();
|
|
3177 }
|
|
3178 xk = true;
|
|
3179 return TypeAryPtr::make( ptr, o, tary, tap->_klass, xk, off );
|
|
3180 }
|
|
3181 case NotNull:
|
|
3182 case BotPTR:
|
|
3183 // Compute new klass on demand, do not use tap->_klass
|
|
3184 if (above_centerline(this->_ptr))
|
|
3185 xk = tap->_klass_is_exact;
|
|
3186 else if (above_centerline(tap->_ptr))
|
|
3187 xk = this->_klass_is_exact;
|
|
3188 else xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
|
|
3189 (klass() == tap->klass()); // Only precise for identical arrays
|
|
3190 return TypeAryPtr::make( ptr, NULL, tary, lazy_klass, xk, off, iid );
|
|
3191 default: ShouldNotReachHere();
|
|
3192 }
|
|
3193 }
|
|
3194
|
|
3195 // All arrays inherit from Object class
|
|
3196 case InstPtr: {
|
|
3197 const TypeInstPtr *tp = t->is_instptr();
|
|
3198 int offset = meet_offset(tp->offset());
|
|
3199 PTR ptr = meet_ptr(tp->ptr());
|
|
3200 int iid = meet_instance(tp->instance_id());
|
|
3201 switch (ptr) {
|
|
3202 case TopPTR:
|
|
3203 case AnyNull: // Fall 'down' to dual of object klass
|
|
3204 if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) {
|
|
3205 return TypeAryPtr::make( ptr, _ary, _klass, _klass_is_exact, offset, iid );
|
|
3206 } else {
|
|
3207 // cannot subclass, so the meet has to fall badly below the centerline
|
|
3208 ptr = NotNull;
|
|
3209 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, iid);
|
|
3210 }
|
|
3211 case Constant:
|
|
3212 case NotNull:
|
|
3213 case BotPTR: // Fall down to object klass
|
|
3214 // LCA is object_klass, but if we subclass from the top we can do better
|
|
3215 if (above_centerline(tp->ptr())) {
|
|
3216 // If 'tp' is above the centerline and it is Object class
|
|
3217 // then we can subclass in the Java class heirarchy.
|
|
3218 if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) {
|
|
3219 // that is, my array type is a subtype of 'tp' klass
|
|
3220 return make( ptr, _ary, _klass, _klass_is_exact, offset, iid );
|
|
3221 }
|
|
3222 }
|
|
3223 // The other case cannot happen, since t cannot be a subtype of an array.
|
|
3224 // The meet falls down to Object class below centerline.
|
|
3225 if( ptr == Constant )
|
|
3226 ptr = NotNull;
|
|
3227 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, iid);
|
|
3228 default: typerr(t);
|
|
3229 }
|
|
3230 }
|
|
3231
|
|
3232 case KlassPtr:
|
|
3233 return TypeInstPtr::BOTTOM;
|
|
3234
|
|
3235 }
|
|
3236 return this; // Lint noise
|
|
3237 }
|
|
3238
|
|
3239 //------------------------------xdual------------------------------------------
|
|
3240 // Dual: compute field-by-field dual
|
|
3241 const Type *TypeAryPtr::xdual() const {
|
|
3242 return new TypeAryPtr( dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_instance() );
|
|
3243 }
|
|
3244
|
|
3245 //------------------------------dump2------------------------------------------
|
|
3246 #ifndef PRODUCT
|
|
3247 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
|
|
3248 _ary->dump2(d,depth,st);
|
|
3249 switch( _ptr ) {
|
|
3250 case Constant:
|
|
3251 const_oop()->print(st);
|
|
3252 break;
|
|
3253 case BotPTR:
|
|
3254 if (!WizardMode && !Verbose) {
|
|
3255 if( _klass_is_exact ) st->print(":exact");
|
|
3256 break;
|
|
3257 }
|
|
3258 case TopPTR:
|
|
3259 case AnyNull:
|
|
3260 case NotNull:
|
|
3261 st->print(":%s", ptr_msg[_ptr]);
|
|
3262 if( _klass_is_exact ) st->print(":exact");
|
|
3263 break;
|
|
3264 }
|
|
3265
|
|
3266 st->print("*");
|
|
3267 if (_instance_id != UNKNOWN_INSTANCE)
|
|
3268 st->print(",iid=%d",_instance_id);
|
|
3269 if( !_offset ) return;
|
|
3270 if( _offset == OffsetTop ) st->print("+undefined");
|
|
3271 else if( _offset == OffsetBot ) st->print("+any");
|
|
3272 else if( _offset < 12 ) st->print("+%d",_offset);
|
|
3273 else st->print("[%d]", (_offset-12)/4 );
|
|
3274 }
|
|
3275 #endif
|
|
3276
|
|
3277 bool TypeAryPtr::empty(void) const {
|
|
3278 if (_ary->empty()) return true;
|
|
3279 return TypeOopPtr::empty();
|
|
3280 }
|
|
3281
|
|
3282 //------------------------------add_offset-------------------------------------
|
|
3283 const TypePtr *TypeAryPtr::add_offset( int offset ) const {
|
|
3284 return make( _ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id );
|
|
3285 }
|
|
3286
|
|
3287
|
|
3288 //=============================================================================
|
|
3289 // Convenience common pre-built types.
|
|
3290
|
|
3291 // Not-null object klass or below
|
|
3292 const TypeKlassPtr *TypeKlassPtr::OBJECT;
|
|
3293 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL;
|
|
3294
|
|
3295 //------------------------------TypeKlasPtr------------------------------------
|
|
3296 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, int offset )
|
|
3297 : TypeOopPtr(KlassPtr, ptr, klass, (ptr==Constant), (ptr==Constant ? klass : NULL), offset, 0) {
|
|
3298 }
|
|
3299
|
|
3300 //------------------------------make-------------------------------------------
|
|
3301 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant
|
|
3302 const TypeKlassPtr *TypeKlassPtr::make( PTR ptr, ciKlass* k, int offset ) {
|
|
3303 assert( k != NULL, "Expect a non-NULL klass");
|
|
3304 assert(k->is_instance_klass() || k->is_array_klass() ||
|
|
3305 k->is_method_klass(), "Incorrect type of klass oop");
|
|
3306 TypeKlassPtr *r =
|
|
3307 (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons();
|
|
3308
|
|
3309 return r;
|
|
3310 }
|
|
3311
|
|
3312 //------------------------------eq---------------------------------------------
|
|
3313 // Structural equality check for Type representations
|
|
3314 bool TypeKlassPtr::eq( const Type *t ) const {
|
|
3315 const TypeKlassPtr *p = t->is_klassptr();
|
|
3316 return
|
|
3317 klass()->equals(p->klass()) &&
|
|
3318 TypeOopPtr::eq(p);
|
|
3319 }
|
|
3320
|
|
3321 //------------------------------hash-------------------------------------------
|
|
3322 // Type-specific hashing function.
|
|
3323 int TypeKlassPtr::hash(void) const {
|
|
3324 return klass()->hash() + TypeOopPtr::hash();
|
|
3325 }
|
|
3326
|
|
3327
|
|
3328 //------------------------------klass------------------------------------------
|
|
3329 // Return the defining klass for this class
|
|
3330 ciKlass* TypeAryPtr::klass() const {
|
|
3331 if( _klass ) return _klass; // Return cached value, if possible
|
|
3332
|
|
3333 // Oops, need to compute _klass and cache it
|
|
3334 ciKlass* k_ary = NULL;
|
|
3335 const TypeInstPtr *tinst;
|
|
3336 const TypeAryPtr *tary;
|
|
3337 // Get element klass
|
|
3338 if ((tinst = elem()->isa_instptr()) != NULL) {
|
|
3339 // Compute array klass from element klass
|
|
3340 k_ary = ciObjArrayKlass::make(tinst->klass());
|
|
3341 } else if ((tary = elem()->isa_aryptr()) != NULL) {
|
|
3342 // Compute array klass from element klass
|
|
3343 ciKlass* k_elem = tary->klass();
|
|
3344 // If element type is something like bottom[], k_elem will be null.
|
|
3345 if (k_elem != NULL)
|
|
3346 k_ary = ciObjArrayKlass::make(k_elem);
|
|
3347 } else if ((elem()->base() == Type::Top) ||
|
|
3348 (elem()->base() == Type::Bottom)) {
|
|
3349 // element type of Bottom occurs from meet of basic type
|
|
3350 // and object; Top occurs when doing join on Bottom.
|
|
3351 // Leave k_ary at NULL.
|
|
3352 } else {
|
|
3353 // Cannot compute array klass directly from basic type,
|
|
3354 // since subtypes of TypeInt all have basic type T_INT.
|
|
3355 assert(!elem()->isa_int(),
|
|
3356 "integral arrays must be pre-equipped with a class");
|
|
3357 // Compute array klass directly from basic type
|
|
3358 k_ary = ciTypeArrayKlass::make(elem()->basic_type());
|
|
3359 }
|
|
3360
|
|
3361 if( this != TypeAryPtr::OOPS )
|
|
3362 // The _klass field acts as a cache of the underlying
|
|
3363 // ciKlass for this array type. In order to set the field,
|
|
3364 // we need to cast away const-ness.
|
|
3365 //
|
|
3366 // IMPORTANT NOTE: we *never* set the _klass field for the
|
|
3367 // type TypeAryPtr::OOPS. This Type is shared between all
|
|
3368 // active compilations. However, the ciKlass which represents
|
|
3369 // this Type is *not* shared between compilations, so caching
|
|
3370 // this value would result in fetching a dangling pointer.
|
|
3371 //
|
|
3372 // Recomputing the underlying ciKlass for each request is
|
|
3373 // a bit less efficient than caching, but calls to
|
|
3374 // TypeAryPtr::OOPS->klass() are not common enough to matter.
|
|
3375 ((TypeAryPtr*)this)->_klass = k_ary;
|
|
3376 return k_ary;
|
|
3377 }
|
|
3378
|
|
3379
|
|
3380 //------------------------------add_offset-------------------------------------
|
|
3381 // Access internals of klass object
|
|
3382 const TypePtr *TypeKlassPtr::add_offset( int offset ) const {
|
|
3383 return make( _ptr, klass(), xadd_offset(offset) );
|
|
3384 }
|
|
3385
|
|
3386 //------------------------------cast_to_ptr_type-------------------------------
|
|
3387 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const {
|
|
3388 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
|
|
3389 if( ptr == _ptr ) return this;
|
|
3390 return make(ptr, _klass, _offset);
|
|
3391 }
|
|
3392
|
|
3393
|
|
3394 //-----------------------------cast_to_exactness-------------------------------
|
|
3395 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const {
|
|
3396 if( klass_is_exact == _klass_is_exact ) return this;
|
|
3397 if (!UseExactTypes) return this;
|
|
3398 return make(klass_is_exact ? Constant : NotNull, _klass, _offset);
|
|
3399 }
|
|
3400
|
|
3401
|
|
3402 //-----------------------------as_instance_type--------------------------------
|
|
3403 // Corresponding type for an instance of the given class.
|
|
3404 // It will be NotNull, and exact if and only if the klass type is exact.
|
|
3405 const TypeOopPtr* TypeKlassPtr::as_instance_type() const {
|
|
3406 ciKlass* k = klass();
|
|
3407 bool xk = klass_is_exact();
|
|
3408 //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0);
|
|
3409 const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k);
|
|
3410 toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
|
|
3411 return toop->cast_to_exactness(xk)->is_oopptr();
|
|
3412 }
|
|
3413
|
|
3414
|
|
3415 //------------------------------xmeet------------------------------------------
|
|
3416 // Compute the MEET of two types, return a new Type object.
|
|
3417 const Type *TypeKlassPtr::xmeet( const Type *t ) const {
|
|
3418 // Perform a fast test for common case; meeting the same types together.
|
|
3419 if( this == t ) return this; // Meeting same type-rep?
|
|
3420
|
|
3421 // Current "this->_base" is Pointer
|
|
3422 switch (t->base()) { // switch on original type
|
|
3423
|
|
3424 case Int: // Mixing ints & oops happens when javac
|
|
3425 case Long: // reuses local variables
|
|
3426 case FloatTop:
|
|
3427 case FloatCon:
|
|
3428 case FloatBot:
|
|
3429 case DoubleTop:
|
|
3430 case DoubleCon:
|
|
3431 case DoubleBot:
|
|
3432 case Bottom: // Ye Olde Default
|
|
3433 return Type::BOTTOM;
|
|
3434 case Top:
|
|
3435 return this;
|
|
3436
|
|
3437 default: // All else is a mistake
|
|
3438 typerr(t);
|
|
3439
|
|
3440 case RawPtr: return TypePtr::BOTTOM;
|
|
3441
|
|
3442 case OopPtr: { // Meeting to OopPtrs
|
|
3443 // Found a OopPtr type vs self-KlassPtr type
|
|
3444 const TypePtr *tp = t->is_oopptr();
|
|
3445 int offset = meet_offset(tp->offset());
|
|
3446 PTR ptr = meet_ptr(tp->ptr());
|
|
3447 switch (tp->ptr()) {
|
|
3448 case TopPTR:
|
|
3449 case AnyNull:
|
|
3450 return make(ptr, klass(), offset);
|
|
3451 case BotPTR:
|
|
3452 case NotNull:
|
|
3453 return TypePtr::make(AnyPtr, ptr, offset);
|
|
3454 default: typerr(t);
|
|
3455 }
|
|
3456 }
|
|
3457
|
|
3458 case AnyPtr: { // Meeting to AnyPtrs
|
|
3459 // Found an AnyPtr type vs self-KlassPtr type
|
|
3460 const TypePtr *tp = t->is_ptr();
|
|
3461 int offset = meet_offset(tp->offset());
|
|
3462 PTR ptr = meet_ptr(tp->ptr());
|
|
3463 switch (tp->ptr()) {
|
|
3464 case TopPTR:
|
|
3465 return this;
|
|
3466 case Null:
|
|
3467 if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset );
|
|
3468 case AnyNull:
|
|
3469 return make( ptr, klass(), offset );
|
|
3470 case BotPTR:
|
|
3471 case NotNull:
|
|
3472 return TypePtr::make(AnyPtr, ptr, offset);
|
|
3473 default: typerr(t);
|
|
3474 }
|
|
3475 }
|
|
3476
|
|
3477 case AryPtr: // Meet with AryPtr
|
|
3478 case InstPtr: // Meet with InstPtr
|
|
3479 return TypeInstPtr::BOTTOM;
|
|
3480
|
|
3481 //
|
|
3482 // A-top }
|
|
3483 // / | \ } Tops
|
|
3484 // B-top A-any C-top }
|
|
3485 // | / | \ | } Any-nulls
|
|
3486 // B-any | C-any }
|
|
3487 // | | |
|
|
3488 // B-con A-con C-con } constants; not comparable across classes
|
|
3489 // | | |
|
|
3490 // B-not | C-not }
|
|
3491 // | \ | / | } not-nulls
|
|
3492 // B-bot A-not C-bot }
|
|
3493 // \ | / } Bottoms
|
|
3494 // A-bot }
|
|
3495 //
|
|
3496
|
|
3497 case KlassPtr: { // Meet two KlassPtr types
|
|
3498 const TypeKlassPtr *tkls = t->is_klassptr();
|
|
3499 int off = meet_offset(tkls->offset());
|
|
3500 PTR ptr = meet_ptr(tkls->ptr());
|
|
3501
|
|
3502 // Check for easy case; klasses are equal (and perhaps not loaded!)
|
|
3503 // If we have constants, then we created oops so classes are loaded
|
|
3504 // and we can handle the constants further down. This case handles
|
|
3505 // not-loaded classes
|
|
3506 if( ptr != Constant && tkls->klass()->equals(klass()) ) {
|
|
3507 return make( ptr, klass(), off );
|
|
3508 }
|
|
3509
|
|
3510 // Classes require inspection in the Java klass hierarchy. Must be loaded.
|
|
3511 ciKlass* tkls_klass = tkls->klass();
|
|
3512 ciKlass* this_klass = this->klass();
|
|
3513 assert( tkls_klass->is_loaded(), "This class should have been loaded.");
|
|
3514 assert( this_klass->is_loaded(), "This class should have been loaded.");
|
|
3515
|
|
3516 // If 'this' type is above the centerline and is a superclass of the
|
|
3517 // other, we can treat 'this' as having the same type as the other.
|
|
3518 if ((above_centerline(this->ptr())) &&
|
|
3519 tkls_klass->is_subtype_of(this_klass)) {
|
|
3520 this_klass = tkls_klass;
|
|
3521 }
|
|
3522 // If 'tinst' type is above the centerline and is a superclass of the
|
|
3523 // other, we can treat 'tinst' as having the same type as the other.
|
|
3524 if ((above_centerline(tkls->ptr())) &&
|
|
3525 this_klass->is_subtype_of(tkls_klass)) {
|
|
3526 tkls_klass = this_klass;
|
|
3527 }
|
|
3528
|
|
3529 // Check for classes now being equal
|
|
3530 if (tkls_klass->equals(this_klass)) {
|
|
3531 // If the klasses are equal, the constants may still differ. Fall to
|
|
3532 // NotNull if they do (neither constant is NULL; that is a special case
|
|
3533 // handled elsewhere).
|
|
3534 ciObject* o = NULL; // Assume not constant when done
|
|
3535 ciObject* this_oop = const_oop();
|
|
3536 ciObject* tkls_oop = tkls->const_oop();
|
|
3537 if( ptr == Constant ) {
|
|
3538 if (this_oop != NULL && tkls_oop != NULL &&
|
|
3539 this_oop->equals(tkls_oop) )
|
|
3540 o = this_oop;
|
|
3541 else if (above_centerline(this->ptr()))
|
|
3542 o = tkls_oop;
|
|
3543 else if (above_centerline(tkls->ptr()))
|
|
3544 o = this_oop;
|
|
3545 else
|
|
3546 ptr = NotNull;
|
|
3547 }
|
|
3548 return make( ptr, this_klass, off );
|
|
3549 } // Else classes are not equal
|
|
3550
|
|
3551 // Since klasses are different, we require the LCA in the Java
|
|
3552 // class hierarchy - which means we have to fall to at least NotNull.
|
|
3553 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
|
|
3554 ptr = NotNull;
|
|
3555 // Now we find the LCA of Java classes
|
|
3556 ciKlass* k = this_klass->least_common_ancestor(tkls_klass);
|
|
3557 return make( ptr, k, off );
|
|
3558 } // End of case KlassPtr
|
|
3559
|
|
3560 } // End of switch
|
|
3561 return this; // Return the double constant
|
|
3562 }
|
|
3563
|
|
3564 //------------------------------xdual------------------------------------------
|
|
3565 // Dual: compute field-by-field dual
|
|
3566 const Type *TypeKlassPtr::xdual() const {
|
|
3567 return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() );
|
|
3568 }
|
|
3569
|
|
3570 //------------------------------dump2------------------------------------------
|
|
3571 // Dump Klass Type
|
|
3572 #ifndef PRODUCT
|
|
3573 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
|
|
3574 switch( _ptr ) {
|
|
3575 case Constant:
|
|
3576 st->print("precise ");
|
|
3577 case NotNull:
|
|
3578 {
|
|
3579 const char *name = klass()->name()->as_utf8();
|
|
3580 if( name ) {
|
|
3581 st->print("klass %s: " INTPTR_FORMAT, name, klass());
|
|
3582 } else {
|
|
3583 ShouldNotReachHere();
|
|
3584 }
|
|
3585 }
|
|
3586 case BotPTR:
|
|
3587 if( !WizardMode && !Verbose && !_klass_is_exact ) break;
|
|
3588 case TopPTR:
|
|
3589 case AnyNull:
|
|
3590 st->print(":%s", ptr_msg[_ptr]);
|
|
3591 if( _klass_is_exact ) st->print(":exact");
|
|
3592 break;
|
|
3593 }
|
|
3594
|
|
3595 if( _offset ) { // Dump offset, if any
|
|
3596 if( _offset == OffsetBot ) { st->print("+any"); }
|
|
3597 else if( _offset == OffsetTop ) { st->print("+unknown"); }
|
|
3598 else { st->print("+%d", _offset); }
|
|
3599 }
|
|
3600
|
|
3601 st->print(" *");
|
|
3602 }
|
|
3603 #endif
|
|
3604
|
|
3605
|
|
3606
|
|
3607 //=============================================================================
|
|
3608 // Convenience common pre-built types.
|
|
3609
|
|
3610 //------------------------------make-------------------------------------------
|
|
3611 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
|
|
3612 return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
|
|
3613 }
|
|
3614
|
|
3615 //------------------------------make-------------------------------------------
|
|
3616 const TypeFunc *TypeFunc::make(ciMethod* method) {
|
|
3617 Compile* C = Compile::current();
|
|
3618 const TypeFunc* tf = C->last_tf(method); // check cache
|
|
3619 if (tf != NULL) return tf; // The hit rate here is almost 50%.
|
|
3620 const TypeTuple *domain;
|
|
3621 if (method->flags().is_static()) {
|
|
3622 domain = TypeTuple::make_domain(NULL, method->signature());
|
|
3623 } else {
|
|
3624 domain = TypeTuple::make_domain(method->holder(), method->signature());
|
|
3625 }
|
|
3626 const TypeTuple *range = TypeTuple::make_range(method->signature());
|
|
3627 tf = TypeFunc::make(domain, range);
|
|
3628 C->set_last_tf(method, tf); // fill cache
|
|
3629 return tf;
|
|
3630 }
|
|
3631
|
|
3632 //------------------------------meet-------------------------------------------
|
|
3633 // Compute the MEET of two types. It returns a new Type object.
|
|
3634 const Type *TypeFunc::xmeet( const Type *t ) const {
|
|
3635 // Perform a fast test for common case; meeting the same types together.
|
|
3636 if( this == t ) return this; // Meeting same type-rep?
|
|
3637
|
|
3638 // Current "this->_base" is Func
|
|
3639 switch (t->base()) { // switch on original type
|
|
3640
|
|
3641 case Bottom: // Ye Olde Default
|
|
3642 return t;
|
|
3643
|
|
3644 default: // All else is a mistake
|
|
3645 typerr(t);
|
|
3646
|
|
3647 case Top:
|
|
3648 break;
|
|
3649 }
|
|
3650 return this; // Return the double constant
|
|
3651 }
|
|
3652
|
|
3653 //------------------------------xdual------------------------------------------
|
|
3654 // Dual: compute field-by-field dual
|
|
3655 const Type *TypeFunc::xdual() const {
|
|
3656 return this;
|
|
3657 }
|
|
3658
|
|
3659 //------------------------------eq---------------------------------------------
|
|
3660 // Structural equality check for Type representations
|
|
3661 bool TypeFunc::eq( const Type *t ) const {
|
|
3662 const TypeFunc *a = (const TypeFunc*)t;
|
|
3663 return _domain == a->_domain &&
|
|
3664 _range == a->_range;
|
|
3665 }
|
|
3666
|
|
3667 //------------------------------hash-------------------------------------------
|
|
3668 // Type-specific hashing function.
|
|
3669 int TypeFunc::hash(void) const {
|
|
3670 return (intptr_t)_domain + (intptr_t)_range;
|
|
3671 }
|
|
3672
|
|
3673 //------------------------------dump2------------------------------------------
|
|
3674 // Dump Function Type
|
|
3675 #ifndef PRODUCT
|
|
3676 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
|
|
3677 if( _range->_cnt <= Parms )
|
|
3678 st->print("void");
|
|
3679 else {
|
|
3680 uint i;
|
|
3681 for (i = Parms; i < _range->_cnt-1; i++) {
|
|
3682 _range->field_at(i)->dump2(d,depth,st);
|
|
3683 st->print("/");
|
|
3684 }
|
|
3685 _range->field_at(i)->dump2(d,depth,st);
|
|
3686 }
|
|
3687 st->print(" ");
|
|
3688 st->print("( ");
|
|
3689 if( !depth || d[this] ) { // Check for recursive dump
|
|
3690 st->print("...)");
|
|
3691 return;
|
|
3692 }
|
|
3693 d.Insert((void*)this,(void*)this); // Stop recursion
|
|
3694 if (Parms < _domain->_cnt)
|
|
3695 _domain->field_at(Parms)->dump2(d,depth-1,st);
|
|
3696 for (uint i = Parms+1; i < _domain->_cnt; i++) {
|
|
3697 st->print(", ");
|
|
3698 _domain->field_at(i)->dump2(d,depth-1,st);
|
|
3699 }
|
|
3700 st->print(" )");
|
|
3701 }
|
|
3702
|
|
3703 //------------------------------print_flattened--------------------------------
|
|
3704 // Print a 'flattened' signature
|
|
3705 static const char * const flat_type_msg[Type::lastype] = {
|
|
3706 "bad","control","top","int","long","_",
|
|
3707 "tuple:", "array:",
|
|
3708 "ptr", "rawptr", "ptr", "ptr", "ptr", "ptr",
|
|
3709 "func", "abIO", "return_address", "mem",
|
|
3710 "float_top", "ftcon:", "flt",
|
|
3711 "double_top", "dblcon:", "dbl",
|
|
3712 "bottom"
|
|
3713 };
|
|
3714
|
|
3715 void TypeFunc::print_flattened() const {
|
|
3716 if( _range->_cnt <= Parms )
|
|
3717 tty->print("void");
|
|
3718 else {
|
|
3719 uint i;
|
|
3720 for (i = Parms; i < _range->_cnt-1; i++)
|
|
3721 tty->print("%s/",flat_type_msg[_range->field_at(i)->base()]);
|
|
3722 tty->print("%s",flat_type_msg[_range->field_at(i)->base()]);
|
|
3723 }
|
|
3724 tty->print(" ( ");
|
|
3725 if (Parms < _domain->_cnt)
|
|
3726 tty->print("%s",flat_type_msg[_domain->field_at(Parms)->base()]);
|
|
3727 for (uint i = Parms+1; i < _domain->_cnt; i++)
|
|
3728 tty->print(", %s",flat_type_msg[_domain->field_at(i)->base()]);
|
|
3729 tty->print(" )");
|
|
3730 }
|
|
3731 #endif
|
|
3732
|
|
3733 //------------------------------singleton--------------------------------------
|
|
3734 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
|
|
3735 // constants (Ldi nodes). Singletons are integer, float or double constants
|
|
3736 // or a single symbol.
|
|
3737 bool TypeFunc::singleton(void) const {
|
|
3738 return false; // Never a singleton
|
|
3739 }
|
|
3740
|
|
3741 bool TypeFunc::empty(void) const {
|
|
3742 return false; // Never empty
|
|
3743 }
|
|
3744
|
|
3745
|
|
3746 BasicType TypeFunc::return_type() const{
|
|
3747 if (range()->cnt() == TypeFunc::Parms) {
|
|
3748 return T_VOID;
|
|
3749 }
|
|
3750 return range()->field_at(TypeFunc::Parms)->basic_type();
|
|
3751 }
|