Commit cc74437b authored by rmcilroy's avatar rmcilroy Committed by Commit bot

[interpreter] Fix nosnap build for interpreter table generation.

Moves the creation of the interpreter table early on during initialization
to ensure that even on nosnap builds it still gets allocated in the
first page.

BUG=v8:4280
LOG=N

Review URL: https://codereview.chromium.org/1278413002

Cr-Commit-Position: refs/heads/master@{#30096}
parent 1b1de2d2
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "src/heap/objects-visiting.h" #include "src/heap/objects-visiting.h"
#include "src/heap/store-buffer.h" #include "src/heap/store-buffer.h"
#include "src/heap-profiler.h" #include "src/heap-profiler.h"
#include "src/interpreter/interpreter.h"
#include "src/runtime-profiler.h" #include "src/runtime-profiler.h"
#include "src/scopeinfo.h" #include "src/scopeinfo.h"
#include "src/snapshot/natives.h" #include "src/snapshot/natives.h"
...@@ -3363,7 +3364,9 @@ void Heap::CreateInitialObjects() { ...@@ -3363,7 +3364,9 @@ void Heap::CreateInitialObjects() {
set_weak_stack_trace_list(Smi::FromInt(0)); set_weak_stack_trace_list(Smi::FromInt(0));
// Will be filled in by Interpreter::Initialize(). // Will be filled in by Interpreter::Initialize().
set_interpreter_table(empty_fixed_array()); set_interpreter_table(
*interpreter::Interpreter::CreateUninitializedInterpreterTable(
isolate()));
set_allocation_sites_scratchpad( set_allocation_sites_scratchpad(
*factory->NewFixedArray(kAllocationSiteScratchpadSize, TENURED)); *factory->NewFixedArray(kAllocationSiteScratchpadSize, TENURED));
...@@ -3415,7 +3418,6 @@ bool Heap::RootCanBeWrittenAfterInitialization(Heap::RootListIndex root_index) { ...@@ -3415,7 +3418,6 @@ bool Heap::RootCanBeWrittenAfterInitialization(Heap::RootListIndex root_index) {
case kWeakObjectToCodeTableRootIndex: case kWeakObjectToCodeTableRootIndex:
case kRetainedMapsRootIndex: case kRetainedMapsRootIndex:
case kWeakStackTraceListRootIndex: case kWeakStackTraceListRootIndex:
case kInterpreterTableRootIndex:
// Smi values // Smi values
#define SMI_ENTRY(type, name, Name) case k##Name##RootIndex: #define SMI_ENTRY(type, name, Name) case k##Name##RootIndex:
SMI_ROOT_LIST(SMI_ENTRY) SMI_ROOT_LIST(SMI_ENTRY)
......
...@@ -1024,10 +1024,6 @@ class Heap { ...@@ -1024,10 +1024,6 @@ class Heap {
roots_[kMaterializedObjectsRootIndex] = objects; roots_[kMaterializedObjectsRootIndex] = objects;
} }
void public_set_interpreter_table(FixedArray* table) {
roots_[kInterpreterTableRootIndex] = table;
}
// Generated code can embed this address to get access to the roots. // Generated code can embed this address to get access to the roots.
Object** roots_array_start() { return roots_; } Object** roots_array_start() { return roots_; }
......
...@@ -18,36 +18,55 @@ using compiler::Node; ...@@ -18,36 +18,55 @@ using compiler::Node;
#define __ assembler-> #define __ assembler->
Interpreter::Interpreter(Isolate* isolate) : isolate_(isolate) {} Interpreter::Interpreter(Isolate* isolate)
: isolate_(isolate) {}
// static
Handle<FixedArray> Interpreter::CreateUninitializedInterpreterTable(
Isolate* isolate) {
Handle<FixedArray> handler_table = isolate->factory()->NewFixedArray(
static_cast<int>(Bytecode::kLast) + 1, TENURED);
// We rely on the interpreter handler table being immovable, so check that
// it was allocated on the first page (which is always immovable).
DCHECK(isolate->heap()->old_space()->FirstPage()->Contains(
handler_table->address()));
for (int i = 0; i < static_cast<int>(Bytecode::kLast); i++) {
handler_table->set(i, isolate->builtins()->builtin(Builtins::kIllegal));
}
return handler_table;
}
void Interpreter::Initialize(bool create_heap_objects) { void Interpreter::Initialize() {
DCHECK(FLAG_ignition); DCHECK(FLAG_ignition);
if (create_heap_objects) { Handle<FixedArray> handler_table = isolate_->factory()->interpreter_table();
if (!IsInterpreterTableInitialized(handler_table)) {
Zone zone; Zone zone;
HandleScope scope(isolate_); HandleScope scope(isolate_);
Handle<FixedArray> handler_table = isolate_->factory()->NewFixedArray(
static_cast<int>(Bytecode::kLast) + 1, TENURED); #define GENERATE_CODE(Name, ...) \
// We rely on the interpreter handler table being immovable, so check that { \
// it was allocated on the first page (which is always immovable). compiler::InterpreterAssembler assembler(isolate_, &zone, \
DCHECK(isolate_->heap()->old_space()->FirstPage()->Contains( Bytecode::k##Name); \
handler_table->address())); Do##Name(&assembler); \
isolate_->heap()->public_set_interpreter_table(*handler_table); Handle<Code> code = assembler.GenerateCode(); \
handler_table->set(static_cast<int>(Bytecode::k##Name), *code); \
#define GENERATE_CODE(Name, ...) \ }
{ \
compiler::InterpreterAssembler assembler(isolate_, &zone, \
Bytecode::k##Name); \
Do##Name(&assembler); \
Handle<Code> code = assembler.GenerateCode(); \
handler_table->set(static_cast<int>(Bytecode::k##Name), *code); \
}
BYTECODE_LIST(GENERATE_CODE) BYTECODE_LIST(GENERATE_CODE)
#undef GENERATE_CODE #undef GENERATE_CODE
} }
} }
bool Interpreter::IsInterpreterTableInitialized(
Handle<FixedArray> handler_table) {
DCHECK(handler_table->length() == static_cast<int>(Bytecode::kLast) + 1);
return handler_table->get(0) ==
isolate_->builtins()->builtin(Builtins::kIllegal);
}
// LdaZero // LdaZero
// //
// Load literal '0' into the accumulator. // Load literal '0' into the accumulator.
......
...@@ -28,7 +28,13 @@ class Interpreter { ...@@ -28,7 +28,13 @@ class Interpreter {
explicit Interpreter(Isolate* isolate); explicit Interpreter(Isolate* isolate);
virtual ~Interpreter() {} virtual ~Interpreter() {}
void Initialize(bool create_heap_objects); // Creates an uninitialized interpreter handler table, where each handler
// points to the Illegal builtin.
static Handle<FixedArray> CreateUninitializedInterpreterTable(
Isolate* isolate);
// Initializes the interpreter.
void Initialize();
private: private:
// Bytecode handler generator functions. // Bytecode handler generator functions.
...@@ -37,6 +43,8 @@ class Interpreter { ...@@ -37,6 +43,8 @@ class Interpreter {
BYTECODE_LIST(DECLARE_BYTECODE_HANDLER_GENERATOR) BYTECODE_LIST(DECLARE_BYTECODE_HANDLER_GENERATOR)
#undef DECLARE_BYTECODE_HANDLER_GENERATOR #undef DECLARE_BYTECODE_HANDLER_GENERATOR
bool IsInterpreterTableInitialized(Handle<FixedArray> handler_table);
Isolate* isolate_; Isolate* isolate_;
DISALLOW_COPY_AND_ASSIGN(Interpreter); DISALLOW_COPY_AND_ASSIGN(Interpreter);
......
...@@ -2167,7 +2167,7 @@ bool Isolate::Init(Deserializer* des) { ...@@ -2167,7 +2167,7 @@ bool Isolate::Init(Deserializer* des) {
builtins_.SetUp(this, create_heap_objects); builtins_.SetUp(this, create_heap_objects);
if (FLAG_ignition) { if (FLAG_ignition) {
interpreter_->Initialize(create_heap_objects); interpreter_->Initialize();
} }
if (FLAG_log_internal_timer_events) { if (FLAG_log_internal_timer_events) {
......
...@@ -35,13 +35,8 @@ class InterpreterTester { ...@@ -35,13 +35,8 @@ class InterpreterTester {
InterpreterTester(Isolate* isolate, Handle<BytecodeArray> bytecode) InterpreterTester(Isolate* isolate, Handle<BytecodeArray> bytecode)
: isolate_(isolate), function_(GetBytecodeFunction(isolate, bytecode)) { : isolate_(isolate), function_(GetBytecodeFunction(isolate, bytecode)) {
i::FLAG_ignition = true; i::FLAG_ignition = true;
Handle<FixedArray> empty_array = isolate->factory()->empty_fixed_array(); // Ensure handler table is generated.
Handle<FixedArray> interpreter_table = isolate->interpreter()->Initialize();
isolate->factory()->interpreter_table();
if (interpreter_table.is_identical_to(empty_array)) {
// Ensure handler table is generated.
isolate->interpreter()->Initialize(true);
}
} }
virtual ~InterpreterTester() {} virtual ~InterpreterTester() {}
......
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