Commit 1c2c2f43 authored by rmcilroy's avatar rmcilroy Committed by Commit bot

[Interpreter] Avoid accessing Isolate from during bytecode generation.

Removes all accesses to the Isolate during bytecode generation and the
bytecode pipeline. Adds an DisallowIsolateAccessScope which is used to
enforce this invariant within the BytecodeGenerator.

BUG=v8:5203

Review-Url: https://codereview.chromium.org/2242193002
Cr-Commit-Position: refs/heads/master@{#38716}
parent ece2f108
......@@ -411,8 +411,15 @@ class Scope: public ZoneObject {
// 'this' is bound, and what determines the function kind.
DeclarationScope* GetReceiverScope();
// Creates a scope info if it doesn't already exist.
Handle<ScopeInfo> GetScopeInfo(Isolate* isolate);
// GetScopeInfo() must have been called once to create the ScopeInfo.
Handle<ScopeInfo> scope_info() {
DCHECK(!scope_info_.is_null());
return scope_info_;
}
// ---------------------------------------------------------------------------
// Strict mode support.
bool IsDeclared(const AstRawString* name) {
......
......@@ -21,17 +21,16 @@ BytecodeArrayBuilder::BytecodeArrayBuilder(
Isolate* isolate, Zone* zone, int parameter_count, int context_count,
int locals_count, FunctionLiteral* literal,
SourcePositionTableBuilder::RecordingMode source_position_mode)
: isolate_(isolate),
zone_(zone),
: zone_(zone),
bytecode_generated_(false),
constant_array_builder_(isolate, zone),
handler_table_builder_(isolate, zone),
constant_array_builder_(zone, isolate->factory()->the_hole_value()),
handler_table_builder_(zone),
return_seen_in_block_(false),
parameter_count_(parameter_count),
local_register_count_(locals_count),
context_register_count_(context_count),
temporary_allocator_(zone, fixed_register_count()),
bytecode_array_writer_(isolate, zone, &constant_array_builder_,
bytecode_array_writer_(zone, &constant_array_builder_,
source_position_mode),
pipeline_(&bytecode_array_writer_) {
DCHECK_GE(parameter_count_, 0);
......@@ -75,14 +74,15 @@ bool BytecodeArrayBuilder::RegisterIsParameterOrLocal(Register reg) const {
return reg.is_parameter() || reg.index() < locals_count();
}
Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray() {
Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray(Isolate* isolate) {
DCHECK(return_seen_in_block_);
DCHECK(!bytecode_generated_);
bytecode_generated_ = true;
Handle<FixedArray> handler_table = handler_table_builder()->ToHandlerTable();
return pipeline_->ToBytecodeArray(fixed_register_count(), parameter_count(),
handler_table);
Handle<FixedArray> handler_table =
handler_table_builder()->ToHandlerTable(isolate);
return pipeline_->ToBytecodeArray(isolate, fixed_register_count(),
parameter_count(), handler_table);
}
namespace {
......
......@@ -34,7 +34,7 @@ class BytecodeArrayBuilder final : public ZoneObject {
SourcePositionTableBuilder::RecordingMode source_position_mode =
SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS);
Handle<BytecodeArray> ToBytecodeArray();
Handle<BytecodeArray> ToBytecodeArray(Isolate* isolate);
// Get the number of parameters expected by function.
int parameter_count() const {
......@@ -363,7 +363,6 @@ class BytecodeArrayBuilder final : public ZoneObject {
void LeaveBasicBlock() { return_seen_in_block_ = false; }
Isolate* isolate() const { return isolate_; }
BytecodeArrayWriter* bytecode_array_writer() {
return &bytecode_array_writer_;
}
......@@ -378,7 +377,6 @@ class BytecodeArrayBuilder final : public ZoneObject {
return &handler_table_builder_;
}
Isolate* isolate_;
Zone* zone_;
bool bytecode_generated_;
ConstantArrayBuilder constant_array_builder_;
......
......@@ -18,10 +18,9 @@ STATIC_CONST_MEMBER_DEFINITION const size_t
BytecodeArrayWriter::kMaxSizeOfPackedBytecode;
BytecodeArrayWriter::BytecodeArrayWriter(
Isolate* isolate, Zone* zone, ConstantArrayBuilder* constant_array_builder,
Zone* zone, ConstantArrayBuilder* constant_array_builder,
SourcePositionTableBuilder::RecordingMode source_position_mode)
: isolate_(isolate),
bytecodes_(zone),
: bytecodes_(zone),
max_register_count_(0),
unbound_jumps_(0),
source_position_table_builder_(zone, source_position_mode),
......@@ -32,7 +31,7 @@ BytecodeArrayWriter::~BytecodeArrayWriter() {}
// override
Handle<BytecodeArray> BytecodeArrayWriter::ToBytecodeArray(
int fixed_register_count, int parameter_count,
Isolate* isolate, int fixed_register_count, int parameter_count,
Handle<FixedArray> handler_table) {
DCHECK_EQ(0, unbound_jumps_);
......@@ -43,14 +42,15 @@ Handle<BytecodeArray> BytecodeArrayWriter::ToBytecodeArray(
int frame_size_for_locals = fixed_register_count * kPointerSize;
int frame_size_used = max_register_count() * kPointerSize;
int frame_size = std::max(frame_size_for_locals, frame_size_used);
Handle<FixedArray> constant_pool = constant_array_builder()->ToFixedArray();
Handle<BytecodeArray> bytecode_array = isolate_->factory()->NewBytecodeArray(
Handle<FixedArray> constant_pool =
constant_array_builder()->ToFixedArray(isolate);
Handle<BytecodeArray> bytecode_array = isolate->factory()->NewBytecodeArray(
bytecode_size, &bytecodes()->front(), frame_size, parameter_count,
constant_pool);
bytecode_array->set_handler_table(*handler_table);
Handle<ByteArray> source_position_table =
source_position_table_builder()->ToSourcePositionTable(
isolate(), Handle<AbstractCode>::cast(bytecode_array));
isolate, Handle<AbstractCode>::cast(bytecode_array));
bytecode_array->set_source_position_table(*source_position_table);
return bytecode_array;
}
......
......@@ -23,8 +23,7 @@ class ConstantArrayBuilder;
class BytecodeArrayWriter final : public BytecodePipelineStage {
public:
BytecodeArrayWriter(
Isolate* isolate, Zone* zone,
ConstantArrayBuilder* constant_array_builder,
Zone* zone, ConstantArrayBuilder* constant_array_builder,
SourcePositionTableBuilder::RecordingMode source_position_mode);
virtual ~BytecodeArrayWriter();
......@@ -34,7 +33,7 @@ class BytecodeArrayWriter final : public BytecodePipelineStage {
void BindLabel(BytecodeLabel* label) override;
void BindLabel(const BytecodeLabel& target, BytecodeLabel* label) override;
Handle<BytecodeArray> ToBytecodeArray(
int fixed_register_count, int parameter_count,
Isolate* isolate, int fixed_register_count, int parameter_count,
Handle<FixedArray> handler_table) override;
private:
......@@ -63,7 +62,6 @@ class BytecodeArrayWriter final : public BytecodePipelineStage {
void EmitJump(BytecodeNode* node, BytecodeLabel* label);
void UpdateSourcePositionTable(const BytecodeNode* const node);
Isolate* isolate() { return isolate_; }
ZoneVector<uint8_t>* bytecodes() { return &bytecodes_; }
SourcePositionTableBuilder* source_position_table_builder() {
return &source_position_table_builder_;
......@@ -73,7 +71,6 @@ class BytecodeArrayWriter final : public BytecodePipelineStage {
}
int max_register_count() { return max_register_count_; }
Isolate* isolate_;
ZoneVector<uint8_t> bytecodes_;
int max_register_count_;
int unbound_jumps_;
......
......@@ -14,10 +14,10 @@ BytecodeDeadCodeOptimizer::BytecodeDeadCodeOptimizer(
// override
Handle<BytecodeArray> BytecodeDeadCodeOptimizer::ToBytecodeArray(
int fixed_register_count, int parameter_count,
Isolate* isolate, int fixed_register_count, int parameter_count,
Handle<FixedArray> handler_table) {
return next_stage_->ToBytecodeArray(fixed_register_count, parameter_count,
handler_table);
return next_stage_->ToBytecodeArray(isolate, fixed_register_count,
parameter_count, handler_table);
}
// override
......
......@@ -24,7 +24,7 @@ class BytecodeDeadCodeOptimizer final : public BytecodePipelineStage,
void BindLabel(BytecodeLabel* label) override;
void BindLabel(const BytecodeLabel& target, BytecodeLabel* label) override;
Handle<BytecodeArray> ToBytecodeArray(
int fixed_register_count, int parameter_count,
Isolate* isolate, int fixed_register_count, int parameter_count,
Handle<FixedArray> handler_table) override;
private:
......
......@@ -600,9 +600,8 @@ class BytecodeGenerator::TestResultScope final : public ExpressionResultScope {
// Used to build a list of global declaration initial value pairs.
class BytecodeGenerator::GlobalDeclarationsBuilder final : public ZoneObject {
public:
GlobalDeclarationsBuilder(Isolate* isolate, Zone* zone)
: isolate_(isolate),
declarations_(0, zone),
explicit GlobalDeclarationsBuilder(Zone* zone)
: declarations_(0, zone),
constant_pool_entry_(0),
has_constant_pool_entry_(false) {}
......@@ -619,14 +618,14 @@ class BytecodeGenerator::GlobalDeclarationsBuilder final : public ZoneObject {
Handle<FixedArray> AllocateDeclarationPairs(CompilationInfo* info) {
DCHECK(has_constant_pool_entry_);
int array_index = 0;
Handle<FixedArray> pairs = isolate_->factory()->NewFixedArray(
Handle<FixedArray> pairs = info->isolate()->factory()->NewFixedArray(
static_cast<int>(declarations_.size() * 2), TENURED);
for (std::pair<FeedbackVectorSlot, FunctionLiteral*> declaration :
declarations_) {
FunctionLiteral* func = declaration.second;
Handle<Object> initial_value;
if (func == nullptr) {
initial_value = isolate_->factory()->undefined_value();
initial_value = info->isolate()->factory()->undefined_value();
} else {
initial_value =
Compiler::GetSharedFunctionInfo(func, info->script(), info);
......@@ -657,15 +656,13 @@ class BytecodeGenerator::GlobalDeclarationsBuilder final : public ZoneObject {
bool empty() { return declarations_.empty(); }
private:
Isolate* isolate_;
ZoneVector<std::pair<FeedbackVectorSlot, FunctionLiteral*>> declarations_;
size_t constant_pool_entry_;
bool has_constant_pool_entry_;
};
BytecodeGenerator::BytecodeGenerator(CompilationInfo* info)
: isolate_(info->isolate()),
zone_(info->zone()),
: zone_(info->zone()),
builder_(new (zone()) BytecodeArrayBuilder(
info->isolate(), info->zone(), info->num_parameters_including_this(),
info->scope()->MaxNestedContextChainLength(),
......@@ -673,8 +670,7 @@ BytecodeGenerator::BytecodeGenerator(CompilationInfo* info)
info->SourcePositionRecordingMode())),
info_(info),
scope_(info->scope()),
globals_builder_(new (zone()) GlobalDeclarationsBuilder(info->isolate(),
info->zone())),
globals_builder_(new (zone()) GlobalDeclarationsBuilder(info->zone())),
global_declarations_(0, info->zone()),
function_literals_(0, info->zone()),
native_function_literals_(0, info->zone()),
......@@ -684,24 +680,26 @@ BytecodeGenerator::BytecodeGenerator(CompilationInfo* info)
register_allocator_(nullptr),
generator_resume_points_(info->literal()->yield_count(), info->zone()),
generator_state_(),
loop_depth_(0) {
InitializeAstVisitor(isolate()->stack_guard()->real_climit());
loop_depth_(0),
home_object_symbol_(info->isolate()->factory()->home_object_symbol()),
prototype_string_(info->isolate()->factory()->prototype_string()) {
InitializeAstVisitor(info->isolate()->stack_guard()->real_climit());
}
Handle<BytecodeArray> BytecodeGenerator::MakeBytecode() {
Handle<BytecodeArray> BytecodeGenerator::MakeBytecode(Isolate* isolate) {
// Create an inner HandleScope to avoid unnecessarily canonicalizing handles
// created as part of bytecode finalization.
HandleScope scope(isolate());
HandleScope scope(isolate);
GenerateBytecode();
FinalizeBytecode();
FinalizeBytecode(isolate);
if (HasStackOverflow()) return Handle<BytecodeArray>();
return scope.CloseAndEscape(builder()->ToBytecodeArray());
return scope.CloseAndEscape(builder()->ToBytecodeArray(isolate));
}
void BytecodeGenerator::FinalizeBytecode() {
void BytecodeGenerator::FinalizeBytecode(Isolate* isolate) {
// Build global declaration pair arrays.
for (GlobalDeclarationsBuilder* globals_builder : global_declarations_) {
Handle<FixedArray> declarations =
......@@ -1025,7 +1023,7 @@ void BytecodeGenerator::VisitDeclarations(
// Push and reset globals builder.
global_declarations_.push_back(globals_builder());
globals_builder_ = new (zone()) GlobalDeclarationsBuilder(isolate(), zone());
globals_builder_ = new (zone()) GlobalDeclarationsBuilder(zone());
}
void BytecodeGenerator::VisitStatements(ZoneList<Statement*>* statements) {
......@@ -1497,11 +1495,10 @@ void BytecodeGenerator::VisitClassLiteral(ClassLiteral* expr) {
register_allocator()->PrepareForConsecutiveAllocations(2);
Register literal = register_allocator()->NextConsecutiveRegister();
Register prototype = register_allocator()->NextConsecutiveRegister();
Handle<String> name = isolate()->factory()->prototype_string();
FeedbackVectorSlot slot = expr->PrototypeSlot();
builder()
->StoreAccumulatorInRegister(literal)
.LoadNamedProperty(literal, name, feedback_index(slot))
.LoadNamedProperty(literal, prototype_string(), feedback_index(slot))
.StoreAccumulatorInRegister(prototype);
VisitClassLiteralProperties(expr, literal, prototype);
......@@ -1619,7 +1616,7 @@ void BytecodeGenerator::VisitClassLiteralStaticPrototypeWithComputedName(
Register key) {
BytecodeLabel done;
builder()
->LoadLiteral(isolate()->factory()->prototype_string())
->LoadLiteral(prototype_string())
.CompareOperation(Token::Value::EQ_STRICT, key)
.JumpIfFalse(&done)
.CallRuntime(Runtime::kThrowStaticPrototypeError, Register(0), 0)
......@@ -3172,7 +3169,7 @@ void BytecodeGenerator::VisitNewLocalFunctionContext() {
builder()
->LoadAccumulatorWithRegister(Register::function_closure())
.StoreAccumulatorInRegister(closure)
.LoadLiteral(scope->GetScopeInfo(isolate()))
.LoadLiteral(scope->scope_info())
.StoreAccumulatorInRegister(scope_info)
.CallRuntime(Runtime::kNewScriptContext, closure, 2);
} else {
......@@ -3215,8 +3212,7 @@ void BytecodeGenerator::VisitNewLocalBlockContext(Scope* scope) {
DCHECK(scope->is_block_scope());
VisitFunctionClosureForContext();
builder()->CreateBlockContext(scope->GetScopeInfo(isolate()));
builder()->CreateBlockContext(scope->scope_info());
execution_result()->SetResultInAccumulator();
}
......@@ -3271,11 +3267,11 @@ void BytecodeGenerator::VisitSetHomeObject(Register value, Register home_object,
int slot_number) {
Expression* expr = property->value();
if (FunctionLiteral::NeedsHomeObject(expr)) {
Handle<Name> name = isolate()->factory()->home_object_symbol();
FeedbackVectorSlot slot = property->GetSlot(slot_number);
builder()
->LoadAccumulatorWithRegister(home_object)
.StoreNamedProperty(value, name, feedback_index(slot), language_mode());
.StoreNamedProperty(value, home_object_symbol(), feedback_index(slot),
language_mode());
}
}
......
......@@ -24,7 +24,7 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
public:
explicit BytecodeGenerator(CompilationInfo* info);
Handle<BytecodeArray> MakeBytecode();
Handle<BytecodeArray> MakeBytecode(Isolate* isolate);
#define DECLARE_VISIT(type) void Visit##type(type* node);
AST_NODE_LIST(DECLARE_VISIT)
......@@ -54,7 +54,7 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
void GenerateBytecode();
void GenerateBytecodeBody();
void FinalizeBytecode();
void FinalizeBytecode(Isolate* isolate);
DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
......@@ -177,7 +177,6 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
void InitializeWithConsecutiveRegisters(Register (&registers)[N]);
inline BytecodeArrayBuilder* builder() const { return builder_; }
inline Isolate* isolate() const { return isolate_; }
inline Zone* zone() const { return zone_; }
inline DeclarationScope* scope() const { return scope_; }
inline CompilationInfo* info() const { return info_; }
......@@ -206,23 +205,31 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
inline LanguageMode language_mode() const;
int feedback_index(FeedbackVectorSlot slot) const;
Isolate* isolate_;
Handle<Name> home_object_symbol() const { return home_object_symbol_; }
Handle<Name> prototype_string() const { return prototype_string_; }
Zone* zone_;
BytecodeArrayBuilder* builder_;
CompilationInfo* info_;
DeclarationScope* scope_;
GlobalDeclarationsBuilder* globals_builder_;
ZoneVector<GlobalDeclarationsBuilder*> global_declarations_;
ZoneVector<std::pair<FunctionLiteral*, size_t>> function_literals_;
ZoneVector<std::pair<NativeFunctionLiteral*, size_t>>
native_function_literals_;
ControlScope* execution_control_;
ContextScope* execution_context_;
ExpressionResultScope* execution_result_;
RegisterAllocationScope* register_allocator_;
ZoneVector<BytecodeLabel> generator_resume_points_;
Register generator_state_;
int loop_depth_;
Handle<Name> home_object_symbol_;
Handle<Name> prototype_string_;
};
} // namespace interpreter
......
......@@ -19,11 +19,11 @@ BytecodePeepholeOptimizer::BytecodePeepholeOptimizer(
// override
Handle<BytecodeArray> BytecodePeepholeOptimizer::ToBytecodeArray(
int fixed_register_count, int parameter_count,
Isolate* isolate, int fixed_register_count, int parameter_count,
Handle<FixedArray> handler_table) {
Flush();
return next_stage_->ToBytecodeArray(fixed_register_count, parameter_count,
handler_table);
return next_stage_->ToBytecodeArray(isolate, fixed_register_count,
parameter_count, handler_table);
}
// override
......
......@@ -28,7 +28,7 @@ class BytecodePeepholeOptimizer final : public BytecodePipelineStage,
void BindLabel(BytecodeLabel* label) override;
void BindLabel(const BytecodeLabel& target, BytecodeLabel* label) override;
Handle<BytecodeArray> ToBytecodeArray(
int fixed_register_count, int parameter_count,
Isolate* isolate, int fixed_register_count, int parameter_count,
Handle<FixedArray> handler_table) override;
private:
......
......@@ -47,7 +47,7 @@ class BytecodePipelineStage {
// Flush the pipeline and generate a bytecode array.
virtual Handle<BytecodeArray> ToBytecodeArray(
int fixed_register_count, int parameter_count,
Isolate* isolate, int fixed_register_count, int parameter_count,
Handle<FixedArray> handler_table) = 0;
};
......
......@@ -208,11 +208,11 @@ BytecodeRegisterOptimizer::BytecodeRegisterOptimizer(
// override
Handle<BytecodeArray> BytecodeRegisterOptimizer::ToBytecodeArray(
int fixed_register_count, int parameter_count,
Isolate* isolate, int fixed_register_count, int parameter_count,
Handle<FixedArray> handler_table) {
FlushState();
return next_stage_->ToBytecodeArray(fixed_register_count, parameter_count,
handler_table);
return next_stage_->ToBytecodeArray(isolate, fixed_register_count,
parameter_count, handler_table);
}
// override
......
......@@ -31,7 +31,7 @@ class BytecodeRegisterOptimizer final : public BytecodePipelineStage,
void BindLabel(BytecodeLabel* label) override;
void BindLabel(const BytecodeLabel& target, BytecodeLabel* label) override;
Handle<BytecodeArray> ToBytecodeArray(
int fixed_register_count, int parameter_count,
Isolate* isolate, int fixed_register_count, int parameter_count,
Handle<FixedArray> handler_table) override;
private:
......
......@@ -70,11 +70,12 @@ STATIC_CONST_MEMBER_DEFINITION const size_t
STATIC_CONST_MEMBER_DEFINITION const size_t
ConstantArrayBuilder::k32BitCapacity;
ConstantArrayBuilder::ConstantArrayBuilder(Isolate* isolate, Zone* zone)
: isolate_(isolate),
constants_map_(zone),
ConstantArrayBuilder::ConstantArrayBuilder(Zone* zone,
Handle<Object> the_hole_value)
: constants_map_(zone),
smi_map_(zone),
smi_pairs_(zone) {
smi_pairs_(zone),
the_hole_value_(the_hole_value) {
idx_slice_[0] =
new (zone) ConstantArraySlice(zone, 0, k8BitCapacity, OperandSize::kByte);
idx_slice_[1] = new (zone) ConstantArraySlice(
......@@ -111,18 +112,18 @@ Handle<Object> ConstantArrayBuilder::At(size_t index) const {
return slice->At(index);
} else {
DCHECK_LT(index, slice->capacity());
return isolate_->factory()->the_hole_value();
return the_hole_value();
}
}
Handle<FixedArray> ConstantArrayBuilder::ToFixedArray() {
Handle<FixedArray> ConstantArrayBuilder::ToFixedArray(Isolate* isolate) {
// First insert reserved SMI values.
for (auto reserved_smi : smi_pairs_) {
InsertAllocatedEntry(reserved_smi.second,
handle(reserved_smi.first, isolate_));
handle(reserved_smi.first, isolate));
}
Handle<FixedArray> fixed_array = isolate_->factory()->NewFixedArray(
Handle<FixedArray> fixed_array = isolate->factory()->NewFixedArray(
static_cast<int>(size()), PretenureFlag::TENURED);
int array_index = 0;
for (const ConstantArraySlice* slice : idx_slice_) {
......@@ -144,7 +145,7 @@ Handle<FixedArray> ConstantArrayBuilder::ToFixedArray() {
std::min(static_cast<size_t>(fixed_array->length() - array_index),
slice->capacity() - slice->size());
for (size_t i = 0; i < padding; i++) {
fixed_array->set(array_index++, *isolate_->factory()->the_hole_value());
fixed_array->set(array_index++, *the_hole_value());
}
}
DCHECK_EQ(array_index, fixed_array->length());
......@@ -197,12 +198,12 @@ ConstantArrayBuilder::OperandSizeToSlice(OperandSize operand_size) const {
}
size_t ConstantArrayBuilder::AllocateEntry() {
return AllocateIndex(isolate_->factory()->the_hole_value());
return AllocateIndex(the_hole_value());
}
void ConstantArrayBuilder::InsertAllocatedEntry(size_t index,
Handle<Object> object) {
DCHECK_EQ(isolate_->heap()->the_hole_value(), *At(index));
DCHECK_EQ(the_hole_value().address(), At(index).address());
ConstantArraySlice* slice = IndexToSlice(index);
slice->InsertAt(index, object);
}
......
......@@ -32,10 +32,10 @@ class ConstantArrayBuilder final BASE_EMBEDDED {
static const size_t k32BitCapacity =
kMaxUInt32 - k16BitCapacity - k8BitCapacity + 1;
ConstantArrayBuilder(Isolate* isolate, Zone* zone);
ConstantArrayBuilder(Zone* zone, Handle<Object> the_hole_value);
// Generate a fixed array of constants based on inserted objects.
Handle<FixedArray> ToFixedArray();
Handle<FixedArray> ToFixedArray(Isolate* isolate);
// Returns the object in the constant pool array that at index
// |index|.
......@@ -105,11 +105,13 @@ class ConstantArrayBuilder final BASE_EMBEDDED {
ConstantArraySlice* IndexToSlice(size_t index) const;
ConstantArraySlice* OperandSizeToSlice(OperandSize operand_size) const;
Isolate* isolate_;
Handle<Object> the_hole_value() const { return the_hole_value_; }
ConstantArraySlice* idx_slice_[3];
ZoneMap<Address, index_t> constants_map_;
ZoneMap<Smi*, index_t> smi_map_;
ZoneVector<std::pair<Smi*, index_t>> smi_pairs_;
Handle<Object> the_hole_value_;
};
} // namespace interpreter
......
......@@ -13,13 +13,12 @@ namespace v8 {
namespace internal {
namespace interpreter {
HandlerTableBuilder::HandlerTableBuilder(Isolate* isolate, Zone* zone)
: isolate_(isolate), entries_(zone) {}
HandlerTableBuilder::HandlerTableBuilder(Zone* zone) : entries_(zone) {}
Handle<HandlerTable> HandlerTableBuilder::ToHandlerTable() {
Handle<HandlerTable> HandlerTableBuilder::ToHandlerTable(Isolate* isolate) {
int handler_table_size = static_cast<int>(entries_.size());
Handle<HandlerTable> table =
Handle<HandlerTable>::cast(isolate_->factory()->NewFixedArray(
Handle<HandlerTable>::cast(isolate->factory()->NewFixedArray(
HandlerTable::LengthForRange(handler_table_size), TENURED));
for (int i = 0; i < handler_table_size; ++i) {
Entry& entry = entries_[i];
......
......@@ -21,11 +21,11 @@ namespace interpreter {
// A helper class for constructing exception handler tables for the interpreter.
class HandlerTableBuilder final BASE_EMBEDDED {
public:
HandlerTableBuilder(Isolate* isolate, Zone* zone);
explicit HandlerTableBuilder(Zone* zone);
// Builds the actual handler table by copying the current values into a heap
// object. Any further mutations to the builder won't be reflected.
Handle<HandlerTable> ToHandlerTable();
Handle<HandlerTable> ToHandlerTable(Isolate* isolate);
// Creates a new handler table entry and returns a {hander_id} identifying the
// entry, so that it can be referenced by below setter functions.
......@@ -50,7 +50,6 @@ class HandlerTableBuilder final BASE_EMBEDDED {
HandlerTable::CatchPrediction catch_prediction_;
};
Isolate* isolate_;
ZoneVector<Entry> entries_;
DISALLOW_COPY_AND_ASSIGN(HandlerTableBuilder);
......
......@@ -157,7 +157,7 @@ bool Interpreter::MakeBytecode(CompilationInfo* info) {
#endif // DEBUG
BytecodeGenerator generator(info);
Handle<BytecodeArray> bytecodes = generator.MakeBytecode();
Handle<BytecodeArray> bytecodes = generator.MakeBytecode(info->isolate());
if (generator.HasStackOverflow()) return false;
......
......@@ -28,7 +28,7 @@ class InvokeIntrinsicHelper {
BytecodeArrayBuilder builder(isolate_, zone_, sizeof...(args), 0, 0);
builder.CallRuntime(function_id_, builder.Parameter(0), sizeof...(args))
.Return();
InterpreterTester tester(isolate_, builder.ToBytecodeArray());
InterpreterTester tester(isolate_, builder.ToBytecodeArray(isolate_));
auto callable = tester.GetCallable<A...>();
return callable(args...).ToHandleChecked();
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -376,7 +376,7 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) {
builder.Return();
// Generate BytecodeArray.
Handle<BytecodeArray> the_array = builder.ToBytecodeArray();
Handle<BytecodeArray> the_array = builder.ToBytecodeArray(isolate());
CHECK_EQ(the_array->frame_size(),
builder.fixed_and_temporary_register_count() * kPointerSize);
......@@ -465,7 +465,7 @@ TEST_F(BytecodeArrayBuilderTest, FrameSizesLookGood) {
}
builder.Return();
Handle<BytecodeArray> the_array = builder.ToBytecodeArray();
Handle<BytecodeArray> the_array = builder.ToBytecodeArray(isolate());
int total_registers = locals + contexts + temps;
CHECK_EQ(the_array->frame_size(), total_registers * kPointerSize);
}
......@@ -538,7 +538,7 @@ TEST_F(BytecodeArrayBuilderTest, Constants) {
.LoadLiteral(heap_num_2_copy)
.Return();
Handle<BytecodeArray> array = builder.ToBytecodeArray();
Handle<BytecodeArray> array = builder.ToBytecodeArray(isolate());
// Should only have one entry for each identical constant.
CHECK_EQ(array->constant_pool()->length(), 3);
}
......@@ -591,7 +591,7 @@ TEST_F(BytecodeArrayBuilderTest, ForwardJumps) {
builder.Bind(&far0).Bind(&far1).Bind(&far2).Bind(&far3).Bind(&far4);
builder.Return();
Handle<BytecodeArray> array = builder.ToBytecodeArray();
Handle<BytecodeArray> array = builder.ToBytecodeArray(isolate());
DCHECK_EQ(array->length(), 40 + kFarJumpDistance - 20 + 1);
BytecodeArrayIterator iterator(array);
......@@ -711,7 +711,7 @@ TEST_F(BytecodeArrayBuilderTest, BackwardJumps) {
builder.Bind(&end);
builder.Return();
Handle<BytecodeArray> array = builder.ToBytecodeArray();
Handle<BytecodeArray> array = builder.ToBytecodeArray(isolate());
BytecodeArrayIterator iterator(array);
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
CHECK_EQ(iterator.GetImmediateOperand(0), 0);
......@@ -806,7 +806,7 @@ TEST_F(BytecodeArrayBuilderTest, LabelReuse) {
.Bind(&after_jump1)
.Return();
Handle<BytecodeArray> array = builder.ToBytecodeArray();
Handle<BytecodeArray> array = builder.ToBytecodeArray(isolate());
BytecodeArrayIterator iterator(array);
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
CHECK_EQ(iterator.GetImmediateOperand(0), 2);
......@@ -839,7 +839,7 @@ TEST_F(BytecodeArrayBuilderTest, LabelAddressReuse) {
}
builder.Return();
Handle<BytecodeArray> array = builder.ToBytecodeArray();
Handle<BytecodeArray> array = builder.ToBytecodeArray(isolate());
BytecodeArrayIterator iterator(array);
for (int i = 0; i < kRepeats; i++) {
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
......
......@@ -62,7 +62,7 @@ TEST_F(BytecodeArrayIteratorTest, IteratesBytecodeArray) {
.Return();
// Test iterator sees the expected output from the builder.
BytecodeArrayIterator iterator(builder.ToBytecodeArray());
BytecodeArrayIterator iterator(builder.ToBytecodeArray(isolate()));
const int kPrefixByteSize = 1;
int offset = 0;
......
......@@ -22,9 +22,9 @@ namespace interpreter {
class BytecodeArrayWriterUnittest : public TestWithIsolateAndZone {
public:
BytecodeArrayWriterUnittest()
: constant_array_builder_(isolate(), zone()),
: constant_array_builder_(zone(), isolate()->factory()->the_hole_value()),
bytecode_array_writer_(
isolate(), zone(), &constant_array_builder_,
zone(), &constant_array_builder_,
SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS) {}
~BytecodeArrayWriterUnittest() override {}
......@@ -137,8 +137,8 @@ TEST_F(BytecodeArrayWriterUnittest, SimpleExample) {
CHECK_EQ(bytecodes()->at(i), bytes[i]);
}
Handle<BytecodeArray> bytecode_array =
writer()->ToBytecodeArray(0, 0, factory()->empty_fixed_array());
Handle<BytecodeArray> bytecode_array = writer()->ToBytecodeArray(
isolate(), 0, 0, factory()->empty_fixed_array());
CHECK_EQ(bytecodes()->size(), arraysize(bytes));
PositionTableEntry expected_positions[] = {
......@@ -235,8 +235,8 @@ TEST_F(BytecodeArrayWriterUnittest, ComplexExample) {
static_cast<int>(expected_bytes[i]));
}
Handle<BytecodeArray> bytecode_array =
writer()->ToBytecodeArray(0, 0, factory()->empty_fixed_array());
Handle<BytecodeArray> bytecode_array = writer()->ToBytecodeArray(
isolate(), 0, 0, factory()->empty_fixed_array());
SourcePositionTableIterator source_iterator(
bytecode_array->source_position_table());
for (size_t i = 0; i < arraysize(expected_positions); ++i) {
......
......@@ -32,7 +32,7 @@ class BytecodeDeadCodeOptimizerTest : public BytecodePipelineStage,
void BindLabel(BytecodeLabel* label) override {}
void BindLabel(const BytecodeLabel& target, BytecodeLabel* label) override {}
Handle<BytecodeArray> ToBytecodeArray(
int fixed_register_count, int parameter_count,
Isolate* isolate, int fixed_register_count, int parameter_count,
Handle<FixedArray> handle_table) override {
return Handle<BytecodeArray>();
}
......
......@@ -39,13 +39,14 @@ class BytecodePeepholeOptimizerTest : public BytecodePipelineStage,
void BindLabel(BytecodeLabel* label) override {}
void BindLabel(const BytecodeLabel& target, BytecodeLabel* label) override {}
Handle<BytecodeArray> ToBytecodeArray(
int fixed_register_count, int parameter_count,
Isolate* isolate, int fixed_register_count, int parameter_count,
Handle<FixedArray> handle_table) override {
return Handle<BytecodeArray>();
}
void Flush() {
optimizer()->ToBytecodeArray(0, 0, factory()->empty_fixed_array());
optimizer()->ToBytecodeArray(isolate(), 0, 0,
factory()->empty_fixed_array());
}
BytecodePeepholeOptimizer* optimizer() { return &peephole_optimizer_; }
......
......@@ -35,7 +35,7 @@ class BytecodeRegisterOptimizerTest : public BytecodePipelineStage,
void BindLabel(BytecodeLabel* label) override {}
void BindLabel(const BytecodeLabel& target, BytecodeLabel* label) override {}
Handle<BytecodeArray> ToBytecodeArray(
int fixed_register_count, int parameter_count,
Isolate* isolate, int fixed_register_count, int parameter_count,
Handle<FixedArray> handle_table) override {
return Handle<BytecodeArray>();
}
......
......@@ -30,7 +30,7 @@ STATIC_CONST_MEMBER_DEFINITION const size_t
TEST_F(ConstantArrayBuilderTest, AllocateAllEntries) {
CanonicalHandleScope canonical(isolate());
ConstantArrayBuilder builder(isolate(), zone());
ConstantArrayBuilder builder(zone(), isolate()->factory()->the_hole_value());
for (size_t i = 0; i < k16BitCapacity; i++) {
builder.Insert(handle(Smi::FromInt(static_cast<int>(i)), isolate()));
}
......@@ -42,14 +42,14 @@ TEST_F(ConstantArrayBuilderTest, AllocateAllEntries) {
TEST_F(ConstantArrayBuilderTest, ToFixedArray) {
CanonicalHandleScope canonical(isolate());
ConstantArrayBuilder builder(isolate(), zone());
ConstantArrayBuilder builder(zone(), isolate()->factory()->the_hole_value());
static const size_t kNumberOfElements = 37;
for (size_t i = 0; i < kNumberOfElements; i++) {
Handle<Object> object = isolate()->factory()->NewNumberFromSize(i);
builder.Insert(object);
CHECK(builder.At(i)->SameValue(*object));
}
Handle<FixedArray> constant_array = builder.ToFixedArray();
Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
CHECK_EQ(constant_array->length(), kNumberOfElements);
for (size_t i = 0; i < kNumberOfElements; i++) {
CHECK(constant_array->get(static_cast<int>(i))->SameValue(*builder.At(i)));
......@@ -58,14 +58,14 @@ TEST_F(ConstantArrayBuilderTest, ToFixedArray) {
TEST_F(ConstantArrayBuilderTest, ToLargeFixedArray) {
CanonicalHandleScope canonical(isolate());
ConstantArrayBuilder builder(isolate(), zone());
ConstantArrayBuilder builder(zone(), isolate()->factory()->the_hole_value());
static const size_t kNumberOfElements = 37373;
for (size_t i = 0; i < kNumberOfElements; i++) {
Handle<Object> object = isolate()->factory()->NewNumberFromSize(i);
builder.Insert(object);
CHECK(builder.At(i)->SameValue(*object));
}
Handle<FixedArray> constant_array = builder.ToFixedArray();
Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
CHECK_EQ(constant_array->length(), kNumberOfElements);
for (size_t i = 0; i < kNumberOfElements; i++) {
CHECK(constant_array->get(static_cast<int>(i))->SameValue(*builder.At(i)));
......@@ -74,13 +74,13 @@ TEST_F(ConstantArrayBuilderTest, ToLargeFixedArray) {
TEST_F(ConstantArrayBuilderTest, ToLargeFixedArrayWithReservations) {
CanonicalHandleScope canonical(isolate());
ConstantArrayBuilder builder(isolate(), zone());
ConstantArrayBuilder builder(zone(), isolate()->factory()->the_hole_value());
static const size_t kNumberOfElements = 37373;
for (size_t i = 0; i < kNumberOfElements; i++) {
builder.CommitReservedEntry(builder.CreateReservedEntry(),
Smi::FromInt(static_cast<int>(i)));
}
Handle<FixedArray> constant_array = builder.ToFixedArray();
Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
CHECK_EQ(constant_array->length(), kNumberOfElements);
for (size_t i = 0; i < kNumberOfElements; i++) {
CHECK(constant_array->get(static_cast<int>(i))->SameValue(*builder.At(i)));
......@@ -90,7 +90,8 @@ TEST_F(ConstantArrayBuilderTest, ToLargeFixedArrayWithReservations) {
TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithIdx8Reservations) {
CanonicalHandleScope canonical(isolate());
for (size_t reserved = 1; reserved < k8BitCapacity; reserved *= 3) {
ConstantArrayBuilder builder(isolate(), zone());
ConstantArrayBuilder builder(zone(),
isolate()->factory()->the_hole_value());
for (size_t i = 0; i < reserved; i++) {
OperandSize operand_size = builder.CreateReservedEntry();
CHECK(operand_size == OperandSize::kByte);
......@@ -135,7 +136,7 @@ TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithIdx8Reservations) {
CHECK_EQ(static_cast<int>(index), k8BitCapacity - reserved + i);
}
Handle<FixedArray> constant_array = builder.ToFixedArray();
Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
CHECK_EQ(constant_array->length(), 2 * k8BitCapacity + reserved);
// Check all committed values match expected
......@@ -155,7 +156,8 @@ TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithIdx8Reservations) {
TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithWideReservations) {
CanonicalHandleScope canonical(isolate());
for (size_t reserved = 1; reserved < k8BitCapacity; reserved *= 3) {
ConstantArrayBuilder builder(isolate(), zone());
ConstantArrayBuilder builder(zone(),
isolate()->factory()->the_hole_value());
for (size_t i = 0; i < k8BitCapacity; i++) {
builder.CommitReservedEntry(builder.CreateReservedEntry(),
Smi::FromInt(static_cast<int>(i)));
......@@ -185,7 +187,7 @@ TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithWideReservations) {
CHECK_EQ(builder.size(), i + 1);
}
Handle<FixedArray> constant_array = builder.ToFixedArray();
Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
CHECK_EQ(constant_array->length(), k8BitCapacity + reserved);
for (size_t i = 0; i < k8BitCapacity + reserved; i++) {
Object* value = constant_array->get(static_cast<int>(i));
......@@ -196,7 +198,7 @@ TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithWideReservations) {
TEST_F(ConstantArrayBuilderTest, GapFilledWhenLowReservationCommitted) {
CanonicalHandleScope canonical(isolate());
ConstantArrayBuilder builder(isolate(), zone());
ConstantArrayBuilder builder(zone(), isolate()->factory()->the_hole_value());
for (size_t i = 0; i < k8BitCapacity; i++) {
OperandSize operand_size = builder.CreateReservedEntry();
CHECK(OperandSize::kByte == operand_size);
......@@ -212,7 +214,7 @@ TEST_F(ConstantArrayBuilderTest, GapFilledWhenLowReservationCommitted) {
Smi::FromInt(static_cast<int>(i)));
CHECK_EQ(builder.size(), 2 * k8BitCapacity);
}
Handle<FixedArray> constant_array = builder.ToFixedArray();
Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
CHECK_EQ(constant_array->length(), 2 * k8BitCapacity);
for (size_t i = 0; i < k8BitCapacity; i++) {
Object* original = constant_array->get(static_cast<int>(k8BitCapacity + i));
......@@ -225,7 +227,7 @@ TEST_F(ConstantArrayBuilderTest, GapFilledWhenLowReservationCommitted) {
TEST_F(ConstantArrayBuilderTest, GapNotFilledWhenLowReservationDiscarded) {
CanonicalHandleScope canonical(isolate());
ConstantArrayBuilder builder(isolate(), zone());
ConstantArrayBuilder builder(zone(), isolate()->factory()->the_hole_value());
for (size_t i = 0; i < k8BitCapacity; i++) {
OperandSize operand_size = builder.CreateReservedEntry();
CHECK(OperandSize::kByte == operand_size);
......@@ -253,7 +255,7 @@ TEST_F(ConstantArrayBuilderTest, GapNotFilledWhenLowReservationDiscarded) {
TEST_F(ConstantArrayBuilderTest, HolesWithUnusedReservations) {
CanonicalHandleScope canonical(isolate());
static int kNumberOfHoles = 128;
ConstantArrayBuilder builder(isolate(), zone());
ConstantArrayBuilder builder(zone(), isolate()->factory()->the_hole_value());
for (int i = 0; i < kNumberOfHoles; ++i) {
CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kByte);
}
......@@ -262,7 +264,7 @@ TEST_F(ConstantArrayBuilderTest, HolesWithUnusedReservations) {
}
CHECK_EQ(builder.Insert(isolate()->factory()->NewNumber(256)), 256);
Handle<FixedArray> constant_array = builder.ToFixedArray();
Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
CHECK_EQ(constant_array->length(), 257);
for (int i = 128; i < 256; i++) {
CHECK(constant_array->get(i)->SameValue(
......@@ -276,7 +278,7 @@ TEST_F(ConstantArrayBuilderTest, HolesWithUnusedReservations) {
TEST_F(ConstantArrayBuilderTest, ReservationsAtAllScales) {
CanonicalHandleScope canonical(isolate());
ConstantArrayBuilder builder(isolate(), zone());
ConstantArrayBuilder builder(zone(), isolate()->factory()->the_hole_value());
for (int i = 0; i < 256; i++) {
CHECK_EQ(builder.CreateReservedEntry(), OperandSize::kByte);
}
......@@ -291,7 +293,7 @@ TEST_F(ConstantArrayBuilderTest, ReservationsAtAllScales) {
256);
CHECK_EQ(builder.CommitReservedEntry(OperandSize::kQuad, Smi::FromInt(3)),
65536);
Handle<FixedArray> constant_array = builder.ToFixedArray();
Handle<FixedArray> constant_array = builder.ToFixedArray(isolate());
CHECK_EQ(constant_array->length(), 65537);
int count = 1;
for (int i = 0; i < constant_array->length(); ++i) {
......@@ -307,7 +309,7 @@ TEST_F(ConstantArrayBuilderTest, ReservationsAtAllScales) {
TEST_F(ConstantArrayBuilderTest, AllocateEntriesWithFixedReservations) {
CanonicalHandleScope canonical(isolate());
ConstantArrayBuilder builder(isolate(), zone());
ConstantArrayBuilder builder(zone(), isolate()->factory()->the_hole_value());
for (size_t i = 0; i < k16BitCapacity; i++) {
if ((i % 2) == 0) {
CHECK_EQ(i, builder.AllocateEntry());
......
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