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) {
__ Ret();
}
bool CEntryStub::NeedsImmovableCode() {
return true;
}
Movability CEntryStub::NeedsImmovableCode() { return kImmovable; }
void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
CEntryStub::GenerateAheadOfTime(isolate);
......
......@@ -19,7 +19,7 @@ class DirectCEntryStub: public PlatformCodeStub {
void GenerateCall(MacroAssembler* masm, Register target);
private:
bool NeedsImmovableCode() override { return true; }
Movability NeedsImmovableCode() override { return kImmovable; }
DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
DEFINE_PLATFORM_CODE_STUB(DirectCEntry, PlatformCodeStub);
......
......@@ -235,8 +235,7 @@ void CodeStub::GenerateFPStubs(Isolate* isolate) {
USE(isolate);
}
bool CEntryStub::NeedsImmovableCode() {
Movability CEntryStub::NeedsImmovableCode() {
// 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
// when the C++ code returns to the stub because LR holds the return address
......@@ -245,7 +244,7 @@ bool CEntryStub::NeedsImmovableCode() {
// 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
// this function returns. The anaylsis should be properly confirmed.
return true;
return kImmovable;
}
......
......@@ -16,7 +16,7 @@ class DirectCEntryStub: public PlatformCodeStub {
void GenerateCall(MacroAssembler* masm, Register target);
private:
bool NeedsImmovableCode() override { return true; }
Movability NeedsImmovableCode() override { return kImmovable; }
DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
DEFINE_PLATFORM_CODE_STUB(DirectCEntry, PlatformCodeStub);
......
......@@ -194,7 +194,7 @@ class CodeStub : public ZoneObject {
// Returns whether the code generated for this stub needs to be allocated as
// 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 PrintBaseName(std::ostream& os) const; // NOLINT
......@@ -693,7 +693,7 @@ class CEntryStub : public PlatformCodeStub {
bool is_builtin_exit() const { return FrameTypeBits::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 ArgvMode : public BitField<bool, 1, 1> {};
......
......@@ -317,7 +317,7 @@ Handle<Code> CodeGenerator::FinalizeCode() {
Handle<Code> result = isolate()->factory()->NewCode(
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());
isolate()->counters()->total_compiled_code_size()->Increment(
result->instruction_size());
......
......@@ -1794,7 +1794,7 @@ void Deoptimizer::EnsureCodeForDeoptimizationEntry(Isolate* isolate,
// 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>(), true);
MaybeHandle<ByteArray>(), MaybeHandle<DeoptimizationData>(), kImmovable);
CHECK(Heap::IsImmovable(*code));
CHECK_NULL(data->deopt_entry_code_[type]);
......
......@@ -1792,9 +1792,9 @@ Handle<CodeDataContainer> Factory::NewCodeDataContainer(int flags) {
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(),
isolate()->heap()->AllocateCode(object_size, immovable),
isolate()->heap()->AllocateCode(object_size, movability),
Code);
}
......@@ -1802,7 +1802,7 @@ Handle<Code> Factory::NewCode(
const CodeDesc& desc, Code::Kind kind, Handle<Object> self_ref,
MaybeHandle<HandlerTable> maybe_handler_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,
int safepoint_table_offset) {
Handle<ByteArray> reloc_info = NewByteArray(desc.reloc_size, TENURED);
......@@ -1833,7 +1833,7 @@ Handle<Code> Factory::NewCode(
int obj_size = Code::SizeFor(RoundUp(body_size, kObjectAlignment));
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() ||
isolate()->heap()->memory_allocator()->code_range()->contains(
code->address()) ||
......@@ -1893,8 +1893,7 @@ Handle<Code> Factory::NewCode(
}
Handle<Code> Factory::NewCodeForDeserialization(uint32_t size) {
const bool kNotImmovable = false;
return NewCodeRaw(size, kNotImmovable);
return NewCodeRaw(size, kMovable);
}
Handle<Code> Factory::CopyCode(Handle<Code> code) {
......
......@@ -678,7 +678,7 @@ class V8_EXPORT_PRIVATE Factory final {
MaybeHandle<ByteArray>(),
MaybeHandle<DeoptimizationData> maybe_deopt_data =
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,
int safepoint_table_offset = 0);
......@@ -853,7 +853,7 @@ class V8_EXPORT_PRIVATE Factory final {
PretenureFlag pretenure);
// 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
// the string representation of the number. Otherwise return undefined.
......
......@@ -617,6 +617,8 @@ enum GarbageCollector { SCAVENGER, MARK_COMPACTOR, MINOR_MARK_COMPACTOR };
enum Executability { NOT_EXECUTABLE, EXECUTABLE };
enum Movability { kMovable, kImmovable };
enum VisitMode {
VISIT_ALL,
VISIT_ALL_IN_MINOR_MC_MARK,
......
......@@ -3066,14 +3066,13 @@ AllocationResult Heap::AllocateFixedTypedArray(int length,
return elements;
}
AllocationResult Heap::AllocateCode(int object_size, bool immovable) {
AllocationResult Heap::AllocateCode(int object_size, Movability movability) {
DCHECK(IsAligned(static_cast<intptr_t>(object_size), kCodeAlignment));
AllocationResult allocation = AllocateRaw(object_size, CODE_SPACE);
HeapObject* result = nullptr;
if (!allocation.To(&result)) return allocation;
if (immovable) {
if (movability == kImmovable) {
Address address = result->address();
MemoryChunk* chunk = MemoryChunk::FromAddress(address);
// Code objects which should stay at a fixed address are allocated either
......
......@@ -2216,8 +2216,8 @@ class Heap {
MUST_USE_RESULT AllocationResult
AllocateForeign(Address address, PretenureFlag pretenure = NOT_TENURED);
MUST_USE_RESULT AllocationResult
AllocateCode(int object_size, bool immovable);
MUST_USE_RESULT AllocationResult AllocateCode(int object_size,
Movability movability);
void set_force_oom(bool value) { force_oom_ = value; }
......
......@@ -283,11 +283,7 @@ void MathPowStub::Generate(MacroAssembler* masm) {
__ ret(0);
}
bool CEntryStub::NeedsImmovableCode() {
return false;
}
Movability CEntryStub::NeedsImmovableCode() { return kMovable; }
void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
CEntryStub::GenerateAheadOfTime(isolate);
......
......@@ -287,10 +287,7 @@ void MathPowStub::Generate(MacroAssembler* masm) {
__ Ret();
}
bool CEntryStub::NeedsImmovableCode() {
return true;
}
Movability CEntryStub::NeedsImmovableCode() { return kImmovable; }
void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
CEntryStub::GenerateAheadOfTime(isolate);
......
......@@ -19,7 +19,7 @@ class DirectCEntryStub: public PlatformCodeStub {
void GenerateCall(MacroAssembler* masm, Register target);
private:
bool NeedsImmovableCode() override { return true; }
Movability NeedsImmovableCode() override { return kImmovable; }
DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
DEFINE_PLATFORM_CODE_STUB(DirectCEntry, PlatformCodeStub);
......
......@@ -286,10 +286,7 @@ void MathPowStub::Generate(MacroAssembler* masm) {
__ Ret();
}
bool CEntryStub::NeedsImmovableCode() {
return true;
}
Movability CEntryStub::NeedsImmovableCode() { return kImmovable; }
void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
CEntryStub::GenerateAheadOfTime(isolate);
......
......@@ -19,7 +19,7 @@ class DirectCEntryStub : public PlatformCodeStub {
void GenerateCall(MacroAssembler* masm, Register target);
private:
bool NeedsImmovableCode() override { return true; }
Movability NeedsImmovableCode() override { return kImmovable; }
DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
DEFINE_PLATFORM_CODE_STUB(DirectCEntry, PlatformCodeStub);
......
......@@ -258,9 +258,7 @@ void MathPowStub::Generate(MacroAssembler* masm) {
__ Ret();
}
bool CEntryStub::NeedsImmovableCode() { return true; }
Movability CEntryStub::NeedsImmovableCode() { return kImmovable; }
void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
CEntryStub::GenerateAheadOfTime(isolate);
......
......@@ -19,7 +19,7 @@ class DirectCEntryStub : public PlatformCodeStub {
void GenerateCall(MacroAssembler* masm, Register target);
private:
bool NeedsImmovableCode() override { return true; }
Movability NeedsImmovableCode() override { return kImmovable; }
DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
DEFINE_PLATFORM_CODE_STUB(DirectCEntry, PlatformCodeStub);
......
......@@ -249,7 +249,7 @@ void MathPowStub::Generate(MacroAssembler* masm) {
__ Ret();
}
bool CEntryStub::NeedsImmovableCode() { return true; }
Movability CEntryStub::NeedsImmovableCode() { return kImmovable; }
void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
CEntryStub::GenerateAheadOfTime(isolate);
......
......@@ -19,7 +19,7 @@ class DirectCEntryStub : public PlatformCodeStub {
void GenerateCall(MacroAssembler* masm, Register target);
private:
bool NeedsImmovableCode() override { return true; }
Movability NeedsImmovableCode() override { return kImmovable; }
DEFINE_NULL_CALL_INTERFACE_DESCRIPTOR();
DEFINE_PLATFORM_CODE_STUB(DirectCEntry, PlatformCodeStub);
......
......@@ -251,11 +251,7 @@ void MathPowStub::Generate(MacroAssembler* masm) {
__ ret(0);
}
bool CEntryStub::NeedsImmovableCode() {
return false;
}
Movability CEntryStub::NeedsImmovableCode() { return kMovable; }
void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
CEntryStub::GenerateAheadOfTime(isolate);
......
......@@ -5801,7 +5801,6 @@ Handle<Code> GenerateDummyImmovableCode(Isolate* isolate) {
CodeDesc desc;
assm.GetCode(isolate, &desc);
const bool kImmovable = true;
Handle<Code> code = isolate->factory()->NewCode(
desc, Code::STUB, Handle<Code>(), HandlerTable::Empty(isolate),
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