1 | /* |
2 | * Copyright (C) 2017 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. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | namespace JSC { |
29 | |
30 | // We track collector phase in order to allow either the collector thread or the mutator thread to |
31 | // jump in and do work. The collector and mutator trade the conn |
32 | // (https://en.wikipedia.org/wiki/Conn_(nautical)) with each other based on who is available to do work, |
33 | // and they use the phase to help each other know what to do once they take the conn. |
34 | // |
35 | // The collector relinquishes the conn whenever it stopTheMutator's and the mutator is running. Then the |
36 | // collector thread goes to sleep. |
37 | // |
38 | // The mutator relinquishes the conn whenever it releaseAccess's. That wakes up the collector thread. |
39 | enum class CollectorPhase : uint8_t { |
40 | // We use this phase when the collector is not running at all. After this state is Begin. |
41 | NotRunning, |
42 | |
43 | // This is everything from when the collector begins to when it first yields to the mutator for |
44 | // marking. After this is Fixpoint. |
45 | Begin, |
46 | |
47 | // This means that we should try to do some progress with the world stopped. This usually means |
48 | // doing an iteration of MarkingConstraintSet::executeConvergence, but it could also mean marking |
49 | // with the world stopped. After this is either Concurrent or End. |
50 | Fixpoint, |
51 | |
52 | // In this state the collector is relying on the parallel helpers and incremental mutator work to |
53 | // make progress. After this is Reloop, once marking stalls. |
54 | Concurrent, |
55 | |
56 | // We did some concurrent marking and now we ran out of work. This phase prepares the GC for another |
57 | // Fixpoint. After this is Fixpoint. |
58 | Reloop, |
59 | |
60 | // The collector is trying to finish up. After this state is NotRunning. |
61 | End |
62 | }; |
63 | |
64 | bool worldShouldBeSuspended(CollectorPhase phase); |
65 | |
66 | } // namespace JSC |
67 | |
68 | namespace WTF { |
69 | |
70 | class PrintStream; |
71 | |
72 | void printInternal(PrintStream&, JSC::CollectorPhase); |
73 | |
74 | } // namespace WTF |
75 | |
76 | |