Dynamic Dead Code Analysis via Aspect-Oriented Runtime Weaving
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Conventional static and dynamic code analysis tools fail to accurately identify unused code, particularly unreachable code that is never invoked, and require significant changes to the codebase for dynamic tools to function effectively.
Innovation Solution
A language-agnostic dynamic dead code analysis module that creates a list of method names before application launch, stores them in a hash set, and implements a pointcut process around method execution to identify and remove unused methods, using aspect-oriented programming and load-time weaving for dynamic code analysis with minimal code changes.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Measurement precision
If static analysis tools are used to identify dead code, then code can be analyzed during compile time, but these tools fail to accurately identify unreachable code that is never actually invoked
Solution Approach 1:
The patent creates a comprehensive list of all method names in the codebase before runtime analysis begins. This preliminary action establishes a baseline inventory of all available methods, which is then used to compare against actually invoked methods during runtime, enabling accurate identification of dead code without missing unreachable methods
Solution Approach 2:
The system implements continuous feedback by monitoring method invocations during runtime and dynamically updating the dead code identification. The pointcut process captures actual method calls and feeds this information back to the analysis module, which compares invoked methods against the preliminary list to accurately identify which methods were never called
2Measurement precision
If dynamic analysis tools are used to identify dead code, then unreachable code can be identified at runtime, but these tools require significant changes to the codebase to function effectively
Solution Approach 1:
The patent introduces an intermediary analysis module that sits between the application code and the runtime execution. This module uses aspect-oriented programming to intercept method invocations without requiring changes to the original business logic. The intermediary captures invocation data and passes it to the dead code identification logic, enabling dynamic analysis while preserving code integrity
Solution Approach 2:
The pointcut process implemented through aspect-oriented programming serves multiple functions: it monitors method invocations, captures invocation data, updates the analysis state, and identifies dead code. This universal mechanism handles all method call tracking across the entire codebase through a single reusable framework, reducing overall system complexity
3Ease of manufacture
If comprehensive code analysis is performed to identify all dead code, then code maintainability improves, but build time and team productivity decrease due to slowed builds
Solution Approach 1:
The system performs dead code analysis periodically based on trigger events such as build completion or deployment milestones rather than continuously during every compilation step. This periodic execution reduces the frequency of analysis operations, maintaining code quality insights while minimizing the impact on build throughput and developer productivity
Data Source
AI summary
Various methods, apparatuses/systems, and media for dynamic code analysis using aspect oriented programming (AOP) are disclosed. A processor (i) creates a list of all method names associated with an application before launching the application and writes into a file; (ii) at runtime, reads the method names from the file into a hash set and using AOP load time weaving, each time a method is invoked, pointcut around the execution of the method to remove method name from the hash set in memory; (iii) periodically overwrites the file with a dump of current entries in the hash set for fault tolerance; (iv) for every subsequent restart of the application, the processor repeats from processes (ii) and (iii). After running processes (i)-(iv) for a predetermined time period (a month, a quarter etc.), the processor creates a final with methods that have not been invoked for potential deletion.


