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

[heap] Introduce {Movability} enum for type safety.

R=mlippautz@chromium.org

Change-Id: Ie5ff0347d7c849e1941f8c8237a0bd56fdb68a4e
Reviewed-on: https://chromium-review.googlesource.com/768672Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49372}
parent aeb1d787
...@@ -220,10 +220,7 @@ void MathPowStub::Generate(MacroAssembler* masm) { ...@@ -220,10 +220,7 @@ void MathPowStub::Generate(MacroAssembler* masm) {
__ Ret(); __ Ret();
} }
bool CEntryStub::NeedsImmovableCode() { Movability CEntryStub::NeedsImmovableCode() { return kImmovable; }
return true;
}
void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
CEntryStub::GenerateAheadOfTime(isolate); CEntryStub::GenerateAheadOfTime(isolate);
......
...@@ -19,7 +19,7 @@ class DirectCEntryStub: public PlatformCodeStub { ...@@ -19,7 +19,7 @@ class DirectCEntryStub: public PlatformCodeStub {
void GenerateCall(MacroAssembler* masm, Register target); void GenerateCall(MacroAssembler* masm, Register target);
private: private:
bool NeedsImmovableCode() override { return true; } Movability NeedsImmovableCode() override { return kImmovable; }
DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR(); DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
DEFINE_PLATFORM_CODE_STUB(DirectCEntry, PlatformCodeStub); DEFINE_PLATFORM_CODE_STUB(DirectCEntry, PlatformCodeStub);
......
...@@ -235,8 +235,7 @@ void CodeStub::GenerateFPStubs(Isolate* isolate) { ...@@ -235,8 +235,7 @@ void CodeStub::GenerateFPStubs(Isolate* isolate) {
USE(isolate); USE(isolate);
} }
Movability CEntryStub::NeedsImmovableCode() {
bool CEntryStub::NeedsImmovableCode() {
// CEntryStub stores the return address on the stack before calling into // CEntryStub stores the return address on the stack before calling into
// C++ code. In some cases, the VM accesses this address, but it is not used // C++ code. In some cases, the VM accesses this address, but it is not used
// when the C++ code returns to the stub because LR holds the return address // when the C++ code returns to the stub because LR holds the return address
...@@ -245,7 +244,7 @@ bool CEntryStub::NeedsImmovableCode() { ...@@ -245,7 +244,7 @@ bool CEntryStub::NeedsImmovableCode() {
// TODO(jbramley): Whilst this is the only analysis that makes sense, I can't // TODO(jbramley): Whilst this is the only analysis that makes sense, I can't
// find any comment to confirm this, and I don't hit any crashes whatever // find any comment to confirm this, and I don't hit any crashes whatever
// this function returns. The anaylsis should be properly confirmed. // this function returns. The anaylsis should be properly confirmed.
return true; return kImmovable;
} }
......
...@@ -16,7 +16,7 @@ class DirectCEntryStub: public PlatformCodeStub { ...@@ -16,7 +16,7 @@ class DirectCEntryStub: public PlatformCodeStub {
void GenerateCall(MacroAssembler* masm, Register target); void GenerateCall(MacroAssembler* masm, Register target);
private: private:
bool NeedsImmovableCode() override { return true; } Movability NeedsImmovableCode() override { return kImmovable; }
DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR(); DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
DEFINE_PLATFORM_CODE_STUB(DirectCEntry, PlatformCodeStub); DEFINE_PLATFORM_CODE_STUB(DirectCEntry, PlatformCodeStub);
......
...@@ -194,7 +194,7 @@ class CodeStub : public ZoneObject { ...@@ -194,7 +194,7 @@ class CodeStub : public ZoneObject {
// Returns whether the code generated for this stub needs to be allocated as // Returns whether the code generated for this stub needs to be allocated as
// a fixed (non-moveable) code object. // a fixed (non-moveable) code object.
virtual bool NeedsImmovableCode() { return false; } virtual Movability NeedsImmovableCode() { return kMovable; }
virtual void PrintName(std::ostream& os) const; // NOLINT virtual void PrintName(std::ostream& os) const; // NOLINT
virtual void PrintBaseName(std::ostream& os) const; // NOLINT virtual void PrintBaseName(std::ostream& os) const; // NOLINT
...@@ -693,7 +693,7 @@ class CEntryStub : public PlatformCodeStub { ...@@ -693,7 +693,7 @@ class CEntryStub : public PlatformCodeStub {
bool is_builtin_exit() const { return FrameTypeBits::decode(minor_key_); } bool is_builtin_exit() const { return FrameTypeBits::decode(minor_key_); }
int result_size() const { return ResultSizeBits::decode(minor_key_); } int result_size() const { return ResultSizeBits::decode(minor_key_); }
bool NeedsImmovableCode() override; Movability NeedsImmovableCode() override;
class SaveDoublesBits : public BitField<bool, 0, 1> {}; class SaveDoublesBits : public BitField<bool, 0, 1> {};
class ArgvMode : public BitField<bool, 1, 1> {}; class ArgvMode : public BitField<bool, 1, 1> {};
......
...@@ -317,7 +317,7 @@ Handle<Code> CodeGenerator::FinalizeCode() { ...@@ -317,7 +317,7 @@ 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, info()->stub_key(), true, 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());
......
...@@ -1794,7 +1794,7 @@ void Deoptimizer::EnsureCodeForDeoptimizationEntry(Isolate* isolate, ...@@ -1794,7 +1794,7 @@ void Deoptimizer::EnsureCodeForDeoptimizationEntry(Isolate* isolate,
// 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>(), MaybeHandle<HandlerTable>(),
MaybeHandle<ByteArray>(), MaybeHandle<DeoptimizationData>(), true); 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]);
......
...@@ -1792,9 +1792,9 @@ Handle<CodeDataContainer> Factory::NewCodeDataContainer(int flags) { ...@@ -1792,9 +1792,9 @@ Handle<CodeDataContainer> Factory::NewCodeDataContainer(int flags) {
return data_container; return data_container;
} }
Handle<Code> Factory::NewCodeRaw(int object_size, bool immovable) { Handle<Code> Factory::NewCodeRaw(int object_size, Movability movability) {
CALL_HEAP_FUNCTION(isolate(), CALL_HEAP_FUNCTION(isolate(),
isolate()->heap()->AllocateCode(object_size, immovable), isolate()->heap()->AllocateCode(object_size, movability),
Code); Code);
} }
...@@ -1802,7 +1802,7 @@ Handle<Code> Factory::NewCode( ...@@ -1802,7 +1802,7 @@ 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, 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, Movability movability,
uint32_t stub_key, bool is_turbofanned, int stack_slots, uint32_t stub_key, bool is_turbofanned, int stack_slots,
int safepoint_table_offset) { int safepoint_table_offset) {
Handle<ByteArray> reloc_info = NewByteArray(desc.reloc_size, TENURED); Handle<ByteArray> reloc_info = NewByteArray(desc.reloc_size, TENURED);
...@@ -1833,7 +1833,7 @@ Handle<Code> Factory::NewCode( ...@@ -1833,7 +1833,7 @@ Handle<Code> Factory::NewCode(
int obj_size = Code::SizeFor(RoundUp(body_size, kObjectAlignment)); int obj_size = Code::SizeFor(RoundUp(body_size, kObjectAlignment));
CodeSpaceMemoryModificationScope code_allocation(isolate()->heap()); CodeSpaceMemoryModificationScope code_allocation(isolate()->heap());
Handle<Code> code = NewCodeRaw(obj_size, immovable); Handle<Code> code = NewCodeRaw(obj_size, movability);
DCHECK(!isolate()->heap()->memory_allocator()->code_range()->valid() || DCHECK(!isolate()->heap()->memory_allocator()->code_range()->valid() ||
isolate()->heap()->memory_allocator()->code_range()->contains( isolate()->heap()->memory_allocator()->code_range()->contains(
code->address()) || code->address()) ||
...@@ -1893,8 +1893,7 @@ Handle<Code> Factory::NewCode( ...@@ -1893,8 +1893,7 @@ Handle<Code> Factory::NewCode(
} }
Handle<Code> Factory::NewCodeForDeserialization(uint32_t size) { Handle<Code> Factory::NewCodeForDeserialization(uint32_t size) {
const bool kNotImmovable = false; return NewCodeRaw(size, kMovable);
return NewCodeRaw(size, kNotImmovable);
} }
Handle<Code> Factory::CopyCode(Handle<Code> code) { Handle<Code> Factory::CopyCode(Handle<Code> code) {
......
...@@ -678,7 +678,7 @@ class V8_EXPORT_PRIVATE Factory final { ...@@ -678,7 +678,7 @@ 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, uint32_t stub_key = 0, Movability movability = kMovable, uint32_t stub_key = 0,
bool is_turbofanned = false, int stack_slots = 0, bool is_turbofanned = false, int stack_slots = 0,
int safepoint_table_offset = 0); int safepoint_table_offset = 0);
...@@ -853,7 +853,7 @@ class V8_EXPORT_PRIVATE Factory final { ...@@ -853,7 +853,7 @@ class V8_EXPORT_PRIVATE Factory final {
PretenureFlag pretenure); PretenureFlag pretenure);
// Creates a code object that is not yet fully initialized yet. // Creates a code object that is not yet fully initialized yet.
Handle<Code> NewCodeRaw(int object_size, bool immovable); Handle<Code> NewCodeRaw(int object_size, Movability movability);
// Attempt to find the number in a small cache. If we finds it, return // Attempt to find the number in a small cache. If we finds it, return
// the string representation of the number. Otherwise return undefined. // the string representation of the number. Otherwise return undefined.
......
...@@ -617,6 +617,8 @@ enum GarbageCollector { SCAVENGER, MARK_COMPACTOR, MINOR_MARK_COMPACTOR }; ...@@ -617,6 +617,8 @@ enum GarbageCollector { SCAVENGER, MARK_COMPACTOR, MINOR_MARK_COMPACTOR };
enum Executability { NOT_EXECUTABLE, EXECUTABLE }; enum Executability { NOT_EXECUTABLE, EXECUTABLE };
enum Movability { kMovable, kImmovable };
enum VisitMode { enum VisitMode {
VISIT_ALL, VISIT_ALL,
VISIT_ALL_IN_MINOR_MC_MARK, VISIT_ALL_IN_MINOR_MC_MARK,
......
...@@ -3066,14 +3066,13 @@ AllocationResult Heap::AllocateFixedTypedArray(int length, ...@@ -3066,14 +3066,13 @@ AllocationResult Heap::AllocateFixedTypedArray(int length,
return elements; return elements;
} }
AllocationResult Heap::AllocateCode(int object_size, Movability movability) {
AllocationResult Heap::AllocateCode(int object_size, bool immovable) {
DCHECK(IsAligned(static_cast<intptr_t>(object_size), kCodeAlignment)); DCHECK(IsAligned(static_cast<intptr_t>(object_size), kCodeAlignment));
AllocationResult allocation = AllocateRaw(object_size, CODE_SPACE); AllocationResult allocation = AllocateRaw(object_size, CODE_SPACE);
HeapObject* result = nullptr; HeapObject* result = nullptr;
if (!allocation.To(&result)) return allocation; if (!allocation.To(&result)) return allocation;
if (immovable) { if (movability == kImmovable) {
Address address = result->address(); Address address = result->address();
MemoryChunk* chunk = MemoryChunk::FromAddress(address); MemoryChunk* chunk = MemoryChunk::FromAddress(address);
// Code objects which should stay at a fixed address are allocated either // Code objects which should stay at a fixed address are allocated either
......
...@@ -2216,8 +2216,8 @@ class Heap { ...@@ -2216,8 +2216,8 @@ class Heap {
MUST_USE_RESULT AllocationResult MUST_USE_RESULT AllocationResult
AllocateForeign(Address address, PretenureFlag pretenure = NOT_TENURED); AllocateForeign(Address address, PretenureFlag pretenure = NOT_TENURED);
MUST_USE_RESULT AllocationResult MUST_USE_RESULT AllocationResult AllocateCode(int object_size,
AllocateCode(int object_size, bool immovable); Movability movability);
void set_force_oom(bool value) { force_oom_ = value; } void set_force_oom(bool value) { force_oom_ = value; }
......
...@@ -283,11 +283,7 @@ void MathPowStub::Generate(MacroAssembler* masm) { ...@@ -283,11 +283,7 @@ void MathPowStub::Generate(MacroAssembler* masm) {
__ ret(0); __ ret(0);
} }
Movability CEntryStub::NeedsImmovableCode() { return kMovable; }
bool CEntryStub::NeedsImmovableCode() {
return false;
}
void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
CEntryStub::GenerateAheadOfTime(isolate); CEntryStub::GenerateAheadOfTime(isolate);
......
...@@ -287,10 +287,7 @@ void MathPowStub::Generate(MacroAssembler* masm) { ...@@ -287,10 +287,7 @@ void MathPowStub::Generate(MacroAssembler* masm) {
__ Ret(); __ Ret();
} }
bool CEntryStub::NeedsImmovableCode() { Movability CEntryStub::NeedsImmovableCode() { return kImmovable; }
return true;
}
void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
CEntryStub::GenerateAheadOfTime(isolate); CEntryStub::GenerateAheadOfTime(isolate);
......
...@@ -19,7 +19,7 @@ class DirectCEntryStub: public PlatformCodeStub { ...@@ -19,7 +19,7 @@ class DirectCEntryStub: public PlatformCodeStub {
void GenerateCall(MacroAssembler* masm, Register target); void GenerateCall(MacroAssembler* masm, Register target);
private: private:
bool NeedsImmovableCode() override { return true; } Movability NeedsImmovableCode() override { return kImmovable; }
DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR(); DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
DEFINE_PLATFORM_CODE_STUB(DirectCEntry, PlatformCodeStub); DEFINE_PLATFORM_CODE_STUB(DirectCEntry, PlatformCodeStub);
......
...@@ -286,10 +286,7 @@ void MathPowStub::Generate(MacroAssembler* masm) { ...@@ -286,10 +286,7 @@ void MathPowStub::Generate(MacroAssembler* masm) {
__ Ret(); __ Ret();
} }
bool CEntryStub::NeedsImmovableCode() { Movability CEntryStub::NeedsImmovableCode() { return kImmovable; }
return true;
}
void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
CEntryStub::GenerateAheadOfTime(isolate); CEntryStub::GenerateAheadOfTime(isolate);
......
...@@ -19,7 +19,7 @@ class DirectCEntryStub : public PlatformCodeStub { ...@@ -19,7 +19,7 @@ class DirectCEntryStub : public PlatformCodeStub {
void GenerateCall(MacroAssembler* masm, Register target); void GenerateCall(MacroAssembler* masm, Register target);
private: private:
bool NeedsImmovableCode() override { return true; } Movability NeedsImmovableCode() override { return kImmovable; }
DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR(); DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
DEFINE_PLATFORM_CODE_STUB(DirectCEntry, PlatformCodeStub); DEFINE_PLATFORM_CODE_STUB(DirectCEntry, PlatformCodeStub);
......
...@@ -258,9 +258,7 @@ void MathPowStub::Generate(MacroAssembler* masm) { ...@@ -258,9 +258,7 @@ void MathPowStub::Generate(MacroAssembler* masm) {
__ Ret(); __ Ret();
} }
Movability CEntryStub::NeedsImmovableCode() { return kImmovable; }
bool CEntryStub::NeedsImmovableCode() { return true; }
void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
CEntryStub::GenerateAheadOfTime(isolate); CEntryStub::GenerateAheadOfTime(isolate);
......
...@@ -19,7 +19,7 @@ class DirectCEntryStub : public PlatformCodeStub { ...@@ -19,7 +19,7 @@ class DirectCEntryStub : public PlatformCodeStub {
void GenerateCall(MacroAssembler* masm, Register target); void GenerateCall(MacroAssembler* masm, Register target);
private: private:
bool NeedsImmovableCode() override { return true; } Movability NeedsImmovableCode() override { return kImmovable; }
DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR(); DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
DEFINE_PLATFORM_CODE_STUB(DirectCEntry, PlatformCodeStub); DEFINE_PLATFORM_CODE_STUB(DirectCEntry, PlatformCodeStub);
......
...@@ -249,7 +249,7 @@ void MathPowStub::Generate(MacroAssembler* masm) { ...@@ -249,7 +249,7 @@ void MathPowStub::Generate(MacroAssembler* masm) {
__ Ret(); __ Ret();
} }
bool CEntryStub::NeedsImmovableCode() { return true; } Movability CEntryStub::NeedsImmovableCode() { return kImmovable; }
void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
CEntryStub::GenerateAheadOfTime(isolate); CEntryStub::GenerateAheadOfTime(isolate);
......
...@@ -19,7 +19,7 @@ class DirectCEntryStub : public PlatformCodeStub { ...@@ -19,7 +19,7 @@ class DirectCEntryStub : public PlatformCodeStub {
void GenerateCall(MacroAssembler* masm, Register target); void GenerateCall(MacroAssembler* masm, Register target);
private: private:
bool NeedsImmovableCode() override { return true; } Movability NeedsImmovableCode() override { return kImmovable; }
DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR(); DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
DEFINE_PLATFORM_CODE_STUB(DirectCEntry, PlatformCodeStub); DEFINE_PLATFORM_CODE_STUB(DirectCEntry, PlatformCodeStub);
......
...@@ -251,11 +251,7 @@ void MathPowStub::Generate(MacroAssembler* masm) { ...@@ -251,11 +251,7 @@ void MathPowStub::Generate(MacroAssembler* masm) {
__ ret(0); __ ret(0);
} }
Movability CEntryStub::NeedsImmovableCode() { return kMovable; }
bool CEntryStub::NeedsImmovableCode() {
return false;
}
void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
CEntryStub::GenerateAheadOfTime(isolate); CEntryStub::GenerateAheadOfTime(isolate);
......
...@@ -5801,7 +5801,6 @@ Handle<Code> GenerateDummyImmovableCode(Isolate* isolate) { ...@@ -5801,7 +5801,6 @@ Handle<Code> GenerateDummyImmovableCode(Isolate* isolate) {
CodeDesc desc; CodeDesc desc;
assm.GetCode(isolate, &desc); assm.GetCode(isolate, &desc);
const bool kImmovable = true;
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>(), HandlerTable::Empty(isolate),
MaybeHandle<ByteArray>(), DeoptimizationData::Empty(isolate), kImmovable); MaybeHandle<ByteArray>(), DeoptimizationData::Empty(isolate), kImmovable);
......
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