Make the typefeedback oracle use a NumberDictionary instead of JSObject as its backing store.

This avoids problems when getters/setters are defined on Object.

BUG=v8:1232


Review URL: http://codereview.chromium.org/6625054

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7081 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
fschneider@chromium.org 2011-03-07 16:09:56 +00:00
parent 2662624988
commit ade4b7506b
2 changed files with 43 additions and 28 deletions

View File

@ -64,42 +64,44 @@ STATIC_ASSERT(DEFAULT_STRING_STUB == Code::kNoExtraICState);
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 @@ ZoneMapList* TypeFeedbackOracle::CallReceiverTypes(Call* expr,
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 @@ Handle<JSObject> TypeFeedbackOracle::GetPrototypeForPrimitiveCheck(
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::CompareType(CompareOperation* expr) {
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::BinaryType(BinaryOperation* expr) {
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 @@ TypeInfo TypeFeedbackOracle::SwitchType(CaseClause* clause) {
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,45 +322,57 @@ void TypeFeedbackOracle::PopulateMap(Handle<Code> code) {
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++) {
HandleScope loop_scope;
RelocInfo info(code->instruction_start() + code_positions[i],
RelocInfo::CODE_TARGET, 0);
Handle<Code> target(Code::GetCodeFromTargetAddress(info.target_address()));
int position = source_positions[i];
InlineCacheState state = target->ic_state();
Code::Kind kind = target->kind();
Handle<Object> value;
if (kind == Code::BINARY_OP_IC ||
kind == Code::TYPE_RECORDING_BINARY_OP_IC ||
kind == Code::COMPARE_IC) {
// 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) {
value = 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);
value = target;
} else {
SetElement(map_, position, map, kNonStrictMode);
value = 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);
value = Handle<Object>(Smi::FromInt(check));
}
} else if (state == MEGAMORPHIC) {
SetElement(map_, position, target, kNonStrictMode);
value = target;
}
if (!value.is_null()) {
Handle<NumberDictionary> new_dict =
Factory::DictionaryAtNumberPut(dictionary_, position, value);
dictionary_ = loop_scope.CloseAndEscape(new_dict);
}
}
// Allocate handle in the parent scope.
dictionary_ = scope.CloseAndEscape(dictionary_);
}

View File

@ -260,8 +260,6 @@ class TypeFeedbackOracle BASE_EMBEDDED {
TypeInfo SwitchType(CaseClause* clause);
private:
void Initialize(Handle<Code> code);
ZoneMapList* CollectReceiverTypes(int position,
Handle<String> name,
Code::Flags flags);
@ -272,8 +270,12 @@ class TypeFeedbackOracle BASE_EMBEDDED {
List<int>* code_positions,
List<int>* source_positions);
// Returns an element from the backing store. Returns undefined if
// there is no information.
Handle<Object> GetInfo(int pos);
Handle<Context> global_context_;
Handle<JSObject> map_;
Handle<NumberDictionary> dictionary_;
DISALLOW_COPY_AND_ASSIGN(TypeFeedbackOracle);
};