From 88ca76bce18689cc47095d6654d267728214b71c Mon Sep 17 00:00:00 2001 From: "bmeurer@chromium.org" Date: Mon, 28 Apr 2014 05:47:43 +0000 Subject: [PATCH] Fix CurrentMapForDeprecated() to return MaybeHandle instead of a null handle. Also fix TryMigrateInstance() to return bool instead of the parameter or a null handle. R=yangguo@chromium.org Review URL: https://codereview.chromium.org/251683003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20996 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/ast.h | 3 +-- src/hydrogen.cc | 6 +++--- src/objects.cc | 29 +++++++++++++++++------------ src/objects.h | 10 ++++++---- src/runtime.cc | 3 +-- src/type-info.cc | 4 ++-- 6 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/ast.h b/src/ast.h index ed3a8b6..97b6a60 100644 --- a/src/ast.h +++ b/src/ast.h @@ -281,8 +281,7 @@ class SmallMapList V8_FINAL { int length() const { return list_.length(); } void AddMapIfMissing(Handle map, Zone* zone) { - map = Map::CurrentMapForDeprecated(map); - if (map.is_null()) return; + if (!Map::CurrentMapForDeprecated(map).ToHandle(&map)) return; for (int i = 0; i < length(); ++i) { if (at(i).is_identical_to(map)) return; } diff --git a/src/hydrogen.cc b/src/hydrogen.cc index bee033d..dcaf665 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -5114,9 +5114,9 @@ static bool CanInlinePropertyAccess(Type* type) { static bool IsFastLiteral(Handle boilerplate, int max_depth, int* max_properties) { - if (boilerplate->map()->is_deprecated()) { - Handle result = JSObject::TryMigrateInstance(boilerplate); - if (result.is_null()) return false; + if (boilerplate->map()->is_deprecated() && + !JSObject::TryMigrateInstance(boilerplate)) { + return false; } ASSERT(max_depth >= 0 && *max_properties >= 0); diff --git a/src/objects.cc b/src/objects.cc index 08f4a44..0910176 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -2764,20 +2764,22 @@ Handle Map::GeneralizeAllFieldRepresentations( } -Handle Map::CurrentMapForDeprecated(Handle map) { +// static +MaybeHandle Map::CurrentMapForDeprecated(Handle map) { Handle proto_map(map); while (proto_map->prototype()->IsJSObject()) { Handle holder(JSObject::cast(proto_map->prototype())); - if (holder->map()->is_deprecated()) { - JSObject::TryMigrateInstance(holder); - } proto_map = Handle(holder->map()); + if (proto_map->is_deprecated() && JSObject::TryMigrateInstance(holder)) { + proto_map = Handle(holder->map()); + } } return CurrentMapForDeprecatedInternal(map); } -Handle Map::CurrentMapForDeprecatedInternal(Handle map) { +// static +MaybeHandle Map::CurrentMapForDeprecatedInternal(Handle map) { if (!map->is_deprecated()) return map; DisallowHeapAllocation no_allocation; @@ -2787,18 +2789,18 @@ Handle Map::CurrentMapForDeprecatedInternal(Handle map) { Map* root_map = map->FindRootMap(); // Check the state of the root map. - if (!map->EquivalentToForTransition(root_map)) return Handle(); + if (!map->EquivalentToForTransition(root_map)) return MaybeHandle(); int verbatim = root_map->NumberOfOwnDescriptors(); Map* updated = root_map->FindUpdatedMap( verbatim, descriptors, old_descriptors); - if (updated == NULL) return Handle(); + if (updated == NULL) return MaybeHandle(); DescriptorArray* updated_descriptors = updated->instance_descriptors(); int valid = updated->NumberOfOwnDescriptors(); if (!updated_descriptors->IsMoreGeneralThan( verbatim, valid, descriptors, old_descriptors)) { - return Handle(); + return MaybeHandle(); } return handle(updated); @@ -3903,15 +3905,18 @@ void JSObject::MigrateInstance(Handle object) { } -Handle JSObject::TryMigrateInstance(Handle object) { +// static +bool JSObject::TryMigrateInstance(Handle object) { Handle original_map(object->map()); - Handle new_map = Map::CurrentMapForDeprecatedInternal(original_map); - if (new_map.is_null()) return Handle(); + Handle new_map; + if (!Map::CurrentMapForDeprecatedInternal(original_map).ToHandle(&new_map)) { + return false; + } JSObject::MigrateToMap(object, new_map); if (FLAG_trace_migration) { object->PrintInstanceMigration(stdout, *original_map, object->map()); } - return object; + return true; } diff --git a/src/objects.h b/src/objects.h index 8970c9e..5d96c2f 100644 --- a/src/objects.h +++ b/src/objects.h @@ -2294,8 +2294,8 @@ class JSObject: public JSReceiver { static void MigrateInstance(Handle instance); // Migrates the given object only if the target map is already available, - // or returns an empty handle if such a map is not yet available. - static Handle TryMigrateInstance(Handle instance); + // or returns false if such a map is not yet available. + static bool TryMigrateInstance(Handle instance); // Retrieve a value in a normalized object given a lookup result. // Handles the special representation of JS global objects. @@ -6429,9 +6429,11 @@ class Map: public HeapObject { // is found by re-transitioning from the root of the transition tree using the // descriptor array of the map. Returns NULL if no updated map is found. // This method also applies any pending migrations along the prototype chain. - static Handle CurrentMapForDeprecated(Handle map); + static MaybeHandle CurrentMapForDeprecated(Handle map) + V8_WARN_UNUSED_RESULT; // Same as above, but does not touch the prototype chain. - static Handle CurrentMapForDeprecatedInternal(Handle map); + static MaybeHandle CurrentMapForDeprecatedInternal(Handle map) + V8_WARN_UNUSED_RESULT; static Handle CopyDropDescriptors(Handle map); static Handle CopyInsertDescriptor(Handle map, diff --git a/src/runtime.cc b/src/runtime.cc index bc88f78..f3946d3 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -14583,8 +14583,7 @@ RUNTIME_FUNCTION(Runtime_TryMigrateInstance) { // code where we can't handle lazy deopts for lack of a suitable bailout // ID. So we just try migration and signal failure if necessary, // which will also trigger a deopt. - Handle result = JSObject::TryMigrateInstance(js_object); - if (result.is_null()) return Smi::FromInt(0); + if (!JSObject::TryMigrateInstance(js_object)) return Smi::FromInt(0); return *object; } diff --git a/src/type-info.cc b/src/type-info.cc index f863af0..0ba6dfa 100644 --- a/src/type-info.cc +++ b/src/type-info.cc @@ -217,8 +217,8 @@ void TypeFeedbackOracle::CompareType(TypeFeedbackId id, Handle map; Map* raw_map = code->FindFirstMap(); if (raw_map != NULL) { - map = Map::CurrentMapForDeprecated(handle(raw_map)); - if (!map.is_null() && CanRetainOtherContext(*map, *native_context_)) { + if (Map::CurrentMapForDeprecated(handle(raw_map)).ToHandle(&map) && + CanRetainOtherContext(*map, *native_context_)) { map = Handle::null(); } } -- 2.7.4