ForkJoinParallelCpgPass
A parallel CPG pass using the fork/join model.
Instead of returning an Iterator, generateParts returns an Array. This means that the entire collection of parts must live on the heap at the same time; on the other hand, there are no possible issues with iterator invalidation, e.g. when running over all METHOD nodes and deleting some of them.
Instead of streaming writes as ParallelCpgPass do, all runOnPart invocations read the initial state of the graph. Then all changes (accumulated in the DiffGraphBuilders) are merged into a single change, and applied in one go.
In other words, the parallelism follows the fork/join parallel map-reduce (java: collect, scala: aggregate) model. The effect is identical as if one were to sequentially run runOnPart on all output elements of generateParts in sequential order, with the same builder.
This simplifies semantics and makes it easy to reason about possible races.
Note that ForkJoinParallelCpgPass never writes intermediate results, so one must consider peak memory consumption when porting from ParallelCpgPass.
Initialization and cleanup of external resources or large datastructures can be done in the init and finish methods. This may be better than using the constructor or GC, because e.g. SCPG chains of passes construct passes eagerly, and releases them only when the entire chain has run.
This is a simplified form of ForkJoinParallelCpgPassWithAccumulator that does not use an accumulator.
Type parameters
- T
-
the type of each part produced by generateParts
Value parameters
- cpg
-
the code property graph to modify
- outname
-
optional output name
Attributes
- Graph
-
- Supertypes
- Known subtypes
-
class CpgPassclass SimpleCpgPass
Members list
Type members
Inherited types
Attributes
- Inherited from:
- ForkJoinParallelCpgPassWithAccumulator
Value members
Abstract methods
Process a single part and record graph modifications in the provided builder.
Process a single part and record graph modifications in the provided builder.
Value parameters
- builder
-
the DiffGraphBuilder that accumulates graph modifications
- part
-
the part to process, as produced by generateParts
Attributes
Concrete methods
Create a fresh accumulator instance. Called once per parallel worker thread.
Create a fresh accumulator instance. Called once per parallel worker thread.
Attributes
- Definition Classes
Merge the accumulator (right) into left. Called during the combine phase of fork/join.
Merge the accumulator (right) into left. Called during the combine phase of fork/join.
Attributes
- Definition Classes
Called once after all parts are processed and accumulators are merged. Use to record additional graph changes based on the fully merged accumulator.
Called once after all parts are processed and accumulators are merged. Use to record additional graph changes based on the fully merged accumulator.
Value parameters
- accumulator
-
the final merged accumulator
- builder
-
the DiffGraphBuilder for any additional modifications
Attributes
- Definition Classes
Process a single part, recording graph changes in builder and side results in accumulator.
Process a single part, recording graph changes in builder and side results in accumulator.
Value parameters
- accumulator
-
the thread-local accumulator for this worker
- builder
-
the DiffGraphBuilder that accumulates graph modifications
- part
-
the part to process
Attributes
- Definition Classes
Inherited methods
Attributes
- Inherited from:
- CpgPassBase
Creates a new DiffGraphBuilder, runs the pass (init, generateParts, runOnPart, finish), applies all accumulated changes to the graph, and logs timing information. Exceptions during execution are logged and re-thrown.
Creates a new DiffGraphBuilder, runs the pass (init, generateParts, runOnPart, finish), applies all accumulated changes to the graph, and logs timing information. Exceptions during execution are logged and re-thrown.
Attributes
- Definition Classes
- Inherited from:
- ForkJoinParallelCpgPassWithAccumulator
Called once after all parts have been processed (in a finally block). Use to release resources acquired in init.
Called once after all parts have been processed (in a finally block). Use to release resources acquired in init.
Attributes
- Inherited from:
- ForkJoinParallelCpgPassWithAccumulator
Attributes
- Inherited from:
- CpgPassBase
Called once before generateParts. Use to set up large data structures or acquire external resources.
Called once before generateParts. Use to set up large data structures or acquire external resources.
Attributes
- Inherited from:
- ForkJoinParallelCpgPassWithAccumulator
Override and return false to disable parallel execution. Useful for debugging.
Override and return false to disable parallel execution. Useful for debugging.
Attributes
- Inherited from:
- ForkJoinParallelCpgPassWithAccumulator
Name of the pass. By default it is inferred from the name of the class, override if needed.
Name of the pass. By default it is inferred from the name of the class, override if needed.
Attributes
- Inherited from:
- CpgPassBase
Runs the full pass lifecycle (init, generateParts, parallel runOnPart, accumulator merge, finish) and absorbs all changes into externalBuilder without applying them to the graph. The caller is responsible for applying the builder.
Runs the full pass lifecycle (init, generateParts, parallel runOnPart, accumulator merge, finish) and absorbs all changes into externalBuilder without applying them to the graph. The caller is responsible for applying the builder.
Value parameters
- externalBuilder
-
the builder to absorb all generated changes into
Attributes
- Returns
-
the number of parts that were processed
- Definition Classes
- Inherited from:
- ForkJoinParallelCpgPassWithAccumulator
Wraps runWithBuilder with logging and exception handling. Use with caution — API is unstable.
Wraps runWithBuilder with logging and exception handling. Use with caution — API is unstable.
Value parameters
- builder
-
the DiffGraphBuilder to absorb changes into
Attributes
- Returns
-
the number of parts processed, or
-1if the pass threw an exception - Inherited from:
- CpgPassBase
Executes fun while logging the pass start and completion time (including duration via MDC).
Executes fun while logging the pass start and completion time (including duration via MDC).
Type parameters
- A
-
the return type of the wrapped computation
Value parameters
- fun
-
the computation to execute
Attributes
- Returns
-
the result of
fun - Inherited from:
- CpgPassBase
Inherited and Abstract methods
Generate an array of parts to be processed in parallel by runOnPart.
Generate an array of parts to be processed in parallel by runOnPart.
Attributes
- Inherited from:
- ForkJoinParallelCpgPassWithAccumulator
Deprecated and Inherited methods
Attributes
- Deprecated
- Please use createAndApply
- Definition Classes
- Inherited from:
- ForkJoinParallelCpgPassWithAccumulator
Attributes
- Deprecated
- true
- Inherited from:
- CpgPassBase