Reviewers: Igor Sheludko,
Message:
PTAL
Description:
Initial steps for moving code onto Map
BUG=
Please review this at https://codereview.chromium.org/237143004/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+28, -52 lines):
M src/objects.h
M src/objects.cc
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index
73b8c23101ff753fc0b90af043d3726b16c7d954..97984e5762d060794faac81f8551534968f30fc4
100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -1825,23 +1825,6 @@ static Handle<Object> NewStorageFor(Isolate* isolate,
}
-static Handle<Map> CopyAddFieldDescriptor(Handle<Map> map,
- Handle<Name> name,
- int index,
- PropertyAttributes attributes,
- Representation representation,
- TransitionFlag flag) {
- FieldDescriptor new_field_desc(name, index, attributes, representation);
- Handle<Map> new_map = Map::CopyAddDescriptor(map, &new_field_desc, flag);
- int unused_property_fields = map->unused_property_fields() - 1;
- if (unused_property_fields < 0) {
- unused_property_fields += JSObject::kFieldsAdded;
- }
- new_map->set_unused_property_fields(unused_property_fields);
- return new_map;
-}
-
-
void JSObject::AddFastProperty(Handle<JSObject> object,
Handle<Name> name,
Handle<Object> value,
@@ -1865,14 +1848,21 @@ void JSObject::AddFastProperty(Handle<JSObject>
object,
return;
}
- // Compute the new index for new field.
- int index = object->map()->NextFreePropertyIndex();
-
// Allocate new instance descriptors with (name, index) added
if (object->IsJSContextExtensionObject()) value_type = FORCE_TAGGED;
Representation representation = value->OptimalRepresentation(value_type);
- Handle<Map> new_map = CopyAddFieldDescriptor(
- handle(object->map()), name, index, attributes, representation,
flag);
+
+ // Compute the new index for new field.
+ int index = object->map()->NextFreePropertyIndex();
+
+ FieldDescriptor new_field_desc(name, index, attributes, representation);
+ Handle<Map> new_map = Map::CopyAddDescriptor(
+ handle(object->map()), &new_field_desc, flag);
+ int unused_property_fields = new_map->unused_property_fields() - 1;
+ if (unused_property_fields < 0) {
+ unused_property_fields += JSObject::kFieldsAdded;
+ }
+ new_map->set_unused_property_fields(unused_property_fields);
JSObject::MigrateToMap(object, new_map);
@@ -1887,33 +1877,19 @@ void JSObject::AddFastProperty(Handle<JSObject>
object,
}
-static Handle<Map> CopyAddConstantDescriptor(Handle<Map> map,
- Handle<Name> name,
- Handle<Object> value,
- PropertyAttributes attributes,
- TransitionFlag flag) {
- ConstantDescriptor new_constant_desc(name, value, attributes);
- return Map::CopyAddDescriptor(map, &new_constant_desc, flag);
-}
-
-
void JSObject::AddConstantProperty(Handle<JSObject> object,
Handle<Name> name,
Handle<Object> constant,
PropertyAttributes attributes,
TransitionFlag initial_flag) {
- TransitionFlag flag =
- // Do not add transitions to global objects.
- (object->IsGlobalObject() ||
- // Don't add transitions to special properties with non-trivial
- // attributes.
- attributes != NONE)
- ? OMIT_TRANSITION
- : initial_flag;
+ ASSERT(!object->IsGlobalObject());
+ // Don't add transitions to special properties with non-trivial
attributes.
+ TransitionFlag flag = attributes != NONE ? OMIT_TRANSITION :
initial_flag;
// Allocate new instance descriptors with (name, constant) added.
- Handle<Map> new_map = CopyAddConstantDescriptor(
- handle(object->map()), name, constant, attributes, flag);
+ ConstantDescriptor new_constant_desc(name, constant, attributes);
+ Handle<Map> new_map = Map::CopyAddDescriptor(
+ handle(object->map()), &new_constant_desc, flag);
JSObject::MigrateToMap(object, new_map);
}
@@ -4410,13 +4386,13 @@ PropertyAttributes
JSObject::GetElementAttributeWithoutInterceptor(
Handle<Map> NormalizedMapCache::Get(Handle<NormalizedMapCache> cache,
- Handle<JSObject> obj,
+ Handle<Map> fast_map,
PropertyNormalizationMode mode) {
- int index = obj->map()->Hash() % kEntries;
+ int index = fast_map->Hash() % kEntries;
Handle<Object> result = handle(cache->get(index), cache->GetIsolate());
if (result->IsMap() &&
- Handle<Map>::cast(result)->EquivalentToForNormalization(obj->map(),
- mode)) {
+ Handle<Map>::cast(result)->EquivalentToForNormalization(
+ *fast_map, mode)) {
#ifdef VERIFY_HEAP
if (FLAG_verify_heap) {
Handle<Map>::cast(result)->SharedMapVerify();
@@ -4427,8 +4403,8 @@ Handle<Map>
NormalizedMapCache::Get(Handle<NormalizedMapCache> cache,
// The cached map should match newly created normalized map
bit-by-bit,
// except for the code cache, which can contain some ics which can be
// applied to the shared map.
- Handle<Map> fresh = Map::CopyNormalized(handle(obj->map()), mode,
- SHARED_NORMALIZED_MAP);
+ Handle<Map> fresh = Map::CopyNormalized(
+ fast_map, mode, SHARED_NORMALIZED_MAP);
ASSERT(memcmp(fresh->address(),
Handle<Map>::cast(result)->address(),
@@ -4445,8 +4421,7 @@ Handle<Map>
NormalizedMapCache::Get(Handle<NormalizedMapCache> cache,
}
Isolate* isolate = cache->GetIsolate();
- Handle<Map> map = Map::CopyNormalized(handle(obj->map()), mode,
- SHARED_NORMALIZED_MAP);
+ Handle<Map> map = Map::CopyNormalized(fast_map, mode,
SHARED_NORMALIZED_MAP);
ASSERT(map->is_dictionary_map());
cache->set(index, *map);
isolate->counters()->normalized_maps()->Increment();
@@ -4540,7 +4515,8 @@ void JSObject::NormalizeProperties(Handle<JSObject>
object,
Handle<NormalizedMapCache> cache(
isolate->context()->native_context()->normalized_map_cache());
- Handle<Map> new_map = NormalizedMapCache::Get(cache, object, mode);
+ Handle<Map> new_map = NormalizedMapCache::Get(
+ cache, handle(object->map()), mode);
ASSERT(new_map->is_dictionary_map());
// From here on we cannot fail and we shouldn't GC anymore.
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index
1c3a82078adc0dfb89cb610f172d1f577dbdebe9..8afd194dc9fe1a43c9481fc693fedd59c92aa8d6
100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -4716,7 +4716,7 @@ class NormalizedMapCache: public FixedArray {
static const int kEntries = 64;
static Handle<Map> Get(Handle<NormalizedMapCache> cache,
- Handle<JSObject> object,
+ Handle<Map> fast_map,
PropertyNormalizationMode mode);
void Clear();
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.