/
ComplexPhase.java
134 lines (122 loc) · 3.63 KB
/
ComplexPhase.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
/*
* 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;
import org.mmtk.utility.Constants;
import org.mmtk.utility.statistics.Timer;
import org.mmtk.utility.Log;
import org.mmtk.vm.VM;
import org.vmmagic.pragma.*;
/**
* Phases of a garbage collection.
*
* A complex phase is a sequence of phases.
*
*/
@Uninterruptible
public final class ComplexPhase extends Phase
implements Constants {
/****************************************************************************
* Instance fields
*/
/**
* The phases that comprise this phase.
*/
private final int[] scheduledSubPhases;
/**
* Construct a complex phase from an array of phase IDs.
*
* @param name The name of the phase.
* @param scheduledSubPhases The sub phases
*/
protected ComplexPhase(String name, int[] scheduledSubPhases) {
super(name);
this.scheduledSubPhases = scheduledSubPhases;
checkPhases();
}
/**
* Construct a complex phase from an array of phase IDs, but using
* the specified timer rather than creating one.
*
* @param name The name of the phase.
* @param timer The timer for this phase to contribute to.
* @param scheduledSubPhases The sub phases
*/
protected ComplexPhase(String name, Timer timer, int[] scheduledSubPhases) {
super(name, timer);
this.scheduledSubPhases = scheduledSubPhases;
checkPhases();
}
/**
* Validate the scheduled sub phases.
*/
private void checkPhases() {
if (VM.VERIFY_ASSERTIONS) {
VM.assertions._assert(scheduledSubPhases.length > 0);
for(int scheduledPhase: scheduledSubPhases) {
VM.assertions._assert(getSchedule(scheduledPhase) > 0);
VM.assertions._assert(getPhaseId(scheduledPhase) > 0);
}
}
}
/**
* The number of scheduled sub phases.
*/
protected int count() {
return scheduledSubPhases.length;
}
/**
* Return an individual scheduled sub phase.
*
* @param index The index
* @return The scheduled phase.
*/
protected int get(int index) {
return scheduledSubPhases[index];
}
/**
* Display a description of this phase, for debugging purposes.
*/
protected void logPhase() {
Log.write("ComplexPhase(");
Log.write(name);
Log.write(", < ");
for (int subPhase : scheduledSubPhases) {
short ordering = getSchedule(subPhase);
short phaseId = getPhaseId(subPhase);
Log.write(getScheduleName(ordering));
Log.write("(");
Log.write(getName(phaseId));
Log.write(") ");
}
Log.write(">)");
}
/**
* Replace a scheduled phase. Used for example to replace a placeholder.
*
* @param oldScheduledPhase The scheduled phase to replace.
* @param newScheduledPhase The new scheduled phase.
*/
public void replacePhase(int oldScheduledPhase, int newScheduledPhase) {
for (int i = 0; i < scheduledSubPhases.length; i++) {
int scheduledPhase = scheduledSubPhases[i];
if (scheduledPhase == oldScheduledPhase) {
/* Replace */
scheduledSubPhases[i] = newScheduledPhase;
} else if (getSchedule(scheduledPhase) == SCHEDULE_COMPLEX) {
/* Recurse */
ComplexPhase p = (ComplexPhase)getPhase(getPhaseId(scheduledPhase));
p.replacePhase(oldScheduledPhase, newScheduledPhase);
}
}
}
}