WebKit Bugzilla
Attachment 339879 Details for
Bug 185447
: Consider stopping various automatic threads when we VM::shrinkFootprint()
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
patch
a-backup.diff (text/plain), 11.70 KB, created by
Saam Barati
on 2018-05-08 14:37:27 PDT
(
hide
)
Description:
patch
Filename:
MIME Type:
Creator:
Saam Barati
Created:
2018-05-08 14:37:27 PDT
Size:
11.70 KB
patch
obsolete
>Index: Source/JavaScriptCore/ChangeLog >=================================================================== >--- Source/JavaScriptCore/ChangeLog (revision 231512) >+++ Source/JavaScriptCore/ChangeLog (working copy) >@@ -1,3 +1,27 @@ >+2018-05-08 Saam Barati <sbarati@apple.com> >+ >+ Add JSVirtualMachine SPI to shrink the memory footprint of the VM >+ https://bugs.webkit.org/show_bug.cgi?id=185441 >+ <rdar://problem/39999414> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ This patch adds JSVirtualMachine SPI to release as much memory as possible. >+ The SPI does: >+ - Deletes all code caches. >+ - Synchronous GC. >+ - Run the scavenger. >+ >+ * API/JSVirtualMachine.mm: >+ (-[JSVirtualMachine shrinkFootprint]): >+ * API/JSVirtualMachinePrivate.h: Added. >+ * API/tests/testapi.mm: >+ (testObjectiveCAPIMain): >+ * JavaScriptCore.xcodeproj/project.pbxproj: >+ * runtime/VM.cpp: >+ (JSC::VM::shrinkFootprint): >+ * runtime/VM.h: >+ > 2018-05-08 Ryan Haddad <ryanhaddad@apple.com> > > Unreviewed, rolling out r231468. >Index: Source/JavaScriptCore/API/JSVirtualMachine.mm >=================================================================== >--- Source/JavaScriptCore/API/JSVirtualMachine.mm (revision 231496) >+++ Source/JavaScriptCore/API/JSVirtualMachine.mm (working copy) >@@ -268,6 +268,13 @@ - (NSMapTable *)externalRememberedSet > return m_externalRememberedSet; > } > >+- (void)shrinkFootprint >+{ >+ JSC::VM* vm = toJS(m_group); >+ JSC::JSLockHolder locker(vm); >+ vm->shrinkFootprint(); >+} >+ > @end > > static void scanExternalObjectGraph(JSC::VM& vm, JSC::SlotVisitor& visitor, void* root, bool lockAcquired) >Index: Source/JavaScriptCore/API/JSVirtualMachinePrivate.h >=================================================================== >--- Source/JavaScriptCore/API/JSVirtualMachinePrivate.h (nonexistent) >+++ Source/JavaScriptCore/API/JSVirtualMachinePrivate.h (working copy) >@@ -0,0 +1,48 @@ >+/* >+ * Copyright (C) 2018 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY >+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE >+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR >+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, >+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, >+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR >+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY >+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT >+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE >+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#ifndef JSVirtualMachinePrivate_h >+#define JSVirtualMachinePrivate_h >+ >+#if JSC_OBJC_API_ENABLED >+ >+#import <JavaScriptCore/JSVirtualMachine.h> >+ >+@interface JSVirtualMachine(Private) >+ >+/*! >+@property >+@discussion Shrinks the memory footprint of the VM by deleting various internal caches, >+ running synchronous garbage collection, and releasing memory back to the OS. For this >+ to free as much memory as possible, do not call this when JavaScript is running on the stack. >+*/ >+ >+- (void)shrinkFootprint; // FIXME: Annotate this with NS_AVAILABLE: <rdar://problem/40071332>. >+ >+@end >+ >+#endif // JSC_OBJC_API_ENABLED >+ >+#endif // JSVirtualMachinePrivate_h >Index: Source/JavaScriptCore/API/tests/testapi.mm >=================================================================== >--- Source/JavaScriptCore/API/tests/testapi.mm (revision 231496) >+++ Source/JavaScriptCore/API/tests/testapi.mm (working copy) >@@ -28,11 +28,14 @@ > #import "CurrentThisInsideBlockGetterTest.h" > #import "DateTests.h" > #import "JSExportTests.h" >+#import "JSVirtualMachinePrivate.h" > #import "Regress141275.h" > #import "Regress141809.h" > > #import <pthread.h> > #import <vector> >+#import <wtf/MemoryFootprint.h> >+#import <wtf/Optional.h> > > extern "C" void JSSynchronousGarbageCollectForDebugging(JSContextRef); > extern "C" void JSSynchronousEdenCollectForDebugging(JSContextRef); >@@ -1469,6 +1472,33 @@ static void testObjectiveCAPIMain() > checkResult(@"Ran code in five concurrent VMs that GC'd", ok); > } > >+ @autoreleasepool { >+ JSContext *context = [[JSContext alloc] init]; >+ JSVirtualMachine *vm = [context virtualMachine]; >+ [vm shrinkFootprint]; // Make sure that when we allocate a ton of memory below we reuse at little as possible. >+ >+ std::optional<size_t> footprintBefore = WTF::memoryFootprint(); >+ RELEASE_ASSERT(footprintBefore); >+ >+ [context evaluateScript:@"for (let i = 0; i < 10000; ++i) { eval(`myVariable_${i} = [i]`); }"]; >+ >+ static constexpr size_t approximateBytes = 10000 * sizeof(int); >+ std::optional<size_t> footprintMiddle = WTF::memoryFootprint(); >+ RELEASE_ASSERT(footprintMiddle); >+ checkResult(@"Footprint is larger than what we allocated", *footprintMiddle > approximateBytes); >+ checkResult(@"Footprint got larger as we allocated a ton of stuff", *footprintMiddle > *footprintBefore); >+ size_t allocationDelta = *footprintMiddle - *footprintBefore; >+ checkResult(@"We allocated as much or more memory than what we expected to", allocationDelta >= approximateBytes); >+ >+ [context evaluateScript:@"for (let i = 0; i < 10000; ++i) { eval(`myVariable_${i} = null`); }"]; >+ [vm shrinkFootprint]; >+ std::optional<size_t> footprintAfter = WTF::memoryFootprint(); >+ RELEASE_ASSERT(footprintAfter); >+ checkResult(@"Footprint got smaller after we shrank the VM", *footprintAfter < *footprintMiddle); >+ size_t freeDelta = *footprintMiddle - *footprintAfter; >+ checkResult(@"Shrinking the footprint of the VM actually freed memory", freeDelta > (approximateBytes / 2)); >+ } >+ > currentThisInsideBlockGetterTest(); > runDateTests(); > runJSExportTests(); >Index: Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj >=================================================================== >--- Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj (revision 231496) >+++ Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj (working copy) >@@ -1100,6 +1100,7 @@ > 7919B7801E03559C005BEED8 /* B3Compile.h in Headers */ = {isa = PBXBuildFile; fileRef = 7919B77F1E03559C005BEED8 /* B3Compile.h */; settings = {ATTRIBUTES = (Private, ); }; }; > 79233C2B1D34715700C5A834 /* JITMathIC.h in Headers */ = {isa = PBXBuildFile; fileRef = 79233C291D34715700C5A834 /* JITMathIC.h */; settings = {ATTRIBUTES = (Private, ); }; }; > 792CB34A1C4EED5C00D13AF3 /* PCToCodeOriginMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 792CB3481C4EED5C00D13AF3 /* PCToCodeOriginMap.h */; settings = {ATTRIBUTES = (Private, ); }; }; >+ 795AC61820A2355E0052C76C /* JSVirtualMachinePrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 795AC61720A2354B0052C76C /* JSVirtualMachinePrivate.h */; settings = {ATTRIBUTES = (Private, ); }; }; > 7964656A1B952FF0003059EE /* GetPutInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 796465681B952FF0003059EE /* GetPutInfo.h */; settings = {ATTRIBUTES = (Private, ); }; }; > 7965C2171E5D799600B7591D /* AirAllocateRegistersByGraphColoring.h in Headers */ = {isa = PBXBuildFile; fileRef = 7965C2151E5D799600B7591D /* AirAllocateRegistersByGraphColoring.h */; settings = {ATTRIBUTES = (Private, ); }; }; > 796DAA2B1E89CCD6005DF24A /* CalleeBits.h in Headers */ = {isa = PBXBuildFile; fileRef = 796DAA2A1E89CCD6005DF24A /* CalleeBits.h */; settings = {ATTRIBUTES = (Private, ); }; }; >@@ -3615,6 +3616,7 @@ > 79233C291D34715700C5A834 /* JITMathIC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JITMathIC.h; sourceTree = "<group>"; }; > 792CB3471C4EED5C00D13AF3 /* PCToCodeOriginMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PCToCodeOriginMap.cpp; sourceTree = "<group>"; }; > 792CB3481C4EED5C00D13AF3 /* PCToCodeOriginMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PCToCodeOriginMap.h; sourceTree = "<group>"; }; >+ 795AC61720A2354B0052C76C /* JSVirtualMachinePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSVirtualMachinePrivate.h; sourceTree = "<group>"; }; > 795F099C1E03600500BBE37F /* B3Compile.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = B3Compile.cpp; path = b3/B3Compile.cpp; sourceTree = "<group>"; }; > 796465681B952FF0003059EE /* GetPutInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GetPutInfo.h; sourceTree = "<group>"; }; > 7965C2141E5D799600B7591D /* AirAllocateRegistersByGraphColoring.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AirAllocateRegistersByGraphColoring.cpp; path = b3/air/AirAllocateRegistersByGraphColoring.cpp; sourceTree = "<group>"; }; >@@ -5854,6 +5856,7 @@ > 14BD5A2B0A3E91F600BAF59C /* JSValueRef.cpp */, > 1482B6EA0A4300B300517CFC /* JSValueRef.h */, > 86E3C60F167BAB87006D760A /* JSVirtualMachine.h */, >+ 795AC61720A2354B0052C76C /* JSVirtualMachinePrivate.h */, > 86E3C610167BAB87006D760A /* JSVirtualMachine.mm */, > 86E3C611167BAB87006D760A /* JSVirtualMachineInternal.h */, > A7482E37116A697B003B0712 /* JSWeakObjectMapRefInternal.h */, >@@ -8609,6 +8612,7 @@ > 0FFB921C16D02F110055A5DB /* DFGOSRExitCompilationInfo.h in Headers */, > 0F7025AA1714B0FC00382C0E /* DFGOSRExitCompilerCommon.h in Headers */, > 0F392C8A1B46188400844728 /* DFGOSRExitFuzz.h in Headers */, >+ 795AC61820A2355E0052C76C /* JSVirtualMachinePrivate.h in Headers */, > 0FEFC9AB1681A3B600567F53 /* DFGOSRExitJumpPlaceholder.h in Headers */, > 0F235BEE17178E7300690C7F /* DFGOSRExitPreparation.h in Headers */, > 0F6237981AE45CA700D402EA /* DFGPhantomInsertionPhase.h in Headers */, >Index: Source/JavaScriptCore/runtime/VM.cpp >=================================================================== >--- Source/JavaScriptCore/runtime/VM.cpp (revision 231496) >+++ Source/JavaScriptCore/runtime/VM.cpp (working copy) >@@ -771,6 +771,15 @@ void VM::deleteAllCode(DeleteAllCodeEffo > }); > } > >+void VM::shrinkFootprint() >+{ >+ deleteAllCode(DeleteAllCodeIfNotCollecting); >+ heap.collectSync(); >+ WTF::releaseFastMallocFreeMemory(); >+ // FIXME: Consider stopping various automatic threads here. >+ // https://bugs.webkit.org/show_bug.cgi?id=185447 >+} >+ > SourceProviderCache* VM::addSourceProviderCache(SourceProvider* sourceProvider) > { > auto addResult = sourceProviderCacheMap.add(sourceProvider, nullptr); >Index: Source/JavaScriptCore/runtime/VM.h >=================================================================== >--- Source/JavaScriptCore/runtime/VM.h (revision 231496) >+++ Source/JavaScriptCore/runtime/VM.h (working copy) >@@ -746,6 +746,8 @@ public: > JS_EXPORT_PRIVATE void deleteAllCode(DeleteAllCodeEffort); > JS_EXPORT_PRIVATE void deleteAllLinkedCode(DeleteAllCodeEffort); > >+ void shrinkFootprint(); >+ > WatchpointSet* ensureWatchpointSetForImpureProperty(const Identifier&); > void registerWatchpointForImpureProperty(const Identifier&, Watchpoint*); >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 185447
:
339879