Commit e06ef53f authored by Marja Hölttä's avatar Marja Hölttä Committed by Commit Bot

[in-place weak refs] Migrate PrototypeInfo::weak_cell.

Currently it was only used for modules, so repurposed it to be a weak pointer to
JSModuleNamespace.

BUG=v8:7308

Change-Id: I4ef522fafebd37624c309081d7432501c2c69b7a
Reviewed-on: https://chromium-review.googlesource.com/1163704Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55013}
parent 84daf4a6
......@@ -428,10 +428,8 @@ bool AccessInfoFactory::ComputePropertyAccessInfo(
DCHECK(map->is_prototype_map());
Handle<PrototypeInfo> proto_info =
Map::GetOrCreatePrototypeInfo(map, isolate());
DCHECK(proto_info->weak_cell()->IsWeakCell());
Handle<JSModuleNamespace> module_namespace(
JSModuleNamespace::cast(
WeakCell::cast(proto_info->weak_cell())->value()),
JSModuleNamespace::cast(proto_info->module_namespace()),
isolate());
Handle<Cell> cell(
Cell::cast(module_namespace->module()->exports()->Lookup(
......
......@@ -209,6 +209,7 @@ Handle<PrototypeInfo> Factory::NewPrototypeInfo() {
result->set_prototype_users(*empty_weak_array_list());
result->set_registry_slot(PrototypeInfo::UNREGISTERED);
result->set_bit_field(0);
result->set_module_namespace(*undefined_value());
return result;
}
......
......@@ -1561,7 +1561,8 @@ void Module::ModuleVerify(Isolate* isolate) {
void PrototypeInfo::PrototypeInfoVerify(Isolate* isolate) {
CHECK(IsPrototypeInfo());
CHECK(weak_cell()->IsWeakCell() || weak_cell()->IsUndefined(isolate));
Object* module_ns = module_namespace();
CHECK(module_ns->IsJSModuleNamespace() || module_ns->IsUndefined(isolate));
if (prototype_users()->IsWeakArrayList()) {
PrototypeUsers::Verify(WeakArrayList::cast(prototype_users()));
} else {
......
......@@ -1683,7 +1683,7 @@ void JSModuleNamespace::JSModuleNamespacePrint(std::ostream& os) { // NOLINT
void PrototypeInfo::PrototypeInfoPrint(std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "PrototypeInfo");
os << "\n - weak cell: " << Brief(weak_cell());
os << "\n - module namespace: " << Brief(module_namespace());
os << "\n - prototype users: " << Brief(prototype_users());
os << "\n - registry slot: " << registry_slot();
os << "\n - object create map: " << MaybeObjectBrief(object_create_map());
......
......@@ -12912,30 +12912,6 @@ bool Map::IsPrototypeChainInvalidated(Map* map) {
return true;
}
// static
Handle<WeakCell> Map::GetOrCreatePrototypeWeakCell(Handle<JSReceiver> prototype,
Isolate* isolate) {
DCHECK(!prototype.is_null());
if (prototype->IsJSProxy()) {
Handle<WeakCell> cell = isolate->factory()->NewWeakCell(prototype);
return cell;
}
Handle<PrototypeInfo> proto_info =
GetOrCreatePrototypeInfo(Handle<JSObject>::cast(prototype), isolate);
Object* maybe_cell = proto_info->weak_cell();
// Return existing cell if it's already created.
if (maybe_cell->IsWeakCell()) {
Handle<WeakCell> cell(WeakCell::cast(maybe_cell), isolate);
DCHECK(!cell->cleared());
return cell;
}
// Otherwise create a new cell.
Handle<WeakCell> cell = isolate->factory()->NewWeakCell(prototype);
proto_info->set_weak_cell(*cell);
return cell;
}
// static
void Map::SetPrototype(Isolate* isolate, Handle<Map> map,
Handle<Object> prototype,
......
......@@ -448,11 +448,6 @@ class Map : public HeapObject {
// Return the map of the root of object's prototype chain.
Map* GetPrototypeChainRootMap(Isolate* isolate) const;
// Returns a WeakCell object containing given prototype. The cell is cached
// in PrototypeInfo which is created lazily.
static Handle<WeakCell> GetOrCreatePrototypeWeakCell(
Handle<JSReceiver> prototype, Isolate* isolate);
Map* FindRootMap(Isolate* isolate) const;
Map* FindFieldOwner(Isolate* isolate, int descriptor) const;
......
......@@ -900,7 +900,10 @@ Handle<JSModuleNamespace> Module::GetModuleNamespace(Isolate* isolate,
// - We can store a pointer from the map back to the namespace object.
// Turbofan can use this for inlining the access.
JSObject::OptimizeAsPrototype(ns);
Map::GetOrCreatePrototypeWeakCell(ns, isolate);
Handle<PrototypeInfo> proto_info =
Map::GetOrCreatePrototypeInfo(Handle<JSObject>::cast(ns), isolate);
proto_info->set_module_namespace(*ns);
return ns;
}
......
......@@ -34,7 +34,7 @@ bool PrototypeInfo::HasObjectCreateMap() {
return cache->IsWeakHeapObject();
}
ACCESSORS(PrototypeInfo, weak_cell, Object, kWeakCellOffset)
ACCESSORS(PrototypeInfo, module_namespace, Object, kJSModuleNamespaceOffset)
ACCESSORS(PrototypeInfo, prototype_users, Object, kPrototypeUsersOffset)
WEAK_ACCESSORS(PrototypeInfo, object_create_map, kObjectCreateMapOffset)
SMI_ACCESSORS(PrototypeInfo, registry_slot, kRegistrySlotOffset)
......
......@@ -19,8 +19,11 @@ class PrototypeInfo : public Struct {
public:
static const int UNREGISTERED = -1;
// [weak_cell]: A WeakCell containing this prototype. ICs cache the cell here.
DECL_ACCESSORS(weak_cell, Object)
// [module_namespace]: A backpointer to JSModuleNamespace from its
// PrototypeInfo (or undefined). This field is only used for JSModuleNamespace
// maps. TODO(jkummerow): Figure out if there's a way to store the namespace
// pointer elsewhere to save memory.
DECL_ACCESSORS(module_namespace, Object)
// [prototype_users]: WeakArrayList containing weak references to maps using
// this prototype, or Smi(0) if uninitialized.
......@@ -49,8 +52,9 @@ class PrototypeInfo : public Struct {
DECL_PRINTER(PrototypeInfo)
DECL_VERIFIER(PrototypeInfo)
static const int kWeakCellOffset = HeapObject::kHeaderSize;
static const int kPrototypeUsersOffset = kWeakCellOffset + kPointerSize;
static const int kJSModuleNamespaceOffset = HeapObject::kHeaderSize;
static const int kPrototypeUsersOffset =
kJSModuleNamespaceOffset + kPointerSize;
static const int kRegistrySlotOffset = kPrototypeUsersOffset + kPointerSize;
static const int kValidityCellOffset = kRegistrySlotOffset + kPointerSize;
static const int kObjectCreateMapOffset = kValidityCellOffset + kPointerSize;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment