Reviewers: Lasse Reichstein,

Description:
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



Please review this at http://codereview.chromium.org/6625054/

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
  M     src/type-info.h
  M     src/type-info.cc


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++) {
@@ -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_,
+                                                   position,
+                                                   target);
     }
   }
+  // Allocate handle in the parent scope.
+  dictionary_ = scope.CloseAndEscape(dictionary_);
 }


Index: src/type-info.h
===================================================================
--- src/type-info.h     (revision 7069)
+++ src/type-info.h     (working copy)
@@ -260,8 +260,6 @@
   TypeInfo SwitchType(CaseClause* clause);

  private:
-  void Initialize(Handle<Code> code);
-
   ZoneMapList* CollectReceiverTypes(int position,
                                     Handle<String> name,
                                     Code::Flags flags);
@@ -272,8 +270,12 @@
                         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);
 };


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to