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

[builtins] Set {builtin_index} during code allocation.

This ensures that the {Code::builtin_index} field is only set during
allocation of new {Code} objects, making this field truly immutable.

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

Change-Id: Ic793346976183149e2d077e92cb9da3c925ea865
Reviewed-on: https://chromium-review.googlesource.com/774439Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49414}
parent 8ff0ca1b
This diff is collapsed.
...@@ -129,8 +129,9 @@ Handle<Code> PlatformCodeStub::GenerateCode() { ...@@ -129,8 +129,9 @@ Handle<Code> PlatformCodeStub::GenerateCode() {
masm.GetCode(isolate(), &desc); masm.GetCode(isolate(), &desc);
// 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(), Builtins::kNoBuiltinId, table,
DeoptimizationData::Empty(isolate()), NeedsImmovableCode(), GetKey()); MaybeHandle<ByteArray>(), DeoptimizationData::Empty(isolate()),
NeedsImmovableCode(), GetKey());
return new_object; return new_object;
} }
......
...@@ -67,6 +67,7 @@ CompilationInfo::CompilationInfo(Vector<const char> debug_name, ...@@ -67,6 +67,7 @@ CompilationInfo::CompilationInfo(Vector<const char> debug_name,
flags_(0), flags_(0),
code_kind_(code_kind), code_kind_(code_kind),
stub_key_(0), stub_key_(0),
builtin_index_(Builtins::kNoBuiltinId),
mode_(mode), mode_(mode),
osr_offset_(BailoutId::None()), osr_offset_(BailoutId::None()),
feedback_vector_spec_(zone), feedback_vector_spec_(zone),
......
...@@ -89,6 +89,8 @@ class V8_EXPORT_PRIVATE CompilationInfo final { ...@@ -89,6 +89,8 @@ class V8_EXPORT_PRIVATE CompilationInfo final {
Code::Kind code_kind() const { return code_kind_; } Code::Kind code_kind() const { return code_kind_; }
uint32_t stub_key() const { return stub_key_; } uint32_t stub_key() const { return stub_key_; }
void set_stub_key(uint32_t stub_key) { stub_key_ = stub_key; } void set_stub_key(uint32_t stub_key) { stub_key_ = stub_key; }
int32_t builtin_index() const { return builtin_index_; }
void set_builtin_index(int32_t index) { builtin_index_ = index; }
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;
...@@ -279,6 +281,7 @@ class V8_EXPORT_PRIVATE CompilationInfo final { ...@@ -279,6 +281,7 @@ class V8_EXPORT_PRIVATE CompilationInfo final {
Code::Kind code_kind_; Code::Kind code_kind_;
uint32_t stub_key_; uint32_t stub_key_;
int32_t builtin_index_;
Handle<SharedFunctionInfo> shared_info_; Handle<SharedFunctionInfo> shared_info_;
......
...@@ -56,30 +56,31 @@ static_assert( ...@@ -56,30 +56,31 @@ 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, uint32_t stub_key) Code::Kind kind, const char* name, size_t result_size, uint32_t stub_key,
int32_t builtin_index)
: 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, stub_key) {} kind, name, stub_key, builtin_index) {}
CodeAssemblerState::CodeAssemblerState(Isolate* isolate, Zone* zone, CodeAssemblerState::CodeAssemblerState(Isolate* isolate, Zone* zone,
int parameter_count, Code::Kind kind, int parameter_count, Code::Kind kind,
const char* name) const char* name, int32_t builtin_index)
: CodeAssemblerState( : CodeAssemblerState(
isolate, zone, isolate, zone,
Linkage::GetJSCallDescriptor(zone, false, parameter_count, Linkage::GetJSCallDescriptor(zone, false, parameter_count,
kind == Code::BUILTIN kind == Code::BUILTIN
? CallDescriptor::kPushArgumentCount ? CallDescriptor::kPushArgumentCount
: CallDescriptor::kNoFlags), : CallDescriptor::kNoFlags),
kind, name, 0) {} kind, name, 0, builtin_index) {}
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) uint32_t stub_key, int32_t builtin_index)
: 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(),
...@@ -88,6 +89,7 @@ CodeAssemblerState::CodeAssemblerState(Isolate* isolate, Zone* zone, ...@@ -88,6 +89,7 @@ CodeAssemblerState::CodeAssemblerState(Isolate* isolate, Zone* zone,
kind_(kind), kind_(kind),
name_(name), name_(name),
stub_key_(stub_key), stub_key_(stub_key),
builtin_index_(builtin_index),
code_generated_(false), code_generated_(false),
variables_(zone) {} variables_(zone) {}
...@@ -180,7 +182,7 @@ Handle<Code> CodeAssembler::GenerateCode(CodeAssemblerState* state) { ...@@ -180,7 +182,7 @@ 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_, state->stub_key_, state->kind_, state->name_, state->stub_key_, state->builtin_index_,
should_optimize_jumps ? &jump_opt : nullptr); should_optimize_jumps ? &jump_opt : nullptr);
if (jump_opt.is_optimizable()) { if (jump_opt.is_optimizable()) {
...@@ -189,7 +191,8 @@ Handle<Code> CodeAssembler::GenerateCode(CodeAssemblerState* state) { ...@@ -189,7 +191,8 @@ 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_, state->stub_key_, &jump_opt); state->kind_, state->name_, state->stub_key_, state->builtin_index_,
&jump_opt);
} }
state->code_generated_ = true; state->code_generated_ = true;
......
...@@ -1192,11 +1192,13 @@ class V8_EXPORT_PRIVATE CodeAssemblerState { ...@@ -1192,11 +1192,13 @@ class V8_EXPORT_PRIVATE CodeAssemblerState {
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); uint32_t stub_key = 0,
int32_t builtin_index = Builtins::kNoBuiltinId);
// Create with JSCall linkage. // Create with JSCall linkage.
CodeAssemblerState(Isolate* isolate, Zone* zone, int parameter_count, CodeAssemblerState(Isolate* isolate, Zone* zone, int parameter_count,
Code::Kind kind, const char* name); Code::Kind kind, const char* name,
int32_t builtin_index = Builtins::kNoBuiltinId);
~CodeAssemblerState(); ~CodeAssemblerState();
...@@ -1216,12 +1218,14 @@ class V8_EXPORT_PRIVATE CodeAssemblerState { ...@@ -1216,12 +1218,14 @@ 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, uint32_t stub_key); const char* name, uint32_t stub_key,
int32_t builtin_index);
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_; uint32_t stub_key_;
int32_t builtin_index_;
bool code_generated_; bool code_generated_;
ZoneSet<CodeAssemblerVariable::Impl*> variables_; ZoneSet<CodeAssemblerVariable::Impl*> variables_;
CodeAssemblerCallback call_prologue_; CodeAssemblerCallback call_prologue_;
......
...@@ -315,8 +315,8 @@ Handle<Code> CodeGenerator::FinalizeCode() { ...@@ -315,8 +315,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>(), info()->builtin_index(),
deopt_data, kMovable, info()->stub_key(), true, table, source_positions, deopt_data, kMovable, info()->stub_key(), true,
frame()->GetTotalFrameSlotCount(), 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());
......
...@@ -1927,8 +1927,9 @@ bool PipelineImpl::OptimizeGraph(Linkage* linkage) { ...@@ -1927,8 +1927,9 @@ bool PipelineImpl::OptimizeGraph(Linkage* linkage) {
Handle<Code> Pipeline::GenerateCodeForCodeStub( Handle<Code> Pipeline::GenerateCodeForCodeStub(
Isolate* isolate, CallDescriptor* call_descriptor, Graph* graph, Isolate* isolate, CallDescriptor* call_descriptor, Graph* graph,
Schedule* schedule, Code::Kind kind, const char* debug_name, Schedule* schedule, Code::Kind kind, const char* debug_name,
uint32_t stub_key, JumpOptimizationInfo* jump_opt) { uint32_t stub_key, int32_t builtin_index, JumpOptimizationInfo* jump_opt) {
CompilationInfo info(CStrVector(debug_name), graph->zone(), kind); CompilationInfo info(CStrVector(debug_name), graph->zone(), kind);
info.set_builtin_index(builtin_index);
info.set_stub_key(stub_key); info.set_stub_key(stub_key);
// Construct a pipeline for scheduling and code generation. // Construct a pipeline for scheduling and code generation.
......
...@@ -56,7 +56,7 @@ class Pipeline : public AllStatic { ...@@ -56,7 +56,7 @@ class Pipeline : public AllStatic {
static Handle<Code> GenerateCodeForCodeStub( static Handle<Code> GenerateCodeForCodeStub(
Isolate* isolate, CallDescriptor* call_descriptor, Graph* graph, Isolate* isolate, CallDescriptor* call_descriptor, Graph* graph,
Schedule* schedule, Code::Kind kind, const char* debug_name, Schedule* schedule, Code::Kind kind, const char* debug_name,
uint32_t stub_key, JumpOptimizationInfo* jump_opt); uint32_t stub_key, int32_t builtin_index, 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.
......
...@@ -1786,8 +1786,9 @@ void Deoptimizer::EnsureCodeForDeoptimizationEntry(Isolate* isolate, ...@@ -1786,8 +1786,9 @@ void Deoptimizer::EnsureCodeForDeoptimizationEntry(Isolate* isolate,
// Allocate the code as immovable since the entry addresses will be used // Allocate the code as immovable since the entry addresses will be used
// directly and there is no support for relocating them. // directly and there is no support for relocating them.
Handle<Code> code = isolate->factory()->NewCode( Handle<Code> code = isolate->factory()->NewCode(
desc, Code::STUB, Handle<Object>(), MaybeHandle<HandlerTable>(), desc, Code::STUB, Handle<Object>(), Builtins::kNoBuiltinId,
MaybeHandle<ByteArray>(), MaybeHandle<DeoptimizationData>(), kImmovable); MaybeHandle<HandlerTable>(), MaybeHandle<ByteArray>(),
MaybeHandle<DeoptimizationData>(), kImmovable);
CHECK(Heap::IsImmovable(*code)); CHECK(Heap::IsImmovable(*code));
CHECK_NULL(data->deopt_entry_code_[type]); CHECK_NULL(data->deopt_entry_code_[type]);
......
...@@ -1800,7 +1800,7 @@ Handle<Code> Factory::NewCodeRaw(int object_size, Movability movability) { ...@@ -1800,7 +1800,7 @@ Handle<Code> Factory::NewCodeRaw(int object_size, Movability movability) {
Handle<Code> Factory::NewCode( Handle<Code> Factory::NewCode(
const CodeDesc& desc, Code::Kind kind, Handle<Object> self_ref, const CodeDesc& desc, Code::Kind kind, Handle<Object> self_ref,
MaybeHandle<HandlerTable> maybe_handler_table, int32_t builtin_index, MaybeHandle<HandlerTable> maybe_handler_table,
MaybeHandle<ByteArray> maybe_source_position_table, MaybeHandle<ByteArray> maybe_source_position_table,
MaybeHandle<DeoptimizationData> maybe_deopt_data, Movability movability, MaybeHandle<DeoptimizationData> maybe_deopt_data, Movability movability,
uint32_t stub_key, bool is_turbofanned, int stack_slots, uint32_t stub_key, bool is_turbofanned, int stack_slots,
...@@ -1857,7 +1857,7 @@ Handle<Code> Factory::NewCode( ...@@ -1857,7 +1857,7 @@ Handle<Code> Factory::NewCode(
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);
code->set_constant_pool_offset(desc.instr_size - desc.constant_pool_size); code->set_constant_pool_offset(desc.instr_size - desc.constant_pool_size);
code->set_builtin_index(-1); code->set_builtin_index(builtin_index);
code->set_trap_handler_index(Smi::FromInt(-1)); code->set_trap_handler_index(Smi::FromInt(-1));
switch (code->kind()) { switch (code->kind()) {
......
...@@ -672,6 +672,7 @@ class V8_EXPORT_PRIVATE Factory final { ...@@ -672,6 +672,7 @@ class V8_EXPORT_PRIVATE Factory final {
// by containing this handle. // by containing this handle.
Handle<Code> NewCode(const CodeDesc& desc, Code::Kind kind, Handle<Code> NewCode(const CodeDesc& desc, Code::Kind kind,
Handle<Object> self_reference, Handle<Object> self_reference,
int32_t builtin_index = Builtins::kNoBuiltinId,
MaybeHandle<HandlerTable> maybe_handler_table = MaybeHandle<HandlerTable> maybe_handler_table =
MaybeHandle<HandlerTable>(), MaybeHandle<HandlerTable>(),
MaybeHandle<ByteArray> maybe_source_position_table = MaybeHandle<ByteArray> maybe_source_position_table =
......
...@@ -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", 0) {} state_(isolate, &zone_, call_descriptor, Code::STUB, "test", 0, -1) {}
CodeAssemblerState* state() { return &state_; } CodeAssemblerState* state() { return &state_; }
......
...@@ -5802,8 +5802,9 @@ Handle<Code> GenerateDummyImmovableCode(Isolate* isolate) { ...@@ -5802,8 +5802,9 @@ Handle<Code> GenerateDummyImmovableCode(Isolate* isolate) {
CodeDesc desc; CodeDesc desc;
assm.GetCode(isolate, &desc); assm.GetCode(isolate, &desc);
Handle<Code> code = isolate->factory()->NewCode( Handle<Code> code = isolate->factory()->NewCode(
desc, Code::STUB, Handle<Code>(), HandlerTable::Empty(isolate), desc, Code::STUB, Handle<Code>(), Builtins::kNoBuiltinId,
MaybeHandle<ByteArray>(), DeoptimizationData::Empty(isolate), kImmovable); HandlerTable::Empty(isolate), MaybeHandle<ByteArray>(),
DeoptimizationData::Empty(isolate), kImmovable);
CHECK(code->IsCode()); CHECK(code->IsCode());
return code; return code;
......
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