Reviewers: Yang,
Message:
PTAL
Description:
Fix CurrentMapForDeprecated() to return MaybeHandle instead of a null
handle.
Also fix TryMigrateInstance() to return bool instead of the parameter or
a null handle.
Please review this at https://codereview.chromium.org/251683003/
SVN Base: [email protected]:v8/v8.git@master
Affected files (+28, -25 lines):
M src/ast.h
M src/hydrogen.cc
M src/objects.h
M src/objects.cc
M src/runtime.cc
M src/type-info.cc
Index: src/ast.h
diff --git a/src/ast.h b/src/ast.h
index
ed3a8b6ee34eb72a14975eb6dc6e22d5099ad39f..97b6a60b3f5656d1a73a721866841b90c42f08d1
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> 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;
}
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index
4c02c90bd82dcc2a4f9d0d71bc2947c873a8da09..76360c5dfb71d7607f6e80c61316baa4247189c3
100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -5017,9 +5017,9 @@ static bool CanInlinePropertyAccess(Type* type) {
static bool IsFastLiteral(Handle<JSObject> boilerplate,
int max_depth,
int* max_properties) {
- if (boilerplate->map()->is_deprecated()) {
- Handle<Object> 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);
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index
2a7252ca13825355cb715eb2bb5b543e16db838d..70b8d0683413385c3d5429f95f7565979ba2233c
100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -2766,20 +2766,22 @@ Handle<Map> Map::GeneralizeAllFieldRepresentations(
}
-Handle<Map> Map::CurrentMapForDeprecated(Handle<Map> map) {
+// static
+MaybeHandle<Map> Map::CurrentMapForDeprecated(Handle<Map> map) {
Handle<Map> proto_map(map);
while (proto_map->prototype()->IsJSObject()) {
Handle<JSObject> holder(JSObject::cast(proto_map->prototype()));
- if (holder->map()->is_deprecated()) {
- JSObject::TryMigrateInstance(holder);
- }
proto_map = Handle<Map>(holder->map());
+ if (proto_map->is_deprecated() &&
JSObject::TryMigrateInstance(holder)) {
+ proto_map = Handle<Map>(holder->map());
+ }
}
return CurrentMapForDeprecatedInternal(map);
}
-Handle<Map> Map::CurrentMapForDeprecatedInternal(Handle<Map> map) {
+// static
+MaybeHandle<Map> Map::CurrentMapForDeprecatedInternal(Handle<Map> map) {
if (!map->is_deprecated()) return map;
DisallowHeapAllocation no_allocation;
@@ -2789,18 +2791,18 @@ Handle<Map>
Map::CurrentMapForDeprecatedInternal(Handle<Map> map) {
Map* root_map = map->FindRootMap();
// Check the state of the root map.
- if (!map->EquivalentToForTransition(root_map)) return Handle<Map>();
+ if (!map->EquivalentToForTransition(root_map)) return MaybeHandle<Map>();
int verbatim = root_map->NumberOfOwnDescriptors();
Map* updated = root_map->FindUpdatedMap(
verbatim, descriptors, old_descriptors);
- if (updated == NULL) return Handle<Map>();
+ if (updated == NULL) return MaybeHandle<Map>();
DescriptorArray* updated_descriptors = updated->instance_descriptors();
int valid = updated->NumberOfOwnDescriptors();
if (!updated_descriptors->IsMoreGeneralThan(
verbatim, valid, descriptors, old_descriptors)) {
- return Handle<Map>();
+ return MaybeHandle<Map>();
}
return handle(updated);
@@ -3907,15 +3909,18 @@ void JSObject::MigrateInstance(Handle<JSObject>
object) {
}
-Handle<Object> JSObject::TryMigrateInstance(Handle<JSObject> object) {
+// static
+bool JSObject::TryMigrateInstance(Handle<JSObject> object) {
Handle<Map> original_map(object->map());
- Handle<Map> new_map = Map::CurrentMapForDeprecatedInternal(original_map);
- if (new_map.is_null()) return Handle<Object>();
+ Handle<Map> 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;
}
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index
d926165c3e06e358ff595567f5ba58a175286743..b4015eef4ecbc9fd9ba8a15afd67da65b159cd06
100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -2308,8 +2308,8 @@ class JSObject: public JSReceiver {
static void MigrateInstance(Handle<JSObject> 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<Object> TryMigrateInstance(Handle<JSObject> instance);
+ // or returns false if such a map is not yet available.
+ static bool TryMigrateInstance(Handle<JSObject> instance);
// Retrieve a value in a normalized object given a lookup result.
// Handles the special representation of JS global objects.
@@ -6458,9 +6458,9 @@ 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<Map> CurrentMapForDeprecated(Handle<Map> map);
+ static MaybeHandle<Map> CurrentMapForDeprecated(Handle<Map> map);
// Same as above, but does not touch the prototype chain.
- static Handle<Map> CurrentMapForDeprecatedInternal(Handle<Map> map);
+ static MaybeHandle<Map> CurrentMapForDeprecatedInternal(Handle<Map> map);
static Handle<Map> CopyDropDescriptors(Handle<Map> map);
static Handle<Map> CopyInsertDescriptor(Handle<Map> map,
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index
c63a93885d631614cfa6c19058663f480b6693dc..611f432108bdfd3a2ba671e380a30c2e21458719
100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -14594,8 +14594,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<Object> result = JSObject::TryMigrateInstance(js_object);
- if (result.is_null()) return Smi::FromInt(0);
+ if (!JSObject::TryMigrateInstance(js_object)) return Smi::FromInt(0);
return *object;
}
Index: src/type-info.cc
diff --git a/src/type-info.cc b/src/type-info.cc
index
f863af0cd51797225379169201a0dcf17f2ce04e..0ba6dfa852e25118518e3c04273a41d7c02b563e
100644
--- a/src/type-info.cc
+++ b/src/type-info.cc
@@ -217,8 +217,8 @@ void TypeFeedbackOracle::CompareType(TypeFeedbackId id,
Handle<Map> 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<Map>::null();
}
}
--
--
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.