1 | /* |
2 | * Copyright (C) 2017-2018 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include "IsoSubspace.h" |
28 | |
29 | #include "AllocatorInlines.h" |
30 | #include "BlockDirectoryInlines.h" |
31 | #include "IsoAlignedMemoryAllocator.h" |
32 | #include "IsoSubspaceInlines.h" |
33 | #include "LocalAllocatorInlines.h" |
34 | |
35 | namespace JSC { |
36 | |
37 | IsoSubspace::IsoSubspace(CString name, Heap& heap, HeapCellType* heapCellType, size_t size) |
38 | : Subspace(name, heap) |
39 | , m_size(size) |
40 | , m_directory(&heap, WTF::roundUpToMultipleOf<MarkedBlock::atomSize>(size)) |
41 | , m_localAllocator(&m_directory) |
42 | , m_isoAlignedMemoryAllocator(std::make_unique<IsoAlignedMemoryAllocator>()) |
43 | { |
44 | initialize(heapCellType, m_isoAlignedMemoryAllocator.get()); |
45 | |
46 | auto locker = holdLock(m_space.directoryLock()); |
47 | m_directory.setSubspace(this); |
48 | m_space.addBlockDirectory(locker, &m_directory); |
49 | m_alignedMemoryAllocator->registerDirectory(&m_directory); |
50 | m_firstDirectory = &m_directory; |
51 | } |
52 | |
53 | IsoSubspace::~IsoSubspace() |
54 | { |
55 | } |
56 | |
57 | Allocator IsoSubspace::allocatorFor(size_t size, AllocatorForMode mode) |
58 | { |
59 | return allocatorForNonVirtual(size, mode); |
60 | } |
61 | |
62 | void* IsoSubspace::allocate(VM& vm, size_t size, GCDeferralContext* deferralContext, AllocationFailureMode failureMode) |
63 | { |
64 | return allocateNonVirtual(vm, size, deferralContext, failureMode); |
65 | } |
66 | |
67 | void IsoSubspace::didResizeBits(size_t blockIndex) |
68 | { |
69 | m_cellSets.forEach( |
70 | [&] (IsoCellSet* set) { |
71 | set->didResizeBits(blockIndex); |
72 | }); |
73 | } |
74 | |
75 | void IsoSubspace::didRemoveBlock(size_t blockIndex) |
76 | { |
77 | m_cellSets.forEach( |
78 | [&] (IsoCellSet* set) { |
79 | set->didRemoveBlock(blockIndex); |
80 | }); |
81 | } |
82 | |
83 | void IsoSubspace::didBeginSweepingToFreeList(MarkedBlock::Handle* block) |
84 | { |
85 | m_cellSets.forEach( |
86 | [&] (IsoCellSet* set) { |
87 | set->sweepToFreeList(block); |
88 | }); |
89 | } |
90 | |
91 | } // namespace JSC |
92 | |
93 | |