APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.tools.javac.api

public Class JavacTaskPool

extends Object
Class Inheritance
Imports
java.io.PrintStream, .PrintWriter, .Writer, java.util.ArrayDeque, .ArrayList, .Collection, .HashMap, .HashSet, .List, .Map, .Queue, .Set, java.util.stream.Collectors, .StreamSupport, javax.tools.Diagnostic, .DiagnosticListener, .JavaFileManager, .JavaFileObject, .StandardLocation, com.sun.source.tree.ClassTree, .CompilationUnitTree, .Tree, com.sun.source.util.JavacTask, .TaskEvent, .TaskEvent.Kind, .TaskListener, .TreeScanner, com.sun.tools.javac.code.Kinds, .LintMapper, .Preview, .Symbol, .Symtab, .Type, .Type.ClassType, .TypeTag, .Types, com.sun.tools.javac.comp.Annotate, .Check, .CompileStates, .Enter, .Modules, com.sun.tools.javac.main.Arguments, .JavaCompiler, com.sun.tools.javac.model.JavacElements, com.sun.tools.javac.platform.PlatformDescription, com.sun.tools.javac.tree.JCTree.JCClassDecl, .JCTree.LetExpr, com.sun.tools.javac.util.Context, .DefinedBy, .DefinedBy.Api, .Log, .Options

A pool of reusable JavacTasks. When a task is no valid anymore, it is returned to the pool, and its Context may be reused for future processing in some cases. The reuse is achieved by replacing some components (most notably JavaCompiler and Log) with reusable counterparts, and by cleaning up leftovers from previous compilation.

For each combination of options, a separate task/context is created and kept, as most option values are cached inside components themselves.

When the compilation redefines sensitive classes (e.g. classes in the java.* packages), the task/context is not reused.

When the task is reused, then packages that were already listed won't be listed again.

Care must be taken to only return tasks that won't be used by the original caller.

Care must also be taken when custom components are installed, as those are not cleaned when the task/context is reused, and subsequent getTask may return a task based on a context with these custom components.

This is NOT part of any supported API. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
public static interface

Field Summary

Modifier and TypeField and Description
private static final Queue<JavacTaskPool.ReusableContext>
private int
private final int
private final Map<List<String>, Queue<JavacTaskPool.ReusableContext>>
private int
private int
private int
private int
private static final JavacTool

Constructor Summary

AccessConstructor and Description
public
JavacTaskPool(int
maximum number of tasks/context that will be kept in the pool.
maxPoolSize
)

Creates the pool.

Method Summary

Modifier and TypeMethod and Description
private long
public <Z> Z

Returns:

an object representing the compilation
getTask
(Writer
a Writer for additional output from the compiler; use System.err if null
out
,
JavaFileManager
a file manager; if null use the compiler's standard file manager
fileManager
,
DiagnosticListener<? super JavaFileObject>
a diagnostic listener; if null use the compiler's default method for reporting diagnostics
diagnosticListener
,
Iterable<String>
compiler options, null means no options
options
,
Iterable<String>
names of classes to be processed by annotation processing, null means no class names
classes
,
Iterable<? extends JavaFileObject>
the compilation units to compile, null means no compilation units
compilationUnits
,
JavacTaskPool.Worker<Z>
that should be run with the task
worker
)

Creates a new task as if by javax.tools.JavaCompiler#getTask and runs the provided worker with it.

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EMPTY_QUEUEback to summary
private static final Queue<JavacTaskPool.ReusableContext> EMPTY_QUEUE
idback to summary
private int id
maxPoolSizeback to summary
private final int maxPoolSize
options2Contextsback to summary
private final Map<List<String>, Queue<JavacTaskPool.ReusableContext>> options2Contexts
statNewback to summary
private int statNew
statPollutedback to summary
private int statPolluted
statRemovedback to summary
private int statRemoved
statReusedback to summary
private int statReused
systemProviderback to summary
private static final JavacTool systemProvider

Constructor Detail

JavacTaskPoolback to summary
public JavacTaskPool(int maxPoolSize)

Creates the pool.

Parameters
maxPoolSize:int

maximum number of tasks/context that will be kept in the pool.

Method Detail

cacheSizeback to summary
private long cacheSize()
getTaskback to summary
public <Z> Z getTask(Writer out, JavaFileManager fileManager, DiagnosticListener<? super JavaFileObject> diagnosticListener, Iterable<String> options, Iterable<String> classes, Iterable<? extends JavaFileObject> compilationUnits, JavacTaskPool.Worker<Z> worker)

Creates a new task as if by javax.tools.JavaCompiler#getTask and runs the provided worker with it. The task is only valid while the worker is running. The internal structures may be reused from some previous compilation.

Parameters
out:Writer

a Writer for additional output from the compiler; use System.err if null

fileManager:JavaFileManager

a file manager; if null use the compiler's standard file manager

diagnosticListener:DiagnosticListener<? super JavaFileObject>

a diagnostic listener; if null use the compiler's default method for reporting diagnostics

options:Iterable<String>

compiler options, null means no options

classes:Iterable<String>

names of classes to be processed by annotation processing, null means no class names

compilationUnits:Iterable<? extends JavaFileObject>

the compilation units to compile, null means no compilation units

worker:JavacTaskPool.Worker<Z>

that should be run with the task

Returns:Z

an object representing the compilation

Exceptions
RuntimeException:
if an unrecoverable error occurred in a user supplied component. The cause will be the error in user code.
IllegalArgumentException:
if any of the options are invalid, or if any of the given compilation units are of other kind than source
printStatisticsback to summary
public void printStatistics(PrintStream out)
com.sun.tools.javac.api back to summary

pack-priv Class JavacTaskPool.ReusableContext

extends Context
implements TaskListener
Class Inheritance
All Implemented Interfaces
com.sun.source.util.TaskListener

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
JavacTaskPool.ReusableContext.ReusableJavaCompiler

Reusable JavaCompiler; exposes a method to clean up the component from leftovers associated with previous compilations.

pack-priv static class
JavacTaskPool.ReusableContext.ReusableLog

Reusable Log; exposes a method to clean up the component from leftovers associated with previous compilations.

Field Summary

Modifier and TypeField and Description
pack-priv List<String>
pack-priv boolean
pack-priv TreeScanner<Void, Symtab>
pollutionScanner

This scanner detects as to whether the shared context has been polluted.

pack-priv Set<CompilationUnitTree>
pack-priv long
pack-priv int
Inherited from com.sun.tools.javac.util.Context:
ht

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv <T> void
pack-priv <T> void
drop(Class<T> c)

public void
finished(TaskEvent e)

Overrides default com.sun.source.util.TaskListener.finished.

Invoked when an event has been completed.

public void
started(TaskEvent e)

Overrides default com.sun.source.util.TaskListener.started.

Invoked when an event has begun.

Inherited from com.sun.tools.javac.util.Context:
dumpgetgetkeyputputputput

Field Detail

argumentsback to summary
pack-priv List<String> arguments
pollutedback to summary
pack-priv boolean polluted
pollutionScannerback to summary
pack-priv TreeScanner<Void, Symtab> pollutionScanner

This scanner detects as to whether the shared context has been polluted. This happens whenever a compiled program redefines a core class (in 'java.*' package) or when (typically because of cyclic inheritance) the symbol kind of a core class has been touched.

rootsback to summary
pack-priv Set<CompilationUnitTree> roots
timeStampback to summary
pack-priv long timeStamp
useCountback to summary
pack-priv int useCount

Constructor Detail

ReusableContextback to summary
pack-priv ReusableContext(List<String> arguments)

Method Detail

clearback to summary
pack-priv void clear()
dropback to summary
pack-priv <T> void drop(Context.Key<T> k)
dropback to summary
pack-priv <T> void drop(Class<T> c)
finishedback to summary
public void finished(TaskEvent e)

Overrides default com.sun.source.util.TaskListener.finished.

Doc from com.sun.source.util.TaskListener.finished.

Invoked when an event has been completed.

Annotations
@Override
@DefinedBy:COMPILER_TREE
startedback to summary
public void started(TaskEvent e)

Overrides default com.sun.source.util.TaskListener.started.

Doc from com.sun.source.util.TaskListener.started.

Invoked when an event has begun.

Annotations
@Override
@DefinedBy:COMPILER_TREE
com.sun.tools.javac.api back to summary

pack-priv Class JavacTaskPool.ReusableContext.ReusableJavaCompiler

extends JavaCompiler
Class Inheritance

Reusable JavaCompiler; exposes a method to clean up the component from leftovers associated with previous compilations.

Constructor Summary

AccessConstructor and Description
pack-priv

Field Detail

factoryback to summary
pack-priv static final Context.Factory<JavaCompiler> factory

Constructor Detail

ReusableJavaCompilerback to summary
pack-priv ReusableJavaCompiler(Context context)

Method Detail

checkReusableback to summary
protected void checkReusable()

Overrides com.sun.tools.javac.main.JavaCompiler.checkReusable.

Annotations
@Override
clearback to summary
pack-priv void clear()
closeback to summary
public void close()

Overrides com.sun.tools.javac.main.JavaCompiler.close.

Doc from com.sun.tools.javac.main.JavaCompiler.close.

Close the compiler, flushing the logs

Annotations
@Override
com.sun.tools.javac.api back to summary

pack-priv Class JavacTaskPool.ReusableContext.ReusableLog

extends Log
Class Inheritance

Reusable Log; exposes a method to clean up the component from leftovers associated with previous compilations.

Constructor Summary

AccessConstructor and Description
pack-priv

Field Detail

contextback to summary
pack-priv Context context

Hides com.sun.tools.javac.util.Log.context.

factoryback to summary
pack-priv static final Context.Factory<Log> factory

Constructor Detail

ReusableLogback to summary
pack-priv ReusableLog(Context context)

Method Detail

clearback to summary
public void clear()

Overrides com.sun.tools.javac.util.Log.clear.

Doc from com.sun.tools.javac.util.Log.clear.

Reset the state of this instance.

Annotations
@Override
com.sun.tools.javac.api back to summary

public Interface JavacTaskPool.Worker<Z>


Method Summary

Modifier and TypeMethod and Description
public Z

Method Detail

withTaskback to summary
public Z withTask(JavacTask task)