Skip to content

Commit ebe252d

Browse files
committed
Merge pull request #8 in G/truffle from pr/incremental-instrumentation-registration to master
Contributed by Stefan Marr <stefan.marr@jku.at> * commit '12740cc59a324b3543a67a03ed711024a8951264': Add support for incremental compilation to Instrument registration
2 parents fc569a2 + 12740cc commit ebe252d

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

truffle/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/InstrumentRegistrationProcessor.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,34 @@ public SourceVersion getSupportedSourceVersion() {
5757
return SourceVersion.latest();
5858
}
5959

60+
private static final int NUMBER_OF_PROPERTIES_PER_ENTRY = 4;
61+
6062
private void generateFile(List<TypeElement> instruments) {
6163
String filename = "META-INF/truffle/instrument";
6264
Properties p = new Properties();
65+
int numInstruments = loadIfFileAlreadyExists(filename, p);
6366

64-
int cnt = 0;
6567
for (TypeElement l : instruments) {
6668
Registration annotation = l.getAnnotation(Registration.class);
6769
if (annotation == null) {
6870
continue;
6971
}
70-
String prefix = "instrument" + ++cnt + ".";
72+
73+
int instNum = findInstrument(annotation.id(), p);
74+
if (instNum == 0) { // not found
75+
numInstruments += 1;
76+
instNum = numInstruments;
77+
}
78+
79+
String prefix = "instrument" + instNum + ".";
7180
String className = processingEnv.getElementUtils().getBinaryName(l).toString();
81+
7282
p.setProperty(prefix + "id", annotation.id());
7383
p.setProperty(prefix + "name", annotation.name());
7484
p.setProperty(prefix + "version", annotation.version());
7585
p.setProperty(prefix + "className", className);
7686
}
77-
if (cnt > 0) {
87+
if (numInstruments > 0) {
7888
try {
7989
FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", filename);
8090
try (OutputStream os = file.openOutputStream()) {
@@ -86,6 +96,31 @@ private void generateFile(List<TypeElement> instruments) {
8696
}
8797
}
8898

99+
private static int findInstrument(String id, Properties p) {
100+
int cnt = 1;
101+
String val;
102+
while ((val = p.getProperty("instrument" + cnt + ".id")) != null) {
103+
if (id.equals(val)) {
104+
return cnt;
105+
}
106+
cnt += 1;
107+
}
108+
return 0;
109+
}
110+
111+
private int loadIfFileAlreadyExists(String filename, Properties p) {
112+
try {
113+
FileObject file = processingEnv.getFiler().getResource(
114+
StandardLocation.CLASS_OUTPUT, "", filename);
115+
p.load(file.openInputStream());
116+
117+
return p.keySet().size() / NUMBER_OF_PROPERTIES_PER_ENTRY;
118+
} catch (IOException e) {
119+
// Ignore error. It is ok if the file does not exist
120+
return 0;
121+
}
122+
}
123+
89124
static void loadExistingTypes(ProcessingEnvironment env, List<TypeElement> instruments, String filename, String pre) {
90125
Set<String> typeNames = new HashSet<>();
91126
for (TypeElement type : instruments) {

0 commit comments

Comments
 (0)