Reviewers: Igor Sheludko,
Message:
PTAL
Description:
Immediately "optimize as prototype" when setting as prototype of a function.
This saves space since OptimizeAsPrototype detaches from the transition
tree,
reclaiming intermediate maps. On gmail this corresponds to roughly 20% of
all
maps.
BUG=
Please review this at https://codereview.chromium.org/941213005/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+45, -35 lines):
M src/objects.cc
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index
0eda4912e63902939c8efd1effdc71953670f307..5ecd73991942075f55572171721cbbb23f1111a3
100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -10033,6 +10033,45 @@ void SharedFunctionInfo::TrimOptimizedCodeMap(int
shrink_by) {
}
+static void GetMinInobjectSlack(Map* map, void* data) {
+ int slack = map->unused_property_fields();
+ if (*reinterpret_cast<int*>(data) > slack) {
+ *reinterpret_cast<int*>(data) = slack;
+ }
+}
+
+
+static void ShrinkInstanceSize(Map* map, void* data) {
+ int slack = *reinterpret_cast<int*>(data);
+ map->set_inobject_properties(map->inobject_properties() - slack);
+ map->set_unused_property_fields(map->unused_property_fields() - slack);
+ map->set_instance_size(map->instance_size() - slack * kPointerSize);
+
+ // Visitor id might depend on the instance size, recalculate it.
+ map->set_visitor_id(StaticVisitorBase::GetVisitorId(map));
+}
+
+
+static void OptimizeMapTreeSize(Map* map) {
+ int slack = map->unused_property_fields();
+ map->TraverseTransitionTree(&GetMinInobjectSlack, &slack);
+ if (slack != 0) {
+ // Resize the initial map and all maps in its transition tree.
+ map->TraverseTransitionTree(&ShrinkInstanceSize, &slack);
+ }
+}
+
+
+void JSFunction::CompleteInobjectSlackTracking() {
+ DCHECK(has_initial_map());
+ Map* map = initial_map();
+
+ DCHECK(map->counter() >= Map::kSlackTrackingCounterEnd - 1);
+ map->set_counter(Map::kRetainingCounterStart);
+ OptimizeMapTreeSize(map);
+}
+
+
void JSObject::OptimizeAsPrototype(Handle<JSObject> object,
PrototypeOptimizationMode mode) {
if (object->IsGlobalObject()) return;
@@ -10046,6 +10085,7 @@ void JSObject::OptimizeAsPrototype(Handle<JSObject>
object,
if (!object->HasFastProperties()) {
JSObject::MigrateSlowToFast(object, 0, "OptimizeAsPrototype");
has_just_copied_map = true;
+ OptimizeMapTreeSize(object->map());
}
if (mode == FAST_PROTOTYPE && object->HasFastProperties() &&
!object->map()->is_prototype_map()) {
@@ -10224,6 +10264,11 @@ void
JSFunction::SetInstancePrototype(Handle<JSFunction> function,
// needed. At that point, a new initial map is created and the
// prototype is put into the initial map where it belongs.
function->set_prototype_or_initial_map(*value);
+ if (value->IsJSObject()) {
+ // Optimize as prototype to detach it from its transition tree.
+ JSObject::OptimizeAsPrototype(Handle<JSObject>::cast(value),
+ FAST_PROTOTYPE);
+ }
}
isolate->heap()->ClearInstanceofCache();
}
@@ -10766,41 +10811,6 @@ void SharedFunctionInfo::ResetForNewContext(int
new_ic_age) {
}
-static void GetMinInobjectSlack(Map* map, void* data) {
- int slack = map->unused_property_fields();
- if (*reinterpret_cast<int*>(data) > slack) {
- *reinterpret_cast<int*>(data) = slack;
- }
-}
-
-
-static void ShrinkInstanceSize(Map* map, void* data) {
- int slack = *reinterpret_cast<int*>(data);
- map->set_inobject_properties(map->inobject_properties() - slack);
- map->set_unused_property_fields(map->unused_property_fields() - slack);
- map->set_instance_size(map->instance_size() - slack * kPointerSize);
-
- // Visitor id might depend on the instance size, recalculate it.
- map->set_visitor_id(StaticVisitorBase::GetVisitorId(map));
-}
-
-
-void JSFunction::CompleteInobjectSlackTracking() {
- DCHECK(has_initial_map());
- Map* map = initial_map();
-
- DCHECK(map->counter() >= Map::kSlackTrackingCounterEnd - 1);
- map->set_counter(Map::kRetainingCounterStart);
-
- int slack = map->unused_property_fields();
- map->TraverseTransitionTree(&GetMinInobjectSlack, &slack);
- if (slack != 0) {
- // Resize the initial map and all maps in its transition tree.
- map->TraverseTransitionTree(&ShrinkInstanceSize, &slack);
- }
-}
-
-
int SharedFunctionInfo::SearchOptimizedCodeMap(Context* native_context,
BailoutId osr_ast_id) {
DisallowHeapAllocation no_gc;
--
--
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.