Chromium Code Reviews| Index: src/type-info.cc |
| =================================================================== |
| --- src/type-info.cc (revision 7069) |
| +++ src/type-info.cc (working copy) |
| @@ -64,42 +64,44 @@ |
| TypeFeedbackOracle::TypeFeedbackOracle(Handle<Code> code, |
| Handle<Context> global_context) { |
| global_context_ = global_context; |
| - Initialize(code); |
| + PopulateMap(code); |
| + ASSERT(reinterpret_cast<Address>(*dictionary_.location()) != kHandleZapValue); |
| } |
| -void TypeFeedbackOracle::Initialize(Handle<Code> code) { |
| - ASSERT(map_.is_null()); // Only initialize once. |
| - map_ = Factory::NewJSObject(Top::object_function()); |
| - PopulateMap(code); |
| +Handle<Object> TypeFeedbackOracle::GetInfo(int pos) { |
| + int entry = dictionary_->FindEntry(pos); |
| + return entry != NumberDictionary::kNotFound |
| + ? Handle<Object>(dictionary_->ValueAt(entry)) |
| + : Factory::undefined_value(); |
| } |
| bool TypeFeedbackOracle::LoadIsMonomorphic(Property* expr) { |
| - return GetElement(map_, expr->position())->IsMap(); |
| + return GetInfo(expr->position())->IsMap(); |
| } |
| bool TypeFeedbackOracle:: StoreIsMonomorphic(Assignment* expr) { |
| - return GetElement(map_, expr->position())->IsMap(); |
| + return GetInfo(expr->position())->IsMap(); |
| } |
| bool TypeFeedbackOracle::CallIsMonomorphic(Call* expr) { |
| - Handle<Object> value = GetElement(map_, expr->position()); |
| + Handle<Object> value = GetInfo(expr->position()); |
| return value->IsMap() || value->IsSmi(); |
| } |
| Handle<Map> TypeFeedbackOracle::LoadMonomorphicReceiverType(Property* expr) { |
| ASSERT(LoadIsMonomorphic(expr)); |
| - return Handle<Map>::cast(GetElement(map_, expr->position())); |
| + return Handle<Map>::cast(GetInfo(expr->position())); |
| } |
| Handle<Map> TypeFeedbackOracle::StoreMonomorphicReceiverType(Assignment* expr) { |
| ASSERT(StoreIsMonomorphic(expr)); |
| - return Handle<Map>::cast(GetElement(map_, expr->position())); |
| + return Handle<Map>::cast(GetInfo(expr->position())); |
| } |
| @@ -135,7 +137,7 @@ |
| CheckType TypeFeedbackOracle::GetCallCheckType(Call* expr) { |
| - Handle<Object> value = GetElement(map_, expr->position()); |
| + Handle<Object> value = GetInfo(expr->position()); |
| if (!value->IsSmi()) return RECEIVER_MAP_CHECK; |
| CheckType check = static_cast<CheckType>(Smi::cast(*value)->value()); |
| ASSERT(check != RECEIVER_MAP_CHECK); |
| @@ -166,13 +168,12 @@ |
| bool TypeFeedbackOracle::LoadIsBuiltin(Property* expr, Builtins::Name id) { |
| - Handle<Object> object = GetElement(map_, expr->position()); |
| - return *object == Builtins::builtin(id); |
| + return *GetInfo(expr->position()) == Builtins::builtin(id); |
| } |
| TypeInfo TypeFeedbackOracle::CompareType(CompareOperation* expr) { |
| - Handle<Object> object = GetElement(map_, expr->position()); |
| + Handle<Object> object = GetInfo(expr->position()); |
| TypeInfo unknown = TypeInfo::Unknown(); |
| if (!object->IsCode()) return unknown; |
| Handle<Code> code = Handle<Code>::cast(object); |
| @@ -199,7 +200,7 @@ |
| TypeInfo TypeFeedbackOracle::BinaryType(BinaryOperation* expr) { |
| - Handle<Object> object = GetElement(map_, expr->position()); |
| + Handle<Object> object = GetInfo(expr->position()); |
| TypeInfo unknown = TypeInfo::Unknown(); |
| if (!object->IsCode()) return unknown; |
| Handle<Code> code = Handle<Code>::cast(object); |
| @@ -261,7 +262,7 @@ |
| TypeInfo TypeFeedbackOracle::SwitchType(CaseClause* clause) { |
| - Handle<Object> object = GetElement(map_, clause->position()); |
| + Handle<Object> object = GetInfo(clause->position()); |
| TypeInfo unknown = TypeInfo::Unknown(); |
| if (!object->IsCode()) return unknown; |
| Handle<Code> code = Handle<Code>::cast(object); |
| @@ -290,7 +291,7 @@ |
| ZoneMapList* TypeFeedbackOracle::CollectReceiverTypes(int position, |
| Handle<String> name, |
| Code::Flags flags) { |
| - Handle<Object> object = GetElement(map_, position); |
| + Handle<Object> object = GetInfo(position); |
| if (object->IsUndefined() || object->IsSmi()) return NULL; |
| if (*object == Builtins::builtin(Builtins::StoreIC_GlobalProxy)) { |
| @@ -321,6 +322,9 @@ |
| List<int> source_positions(kInitialCapacity); |
| CollectPositions(*code, &code_positions, &source_positions); |
| + ASSERT(dictionary_.is_null()); // Only initialize once. |
| + dictionary_ = Factory::NewNumberDictionary(code_positions.length()); |
| + |
| int length = code_positions.length(); |
| ASSERT(source_positions.length() == length); |
| for (int i = 0; i < length; i++) { |
|
Lasse Reichstein
2011/03/07 13:49:46
You may want a loop HandleScope to avoid using too
|
| @@ -336,30 +340,43 @@ |
| // TODO(kasperl): Avoid having multiple ICs with the same |
| // position by making sure that we have position information |
| // recorded for all binary ICs. |
| - if (GetElement(map_, position)->IsUndefined()) { |
| - SetElement(map_, position, target, kNonStrictMode); |
| + int entry = dictionary_->FindEntry(position); |
| + if (entry == NumberDictionary::kNotFound) { |
| + dictionary_ = Factory::DictionaryAtNumberPut(dictionary_, |
| + position, |
| + target); |
| } |
| } else if (state == MONOMORPHIC) { |
| if (target->kind() != Code::CALL_IC || |
| target->check_type() == RECEIVER_MAP_CHECK) { |
| Handle<Map> map = Handle<Map>(target->FindFirstMap()); |
| if (*map == NULL) { |
| - SetElement(map_, position, target, kNonStrictMode); |
| + dictionary_ = Factory::DictionaryAtNumberPut(dictionary_, |
| + position, |
| + target); |
| } else { |
| - SetElement(map_, position, map, kNonStrictMode); |
| + dictionary_ = Factory::DictionaryAtNumberPut(dictionary_, |
| + position, |
| + map); |
| } |
| } else { |
| ASSERT(target->kind() == Code::CALL_IC); |
| CheckType check = target->check_type(); |
| ASSERT(check != RECEIVER_MAP_CHECK); |
| - SetElement(map_, position, |
| - Handle<Object>(Smi::FromInt(check)), kNonStrictMode); |
| - ASSERT(Smi::cast(*GetElement(map_, position))->value() == check); |
| + dictionary_ = |
| + Factory::DictionaryAtNumberPut(dictionary_, |
| + position, |
| + Handle<Smi>(Smi::FromInt(check))); |
| + ASSERT(Handle<Smi>::cast(GetInfo(position))->value() == check); |
| } |
| } else if (state == MEGAMORPHIC) { |
| - SetElement(map_, position, target, kNonStrictMode); |
| + dictionary_ = Factory::DictionaryAtNumberPut(dictionary_, |
|
Lasse Reichstein
2011/03/07 13:49:46
It seems almost all branches end in a dictionary p
|
| + position, |
| + target); |
| } |
| } |
| + // Allocate handle in the parent scope. |
| + dictionary_ = scope.CloseAndEscape(dictionary_); |
| } |