| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 : TypeInfo::Double(); | 51 : TypeInfo::Double(); |
| 52 } else if (value->IsString()) { | 52 } else if (value->IsString()) { |
| 53 info = TypeInfo::String(); | 53 info = TypeInfo::String(); |
| 54 } else { | 54 } else { |
| 55 info = TypeInfo::Unknown(); | 55 info = TypeInfo::Unknown(); |
| 56 } | 56 } |
| 57 return info; | 57 return info; |
| 58 } | 58 } |
| 59 | 59 |
| 60 | 60 |
| 61 TypeFeedbackOracle::TypeFeedbackOracle(Handle<Code> code) { | 61 STATIC_ASSERT(DEFAULT_STRING_STUB == Code::kNoExtraICState); |
| 62 |
| 63 |
| 64 TypeFeedbackOracle::TypeFeedbackOracle(Handle<Code> code, |
| 65 Handle<Context> global_context) { |
| 66 global_context_ = global_context; |
| 62 Initialize(code); | 67 Initialize(code); |
| 63 } | 68 } |
| 64 | 69 |
| 65 | 70 |
| 66 void TypeFeedbackOracle::Initialize(Handle<Code> code) { | 71 void TypeFeedbackOracle::Initialize(Handle<Code> code) { |
| 67 ASSERT(map_.is_null()); // Only initialize once. | 72 ASSERT(map_.is_null()); // Only initialize once. |
| 68 map_ = Factory::NewJSObject(Top::object_function()); | 73 map_ = Factory::NewJSObject(Top::object_function()); |
| 69 PopulateMap(code); | 74 PopulateMap(code); |
| 70 } | 75 } |
| 71 | 76 |
| 72 | 77 |
| 73 bool TypeFeedbackOracle::LoadIsMonomorphic(Property* expr) { | 78 bool TypeFeedbackOracle::LoadIsMonomorphic(Property* expr) { |
| 74 return IsMonomorphic(expr->position()); | 79 return GetElement(map_, expr->position())->IsMap(); |
| 75 } | 80 } |
| 76 | 81 |
| 77 | 82 |
| 78 bool TypeFeedbackOracle:: StoreIsMonomorphic(Assignment* expr) { | 83 bool TypeFeedbackOracle:: StoreIsMonomorphic(Assignment* expr) { |
| 79 return IsMonomorphic(expr->position()); | 84 return GetElement(map_, expr->position())->IsMap(); |
| 80 } | 85 } |
| 81 | 86 |
| 82 | 87 |
| 83 bool TypeFeedbackOracle::CallIsMonomorphic(Call* expr) { | 88 bool TypeFeedbackOracle::CallIsMonomorphic(Call* expr) { |
| 84 return IsMonomorphic(expr->position()); | 89 Handle<Object> value = GetElement(map_, expr->position()); |
| 90 return value->IsMap() || value->IsSmi(); |
| 85 } | 91 } |
| 86 | 92 |
| 87 | 93 |
| 88 Handle<Map> TypeFeedbackOracle::LoadMonomorphicReceiverType(Property* expr) { | 94 Handle<Map> TypeFeedbackOracle::LoadMonomorphicReceiverType(Property* expr) { |
| 89 ASSERT(LoadIsMonomorphic(expr)); | 95 ASSERT(LoadIsMonomorphic(expr)); |
| 90 return Handle<Map>::cast(GetElement(map_, expr->position())); | 96 return Handle<Map>::cast(GetElement(map_, expr->position())); |
| 91 } | 97 } |
| 92 | 98 |
| 93 | 99 |
| 94 Handle<Map> TypeFeedbackOracle::StoreMonomorphicReceiverType(Assignment* expr) { | 100 Handle<Map> TypeFeedbackOracle::StoreMonomorphicReceiverType(Assignment* expr) { |
| 95 ASSERT(StoreIsMonomorphic(expr)); | 101 ASSERT(StoreIsMonomorphic(expr)); |
| 96 return Handle<Map>::cast(GetElement(map_, expr->position())); | 102 return Handle<Map>::cast(GetElement(map_, expr->position())); |
| 97 } | 103 } |
| 98 | 104 |
| 99 | 105 |
| 100 Handle<Map> TypeFeedbackOracle::CallMonomorphicReceiverType(Call* expr) { | |
| 101 ASSERT(CallIsMonomorphic(expr)); | |
| 102 return Handle<Map>::cast(GetElement(map_, expr->position())); | |
| 103 } | |
| 104 | |
| 105 | |
| 106 ZoneMapList* TypeFeedbackOracle::LoadReceiverTypes(Property* expr, | 106 ZoneMapList* TypeFeedbackOracle::LoadReceiverTypes(Property* expr, |
| 107 Handle<String> name) { | 107 Handle<String> name) { |
| 108 Code::Flags flags = Code::ComputeMonomorphicFlags(Code::LOAD_IC, NORMAL); | 108 Code::Flags flags = Code::ComputeMonomorphicFlags(Code::LOAD_IC, NORMAL); |
| 109 return CollectReceiverTypes(expr->position(), name, flags); | 109 return CollectReceiverTypes(expr->position(), name, flags); |
| 110 } | 110 } |
| 111 | 111 |
| 112 | 112 |
| 113 ZoneMapList* TypeFeedbackOracle::StoreReceiverTypes(Assignment* expr, | 113 ZoneMapList* TypeFeedbackOracle::StoreReceiverTypes(Assignment* expr, |
| 114 Handle<String> name) { | 114 Handle<String> name) { |
| 115 Code::Flags flags = Code::ComputeMonomorphicFlags(Code::STORE_IC, NORMAL); | 115 Code::Flags flags = Code::ComputeMonomorphicFlags(Code::STORE_IC, NORMAL); |
| 116 return CollectReceiverTypes(expr->position(), name, flags); | 116 return CollectReceiverTypes(expr->position(), name, flags); |
| 117 } | 117 } |
| 118 | 118 |
| 119 | 119 |
| 120 ZoneMapList* TypeFeedbackOracle::CallReceiverTypes(Call* expr, | 120 ZoneMapList* TypeFeedbackOracle::CallReceiverTypes(Call* expr, |
| 121 Handle<String> name) { | 121 Handle<String> name) { |
| 122 int arity = expr->arguments()->length(); | 122 int arity = expr->arguments()->length(); |
| 123 Code::Flags flags = Code::ComputeMonomorphicFlags( | 123 // Note: these flags won't let us get maps from stubs with |
| 124 Code::CALL_IC, NORMAL, OWN_MAP, NOT_IN_LOOP, arity); | 124 // non-default extra ic state in the megamorphic case. In the more |
| 125 // important monomorphic case the map is obtained directly, so it's |
| 126 // not a problem until we decide to emit more polymorphic code. |
| 127 Code::Flags flags = Code::ComputeMonomorphicFlags(Code::CALL_IC, |
| 128 NORMAL, |
| 129 Code::kNoExtraICState, |
| 130 OWN_MAP, |
| 131 NOT_IN_LOOP, |
| 132 arity); |
| 125 return CollectReceiverTypes(expr->position(), name, flags); | 133 return CollectReceiverTypes(expr->position(), name, flags); |
| 126 } | 134 } |
| 127 | 135 |
| 128 | 136 |
| 137 CheckType TypeFeedbackOracle::GetCallCheckType(Call* expr) { |
| 138 Handle<Object> value = GetElement(map_, expr->position()); |
| 139 if (!value->IsSmi()) return RECEIVER_MAP_CHECK; |
| 140 CheckType check = static_cast<CheckType>(Smi::cast(*value)->value()); |
| 141 ASSERT(check != RECEIVER_MAP_CHECK); |
| 142 return check; |
| 143 } |
| 144 |
| 145 |
| 146 Handle<JSObject> TypeFeedbackOracle::GetPrototypeForPrimitiveCheck( |
| 147 CheckType check) { |
| 148 JSFunction* function = NULL; |
| 149 switch (check) { |
| 150 case RECEIVER_MAP_CHECK: |
| 151 UNREACHABLE(); |
| 152 break; |
| 153 case STRING_CHECK: |
| 154 function = global_context_->string_function(); |
| 155 break; |
| 156 case NUMBER_CHECK: |
| 157 function = global_context_->number_function(); |
| 158 break; |
| 159 case BOOLEAN_CHECK: |
| 160 function = global_context_->boolean_function(); |
| 161 break; |
| 162 } |
| 163 ASSERT(function != NULL); |
| 164 return Handle<JSObject>(JSObject::cast(function->instance_prototype())); |
| 165 } |
| 166 |
| 167 |
| 129 bool TypeFeedbackOracle::LoadIsBuiltin(Property* expr, Builtins::Name id) { | 168 bool TypeFeedbackOracle::LoadIsBuiltin(Property* expr, Builtins::Name id) { |
| 130 Handle<Object> object = GetElement(map_, expr->position()); | 169 Handle<Object> object = GetElement(map_, expr->position()); |
| 131 return *object == Builtins::builtin(id); | 170 return *object == Builtins::builtin(id); |
| 132 } | 171 } |
| 133 | 172 |
| 134 | 173 |
| 135 TypeInfo TypeFeedbackOracle::CompareType(CompareOperation* expr, Side side) { | 174 TypeInfo TypeFeedbackOracle::CompareType(CompareOperation* expr) { |
| 136 Handle<Object> object = GetElement(map_, expr->position()); | 175 Handle<Object> object = GetElement(map_, expr->position()); |
| 137 TypeInfo unknown = TypeInfo::Unknown(); | 176 TypeInfo unknown = TypeInfo::Unknown(); |
| 138 if (!object->IsCode()) return unknown; | 177 if (!object->IsCode()) return unknown; |
| 139 Handle<Code> code = Handle<Code>::cast(object); | 178 Handle<Code> code = Handle<Code>::cast(object); |
| 140 if (!code->is_compare_ic_stub()) return unknown; | 179 if (!code->is_compare_ic_stub()) return unknown; |
| 141 | 180 |
| 142 CompareIC::State state = static_cast<CompareIC::State>(code->compare_state()); | 181 CompareIC::State state = static_cast<CompareIC::State>(code->compare_state()); |
| 143 switch (state) { | 182 switch (state) { |
| 144 case CompareIC::UNINITIALIZED: | 183 case CompareIC::UNINITIALIZED: |
| 145 // Uninitialized means never executed. | 184 // Uninitialized means never executed. |
| 146 // TODO(fschneider): Introduce a separate value for never-executed ICs. | 185 // TODO(fschneider): Introduce a separate value for never-executed ICs. |
| 147 return unknown; | 186 return unknown; |
| 148 case CompareIC::SMIS: | 187 case CompareIC::SMIS: |
| 149 return TypeInfo::Smi(); | 188 return TypeInfo::Smi(); |
| 150 case CompareIC::HEAP_NUMBERS: | 189 case CompareIC::HEAP_NUMBERS: |
| 151 return TypeInfo::Number(); | 190 return TypeInfo::Number(); |
| 152 case CompareIC::OBJECTS: | 191 case CompareIC::OBJECTS: |
| 153 // TODO(kasperl): We really need a type for JS objects here. | 192 // TODO(kasperl): We really need a type for JS objects here. |
| 154 return TypeInfo::NonPrimitive(); | 193 return TypeInfo::NonPrimitive(); |
| 155 case CompareIC::GENERIC: | 194 case CompareIC::GENERIC: |
| 156 default: | 195 default: |
| 157 return unknown; | 196 return unknown; |
| 158 } | 197 } |
| 159 } | 198 } |
| 160 | 199 |
| 161 | 200 |
| 162 TypeInfo TypeFeedbackOracle::BinaryType(BinaryOperation* expr, Side side) { | 201 TypeInfo TypeFeedbackOracle::BinaryType(BinaryOperation* expr) { |
| 163 Handle<Object> object = GetElement(map_, expr->position()); | 202 Handle<Object> object = GetElement(map_, expr->position()); |
| 164 TypeInfo unknown = TypeInfo::Unknown(); | 203 TypeInfo unknown = TypeInfo::Unknown(); |
| 165 if (!object->IsCode()) return unknown; | 204 if (!object->IsCode()) return unknown; |
| 166 Handle<Code> code = Handle<Code>::cast(object); | 205 Handle<Code> code = Handle<Code>::cast(object); |
| 167 if (code->is_binary_op_stub()) { | 206 if (code->is_binary_op_stub()) { |
| 168 BinaryOpIC::TypeInfo type = static_cast<BinaryOpIC::TypeInfo>( | 207 BinaryOpIC::TypeInfo type = static_cast<BinaryOpIC::TypeInfo>( |
| 169 code->binary_op_type()); | 208 code->binary_op_type()); |
| 170 switch (type) { | 209 switch (type) { |
| 171 case BinaryOpIC::UNINIT_OR_SMI: | 210 case BinaryOpIC::UNINIT_OR_SMI: |
| 172 return TypeInfo::Smi(); | 211 return TypeInfo::Smi(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 case TRBinaryOpIC::STRING: | 252 case TRBinaryOpIC::STRING: |
| 214 case TRBinaryOpIC::GENERIC: | 253 case TRBinaryOpIC::GENERIC: |
| 215 return unknown; | 254 return unknown; |
| 216 default: | 255 default: |
| 217 return unknown; | 256 return unknown; |
| 218 } | 257 } |
| 219 } | 258 } |
| 220 return unknown; | 259 return unknown; |
| 221 } | 260 } |
| 222 | 261 |
| 262 |
| 223 TypeInfo TypeFeedbackOracle::SwitchType(CaseClause* clause) { | 263 TypeInfo TypeFeedbackOracle::SwitchType(CaseClause* clause) { |
| 224 Handle<Object> object = GetElement(map_, clause->position()); | 264 Handle<Object> object = GetElement(map_, clause->position()); |
| 225 TypeInfo unknown = TypeInfo::Unknown(); | 265 TypeInfo unknown = TypeInfo::Unknown(); |
| 226 if (!object->IsCode()) return unknown; | 266 if (!object->IsCode()) return unknown; |
| 227 Handle<Code> code = Handle<Code>::cast(object); | 267 Handle<Code> code = Handle<Code>::cast(object); |
| 228 if (!code->is_compare_ic_stub()) return unknown; | 268 if (!code->is_compare_ic_stub()) return unknown; |
| 229 | 269 |
| 230 CompareIC::State state = static_cast<CompareIC::State>(code->compare_state()); | 270 CompareIC::State state = static_cast<CompareIC::State>(code->compare_state()); |
| 231 switch (state) { | 271 switch (state) { |
| 232 case CompareIC::UNINITIALIZED: | 272 case CompareIC::UNINITIALIZED: |
| 233 // Uninitialized means never executed. | 273 // Uninitialized means never executed. |
| 234 // TODO(fschneider): Introduce a separate value for never-executed ICs. | 274 // TODO(fschneider): Introduce a separate value for never-executed ICs. |
| 235 return unknown; | 275 return unknown; |
| 236 case CompareIC::SMIS: | 276 case CompareIC::SMIS: |
| 237 return TypeInfo::Smi(); | 277 return TypeInfo::Smi(); |
| 238 case CompareIC::HEAP_NUMBERS: | 278 case CompareIC::HEAP_NUMBERS: |
| 239 return TypeInfo::Number(); | 279 return TypeInfo::Number(); |
| 240 case CompareIC::OBJECTS: | 280 case CompareIC::OBJECTS: |
| 241 // TODO(kasperl): We really need a type for JS objects here. | 281 // TODO(kasperl): We really need a type for JS objects here. |
| 242 return TypeInfo::NonPrimitive(); | 282 return TypeInfo::NonPrimitive(); |
| 243 case CompareIC::GENERIC: | 283 case CompareIC::GENERIC: |
| 244 default: | 284 default: |
| 245 return unknown; | 285 return unknown; |
| 246 } | 286 } |
| 247 } | 287 } |
| 248 | 288 |
| 249 | 289 |
| 250 | |
| 251 ZoneMapList* TypeFeedbackOracle::CollectReceiverTypes(int position, | 290 ZoneMapList* TypeFeedbackOracle::CollectReceiverTypes(int position, |
| 252 Handle<String> name, | 291 Handle<String> name, |
| 253 Code::Flags flags) { | 292 Code::Flags flags) { |
| 254 Handle<Object> object = GetElement(map_, position); | 293 Handle<Object> object = GetElement(map_, position); |
| 255 if (object->IsUndefined()) return NULL; | 294 if (object->IsUndefined() || object->IsSmi()) return NULL; |
| 256 | 295 |
| 257 if (*object == Builtins::builtin(Builtins::StoreIC_GlobalProxy)) { | 296 if (*object == Builtins::builtin(Builtins::StoreIC_GlobalProxy)) { |
| 258 // TODO(fschneider): We could collect the maps and signal that | 297 // TODO(fschneider): We could collect the maps and signal that |
| 259 // we need a generic store (or load) here. | 298 // we need a generic store (or load) here. |
| 260 ASSERT(Handle<Code>::cast(object)->ic_state() == MEGAMORPHIC); | 299 ASSERT(Handle<Code>::cast(object)->ic_state() == MEGAMORPHIC); |
| 261 return NULL; | 300 return NULL; |
| 262 } else if (object->IsMap()) { | 301 } else if (object->IsMap()) { |
| 263 ZoneMapList* types = new ZoneMapList(1); | 302 ZoneMapList* types = new ZoneMapList(1); |
| 264 types->Add(Handle<Map>::cast(object)); | 303 types->Add(Handle<Map>::cast(object)); |
| 265 return types; | 304 return types; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 294 if (kind == Code::BINARY_OP_IC || | 333 if (kind == Code::BINARY_OP_IC || |
| 295 kind == Code::TYPE_RECORDING_BINARY_OP_IC || | 334 kind == Code::TYPE_RECORDING_BINARY_OP_IC || |
| 296 kind == Code::COMPARE_IC) { | 335 kind == Code::COMPARE_IC) { |
| 297 // TODO(kasperl): Avoid having multiple ICs with the same | 336 // TODO(kasperl): Avoid having multiple ICs with the same |
| 298 // position by making sure that we have position information | 337 // position by making sure that we have position information |
| 299 // recorded for all binary ICs. | 338 // recorded for all binary ICs. |
| 300 if (GetElement(map_, position)->IsUndefined()) { | 339 if (GetElement(map_, position)->IsUndefined()) { |
| 301 SetElement(map_, position, target); | 340 SetElement(map_, position, target); |
| 302 } | 341 } |
| 303 } else if (state == MONOMORPHIC) { | 342 } else if (state == MONOMORPHIC) { |
| 304 Handle<Map> map = Handle<Map>(target->FindFirstMap()); | 343 if (target->kind() != Code::CALL_IC || |
| 305 if (*map == NULL) { | 344 target->check_type() == RECEIVER_MAP_CHECK) { |
| 306 SetElement(map_, position, target); | 345 Handle<Map> map = Handle<Map>(target->FindFirstMap()); |
| 346 if (*map == NULL) { |
| 347 SetElement(map_, position, target); |
| 348 } else { |
| 349 SetElement(map_, position, map); |
| 350 } |
| 307 } else { | 351 } else { |
| 308 SetElement(map_, position, map); | 352 ASSERT(target->kind() == Code::CALL_IC); |
| 353 CheckType check = target->check_type(); |
| 354 ASSERT(check != RECEIVER_MAP_CHECK); |
| 355 SetElement(map_, position, Handle<Object>(Smi::FromInt(check))); |
| 356 ASSERT(Smi::cast(*GetElement(map_, position))->value() == check); |
| 309 } | 357 } |
| 310 } else if (state == MEGAMORPHIC) { | 358 } else if (state == MEGAMORPHIC) { |
| 311 SetElement(map_, position, target); | 359 SetElement(map_, position, target); |
| 312 } | 360 } |
| 313 } | 361 } |
| 314 } | 362 } |
| 315 | 363 |
| 316 | 364 |
| 317 void TypeFeedbackOracle::CollectPositions(Code* code, | 365 void TypeFeedbackOracle::CollectPositions(Code* code, |
| 318 List<int>* code_positions, | 366 List<int>* code_positions, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 335 if (kind == Code::BINARY_OP_IC) { | 383 if (kind == Code::BINARY_OP_IC) { |
| 336 if (target->binary_op_type() == BinaryOpIC::GENERIC) continue; | 384 if (target->binary_op_type() == BinaryOpIC::GENERIC) continue; |
| 337 } else if (kind == Code::TYPE_RECORDING_BINARY_OP_IC) { | 385 } else if (kind == Code::TYPE_RECORDING_BINARY_OP_IC) { |
| 338 if (target->type_recording_binary_op_type() == | 386 if (target->type_recording_binary_op_type() == |
| 339 TRBinaryOpIC::GENERIC) { | 387 TRBinaryOpIC::GENERIC) { |
| 340 continue; | 388 continue; |
| 341 } | 389 } |
| 342 } else if (kind == Code::COMPARE_IC) { | 390 } else if (kind == Code::COMPARE_IC) { |
| 343 if (target->compare_state() == CompareIC::GENERIC) continue; | 391 if (target->compare_state() == CompareIC::GENERIC) continue; |
| 344 } else { | 392 } else { |
| 345 if (kind == Code::CALL_IC && state == MONOMORPHIC && | |
| 346 target->check_type() != RECEIVER_MAP_CHECK) continue; | |
| 347 if (state != MONOMORPHIC && state != MEGAMORPHIC) continue; | 393 if (state != MONOMORPHIC && state != MEGAMORPHIC) continue; |
| 348 } | 394 } |
| 349 code_positions->Add( | 395 code_positions->Add( |
| 350 static_cast<int>(info->pc() - code->instruction_start())); | 396 static_cast<int>(info->pc() - code->instruction_start())); |
| 351 source_positions->Add(position); | 397 source_positions->Add(position); |
| 352 } | 398 } |
| 353 } else { | 399 } else { |
| 354 ASSERT(RelocInfo::IsPosition(mode)); | 400 ASSERT(RelocInfo::IsPosition(mode)); |
| 355 position = static_cast<int>(info->data()); | 401 position = static_cast<int>(info->data()); |
| 356 } | 402 } |
| 357 } | 403 } |
| 358 } | 404 } |
| 359 | 405 |
| 360 } } // namespace v8::internal | 406 } } // namespace v8::internal |
| OLD | NEW |