summaryrefslogtreecommitdiff
path: root/deps/v8/src/heap/heap-inl.h
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/heap/heap-inl.h')
-rw-r--r--deps/v8/src/heap/heap-inl.h64
1 files changed, 50 insertions, 14 deletions
diff --git a/deps/v8/src/heap/heap-inl.h b/deps/v8/src/heap/heap-inl.h
index 0e5230f1e0..e618b91058 100644
--- a/deps/v8/src/heap/heap-inl.h
+++ b/deps/v8/src/heap/heap-inl.h
@@ -10,6 +10,7 @@
// Clients of this interface shouldn't depend on lots of heap internals.
// Do not include anything from src/heap other than src/heap/heap.h and its
// write barrier here!
+#include "src/base/atomicops.h"
#include "src/heap/heap-write-barrier.h"
#include "src/heap/heap.h"
#include "src/heap/third-party/heap-api.h"
@@ -65,7 +66,14 @@ int64_t Heap::external_memory() {
}
void Heap::update_external_memory(int64_t delta) {
- isolate()->isolate_data()->external_memory_ += delta;
+ const int64_t amount = isolate()->isolate_data()->external_memory_ + delta;
+ isolate()->isolate_data()->external_memory_ = amount;
+ if (amount <
+ isolate()->isolate_data()->external_memory_low_since_mark_compact_) {
+ isolate()->isolate_data()->external_memory_low_since_mark_compact_ = amount;
+ isolate()->isolate_data()->external_memory_limit_ =
+ amount + kExternalAllocationSoftLimit;
+ }
}
void Heap::update_external_memory_concurrently_freed(uintptr_t freed) {
@@ -73,8 +81,8 @@ void Heap::update_external_memory_concurrently_freed(uintptr_t freed) {
}
void Heap::account_external_memory_concurrently_freed() {
- isolate()->isolate_data()->external_memory_ -=
- external_memory_concurrently_freed_;
+ update_external_memory(
+ -static_cast<int64_t>(external_memory_concurrently_freed_));
external_memory_concurrently_freed_ = 0;
}
@@ -155,6 +163,14 @@ size_t Heap::NewSpaceAllocationCounter() {
return new_space_allocation_counter_ + new_space()->AllocatedSinceLastGC();
}
+inline const base::AddressRegion& Heap::code_range() {
+#ifdef V8_ENABLE_THIRD_PARTY_HEAP
+ return tp_heap_->GetCodeRange();
+#else
+ return memory_allocator_->code_range();
+#endif
+}
+
AllocationResult Heap::AllocateRaw(int size_in_bytes, AllocationType type,
AllocationOrigin origin,
AllocationAlignment alignment) {
@@ -248,13 +264,13 @@ template <Heap::AllocationRetryMode mode>
HeapObject Heap::AllocateRawWith(int size, AllocationType allocation,
AllocationOrigin origin,
AllocationAlignment alignment) {
+ DCHECK(AllowHandleAllocation::IsAllowed());
+ DCHECK(AllowHeapAllocation::IsAllowed());
if (V8_ENABLE_THIRD_PARTY_HEAP_BOOL) {
AllocationResult result = AllocateRaw(size, allocation, origin, alignment);
DCHECK(!result.IsRetry());
return result.ToObjectChecked();
}
- DCHECK(AllowHandleAllocation::IsAllowed());
- DCHECK(AllowHeapAllocation::IsAllowed());
DCHECK_EQ(gc_state_, NOT_IN_GC);
Heap* heap = isolate()->heap();
Address* top = heap->NewSpaceAllocationTopAddress();
@@ -286,7 +302,7 @@ HeapObject Heap::AllocateRawWith(int size, AllocationType allocation,
Address Heap::DeserializerAllocate(AllocationType type, int size_in_bytes) {
if (V8_ENABLE_THIRD_PARTY_HEAP_BOOL) {
AllocationResult allocation = tp_heap_->Allocate(
- size_in_bytes, type, AllocationAlignment::kWordAligned);
+ size_in_bytes, type, AllocationAlignment::kDoubleAligned);
return allocation.ToObjectChecked().ptr();
} else {
UNIMPLEMENTED(); // unimplemented
@@ -560,11 +576,27 @@ Oddball Heap::ToBoolean(bool condition) {
}
int Heap::NextScriptId() {
- int last_id = last_script_id().value();
- if (last_id == Smi::kMaxValue) last_id = v8::UnboundScript::kNoScriptId;
- last_id++;
- set_last_script_id(Smi::FromInt(last_id));
- return last_id;
+ FullObjectSlot last_script_id_slot(&roots_table()[RootIndex::kLastScriptId]);
+ Smi last_id = Smi::cast(last_script_id_slot.Relaxed_Load());
+ Smi new_id, last_id_before_cas;
+ do {
+ if (last_id.value() == Smi::kMaxValue) {
+ STATIC_ASSERT(v8::UnboundScript::kNoScriptId == 0);
+ new_id = Smi::FromInt(1);
+ } else {
+ new_id = Smi::FromInt(last_id.value() + 1);
+ }
+
+ // CAS returns the old value on success, and the current value in the slot
+ // on failure. Therefore, we want to break if the returned value matches the
+ // old value (last_id), and keep looping (with the new last_id value) if it
+ // doesn't.
+ last_id_before_cas = last_id;
+ last_id =
+ Smi::cast(last_script_id_slot.Relaxed_CompareAndSwap(last_id, new_id));
+ } while (last_id != last_id_before_cas);
+
+ return new_id.value();
}
int Heap::NextDebuggingId() {
@@ -608,17 +640,21 @@ void Heap::DecrementExternalBackingStoreBytes(ExternalBackingStoreType type,
base::CheckedDecrement(&backing_store_bytes_, amount);
}
+bool Heap::HasDirtyJSFinalizationRegistries() {
+ return !dirty_js_finalization_registries_list().IsUndefined(isolate());
+}
+
AlwaysAllocateScope::AlwaysAllocateScope(Heap* heap) : heap_(heap) {
heap_->always_allocate_scope_count_++;
}
-AlwaysAllocateScope::AlwaysAllocateScope(Isolate* isolate)
- : AlwaysAllocateScope(isolate->heap()) {}
-
AlwaysAllocateScope::~AlwaysAllocateScope() {
heap_->always_allocate_scope_count_--;
}
+AlwaysAllocateScopeForTesting::AlwaysAllocateScopeForTesting(Heap* heap)
+ : scope_(heap) {}
+
CodeSpaceMemoryModificationScope::CodeSpaceMemoryModificationScope(Heap* heap)
: heap_(heap) {
if (heap_->write_protect_code_memory()) {