Commit fdf6c2b1 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[turbofan] Set {Code::stub_key} within the allocator.

This moves the initialization of the {Code::stub_key} field into the
allocator for {Code} objects, essentially making the field in question
immutable after allocation.

R=verwaest@chromium.org
BUG=v8:6792

Change-Id: I8ba2ffeea792d0d566995c08e3572ae63a7c1e94
Reviewed-on: https://chromium-review.googlesource.com/739141
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48971}
parent bfd4df03
...@@ -130,7 +130,7 @@ Handle<Code> PlatformCodeStub::GenerateCode() { ...@@ -130,7 +130,7 @@ Handle<Code> PlatformCodeStub::GenerateCode() {
// Copy the generated code into a heap object. // Copy the generated code into a heap object.
Handle<Code> new_object = factory->NewCode( Handle<Code> new_object = factory->NewCode(
desc, Code::STUB, masm.CodeObject(), table, MaybeHandle<ByteArray>(), desc, Code::STUB, masm.CodeObject(), table, MaybeHandle<ByteArray>(),
DeoptimizationData::Empty(isolate()), NeedsImmovableCode()); DeoptimizationData::Empty(isolate()), NeedsImmovableCode(), GetKey());
return new_object; return new_object;
} }
...@@ -150,7 +150,7 @@ Handle<Code> CodeStub::GetCode() { ...@@ -150,7 +150,7 @@ Handle<Code> CodeStub::GetCode() {
CanonicalHandleScope canonical(isolate()); CanonicalHandleScope canonical(isolate());
Handle<Code> new_object = GenerateCode(); Handle<Code> new_object = GenerateCode();
new_object->set_stub_key(GetKey()); DCHECK_EQ(GetKey(), new_object->stub_key());
RecordCodeGeneration(new_object); RecordCodeGeneration(new_object);
#ifdef ENABLE_DISASSEMBLER #ifdef ENABLE_DISASSEMBLER
...@@ -302,7 +302,7 @@ Handle<Code> TurboFanCodeStub::GenerateCode() { ...@@ -302,7 +302,7 @@ Handle<Code> TurboFanCodeStub::GenerateCode() {
Zone zone(isolate()->allocator(), ZONE_NAME); Zone zone(isolate()->allocator(), ZONE_NAME);
CallInterfaceDescriptor descriptor(GetCallInterfaceDescriptor()); CallInterfaceDescriptor descriptor(GetCallInterfaceDescriptor());
compiler::CodeAssemblerState state(isolate(), &zone, descriptor, Code::STUB, compiler::CodeAssemblerState state(isolate(), &zone, descriptor, Code::STUB,
name); name, 1, GetKey());
GenerateAssembly(&state); GenerateAssembly(&state);
return compiler::CodeAssembler::GenerateCode(&state); return compiler::CodeAssembler::GenerateCode(&state);
} }
......
...@@ -277,11 +277,6 @@ class CodeStub : public ZoneObject { ...@@ -277,11 +277,6 @@ class CodeStub : public ZoneObject {
void GenerateAssembly(compiler::CodeAssemblerState* state) const override; \ void GenerateAssembly(compiler::CodeAssemblerState* state) const override; \
DEFINE_CODE_STUB(NAME, SUPER) DEFINE_CODE_STUB(NAME, SUPER)
#define DEFINE_HANDLER_CODE_STUB(NAME, SUPER) \
public: \
Handle<Code> GenerateCode() override; \
DEFINE_CODE_STUB(NAME, SUPER)
#define DEFINE_CALL_INTERFACE_DESCRIPTOR(NAME) \ #define DEFINE_CALL_INTERFACE_DESCRIPTOR(NAME) \
public: \ public: \
typedef NAME##Descriptor Descriptor; \ typedef NAME##Descriptor Descriptor; \
...@@ -1093,7 +1088,6 @@ class StoreBufferOverflowStub : public PlatformCodeStub { ...@@ -1093,7 +1088,6 @@ class StoreBufferOverflowStub : public PlatformCodeStub {
#undef DEFINE_CALL_INTERFACE_DESCRIPTOR #undef DEFINE_CALL_INTERFACE_DESCRIPTOR
#undef DEFINE_PLATFORM_CODE_STUB #undef DEFINE_PLATFORM_CODE_STUB
#undef DEFINE_HANDLER_CODE_STUB
#undef DEFINE_CODE_STUB #undef DEFINE_CODE_STUB
#undef DEFINE_CODE_STUB_BASE #undef DEFINE_CODE_STUB_BASE
......
...@@ -67,8 +67,10 @@ CompilationInfo::CompilationInfo(Vector<const char> debug_name, ...@@ -67,8 +67,10 @@ CompilationInfo::CompilationInfo(Vector<const char> debug_name,
Isolate* isolate, Zone* zone) Isolate* isolate, Zone* zone)
: isolate_(isolate), : isolate_(isolate),
literal_(nullptr), literal_(nullptr),
source_range_map_(nullptr),
flags_(0), flags_(0),
code_kind_(code_kind), code_kind_(code_kind),
stub_key_(0),
mode_(mode), mode_(mode),
osr_offset_(BailoutId::None()), osr_offset_(BailoutId::None()),
feedback_vector_spec_(zone), feedback_vector_spec_(zone),
......
...@@ -88,6 +88,8 @@ class V8_EXPORT_PRIVATE CompilationInfo final { ...@@ -88,6 +88,8 @@ class V8_EXPORT_PRIVATE CompilationInfo final {
Handle<JSFunction> closure() const { return closure_; } Handle<JSFunction> closure() const { return closure_; }
Handle<Code> code() const { return code_; } Handle<Code> code() const { return code_; }
Code::Kind code_kind() const { return code_kind_; } Code::Kind code_kind() const { return code_kind_; }
uint32_t stub_key() const { return stub_key_; }
void set_stub_key(uint32_t stub_key) { stub_key_ = stub_key; }
BailoutId osr_offset() const { return osr_offset_; } BailoutId osr_offset() const { return osr_offset_; }
JavaScriptFrame* osr_frame() const { return osr_frame_; } JavaScriptFrame* osr_frame() const { return osr_frame_; }
int num_parameters() const; int num_parameters() const;
...@@ -281,6 +283,7 @@ class V8_EXPORT_PRIVATE CompilationInfo final { ...@@ -281,6 +283,7 @@ class V8_EXPORT_PRIVATE CompilationInfo final {
unsigned flags_; unsigned flags_;
Code::Kind code_kind_; Code::Kind code_kind_;
uint32_t stub_key_;
Handle<SharedFunctionInfo> shared_info_; Handle<SharedFunctionInfo> shared_info_;
......
...@@ -56,14 +56,14 @@ static_assert( ...@@ -56,14 +56,14 @@ static_assert(
CodeAssemblerState::CodeAssemblerState( CodeAssemblerState::CodeAssemblerState(
Isolate* isolate, Zone* zone, const CallInterfaceDescriptor& descriptor, Isolate* isolate, Zone* zone, const CallInterfaceDescriptor& descriptor,
Code::Kind kind, const char* name, size_t result_size) Code::Kind kind, const char* name, size_t result_size, uint32_t stub_key)
: CodeAssemblerState( : CodeAssemblerState(
isolate, zone, isolate, zone,
Linkage::GetStubCallDescriptor( Linkage::GetStubCallDescriptor(
isolate, zone, descriptor, descriptor.GetStackParameterCount(), isolate, zone, descriptor, descriptor.GetStackParameterCount(),
CallDescriptor::kNoFlags, Operator::kNoProperties, CallDescriptor::kNoFlags, Operator::kNoProperties,
MachineType::AnyTagged(), result_size), MachineType::AnyTagged(), result_size),
kind, name) {} kind, name, stub_key) {}
CodeAssemblerState::CodeAssemblerState(Isolate* isolate, Zone* zone, CodeAssemblerState::CodeAssemblerState(Isolate* isolate, Zone* zone,
int parameter_count, Code::Kind kind, int parameter_count, Code::Kind kind,
...@@ -74,11 +74,12 @@ CodeAssemblerState::CodeAssemblerState(Isolate* isolate, Zone* zone, ...@@ -74,11 +74,12 @@ CodeAssemblerState::CodeAssemblerState(Isolate* isolate, Zone* zone,
kind == Code::BUILTIN kind == Code::BUILTIN
? CallDescriptor::kPushArgumentCount ? CallDescriptor::kPushArgumentCount
: CallDescriptor::kNoFlags), : CallDescriptor::kNoFlags),
kind, name) {} kind, name, 0) {}
CodeAssemblerState::CodeAssemblerState(Isolate* isolate, Zone* zone, CodeAssemblerState::CodeAssemblerState(Isolate* isolate, Zone* zone,
CallDescriptor* call_descriptor, CallDescriptor* call_descriptor,
Code::Kind kind, const char* name) Code::Kind kind, const char* name,
uint32_t stub_key)
: raw_assembler_(new RawMachineAssembler( : raw_assembler_(new RawMachineAssembler(
isolate, new (zone) Graph(zone), call_descriptor, isolate, new (zone) Graph(zone), call_descriptor,
MachineType::PointerRepresentation(), MachineType::PointerRepresentation(),
...@@ -86,6 +87,7 @@ CodeAssemblerState::CodeAssemblerState(Isolate* isolate, Zone* zone, ...@@ -86,6 +87,7 @@ CodeAssemblerState::CodeAssemblerState(Isolate* isolate, Zone* zone,
InstructionSelector::AlignmentRequirements())), InstructionSelector::AlignmentRequirements())),
kind_(kind), kind_(kind),
name_(name), name_(name),
stub_key_(stub_key),
code_generated_(false), code_generated_(false),
variables_(zone) {} variables_(zone) {}
...@@ -174,7 +176,8 @@ Handle<Code> CodeAssembler::GenerateCode(CodeAssemblerState* state) { ...@@ -174,7 +176,8 @@ Handle<Code> CodeAssembler::GenerateCode(CodeAssemblerState* state) {
Handle<Code> code = Pipeline::GenerateCodeForCodeStub( Handle<Code> code = Pipeline::GenerateCodeForCodeStub(
rasm->isolate(), rasm->call_descriptor(), rasm->graph(), schedule, rasm->isolate(), rasm->call_descriptor(), rasm->graph(), schedule,
state->kind_, state->name_, should_optimize_jumps ? &jump_opt : nullptr); state->kind_, state->name_, state->stub_key_,
should_optimize_jumps ? &jump_opt : nullptr);
if (jump_opt.is_optimizable()) { if (jump_opt.is_optimizable()) {
jump_opt.set_optimizing(); jump_opt.set_optimizing();
...@@ -182,7 +185,7 @@ Handle<Code> CodeAssembler::GenerateCode(CodeAssemblerState* state) { ...@@ -182,7 +185,7 @@ Handle<Code> CodeAssembler::GenerateCode(CodeAssemblerState* state) {
// Regenerate machine code // Regenerate machine code
code = Pipeline::GenerateCodeForCodeStub( code = Pipeline::GenerateCodeForCodeStub(
rasm->isolate(), rasm->call_descriptor(), rasm->graph(), schedule, rasm->isolate(), rasm->call_descriptor(), rasm->graph(), schedule,
state->kind_, state->name_, &jump_opt); state->kind_, state->name_, state->stub_key_, &jump_opt);
} }
state->code_generated_ = true; state->code_generated_ = true;
......
...@@ -1184,7 +1184,8 @@ class V8_EXPORT_PRIVATE CodeAssemblerState { ...@@ -1184,7 +1184,8 @@ class V8_EXPORT_PRIVATE CodeAssemblerState {
// TODO(rmcilroy): move result_size to the CallInterfaceDescriptor. // TODO(rmcilroy): move result_size to the CallInterfaceDescriptor.
CodeAssemblerState(Isolate* isolate, Zone* zone, CodeAssemblerState(Isolate* isolate, Zone* zone,
const CallInterfaceDescriptor& descriptor, Code::Kind kind, const CallInterfaceDescriptor& descriptor, Code::Kind kind,
const char* name, size_t result_size = 1); const char* name, size_t result_size = 1,
uint32_t stub_key = 0);
// Create with JSCall linkage. // Create with JSCall linkage.
CodeAssemblerState(Isolate* isolate, Zone* zone, int parameter_count, CodeAssemblerState(Isolate* isolate, Zone* zone, int parameter_count,
...@@ -1208,11 +1209,12 @@ class V8_EXPORT_PRIVATE CodeAssemblerState { ...@@ -1208,11 +1209,12 @@ class V8_EXPORT_PRIVATE CodeAssemblerState {
CodeAssemblerState(Isolate* isolate, Zone* zone, CodeAssemblerState(Isolate* isolate, Zone* zone,
CallDescriptor* call_descriptor, Code::Kind kind, CallDescriptor* call_descriptor, Code::Kind kind,
const char* name); const char* name, uint32_t stub_key);
std::unique_ptr<RawMachineAssembler> raw_assembler_; std::unique_ptr<RawMachineAssembler> raw_assembler_;
Code::Kind kind_; Code::Kind kind_;
const char* name_; const char* name_;
uint32_t stub_key_;
bool code_generated_; bool code_generated_;
ZoneSet<CodeAssemblerVariable::Impl*> variables_; ZoneSet<CodeAssemblerVariable::Impl*> variables_;
CodeAssemblerCallback call_prologue_; CodeAssemblerCallback call_prologue_;
......
...@@ -317,8 +317,8 @@ Handle<Code> CodeGenerator::FinalizeCode() { ...@@ -317,8 +317,8 @@ Handle<Code> CodeGenerator::FinalizeCode() {
Handle<Code> result = isolate()->factory()->NewCode( Handle<Code> result = isolate()->factory()->NewCode(
desc, info()->code_kind(), Handle<Object>(), table, source_positions, desc, info()->code_kind(), Handle<Object>(), table, source_positions,
deopt_data, false, true, frame()->GetTotalFrameSlotCount(), deopt_data, false, info()->stub_key(), true,
safepoints()->GetCodeOffset()); frame()->GetTotalFrameSlotCount(), safepoints()->GetCodeOffset());
isolate()->counters()->total_compiled_code_size()->Increment( isolate()->counters()->total_compiled_code_size()->Increment(
result->instruction_size()); result->instruction_size());
......
...@@ -157,6 +157,7 @@ class PipelineData { ...@@ -157,6 +157,7 @@ class PipelineData {
register_allocation_zone_scope_(zone_stats_, ZONE_NAME), register_allocation_zone_scope_(zone_stats_, ZONE_NAME),
register_allocation_zone_(register_allocation_zone_scope_.zone()), register_allocation_zone_(register_allocation_zone_scope_.zone()),
jump_optimization_info_(jump_opt) {} jump_optimization_info_(jump_opt) {}
// For register allocation testing entry point. // For register allocation testing entry point.
PipelineData(ZoneStats* zone_stats, CompilationInfo* info, PipelineData(ZoneStats* zone_stats, CompilationInfo* info,
InstructionSequence* sequence) InstructionSequence* sequence)
...@@ -1923,14 +1924,13 @@ bool PipelineImpl::OptimizeGraph(Linkage* linkage) { ...@@ -1923,14 +1924,13 @@ bool PipelineImpl::OptimizeGraph(Linkage* linkage) {
return ScheduleAndSelectInstructions(linkage, true); return ScheduleAndSelectInstructions(linkage, true);
} }
Handle<Code> Pipeline::GenerateCodeForCodeStub(Isolate* isolate, Handle<Code> Pipeline::GenerateCodeForCodeStub(
CallDescriptor* call_descriptor, Isolate* isolate, CallDescriptor* call_descriptor, Graph* graph,
Graph* graph, Schedule* schedule, Schedule* schedule, Code::Kind kind, const char* debug_name,
Code::Kind kind, uint32_t stub_key, JumpOptimizationInfo* jump_opt) {
const char* debug_name,
JumpOptimizationInfo* jump_opt) {
CompilationInfo info(CStrVector(debug_name), isolate, graph->zone(), kind); CompilationInfo info(CStrVector(debug_name), isolate, graph->zone(), kind);
if (isolate->serializer_enabled()) info.MarkAsSerializing(); if (isolate->serializer_enabled()) info.MarkAsSerializing();
info.set_stub_key(stub_key);
// Construct a pipeline for scheduling and code generation. // Construct a pipeline for scheduling and code generation.
ZoneStats zone_stats(isolate->allocator()); ZoneStats zone_stats(isolate->allocator());
......
...@@ -53,12 +53,10 @@ class Pipeline : public AllStatic { ...@@ -53,12 +53,10 @@ class Pipeline : public AllStatic {
// Run the pipeline on a machine graph and generate code. The {schedule} must // Run the pipeline on a machine graph and generate code. The {schedule} must
// be valid, hence the given {graph} does not need to be schedulable. // be valid, hence the given {graph} does not need to be schedulable.
static Handle<Code> GenerateCodeForCodeStub(Isolate* isolate, static Handle<Code> GenerateCodeForCodeStub(
CallDescriptor* call_descriptor, Isolate* isolate, CallDescriptor* call_descriptor, Graph* graph,
Graph* graph, Schedule* schedule, Schedule* schedule, Code::Kind kind, const char* debug_name,
Code::Kind kind, uint32_t stub_key, JumpOptimizationInfo* jump_opt);
const char* debug_name,
JumpOptimizationInfo* jump_opt);
// Run the entire pipeline and generate a handle to a code object suitable for // Run the entire pipeline and generate a handle to a code object suitable for
// testing. // testing.
......
...@@ -1796,7 +1796,8 @@ Handle<Code> Factory::NewCode( ...@@ -1796,7 +1796,8 @@ Handle<Code> Factory::NewCode(
MaybeHandle<HandlerTable> maybe_handler_table, MaybeHandle<HandlerTable> maybe_handler_table,
MaybeHandle<ByteArray> maybe_source_position_table, MaybeHandle<ByteArray> maybe_source_position_table,
MaybeHandle<DeoptimizationData> maybe_deopt_data, bool immovable, MaybeHandle<DeoptimizationData> maybe_deopt_data, bool immovable,
bool is_turbofanned, int stack_slots, int safepoint_table_offset) { uint32_t stub_key, bool is_turbofanned, int stack_slots,
int safepoint_table_offset) {
Handle<ByteArray> reloc_info = NewByteArray(desc.reloc_size, TENURED); Handle<ByteArray> reloc_info = NewByteArray(desc.reloc_size, TENURED);
Handle<CodeDataContainer> data_container = NewCodeDataContainer(0); Handle<CodeDataContainer> data_container = NewCodeDataContainer(0);
...@@ -1844,7 +1845,7 @@ Handle<Code> Factory::NewCode( ...@@ -1844,7 +1845,7 @@ Handle<Code> Factory::NewCode(
code->set_code_data_container(*data_container); code->set_code_data_container(*data_container);
code->set_has_tagged_params(true); code->set_has_tagged_params(true);
code->set_deoptimization_data(*deopt_data); code->set_deoptimization_data(*deopt_data);
code->set_stub_key(0); code->set_stub_key(stub_key);
code->set_handler_table(*handler_table); code->set_handler_table(*handler_table);
code->set_source_position_table(*source_position_table); code->set_source_position_table(*source_position_table);
code->set_protected_instructions(*empty_fixed_array(), SKIP_WRITE_BARRIER); code->set_protected_instructions(*empty_fixed_array(), SKIP_WRITE_BARRIER);
......
...@@ -685,8 +685,9 @@ class V8_EXPORT_PRIVATE Factory final { ...@@ -685,8 +685,9 @@ class V8_EXPORT_PRIVATE Factory final {
MaybeHandle<ByteArray>(), MaybeHandle<ByteArray>(),
MaybeHandle<DeoptimizationData> maybe_deopt_data = MaybeHandle<DeoptimizationData> maybe_deopt_data =
MaybeHandle<DeoptimizationData>(), MaybeHandle<DeoptimizationData>(),
bool immovable = false, bool is_turbofanned = false, bool immovable = false, uint32_t stub_key = 0,
int stack_slots = 0, int safepoint_table_offset = 0); bool is_turbofanned = false, int stack_slots = 0,
int safepoint_table_offset = 0);
// Allocates a new, empty code object for use by builtin deserialization. The // Allocates a new, empty code object for use by builtin deserialization. The
// given {size} argument specifies the size of the entire code object. // given {size} argument specifies the size of the entire code object.
......
...@@ -19,10 +19,11 @@ Handle<Code> PropertyHandlerCompiler::GetCode(Handle<Name> name) { ...@@ -19,10 +19,11 @@ Handle<Code> PropertyHandlerCompiler::GetCode(Handle<Name> name) {
// Create code object in the heap. // Create code object in the heap.
CodeDesc desc; CodeDesc desc;
masm()->GetCode(isolate(), &desc); masm()->GetCode(isolate(), &desc);
Handle<Code> code = Handle<Code> code = factory()->NewCode(
factory()->NewCode(desc, Code::STUB, masm()->CodeObject()); desc, Code::STUB, masm()->CodeObject(), MaybeHandle<HandlerTable>(),
MaybeHandle<ByteArray>(), MaybeHandle<DeoptimizationData>(),
CodeStub::NoCacheKey());
DCHECK(code->is_stub()); DCHECK(code->is_stub());
code->set_stub_key(CodeStub::NoCacheKey());
#ifdef ENABLE_DISASSEMBLER #ifdef ENABLE_DISASSEMBLER
if (FLAG_print_code_stubs) { if (FLAG_print_code_stubs) {
char* raw_name = !name.is_null() && name->IsString() char* raw_name = !name.is_null() && name->IsString()
......
...@@ -39,7 +39,7 @@ class CodeAssemblerTester { ...@@ -39,7 +39,7 @@ class CodeAssemblerTester {
CodeAssemblerTester(Isolate* isolate, CallDescriptor* call_descriptor) CodeAssemblerTester(Isolate* isolate, CallDescriptor* call_descriptor)
: zone_(isolate->allocator(), ZONE_NAME), : zone_(isolate->allocator(), ZONE_NAME),
scope_(isolate), scope_(isolate),
state_(isolate, &zone_, call_descriptor, Code::STUB, "test") {} state_(isolate, &zone_, call_descriptor, Code::STUB, "test", 0) {}
CodeAssemblerState* state() { return &state_; } CodeAssemblerState* state() { return &state_; }
......
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