| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #define V8_TYPE_INFO_H_ | 29 #define V8_TYPE_INFO_H_ |
| 30 | 30 |
| 31 #include "allocation.h" | 31 #include "allocation.h" |
| 32 #include "globals.h" | 32 #include "globals.h" |
| 33 #include "types.h" | 33 #include "types.h" |
| 34 #include "zone-inl.h" | 34 #include "zone-inl.h" |
| 35 | 35 |
| 36 namespace v8 { | 36 namespace v8 { |
| 37 namespace internal { | 37 namespace internal { |
| 38 | 38 |
| 39 const int kMaxKeyedPolymorphism = 4; | |
| 40 | |
| 41 // Unknown | |
| 42 // | \____________ | |
| 43 // | | | |
| 44 // Primitive Non-primitive | |
| 45 // | \_______ | | |
| 46 // | | | | |
| 47 // Number String | | |
| 48 // / \ | | | |
| 49 // Double Integer32 | / | |
| 50 // | | / / | |
| 51 // | Smi / / | |
| 52 // | | / __/ | |
| 53 // Uninitialized. | |
| 54 | |
| 55 class TypeInfo { | |
| 56 public: | |
| 57 TypeInfo() : type_(kUninitialized) { } | |
| 58 | |
| 59 static TypeInfo Unknown() { return TypeInfo(kUnknown); } | |
| 60 // We know it's a primitive type. | |
| 61 static TypeInfo Primitive() { return TypeInfo(kPrimitive); } | |
| 62 // We know it's a number of some sort. | |
| 63 static TypeInfo Number() { return TypeInfo(kNumber); } | |
| 64 // We know it's a signed 32 bit integer. | |
| 65 static TypeInfo Integer32() { return TypeInfo(kInteger32); } | |
| 66 // We know it's a Smi. | |
| 67 static TypeInfo Smi() { return TypeInfo(kSmi); } | |
| 68 // We know it's a heap number. | |
| 69 static TypeInfo Double() { return TypeInfo(kDouble); } | |
| 70 // We know it's a string. | |
| 71 static TypeInfo String() { return TypeInfo(kString); } | |
| 72 // We know it's an internalized string. | |
| 73 static TypeInfo InternalizedString() { return TypeInfo(kInternalizedString); } | |
| 74 // We know it's a non-primitive (object) type. | |
| 75 static TypeInfo NonPrimitive() { return TypeInfo(kNonPrimitive); } | |
| 76 // We haven't started collecting info yet. | |
| 77 static TypeInfo Uninitialized() { return TypeInfo(kUninitialized); } | |
| 78 | |
| 79 int ToInt() { | |
| 80 return type_; | |
| 81 } | |
| 82 | |
| 83 static TypeInfo FromInt(int bit_representation) { | |
| 84 Type t = static_cast<Type>(bit_representation); | |
| 85 ASSERT(t == kUnknown || | |
| 86 t == kPrimitive || | |
| 87 t == kNumber || | |
| 88 t == kInteger32 || | |
| 89 t == kSmi || | |
| 90 t == kDouble || | |
| 91 t == kString || | |
| 92 t == kNonPrimitive); | |
| 93 return TypeInfo(t); | |
| 94 } | |
| 95 | |
| 96 // Return the weakest (least precise) common type. | |
| 97 static TypeInfo Combine(TypeInfo a, TypeInfo b) { | |
| 98 return TypeInfo(static_cast<Type>(a.type_ & b.type_)); | |
| 99 } | |
| 100 | |
| 101 | |
| 102 // Integer32 is an integer that can be represented as a signed | |
| 103 // 32-bit integer. It has to be | |
| 104 // in the range [-2^31, 2^31 - 1]. We also have to check for negative 0 | |
| 105 // as it is not an Integer32. | |
| 106 static inline bool IsInt32Double(double value) { | |
| 107 const DoubleRepresentation minus_zero(-0.0); | |
| 108 DoubleRepresentation rep(value); | |
| 109 if (rep.bits == minus_zero.bits) return false; | |
| 110 if (value >= kMinInt && value <= kMaxInt && | |
| 111 value == static_cast<int32_t>(value)) { | |
| 112 return true; | |
| 113 } | |
| 114 return false; | |
| 115 } | |
| 116 | |
| 117 static TypeInfo FromValue(Handle<Object> value); | |
| 118 | |
| 119 bool Equals(const TypeInfo& other) { | |
| 120 return type_ == other.type_; | |
| 121 } | |
| 122 | |
| 123 inline bool IsUnknown() { | |
| 124 ASSERT(type_ != kUninitialized); | |
| 125 return type_ == kUnknown; | |
| 126 } | |
| 127 | |
| 128 inline bool IsPrimitive() { | |
| 129 ASSERT(type_ != kUninitialized); | |
| 130 return ((type_ & kPrimitive) == kPrimitive); | |
| 131 } | |
| 132 | |
| 133 inline bool IsNumber() { | |
| 134 ASSERT(type_ != kUninitialized); | |
| 135 return ((type_ & kNumber) == kNumber); | |
| 136 } | |
| 137 | |
| 138 inline bool IsSmi() { | |
| 139 ASSERT(type_ != kUninitialized); | |
| 140 return ((type_ & kSmi) == kSmi); | |
| 141 } | |
| 142 | |
| 143 inline bool IsInternalizedString() { | |
| 144 ASSERT(type_ != kUninitialized); | |
| 145 return ((type_ & kInternalizedString) == kInternalizedString); | |
| 146 } | |
| 147 | |
| 148 inline bool IsNonInternalizedString() { | |
| 149 ASSERT(type_ != kUninitialized); | |
| 150 return ((type_ & kInternalizedString) == kString); | |
| 151 } | |
| 152 | |
| 153 inline bool IsInteger32() { | |
| 154 ASSERT(type_ != kUninitialized); | |
| 155 return ((type_ & kInteger32) == kInteger32); | |
| 156 } | |
| 157 | |
| 158 inline bool IsDouble() { | |
| 159 ASSERT(type_ != kUninitialized); | |
| 160 return ((type_ & kDouble) == kDouble); | |
| 161 } | |
| 162 | |
| 163 inline bool IsString() { | |
| 164 ASSERT(type_ != kUninitialized); | |
| 165 return ((type_ & kString) == kString); | |
| 166 } | |
| 167 | |
| 168 inline bool IsNonPrimitive() { | |
| 169 ASSERT(type_ != kUninitialized); | |
| 170 return ((type_ & kNonPrimitive) == kNonPrimitive); | |
| 171 } | |
| 172 | |
| 173 inline bool IsUninitialized() { | |
| 174 return type_ == kUninitialized; | |
| 175 } | |
| 176 | |
| 177 const char* ToString() { | |
| 178 switch (type_) { | |
| 179 case kUnknown: return "Unknown"; | |
| 180 case kPrimitive: return "Primitive"; | |
| 181 case kNumber: return "Number"; | |
| 182 case kInteger32: return "Integer32"; | |
| 183 case kSmi: return "Smi"; | |
| 184 case kInternalizedString: return "InternalizedString"; | |
| 185 case kDouble: return "Double"; | |
| 186 case kString: return "String"; | |
| 187 case kNonPrimitive: return "Object"; | |
| 188 case kUninitialized: return "Uninitialized"; | |
| 189 } | |
| 190 UNREACHABLE(); | |
| 191 return "Unreachable code"; | |
| 192 } | |
| 193 | |
| 194 private: | |
| 195 enum Type { | |
| 196 kUnknown = 0, // 0000000 | |
| 197 kPrimitive = 0x10, // 0010000 | |
| 198 kNumber = 0x11, // 0010001 | |
| 199 kInteger32 = 0x13, // 0010011 | |
| 200 kSmi = 0x17, // 0010111 | |
| 201 kDouble = 0x19, // 0011001 | |
| 202 kString = 0x30, // 0110000 | |
| 203 kInternalizedString = 0x32, // 0110010 | |
| 204 kNonPrimitive = 0x40, // 1000000 | |
| 205 kUninitialized = 0x7f // 1111111 | |
| 206 }; | |
| 207 | |
| 208 explicit inline TypeInfo(Type t) : type_(t) { } | |
| 209 | |
| 210 Type type_; | |
| 211 }; | |
| 212 | |
| 213 | |
| 214 enum StringStubFeedback { | |
| 215 DEFAULT_STRING_STUB = 0, | |
| 216 STRING_INDEX_OUT_OF_BOUNDS = 1 | |
| 217 }; | |
| 218 | |
| 219 | |
| 220 // Forward declarations. | 39 // Forward declarations. |
| 221 class CompilationInfo; | |
| 222 class ICStub; | 40 class ICStub; |
| 223 class SmallMapList; | 41 class SmallMapList; |
| 224 | 42 |
| 225 | 43 |
| 226 class TypeFeedbackOracle: public ZoneObject { | 44 class TypeFeedbackOracle: public ZoneObject { |
| 227 public: | 45 public: |
| 228 TypeFeedbackOracle(Handle<Code> code, | 46 TypeFeedbackOracle(Handle<Code> code, |
| 229 Handle<Context> native_context, | 47 Handle<Context> native_context, |
| 230 Isolate* isolate, | 48 Isolate* isolate, |
| 231 Zone* zone); | 49 Zone* zone); |
| 232 | 50 |
| 233 bool LoadIsMonomorphicNormal(TypeFeedbackId id); | |
| 234 bool LoadIsUninitialized(TypeFeedbackId id); | 51 bool LoadIsUninitialized(TypeFeedbackId id); |
| 235 bool LoadIsPreMonomorphic(TypeFeedbackId id); | 52 bool LoadIsPreMonomorphic(TypeFeedbackId id); |
| 236 bool LoadIsPolymorphic(TypeFeedbackId id); | |
| 237 bool StoreIsUninitialized(TypeFeedbackId id); | 53 bool StoreIsUninitialized(TypeFeedbackId id); |
| 238 bool StoreIsMonomorphicNormal(TypeFeedbackId id); | |
| 239 bool StoreIsPreMonomorphic(TypeFeedbackId id); | 54 bool StoreIsPreMonomorphic(TypeFeedbackId id); |
| 240 bool StoreIsKeyedPolymorphic(TypeFeedbackId id); | 55 bool StoreIsKeyedPolymorphic(TypeFeedbackId id); |
| 241 bool CallIsMonomorphic(TypeFeedbackId aid); | 56 bool CallIsMonomorphic(TypeFeedbackId aid); |
| 242 bool KeyedArrayCallIsHoley(TypeFeedbackId id); | 57 bool KeyedArrayCallIsHoley(TypeFeedbackId id); |
| 243 bool CallNewIsMonomorphic(TypeFeedbackId id); | 58 bool CallNewIsMonomorphic(TypeFeedbackId id); |
| 244 bool ObjectLiteralStoreIsMonomorphic(TypeFeedbackId id); | |
| 245 | 59 |
| 246 // TODO(1571) We can't use ForInStatement::ForInType as the return value due | 60 // TODO(1571) We can't use ForInStatement::ForInType as the return value due |
| 247 // to various cycles in our headers. | 61 // to various cycles in our headers. |
| 248 // TODO(rossberg): once all oracle access is removed from ast.cc, it should | 62 // TODO(rossberg): once all oracle access is removed from ast.cc, it should |
| 249 // be possible. | 63 // be possible. |
| 250 byte ForInType(TypeFeedbackId id); | 64 byte ForInType(TypeFeedbackId id); |
| 251 | 65 |
| 252 Handle<Map> LoadMonomorphicReceiverType(TypeFeedbackId id); | |
| 253 Handle<Map> StoreMonomorphicReceiverType(TypeFeedbackId id); | |
| 254 | |
| 255 KeyedAccessStoreMode GetStoreMode(TypeFeedbackId id); | 66 KeyedAccessStoreMode GetStoreMode(TypeFeedbackId id); |
| 256 | 67 |
| 257 void LoadReceiverTypes(TypeFeedbackId id, | |
| 258 Handle<String> name, | |
| 259 SmallMapList* types); | |
| 260 void StoreReceiverTypes(TypeFeedbackId id, | |
| 261 Handle<String> name, | |
| 262 SmallMapList* types); | |
| 263 void CallReceiverTypes(TypeFeedbackId id, | 68 void CallReceiverTypes(TypeFeedbackId id, |
| 264 Handle<String> name, | 69 Handle<String> name, |
| 265 int arity, | 70 int arity, |
| 266 CallKind call_kind, | 71 CallKind call_kind, |
| 267 SmallMapList* types); | 72 SmallMapList* types); |
| 268 void CollectKeyedReceiverTypes(TypeFeedbackId id, | |
| 269 SmallMapList* types); | |
| 270 void CollectPolymorphicStoreReceiverTypes(TypeFeedbackId id, | |
| 271 SmallMapList* types); | |
| 272 | |
| 273 void PropertyReceiverTypes(TypeFeedbackId id, | 73 void PropertyReceiverTypes(TypeFeedbackId id, |
| 274 Handle<String> name, | 74 Handle<String> name, |
| 275 SmallMapList* receiver_types, | 75 SmallMapList* receiver_types, |
| 276 bool* is_prototype); | 76 bool* is_prototype); |
| 277 void KeyedPropertyReceiverTypes(TypeFeedbackId id, | 77 void KeyedPropertyReceiverTypes(TypeFeedbackId id, |
| 278 SmallMapList* receiver_types, | 78 SmallMapList* receiver_types, |
| 279 bool* is_string); | 79 bool* is_string); |
| 280 void AssignmentReceiverTypes(TypeFeedbackId id, | 80 void AssignmentReceiverTypes(TypeFeedbackId id, |
| 281 Handle<String> name, | 81 Handle<String> name, |
| 282 SmallMapList* receiver_types); | 82 SmallMapList* receiver_types); |
| 283 void KeyedAssignmentReceiverTypes(TypeFeedbackId id, | 83 void KeyedAssignmentReceiverTypes(TypeFeedbackId id, |
| 284 SmallMapList* receiver_types, | 84 SmallMapList* receiver_types, |
| 285 KeyedAccessStoreMode* store_mode); | 85 KeyedAccessStoreMode* store_mode); |
| 286 void CountReceiverTypes(TypeFeedbackId id, | 86 void CountReceiverTypes(TypeFeedbackId id, |
| 287 SmallMapList* receiver_types); | 87 SmallMapList* receiver_types); |
| 288 | 88 |
| 89 void CollectReceiverTypes(TypeFeedbackId id, |
| 90 SmallMapList* types); |
| 91 |
| 289 static bool CanRetainOtherContext(Map* map, Context* native_context); | 92 static bool CanRetainOtherContext(Map* map, Context* native_context); |
| 290 static bool CanRetainOtherContext(JSFunction* function, | 93 static bool CanRetainOtherContext(JSFunction* function, |
| 291 Context* native_context); | 94 Context* native_context); |
| 292 | 95 |
| 293 void CollectPolymorphicMaps(Handle<Code> code, SmallMapList* types); | |
| 294 | |
| 295 CheckType GetCallCheckType(TypeFeedbackId id); | 96 CheckType GetCallCheckType(TypeFeedbackId id); |
| 296 Handle<JSFunction> GetCallTarget(TypeFeedbackId id); | 97 Handle<JSFunction> GetCallTarget(TypeFeedbackId id); |
| 297 Handle<JSFunction> GetCallNewTarget(TypeFeedbackId id); | 98 Handle<JSFunction> GetCallNewTarget(TypeFeedbackId id); |
| 298 Handle<Cell> GetCallNewAllocationInfoCell(TypeFeedbackId id); | 99 Handle<Cell> GetCallNewAllocationInfoCell(TypeFeedbackId id); |
| 299 | 100 |
| 300 Handle<Map> GetObjectLiteralStoreMap(TypeFeedbackId id); | |
| 301 | |
| 302 bool LoadIsBuiltin(TypeFeedbackId id, Builtins::Name builtin_id); | 101 bool LoadIsBuiltin(TypeFeedbackId id, Builtins::Name builtin_id); |
| 303 bool LoadIsStub(TypeFeedbackId id, ICStub* stub); | 102 bool LoadIsStub(TypeFeedbackId id, ICStub* stub); |
| 304 | 103 |
| 305 // TODO(1571) We can't use ToBooleanStub::Types as the return value because | 104 // TODO(1571) We can't use ToBooleanStub::Types as the return value because |
| 306 // of various cycles in our headers. Death to tons of implementations in | 105 // of various cycles in our headers. Death to tons of implementations in |
| 307 // headers!! :-P | 106 // headers!! :-P |
| 308 byte ToBooleanTypes(TypeFeedbackId id); | 107 byte ToBooleanTypes(TypeFeedbackId id); |
| 309 | 108 |
| 310 // Get type information for arithmetic operations and compares. | 109 // Get type information for arithmetic operations and compares. |
| 311 void BinaryType(TypeFeedbackId id, | 110 void BinaryType(TypeFeedbackId id, |
| 312 Handle<Type>* left, | 111 Handle<Type>* left, |
| 313 Handle<Type>* right, | 112 Handle<Type>* right, |
| 314 Handle<Type>* result, | 113 Handle<Type>* result, |
| 315 Maybe<int>* fixed_right_arg, | 114 Maybe<int>* fixed_right_arg, |
| 115 Handle<AllocationSite>* allocation_site, |
| 316 Token::Value operation); | 116 Token::Value operation); |
| 317 | 117 |
| 318 void CompareType(TypeFeedbackId id, | 118 void CompareType(TypeFeedbackId id, |
| 319 Handle<Type>* left, | 119 Handle<Type>* left, |
| 320 Handle<Type>* right, | 120 Handle<Type>* right, |
| 321 Handle<Type>* combined); | 121 Handle<Type>* combined); |
| 322 | 122 |
| 323 Handle<Type> CountType(TypeFeedbackId id); | 123 Handle<Type> CountType(TypeFeedbackId id); |
| 324 | 124 |
| 325 Handle<Type> ClauseType(TypeFeedbackId id); | |
| 326 | |
| 327 Zone* zone() const { return zone_; } | 125 Zone* zone() const { return zone_; } |
| 328 Isolate* isolate() const { return isolate_; } | 126 Isolate* isolate() const { return isolate_; } |
| 329 | 127 |
| 330 private: | 128 private: |
| 331 void CollectReceiverTypes(TypeFeedbackId id, | 129 void CollectReceiverTypes(TypeFeedbackId id, |
| 332 Handle<String> name, | 130 Handle<String> name, |
| 333 Code::Flags flags, | 131 Code::Flags flags, |
| 334 SmallMapList* types); | 132 SmallMapList* types); |
| 335 | 133 |
| 336 void SetInfo(TypeFeedbackId id, Object* target); | 134 void SetInfo(TypeFeedbackId id, Object* target); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 356 Isolate* isolate_; | 154 Isolate* isolate_; |
| 357 Zone* zone_; | 155 Zone* zone_; |
| 358 Handle<UnseededNumberDictionary> dictionary_; | 156 Handle<UnseededNumberDictionary> dictionary_; |
| 359 | 157 |
| 360 DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle); | 158 DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle); |
| 361 }; | 159 }; |
| 362 | 160 |
| 363 } } // namespace v8::internal | 161 } } // namespace v8::internal |
| 364 | 162 |
| 365 #endif // V8_TYPE_INFO_H_ | 163 #endif // V8_TYPE_INFO_H_ |
| OLD | NEW |