fpizlo@apple.com | 195d7b8 | 2013-09-03 16:39:29 +0000 | [diff] [blame] | 1 | /* |
fpizlo@apple.com | ea379af | 2016-10-21 02:17:35 +0000 | [diff] [blame] | 2 | * Copyright (C) 2013-2016 Apple Inc. All rights reserved. |
fpizlo@apple.com | 195d7b8 | 2013-09-03 16:39:29 +0000 | [diff] [blame] | 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 "CodeBlockSet.h" |
| 28 | |
| 29 | #include "CodeBlock.h" |
fpizlo@apple.com | fb7eff2 | 2014-02-11 01:45:50 +0000 | [diff] [blame] | 30 | #include "JSCInlines.h" |
fpizlo@apple.com | 229fa34 | 2014-05-08 02:35:22 +0000 | [diff] [blame] | 31 | #include <wtf/CommaPrinter.h> |
fpizlo@apple.com | 195d7b8 | 2013-09-03 16:39:29 +0000 | [diff] [blame] | 32 | |
| 33 | namespace JSC { |
| 34 | |
| 35 | static const bool verbose = false; |
| 36 | |
ggaren@apple.com | ccb53a7 | 2015-01-29 19:20:06 +0000 | [diff] [blame] | 37 | CodeBlockSet::CodeBlockSet() |
mhahnenberg@apple.com | 87a6cde | 2014-02-05 17:31:47 +0000 | [diff] [blame] | 38 | { |
| 39 | } |
fpizlo@apple.com | 195d7b8 | 2013-09-03 16:39:29 +0000 | [diff] [blame] | 40 | |
| 41 | CodeBlockSet::~CodeBlockSet() |
| 42 | { |
fpizlo@apple.com | 195d7b8 | 2013-09-03 16:39:29 +0000 | [diff] [blame] | 43 | } |
| 44 | |
ggaren@apple.com | 81def5f | 2015-10-09 23:10:16 +0000 | [diff] [blame] | 45 | void CodeBlockSet::add(CodeBlock* codeBlock) |
fpizlo@apple.com | 195d7b8 | 2013-09-03 16:39:29 +0000 | [diff] [blame] | 46 | { |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 47 | LockHolder locker(&m_lock); |
ggaren@apple.com | 81def5f | 2015-10-09 23:10:16 +0000 | [diff] [blame] | 48 | bool isNewEntry = m_newCodeBlocks.add(codeBlock).isNewEntry; |
fpizlo@apple.com | 195d7b8 | 2013-09-03 16:39:29 +0000 | [diff] [blame] | 49 | ASSERT_UNUSED(isNewEntry, isNewEntry); |
| 50 | } |
| 51 | |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 52 | void CodeBlockSet::promoteYoungCodeBlocks(const LockHolder&) |
fpizlo@apple.com | 195d7b8 | 2013-09-03 16:39:29 +0000 | [diff] [blame] | 53 | { |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 54 | ASSERT(m_lock.isLocked()); |
mhahnenberg@apple.com | 7d223bb | 2014-04-02 23:50:25 +0000 | [diff] [blame] | 55 | m_oldCodeBlocks.add(m_newCodeBlocks.begin(), m_newCodeBlocks.end()); |
| 56 | m_newCodeBlocks.clear(); |
| 57 | } |
| 58 | |
| 59 | void CodeBlockSet::clearMarksForFullCollection() |
| 60 | { |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 61 | LockHolder locker(&m_lock); |
ggaren@apple.com | 0eb1644 | 2015-09-02 19:52:04 +0000 | [diff] [blame] | 62 | for (CodeBlock* codeBlock : m_oldCodeBlocks) |
ggaren@apple.com | 81def5f | 2015-10-09 23:10:16 +0000 | [diff] [blame] | 63 | codeBlock->clearVisitWeaklyHasBeenCalled(); |
mhahnenberg@apple.com | 7d223bb | 2014-04-02 23:50:25 +0000 | [diff] [blame] | 64 | |
| 65 | // We promote after we clear marks on the old generation CodeBlocks because |
| 66 | // none of the young generations CodeBlocks need to be cleared. |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 67 | promoteYoungCodeBlocks(locker); |
fpizlo@apple.com | 195d7b8 | 2013-09-03 16:39:29 +0000 | [diff] [blame] | 68 | } |
| 69 | |
ggaren@apple.com | 81def5f | 2015-10-09 23:10:16 +0000 | [diff] [blame] | 70 | void CodeBlockSet::lastChanceToFinalize() |
commit-queue@webkit.org | 87dc3e7 | 2015-10-04 01:45:21 +0000 | [diff] [blame] | 71 | { |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 72 | LockHolder locker(&m_lock); |
ggaren@apple.com | 81def5f | 2015-10-09 23:10:16 +0000 | [diff] [blame] | 73 | for (CodeBlock* codeBlock : m_newCodeBlocks) |
| 74 | codeBlock->classInfo()->methodTable.destroy(codeBlock); |
| 75 | |
| 76 | for (CodeBlock* codeBlock : m_oldCodeBlocks) |
| 77 | codeBlock->classInfo()->methodTable.destroy(codeBlock); |
commit-queue@webkit.org | 87dc3e7 | 2015-10-04 01:45:21 +0000 | [diff] [blame] | 78 | } |
| 79 | |
fpizlo@apple.com | ea379af | 2016-10-21 02:17:35 +0000 | [diff] [blame] | 80 | void CodeBlockSet::deleteUnmarkedAndUnreferenced(CollectionScope scope) |
mhahnenberg@apple.com | 7d223bb | 2014-04-02 23:50:25 +0000 | [diff] [blame] | 81 | { |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 82 | LockHolder locker(&m_lock); |
fpizlo@apple.com | ea379af | 2016-10-21 02:17:35 +0000 | [diff] [blame] | 83 | HashSet<CodeBlock*>& set = scope == CollectionScope::Eden ? m_newCodeBlocks : m_oldCodeBlocks; |
ggaren@apple.com | 81def5f | 2015-10-09 23:10:16 +0000 | [diff] [blame] | 84 | Vector<CodeBlock*> unmarked; |
| 85 | for (CodeBlock* codeBlock : set) { |
| 86 | if (Heap::isMarked(codeBlock)) |
| 87 | continue; |
| 88 | unmarked.append(codeBlock); |
| 89 | } |
mhahnenberg@apple.com | 7d223bb | 2014-04-02 23:50:25 +0000 | [diff] [blame] | 90 | |
ggaren@apple.com | 81def5f | 2015-10-09 23:10:16 +0000 | [diff] [blame] | 91 | for (CodeBlock* codeBlock : unmarked) { |
| 92 | codeBlock->classInfo()->methodTable.destroy(codeBlock); |
| 93 | set.remove(codeBlock); |
fpizlo@apple.com | 195d7b8 | 2013-09-03 16:39:29 +0000 | [diff] [blame] | 94 | } |
mhahnenberg@apple.com | 7d223bb | 2014-04-02 23:50:25 +0000 | [diff] [blame] | 95 | |
| 96 | // Any remaining young CodeBlocks are live and need to be promoted to the set of old CodeBlocks. |
fpizlo@apple.com | ea379af | 2016-10-21 02:17:35 +0000 | [diff] [blame] | 97 | if (scope == CollectionScope::Eden) |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 98 | promoteYoungCodeBlocks(locker); |
fpizlo@apple.com | 195d7b8 | 2013-09-03 16:39:29 +0000 | [diff] [blame] | 99 | } |
| 100 | |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 101 | bool CodeBlockSet::contains(const LockHolder&, void* candidateCodeBlock) |
mark.lam@apple.com | aebf685 | 2014-03-03 21:39:21 +0000 | [diff] [blame] | 102 | { |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 103 | RELEASE_ASSERT(m_lock.isLocked()); |
| 104 | CodeBlock* codeBlock = static_cast<CodeBlock*>(candidateCodeBlock); |
| 105 | if (!HashSet<CodeBlock*>::isValidValue(codeBlock)) |
| 106 | return false; |
| 107 | return m_oldCodeBlocks.contains(codeBlock) || m_newCodeBlocks.contains(codeBlock) || m_currentlyExecuting.contains(codeBlock); |
mark.lam@apple.com | aebf685 | 2014-03-03 21:39:21 +0000 | [diff] [blame] | 108 | } |
| 109 | |
fpizlo@apple.com | 7b23164 | 2016-10-11 23:52:02 +0000 | [diff] [blame] | 110 | void CodeBlockSet::writeBarrierCurrentlyExecuting(Heap* heap) |
mhahnenberg@apple.com | 3ddd7ac | 2014-01-10 02:28:27 +0000 | [diff] [blame] | 111 | { |
sbarati@apple.com | a4ce86b | 2016-01-11 06:49:49 +0000 | [diff] [blame] | 112 | LockHolder locker(&m_lock); |
fpizlo@apple.com | 04a048c | 2014-04-28 19:01:07 +0000 | [diff] [blame] | 113 | if (verbose) |
| 114 | dataLog("Remembering ", m_currentlyExecuting.size(), " code blocks.\n"); |
ggaren@apple.com | 81def5f | 2015-10-09 23:10:16 +0000 | [diff] [blame] | 115 | for (CodeBlock* codeBlock : m_currentlyExecuting) |
| 116 | heap->writeBarrier(codeBlock); |
fpizlo@apple.com | 7b23164 | 2016-10-11 23:52:02 +0000 | [diff] [blame] | 117 | } |
commit-queue@webkit.org | 87dc3e7 | 2015-10-04 01:45:21 +0000 | [diff] [blame] | 118 | |
fpizlo@apple.com | 7b23164 | 2016-10-11 23:52:02 +0000 | [diff] [blame] | 119 | void CodeBlockSet::clearCurrentlyExecuting() |
| 120 | { |
mhahnenberg@apple.com | 3ddd7ac | 2014-01-10 02:28:27 +0000 | [diff] [blame] | 121 | m_currentlyExecuting.clear(); |
mhahnenberg@apple.com | 3ddd7ac | 2014-01-10 02:28:27 +0000 | [diff] [blame] | 122 | } |
| 123 | |
fpizlo@apple.com | 229fa34 | 2014-05-08 02:35:22 +0000 | [diff] [blame] | 124 | void CodeBlockSet::dump(PrintStream& out) const |
| 125 | { |
| 126 | CommaPrinter comma; |
| 127 | out.print("{old = ["); |
| 128 | for (CodeBlock* codeBlock : m_oldCodeBlocks) |
| 129 | out.print(comma, pointerDump(codeBlock)); |
| 130 | out.print("], new = ["); |
| 131 | comma = CommaPrinter(); |
| 132 | for (CodeBlock* codeBlock : m_newCodeBlocks) |
| 133 | out.print(comma, pointerDump(codeBlock)); |
| 134 | out.print("], currentlyExecuting = ["); |
| 135 | comma = CommaPrinter(); |
ggaren@apple.com | 81def5f | 2015-10-09 23:10:16 +0000 | [diff] [blame] | 136 | for (CodeBlock* codeBlock : m_currentlyExecuting) |
| 137 | out.print(comma, pointerDump(codeBlock)); |
fpizlo@apple.com | 229fa34 | 2014-05-08 02:35:22 +0000 | [diff] [blame] | 138 | out.print("]}"); |
| 139 | } |
| 140 | |
fpizlo@apple.com | 195d7b8 | 2013-09-03 16:39:29 +0000 | [diff] [blame] | 141 | } // namespace JSC |
| 142 | |