JavaScriptCore: Added PageAllocationAligned, a cross-platform abstraction for memory...
authorbarraclough@apple.com <barraclough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Dec 2010 23:53:25 +0000 (23:53 +0000)
committerbarraclough@apple.com <barraclough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Dec 2010 23:53:25 +0000 (23:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=51359

Patch by Geoffrey Garen <ggaren@apple.com> on 2010-12-21
Reviewed by Gavin Barraclough & Oliver Hunt.

I think this patch fixes <rdar://problem/8107952> [5.0.1] WER crash in
Heap::allocateBlock (1902752929), and some other leaks and crashes as well.

* Android.mk:
* CMakeLists.txt:
* GNUmakefile.am:
* JavaScriptCore.gypi:
* JavaScriptCore.vcproj/WTF/WTF.vcproj:
* JavaScriptCore.xcodeproj/project.pbxproj: Updated build files.

* runtime/AlignedMemoryAllocator.h: Removed. Supplanted by
PageAllocationAligned.

* runtime/Collector.cpp:
(JSC::Heap::destroy):
(JSC::Heap::allocateBlock):
(JSC::Heap::freeBlock):
(JSC::Heap::addWeakGCHandle):
* runtime/Collector.h: Switched from AlignedMemoryAllocator to
PageAllocationAligned.

* runtime/GCHandle.cpp:
* runtime/GCHandle.h: Ditto.

* wtf/PageAllocation.h:
(WTF::PageAllocation::PageAllocation): Removed aligned memory allocation
functions. Supplanted by PageAllocationAligned.

* wtf/PageAllocationAligned.cpp: Added.
(WTF::PageAllocationAligned::allocate):
(WTF::PageAllocationAligned::deallocate):
* wtf/PageAllocationAligned.h: Added.
(WTF::PageAllocationAligned::PageAllocationAligned): New cross-platform
class for doing aligned memory allocation. This class properly matches
allocation and deallocation library calls, fixing a long-standing bug
in PageAllocation.

* wtf/Platform.h: Removed some defunction VM platform defines.

* wtf/wtf.pri: Updated build files.

JavaScriptGlue: Added PageAllocationAligned, a cross-platform abstraction for memory allocations with arbitrary alignment requirements
https://bugs.webkit.org/show_bug.cgi?id=51359

Patch by Geoffrey Garen <ggaren@apple.com> on 2010-12-21
Reviewed by Gavin Barraclough & Oliver Hunt.

* ForwardingHeaders/wtf/PageAllocationAligned.h: Added.

WebCore: Added PageAllocationAligned, a cross-platform abstraction for memory allocations with arbitrary alignment requirements
https://bugs.webkit.org/show_bug.cgi?id=51359

Patch by Geoffrey Garen <ggaren@apple.com> on 2010-12-21
Reviewed by Gavin Barraclough & Oliver Hunt.

* ForwardingHeaders/wtf/PageAllocationAligned.h: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@74431 268f45cc-cd09-0410-ab3c-d52691b4dbfc

29 files changed:
JavaScriptCore/Android.mk
JavaScriptCore/CMakeLists.txt
JavaScriptCore/ChangeLog
JavaScriptCore/GNUmakefile.am
JavaScriptCore/JavaScriptCore.exp
JavaScriptCore/JavaScriptCore.gypi
JavaScriptCore/JavaScriptCore.vcproj/WTF/WTF.vcproj
JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
JavaScriptCore/runtime/AlignedMemoryAllocator.h [deleted file]
JavaScriptCore/runtime/Collector.cpp
JavaScriptCore/runtime/Collector.h
JavaScriptCore/runtime/GCHandle.cpp
JavaScriptCore/runtime/GCHandle.h
JavaScriptCore/runtime/MarkStack.h
JavaScriptCore/wtf/OSAllocator.h
JavaScriptCore/wtf/OSAllocatorPosix.cpp
JavaScriptCore/wtf/OSAllocatorSymbian.cpp
JavaScriptCore/wtf/OSAllocatorWin.cpp
JavaScriptCore/wtf/PageAllocation.h
JavaScriptCore/wtf/PageAllocationAligned.cpp [new file with mode: 0644]
JavaScriptCore/wtf/PageAllocationAligned.h [new file with mode: 0644]
JavaScriptCore/wtf/PageBlock.h
JavaScriptCore/wtf/PageReservation.h
JavaScriptCore/wtf/Platform.h
JavaScriptCore/wtf/wtf.pri
JavaScriptGlue/ChangeLog
JavaScriptGlue/ForwardingHeaders/wtf/PageAllocationAligned.h [new file with mode: 0644]
WebCore/ChangeLog
WebCore/ForwardingHeaders/wtf/PageAllocationAligned.h [new file with mode: 0644]

index b87ff08..70e8ef4 100644 (file)
@@ -162,6 +162,7 @@ LOCAL_SRC_FILES := \
        wtf/FastMalloc.cpp \
        wtf/HashTable.cpp \
        wtf/MainThread.cpp \
+       wtf/PageAllocationAligned.cpp\
        wtf/PageBlock.cpp\
        wtf/RandomNumber.cpp \
        wtf/RefCountedLeakCounter.cpp \
index 79f3dce..e275db8 100644 (file)
@@ -171,6 +171,7 @@ SET(JavaScriptCore_SOURCES
     yarr/RegexJIT.cpp
 
     wtf/DateMath.cpp
+    wtf/PageAllocationAligned.cpp
     wtf/PageBlock.cpp
 )
 SET(JavaScriptCore_HEADERS )
index 85a35e6..c8f9218 100644 (file)
@@ -1,3 +1,51 @@
+2010-12-21  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Gavin Barraclough & Oliver Hunt.
+
+        Added PageAllocationAligned, a cross-platform abstraction for memory allocations with arbitrary alignment requirements
+        https://bugs.webkit.org/show_bug.cgi?id=51359
+        
+        I think this patch fixes <rdar://problem/8107952> [5.0.1] WER crash in
+        Heap::allocateBlock (1902752929), and some other leaks and crashes as well.
+
+        * Android.mk:
+        * CMakeLists.txt:
+        * GNUmakefile.am:
+        * JavaScriptCore.gypi:
+        * JavaScriptCore.vcproj/WTF/WTF.vcproj:
+        * JavaScriptCore.xcodeproj/project.pbxproj: Updated build files.
+
+        * runtime/AlignedMemoryAllocator.h: Removed. Supplanted by
+        PageAllocationAligned.
+
+        * runtime/Collector.cpp:
+        (JSC::Heap::destroy):
+        (JSC::Heap::allocateBlock):
+        (JSC::Heap::freeBlock):
+        (JSC::Heap::addWeakGCHandle):
+        * runtime/Collector.h: Switched from AlignedMemoryAllocator to
+        PageAllocationAligned.
+
+        * runtime/GCHandle.cpp:
+        * runtime/GCHandle.h: Ditto.
+
+        * wtf/PageAllocation.h:
+        (WTF::PageAllocation::PageAllocation): Removed aligned memory allocation
+        functions. Supplanted by PageAllocationAligned.
+
+        * wtf/PageAllocationAligned.cpp: Added.
+        (WTF::PageAllocationAligned::allocate):
+        (WTF::PageAllocationAligned::deallocate):
+        * wtf/PageAllocationAligned.h: Added.
+        (WTF::PageAllocationAligned::PageAllocationAligned): New cross-platform
+        class for doing aligned memory allocation. This class properly matches
+        allocation and deallocation library calls, fixing a long-standing bug
+        in PageAllocation.
+
+        * wtf/Platform.h: Removed some defunction VM platform defines.
+
+        * wtf/wtf.pri: Updated build files.
+
 2010-12-21  Oliver Hunt  <oliver@apple.com>
 
         Reviewed by Gavin Barraclough.
index 2dc1522..a4de3c6 100644 (file)
@@ -216,7 +216,6 @@ javascriptcore_sources += \
        JavaScriptCore/profiler/ProfileNode.h \
        JavaScriptCore/profiler/Profiler.cpp \
        JavaScriptCore/profiler/Profiler.h \
-       JavaScriptCore/runtime/AlignedMemoryAllocator.h \
        JavaScriptCore/runtime/ArgList.cpp \
        JavaScriptCore/runtime/ArgList.h \
        JavaScriptCore/runtime/Arguments.cpp \
@@ -477,9 +476,11 @@ javascriptcore_sources += \
        JavaScriptCore/wtf/OwnPtrCommon.h \
        JavaScriptCore/wtf/OwnPtr.h \
        JavaScriptCore/wtf/PageAllocation.h \
-       JavaScriptCore/wtf/PageBlock.h \
+       JavaScriptCore/wtf/PageAllocationAligned.cpp \
+       JavaScriptCore/wtf/PageAllocationAligned.h \
        JavaScriptCore/wtf/PageReservation.h \
        JavaScriptCore/wtf/PageBlock.cpp \
+       JavaScriptCore/wtf/PageBlock.h \
        JavaScriptCore/wtf/PassOwnArrayPtr.h \
        JavaScriptCore/wtf/PassOwnPtr.h \
        JavaScriptCore/wtf/PassRefPtr.h \
index f310f80..a8ee65b 100644 (file)
@@ -360,7 +360,7 @@ __ZN3WTF10fastCallocEmm
 __ZN3WTF10fastMallocEm
 __ZN3WTF10fastStrDupEPKc
 __ZN3WTF11OSAllocator16reserveAndCommitEmNS0_5UsageEbb
-__ZN3WTF11OSAllocator7releaseEPvm
+__ZN3WTF11OSAllocator18releaseDecommittedEPvm
 __ZN3WTF11commentAtomE
 __ZN3WTF11currentTimeEv
 __ZN3WTF11dtoaRoundDPEPcdiRbRiRj
index 2ea0af1..bd19875 100644 (file)
             'profiler/Profiler.cpp',
             'profiler/Profiler.h',
             'profiler/ProfilerServer.h',
-            'runtime/AlignedMemoryAllocator.h',
             'runtime/ArgList.cpp',
             'runtime/ArgList.h',
             'runtime/Arguments.cpp',
             'wtf/OwnPtrCommon.h',
             'wtf/PageBlock.cpp',
             'wtf/PageAllocation.h',
+            'wtf/PageAllocationAligned.cpp',
+            'wtf/PageAllocationAligned.h',
             'wtf/PageReservation',
             'wtf/PassOwnPtr.h',
             'wtf/PassRefPtr.h',
index acd1c4e..e232683 100644 (file)
                        >
                </File>
                <File
+                       RelativePath="..\..\wtf\PageBlock.h"
+                       >
+               </File>
+               <File
                        RelativePath="..\..\wtf\PageAllocation.h"
                        >
                </File>
                <File
+                       RelativePath="..\..\wtf\PageAllocationAligned.cpp"
+                       >
+               </File>
+               <File
+                       RelativePath="..\..\wtf\PageAllocationAligned.h"
+                       >
+               </File>
+               <File
                        RelativePath="..\..\wtf\PageReservation.h"
                        >
                </File>
index 76af919..58c376a 100644 (file)
                14F8BA3E107EC886009892DC /* FastMalloc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65E217B908E7EECC0023E5F6 /* FastMalloc.cpp */; };
                14F8BA43107EC88C009892DC /* TCSystemAlloc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6541BD7008E80A17002CBEE7 /* TCSystemAlloc.cpp */; };
                14F8BA4F107EC899009892DC /* Collector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F692A8520255597D01FF60F7 /* Collector.cpp */; };
+               14FFF98C12BFFF7500795BB8 /* PageAllocationAligned.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14FFF98A12BFFF7500795BB8 /* PageAllocationAligned.cpp */; };
+               14FFF98D12BFFF7500795BB8 /* PageAllocationAligned.h in Headers */ = {isa = PBXBuildFile; fileRef = 14FFF98B12BFFF7500795BB8 /* PageAllocationAligned.h */; settings = {ATTRIBUTES = (Private, ); }; };
                180B9B080F16D94F009BDBC5 /* CurrentTime.h in Headers */ = {isa = PBXBuildFile; fileRef = 180B9AF00F16C569009BDBC5 /* CurrentTime.h */; settings = {ATTRIBUTES = (Private, ); }; };
                180B9BFE0F16E94D009BDBC5 /* CurrentTime.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 180B9AEF0F16C569009BDBC5 /* CurrentTime.cpp */; };
                18BAB55310DAE054000D945B /* ThreadIdentifierDataPthreads.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 18BAB52710DADFCD000D945B /* ThreadIdentifierDataPthreads.cpp */; };
                BCFD8C920EEB2EE700283848 /* JumpTable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCFD8C900EEB2EE700283848 /* JumpTable.cpp */; };
                BCFD8C930EEB2EE700283848 /* JumpTable.h in Headers */ = {isa = PBXBuildFile; fileRef = BCFD8C910EEB2EE700283848 /* JumpTable.h */; };
                C0A272630E50A06300E96E15 /* NotFound.h in Headers */ = {isa = PBXBuildFile; fileRef = C0A2723F0E509F1E00E96E15 /* NotFound.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               DD2724681208D1FF00F9ABE7 /* AlignedMemoryAllocator.h in Headers */ = {isa = PBXBuildFile; fileRef = DD2724671208D1FF00F9ABE7 /* AlignedMemoryAllocator.h */; };
-               DD2724691208D1FF00F9ABE7 /* AlignedMemoryAllocator.h in Headers */ = {isa = PBXBuildFile; fileRef = DD2724671208D1FF00F9ABE7 /* AlignedMemoryAllocator.h */; settings = {ATTRIBUTES = (Private, ); }; };
                DD377CBC12072C18006A2517 /* Bitmap.h in Headers */ = {isa = PBXBuildFile; fileRef = DD377CBB12072C18006A2517 /* Bitmap.h */; settings = {ATTRIBUTES = (Private, ); }; };
                DDE82AD31209D955005C1756 /* GCHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDE82AD11209D955005C1756 /* GCHandle.cpp */; };
                DDE82AD41209D955005C1756 /* GCHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DDE82AD11209D955005C1756 /* GCHandle.cpp */; };
                14DE0D680D02431400AACCA2 /* JSGlobalObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSGlobalObject.cpp; sourceTree = "<group>"; };
                14F252560D08DD8D004ECFFF /* JSVariableObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSVariableObject.h; sourceTree = "<group>"; };
                14F3488E0E95EF8A003648BC /* CollectorHeapIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CollectorHeapIterator.h; sourceTree = "<group>"; };
+               14FFF98A12BFFF7500795BB8 /* PageAllocationAligned.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PageAllocationAligned.cpp; sourceTree = "<group>"; };
+               14FFF98B12BFFF7500795BB8 /* PageAllocationAligned.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PageAllocationAligned.h; sourceTree = "<group>"; };
                180B9AEF0F16C569009BDBC5 /* CurrentTime.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CurrentTime.cpp; sourceTree = "<group>"; };
                180B9AF00F16C569009BDBC5 /* CurrentTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CurrentTime.h; sourceTree = "<group>"; };
                18BAB52710DADFCD000D945B /* ThreadIdentifierDataPthreads.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ThreadIdentifierDataPthreads.cpp; sourceTree = "<group>"; };
                C0A2723F0E509F1E00E96E15 /* NotFound.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NotFound.h; sourceTree = "<group>"; };
                D21202280AD4310C00ED79B6 /* DateConversion.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = DateConversion.cpp; sourceTree = "<group>"; };
                D21202290AD4310C00ED79B6 /* DateConversion.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DateConversion.h; sourceTree = "<group>"; };
-               DD2724671208D1FF00F9ABE7 /* AlignedMemoryAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AlignedMemoryAllocator.h; sourceTree = "<group>"; };
                DD377CBB12072C18006A2517 /* Bitmap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Bitmap.h; sourceTree = "<group>"; };
                DDE82AD11209D955005C1756 /* GCHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GCHandle.cpp; sourceTree = "<group>"; };
                DDE82AD21209D955005C1756 /* GCHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCHandle.h; sourceTree = "<group>"; };
                                9303F567099118FA00AD71B8 /* OwnPtr.h */,
                                440B7AED0FAF7FCB0073323E /* OwnPtrCommon.h */,
                                8627E5EA11F1281900A313B5 /* PageAllocation.h */,
+                               14FFF98A12BFFF7500795BB8 /* PageAllocationAligned.cpp */,
+                               14FFF98B12BFFF7500795BB8 /* PageAllocationAligned.h */,
                                14B3EF0412BC24DD00D29EFF /* PageBlock.cpp */,
                                14B3EF0312BC24DD00D29EFF /* PageBlock.h */,
                                8690231412092D5C00630AF9 /* PageReservation.h */,
                7EF6E0BB0EB7A1EC0079AFAF /* runtime */ = {
                        isa = PBXGroup;
                        children = (
-                               DD2724671208D1FF00F9ABE7 /* AlignedMemoryAllocator.h */,
                                DDF7ABD211F60ED200108E36 /* GCActivityCallback.h */,
                                DDF7ABD311F60ED200108E36 /* GCActivityCallbackCF.cpp */,
                                BCF605110E203EF800B9A64D /* ArgList.cpp */,
                                144007570A5370D20005F061 /* JSNodeList.h in Headers */,
                                144005CC0A5338F80005F061 /* Node.h in Headers */,
                                1440074A0A536CC20005F061 /* NodeList.h in Headers */,
-                               DD2724681208D1FF00F9ABE7 /* AlignedMemoryAllocator.h in Headers */,
                                DDE82AD61209D955005C1756 /* GCHandle.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                                86D08D5411793613006E5ED0 /* WTFThreadData.h in Headers */,
                                9688CB160ED12B4E001D649F /* X86Assembler.h in Headers */,
                                DDF7ABD411F60ED200108E36 /* GCActivityCallback.h in Headers */,
-                               DD2724691208D1FF00F9ABE7 /* AlignedMemoryAllocator.h in Headers */,
                                DDE82AD81209D955005C1756 /* GCHandle.h in Headers */,
                                86F38859121130CA007A7CE3 /* AtomicStringHash.h in Headers */,
                                862AF4B612239C7B0024E5B8 /* DecimalNumber.h in Headers */,
                                F3BD31ED126735770065467F /* TextPosition.h in Headers */,
                                1400067712A6F7830064D123 /* OSAllocator.h in Headers */,
                                14B3EF0512BC24DD00D29EFF /* PageBlock.h in Headers */,
+                               14FFF98D12BFFF7500795BB8 /* PageAllocationAligned.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                147F39BD107EC37600427A48 /* ArgList.cpp in Sources */,
                                147F39BE107EC37600427A48 /* Arguments.cpp in Sources */,
                                86D3B2C310156BDE002865E7 /* ARMAssembler.cpp in Sources */,
+                               A74DE1D0120B875600D40D5B /* ARMv7Assembler.cpp in Sources */,
                                147F39BF107EC37600427A48 /* ArrayConstructor.cpp in Sources */,
                                147F39C0107EC37600427A48 /* ArrayPrototype.cpp in Sources */,
                                65FDE49C0BDD1D4A00E80111 /* Assertions.cpp in Sources */,
                                14280823107EC02C0013E7B2 /* Debugger.cpp in Sources */,
                                BC3135650F302FA3003DFD3A /* DebuggerActivation.cpp in Sources */,
                                149559EE0DDCDDF700648087 /* DebuggerCallFrame.cpp in Sources */,
+                               0F29479C126E698C00B3ABF5 /* DecimalNumber.cpp in Sources */,
                                14469DD7107EC79E00650446 /* dtoa.cpp in Sources */,
                                147F39C7107EC37600427A48 /* Error.cpp in Sources */,
                                147F39C8107EC37600427A48 /* ErrorConstructor.cpp in Sources */,
                                14F8BA3E107EC886009892DC /* FastMalloc.cpp in Sources */,
                                147F39CB107EC37600427A48 /* FunctionConstructor.cpp in Sources */,
                                147F39CC107EC37600427A48 /* FunctionPrototype.cpp in Sources */,
+                               DDF7ABD511F60ED200108E36 /* GCActivityCallbackCF.cpp in Sources */,
+                               DDE82AD71209D955005C1756 /* GCHandle.cpp in Sources */,
                                14280855107EC0E70013E7B2 /* GetterSetter.cpp in Sources */,
                                147F39CD107EC37600427A48 /* GlobalEvalFunction.cpp in Sources */,
                                65DFC93308EA173A00F7300B /* HashTable.cpp in Sources */,
                                A7C530E4102A3813005BC741 /* MarkStackPosix.cpp in Sources */,
                                14469DDF107EC7E700650446 /* MathObject.cpp in Sources */,
                                511FC4C9117EE28700425272 /* MD5.cpp in Sources */,
+                               90213E3D123A40C200D422F3 /* MemoryStatistics.cpp in Sources */,
                                14469DE0107EC7E700650446 /* NativeErrorConstructor.cpp in Sources */,
                                14469DE1107EC7E700650446 /* NativeErrorPrototype.cpp in Sources */,
                                148F21B7107EC5470042EC2C /* Nodes.cpp in Sources */,
                                E124A8F80E555775003091F1 /* OpaqueJSString.cpp in Sources */,
                                969A079A0ED1D3AE00F1F681 /* Opcode.cpp in Sources */,
                                14280850107EC0D70013E7B2 /* Operations.cpp in Sources */,
+                               1400069312A6F9E10064D123 /* OSAllocatorPosix.cpp in Sources */,
+                               14FFF98C12BFFF7500795BB8 /* PageAllocationAligned.cpp in Sources */,
+                               14B3EF0612BC24DD00D29EFF /* PageBlock.cpp in Sources */,
+                               9714AF5E122F32070092D9F5 /* ParsedURL.cpp in Sources */,
                                148F21BC107EC54D0042EC2C /* Parser.cpp in Sources */,
                                93052C340FB792190048FDC3 /* ParserArena.cpp in Sources */,
                                930754C108B0F68000AB3056 /* pcre_compile.cpp in Sources */,
                                14469DEA107EC7E700650446 /* ScopeChain.cpp in Sources */,
                                0BF28A2911A33DC300638F84 /* SizeLimits.cpp in Sources */,
                                9330402C0E6A764000786E6A /* SmallStrings.cpp in Sources */,
+                               A730B6131250068F009D25B1 /* StrictEvalActivation.cpp in Sources */,
+                               86438FC41265503E00E0DFCA /* StringBuilder.cpp in Sources */,
                                86D87DAE12BCA7D1008E73A1 /* StackBounds.cpp in Sources */,
                                14469DEB107EC7E700650446 /* StringConstructor.cpp in Sources */,
                                868BFA0E117CEFD100B908B1 /* StringImpl.cpp in Sources */,
                                A7386555118697B400540279 /* ThunkGenerators.cpp in Sources */,
                                14A42E3F0F4F60EE00599099 /* TimeoutChecker.cpp in Sources */,
                                0B330C270F38C62300692DE3 /* TypeTraits.cpp in Sources */,
+                               9714AF46122F28850092D9F5 /* URLSegments.cpp in Sources */,
                                14469DEE107EC7E700650446 /* UString.cpp in Sources */,
                                E1EF79AA0CE97BA60088D500 /* UTF8.cpp in Sources */,
                                868BFA17117CF19900B908B1 /* WTFString.cpp in Sources */,
                                86D08D5311793613006E5ED0 /* WTFThreadData.cpp in Sources */,
-                               DDF7ABD511F60ED200108E36 /* GCActivityCallbackCF.cpp in Sources */,
-                               DDE82AD71209D955005C1756 /* GCHandle.cpp in Sources */,
-                               A74DE1D0120B875600D40D5B /* ARMv7Assembler.cpp in Sources */,
-                               9714AF46122F28850092D9F5 /* URLSegments.cpp in Sources */,
-                               9714AF5E122F32070092D9F5 /* ParsedURL.cpp in Sources */,
-                               90213E3D123A40C200D422F3 /* MemoryStatistics.cpp in Sources */,
-                               A730B6131250068F009D25B1 /* StrictEvalActivation.cpp in Sources */,
-                               86438FC41265503E00E0DFCA /* StringBuilder.cpp in Sources */,
-                               0F29479C126E698C00B3ABF5 /* DecimalNumber.cpp in Sources */,
-                               1400069312A6F9E10064D123 /* OSAllocatorPosix.cpp in Sources */,
-                               14B3EF0612BC24DD00D29EFF /* PageBlock.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
diff --git a/JavaScriptCore/runtime/AlignedMemoryAllocator.h b/JavaScriptCore/runtime/AlignedMemoryAllocator.h
deleted file mode 100644 (file)
index 8c54103..0000000
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- *  Copyright (C) 2010 Apple Inc. All rights reserved.
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- *
- */
-
-#ifndef AlignedMemoryAllocator_h
-#define AlignedMemoryAllocator_h
-
-#include <wtf/Bitmap.h>
-#include <wtf/PageReservation.h>
-
-namespace JSC {
-
-struct AlignedMemoryAllocatorConstants {
-// Set sane defaults if -D<flagname=value> wasn't provided via compiler args
-#if defined(JSCCOLLECTOR_VIRTUALMEM_RESERVATION)
-    // Keep backwards compatibility with symbian build system
-    static const size_t virtualMemoryReservation = JSCCOLLECTOR_VIRTUALMEM_RESERVATION;
-#elif defined(__WINS__)
-    // Emulator has limited virtual address space
-    static const size_t virtualMemoryReservation = 0x400000;
-#else
-    // HW has plenty of virtual addresses
-    static const size_t virtualMemoryReservation = 0x8000000;
-#endif
-};
-
-template<size_t blockSize> class AlignedMemory;
-template<size_t blockSize> class AlignedMemoryAllocator;
-
-#if HAVE(PAGE_ALLOCATE_ALIGNED)
-
-template<size_t blockSize>
-class AlignedMemoryAllocator;
-
-template<size_t blockSize>
-class AlignedMemory {
-public:
-    void deallocate();
-    void* base();
-
-private:
-    friend class AlignedMemoryAllocator<blockSize>;
-
-    AlignedMemory(PageAllocation);
-
-    PageAllocation m_allocation;
-};
-
-template<size_t blockSize>
-class AlignedMemoryAllocator {
-public:
-    void destroy();
-    AlignedMemory<blockSize> allocate();
-};
-
-template<size_t blockSize>
-inline void AlignedMemoryAllocator<blockSize>::destroy()
-{
-}
-
-template<size_t blockSize>
-inline AlignedMemory<blockSize> AlignedMemoryAllocator<blockSize>::allocate()
-{
-    return AlignedMemory<blockSize>(PageAllocation::allocateAligned(blockSize, OSAllocator::JSGCHeapPages));
-}
-
-template<size_t blockSize>
-inline void AlignedMemory<blockSize>::deallocate()
-{
-    m_allocation.deallocate();
-}
-
-template<size_t blockSize>
-inline void* AlignedMemory<blockSize>::base()
-{
-    return m_allocation.base();
-}
-
-template<size_t blockSize>
-inline AlignedMemory<blockSize>::AlignedMemory(PageAllocation allocation)
-    : m_allocation(allocation)
-{
-}
-
-#else
-
-template<size_t blockSize>
-class AlignedMemory {
-public:
-    void deallocate();
-    void* base();
-
-private:
-    friend class AlignedMemoryAllocator<blockSize>;
-
-    AlignedMemory(void* base, AlignedMemoryAllocator<blockSize>* allocator);
-
-    void* m_base;
-    AlignedMemoryAllocator<blockSize>* m_allocator;
-};
-
-template<size_t blockSize>
-class AlignedMemoryAllocator {
-public:
-    AlignedMemoryAllocator();
-    ~AlignedMemoryAllocator();
-
-    void destroy();
-    AlignedMemory<blockSize> allocate();
-    void free(AlignedMemory<blockSize>);
-
-private:
-    static const size_t reservationSize = AlignedMemoryAllocatorConstants::virtualMemoryReservation;
-    static const size_t bitmapSize = reservationSize / blockSize;
-
-    PageReservation m_reservation;
-    size_t m_nextFree;
-    uintptr_t m_reservationBase;
-    WTF::Bitmap<bitmapSize> m_bitmap;
-};
-
-template<size_t blockSize>
-AlignedMemoryAllocator<blockSize>::AlignedMemoryAllocator()
-    : m_reservation(PageReservation::reserve(reservationSize + blockSize, OSAllocator::JSGCHeapPages))
-    , m_nextFree(0)
-{
-    // check that blockSize and reservationSize are powers of two
-    ASSERT(!(blockSize & (blockSize - 1)));
-    ASSERT(!(reservationSize & (reservationSize - 1)));
-
-    // check that blockSize is a multiple of pageSize and that
-    // reservationSize is a multiple of blockSize
-    ASSERT(!(blockSize & (PageAllocation::pageSize() - 1)));
-    ASSERT(!(reservationSize & (blockSize - 1)));
-
-    ASSERT(m_reservation);
-
-    m_reservationBase = reinterpret_cast<uintptr_t>(m_reservation.base());
-    m_reservationBase = (m_reservationBase + blockSize) & ~(blockSize - 1);
-}
-
-template<size_t blockSize>
-AlignedMemoryAllocator<blockSize>::~AlignedMemoryAllocator()
-{
-    destroy();
-    m_reservation.deallocate();
-}
-
-template<size_t blockSize>
-inline void AlignedMemoryAllocator<blockSize>::destroy()
-{
-    for (unsigned i = 0; i < bitmapSize; ++i) {
-        if (m_bitmap.get(i)) {
-            void* blockAddress = reinterpret_cast<void*>(m_reservationBase + m_nextFree * blockSize);
-            m_reservation.decommit(blockAddress, blockSize);
-
-            m_bitmap.clear(i);
-        }
-    }
-}
-
-template<size_t blockSize>
-AlignedMemory<blockSize> AlignedMemoryAllocator<blockSize>::allocate()
-{
-    while (m_nextFree < bitmapSize) {
-        if (!m_bitmap.get(m_nextFree)) {
-            void* blockAddress = reinterpret_cast<void*>(m_reservationBase + m_nextFree * blockSize);
-            m_reservation.commit(blockAddress, blockSize);
-
-            m_bitmap.set(m_nextFree);
-            ++m_nextFree;
-
-            return AlignedMemory<blockSize>(blockAddress, this);
-        }
-        m_bitmap.advanceToNextFreeBit(m_nextFree);
-    }
-
-    if (m_bitmap.isFull())
-        return AlignedMemory<blockSize>(0, this);
-
-    m_nextFree = 0;
-
-    return allocate();
-}
-
-template<size_t blockSize>
-void AlignedMemoryAllocator<blockSize>::free(AlignedMemory<blockSize> allocation)
-{
-    ASSERT(allocation.base());
-    m_reservation.decommit(allocation.base(), blockSize);
-
-    size_t diff = (reinterpret_cast<uintptr_t>(allocation.base()) - m_reservationBase);
-    ASSERT(!(diff & (blockSize - 1)));
-
-    size_t i = diff / blockSize;
-    ASSERT(m_bitmap.get(i));
-
-    m_bitmap.clear(i);
-}
-
-template<size_t blockSize>
-inline void AlignedMemory<blockSize>::deallocate()
-{
-    m_allocator->free(*this);
-}
-
-template<size_t blockSize>
-inline void* AlignedMemory<blockSize>::base()
-{
-    return m_base;
-}
-
-template<size_t blockSize>
-AlignedMemory<blockSize>::AlignedMemory(void* base, AlignedMemoryAllocator<blockSize>* allocator)
-    : m_base(base)
-    , m_allocator(allocator)
-{
-}
-
-#endif
-
-}
-
-#endif
index c53cae5..38845ce 100644 (file)
@@ -171,9 +171,6 @@ void Heap::destroy()
 
     freeBlocks();
 
-    for (unsigned i = 0; i < m_weakGCHandlePools.size(); ++i)
-        m_weakGCHandlePools[i].deallocate();
-
 #if ENABLE(JSC_MULTIPLE_THREADS)
     if (m_currentThreadRegistrar) {
         int error = pthread_key_delete(m_currentThreadRegistrar);
@@ -187,13 +184,12 @@ void Heap::destroy()
         t = next;
     }
 #endif
-    m_blockallocator.destroy();
     m_globalData = 0;
 }
 
 NEVER_INLINE CollectorBlock* Heap::allocateBlock()
 {
-    AlignedCollectorBlock allocation = m_blockallocator.allocate();
+    PageAllocationAligned allocation = PageAllocationAligned::allocate(BLOCK_SIZE, BLOCK_SIZE, OSAllocator::JSGCHeapPages);
     CollectorBlock* block = static_cast<CollectorBlock*>(allocation.base());
     if (!block)
         CRASH();
@@ -211,12 +207,12 @@ NEVER_INLINE CollectorBlock* Heap::allocateBlock()
 
     size_t numBlocks = m_heap.numBlocks;
     if (m_heap.usedBlocks == numBlocks) {
-        static const size_t maxNumBlocks = ULONG_MAX / sizeof(AlignedCollectorBlock) / GROWTH_FACTOR;
+        static const size_t maxNumBlocks = ULONG_MAX / sizeof(PageAllocationAligned) / GROWTH_FACTOR;
         if (numBlocks > maxNumBlocks)
             CRASH();
         numBlocks = max(MIN_ARRAY_SIZE, numBlocks * GROWTH_FACTOR);
         m_heap.numBlocks = numBlocks;
-        m_heap.blocks = static_cast<AlignedCollectorBlock*>(fastRealloc(m_heap.blocks, numBlocks * sizeof(AlignedCollectorBlock)));
+        m_heap.blocks = static_cast<PageAllocationAligned*>(fastRealloc(m_heap.blocks, numBlocks * sizeof(PageAllocationAligned)));
     }
     m_heap.blocks[m_heap.usedBlocks++] = allocation;
 
@@ -239,7 +235,7 @@ NEVER_INLINE void Heap::freeBlock(size_t block)
 
     if (m_heap.numBlocks > MIN_ARRAY_SIZE && m_heap.usedBlocks < m_heap.numBlocks / LOW_WATER_FACTOR) {
         m_heap.numBlocks = m_heap.numBlocks / GROWTH_FACTOR; 
-        m_heap.blocks = static_cast<AlignedCollectorBlock*>(fastRealloc(m_heap.blocks, m_heap.numBlocks * sizeof(AlignedCollectorBlock)));
+        m_heap.blocks = static_cast<PageAllocationAligned*>(fastRealloc(m_heap.blocks, m_heap.numBlocks * sizeof(PageAllocationAligned)));
     }
 }
 
@@ -754,10 +750,10 @@ WeakGCHandle* Heap::addWeakGCHandle(JSCell* ptr)
         if (!weakGCHandlePool(i)->isFull())
             return weakGCHandlePool(i)->allocate(ptr);
 
-    AlignedMemory<WeakGCHandlePool::poolSize> allocation = m_weakGCHandlePoolAllocator.allocate();
+    PageAllocationAligned allocation = PageAllocationAligned::allocate(WeakGCHandlePool::poolSize, WeakGCHandlePool::poolSize, OSAllocator::JSGCHeapPages);
     m_weakGCHandlePools.append(allocation);
 
-    WeakGCHandlePool* pool = new (allocation) WeakGCHandlePool();
+    WeakGCHandlePool* pool = new (allocation.base()) WeakGCHandlePool();
     return pool->allocate(ptr);
 }
 
index 62f620e..a4e2fe1 100644 (file)
@@ -22,7 +22,6 @@
 #ifndef Collector_h
 #define Collector_h
 
-#include "AlignedMemoryAllocator.h"
 #include "GCHandle.h"
 #include "JSValue.h"
 #include <stddef.h>
@@ -34,6 +33,7 @@
 #include <wtf/Noncopyable.h>
 #include <wtf/OwnPtr.h>
 #include <wtf/PageAllocation.h>
+#include <wtf/PageAllocationAligned.h>
 #include <wtf/PassOwnPtr.h>
 #include <wtf/StdLibExtras.h>
 #include <wtf/Threading.h>
@@ -64,13 +64,10 @@ namespace JSC {
     const size_t BLOCK_SIZE = 256 * 1024; // 256k
 #endif
 
-    typedef AlignedMemoryAllocator<BLOCK_SIZE> CollectorBlockAllocator;
-    typedef AlignedMemory<BLOCK_SIZE> AlignedCollectorBlock;
-
     struct CollectorHeap {
         size_t nextBlock;
         size_t nextCell;
-        AlignedCollectorBlock* blocks;
+        PageAllocationAligned* blocks;
         
         void* nextNumber;
 
@@ -191,7 +188,7 @@ namespace JSC {
         CollectorHeap m_heap;
 
         ProtectCountSet m_protectedValues;
-        WTF::Vector<AlignedMemory<WeakGCHandlePool::poolSize> > m_weakGCHandlePools;
+        WTF::Vector<PageAllocationAligned> m_weakGCHandlePools;
         WTF::Vector<WTF::Vector<ValueStringPair>* > m_tempSortingVectors;
 
         HashSet<MarkedArgumentBuffer*>* m_markListSet;
@@ -209,10 +206,6 @@ namespace JSC {
         pthread_key_t m_currentThreadRegistrar;
 #endif
 
-        // Allocates collector blocks with correct alignment
-        CollectorBlockAllocator m_blockallocator; 
-        WeakGCHandlePool::Allocator m_weakGCHandlePoolAllocator; 
-        
         JSGlobalData* m_globalData;
     };
 
index 3331517..297de38 100644 (file)
@@ -83,9 +83,4 @@ void WeakGCHandlePool::free(WeakGCHandle* handle)
     --m_entriesSize;
 }
 
-void* WeakGCHandlePool::operator new(size_t, AlignedMemory<WeakGCHandlePool::poolSize>& allocation)
-{
-    return allocation.base();
-}
-
 }
index 38a7be9..8818f79 100644 (file)
@@ -26,7 +26,7 @@
 #ifndef GCHandle_h
 #define GCHandle_h
 
-#include "AlignedMemoryAllocator.h"
+#include <wtf/Assertions.h>
 
 namespace JSC {
 
@@ -91,8 +91,6 @@ public:
     static const size_t poolMask = ~(poolSize - 1);
     static const size_t numPoolEntries = (poolSize - sizeof(Heap*) - 3 * sizeof(unsigned)) / sizeof(WeakGCHandle);
 
-    typedef AlignedMemoryAllocator<WeakGCHandlePool::poolSize> Allocator;
-
     WeakGCHandlePool();
 
     WeakGCHandle* allocate(JSCell* cell);
@@ -106,8 +104,6 @@ public:
 
     void update();
 
-    void* operator new(size_t, AlignedMemory<WeakGCHandlePool::poolSize>&);
-
 private:
     Heap* m_heap;
     unsigned m_entriesSize;
index be47fad..7bccadf 100644 (file)
@@ -88,7 +88,7 @@ namespace JSC {
         };
 
         static void* allocateStack(size_t size) { return OSAllocator::reserveAndCommit(size); }
-        static void releaseStack(void* addr, size_t size) { OSAllocator::release(addr, size); }
+        static void releaseStack(void* addr, size_t size) { OSAllocator::decommitAndRelease(addr, size); }
 
         static void initializePagesize();
         static size_t pageSize()
index 3c8173b..49216f0 100644 (file)
@@ -40,15 +40,54 @@ public:
         JSJITCodePages = VM_TAG_FOR_EXECUTABLEALLOCATOR_MEMORY,
     };
 
-    static void* reserve(size_t, Usage = UnknownUsage, bool writable = true, bool executable = false);
-    static void* reserveAndCommit(size_t, Usage = UnknownUsage, bool writable = true, bool executable = false);
+    // These methods are symmetric; reserveUncommitted allocates VM in an uncommitted state,
+    // releaseDecommitted should be called on a region of VM allocated by a single reservation,
+    // the memory must all currently be in a decommitted state.
+    static void* reserveUncommitted(size_t, Usage = UnknownUsage, bool writable = true, bool executable = false);
+    static void releaseDecommitted(void*, size_t);
 
+    // These methods are symmetric; tehy commit or decommit a region of VM (uncommitted VM should
+    // never be accessed, since the OS may not have attached physical memory for these regions).
+    // Clients should only call commit on uncommitted regions and decommit on committed regions.
     static void commit(void*, size_t, bool writable, bool executable);
     static void decommit(void*, size_t);
 
-    static void release(void*, size_t);
+    // These methods are symmetric; reserveAndCommit allocates VM in an committed state,
+    // decommitAndRelease should be called on a region of VM allocated by a single reservation,
+    // the memory must all currently be in a committed state.
+    static void* reserveAndCommit(size_t, Usage = UnknownUsage, bool writable = true, bool executable = false);
+    static void decommitAndRelease(void* base, size_t size);
+
+    // These methods are akin to reserveAndCommit/decommitAndRelease, above - however rather than
+    // committing/decommitting the entire region additional parameters allow a subregion to be
+    // specified.
+    static void* reserveAndCommit(size_t reserveSize, size_t commitSize, Usage = UnknownUsage, bool writable = true, bool executable = false);
+    static void decommitAndRelease(void* releaseBase, size_t releaseSize, void* decommitBase, size_t decommitSize);
 };
 
+inline void* OSAllocator::reserveAndCommit(size_t reserveSize, size_t commitSize, Usage usage, bool writable, bool executable)
+{
+    void* base = reserveUncommitted(reserveSize, usage, writable, executable);
+    commit(base, commitSize, writable, executable);
+    return base;
+}
+
+inline void OSAllocator::decommitAndRelease(void* releaseBase, size_t releaseSize, void* decommitBase, size_t decommitSize)
+{
+    ASSERT(decommitBase >= releaseBase && (static_cast<char*>(decommitBase) + decommitSize) <= (static_cast<char*>(releaseBase) + releaseSize));
+#if OS(WINCE)
+    // On most platforms we can actually skip this final decommit; releasing the VM will
+    // implicitly decommit any physical memory in the region. This is not true on WINCE.
+    decommit(decommitBase, decommitSize);
+#endif
+    releaseDecommitted(releaseBase, releaseSize);
+}
+
+inline void OSAllocator::decommitAndRelease(void* base, size_t size)
+{
+    decommitAndRelease(base, size, base, size);
+}
+
 } // namespace WTF
 
 using WTF::OSAllocator;
index 28ca291..5546cef 100644 (file)
@@ -33,7 +33,7 @@
 
 namespace WTF {
 
-void* OSAllocator::reserve(size_t bytes, Usage usage, bool writable, bool executable)
+void* OSAllocator::reserveUncommitted(size_t bytes, Usage usage, bool writable, bool executable)
 {
     void* result = reserveAndCommit(bytes, usage, writable, executable);
 #if HAVE(MADV_FREE_REUSE)
@@ -111,7 +111,7 @@ void OSAllocator::decommit(void* address, size_t bytes)
 #endif
 }
 
-void OSAllocator::release(void* address, size_t bytes)
+void OSAllocator::releaseDecommitted(void* address, size_t bytes)
 {
     int result = munmap(address, bytes);
     if (result == -1)
index 6329850..d9cbcf5 100644 (file)
@@ -30,7 +30,7 @@
 
 namespace WTF {
 
-void* OSAllocator::reserve(size_t, Usage, bool, bool)
+void* OSAllocator::reserveUncommitted(size_t, Usage, bool, bool)
 {
     return fastMalloc(bytes);
 }
@@ -48,7 +48,7 @@ void OSAllocator::decommit(void*, size_t)
 {
 }
 
-void OSAllocator::release(void* address, size_t)
+void OSAllocator::releaseDecommitted(void* address, size_t)
 {
     fastFree(address);
 }
index c0ea037..e7beb8a 100644 (file)
@@ -38,7 +38,7 @@ static inline DWORD protection(bool writable, bool executable)
         (writable ? PAGE_READWRITE : PAGE_READONLY);
 }
 
-void* OSAllocator::reserve(size_t bytes, Usage, bool writable, bool executable)
+void* OSAllocator::reserveUncommitted(size_t bytes, Usage, bool writable, bool executable)
 {
     void* result = VirtualAlloc(0, bytes, MEM_RESERVE, protection(writable, executable));
     if (!result)
@@ -68,18 +68,12 @@ void OSAllocator::decommit(void* address, size_t bytes)
         CRASH();
 }
 
-void OSAllocator::release(void* address, size_t bytes)
+void OSAllocator::releaseDecommitted(void* address, size_t bytes)
 {
-#if OS(WINCE)
-    decommit(address, bytes);
-#endif
     // According to http://msdn.microsoft.com/en-us/library/aa366892(VS.85).aspx,
     // dwSize must be 0 if dwFreeType is MEM_RELEASE.
     bool result = VirtualFree(address, 0, MEM_RELEASE);
-
-    // FIXME: Restore this error checking once aligned allocation is fixed not
-    // to pair malloc with VirtualFree.
-    if (!result && 0)
+    if (!result)
         CRASH();
 }
 
index c83ccad..232cd20 100644 (file)
@@ -77,47 +77,35 @@ namespace WTF {
     Callers may also optinally provide a flag indicating the usage (for use by
     system memory usage tracking tools, where implemented), and boolean values
     specifying the required protection (defaulting to writable, non-executable).
-
-    Where HAVE(PAGE_ALLOCATE_ALIGNED) is available memory may also be allocated
-    with a specified alignment.  PageAllocation::allocateAligned requires that the
-    size is a power of two that is >= system page size.
 */
 
 class PageAllocation : private PageBlock {
 public:
-    static PageAllocation allocate(size_t size, OSAllocator::Usage usage = OSAllocator::UnknownUsage, bool writable = true, bool executable = false)
+    PageAllocation()
     {
-        ASSERT(isPageAligned(size));
-        return PageAllocation(OSAllocator::reserveAndCommit(size, usage, writable, executable), size);
     }
 
-#if HAVE(PAGE_ALLOCATE_ALIGNED)
-    static PageAllocation allocateAligned(size_t size, OSAllocator::Usage usage = OSAllocator::UnknownUsage)
+    using PageBlock::operator bool;
+    using PageBlock::size;
+    using PageBlock::base;
+
+    static PageAllocation allocate(size_t size, OSAllocator::Usage usage = OSAllocator::UnknownUsage, bool writable = true, bool executable = false)
     {
         ASSERT(isPageAligned(size));
-        ASSERT(isPowerOfTwo(size));
-        return systemAllocateAligned(size, usage);
+        return PageAllocation(OSAllocator::reserveAndCommit(size, usage, writable, executable), size);
     }
-#endif
-
-    PageAllocation();
-
-    using PageBlock::operator bool;
-    using PageBlock::base;
-    using PageBlock::size;
 
     void deallocate()
     {
-        ASSERT(*this);
+        // Clear base & size before calling release; if this is *inside* allocation
+        // then we won't be able to clear then after deallocating the memory.
+        PageAllocation tmp;
+        std::swap(tmp, *this);
 
-        // Zero these before calling release; if this is *inside* allocation,
-        // we won't be able to clear then after the call to OSAllocator::release.
-        void* base = m_base;
-        size_t size = m_size;
-        m_base = 0;
-        m_size = 0;
+        ASSERT(tmp);
+        ASSERT(!*this);
 
-        OSAllocator::release(base, size);
+        OSAllocator::decommitAndRelease(tmp.base(), tmp.size());
     }
 
 private:
@@ -125,81 +113,9 @@ private:
         : PageBlock(base, size)
     {
     }
-
-#if HAVE(PAGE_ALLOCATE_ALIGNED)
-    static PageAllocation systemAllocateAligned(size_t, OSAllocator::Usage);
-#endif
 };
 
-inline PageAllocation::PageAllocation()
-    : PageBlock()
-{
-}
-
-
-#if HAVE(MMAP)
-
-inline PageAllocation PageAllocation::systemAllocateAligned(size_t size, OSAllocator::Usage usage)
-{
-#if OS(DARWIN)
-    vm_address_t address = 0;
-    int flags = VM_FLAGS_ANYWHERE;
-    if (usage != -1)
-        flags |= usage;
-    vm_map(current_task(), &address, size, (size - 1), flags, MEMORY_OBJECT_NULL, 0, FALSE, PROT_READ | PROT_WRITE, PROT_READ | PROT_WRITE | PROT_EXEC, VM_INHERIT_DEFAULT);
-    return PageAllocation(reinterpret_cast<void*>(address), size);
-#elif HAVE(POSIX_MEMALIGN)
-    void* address;
-    posix_memalign(&address, size, size);
-    return PageAllocation(address, size);
-#else
-    size_t extra = size - pageSize();
-
-    // Check for overflow.
-    if ((size + extra) < size)
-        return PageAllocation(0, size);
-
-#if OS(DARWIN) && !defined(BUILDING_ON_TIGER)
-    int fd = usage;
-#else
-    int fd = -1;
-#endif
-    void* mmapResult = mmap(0, size + extra, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, fd, 0);
-    if (mmapResult == MAP_FAILED)
-        return PageAllocation(0, size);
-    uintptr_t address = reinterpret_cast<uintptr_t>(mmapResult);
-
-    size_t adjust = 0;
-    if ((address & (size - 1)))
-        adjust = size - (address & (size - 1));
-    if (adjust > 0)
-        munmap(reinterpret_cast<char*>(address), adjust);
-    if (adjust < extra)
-        munmap(reinterpret_cast<char*>(address + adjust + size), extra - adjust);
-    address += adjust;
-
-    return PageAllocation(reinterpret_cast<void*>(address), size);
-#endif
-}
-
-#elif HAVE(VIRTUALALLOC)
-
-#if HAVE(ALIGNED_MALLOC)
-inline PageAllocation PageAllocation::systemAllocateAligned(size_t size, OSAllocator::Usage usage)
-{
-#if COMPILER(MINGW) && !COMPILER(MINGW64)
-    void* address = __mingw_aligned_malloc(size, size);
-#else
-    void* address = _aligned_malloc(size, size);
-#endif
-    memset(address, 0, size);
-    return PageAllocation(address, size);
-}
-#endif
-
-#endif
-
-}
+} // namespace WTF
 
 using WTF::PageAllocation;
 
diff --git a/JavaScriptCore/wtf/PageAllocationAligned.cpp b/JavaScriptCore/wtf/PageAllocationAligned.cpp
new file mode 100644 (file)
index 0000000..6f54710
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2010 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+ */
+
+#include "config.h"
+#include "PageAllocationAligned.h"
+
+namespace WTF {
+
+PageAllocationAligned PageAllocationAligned::allocate(size_t size, size_t alignment, OSAllocator::Usage usage, bool writable, bool executable)
+{
+    ASSERT(isPageAligned(size));
+    ASSERT(isPageAligned(alignment));
+    ASSERT(isPowerOfTwo(alignment));
+    ASSERT(size >= alignment);
+    size_t alignmentMask = alignment - 1;
+
+#if OS(DARWIN)
+    int flags = VM_FLAGS_ANYWHERE;
+    if (usage != OSAllocator::UnknownUsage)
+        flags |= usage;
+    int protection = PROT_READ;
+    if (writable)
+        protection |= PROT_WRITE;
+    if (executable)
+        protection |= PROT_EXEC;
+
+    vm_address_t address = 0;
+    vm_map(current_task(), &address, size, alignmentMask, flags, MEMORY_OBJECT_NULL, 0, FALSE, protection, PROT_READ | PROT_WRITE | PROT_EXEC, VM_INHERIT_DEFAULT);
+    return PageAllocationAligned(reinterpret_cast<void*>(address), size);
+#else
+    size_t alignmentDelta = alignment - pageSize();
+
+    // Resererve with suffcient additional VM to correctly align.
+    size_t reservationSize = size + alignmentDelta;
+    void* reservationBase = OSAllocator::reserveUncommitted(reservationSize, usage, writable, executable);
+
+    // Select an aligned region within the reservation and commit.
+    void* alignedBase = reinterpret_cast<uintptr_t>(reservationBase) & alignmentMask
+        ? reinterpret_cast<void*>((reinterpret_cast<uintptr_t>(reservationBase) & ~alignmentMask) + alignment)
+        : reservationBase;
+    OSAllocator::commit(alignedBase, size, writable, executable);
+
+    return PageAllocationAligned(alignedBase, size, reservationBase, reservationSize);
+#endif
+}
+
+void PageAllocationAligned::deallocate()
+{
+    // Clear base & size before calling release; if this is *inside* allocation
+    // then we won't be able to clear then after deallocating the memory.
+    PageAllocationAligned tmp;
+    std::swap(tmp, *this);
+
+    ASSERT(tmp);
+    ASSERT(!*this);
+
+#if OS(DARWIN)
+    vm_deallocate(current_task(), reinterpret_cast<vm_address_t>(tmp.base()), tmp.size());
+#else
+    ASSERT(tmp.m_reservation.contains(tmp.base(), tmp.size()));
+    OSAllocator::decommitAndRelease(tmp.m_reservation.base(), tmp.m_reservation.size(), tmp.base(), tmp.size());
+#endif
+}
+
+} // namespace WTF
diff --git a/JavaScriptCore/wtf/PageAllocationAligned.h b/JavaScriptCore/wtf/PageAllocationAligned.h
new file mode 100644 (file)
index 0000000..282c9e3
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2010 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. AND ITS CONTRIBUTORS ``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 ITS 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 PageAllocationAligned_h
+#define PageAllocationAligned_h
+
+#include <wtf/OSAllocator.h>
+#include <wtf/PageReservation.h>
+
+namespace WTF {
+
+class PageAllocationAligned : private PageBlock {
+public:
+    PageAllocationAligned()
+    {
+    }
+
+    using PageBlock::operator bool;
+    using PageBlock::size;
+    using PageBlock::base;
+
+    static PageAllocationAligned allocate(size_t size, size_t alignment, OSAllocator::Usage usage = OSAllocator::UnknownUsage, bool writable = true, bool executable = false);
+
+    void deallocate();
+
+private:
+#if OS(DARWIN)
+    PageAllocationAligned(void* base, size_t size)
+        : PageBlock(base, size)
+    {
+    }
+#else
+    PageAllocationAligned(void* base, size_t size, void* reservationBase, size_t reservationSize)
+        : PageBlock(base, size)
+        , m_reservation(reservationBase, reservationSize)
+    {
+    }
+
+    PageBlock m_reservation;
+#endif
+};
+
+
+} // namespace WTF
+
+using WTF::PageAllocationAligned;
+
+#endif // PageAllocationAligned_h
index 500dbbe..07452b3 100644 (file)
@@ -44,7 +44,13 @@ public:
 
     operator bool() const { return !!m_base; }
 
-protected:
+    bool contains(void* containedBase, size_t containedSize)
+    {
+        return containedBase >= m_base
+            && (static_cast<char*>(containedBase) + containedSize) <= (static_cast<char*>(m_base) + m_size);
+    }
+
+private:
     void* m_base;
     size_t m_size;
 };
index 0642350..8c097a4 100644 (file)
@@ -57,6 +57,11 @@ namespace WTF {
 class PageReservation : private PageBlock {
 public:
     PageReservation()
+        : m_writable(false)
+        , m_executable(false)
+#ifndef NDEBUG
+        , m_committed(0)
+#endif
     {
     }
     
@@ -69,6 +74,7 @@ public:
         ASSERT(*this);
         ASSERT(isPageAligned(start));
         ASSERT(isPageAligned(size));
+        ASSERT(contains(start, size));
 
 #ifndef NDEBUG
         m_committed += size;
@@ -81,6 +87,7 @@ public:
         ASSERT(*this);
         ASSERT(isPageAligned(start));
         ASSERT(isPageAligned(size));
+        ASSERT(contains(start, size));
 
 #ifndef NDEBUG
         m_committed -= size;
@@ -91,40 +98,40 @@ public:
     static PageReservation reserve(size_t size, OSAllocator::Usage usage = OSAllocator::UnknownUsage, bool writable = true, bool executable = false)
     {
         ASSERT(isPageAligned(size));
-        return PageReservation(OSAllocator::reserve(size, usage, writable, executable), size, writable, executable);
+        return PageReservation(OSAllocator::reserveUncommitted(size, usage, writable, executable), size, writable, executable);
     }
 
     void deallocate()
     {
         ASSERT(!m_committed);
-        ASSERT(*this);
 
-        // Zero these before calling release; if this is *inside* allocation,
-        // we won't be able to clear then after the call to OSAllocator::release.
-        void* base = m_base;
-        size_t size = m_size;
-        m_base = 0;
-        m_size = 0;
+        // Clear base & size before calling release; if this is *inside* allocation
+        // then we won't be able to clear then after deallocating the memory.
+        PageReservation tmp;
+        std::swap(tmp, *this);
 
-        OSAllocator::release(base, size);
+        ASSERT(tmp);
+        ASSERT(!*this);
+
+        OSAllocator::releaseDecommitted(tmp.base(), tmp.size());
     }
 
 private:
     PageReservation(void* base, size_t size, bool writable, bool executable)
         : PageBlock(base, size)
+        , m_writable(writable)
+        , m_executable(executable)
 #ifndef NDEBUG
         , m_committed(0)
 #endif
-        , m_writable(writable)
-        , m_executable(executable)
     {
     }
 
+    bool m_writable;
+    bool m_executable;
 #ifndef NDEBUG
     size_t m_committed;
 #endif
-    bool m_writable;
-    bool m_executable;
 };
 
 }
index 87a12cc..05e9c14 100644 (file)
 
 #endif
 
-#if HAVE(MMAP) || (HAVE(VIRTUALALLOC) && HAVE(ALIGNED_MALLOC))
-#define HAVE_PAGE_ALLOCATE_ALIGNED 1
-#endif
-#if HAVE(MMAP)
-#define HAVE_PAGE_ALLOCATE_AT 1
-#endif
-
 /* ENABLE macro defaults */
 
 #if PLATFORM(QT)
index a823cbd..c5617ce 100644 (file)
@@ -16,6 +16,7 @@ SOURCES += \
     wtf/qt/MainThreadQt.cpp \
     wtf/qt/StringQt.cpp \
     wtf/qt/ThreadingQt.cpp \
+    wtf/PageAllocationAligned.cpp \
     wtf/PageBlock.cpp \
     wtf/RandomNumber.cpp \
     wtf/RefCountedLeakCounter.cpp \
index e16f588..5ef6c9e 100644 (file)
@@ -1,3 +1,12 @@
+2010-12-21  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Gavin Barraclough & Oliver Hunt.
+
+        Added PageAllocationAligned, a cross-platform abstraction for memory allocations with arbitrary alignment requirements
+        https://bugs.webkit.org/show_bug.cgi?id=51359
+
+        * ForwardingHeaders/wtf/PageAllocationAligned.h: Added.
+
 2010-12-21  Daniel Bates  <dbates@rim.com>
 
         Reviewed by Eric Seidel and Darin Adler.
diff --git a/JavaScriptGlue/ForwardingHeaders/wtf/PageAllocationAligned.h b/JavaScriptGlue/ForwardingHeaders/wtf/PageAllocationAligned.h
new file mode 100644 (file)
index 0000000..caa8e0d
--- /dev/null
@@ -0,0 +1 @@
+#include <JavaScriptCore/PageAllocationAligned.h>
index 6964e9a..9ce2832 100644 (file)
@@ -1,3 +1,12 @@
+2010-12-21  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Gavin Barraclough & Oliver Hunt.
+
+        Added PageAllocationAligned, a cross-platform abstraction for memory allocations with arbitrary alignment requirements
+        https://bugs.webkit.org/show_bug.cgi?id=51359
+
+        * ForwardingHeaders/wtf/PageAllocationAligned.h: Added.
+
 2010-12-21  Ariya Hidayat  <ariya@sencha.com>
 
         Reviewed by Simon Fraser.
diff --git a/WebCore/ForwardingHeaders/wtf/PageAllocationAligned.h b/WebCore/ForwardingHeaders/wtf/PageAllocationAligned.h
new file mode 100644 (file)
index 0000000..26d2216
--- /dev/null
@@ -0,0 +1,4 @@
+#ifndef WebCore_FWD_PageAllocationAligned_h
+#define WebCore_FWD_PageAllocationAligned_h
+#include <JavaScriptCore/PageAllocationAligned.h>
+#endif