Set Up Code Inventory
Code Inventory is designed for application developers to simplify the work of code deprecation/removal. By tracking which methods run within a timeframe, teams can identify methods did not run and target that code for removal. Unlike dead code from static analysis techniques, Code Inventory tracks usage over time and helps pinpoint code regardless of accessibility or frameworks.
Common uses of Code Inventory are:
-
Decomposing monoliths.
-
Reducing an application’s attack surface.
-
Preventing accidental re-activation of dead code.
Enabling Code Inventory
Code Inventory must be enabled within applications. It is recommended for first-party (custom) applications rather than third-party COTS applications.
To enable Code Inventory, add notifyFirstCall=true to your comma-separated AZ_CRS_ARGUMENTS environment variable, see CRS Configuration Options and Diagnostics CRS Arguments.
How Code Inventory Works
Code Inventory tracks usage by recording the first execution of each method. Performance impact is negligible because the JVM has already identified this first execution and subsequent calls to the method are not tracked.
Focused Code Inventory
Since version 1.3.0 of the Intelligence Cloud Agent, you can scope Code Inventory to your own code. The Agent reports every loaded class and every first method call, and most of that is third-party code, such as libraries, frameworks and generated classes. Focused Code Inventory rules, defined in Azul Intelligence Cloud, tell the Agent which classes and methods to report. The Agent applies the rules before it sends anything, which reduces network traffic and processing, and makes the results easier to read.
-
Rules can include packages, and exclude packages or name patterns. Excluding wins over including.
-
Rules can be global, or apply to a specific application environment (
AppEnv). -
JDK classes, Agent internals and generated proxy and lambda classes are always excluded.
You don’t configure anything on the Agent: it receives the rules automatically. Without rules, the Agent reports as before. Focused Code Inventory is available for Azul Intelligence Cloud only, not for Azul Intelligence On-Premises.
Identifying Unused Methods
Code Inventory tracks first method invocation – it does not reproduce the entire inventory of available code found within source files and bytecode. Developers should compare a Code Inventory report against their codebase to identify classes and methods that are in source but not the Code Inventory: these methods were not executed within the timeframe.
Retrieve Code Inventory Results
The results of Code Inventory are available through the API, see API for Code Inventory for more info.