/
CopyMS.java
204 lines (178 loc) · 6.32 KB
/
CopyMS.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
* This file is part of the Jikes RVM project (http://jikesrvm.org).
*
* This file is licensed to You under the Common Public License (CPL);
* You may not use this file except in compliance with the License. You
* may obtain a copy of the License at
*
* http://www.opensource.org/licenses/cpl1.0.php
*
* See the COPYRIGHT.txt file distributed with this work for information
* regarding copyright ownership.
*/
package org.mmtk.plan.copyms;
import org.mmtk.plan.*;
import org.mmtk.policy.CopySpace;
import org.mmtk.policy.MarkSweepSpace;
import org.mmtk.policy.Space;
import org.mmtk.utility.heap.VMRequest;
import org.mmtk.utility.options.Options;
import org.mmtk.utility.sanitychecker.SanityChecker;
import org.vmmagic.pragma.*;
import org.vmmagic.unboxed.ObjectReference;
/**
* This class implements the global state of a full-heap collector
* with a copying nursery and mark-sweep mature space. Unlike a full
* generational collector, there is no write barrier, no remembered set, and
* every collection is full-heap.
*
* All plans make a clear distinction between <i>global</i> and
* <i>thread-local</i> activities, and divides global and local state
* into separate class hierarchies. Global activities must be
* synchronized, whereas no synchronization is required for
* thread-local activities. There is a single instance of Plan (or the
* appropriate sub-class), and a 1:1 mapping of PlanLocal to "kernel
* threads" (aka CPUs). Thus instance
* methods of PlanLocal allow fast, unsychronized access to functions such as
* allocation and collection.
*
* The global instance defines and manages static resources
* (such as memory and virtual memory resources). This mapping of threads to
* instances is crucial to understanding the correctness and
* performance properties of MMTk plans.
*/
@Uninterruptible
public class CopyMS extends StopTheWorld {
/****************************************************************************
* Constants
*/
/****************************************************************************
* Class variables
*/
public static final CopySpace nurserySpace = new CopySpace("nursery", DEFAULT_POLL_FREQUENCY, false, VMRequest.create(0.15f, true));
public static final MarkSweepSpace msSpace = new MarkSweepSpace("ms", DEFAULT_POLL_FREQUENCY, VMRequest.create());
public static final int NURSERY = nurserySpace.getDescriptor();
public static final int MARK_SWEEP = msSpace.getDescriptor();
public static final int ALLOC_NURSERY = ALLOC_DEFAULT;
public static final int ALLOC_MS = StopTheWorld.ALLOCATORS + 1;
public static final int SCAN_COPYMS = 0;
/****************************************************************************
* Instance variables
*/
public final Trace trace;
/**
* Constructor.
*/
public CopyMS() {
trace = new Trace(metaDataSpace);
}
/*****************************************************************************
* Collection
*/
/**
* Perform a (global) collection phase.
*
* @param phaseId Collection phase to execute.
*/
@Inline
public final void collectionPhase(short phaseId) {
if (phaseId == PREPARE) {
super.collectionPhase(phaseId);
trace.prepare();
msSpace.prepare(true);
nurserySpace.prepare(true);
return;
}
if (phaseId == CLOSURE) {
trace.prepare();
return;
}
if (phaseId == RELEASE) {
trace.release();
msSpace.release();
nurserySpace.release();
super.collectionPhase(phaseId);
return;
}
super.collectionPhase(phaseId);
}
/**
* This method controls the triggering of a GC. It is called periodically
* during allocation. Returns true to trigger a collection.
*
* @param spaceFull Space request failed, must recover pages within 'space'.
* @return True if a collection is requested by the plan.
*/
public final boolean collectionRequired(boolean spaceFull) {
boolean nurseryFull = nurserySpace.reservedPages() > Options.nurserySize.getMaxNursery();
return super.collectionRequired(spaceFull) || nurseryFull;
}
/*****************************************************************************
*
* Accounting
*/
/**
* Return the number of pages reserved for use given the pending
* allocation.
*
* @return The number of pages reserved given the pending
* allocation, excluding space reserved for copying.
*/
public int getPagesUsed() {
return super.getPagesUsed() +
msSpace.reservedPages() +
nurserySpace.reservedPages();
}
/**
* Return the number of pages reserved for collection.
* For mark sweep this is a fixed fraction of total pages.
*
* @return The number of pages reserved given the pending
* allocation, including space reserved for collection.
*/
public int getCollectionReserve() {
return nurserySpace.reservedPages() + super.getCollectionReserve();
}
/**
* @return The number of pages available for allocation, <i>assuming
* all future allocation is to the nursery</i>.
*/
public final int getPagesAvail() {
return (getTotalPages() - getPagesReserved()) >> 1;
}
/**
* Calculate the number of pages a collection is required to free to satisfy
* outstanding allocation requests.
*
* @return the number of pages a collection is required to free to satisfy
* outstanding allocation requests.
*/
public int getPagesRequired() {
return super.getPagesRequired() + msSpace.requiredPages() +
(nurserySpace.requiredPages() << 1);
}
/**
* Return the expected reference count. For non-reference counting
* collectors this becomes a true/false relationship.
*
* @param object The object to check.
* @param sanityRootRC The number of root references to the object.
* @return The expected (root excluded) reference count.
*/
public int sanityExpectedRC(ObjectReference object, int sanityRootRC) {
Space space = Space.getSpaceForObject(object);
// Nursery
if (space == CopyMS.nurserySpace) {
return SanityChecker.DEAD;
}
return space.isReachable(object) ? SanityChecker.ALIVE : SanityChecker.DEAD;
}
/**
* Register specialized methods.
*/
@Interruptible
protected void registerSpecializedMethods() {
TransitiveClosure.registerSpecializedScan(SCAN_COPYMS, CopyMSTraceLocal.class);
super.registerSpecializedMethods();
}
}