# Class: com.pnfsoftware.jeb.core.units.code.android.ir.AbstractDCollectionOptimizer

Base class for `dexdec` \(DEX decompiler\) IR optimizer plugins working on a collection of IR contexts. Those plugins can access and modify the intermediate representation of a group of methods being decompiled. They can be used to implement a wide range of optimizations, from trivial code clean\-up to the most complex deobfuscation passes. Internally, `dexdec` uses IR optimizers to perform dead\-code removal, variable substitutions, immediate propagation, restructuring, constant folding, arithmetic operation simplifications, deobfuscations such as control\-flow unflattening, etc. 

 Optimizers are usually managed by [master optimizers](IDMasterOptimizer) \(also called `orchestrators`\). Third\-party optimizer plugins can be automatically registered when creating an orchestrator. Refer to [createMasterOptimizer](IDGlobalContext#createMasterOptimizer(IDMethodContext)). 

 Life\-cycle information:
 \- plugins are reused \(i.e. the [#performOnCollection()](#performOnCollection()) method is called multiple times\)
 \- thread\-safety:
 \-\- Python script plugins must be thread\-safe: a plugin instance may be executed by multiple threads concurrently
 \-\- Java plugins \(including Java script plugins\) are not required to be thread\-safe: a plugin instance will not be executed by multiple threads concurrently
 

 Note: Starting from JEB 5.28, collection optimizers are not enabled by default. You must set the option `.parsers.dcmp_dex.EnableCollectionOptimizers` to `true` to instruct the decompiler to execute them.

## Constructor: AbstractDCollectionOptimizer

Description: Create a [standard](DOptimizerType#NORMAL) optimizer.

## Constructor: AbstractDCollectionOptimizer
- parameter: `type`, type: `com.pnfsoftware.jeb.core.units.code.android.ir.DOptimizerType`

Description: Create an optimizer.
parameter: type: optimizer type, or null to use [DOptimizerType#NORMAL](DOptimizerType#NORMAL)

## Constructor: AbstractDCollectionOptimizer
- parameter: `type`, type: `com.pnfsoftware.jeb.core.units.code.android.ir.DOptimizerType`
- parameter: `name`, type: `java.lang.String`

Description: Create an optimizer.
parameter: type: optimizer type, or null to use [DOptimizerType#NORMAL](DOptimizerType#NORMAL)
parameter: name: optional optimizer name

## Field: ctxlist
Type: `java.util.List<com.pnfsoftware.jeb.core.units.code.android.ir.IDMethodContext>`
Description: The list of IR method contexts available to the optimizer. A collection is not a class. Those IR contexts may represent methods from multiple classes.

## Field: decomp
Type: `com.pnfsoftware.jeb.core.units.code.android.IDexDecompilerUnit`
Description: Managing dex decompiler.

## Field: dex
Type: `com.pnfsoftware.jeb.core.units.code.android.IDexUnit`
Description: Underlying dex code.

## Field: g
Type: `com.pnfsoftware.jeb.core.units.code.android.ir.IDGlobalContext`
Description: IR global context.

## Field: of
Type: `com.pnfsoftware.jeb.core.units.code.java.IJavaOperatorFactory`
Description: IR/AST operation factory reference \(for convenience\).

## Field: tf
Type: `com.pnfsoftware.jeb.core.units.code.java.IJavaTypeFactory`
Description: IR/AST type factory reference \(for convenience\).

## Static Field: logger
Type: `com.pnfsoftware.jeb.util.logging.ILogger`
Description: Public logger accessible by the implementing optimizer. Writing to the logger should be favored over writing directly to `stdout`.

## Protected Method: addTag
- parameter: `tag`, type: `java.lang.String`

Description: Add an optimizer tag.
parameter: tag: tag to add

## Method: assignLocalFields
- parameter: `_ctxlist`, type: `java.util.List<com.pnfsoftware.jeb.core.units.code.android.ir.IDMethodContext>`

Description: This convenience method can be used to assign the object's attributes from the values of the provided IR contexts.
parameter: _ctxlist: an IR context

## Protected Method: checkInterrupted

Description: Verify if an interruption request was made by the managing decompiler. This method may be called when potentially length computations are performed in a loop.

## Method: generatePerClassContextsMap
- return type: `java.util.Map<java.lang.String,java.util.List<com.pnfsoftware.jeb.core.units.code.android.ir.IDMethodContext>>`

Description: Generate a per\-class map of method contexts.
return: a map with key= class signature C, value= list of IR contexts for methods belonging         to the class C

## Method: getName
- return type: `java.lang.String`


## Method: getPluginInformation
- return type: `com.pnfsoftware.jeb.core.EditablePluginInformation`


## Method: getPriority
- return type: `double`


## Method: getTags
- return type: `java.util.Set<java.lang.String>`


## Method: getType
- return type: `com.pnfsoftware.jeb.core.units.code.android.ir.DOptimizerType`


## Method: isCollectionOptimizer
- return type: `boolean`


## Method: isEnabled
- return type: `boolean`


## Method: perform
- parameter: `ctx`, type: `com.pnfsoftware.jeb.core.units.code.android.ir.IDMethodContext`
- return type: `int`


## Method: performOnCollection
- parameter: `ctxlist`, type: `java.util.List<com.pnfsoftware.jeb.core.units.code.android.ir.IDMethodContext>`
- parameter: `pmcntmap`, type: `java.util.Map<com.pnfsoftware.jeb.core.units.code.android.ir.IDMethodContext,java.lang.Integer>`
- return type: `int`


## Method: performOnCollection
- return type: `int`

Description: An optimizer must implement this method. This method is called by a master optimizer to perform optimizations on the provided target contexts.
return: total count of optimizations; it is also recommended to register per\-method         optimizations with [#recordMethodOptimization(IDMethodContext, int)](#recordMethodOptimization(IDMethodContext, int))

## Protected Method: recordMethodOptimization
- parameter: `ctx`, type: `com.pnfsoftware.jeb.core.units.code.android.ir.IDMethodContext`
- parameter: `cnt`, type: `int`

Description: Record optimization counts for a method context.
parameter: ctx: method context
parameter: cnt: number of optimizations performed

## Protected Method: removeTag
- parameter: `tag`, type: `java.lang.String`

Description: Remove an optimizer tag.
parameter: tag: tag to remove

## Method: resetLocalFields

Description: Reset this object's attributes. Same as [assignLocalFields\(null\)](#assignLocalFields(List)).

## Method: setEnabled
- parameter: `enabled`, type: `boolean`

Description: Enable or disable this optimizer. This flag is checked by a [master optimizer](IDMasterOptimizer).
parameter: enabled: true to enable this optimizer

## Protected Method: setName
- parameter: `name`, type: `java.lang.String`

Description: Set the optimizer name. To be used by the constructor.
parameter: name: if null, a name will be auto\-generated

## Protected Method: setPriority
- parameter: `priority`, type: `double`

Description: Set the optimizer priority. To be used by the constructor.
parameter: priority: the new priority \(high means higher priority\). When optimizers are managed            and run by an orchestrator, the optimizers with a higher priority are run before            those having a lower priority. The default priority is 0.

## Protected Method: setType
- parameter: `type`, type: `com.pnfsoftware.jeb.core.units.code.android.ir.DOptimizerType`

Description: Set the optimizer type. To be used by the constructor.
parameter: type: if null, a [standard](DOptimizerType#NORMAL) optimizer is assumed

