Commit a1b206dd authored by Michael Lippautz's avatar Michael Lippautz Committed by V8 LUCI CQ

heap: Call AllocateRawWith directly

Avoid going through Heap but rather call it directly on the allocator.

Bug: v8:12615
Change-Id: I395b96d08b685c63c4125245a76c3610acf1643b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3485677Reviewed-by: 's avatarDominik Inführ <dinfuehr@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79260}
parent 266f41aa
......@@ -76,6 +76,10 @@ ReadOnlyRoots Factory::read_only_roots() const {
return ReadOnlyRoots(isolate());
}
HeapAllocator* Factory::allocator() const {
return isolate()->heap()->allocator();
}
Factory::CodeBuilder& Factory::CodeBuilder::set_interpreter_data(
Handle<HeapObject> interpreter_data) {
// This DCHECK requires this function to be in -inl.h.
......
......@@ -21,6 +21,7 @@
#include "src/execution/isolate-inl.h"
#include "src/execution/protectors-inl.h"
#include "src/heap/basic-memory-chunk.h"
#include "src/heap/heap-allocator-inl.h"
#include "src/heap/heap-inl.h"
#include "src/heap/incremental-marking.h"
#include "src/heap/mark-compact-inl.h"
......@@ -267,16 +268,17 @@ MaybeHandle<Code> Factory::CodeBuilder::BuildInternal(
MaybeHandle<Code> Factory::CodeBuilder::AllocateCode(
bool retry_allocation_or_fail) {
Heap* heap = isolate_->heap();
HeapAllocator* allocator = heap->allocator();
HeapObject result;
AllocationType allocation_type = V8_EXTERNAL_CODE_SPACE_BOOL || is_executable_
? AllocationType::kCode
: AllocationType::kReadOnly;
const int object_size = Code::SizeFor(code_desc_.body_size());
if (retry_allocation_or_fail) {
result = heap->AllocateRawWith<Heap::kRetryOrFail>(
result = allocator->AllocateRawWith<HeapAllocator::kRetryOrFail>(
object_size, allocation_type, AllocationOrigin::kRuntime);
} else {
result = heap->AllocateRawWith<Heap::kLightRetry>(
result = allocator->AllocateRawWith<HeapAllocator::kLightRetry>(
object_size, allocation_type, AllocationOrigin::kRuntime);
// Return an empty handle if we cannot allocate the code object.
if (result.is_null()) return MaybeHandle<Code>();
......@@ -330,7 +332,7 @@ Handle<Code> Factory::CodeBuilder::Build() {
HeapObject Factory::AllocateRaw(int size, AllocationType allocation,
AllocationAlignment alignment) {
return isolate()->heap()->AllocateRawWith<Heap::kRetryOrFail>(
return allocator()->AllocateRawWith<HeapAllocator::kRetryOrFail>(
size, allocation, AllocationOrigin::kRuntime, alignment);
}
......@@ -343,8 +345,8 @@ HeapObject Factory::AllocateRawWithAllocationSite(
DCHECK(V8_ALLOCATION_SITE_TRACKING_BOOL);
size += AllocationMemento::kSize;
}
HeapObject result =
isolate()->heap()->AllocateRawWith<Heap::kRetryOrFail>(size, allocation);
HeapObject result = allocator()->AllocateRawWith<HeapAllocator::kRetryOrFail>(
size, allocation);
WriteBarrierMode write_barrier_mode = allocation == AllocationType::kYoung
? SKIP_WRITE_BARRIER
: UPDATE_WRITE_BARRIER;
......@@ -371,8 +373,8 @@ void Factory::InitializeAllocationMemento(AllocationMemento memento,
HeapObject Factory::New(Handle<Map> map, AllocationType allocation) {
DCHECK(map->instance_type() != MAP_TYPE);
int size = map->instance_size();
HeapObject result =
isolate()->heap()->AllocateRawWith<Heap::kRetryOrFail>(size, allocation);
HeapObject result = allocator()->AllocateRawWith<HeapAllocator::kRetryOrFail>(
size, allocation);
// New space objects are allocated white.
WriteBarrierMode write_barrier_mode = allocation == AllocationType::kYoung
? SKIP_WRITE_BARRIER
......@@ -386,7 +388,7 @@ Handle<HeapObject> Factory::NewFillerObject(int size,
AllocationType allocation,
AllocationOrigin origin) {
Heap* heap = isolate()->heap();
HeapObject result = heap->AllocateRawWith<Heap::kRetryOrFail>(
HeapObject result = allocator()->AllocateRawWith<HeapAllocator::kRetryOrFail>(
size, allocation, origin, alignment);
heap->CreateFillerObjectAt(result.address(), size, ClearRecordedSlots::kNo);
return Handle<HeapObject>(result, isolate());
......@@ -846,8 +848,7 @@ Handle<String> Factory::AllocateInternalizedStringImpl(T t, int chars,
String result = String::cast(AllocateRawWithImmortalMap(
size,
RefineAllocationTypeForInPlaceInternalizableString(
isolate()->heap()->CanAllocateInReadOnlySpace()
? AllocationType::kReadOnly
CanAllocateInReadOnlySpace() ? AllocationType::kReadOnly
: AllocationType::kOld,
map),
map));
......@@ -1150,8 +1151,8 @@ Context Factory::NewContextInternal(Handle<Map> map, int size,
DCHECK_LE(Context::MIN_CONTEXT_SLOTS, variadic_part_length);
DCHECK_LE(Context::SizeFor(variadic_part_length), size);
HeapObject result =
isolate()->heap()->AllocateRawWith<Heap::kRetryOrFail>(size, allocation);
HeapObject result = allocator()->AllocateRawWith<HeapAllocator::kRetryOrFail>(
size, allocation);
result.set_map_after_allocation(*map);
DisallowGarbageCollection no_gc;
Context context = Context::cast(result);
......@@ -1844,7 +1845,7 @@ Handle<Map> Factory::NewMap(InstanceType type, int instance_size,
IsTerminalElementsKind(elements_kind));
DCHECK(allocation_type == AllocationType::kMap ||
allocation_type == AllocationType::kSharedMap);
HeapObject result = isolate()->heap()->AllocateRawWith<Heap::kRetryOrFail>(
HeapObject result = allocator()->AllocateRawWith<HeapAllocator::kRetryOrFail>(
Map::kSize, allocation_type);
DisallowGarbageCollection no_gc;
Heap* roots = allocation_type == AllocationType::kMap
......@@ -1937,7 +1938,8 @@ Handle<JSObject> Factory::CopyJSObjectWithAllocationSite(
DCHECK(V8_ALLOCATION_SITE_TRACKING_BOOL);
adjusted_object_size += AllocationMemento::kSize;
}
HeapObject raw_clone = isolate()->heap()->AllocateRawWith<Heap::kRetryOrFail>(
HeapObject raw_clone =
allocator()->AllocateRawWith<HeapAllocator::kRetryOrFail>(
adjusted_object_size, AllocationType::kYoung);
DCHECK(Heap::InYoungGeneration(raw_clone) || FLAG_single_generation);
......@@ -2175,7 +2177,7 @@ Handle<FixedDoubleArray> Factory::CopyFixedDoubleArray(
}
Handle<HeapNumber> Factory::NewHeapNumberForCodeAssembler(double value) {
return isolate()->heap()->CanAllocateInReadOnlySpace()
return CanAllocateInReadOnlySpace()
? NewHeapNumber<AllocationType::kReadOnly>(value)
: NewHeapNumber<AllocationType::kOld>(value);
}
......@@ -2362,7 +2364,8 @@ Handle<Code> Factory::CopyCode(Handle<Code> code) {
{
int obj_size = code->Size();
CodePageCollectionMemoryModificationScope code_allocation(heap);
HeapObject result = heap->AllocateRawWith<Heap::kRetryOrFail>(
HeapObject result =
allocator()->AllocateRawWith<HeapAllocator::kRetryOrFail>(
obj_size, AllocationType::kCode, AllocationOrigin::kRuntime);
// Copy code object.
......@@ -3874,7 +3877,7 @@ Handle<CallHandlerInfo> Factory::NewCallHandlerInfo(bool has_no_side_effect) {
}
bool Factory::CanAllocateInReadOnlySpace() {
return isolate()->heap()->CanAllocateInReadOnlySpace();
return allocator()->CanAllocateInReadOnlySpace();
}
bool Factory::EmptyStringRootIsInitialized() {
......
......@@ -111,11 +111,6 @@ class V8_EXPORT_PRIVATE Factory : public FactoryBase<Factory> {
public:
inline ReadOnlyRoots read_only_roots() const;
template <typename T>
Handle<T> MakeHandle(T obj) {
return handle(obj, isolate());
}
Handle<Oddball> NewOddball(Handle<Map> map, const char* to_string,
Handle<Object> to_number, const char* type_of,
byte kind);
......@@ -1032,6 +1027,8 @@ class V8_EXPORT_PRIVATE Factory : public FactoryBase<Factory> {
#endif // V8_SANDBOXED_EXTERNAL_POINTERS
}
V8_INLINE HeapAllocator* allocator() const;
bool CanAllocateInReadOnlySpace();
bool EmptyStringRootIsInitialized();
AllocationType AllocationTypeForInPlaceInternalizableString();
......
......@@ -50,6 +50,10 @@ ReadOnlySpace* HeapAllocator::read_only_space() const {
return read_only_space_;
}
bool HeapAllocator::CanAllocateInReadOnlySpace() const {
return read_only_space()->writable();
}
template <AllocationType type>
V8_WARN_UNUSED_RESULT V8_INLINE AllocationResult HeapAllocator::AllocateRaw(
int size_in_bytes, AllocationOrigin origin, AllocationAlignment alignment) {
......
......@@ -65,6 +65,8 @@ class V8_EXPORT_PRIVATE HeapAllocator final {
AllocationOrigin origin = AllocationOrigin::kRuntime,
AllocationAlignment alignment = kTaggedAligned);
V8_INLINE bool CanAllocateInReadOnlySpace() const;
#ifdef V8_ENABLE_ALLOCATION_TIMEOUT
void UpdateAllocationTimeout();
void SetAllocationTimeout(int allocation_timeout);
......
......@@ -203,17 +203,6 @@ AllocationResult Heap::AllocateRaw(int size_in_bytes, AllocationType type,
return heap_allocator_.AllocateRaw(size_in_bytes, type, origin, alignment);
}
template <Heap::AllocationRetryMode mode>
HeapObject Heap::AllocateRawWith(int size, AllocationType allocation,
AllocationOrigin origin,
AllocationAlignment alignment) {
return heap_allocator_.AllocateRawWith < mode ==
AllocationRetryMode::kLightRetry
? HeapAllocator::kLightRetry
: HeapAllocator::kRetryOrFail >
(size, allocation, origin, alignment);
}
Address Heap::AllocateRawOrFail(int size, AllocationType allocation,
AllocationOrigin origin,
AllocationAlignment alignment) {
......@@ -223,10 +212,6 @@ Address Heap::AllocateRawOrFail(int size, AllocationType allocation,
.address();
}
bool Heap::CanAllocateInReadOnlySpace() {
return read_only_space()->writable();
}
void Heap::RegisterExternalString(String string) {
DCHECK(string.IsExternalString());
DCHECK(!string.IsThinString());
......
......@@ -752,7 +752,6 @@ class Heap {
// This event is triggered after object is moved to a new place.
void OnMoveEvent(HeapObject target, HeapObject source, int size_in_bytes);
inline bool CanAllocateInReadOnlySpace();
bool deserialization_complete() const { return deserialization_complete_; }
// We can only invoke Safepoint() on the main thread local heap after
......@@ -2023,6 +2022,8 @@ class Heap {
// Allocation methods. =======================================================
// ===========================================================================
HeapAllocator* allocator() { return &heap_allocator_; }
// Allocates a JS Map in the heap.
V8_WARN_UNUSED_RESULT AllocationResult
AllocateMap(InstanceType instance_type, int instance_size,
......
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