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() {
masm.GetCode(isolate(), &desc);
// 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(), GetKey());
desc, Code::STUB, masm.CodeObject(), Builtins::kNoBuiltinId, table,
MaybeHandle<ByteArray>(), DeoptimizationData::Empty(isolate()),
NeedsImmovableCode(), GetKey());
return new_object;
}
......
......@@ -67,6 +67,7 @@ CompilationInfo::CompilationInfo(Vector<const char> debug_name,
flags_(0),
code_kind_(code_kind),
stub_key_(0),
builtin_index_(Builtins::kNoBuiltinId),
mode_(mode),
osr_offset_(BailoutId::None()),
feedback_vector_spec_(zone),
......
......@@ -89,6 +89,8 @@ class V8_EXPORT_PRIVATE CompilationInfo final {
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; }
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_; }
JavaScriptFrame* osr_frame() const { return osr_frame_; }
int num_parameters() const;
......@@ -279,6 +281,7 @@ class V8_EXPORT_PRIVATE CompilationInfo final {
Code::Kind code_kind_;
uint32_t stub_key_;
int32_t builtin_index_;
Handle<SharedFunctionInfo> shared_info_;
......
......@@ -56,30 +56,31 @@ static_assert(
CodeAssemblerState::CodeAssemblerState(
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(
isolate, zone,
Linkage::GetStubCallDescriptor(
isolate, zone, descriptor, descriptor.GetStackParameterCount(),
CallDescriptor::kNoFlags, Operator::kNoProperties,
MachineType::AnyTagged(), result_size),
kind, name, stub_key) {}
kind, name, stub_key, builtin_index) {}
CodeAssemblerState::CodeAssemblerState(Isolate* isolate, Zone* zone,
int parameter_count, Code::Kind kind,
const char* name)
const char* name, int32_t builtin_index)
: CodeAssemblerState(
isolate, zone,
Linkage::GetJSCallDescriptor(zone, false, parameter_count,
kind == Code::BUILTIN
? CallDescriptor::kPushArgumentCount
: CallDescriptor::kNoFlags),
kind, name, 0) {}
kind, name, 0, builtin_index) {}
CodeAssemblerState::CodeAssemblerState(Isolate* isolate, Zone* zone,
CallDescriptor* call_descriptor,
Code::Kind kind, const char* name,
uint32_t stub_key)
uint32_t stub_key, int32_t builtin_index)
: raw_assembler_(new RawMachineAssembler(
isolate, new (zone) Graph(zone), call_descriptor,
MachineType::PointerRepresentation(),
......@@ -88,6 +89,7 @@ CodeAssemblerState::CodeAssemblerState(Isolate* isolate, Zone* zone,
kind_(kind),
name_(name),
stub_key_(stub_key),
builtin_index_(builtin_index),
code_generated_(false),
variables_(zone) {}
......@@ -180,7 +182,7 @@ Handle<Code> CodeAssembler::GenerateCode(CodeAssemblerState* state) {
Handle<Code> code = Pipeline::GenerateCodeForCodeStub(
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);
if (jump_opt.is_optimizable()) {
......@@ -189,7 +191,8 @@ Handle<Code> CodeAssembler::GenerateCode(CodeAssemblerState* state) {
// Regenerate machine code
code = Pipeline::GenerateCodeForCodeStub(
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;
......
......@@ -1192,11 +1192,13 @@ class V8_EXPORT_PRIVATE CodeAssemblerState {
CodeAssemblerState(Isolate* isolate, Zone* zone,
const CallInterfaceDescriptor& descriptor, Code::Kind kind,
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.
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();
......@@ -1216,12 +1218,14 @@ class V8_EXPORT_PRIVATE CodeAssemblerState {
CodeAssemblerState(Isolate* isolate, Zone* zone,
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_;
Code::Kind kind_;
const char* name_;
uint32_t stub_key_;
int32_t builtin_index_;
bool code_generated_;
ZoneSet<CodeAssemblerVariable::Impl*> variables_;
CodeAssemblerCallback call_prologue_;
......
......@@ -315,8 +315,8 @@ Handle<Code> CodeGenerator::FinalizeCode() {
}
Handle<Code> result = isolate()->factory()->NewCode(
desc, info()->code_kind(), Handle<Object>(), table, source_positions,
deopt_data, kMovable, info()->stub_key(), true,
desc, info()->code_kind(), Handle<Object>(), info()->builtin_index(),
table, source_positions, deopt_data, kMovable, info()->stub_key(), true,
frame()->GetTotalFrameSlotCount(), safepoints()->GetCodeOffset());
isolate()->counters()->total_compiled_code_size()->Increment(
result->instruction_size());
......
......@@ -1927,8 +1927,9 @@ bool PipelineImpl::OptimizeGraph(Linkage* linkage) {
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) {
uint32_t stub_key, int32_t builtin_index, JumpOptimizationInfo* jump_opt) {
CompilationInfo info(CStrVector(debug_name), graph->zone(), kind);
info.set_builtin_index(builtin_index);
info.set_stub_key(stub_key);
// Construct a pipeline for scheduling and code generation.
......
......@@ -56,7 +56,7 @@ class Pipeline : public AllStatic {
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);
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
// testing.
......
......@@ -1786,8 +1786,9 @@ void Deoptimizer::EnsureCodeForDeoptimizationEntry(Isolate* isolate,
// Allocate the code as immovable since the entry addresses will be used
// directly and there is no support for relocating them.
Handle<Code> code = isolate->factory()->NewCode(
desc, Code::STUB, Handle<Object>(), MaybeHandle<HandlerTable>(),
MaybeHandle<ByteArray>(), MaybeHandle<DeoptimizationData>(), kImmovable);
desc, Code::STUB, Handle<Object>(), Builtins::kNoBuiltinId,
MaybeHandle<HandlerTable>(), MaybeHandle<ByteArray>(),
MaybeHandle<DeoptimizationData>(), kImmovable);
CHECK(Heap::IsImmovable(*code));
CHECK_NULL(data->deopt_entry_code_[type]);
......
......@@ -1800,7 +1800,7 @@ Handle<Code> Factory::NewCodeRaw(int object_size, Movability movability) {
Handle<Code> Factory::NewCode(
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<DeoptimizationData> maybe_deopt_data, Movability movability,
uint32_t stub_key, bool is_turbofanned, int stack_slots,
......@@ -1857,7 +1857,7 @@ Handle<Code> Factory::NewCode(
code->set_source_position_table(*source_position_table);
code->set_protected_instructions(*empty_fixed_array(), SKIP_WRITE_BARRIER);
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));
switch (code->kind()) {
......
......@@ -672,6 +672,7 @@ class V8_EXPORT_PRIVATE Factory final {
// by containing this handle.
Handle<Code> NewCode(const CodeDesc& desc, Code::Kind kind,
Handle<Object> self_reference,
int32_t builtin_index = Builtins::kNoBuiltinId,
MaybeHandle<HandlerTable> maybe_handler_table =
MaybeHandle<HandlerTable>(),
MaybeHandle<ByteArray> maybe_source_position_table =
......
......@@ -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", 0) {}
state_(isolate, &zone_, call_descriptor, Code::STUB, "test", 0, -1) {}
CodeAssemblerState* state() { return &state_; }
......
......@@ -5802,8 +5802,9 @@ Handle<Code> GenerateDummyImmovableCode(Isolate* isolate) {
CodeDesc desc;
assm.GetCode(isolate, &desc);
Handle<Code> code = isolate->factory()->NewCode(
desc, Code::STUB, Handle<Code>(), HandlerTable::Empty(isolate),
MaybeHandle<ByteArray>(), DeoptimizationData::Empty(isolate), kImmovable);
desc, Code::STUB, Handle<Code>(), Builtins::kNoBuiltinId,
HandlerTable::Empty(isolate), MaybeHandle<ByteArray>(),
DeoptimizationData::Empty(isolate), kImmovable);
CHECK(code->IsCode());
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