Skip to content
/ baa Public

A simple tool to examine Java methods at the bytecode level and offer basic optimization suggestions.

License

Notifications You must be signed in to change notification settings

googlielmo/baa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BAA: Bytecode Analysis Assistant

A simple tool to examine Java methods at the bytecode level and offer basic optimization suggestions.

Overview

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

Usage

java -jar baa.jar [options] [<target> | --target=<target>]

Options

  • --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)

Examples

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

Sample Output

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

Building

mvn clean package

Creates a JAR file in the target directory.

How It Works

  1. Reads class files using ASM bytecode library
  2. Examines bytecode instructions for basic metrics
  3. Attempts to identify loops through backward jumps
  4. Tries to detect simple recursive patterns
  5. Generates basic suggestions based on findings
  6. Formats results as requested

Current Capabilities

  • Basic allocation detection
  • Simple method call tracking
  • Boxing/unboxing identification
  • Limited recursion detection
  • Basic loop identification
  • Multiple output formats

Limitations

  • Cannot estimate loop bounds
  • No inter-method analysis
  • Suggestions may not improve actual performance
  • Very basic data flow analysis
  • May miss complex patterns

Potential Future Work

  • 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

License

Licensed under the BSD License. See the LICENSE file for details.

ASM is licensed under the BSD license. See the ASM License for details.

About

A simple tool to examine Java methods at the bytecode level and offer basic optimization suggestions.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages