Skip to content

Commit b682c58

Browse files
author
Mark Lam
committed
Add Options::maxHeapSizeAsRAMSizeMultiple() to limit max memory usage for testing.
https://bugs.webkit.org/show_bug.cgi?id=271986 rdar://125733077 Reviewed by Keith Miller. Currently, we're only applying this max check to CompleteSubspace::tryAllocateSlow. We found that adding it to LocalAllocator::allocateSlowCase can cause crashes due to failed Structure allocations (which are fatal). As a result, the testing disruption from those crashes far outweigh any benefits we currently get from it. So, we'll leave the max check out of LocalAllocator::allocateSlowCase for now. * Source/JavaScriptCore/heap/CompleteSubspace.cpp: (JSC::CompleteSubspace::tryAllocateSlow): * Source/JavaScriptCore/jsc.cpp: (jscmain): * Source/JavaScriptCore/runtime/OptionsList.h: Canonical link: https://commits.webkit.org/276909@main
1 parent 4c3661f commit b682c58

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

‎Source/JavaScriptCore/heap/CompleteSubspace.cpp‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2017-2021 Apple Inc. All rights reserved.
2+
* Copyright (C) 2017-2024 Apple Inc. All rights reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -32,6 +32,7 @@
3232
#include "LocalAllocatorInlines.h"
3333
#include "MarkedSpaceInlines.h"
3434
#include "SubspaceInlines.h"
35+
#include <wtf/RAMSize.h>
3536

3637
namespace JSC {
3738

@@ -130,7 +131,11 @@ void* CompleteSubspace::tryAllocateSlow(VM& vm, size_t size, GCDeferralContext*
130131
}
131132

132133
vm.heap.collectIfNecessaryOrDefer(deferralContext);
133-
134+
if (UNLIKELY(Options::maxHeapSizeAsRAMSizeMultiple())) {
135+
if (vm.heap.capacity() > Options::maxHeapSizeAsRAMSizeMultiple() * WTF::ramSize())
136+
return nullptr;
137+
}
138+
134139
size = WTF::roundUpToMultipleOf<MarkedSpace::sizeStep>(size);
135140
PreciseAllocation* allocation = PreciseAllocation::tryCreate(vm.heap, size, this, m_space.m_preciseAllocations.size());
136141
if (!allocation)

‎Source/JavaScriptCore/jsc.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4350,6 +4350,9 @@ int jscmain(int argc, char** argv)
43504350
JSC::JITOperationList::populateDisassemblyLabelsInEmbedder(&startOfJITOperationsInShell, &endOfJITOperationsInShell);
43514351
#endif
43524352

4353+
if (!Options::maxHeapSizeAsRAMSizeMultiple())
4354+
Options::maxHeapSizeAsRAMSizeMultiple() = 2;
4355+
43534356
initializeTimeoutIfNeeded();
43544357

43554358
#if OS(DARWIN) || OS(LINUX)

‎Source/JavaScriptCore/runtime/OptionsList.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2023 Apple Inc. All rights reserved.
2+
* Copyright (C) 2019-2024 Apple Inc. All rights reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -361,6 +361,7 @@ bool canUseHandlerIC();
361361
v(Unsigned, numberOfGCMarkers, computeNumberOfGCMarkers(8), Normal, nullptr) \
362362
v(Bool, useParallelMarkingConstraintSolver, true, Normal, nullptr) \
363363
v(Unsigned, opaqueRootMergeThreshold, 1000, Normal, nullptr) \
364+
v(Unsigned, maxHeapSizeAsRAMSizeMultiple, 0, Normal, nullptr) \
364365
v(Double, minHeapUtilization, 0.8, Normal, nullptr) \
365366
v(Double, minMarkedBlockUtilization, 0.9, Normal, nullptr) \
366367
v(Unsigned, slowPathAllocsBetweenGCs, 0, Normal, "force a GC on every Nth slow path alloc, where N is specified by this option") \

0 commit comments

Comments
 (0)