Skip to content

Commit 852aa18

Browse files
Samuel GroßV8 LUCI CQ
authored andcommitted
[sandbox] Do not trigger GC during EPT entry allocation
This simplifies some call sites as they do not need to worry about stores to external pointer fields (especially lazily initialized ones) triggering GCs. This also keeps the sandbox and non-sandbox mode more consistent, as these stores will never trigger GC in non-sandbox builds. Since there must be millions of objects that own the external pointer table entries, the chances are quite high that GCs will anyway be scheduled. If not, we should instead see if we can introduce an API to only schedule incremental marking but not perform GC finalization. Bug: v8:13535 Change-Id: Ie3c82b51194746107d4b0ed61d47abf87d28ba63 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4061688 Commit-Queue: Samuel Groß <[email protected]> Reviewed-by: Michael Lippautz <[email protected]> Cr-Commit-Position: refs/heads/main@{#84508}
1 parent 6669b5a commit 852aa18

2 files changed

Lines changed: 8 additions & 12 deletions

File tree

src/sandbox/external-pointer-table-inl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define V8_SANDBOX_EXTERNAL_POINTER_TABLE_INL_H_
77

88
#include "src/base/atomicops.h"
9+
#include "src/common/assert-scope.h"
910
#include "src/sandbox/external-pointer-table.h"
1011
#include "src/sandbox/external-pointer.h"
1112
#include "src/utils/allocation.h"
@@ -75,6 +76,13 @@ ExternalPointerHandle ExternalPointerTable::AllocateAndInitializeEntry(
7576
Isolate* isolate, Address initial_value, ExternalPointerTag tag) {
7677
DCHECK(is_initialized());
7778

79+
// We currently don't want entry allocation to trigger garbage collection as
80+
// this may cause seemingly harmless pointer field assignments to trigger
81+
// garbage collection. This is especially true for lazily-initialized
82+
// external pointer slots which will typically only allocate the external
83+
// pointer table entry when the pointer is first set to a non-null value.
84+
DisallowGarbageCollection no_gc;
85+
7886
Freelist freelist;
7987
bool success = false;
8088
while (!success) {

src/sandbox/external-pointer-table.cc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -315,18 +315,6 @@ ExternalPointerTable::Freelist ExternalPointerTable::Grow(Isolate* isolate) {
315315

316316
set_capacity(new_capacity);
317317

318-
// Schedule GC when the table's utilization crosses one of these thresholds.
319-
constexpr double kGCThresholds[] = {0.5, 0.75, 0.9, 0.95, 0.99};
320-
constexpr double kMaxCapacity = static_cast<double>(kMaxExternalPointers);
321-
double old_utilization = static_cast<double>(old_capacity) / kMaxCapacity;
322-
double new_utilization = static_cast<double>(new_capacity) / kMaxCapacity;
323-
for (double threshold : kGCThresholds) {
324-
if (old_utilization < threshold && new_utilization >= threshold) {
325-
isolate->heap()->ReportExternalMemoryPressure();
326-
break;
327-
}
328-
}
329-
330318
// Build freelist bottom to top, which might be more cache friendly.
331319
uint32_t start = std::max<uint32_t>(old_capacity, 1); // Skip entry zero
332320
uint32_t last = new_capacity - 1;

0 commit comments

Comments
 (0)