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