A simple tool to examine Java methods at the bytecode level and offer basic optimization suggestions.
BAA inspects Java bytecode to gather information about methods, potentially helping developers understand their code at the bytecode level.
Basic metrics collected:
- Bytecode size
- Object allocations
- Method calls
- Boxing/unboxing operations
- Basic recursion detection
- Simple loop identification
java -jar baa.jar [options] [<target> | --target=<target>]
--help
- Show help message--method=<className>#<methodName>
- Analyze a specific method--output=json|text|csv
- Output format (default: text)--color=true|false
- Enable or disable colored output (default: true)--threshold=<value>
- Filter by footprint size (0-3)
Analyze a method in a class file:
java -jar baa.jar --method=com.example.Service#processRequest target/classes/com/example/Service.class
Analyze with JSON output:
java -jar baa.jar --method=com.example.Service#processRequest --output=json app.jar
Export to CSV:
java -jar baa.jar --output=csv app.jar > results.csv
Analysis Report for 1 methods
================================================================================
Method: Baa#main([Ljava/lang/String;)V
Overall footprint rating: CRITICAL
============================================================
METRICS:
Bytecode size: 60 bytes
Allocations: 1
Types:
- Baa
External calls: 10
Calls to (first 5):
- Baa#parseOptions
- Map#isEmpty
- Map#containsKey
- PrintStream#println
- Map#get
- ... and 5 more
Boxing operations: 0
Recursion detected: 3 recursive call patterns
Details:
- call to method in same class: Baa#parseOptions
- call to method in same class: Baa#<init>
- call to method in same class: Baa#run
OPTIMIZATION SUGGESTIONS:
• Consider rewriting mutual recursion as iteration to improve performance and reduce stack usage
Impact: High
================================================================================
End of Report
mvn clean package
Creates a JAR file in the target
directory.
- Reads class files using ASM bytecode library
- Examines bytecode instructions for basic metrics
- Attempts to identify loops through backward jumps
- Tries to detect simple recursive patterns
- Generates basic suggestions based on findings
- Formats results as requested
- Basic allocation detection
- Simple method call tracking
- Boxing/unboxing identification
- Limited recursion detection
- Basic loop identification
- Multiple output formats
- Cannot estimate loop bounds
- No inter-method analysis
- Suggestions may not improve actual performance
- Very basic data flow analysis
- May miss complex patterns
- Improved control flow analysis
- Better data flow tracking
- More accurate method call cost estimation
- Exception handler examination
- Memory access pattern detection
- Basic escape analysis
- Loop bound estimation where possible
- IDE integration
Licensed under the BSD License. See the LICENSE file for details.
ASM is licensed under the BSD license. See the ASM License for details.