Skip to content

Commit

Permalink
[in-place weak refs] Migrate PrototypeInfo::weak_cell.
Browse files Browse the repository at this point in the history
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/1163704
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55013}
  • Loading branch information
marjakh authored and Commit Bot committed Aug 9, 2018
1 parent 84daf4a commit e06ef53
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 40 deletions.
4 changes: 1 addition & 3 deletions src/compiler/access-info.cc
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/heap/factory.cc
Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/objects-debug.cc
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/objects-printer.cc
Expand Up @@ -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());
Expand Down
24 changes: 0 additions & 24 deletions src/objects.cc
Expand Up @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions src/objects/map.h
Expand Up @@ -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;

Expand Down
5 changes: 4 additions & 1 deletion src/objects/module.cc
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/objects/prototype-info-inl.h
Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions src/objects/prototype-info.h
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e06ef53

Please sign in to comment.