Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[performance] BatchImageBuilder: write .class files in batches #2948

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,6 @@ protected void restoreAptProblems() {

protected void processCompiledUnits(int startingIndex, boolean lastRound) throws java.lang.Error {
CompilationUnitDeclaration unit = null;
ProcessTaskManager processingTask = null;
try {
if (this.useSingleThread) {
// process all units (some more could be injected in the loop by the lookup environment)
Expand Down Expand Up @@ -596,30 +595,37 @@ protected void processCompiledUnits(int startingIndex, boolean lastRound) throws
}));
}
} else {
processingTask = new ProcessTaskManager(this, startingIndex);
int acceptedCount = 0;
// process all units (some more could be injected in the loop by the lookup environment)
// the processTask can continue to process units until its fixed sized cache is full then it must wait
// for this this thread to accept the units as they appear (it only waits if no units are available)
while (true) {
try (ProcessTaskManager processingTask = new ProcessTaskManager(this, startingIndex)){
int acceptedCount = 0;
// process all units (some more could be injected in the loop by the lookup environment)
// the processTask can continue to process units until its fixed sized cache is full then it must wait
// for this this thread to accept the units as they appear (it only waits if no units are available)
this.requestor.startBatch();
try {
unit = processingTask.removeNextUnit(); // waits if no units are in the processed queue
} catch (Error | RuntimeException e) {
unit = processingTask.unitToProcess;
throw e;
Collection<CompilationUnitDeclaration> units;
do {
try {
units = processingTask.removeNextUnits();
} catch (Error | RuntimeException e) {
unit = processingTask.getUnitWithError();
throw e;
}
for (CompilationUnitDeclaration u : units) {
unit = u;
reportWorked(1, acceptedCount++);
this.stats.lineCount += unit.compilationResult.lineSeparatorPositions.length;
this.requestor.acceptResult(unit.compilationResult.tagAsAccepted());
if (this.options.verbose)
this.out.println(Messages.bind(Messages.compilation_done,
new String[] { String.valueOf(acceptedCount),
String.valueOf(this.totalUnits), new String(unit.getFileName()) }));
}
// processingTask had no more units available => use the time to flush:
this.requestor.flushBatch();
} while (!units.isEmpty());
} finally {
this.requestor.endBatch();
}
if (unit == null) break;
reportWorked(1, acceptedCount++);
this.stats.lineCount += unit.compilationResult.lineSeparatorPositions.length;
this.requestor.acceptResult(unit.compilationResult.tagAsAccepted());
if (this.options.verbose)
this.out.println(
Messages.bind(Messages.compilation_done,
new String[] {
String.valueOf(acceptedCount),
String.valueOf(this.totalUnits),
new String(unit.getFileName())
}));
}
}
if (!lastRound) {
Expand All @@ -640,10 +646,6 @@ protected void processCompiledUnits(int startingIndex, boolean lastRound) throws
this.handleInternalException(e, unit, null);
throw e; // rethrow
} finally {
if (processingTask != null) {
processingTask.shutdown();
processingTask = null;
}
reset();
this.annotationProcessorStartIndex = 0;
this.stats.endTime = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,26 @@ public interface ICompilerRequestor {
* Accept a compilation result.
*/
public void acceptResult(CompilationResult result);

/**
* Optionally called to start multiple {@link #acceptResult(CompilationResult)}
*/
public default void startBatch() {
//nothing
}

/**
* Optionally called after some {@link #acceptResult(CompilationResult)} to signal a good point in time
*/
public default void flushBatch() {
//nothing
}

/**
* if {@link #startBatch} was called then endBatch is called to finalize possibly multiple
* {@link #acceptResult(CompilationResult)}
*/
public default void endBatch() {
// nothing
}
}
Loading