Commit b3c38223 authored by Maya Lekova's avatar Maya Lekova Committed by Commit Bot

Revert "[offthread] Add SFI support to OffThreadFactory"

This reverts commit 453e1a3b.

Reason for revert: Makes UBSan unhappy - https://ci.chromium.org/p/v8/builders/ci/V8%20Linux64%20UBSan/9893

Original change's description:
> [offthread] Add SFI support to OffThreadFactory
> 
> Add support for off-thread SharedFunctionInfo allocation, which
> includes UncompiledData and PreparseData allocation.
> 
> Bug: chromium:1011762
> Change-Id: Ia10f9ce762c7d7eb1108b9e71da75131dce919b7
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2050393
> Commit-Queue: Leszek Swirski <leszeks@chromium.org>
> Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> Reviewed-by: Igor Sheludko <ishell@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#66246}

TBR=ulan@chromium.org,leszeks@chromium.org,ishell@chromium.org

Change-Id: I26bc40ec1c351613f19745aed83f0c3a9fdd9a20
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: chromium:1011762
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2052172Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Commit-Queue: Maya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66247}
parent 453e1a3b
......@@ -15,7 +15,6 @@
#include "src/codegen/label.h"
#include "src/common/globals.h"
#include "src/execution/isolate.h"
#include "src/execution/off-thread-isolate.h"
#include "src/heap/factory.h"
#include "src/objects/elements-kind.h"
#include "src/objects/function-syntax-kind.h"
......@@ -2209,10 +2208,8 @@ class FunctionLiteral final : public Expression {
// Empty handle means that the function does not have a shared name (i.e.
// the name will be set dynamically after creation of the function closure).
template <typename Isolate>
MaybeHandleFor<Isolate, String> GetName(Isolate* isolate) const {
return raw_name_ ? raw_name_->AllocateFlat(isolate)
: MaybeHandleFor<Isolate, String>();
MaybeHandle<String> GetName(Isolate* isolate) const {
return raw_name_ ? raw_name_->AllocateFlat(isolate) : MaybeHandle<String>();
}
bool has_shared_name() const { return raw_name_ != nullptr; }
const AstConsString* raw_name() const { return raw_name_; }
......@@ -2280,11 +2277,6 @@ class FunctionLiteral final : public Expression {
}
UNREACHABLE();
}
OffThreadHandle<String> GetInferredName(OffThreadIsolate* isolate) const {
DCHECK(inferred_name_.is_null());
DCHECK_NOT_NULL(raw_inferred_name_);
return raw_inferred_name_->GetString(isolate);
}
const AstConsString* raw_inferred_name() { return raw_inferred_name_; }
// Only one of {set_inferred_name, set_raw_inferred_name} should be called.
......
......@@ -32,7 +32,6 @@
#include "src/objects/js-array-inl.h"
#include "src/objects/layout-descriptor.h"
#include "src/objects/objects-inl.h"
#include "src/roots/roots.h"
#ifdef V8_INTL_SUPPORT
#include "src/objects/js-break-iterator-inl.h"
#include "src/objects/js-collator-inl.h"
......@@ -817,20 +816,12 @@ void JSFunction::JSFunctionVerify(Isolate* isolate) {
}
void SharedFunctionInfo::SharedFunctionInfoVerify(Isolate* isolate) {
// TODO(leszeks): Add a TorqueGeneratedClassVerifier for OffThreadIsolate.
TorqueGeneratedClassVerifiers::SharedFunctionInfoVerify(*this, isolate);
this->SharedFunctionInfoVerify(ReadOnlyRoots(isolate));
}
void SharedFunctionInfo::SharedFunctionInfoVerify(OffThreadIsolate* isolate) {
this->SharedFunctionInfoVerify(ReadOnlyRoots(isolate));
}
void SharedFunctionInfo::SharedFunctionInfoVerify(ReadOnlyRoots roots) {
Object value = name_or_scope_info();
if (value.IsScopeInfo()) {
CHECK_LT(0, ScopeInfo::cast(value).length());
CHECK_NE(value, roots.empty_scope_info());
CHECK_NE(value, ReadOnlyRoots(isolate).empty_scope_info());
}
CHECK(HasWasmExportedFunctionData() || IsApiFunction() ||
......@@ -839,13 +830,13 @@ void SharedFunctionInfo::SharedFunctionInfoVerify(ReadOnlyRoots roots) {
HasUncompiledDataWithoutPreparseData() || HasWasmJSFunctionData() ||
HasWasmCapiFunctionData());
CHECK(script_or_debug_info().IsUndefined(roots) ||
CHECK(script_or_debug_info().IsUndefined(isolate) ||
script_or_debug_info().IsScript() || HasDebugInfo());
if (!is_compiled()) {
CHECK(!HasFeedbackMetadata());
CHECK(outer_scope_info().IsScopeInfo() ||
outer_scope_info().IsTheHole(roots));
outer_scope_info().IsTheHole(isolate));
} else if (HasBytecodeArray() && HasFeedbackMetadata()) {
CHECK(feedback_metadata().IsFeedbackMetadata());
}
......
......@@ -1290,19 +1290,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
int GetNextScriptId();
#if V8_SFI_HAS_UNIQUE_ID
int GetNextUniqueSharedFunctionInfoId() {
int current_id = next_unique_sfi_id_.load(std::memory_order_relaxed);
int next_id;
do {
if (current_id >= Smi::kMaxValue) {
next_id = 0;
} else {
next_id = current_id + 1;
}
} while (!next_unique_sfi_id_.compare_exchange_weak(
current_id, next_id, std::memory_order_relaxed));
return current_id;
}
int GetNextUniqueSharedFunctionInfoId() { return next_unique_sfi_id_++; }
#endif
Address promise_hook_address() {
......@@ -1777,7 +1765,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
int next_optimization_id_ = 0;
#if V8_SFI_HAS_UNIQUE_ID
std::atomic<int> next_unique_sfi_id_;
int next_unique_sfi_id_ = 0;
#endif
// Vector of callbacks before a Call starts execution.
......
......@@ -18,12 +18,6 @@ OffThreadIsolate::~OffThreadIsolate() { delete logger_; }
int OffThreadIsolate::GetNextScriptId() { return isolate_->GetNextScriptId(); }
#if V8_SFI_HAS_UNIQUE_ID
int OffThreadIsolate::GetNextUniqueSharedFunctionInfoId() {
return isolate_->GetNextUniqueSharedFunctionInfoId();
}
#endif // V8_SFI_HAS_UNIQUE_ID
bool OffThreadIsolate::NeedsSourcePositionsForProfiling() {
// TODO(leszeks): Figure out if it makes sense to check this asynchronously.
return isolate_->NeedsSourcePositionsForProfiling();
......
......@@ -61,9 +61,6 @@ class V8_EXPORT_PRIVATE OffThreadIsolate final
}
int GetNextScriptId();
#if V8_SFI_HAS_UNIQUE_ID
int GetNextUniqueSharedFunctionInfoId();
#endif // V8_SFI_HAS_UNIQUE_ID
bool NeedsSourcePositionsForProfiling();
bool is_collecting_type_profile();
......
......@@ -233,7 +233,7 @@ class OffThreadHandle {
}
private:
Address address_ = 0;
Address address_;
};
// A helper class which wraps an normal or off-thread handle, and returns one
......
......@@ -114,35 +114,6 @@ HandleFor<Impl, FixedArrayBase> FactoryBase<Impl>::NewFixedDoubleArray(
return array;
}
template <typename Impl>
HandleFor<Impl, WeakFixedArray> FactoryBase<Impl>::NewWeakFixedArrayWithMap(
Map map, int length, AllocationType allocation) {
// Zero-length case must be handled outside.
DCHECK_LT(0, length);
DCHECK(ReadOnlyHeap::Contains(map));
HeapObject result =
AllocateRawArray(WeakFixedArray::SizeFor(length), allocation);
result.set_map_after_allocation(map, SKIP_WRITE_BARRIER);
HandleFor<Impl, WeakFixedArray> array =
handle(WeakFixedArray::cast(result), isolate());
array->set_length(length);
MemsetTagged(ObjectSlot(array->data_start()),
read_only_roots().undefined_value(), length);
return array;
}
template <typename Impl>
HandleFor<Impl, WeakFixedArray> FactoryBase<Impl>::NewWeakFixedArray(
int length, AllocationType allocation) {
DCHECK_LE(0, length);
if (length == 0) return impl()->empty_weak_fixed_array();
return NewWeakFixedArrayWithMap(read_only_roots().weak_fixed_array_map(),
length, allocation);
}
template <typename Impl>
HandleFor<Impl, Script> FactoryBase<Impl>::NewScript(
HandleFor<Impl, String> source) {
......@@ -177,111 +148,6 @@ HandleFor<Impl, Script> FactoryBase<Impl>::NewScriptWithId(
return script;
}
template <typename Impl>
HandleFor<Impl, SharedFunctionInfo>
FactoryBase<Impl>::NewSharedFunctionInfoForLiteral(
FunctionLiteral* literal, HandleFor<Impl, Script> script,
bool is_toplevel) {
FunctionKind kind = literal->kind();
HandleFor<Impl, SharedFunctionInfo> shared = NewSharedFunctionInfo(
literal->GetName(isolate()), MaybeHandleFor<Impl, Code>(),
Builtins::kCompileLazy, kind);
SharedFunctionInfo::InitFromFunctionLiteral(isolate(), shared, literal,
is_toplevel);
shared->SetScript(read_only_roots(), *script, literal->function_literal_id(),
false);
return shared;
}
template <typename Impl>
HandleFor<Impl, PreparseData> FactoryBase<Impl>::NewPreparseData(
int data_length, int children_length) {
int size = PreparseData::SizeFor(data_length, children_length);
HandleFor<Impl, PreparseData> result = handle(
PreparseData::cast(AllocateRawWithImmortalMap(
size, AllocationType::kOld, read_only_roots().preparse_data_map())),
isolate());
result->set_data_length(data_length);
result->set_children_length(children_length);
MemsetTagged(result->inner_data_start(), read_only_roots().null_value(),
children_length);
result->clear_padding();
return result;
}
template <typename Impl>
HandleFor<Impl, UncompiledDataWithoutPreparseData>
FactoryBase<Impl>::NewUncompiledDataWithoutPreparseData(
HandleFor<Impl, String> inferred_name, int32_t start_position,
int32_t end_position) {
HandleFor<Impl, UncompiledDataWithoutPreparseData> result = handle(
UncompiledDataWithoutPreparseData::cast(NewWithImmortalMap(
impl()->read_only_roots().uncompiled_data_without_preparse_data_map(),
AllocationType::kOld)),
isolate());
result->Init(impl(), *inferred_name, start_position, end_position);
return result;
}
template <typename Impl>
HandleFor<Impl, UncompiledDataWithPreparseData>
FactoryBase<Impl>::NewUncompiledDataWithPreparseData(
HandleFor<Impl, String> inferred_name, int32_t start_position,
int32_t end_position, HandleFor<Impl, PreparseData> preparse_data) {
HandleFor<Impl, UncompiledDataWithPreparseData> result = handle(
UncompiledDataWithPreparseData::cast(NewWithImmortalMap(
impl()->read_only_roots().uncompiled_data_with_preparse_data_map(),
AllocationType::kOld)),
isolate());
result->Init(impl(), *inferred_name, start_position, end_position,
*preparse_data);
return result;
}
template <typename Impl>
HandleFor<Impl, SharedFunctionInfo> FactoryBase<Impl>::NewSharedFunctionInfo(
MaybeHandleFor<Impl, String> maybe_name,
MaybeHandleFor<Impl, HeapObject> maybe_function_data,
int maybe_builtin_index, FunctionKind kind) {
HandleFor<Impl, SharedFunctionInfo> shared = NewSharedFunctionInfo();
// Function names are assumed to be flat elsewhere.
HandleFor<Impl, String> shared_name;
bool has_shared_name = maybe_name.ToHandle(&shared_name);
if (has_shared_name) {
DCHECK(shared_name->IsFlat());
shared->set_name_or_scope_info(*shared_name);
} else {
DCHECK_EQ(shared->name_or_scope_info(),
SharedFunctionInfo::kNoSharedNameSentinel);
}
HandleFor<Impl, HeapObject> function_data;
if (maybe_function_data.ToHandle(&function_data)) {
// If we pass function_data then we shouldn't pass a builtin index, and
// the function_data should not be code with a builtin.
DCHECK(!Builtins::IsBuiltinId(maybe_builtin_index));
DCHECK_IMPLIES(function_data->IsCode(),
!Code::cast(*function_data).is_builtin());
shared->set_function_data(*function_data);
} else if (Builtins::IsBuiltinId(maybe_builtin_index)) {
shared->set_builtin_id(maybe_builtin_index);
} else {
shared->set_builtin_id(Builtins::kIllegal);
}
shared->CalculateConstructAsBuiltin();
shared->set_kind(kind);
#ifdef VERIFY_HEAP
shared->SharedFunctionInfoVerify(isolate());
#endif // VERIFY_HEAP
return shared;
}
template <typename Impl>
HandleFor<Impl, ObjectBoilerplateDescription>
FactoryBase<Impl>::NewObjectBoilerplateDescription(int boilerplate,
......@@ -537,26 +403,6 @@ FactoryBase<Impl>::NewSourceTextModuleInfo() {
AllocationType::kOld));
}
template <typename Impl>
HandleFor<Impl, SharedFunctionInfo> FactoryBase<Impl>::NewSharedFunctionInfo() {
Map map = read_only_roots().shared_function_info_map();
HandleFor<Impl, SharedFunctionInfo> shared = handle(
SharedFunctionInfo::cast(NewWithImmortalMap(map, AllocationType::kOld)),
isolate());
int unique_id = -1;
#if V8_SFI_HAS_UNIQUE_ID
unique_id = isolate()->GetNextUniqueSharedFunctionInfoId();
#endif // V8_SFI_HAS_UNIQUE_ID
shared->Init(read_only_roots(), unique_id);
#ifdef VERIFY_HEAP
shared->SharedFunctionInfoVerify(isolate());
#endif // VERIFY_HEAP
return shared;
}
template <typename Impl>
HandleFor<Impl, SeqOneByteString>
FactoryBase<Impl>::AllocateRawOneByteInternalizedString(int length,
......
......@@ -8,7 +8,6 @@
#include "src/base/export-template.h"
#include "src/common/globals.h"
#include "src/handles/handle-for.h"
#include "src/objects/function-kind.h"
#include "src/objects/instance-type.h"
#include "src/roots/roots.h"
......@@ -16,8 +15,6 @@ namespace v8 {
namespace internal {
class HeapObject;
class SharedFunctionInfo;
class FunctionLiteral;
class SeqOneByteString;
class SeqTwoByteString;
class FreshlyAllocatedBigInt;
......@@ -25,9 +22,6 @@ class ObjectBoilerplateDescription;
class ArrayBoilerplateDescription;
class TemplateObjectDescription;
class SourceTextModuleInfo;
class PreparseData;
class UncompiledDataWithoutPreparseData;
class UncompiledDataWithPreparseData;
template <typename Impl>
class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) FactoryBase {
......@@ -79,16 +73,6 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) FactoryBase {
HandleFor<Impl, FixedArrayBase> NewFixedDoubleArray(
int length, AllocationType allocation = AllocationType::kYoung);
// Allocates a weak fixed array-like object with given map and initialized
// with undefined values.
HandleFor<Impl, WeakFixedArray> NewWeakFixedArrayWithMap(
Map map, int length, AllocationType allocation = AllocationType::kYoung);
// Allocates a fixed array which may contain in-place weak references. The
// array is initialized with undefined values
HandleFor<Impl, WeakFixedArray> NewWeakFixedArray(
int length, AllocationType allocation = AllocationType::kYoung);
// Allocates a fixed array for name-value pairs of boilerplate properties and
// calculates the number of properties we need to store in the backing store.
HandleFor<Impl, ObjectBoilerplateDescription> NewObjectBoilerplateDescription(
......@@ -108,24 +92,6 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) FactoryBase {
HandleFor<Impl, Script> NewScriptWithId(HandleFor<Impl, String> source,
int script_id);
HandleFor<Impl, SharedFunctionInfo> NewSharedFunctionInfoForLiteral(
FunctionLiteral* literal, HandleFor<Impl, Script> script,
bool is_toplevel);
HandleFor<Impl, PreparseData> NewPreparseData(int data_length,
int children_length);
HandleFor<Impl, UncompiledDataWithoutPreparseData>
NewUncompiledDataWithoutPreparseData(HandleFor<Impl, String> inferred_name,
int32_t start_position,
int32_t end_position);
HandleFor<Impl, UncompiledDataWithPreparseData>
NewUncompiledDataWithPreparseData(HandleFor<Impl, String> inferred_name,
int32_t start_position,
int32_t end_position,
HandleFor<Impl, PreparseData>);
HandleFor<Impl, SeqOneByteString> NewOneByteInternalizedString(
const Vector<const uint8_t>& str, uint32_t hash_field);
HandleFor<Impl, SeqTwoByteString> NewTwoByteInternalizedString(
......@@ -179,12 +145,6 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) FactoryBase {
HandleFor<Impl, FixedArray> NewFixedArrayWithFiller(
Map map, int length, Oddball filler, AllocationType allocation);
HandleFor<Impl, SharedFunctionInfo> NewSharedFunctionInfo();
HandleFor<Impl, SharedFunctionInfo> NewSharedFunctionInfo(
MaybeHandleFor<Impl, String> maybe_name,
MaybeHandleFor<Impl, HeapObject> maybe_function_data,
int maybe_builtin_index, FunctionKind kind = kNormalFunction);
private:
Impl* impl() { return static_cast<Impl*>(this); }
auto isolate() { return impl()->isolate(); }
......
......@@ -10,6 +10,7 @@
#include <utility> // For move
#include "src/ast/ast-source-ranges.h"
#include "src/ast/ast.h"
#include "src/base/bits.h"
#include "src/builtins/accessors.h"
#include "src/builtins/constants-table-builder.h"
......@@ -340,6 +341,40 @@ Handle<FixedArray> Factory::NewFixedArrayWithMapRootIndex(
length, allocation);
}
template <typename T>
Handle<T> Factory::NewWeakFixedArrayWithMap(Map map, int length,
AllocationType allocation) {
static_assert(std::is_base_of<WeakFixedArray, T>::value,
"T must be a descendant of WeakFixedArray");
// Zero-length case must be handled outside.
DCHECK_LT(0, length);
HeapObject result =
AllocateRawArray(WeakFixedArray::SizeFor(length), AllocationType::kOld);
result.set_map_after_allocation(map, SKIP_WRITE_BARRIER);
Handle<WeakFixedArray> array(WeakFixedArray::cast(result), isolate());
array->set_length(length);
MemsetTagged(ObjectSlot(array->data_start()), *undefined_value(), length);
return Handle<T>::cast(array);
}
Handle<WeakFixedArray> Factory::NewWeakFixedArray(int length,
AllocationType allocation) {
DCHECK_LE(0, length);
if (length == 0) return empty_weak_fixed_array();
HeapObject result =
AllocateRawArray(WeakFixedArray::SizeFor(length), allocation);
result.set_map_after_allocation(read_only_roots().weak_fixed_array_map(),
SKIP_WRITE_BARRIER);
Handle<WeakFixedArray> array(WeakFixedArray::cast(result), isolate());
array->set_length(length);
MemsetTagged(ObjectSlot(array->data_start()), *undefined_value(), length);
return array;
}
MaybeHandle<FixedArray> Factory::TryNewFixedArray(
int length, AllocationType allocation_type) {
DCHECK_LE(0, length);
......@@ -1447,9 +1482,8 @@ Handle<DescriptorArray> Factory::NewDescriptorArray(int number_of_descriptors,
Handle<TransitionArray> Factory::NewTransitionArray(int number_of_transitions,
int slack) {
int capacity = TransitionArray::LengthFor(number_of_transitions + slack);
Handle<TransitionArray> array = Handle<TransitionArray>::cast(
NewWeakFixedArrayWithMap(read_only_roots().transition_array_map(),
capacity, AllocationType::kOld));
Handle<TransitionArray> array = NewWeakFixedArrayWithMap<TransitionArray>(
read_only_roots().transition_array_map(), capacity, AllocationType::kOld);
// Transition arrays are AllocationType::kOld. When black allocation is on we
// have to add the transition array to the list of
// encountered_transition_arrays.
......@@ -2096,6 +2130,48 @@ Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
return result;
}
Handle<PreparseData> Factory::NewPreparseData(int data_length,
int children_length) {
int size = PreparseData::SizeFor(data_length, children_length);
Handle<PreparseData> result(
PreparseData::cast(AllocateRawWithImmortalMap(size, AllocationType::kOld,
*preparse_data_map())),
isolate());
result->set_data_length(data_length);
result->set_children_length(children_length);
MemsetTagged(result->inner_data_start(), *null_value(), children_length);
result->clear_padding();
return result;
}
Handle<UncompiledDataWithoutPreparseData>
Factory::NewUncompiledDataWithoutPreparseData(Handle<String> inferred_name,
int32_t start_position,
int32_t end_position) {
Handle<UncompiledDataWithoutPreparseData> result(
UncompiledDataWithoutPreparseData::cast(New(
uncompiled_data_without_preparse_data_map(), AllocationType::kOld)),
isolate());
result->Init(*inferred_name, start_position, end_position);
return result;
}
Handle<UncompiledDataWithPreparseData>
Factory::NewUncompiledDataWithPreparseData(Handle<String> inferred_name,
int32_t start_position,
int32_t end_position,
Handle<PreparseData> preparse_data) {
Handle<UncompiledDataWithPreparseData> result(
UncompiledDataWithPreparseData::cast(
New(uncompiled_data_with_preparse_data_map(), AllocationType::kOld)),
isolate());
result->Init(*inferred_name, start_position, end_position, *preparse_data);
return result;
}
Handle<JSObject> Factory::NewExternal(void* value) {
Handle<Foreign> foreign = NewForeign(reinterpret_cast<Address>(value));
Handle<JSObject> external = NewJSObjectFromMap(external_map());
......@@ -2889,6 +2965,18 @@ void Factory::ReinitializeJSGlobalProxy(Handle<JSGlobalProxy> object,
InitializeJSObjectFromMap(object, raw_properties_or_hash, map);
}
Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfoForLiteral(
FunctionLiteral* literal, Handle<Script> script, bool is_toplevel) {
FunctionKind kind = literal->kind();
Handle<SharedFunctionInfo> shared = NewSharedFunctionInfoForBuiltin(
literal->GetName(isolate()), Builtins::kCompileLazy, kind);
SharedFunctionInfo::InitFromFunctionLiteral(isolate(), shared, literal,
is_toplevel);
shared->SetScript(ReadOnlyRoots(isolate()), *script,
literal->function_literal_id(), false);
return shared;
}
Handle<JSMessageObject> Factory::NewJSMessageObject(
MessageTemplate message, Handle<Object> argument, int start_position,
int end_position, Handle<SharedFunctionInfo> shared_info,
......@@ -2948,6 +3036,64 @@ Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfoForBuiltin(
return shared;
}
Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
MaybeHandle<String> maybe_name, MaybeHandle<HeapObject> maybe_function_data,
int maybe_builtin_index, FunctionKind kind) {
Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo();
// Function names are assumed to be flat elsewhere. Must flatten before
// allocating SharedFunctionInfo to avoid GC seeing the uninitialized SFI.
Handle<String> shared_name;
bool has_shared_name = maybe_name.ToHandle(&shared_name);
if (has_shared_name) {
DCHECK(shared_name->IsFlat());
shared->set_name_or_scope_info(*shared_name);
} else {
DCHECK_EQ(shared->name_or_scope_info(),
SharedFunctionInfo::kNoSharedNameSentinel);
}
Handle<HeapObject> function_data;
if (maybe_function_data.ToHandle(&function_data)) {
// If we pass function_data then we shouldn't pass a builtin index, and
// the function_data should not be code with a builtin.
DCHECK(!Builtins::IsBuiltinId(maybe_builtin_index));
DCHECK_IMPLIES(function_data->IsCode(),
!Code::cast(*function_data).is_builtin());
shared->set_function_data(*function_data);
} else if (Builtins::IsBuiltinId(maybe_builtin_index)) {
shared->set_builtin_id(maybe_builtin_index);
} else {
shared->set_builtin_id(Builtins::kIllegal);
}
shared->CalculateConstructAsBuiltin();
shared->set_kind(kind);
#ifdef VERIFY_HEAP
shared->SharedFunctionInfoVerify(isolate());
#endif // VERIFY_HEAP
return shared;
}
Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo() {
Handle<Map> map = shared_function_info_map();
Handle<SharedFunctionInfo> shared(
SharedFunctionInfo::cast(New(map, AllocationType::kOld)), isolate());
int unique_id = -1;
#if V8_SFI_HAS_UNIQUE_ID
unique_id = isolate()->GetNextUniqueSharedFunctionInfoId();
#endif // V8_SFI_HAS_UNIQUE_ID
shared->Init(ReadOnlyRoots(isolate()), unique_id);
#ifdef VERIFY_HEAP
shared->SharedFunctionInfoVerify(isolate());
#endif // VERIFY_HEAP
return shared;
}
namespace {
inline int NumberToStringCacheHash(Handle<FixedArray> cache, Smi number) {
int mask = (cache->length() >> 1) - 1;
......
......@@ -16,6 +16,7 @@
#include "src/heap/heap.h"
#include "src/objects/code.h"
#include "src/objects/dictionary.h"
#include "src/objects/function-kind.h"
#include "src/objects/js-array.h"
#include "src/objects/js-regexp.h"
#include "src/objects/string.h"
......@@ -54,6 +55,7 @@ class JSWeakMap;
class LoadHandler;
class NativeContext;
class NewFunctionArgs;
class PreparseData;
class PromiseResolveThenableJobTask;
class RegExpMatchInfo;
class ScriptContextTable;
......@@ -63,6 +65,8 @@ class StackTraceFrame;
class StoreHandler;
class SyntheticModule;
class TemplateObjectDescription;
class UncompiledDataWithoutPreparseData;
class UncompiledDataWithPreparseData;
class WasmCapiFunctionData;
class WasmExportedFunctionData;
class WasmJSFunctionData;
......@@ -130,6 +134,17 @@ class V8_EXPORT_PRIVATE Factory : public FactoryBase<Factory> {
RootIndex map_root_index, int length,
AllocationType allocation = AllocationType::kYoung);
// Allocates a weak fixed array-like object with given map and initialized
// with undefined values.
template <typename T = WeakFixedArray>
Handle<T> NewWeakFixedArrayWithMap(
Map map, int length, AllocationType allocation = AllocationType::kYoung);
// Allocates a fixed array which may contain in-place weak references. The
// array is initialized with undefined values
Handle<WeakFixedArray> NewWeakFixedArray(
int length, AllocationType allocation = AllocationType::kYoung);
// Allocates a property array initialized with undefined values.
Handle<PropertyArray> NewPropertyArray(int length);
// Tries allocating a fixed array initialized with undefined values.
......@@ -659,6 +674,17 @@ class V8_EXPORT_PRIVATE Factory : public FactoryBase<Factory> {
Handle<Map> map, Handle<SharedFunctionInfo> info, Handle<Context> context,
AllocationType allocation = AllocationType::kOld);
Handle<PreparseData> NewPreparseData(int data_length, int children_length);
Handle<UncompiledDataWithoutPreparseData>
NewUncompiledDataWithoutPreparseData(Handle<String> inferred_name,
int32_t start_position,
int32_t end_position);
Handle<UncompiledDataWithPreparseData> NewUncompiledDataWithPreparseData(
Handle<String> inferred_name, int32_t start_position,
int32_t end_position, Handle<PreparseData>);
// Create an External object for V8's external API.
Handle<JSObject> NewExternal(void* value);
......@@ -732,6 +758,9 @@ class V8_EXPORT_PRIVATE Factory : public FactoryBase<Factory> {
MaybeHandle<String> name, int builtin_index,
FunctionKind kind = kNormalFunction);
Handle<SharedFunctionInfo> NewSharedFunctionInfoForLiteral(
FunctionLiteral* literal, Handle<Script> script, bool is_toplevel);
static bool IsFunctionModeWithPrototype(FunctionMode function_mode) {
return (function_mode & kWithPrototypeBits) != 0;
}
......@@ -980,6 +1009,11 @@ class V8_EXPORT_PRIVATE Factory : public FactoryBase<Factory> {
ElementsKind elements_kind, int capacity,
ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS);
Handle<SharedFunctionInfo> NewSharedFunctionInfo();
Handle<SharedFunctionInfo> NewSharedFunctionInfo(
MaybeHandle<String> name, MaybeHandle<HeapObject> maybe_function_data,
int maybe_builtin_index, FunctionKind kind = kNormalFunction);
void InitializeAllocationMemento(AllocationMemento memento,
AllocationSite allocation_site);
......
......@@ -2217,7 +2217,7 @@ void MarkCompactCollector::FlushBytecodeFromSFI(
// Initialize the uncompiled data.
UncompiledData uncompiled_data = UncompiledData::cast(compiled_data);
uncompiled_data.InitAfterBytecodeFlush(
uncompiled_data.Init(
inferred_name, start_position, end_position,
[](HeapObject object, ObjectSlot slot, HeapObject target) {
RecordSlot(object, slot, target);
......
......@@ -16,7 +16,6 @@
#include "src/objects/heap-object.h"
#include "src/objects/map-inl.h"
#include "src/objects/objects-body-descriptors-inl.h"
#include "src/objects/shared-function-info.h"
#include "src/objects/string.h"
#include "src/objects/visitors.h"
#include "src/roots/roots-inl.h"
......
......@@ -17,7 +17,6 @@
#include "src/objects/heap-object.h"
#include "src/objects/map.h"
#include "src/objects/objects.h"
#include "src/objects/shared-function-info.h"
#include "src/roots/roots.h"
namespace v8 {
......
......@@ -37,8 +37,7 @@ void FreeSpace::set_next(FreeSpace next) {
}
FreeSpace FreeSpace::cast(HeapObject o) {
SLOW_DCHECK((!Heap::InOffThreadSpace(o) &&
!GetHeapFromWritableObject(o)->deserialization_complete()) ||
SLOW_DCHECK(!GetHeapFromWritableObject(o)->deserialization_complete() ||
o.IsFreeSpace());
return bit_cast<FreeSpace>(o);
}
......
......@@ -33,7 +33,6 @@
#include "src/execution/frames-inl.h"
#include "src/execution/isolate-inl.h"
#include "src/execution/microtask-queue.h"
#include "src/execution/off-thread-isolate.h"
#include "src/execution/protectors-inl.h"
#include "src/heap/factory-inl.h"
#include "src/heap/heap-inl.h"
......@@ -5333,9 +5332,8 @@ void SharedFunctionInfo::DisableOptimization(BailoutReason reason) {
}
// static
template <typename Isolate>
void SharedFunctionInfo::InitFromFunctionLiteral(
Isolate* isolate, HandleFor<Isolate, SharedFunctionInfo> shared_info,
Isolate* isolate, Handle<SharedFunctionInfo> shared_info,
FunctionLiteral* lit, bool is_toplevel) {
DCHECK(!shared_info->name_or_scope_info().IsScopeInfo());
......@@ -5389,12 +5387,12 @@ void SharedFunctionInfo::InitFromFunctionLiteral(
shared_info->set_is_safe_to_skip_arguments_adaptor(false);
shared_info->UpdateExpectedNofPropertiesFromEstimate(lit);
HandleFor<Isolate, UncompiledData> data;
Handle<UncompiledData> data;
ProducedPreparseData* scope_data = lit->produced_preparse_data();
if (scope_data != nullptr) {
HandleFor<Isolate, PreparseData> preparse_data =
scope_data->Serialize(isolate);
Handle<PreparseData> preparse_data =
scope_data->Serialize(shared_info->GetIsolate());
data = isolate->factory()->NewUncompiledDataWithPreparseData(
lit->GetInferredName(isolate), lit->start_position(),
......@@ -5408,16 +5406,6 @@ void SharedFunctionInfo::InitFromFunctionLiteral(
shared_info->set_uncompiled_data(*data);
}
template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) void SharedFunctionInfo::
InitFromFunctionLiteral<Isolate>(Isolate* isolate,
Handle<SharedFunctionInfo> shared_info,
FunctionLiteral* lit, bool is_toplevel);
template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) void SharedFunctionInfo::
InitFromFunctionLiteral<OffThreadIsolate>(
OffThreadIsolate* isolate,
OffThreadHandle<SharedFunctionInfo> shared_info, FunctionLiteral* lit,
bool is_toplevel);
uint16_t SharedFunctionInfo::get_property_estimate_from_literal(
FunctionLiteral* literal) {
int estimate = literal->expected_property_count();
......
......@@ -329,7 +329,7 @@ ScopeInfo SharedFunctionInfo::scope_info() const {
if (maybe_scope_info.IsScopeInfo()) {
return ScopeInfo::cast(maybe_scope_info);
}
return GetReadOnlyRoots().empty_scope_info();
return ScopeInfo::Empty(GetIsolate());
}
void SharedFunctionInfo::set_scope_info(ScopeInfo scope_info,
......@@ -619,15 +619,7 @@ void SharedFunctionInfo::ClearPreparseData() {
DCHECK(HasUncompiledDataWithoutPreparseData());
}
template <typename Isolate>
void UncompiledData::Init(Isolate* isolate, String inferred_name,
int start_position, int end_position) {
set_inferred_name(inferred_name);
set_start_position(start_position);
set_end_position(end_position);
}
void UncompiledData::InitAfterBytecodeFlush(
void UncompiledData::Init(
String inferred_name, int start_position, int end_position,
std::function<void(HeapObject object, ObjectSlot slot, HeapObject target)>
gc_notify_updated_slot) {
......@@ -638,14 +630,17 @@ void UncompiledData::InitAfterBytecodeFlush(
set_end_position(end_position);
}
template <typename Isolate>
void UncompiledDataWithPreparseData::Init(Isolate* isolate,
String inferred_name,
int start_position, int end_position,
PreparseData scope_data) {
this->UncompiledData::Init(isolate, inferred_name, start_position,
end_position);
void UncompiledDataWithPreparseData::Init(
String inferred_name, int start_position, int end_position,
PreparseData scope_data,
std::function<void(HeapObject object, ObjectSlot slot, HeapObject target)>
gc_notify_updated_slot) {
this->UncompiledData::Init(inferred_name, start_position, end_position,
gc_notify_updated_slot);
set_preparse_data(scope_data);
gc_notify_updated_slot(
*this, RawField(UncompiledDataWithPreparseData::kPreparseDataOffset),
scope_data);
}
bool SharedFunctionInfo::HasWasmExportedFunctionData() const {
......
......@@ -9,7 +9,6 @@
#include "src/base/bit-field.h"
#include "src/codegen/bailout-reason.h"
#include "src/handles/handle-for.h"
#include "src/objects/compressed-slots.h"
#include "src/objects/function-kind.h"
#include "src/objects/function-syntax-kind.h"
......@@ -100,14 +99,11 @@ class PreparseData
class UncompiledData
: public TorqueGeneratedUncompiledData<UncompiledData, HeapObject> {
public:
template <typename Isolate>
inline void Init(Isolate* isolate, String inferred_name, int start_position,
int end_position);
inline void InitAfterBytecodeFlush(
inline void Init(
String inferred_name, int start_position, int end_position,
std::function<void(HeapObject object, ObjectSlot slot, HeapObject target)>
gc_notify_updated_slot);
gc_notify_updated_slot =
[](HeapObject object, ObjectSlot slot, HeapObject target) {});
using BodyDescriptor =
FixedBodyDescriptor<kStartOfStrongFieldsOffset, kEndOfStrongFieldsOffset,
......@@ -139,9 +135,12 @@ class UncompiledDataWithPreparseData
public:
DECL_PRINTER(UncompiledDataWithPreparseData)
template <typename Isolate>
inline void Init(Isolate* isolate, String inferred_name, int start_position,
int end_position, PreparseData scope_data);
inline void Init(
String inferred_name, int start_position, int end_position,
PreparseData scope_data,
std::function<void(HeapObject object, ObjectSlot slot, HeapObject target)>
gc_notify_updated_slot =
[](HeapObject object, ObjectSlot slot, HeapObject target) {});
using BodyDescriptor = SubclassBodyDescriptor<
UncompiledData::BodyDescriptor,
......@@ -554,9 +553,8 @@ class SharedFunctionInfo : public HeapObject {
inline bool has_simple_parameters();
// Initialize a SharedFunctionInfo from a parsed function literal.
template <typename Isolate>
static void InitFromFunctionLiteral(
Isolate* isolate, HandleFor<Isolate, SharedFunctionInfo> shared_info,
static void InitFromFunctionLiteral(Isolate* isolate,
Handle<SharedFunctionInfo> shared_info,
FunctionLiteral* lit, bool is_toplevel);
// Updates the expected number of properties based on estimate from parser.
......@@ -589,7 +587,6 @@ class SharedFunctionInfo : public HeapObject {
// Dispatched behavior.
DECL_PRINTER(SharedFunctionInfo)
DECL_VERIFIER(SharedFunctionInfo)
void SharedFunctionInfoVerify(OffThreadIsolate* isolate);
#ifdef OBJECT_PRINT
void PrintSourceCode(std::ostream& os);
#endif
......@@ -641,8 +638,6 @@ class SharedFunctionInfo : public HeapObject {
inline bool needs_home_object() const;
private:
void SharedFunctionInfoVerify(ReadOnlyRoots roots);
// [name_or_scope_info]: Function name string, kNoSharedNameSentinel or
// ScopeInfo.
DECL_ACCESSORS(name_or_scope_info, Object)
......@@ -665,8 +660,7 @@ class SharedFunctionInfo : public HeapObject {
inline uint16_t get_property_estimate_from_literal(FunctionLiteral* literal);
template <typename Impl>
friend class FactoryBase;
friend class Factory;
friend class V8HeapExplorer;
FRIEND_TEST(PreParserTest, LazyFunctionLength);
......
......@@ -199,7 +199,6 @@ class ZonePreparseData : public ZoneObject {
int child_length);
Handle<PreparseData> Serialize(Isolate* isolate);
OffThreadHandle<PreparseData> Serialize(OffThreadIsolate* isolate);
int children_length() const { return static_cast<int>(children_.size()); }
......
......@@ -9,13 +9,11 @@
#include "src/ast/scopes.h"
#include "src/ast/variables.h"
#include "src/handles/handles.h"
#include "src/heap/off-thread-factory.h"
#include "src/objects/objects-inl.h"
#include "src/objects/shared-function-info.h"
#include "src/parsing/parser.h"
#include "src/parsing/preparse-data-impl.h"
#include "src/parsing/preparser.h"
#include "src/roots/roots.h"
#include "src/zone/zone-list-inl.h" // crbug.com/v8/8816
namespace v8 {
......@@ -433,17 +431,6 @@ Handle<PreparseData> PreparseDataBuilder::ByteData::CopyToHeap(
return data;
}
OffThreadHandle<PreparseData>
PreparseDataBuilder::ByteData::CopyToOffThreadHeap(OffThreadIsolate* isolate,
int children_length) {
DCHECK(is_finalized_);
int data_length = zone_byte_data_.length();
OffThreadHandle<PreparseData> data =
isolate->factory()->NewPreparseData(data_length, children_length);
data->copy_in(0, zone_byte_data_.begin(), data_length);
return data;
}
Handle<PreparseData> PreparseDataBuilder::Serialize(Isolate* isolate) {
DCHECK(HasData());
DCHECK(!ThisOrParentBailedOut());
......@@ -460,23 +447,6 @@ Handle<PreparseData> PreparseDataBuilder::Serialize(Isolate* isolate) {
return data;
}
OffThreadHandle<PreparseData> PreparseDataBuilder::Serialize(
OffThreadIsolate* isolate) {
DCHECK(HasData());
DCHECK(!ThisOrParentBailedOut());
OffThreadHandle<PreparseData> data =
byte_data_.CopyToOffThreadHeap(isolate, num_inner_with_data_);
int i = 0;
DCHECK(finalized_children_);
for (const auto& builder : children_) {
if (!builder->HasData()) continue;
OffThreadHandle<PreparseData> child_data = builder->Serialize(isolate);
data->set_child(i++, *child_data);
}
DCHECK_EQ(i, data->children_length());
return data;
}
ZonePreparseData* PreparseDataBuilder::Serialize(Zone* zone) {
DCHECK(HasData());
DCHECK(!ThisOrParentBailedOut());
......@@ -503,10 +473,6 @@ class BuilderProducedPreparseData final : public ProducedPreparseData {
return builder_->Serialize(isolate);
}
OffThreadHandle<PreparseData> Serialize(OffThreadIsolate* isolate) final {
return builder_->Serialize(isolate);
}
ZonePreparseData* Serialize(Zone* zone) final {
return builder_->Serialize(zone);
}
......@@ -525,11 +491,6 @@ class OnHeapProducedPreparseData final : public ProducedPreparseData {
return data_;
}
OffThreadHandle<PreparseData> Serialize(OffThreadIsolate* isolate) final {
// Not required.
UNREACHABLE();
}
ZonePreparseData* Serialize(Zone* zone) final {
// Not required.
UNREACHABLE();
......@@ -547,10 +508,6 @@ class ZoneProducedPreparseData final : public ProducedPreparseData {
return data_->Serialize(isolate);
}
OffThreadHandle<PreparseData> Serialize(OffThreadIsolate* isolate) final {
return data_->Serialize(isolate);
}
ZonePreparseData* Serialize(Zone* zone) final { return data_; }
private:
......@@ -793,23 +750,6 @@ Handle<PreparseData> ZonePreparseData::Serialize(Isolate* isolate) {
return result;
}
OffThreadHandle<PreparseData> ZonePreparseData::Serialize(
OffThreadIsolate* isolate) {
int data_size = static_cast<int>(byte_data()->size());
int child_data_length = children_length();
OffThreadHandle<PreparseData> result =
isolate->factory()->NewPreparseData(data_size, child_data_length);
result->copy_in(0, byte_data()->data(), data_size);
for (int i = 0; i < child_data_length; i++) {
ZonePreparseData* child = get_child(i);
DCHECK_NOT_NULL(child);
OffThreadHandle<PreparseData> child_data = child->Serialize(isolate);
result->set_child(i, *child_data);
}
return result;
}
ZoneConsumedPreparseData::ZoneConsumedPreparseData(Zone* zone,
ZonePreparseData* data)
: data_(data), scope_data_wrapper_(data_->byte_data()) {
......
......@@ -140,8 +140,6 @@ class V8_EXPORT_PRIVATE PreparseDataBuilder : public ZoneObject,
void Finalize(Zone* zone);
Handle<PreparseData> CopyToHeap(Isolate* isolate, int children_length);
OffThreadHandle<PreparseData> CopyToOffThreadHeap(OffThreadIsolate* isolate,
int children_length);
inline ZonePreparseData* CopyToZone(Zone* zone, int children_length);
void Reserve(size_t bytes);
......@@ -210,7 +208,6 @@ class V8_EXPORT_PRIVATE PreparseDataBuilder : public ZoneObject,
friend class BuilderProducedPreparseData;
Handle<PreparseData> Serialize(Isolate* isolate);
OffThreadHandle<PreparseData> Serialize(OffThreadIsolate* isolate);
ZonePreparseData* Serialize(Zone* zone);
void FinalizeChildren(Zone* zone);
......@@ -253,12 +250,6 @@ class ProducedPreparseData : public ZoneObject {
// MaybeHandle.
virtual Handle<PreparseData> Serialize(Isolate* isolate) = 0;
// If there is data (if the Scope contains skippable inner functions), move
// the data into the heap and return a Handle to it; otherwise return a null
// MaybeHandle.
virtual OffThreadHandle<PreparseData> Serialize(
OffThreadIsolate* isolate) = 0;
// If there is data (if the Scope contains skippable inner functions), return
// an off-heap ZonePreparseData representing the data; otherwise
// return nullptr.
......
......@@ -794,13 +794,8 @@ std::unique_ptr<Utf16CharacterStream> ScannerStream::ForTesting(
const char* data, size_t length) {
return std::unique_ptr<Utf16CharacterStream>(
new BufferedCharacterStream<TestingStream>(
0, reinterpret_cast<const uint8_t*>(data), length));
}
std::unique_ptr<Utf16CharacterStream> ScannerStream::ForTesting(
const uint16_t* data, size_t length) {
return std::unique_ptr<Utf16CharacterStream>(
new UnbufferedCharacterStream<TestingStream>(0, data, length));
static_cast<size_t>(0), reinterpret_cast<const uint8_t*>(data),
static_cast<size_t>(length)));
}
Utf16CharacterStream* ScannerStream::For(
......
......@@ -31,8 +31,6 @@ class V8_EXPORT_PRIVATE ScannerStream {
static std::unique_ptr<Utf16CharacterStream> ForTesting(const char* data);
static std::unique_ptr<Utf16CharacterStream> ForTesting(const char* data,
size_t length);
static std::unique_ptr<Utf16CharacterStream> ForTesting(const uint16_t* data,
size_t length);
};
} // namespace internal
......
......@@ -8,25 +8,12 @@
#include <memory>
#include "src/ast/ast-value-factory.h"
#include "src/ast/ast.h"
#include "src/ast/scopes.h"
#include "src/common/assert-scope.h"
#include "src/common/globals.h"
#include "src/execution/off-thread-isolate.h"
#include "src/handles/handles-inl.h"
#include "src/handles/handles.h"
#include "src/heap/off-thread-factory-inl.h"
#include "src/heap/off-thread-factory.h"
#include "src/objects/fixed-array.h"
#include "src/objects/script.h"
#include "src/objects/shared-function-info.h"
#include "src/objects/string.h"
#include "src/parsing/parse-info.h"
#include "src/parsing/parser.h"
#include "src/parsing/rewriter.h"
#include "src/parsing/scanner-character-streams.h"
#include "src/parsing/scanner.h"
#include "src/strings/unicode-inl.h"
#include "src/utils/utils.h"
#include "test/unittests/test-utils.h"
namespace v8 {
......@@ -34,74 +21,10 @@ namespace internal {
class OffThreadIsolate;
namespace {
std::vector<uint16_t> DecodeUtf8(const std::string& string) {
if (string.empty()) return {};
auto utf8_data =
Vector<const uint8_t>::cast(VectorOf(string.data(), string.length()));
Utf8Decoder decoder(utf8_data);
std::vector<uint16_t> utf16(decoder.utf16_length());
decoder.Decode(&utf16[0], utf8_data);
return utf16;
}
} // namespace
class OffThreadFactoryTest : public TestWithIsolateAndZone {
public:
OffThreadFactoryTest()
: TestWithIsolateAndZone(),
off_thread_isolate_(isolate()),
parse_info_(isolate()) {}
FunctionLiteral* ParseProgram(const char* source) {
auto utf16_source = DecodeUtf8(source);
// Normally this would be an external string or whatever, we don't have to
// worry about it for now.
source_string_ =
factory()->NewStringFromUtf8(CStrVector(source)).ToHandleChecked();
parse_info_.set_character_stream(
ScannerStream::ForTesting(utf16_source.data(), utf16_source.size()));
parse_info_.set_toplevel();
parse_info_.set_allow_lazy_parsing();
{
DisallowHeapAllocation no_allocation;
DisallowHandleAllocation no_handles;
DisallowHeapAccess no_heap_access;
Parser parser(parse_info());
parser.InitializeEmptyScopeChain(parse_info());
parser.ParseOnBackground(parse_info());
CHECK(DeclarationScope::Analyze(parse_info()));
}
parse_info()->ast_value_factory()->Internalize(off_thread_isolate());
DeclarationScope::AllocateScopeInfos(parse_info(), off_thread_isolate());
script_ = parse_info_.CreateScript(off_thread_isolate(),
off_thread_factory()->empty_string(),
ScriptOriginOptions());
// Create the SFI list on the script so that SFI SetScript works.
OffThreadHandle<WeakFixedArray> infos =
off_thread_factory()->NewWeakFixedArray(
parse_info()->max_function_literal_id() + 1, AllocationType::kOld);
script_->set_shared_function_infos(*infos);
return parse_info()->literal();
}
ParseInfo* parse_info() { return &parse_info_; }
OffThreadHandle<Script> script() { return script_; }
: TestWithIsolateAndZone(), off_thread_isolate_(isolate()) {}
OffThreadIsolate* off_thread_isolate() { return &off_thread_isolate_; }
OffThreadFactory* off_thread_factory() {
......@@ -118,9 +41,6 @@ class OffThreadFactoryTest : public TestWithIsolateAndZone {
private:
OffThreadIsolate off_thread_isolate_;
ParseInfo parse_info_;
Handle<String> source_string_;
OffThreadHandle<Script> script_;
};
TEST_F(OffThreadFactoryTest, HandleOrOffThreadHandle_IsNullWhenConstructed) {
......@@ -253,95 +173,5 @@ TEST_F(OffThreadFactoryTest, AstConsString_CreatesConsString) {
"foobar-plus-padding-for-length")));
}
TEST_F(OffThreadFactoryTest, EmptyScript) {
FunctionLiteral* program = ParseProgram("");
SharedFunctionInfo shared =
*off_thread_factory()->NewSharedFunctionInfoForLiteral(program, script(),
true);
off_thread_factory()->FinishOffThread();
Handle<SharedFunctionInfo> root_sfi = handle(shared, isolate());
off_thread_factory()->Publish(isolate());
EXPECT_EQ(root_sfi->function_literal_id(), 0);
}
TEST_F(OffThreadFactoryTest, LazyFunction) {
FunctionLiteral* program = ParseProgram("function lazy() {}");
FunctionLiteral* lazy = program->scope()
->declarations()
->AtForTest(0)
->AsFunctionDeclaration()
->fun();
SharedFunctionInfo shared =
*off_thread_factory()->NewSharedFunctionInfoForLiteral(lazy, script(),
true);
off_thread_factory()->FinishOffThread();
Handle<SharedFunctionInfo> lazy_sfi = handle(shared, isolate());
off_thread_factory()->Publish(isolate());
EXPECT_EQ(lazy_sfi->function_literal_id(), 1);
EXPECT_TRUE(lazy_sfi->Name().IsOneByteEqualTo(CStrVector("lazy")));
EXPECT_FALSE(lazy_sfi->is_compiled());
EXPECT_TRUE(lazy_sfi->HasUncompiledDataWithoutPreparseData());
}
TEST_F(OffThreadFactoryTest, EagerFunction) {
FunctionLiteral* program = ParseProgram("(function eager() {})");
FunctionLiteral* eager = program->body()
->at(0)
->AsExpressionStatement()
->expression()
->AsFunctionLiteral();
SharedFunctionInfo shared =
*off_thread_factory()->NewSharedFunctionInfoForLiteral(eager, script(),
true);
off_thread_factory()->FinishOffThread();
Handle<SharedFunctionInfo> eager_sfi = handle(shared, isolate());
off_thread_factory()->Publish(isolate());
EXPECT_EQ(eager_sfi->function_literal_id(), 1);
EXPECT_TRUE(eager_sfi->Name().IsOneByteEqualTo(CStrVector("eager")));
EXPECT_FALSE(eager_sfi->HasUncompiledData());
// TODO(leszeks): Allocate bytecode and enable these checks.
// EXPECT_TRUE(eager_sfi->is_compiled());
// EXPECT_TRUE(eager_sfi->HasBytecodeArray());
}
TEST_F(OffThreadFactoryTest, ImplicitNameFunction) {
FunctionLiteral* program = ParseProgram("let implicit_name = function() {}");
FunctionLiteral* implicit_name = program->body()
->at(0)
->AsBlock()
->statements()
->at(0)
->AsExpressionStatement()
->expression()
->AsAssignment()
->value()
->AsFunctionLiteral();
SharedFunctionInfo shared =
*off_thread_factory()->NewSharedFunctionInfoForLiteral(implicit_name,
script(), true);
off_thread_factory()->FinishOffThread();
Handle<SharedFunctionInfo> implicit_name_sfi = handle(shared, isolate());
off_thread_factory()->Publish(isolate());
EXPECT_EQ(implicit_name_sfi->function_literal_id(), 1);
EXPECT_TRUE(
implicit_name_sfi->Name().IsOneByteEqualTo(CStrVector("implicit_name")));
}
} // namespace internal
} // namespace v8
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