Commit 2bfd8a7c authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[ignition] Remove handles from bytecode generation

Removes handles from bytecode generation, instead storing
un-internalized AstValues (and other, similar values such as Scopes and
AstRawStrings) in the constant array builder.

This will allow us in the future to generate the bytecode before
internalizing the AST.

BUG=v8:5832

Change-Id: I3b8be8f7329a484eb1e5d12808b001d3475239da
Reviewed-on: https://chromium-review.googlesource.com/439326
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43115}
parent 588ed4b3
......@@ -436,7 +436,7 @@ class AstValueFactory {
const AstConsString* NewConsString(const AstString* left,
const AstString* right);
void Internalize(Isolate* isolate);
V8_EXPORT_PRIVATE void Internalize(Isolate* isolate);
#define F(name, str) \
const AstRawString* name##_string() { \
......@@ -445,10 +445,11 @@ class AstValueFactory {
STRING_CONSTANTS(F)
#undef F
const AstValue* NewString(const AstRawString* string);
V8_EXPORT_PRIVATE const AstValue* NewString(const AstRawString* string);
// A JavaScript symbol (ECMA-262 edition 6).
const AstValue* NewSymbol(AstSymbol symbol);
const AstValue* NewNumber(double number, bool with_dot = false);
V8_EXPORT_PRIVATE const AstValue* NewNumber(double number,
bool with_dot = false);
const AstValue* NewSmi(uint32_t number);
const AstValue* NewBoolean(bool b);
const AstValue* NewStringList(ZoneList<const AstRawString*>* strings);
......
......@@ -1538,6 +1538,7 @@ class AccessorTable
class RegExpLiteral final : public MaterializedLiteral {
public:
Handle<String> pattern() const { return pattern_->string(); }
const AstRawString* raw_pattern() const { return pattern_; }
int flags() const { return flags_; }
private:
......
......@@ -411,7 +411,7 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
Scope* GetOuterScopeWithContext();
// Analyze() must have been called once to create the ScopeInfo.
Handle<ScopeInfo> scope_info() {
Handle<ScopeInfo> scope_info() const {
DCHECK(!scope_info_.is_null());
return scope_info_;
}
......@@ -609,7 +609,7 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
friend class ScopeTestHelper;
};
class DeclarationScope : public Scope {
class V8_EXPORT_PRIVATE DeclarationScope : public Scope {
public:
DeclarationScope(Zone* zone, Scope* outer_scope, ScopeType scope_type,
FunctionKind function_kind = kNormalFunction);
......
This diff is collapsed.
......@@ -76,7 +76,9 @@ class V8_EXPORT_PRIVATE BytecodeArrayBuilder final
// Constant loads to accumulator.
BytecodeArrayBuilder& LoadConstantPoolEntry(size_t entry);
BytecodeArrayBuilder& LoadLiteral(v8::internal::Smi* value);
BytecodeArrayBuilder& LoadLiteral(Handle<Object> object);
BytecodeArrayBuilder& LoadLiteral(const AstRawString* raw_string);
BytecodeArrayBuilder& LoadLiteral(const Scope* scope);
BytecodeArrayBuilder& LoadLiteral(const AstValue* ast_value);
BytecodeArrayBuilder& LoadUndefined();
BytecodeArrayBuilder& LoadNull();
BytecodeArrayBuilder& LoadTheHole();
......@@ -84,10 +86,9 @@ class V8_EXPORT_PRIVATE BytecodeArrayBuilder final
BytecodeArrayBuilder& LoadFalse();
// Global loads to the accumulator and stores from the accumulator.
BytecodeArrayBuilder& LoadGlobal(const Handle<String> name, int feedback_slot,
BytecodeArrayBuilder& LoadGlobal(const AstRawString* name, int feedback_slot,
TypeofMode typeof_mode);
BytecodeArrayBuilder& StoreGlobal(const Handle<String> name,
int feedback_slot,
BytecodeArrayBuilder& StoreGlobal(const AstRawString* name, int feedback_slot,
LanguageMode language_mode);
// Load the object at |slot_index| at |depth| in the context chain starting
......@@ -119,10 +120,13 @@ class V8_EXPORT_PRIVATE BytecodeArrayBuilder final
// Named load property.
BytecodeArrayBuilder& LoadNamedProperty(Register object,
const Handle<Name> name,
const AstRawString* name,
int feedback_slot);
// Keyed load property. The key should be in the accumulator.
BytecodeArrayBuilder& LoadKeyedProperty(Register object, int feedback_slot);
// Named load property of the @@iterator symbol.
BytecodeArrayBuilder& LoadIteratorProperty(Register object,
int feedback_slot);
// Store properties. Flag for NeedsSetFunctionName() should
// be in the accumulator.
......@@ -130,35 +134,49 @@ class V8_EXPORT_PRIVATE BytecodeArrayBuilder final
Register object, Register name, DataPropertyInLiteralFlags flags,
int feedback_slot);
// Store properties. The value to be stored should be in the accumulator.
// Store a property named by a property name. The value to be stored should be
// in the accumulator.
BytecodeArrayBuilder& StoreNamedProperty(Register object,
const AstRawString* name,
int feedback_slot,
LanguageMode language_mode);
// Store a property named by a constant from the constant pool. The value to
// be stored should be in the accumulator.
BytecodeArrayBuilder& StoreNamedProperty(Register object,
const Handle<Name> name,
size_t constant_pool_entry,
int feedback_slot,
LanguageMode language_mode);
// Store a property keyed by a value in a register. The value to be stored
// should be in the accumulator.
BytecodeArrayBuilder& StoreKeyedProperty(Register object, Register key,
int feedback_slot,
LanguageMode language_mode);
// Store the home object property. The value to be stored should be in the
// accumulator.
BytecodeArrayBuilder& StoreHomeObjectProperty(Register object,
int feedback_slot,
LanguageMode language_mode);
// Lookup the variable with |name|.
BytecodeArrayBuilder& LoadLookupSlot(const Handle<String> name,
BytecodeArrayBuilder& LoadLookupSlot(const AstRawString* name,
TypeofMode typeof_mode);
// Lookup the variable with |name|, which is known to be at |slot_index| at
// |depth| in the context chain if not shadowed by a context extension
// somewhere in that context chain.
BytecodeArrayBuilder& LoadLookupContextSlot(const Handle<String> name,
BytecodeArrayBuilder& LoadLookupContextSlot(const AstRawString* name,
TypeofMode typeof_mode,
int slot_index, int depth);
// Lookup the variable with |name|, which has its feedback in |feedback_slot|
// and is known to be global if not shadowed by a context extension somewhere
// up to |depth| in that context chain.
BytecodeArrayBuilder& LoadLookupGlobalSlot(const Handle<String> name,
BytecodeArrayBuilder& LoadLookupGlobalSlot(const AstRawString* name,
TypeofMode typeof_mode,
int feedback_slot, int depth);
// Store value in the accumulator into the variable with |name|.
BytecodeArrayBuilder& StoreLookupSlot(const Handle<String> name,
BytecodeArrayBuilder& StoreLookupSlot(const AstRawString* name,
LanguageMode language_mode);
// Create a new closure for a SharedFunctionInfo which will be inserted at
......@@ -166,15 +184,15 @@ class V8_EXPORT_PRIVATE BytecodeArrayBuilder final
BytecodeArrayBuilder& CreateClosure(size_t shared_function_info_entry,
int slot, int flags);
// Create a new local context for a |scope_info| and a closure which should be
// Create a new local context for a |scope| and a closure which should be
// in the accumulator.
BytecodeArrayBuilder& CreateBlockContext(Handle<ScopeInfo> scope_info);
BytecodeArrayBuilder& CreateBlockContext(const Scope* scope);
// Create a new context for a catch block with |exception|, |name|,
// |scope_info|, and the closure in the accumulator.
// |scope|, and the closure in the accumulator.
BytecodeArrayBuilder& CreateCatchContext(Register exception,
Handle<String> name,
Handle<ScopeInfo> scope_info);
const AstRawString* name,
const Scope* scope);
// Create a new context with size |slots|.
BytecodeArrayBuilder& CreateFunctionContext(int slots);
......@@ -182,16 +200,15 @@ class V8_EXPORT_PRIVATE BytecodeArrayBuilder final
// Create a new eval context with size |slots|.
BytecodeArrayBuilder& CreateEvalContext(int slots);
// Creates a new context with the given |scope_info| for a with-statement
// Creates a new context with the given |scope| for a with-statement
// with the |object| in a register and the closure in the accumulator.
BytecodeArrayBuilder& CreateWithContext(Register object,
Handle<ScopeInfo> scope_info);
BytecodeArrayBuilder& CreateWithContext(Register object, const Scope* scope);
// Create a new arguments object in the accumulator.
BytecodeArrayBuilder& CreateArguments(CreateArgumentsType type);
// Literals creation. Constant elements should be in the accumulator.
BytecodeArrayBuilder& CreateRegExpLiteral(Handle<String> pattern,
BytecodeArrayBuilder& CreateRegExpLiteral(const AstRawString* pattern,
int literal_index, int flags);
BytecodeArrayBuilder& CreateArrayLiteral(size_t constant_elements_entry,
int literal_index, int flags);
......@@ -336,12 +353,18 @@ class V8_EXPORT_PRIVATE BytecodeArrayBuilder final
// entry, so that it can be referenced by above exception handling support.
int NewHandlerEntry() { return handler_table_builder()->NewHandlerEntry(); }
// Gets a constant pool entry for the |object|.
size_t GetConstantPoolEntry(Handle<Object> object);
// Allocates a slot in the constant pool which can later be inserted.
size_t AllocateConstantPoolEntry();
// Inserts a entry into an allocated constant pool entry.
void InsertConstantPoolEntryAt(size_t entry, Handle<Object> object);
// Gets a constant pool entry.
size_t GetConstantPoolEntry(const AstRawString* raw_string);
size_t GetConstantPoolEntry(const AstValue* heap_number);
size_t GetConstantPoolEntry(const Scope* scope);
#define ENTRY_GETTER(NAME, ...) size_t NAME##ConstantPoolEntry();
SINGLETON_CONSTANT_ENTRY_TYPES(ENTRY_GETTER)
#undef ENTRY_GETTER
// Allocates a slot in the constant pool which can later be set.
size_t AllocateDeferredConstantPoolEntry();
// Sets the deferred value into an allocated constant pool entry.
void SetDeferredConstantPoolEntry(size_t entry, Handle<Object> object);
void InitializeReturnPosition(FunctionLiteral* literal);
......
This diff is collapsed.
......@@ -18,6 +18,7 @@ class CompilationInfo;
namespace interpreter {
class GlobalDeclarationsBuilder;
class LoopBuilder;
class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
......@@ -108,8 +109,8 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
void BuildAsyncReturn();
void BuildReThrow();
void BuildAbort(BailoutReason bailout_reason);
void BuildThrowIfHole(Handle<String> name);
void BuildThrowReferenceError(Handle<String> name);
void BuildThrowIfHole(const AstRawString* name);
void BuildThrowReferenceError(const AstRawString* name);
void BuildHoleCheckForVariableAssignment(Variable* variable, Token::Value op);
// Build jump to targets[value], where
......@@ -190,14 +191,14 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
return builder()->register_allocator();
}
GlobalDeclarationsBuilder* globals_builder() { return globals_builder_; }
GlobalDeclarationsBuilder* globals_builder() {
DCHECK_NOT_NULL(globals_builder_);
return globals_builder_;
}
inline LanguageMode language_mode() const;
int feedback_index(FeedbackSlot slot) const;
Handle<Name> home_object_symbol() const { return home_object_symbol_; }
Handle<Name> iterator_symbol() const { return iterator_symbol_; }
Handle<Name> prototype_string() const { return prototype_string_; }
Handle<FixedArray> empty_fixed_array() const { return empty_fixed_array_; }
const AstRawString* prototype_string() const { return prototype_string_; }
const AstRawString* undefined_string() const { return undefined_string_; }
Zone* zone_;
......@@ -221,10 +222,7 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
Register generator_state_;
int loop_depth_;
Handle<Name> home_object_symbol_;
Handle<Name> iterator_symbol_;
Handle<Name> prototype_string_;
Handle<FixedArray> empty_fixed_array_;
const AstRawString* prototype_string_;
const AstRawString* undefined_string_;
};
......
This diff is collapsed.
......@@ -14,9 +14,17 @@ namespace v8 {
namespace internal {
class Isolate;
class AstRawString;
class AstValue;
namespace interpreter {
// Constant array entries that represent singletons.
#define SINGLETON_CONSTANT_ENTRY_TYPES(V) \
V(IteratorSymbol, iterator_symbol) \
V(HomeObjectSymbol, home_object_symbol) \
V(EmptyFixedArray, empty_fixed_array)
// A helper class for constructing constant arrays for the
// interpreter. Each instance of this class is intended to be used to
// generate exactly one FixedArray of constants via the ToFixedArray
......@@ -33,28 +41,36 @@ class V8_EXPORT_PRIVATE ConstantArrayBuilder final BASE_EMBEDDED {
static const size_t k32BitCapacity =
kMaxUInt32 - k16BitCapacity - k8BitCapacity + 1;
ConstantArrayBuilder(Zone* zone, Handle<Object> the_hole_value);
ConstantArrayBuilder(Zone* zone);
// Generate a fixed array of constants based on inserted objects.
// Generate a fixed array of constant handles based on inserted objects.
Handle<FixedArray> ToFixedArray(Isolate* isolate);
// Returns the object in the constant pool array that at index
// |index|.
Handle<Object> At(size_t index) const;
// Returns the object, as a handle in |isolate|, that is in the constant pool
// array at index |index|. Returns null if there is no handle at this index.
// Only expected to be used in tests.
MaybeHandle<Object> At(size_t index, Isolate* isolate) const;
// Returns the number of elements in the array.
size_t size() const;
// Insert an object into the constants array if it is not already
// present. Returns the array index associated with the object.
size_t Insert(Handle<Object> object);
// Insert an object into the constants array if it is not already present.
// Returns the array index associated with the object.
size_t Insert(Smi* smi);
size_t Insert(const AstRawString* raw_string);
size_t Insert(const AstValue* heap_number);
size_t Insert(const Scope* scope);
#define INSERT_ENTRY(NAME, ...) size_t Insert##NAME();
SINGLETON_CONSTANT_ENTRY_TYPES(INSERT_ENTRY)
#undef INSERT_ENTRY
// Allocates an empty entry and returns the array index associated with the
// reservation. Entry can be inserted by calling InsertReservedEntry().
size_t AllocateEntry();
// Inserts an empty entry and returns the array index associated with the
// reservation. The entry's handle value can be inserted by calling
// SetDeferredAt().
size_t InsertDeferred();
// Inserts the given object into an allocated entry.
void InsertAllocatedEntry(size_t index, Handle<Object> object);
// Sets the deferred value at |index| to |object|.
void SetDeferredAt(size_t index, Handle<Object> object);
// Creates a reserved entry in the constant pool and returns
// the size of the operand that'll be required to hold the entry
......@@ -71,7 +87,60 @@ class V8_EXPORT_PRIVATE ConstantArrayBuilder final BASE_EMBEDDED {
private:
typedef uint32_t index_t;
index_t AllocateIndex(Handle<Object> object);
class Entry {
private:
enum class Tag : uint8_t;
public:
explicit Entry(Smi* smi) : smi_(smi), tag_(Tag::kSmi) {}
explicit Entry(const AstRawString* raw_string)
: raw_string_(raw_string), tag_(Tag::kRawString) {}
explicit Entry(const AstValue* heap_number)
: heap_number_(heap_number), tag_(Tag::kHeapNumber) {}
explicit Entry(const Scope* scope) : scope_(scope), tag_(Tag::kScope) {}
#define CONSTRUCT_ENTRY(NAME, LOWER_NAME) \
static Entry NAME() { return Entry(Tag::k##NAME); }
SINGLETON_CONSTANT_ENTRY_TYPES(CONSTRUCT_ENTRY)
#undef CONSTRUCT_ENTRY
static Entry Deferred() { return Entry(Tag::kDeferred); }
bool IsDeferred() const { return tag_ == Tag::kDeferred; }
void SetDeferred(Handle<Object> handle) {
DCHECK(tag_ == Tag::kDeferred);
tag_ = Tag::kHandle;
handle_ = handle;
}
Handle<Object> ToHandle(Isolate* isolate) const;
private:
explicit Entry(Tag tag) : tag_(tag) {}
union {
Handle<Object> handle_;
Smi* smi_;
const AstRawString* raw_string_;
const AstValue* heap_number_;
const Scope* scope_;
};
enum class Tag : uint8_t {
kDeferred,
kHandle,
kSmi,
kRawString,
kHeapNumber,
kScope,
#define ENTRY_TAG(NAME, ...) k##NAME,
SINGLETON_CONSTANT_ENTRY_TYPES(ENTRY_TAG)
#undef ENTRY_TAG
} tag_;
};
index_t AllocateIndex(Entry constant_entry);
index_t AllocateReservedEntry(Smi* value);
struct ConstantArraySlice final : public ZoneObject {
......@@ -79,12 +148,12 @@ class V8_EXPORT_PRIVATE ConstantArrayBuilder final BASE_EMBEDDED {
OperandSize operand_size);
void Reserve();
void Unreserve();
size_t Allocate(Handle<Object> object);
Handle<Object> At(size_t index) const;
void InsertAt(size_t index, Handle<Object> object);
size_t Allocate(Entry entry);
Entry& At(size_t index);
const Entry& At(size_t index) const;
#if DEBUG
void CheckAllElementsAreUnique() const;
void CheckAllElementsAreUnique(Isolate* isolate) const;
#endif
inline size_t available() const { return capacity() - reserved() - size(); }
......@@ -100,7 +169,7 @@ class V8_EXPORT_PRIVATE ConstantArrayBuilder final BASE_EMBEDDED {
const size_t capacity_;
size_t reserved_;
OperandSize operand_size_;
ZoneVector<Handle<Object>> constants_;
ZoneVector<Entry> constants_;
DISALLOW_COPY_AND_ASSIGN(ConstantArraySlice);
};
......@@ -108,16 +177,19 @@ class V8_EXPORT_PRIVATE ConstantArrayBuilder final BASE_EMBEDDED {
ConstantArraySlice* IndexToSlice(size_t index) const;
ConstantArraySlice* OperandSizeToSlice(OperandSize operand_size) const;
Handle<Object> the_hole_value() const { return the_hole_value_; }
ConstantArraySlice* idx_slice_[3];
base::TemplateHashMapImpl<Address, index_t, base::KeyEqualityMatcher<Address>,
base::TemplateHashMapImpl<intptr_t, index_t,
base::KeyEqualityMatcher<intptr_t>,
ZoneAllocationPolicy>
constants_map_;
ZoneMap<Smi*, index_t> smi_map_;
ZoneVector<std::pair<Smi*, index_t>> smi_pairs_;
#define SINGLETON_ENTRY_FIELD(NAME, LOWER_NAME) int LOWER_NAME##_;
SINGLETON_CONSTANT_ENTRY_TYPES(SINGLETON_ENTRY_FIELD)
#undef SINGLETON_ENTRY_FIELD
Zone* zone_;
Handle<Object> the_hole_value_;
};
} // namespace interpreter
......
......@@ -13272,7 +13272,7 @@ Handle<JSObject> Script::GetWrapper(Handle<Script> script) {
}
MaybeHandle<SharedFunctionInfo> Script::FindSharedFunctionInfo(
Isolate* isolate, FunctionLiteral* fun) {
Isolate* isolate, const FunctionLiteral* fun) {
DCHECK_NE(fun->function_literal_id(), FunctionLiteral::kIdTypeInvalid);
DCHECK_LT(fun->function_literal_id(), shared_function_infos()->length());
Object* shared = shared_function_infos()->get(fun->function_literal_id());
......
......@@ -6799,8 +6799,8 @@ class Script: public Struct {
// Look through the list of existing shared function infos to find one
// that matches the function literal. Return empty handle if not found.
MaybeHandle<SharedFunctionInfo> FindSharedFunctionInfo(Isolate* isolate,
FunctionLiteral* fun);
MaybeHandle<SharedFunctionInfo> FindSharedFunctionInfo(
Isolate* isolate, const FunctionLiteral* fun);
// Iterate over all script objects on the heap.
class Iterator {
......
This diff is collapsed.
......@@ -4,6 +4,7 @@
#include "src/v8.h"
#include "src/ast/scopes.h"
#include "src/interpreter/bytecode-array-builder.h"
#include "src/interpreter/bytecode-array-iterator.h"
#include "src/interpreter/bytecode-label.h"
......@@ -21,11 +22,13 @@ class BytecodeArrayBuilderTest : public TestWithIsolateAndZone {
~BytecodeArrayBuilderTest() override {}
};
TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) {
CanonicalHandleScope canonical(isolate());
BytecodeArrayBuilder builder(isolate(), zone(), 0, 1, 131);
Factory* factory = isolate()->factory();
AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(),
isolate()->heap()->HashSeed());
DeclarationScope scope(zone(), &ast_factory);
CHECK_EQ(builder.locals_count(), 131);
CHECK_EQ(builder.context_count(), 1);
......@@ -52,7 +55,8 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) {
.StoreAccumulatorInRegister(reg)
.LoadLiteral(Smi::FromInt(10000000))
.StoreAccumulatorInRegister(reg)
.LoadLiteral(factory->NewStringFromStaticChars("A constant"))
.LoadLiteral(
ast_factory.NewString(ast_factory.GetOneByteString("A constant")))
.StoreAccumulatorInRegister(reg)
.LoadUndefined()
.StoreAccumulatorInRegister(reg)
......@@ -77,7 +81,7 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) {
builder.MoveRegister(reg, wide);
// Emit global load / store operations.
Handle<String> name = factory->NewStringFromStaticChars("var_name");
const AstRawString* name = ast_factory.GetOneByteString("var_name");
builder.LoadGlobal(name, 1, TypeofMode::NOT_INSIDE_TYPEOF)
.LoadGlobal(name, 1, TypeofMode::INSIDE_TYPEOF)
.StoreGlobal(name, 1, LanguageMode::SLOPPY)
......@@ -126,14 +130,14 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) {
builder.CreateClosure(0, 1, NOT_TENURED);
// Emit create context operation.
builder.CreateBlockContext(factory->NewScopeInfo(1));
builder.CreateCatchContext(reg, name, factory->NewScopeInfo(1));
builder.CreateBlockContext(&scope);
builder.CreateCatchContext(reg, name, &scope);
builder.CreateFunctionContext(1);
builder.CreateEvalContext(1);
builder.CreateWithContext(reg, factory->NewScopeInfo(1));
builder.CreateWithContext(reg, &scope);
// Emit literal creation operations.
builder.CreateRegExpLiteral(factory->NewStringFromStaticChars("a"), 0, 0);
builder.CreateRegExpLiteral(ast_factory.GetOneByteString("a"), 0, 0);
builder.CreateArrayLiteral(0, 0, 0);
builder.CreateObjectLiteral(0, 0, 0, reg);
......@@ -258,7 +262,7 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) {
.JumpIfNull(&end[5])
.JumpIfUndefined(&end[6])
.JumpIfNotHole(&end[7])
.LoadLiteral(factory->prototype_string())
.LoadLiteral(ast_factory.prototype_string())
.JumpIfJSReceiver(&end[8]);
}
......@@ -307,10 +311,10 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) {
// Wide constant pool loads
for (int i = 0; i < 256; i++) {
// Emit junk in constant pool to force wide constant pool index.
builder.LoadLiteral(factory->NewNumber(2.5321 + i));
builder.LoadLiteral(ast_factory.NewNumber(2.5321 + i));
}
builder.LoadLiteral(Smi::FromInt(20000000));
Handle<String> wide_name = factory->NewStringFromStaticChars("var_wide_name");
const AstRawString* wide_name = ast_factory.GetOneByteString("var_wide_name");
// Emit wide global load / store operations.
builder.LoadGlobal(name, 1024, TypeofMode::NOT_INSIDE_TYPEOF)
......@@ -348,8 +352,7 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) {
// Emit wide variant of literal creation operations.
builder
.CreateRegExpLiteral(factory->NewStringFromStaticChars("wide_literal"), 0,
0)
.CreateRegExpLiteral(ast_factory.GetOneByteString("wide_literal"), 0, 0)
.CreateArrayLiteral(0, 0, 0)
.CreateObjectLiteral(0, 0, 0, reg);
......@@ -385,6 +388,8 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) {
builder.Return();
// Generate BytecodeArray.
scope.SetScriptScopeInfo(factory->NewScopeInfo(1));
ast_factory.Internalize(isolate());
Handle<BytecodeArray> the_array = builder.ToBytecodeArray(isolate());
CHECK_EQ(the_array->frame_size(),
builder.total_register_count() * kPointerSize);
......@@ -504,20 +509,25 @@ TEST_F(BytecodeArrayBuilderTest, Parameters) {
TEST_F(BytecodeArrayBuilderTest, Constants) {
CanonicalHandleScope canonical(isolate());
BytecodeArrayBuilder builder(isolate(), zone(), 0, 0, 0);
AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(),
isolate()->heap()->HashSeed());
const AstValue* heap_num_1 = ast_factory.NewNumber(3.14);
const AstValue* heap_num_2 = ast_factory.NewNumber(5.2);
const AstValue* string =
ast_factory.NewString(ast_factory.GetOneByteString("foo"));
const AstValue* string_copy =
ast_factory.NewString(ast_factory.GetOneByteString("foo"));
Factory* factory = isolate()->factory();
Handle<HeapObject> heap_num_1 = factory->NewHeapNumber(3.14);
Handle<HeapObject> heap_num_2 = factory->NewHeapNumber(5.2);
Handle<Object> large_smi(Smi::FromInt(0x12345678), isolate());
Handle<HeapObject> heap_num_2_copy(*heap_num_2);
builder.LoadLiteral(heap_num_1)
.LoadLiteral(heap_num_2)
.LoadLiteral(large_smi)
.LoadLiteral(string)
.LoadLiteral(heap_num_1)
.LoadLiteral(heap_num_1)
.LoadLiteral(heap_num_2_copy)
.LoadLiteral(string_copy)
.Return();
ast_factory.Internalize(isolate());
Handle<BytecodeArray> array = builder.ToBytecodeArray(isolate());
// Should only have one entry for each identical constant.
CHECK_EQ(array->constant_pool()->length(), 3);
......
......@@ -19,14 +19,14 @@ class BytecodeArrayIteratorTest : public TestWithIsolateAndZone {
~BytecodeArrayIteratorTest() override {}
};
TEST_F(BytecodeArrayIteratorTest, IteratesBytecodeArray) {
// Use a builder to create an array with containing multiple bytecodes
// with 0, 1 and 2 operands.
BytecodeArrayBuilder builder(isolate(), zone(), 3, 3, 0);
Factory* factory = isolate()->factory();
Handle<HeapObject> heap_num_0 = factory->NewHeapNumber(2.718);
Handle<HeapObject> heap_num_1 = factory->NewHeapNumber(2147483647);
AstValueFactory ast_factory(zone(), isolate()->ast_string_constants(),
isolate()->heap()->HashSeed());
const AstValue* heap_num_0 = ast_factory.NewNumber(2.718);
const AstValue* heap_num_1 = ast_factory.NewNumber(2.0 * Smi::kMaxValue);
Smi* zero = Smi::kZero;
Smi* smi_0 = Smi::FromInt(64);
Smi* smi_1 = Smi::FromInt(-65536);
......@@ -35,7 +35,7 @@ TEST_F(BytecodeArrayIteratorTest, IteratesBytecodeArray) {
RegisterList pair(0, 2);
RegisterList triple(0, 3);
Register param = Register::FromParameterIndex(2, builder.parameter_count());
Handle<String> name = factory->NewStringFromStaticChars("abc");
const AstRawString* name = ast_factory.GetOneByteString("abc");
uint32_t name_index = 2;
uint32_t feedback_slot = 97;
......@@ -65,6 +65,7 @@ TEST_F(BytecodeArrayIteratorTest, IteratesBytecodeArray) {
.Return();
// Test iterator sees the expected output from the builder.
ast_factory.Internalize(isolate());
BytecodeArrayIterator iterator(builder.ToBytecodeArray(isolate()));
const int kPrefixByteSize = 1;
int offset = 0;
......@@ -72,7 +73,8 @@ TEST_F(BytecodeArrayIteratorTest, IteratesBytecodeArray) {
CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant);
CHECK_EQ(iterator.current_offset(), offset);
CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
CHECK(iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_0));
CHECK(iterator.GetConstantForIndexOperand(0).is_identical_to(
heap_num_0->value()));
CHECK(!iterator.done());
offset += Bytecodes::Size(Bytecode::kLdaConstant, OperandScale::kSingle);
iterator.Advance();
......@@ -89,7 +91,8 @@ TEST_F(BytecodeArrayIteratorTest, IteratesBytecodeArray) {
CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaConstant);
CHECK_EQ(iterator.current_offset(), offset);
CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle);
CHECK(iterator.GetConstantForIndexOperand(0).is_identical_to(heap_num_1));
CHECK(iterator.GetConstantForIndexOperand(0).is_identical_to(
heap_num_1->value()));
CHECK(!iterator.done());
offset += Bytecodes::Size(Bytecode::kLdaConstant, OperandScale::kSingle);
iterator.Advance();
......
......@@ -23,7 +23,7 @@ namespace interpreter {
class BytecodeArrayWriterUnittest : public TestWithIsolateAndZone {
public:
BytecodeArrayWriterUnittest()
: constant_array_builder_(zone(), isolate()->factory()->the_hole_value()),
: constant_array_builder_(zone()),
bytecode_array_writer_(
zone(), &constant_array_builder_,
SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS) {}
......
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