Commit 589906ab authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

[turbofan] Serialize modules.

Bug: v8:7790
Change-Id: I7f66333d43b057746e279851010681c4ecd36ba1
Reviewed-on: https://chromium-review.googlesource.com/1215626Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55771}
parent 3cfaca63
......@@ -4,6 +4,7 @@
#include "src/compiler/js-heap-broker.h"
#include "src/ast/modules.h"
#include "src/boxed-float.h"
#include "src/code-factory.h"
#include "src/compiler/graph-reducer.h"
......@@ -751,10 +752,67 @@ class SharedFunctionInfoData : public HeapObjectData {
class ModuleData : public HeapObjectData {
public:
ModuleData(JSHeapBroker* broker, Handle<Module> object, HeapObjectType type)
: HeapObjectData(broker, object, type) {}
ModuleData(JSHeapBroker* broker, Handle<Module> object, HeapObjectType type);
void Serialize();
CellData* GetCell(int cell_index) const;
private:
bool serialized_ = false;
ZoneVector<CellData*> imports_;
ZoneVector<CellData*> exports_;
};
ModuleData::ModuleData(JSHeapBroker* broker, Handle<Module> object,
HeapObjectType type)
: HeapObjectData(broker, object, type),
imports_(broker->zone()),
exports_(broker->zone()) {}
CellData* ModuleData::GetCell(int cell_index) const {
CHECK(serialized_);
CellData* cell;
switch (ModuleDescriptor::GetCellIndexKind(cell_index)) {
case ModuleDescriptor::kImport:
cell = imports_.at(Module::ImportIndex(cell_index));
break;
case ModuleDescriptor::kExport:
cell = exports_.at(Module::ExportIndex(cell_index));
break;
case ModuleDescriptor::kInvalid:
UNREACHABLE();
break;
}
CHECK_NOT_NULL(cell);
return cell;
}
void ModuleData::Serialize() {
if (serialized_) return;
serialized_ = true;
Handle<Module> module = Handle<Module>::cast(object());
// TODO(neis): We could be smarter and only serialize the cells we care about.
// TODO(neis): Define a helper for serializing a FixedArray into a ZoneVector.
DCHECK(imports_.empty());
Handle<FixedArray> imports(module->regular_imports(), broker()->isolate());
int const imports_length = imports->length();
imports_.reserve(imports_length);
for (int i = 0; i < imports_length; ++i) {
imports_.push_back(broker()->GetOrCreateData(imports->get(i))->AsCell());
}
DCHECK(exports_.empty());
Handle<FixedArray> exports(module->regular_exports(), broker()->isolate());
int const exports_length = exports->length();
exports_.reserve(exports_length);
for (int i = 0; i < exports_length; ++i) {
exports_.push_back(broker()->GetOrCreateData(exports->get(i))->AsCell());
}
}
class CellData : public HeapObjectData {
public:
CellData(JSHeapBroker* broker, Handle<Cell> object, HeapObjectType type)
......@@ -1669,11 +1727,14 @@ double MutableHeapNumberRef::value() const {
return data()->AsMutableHeapNumber()->value();
}
CellRef ModuleRef::GetCell(int cell_index) {
CellRef ModuleRef::GetCell(int cell_index) const {
if (broker()->mode() == JSHeapBroker::kDisabled) {
AllowHandleAllocation handle_allocation;
AllowHandleDereference allow_handle_dereference;
return CellRef(broker(), handle(object<Module>()->GetCell(cell_index),
broker()->isolate()));
}
return CellRef(data()->AsModule()->GetCell(cell_index));
}
ObjectRef::ObjectRef(JSHeapBroker* broker, Handle<Object> object) {
......@@ -1818,6 +1879,12 @@ void MapRef::SerializeDescriptors() {
data()->AsMap()->SerializeDescriptors();
}
void ModuleRef::Serialize() {
if (broker()->mode() == JSHeapBroker::kDisabled) return;
CHECK_EQ(broker()->mode(), JSHeapBroker::kSerializing);
data()->AsModule()->Serialize();
}
#undef BIMODAL_ACCESSOR
#undef BIMODAL_ACCESSOR_B
#undef BIMODAL_ACCESSOR_C
......
......@@ -422,7 +422,9 @@ class ModuleRef : public HeapObjectRef {
public:
using HeapObjectRef::HeapObjectRef;
CellRef GetCell(int cell_index);
void Serialize();
CellRef GetCell(int cell_index) const;
};
class CellRef : public HeapObjectRef {
......
......@@ -28,6 +28,7 @@ Reduction JSHeapCopyReducer::Reduce(Node* node) {
case IrOpcode::kHeapConstant: {
ObjectRef object(broker(), HeapConstantOf(node->op()));
if (object.IsJSFunction()) object.AsJSFunction().Serialize();
if (object.IsModule()) object.AsModule().Serialize();
break;
}
case IrOpcode::kJSCreateArray: {
......
......@@ -106,22 +106,18 @@ class Module::ResolveSet
Zone* zone_;
};
namespace {
int ExportIndex(int cell_index) {
int Module::ExportIndex(int cell_index) {
DCHECK_EQ(ModuleDescriptor::GetCellIndexKind(cell_index),
ModuleDescriptor::kExport);
return cell_index - 1;
}
int ImportIndex(int cell_index) {
int Module::ImportIndex(int cell_index) {
DCHECK_EQ(ModuleDescriptor::GetCellIndexKind(cell_index),
ModuleDescriptor::kImport);
return -cell_index - 1;
}
} // anonymous namespace
void Module::CreateIndirectExport(Isolate* isolate, Handle<Module> module,
Handle<String> name,
Handle<ModuleInfoEntry> entry) {
......
......@@ -111,6 +111,9 @@ class Module : public Struct, public NeverReadOnlySpaceObject {
static void StoreVariable(Handle<Module> module, int cell_index,
Handle<Object> value);
static int ImportIndex(int cell_index);
static int ExportIndex(int cell_index);
// Get the namespace object for [module_request] of [module]. If it doesn't
// exist yet, it is created.
static Handle<JSModuleNamespace> GetModuleNamespace(Isolate* isolate,
......
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