Skip to content

Estimates the memory size of parameters passed to Java methods using static analysis and runtime instrumentation. Supports input from Dependency Finder and a custom method scanner to ensure complete method coverage for microservice decomposition and performance analysis.

Notifications You must be signed in to change notification settings

TasnimFabiha/java-param-size-estimator

Repository files navigation

Java Method Parameter Size Estimation Tool

This project estimates the sizes of parameters passed to Java methods using method signature information from:

  • A {project}.xml file generated by Dependency Finder, and
  • A fully-qualified-methods.txt file generated by the java-method-scanner, which extracts all project-defined methods using ClassGraph, ensuring better coverage.

The size estimation is performed using the Java Instrumentation API, and the results can be used to compute network overhead, particularly for tools like toMicroservice.


📁 Project Structure

.
├── agent/
│   ├── Agent.java
│   ├── SizeTester.java
│   ├── MANIFEST.MF
│   ├── agent.jar                # Compiled Java agent
├── projects/
│   └── roller/
│       ├── roller.xml           # Dependency Finder output
│       ├── fully-qualified-methods.txt        # List of project-defined method signatures
│       ├── type_list.txt        # Generated list of parameter types
│       ├── type_size_output.csv # Output from Java agent with sizes
│       ├── method_parameters_sizeOf.csv # Final mapping of method to param sizes
│       ├── pom.xml # Required to include runtime maven dependencies
│       └── target/
│           ├── classes/                 # Required for loading project-specific classes
│           ├── dependency/              # Required for saving mvn runtime dependency
│           ├── roller.war               # Required for extracting dependencies
│           └── roller-war-extracted/    # Extracted classes and dependencies from roller.war
├── estimate_param_sizes.py      # Python script to run the estimation process
└── README.md                    # This file

🛠 Setup Instructions

1. Compile the Java Agent

cd agent
javac Agent.java SizeTester.java
jar cmf MANIFEST.MF agent.jar Agent.class SizeTester.class

Make sure your MANIFEST.MF contains:

Manifest-Version: 1.0
Main-Class: Agent

2. Prepare Input

Either one or both of the following inputs are needed:

  • <project_name>.xml: generated by Dependency Finder (may skip some classes for missing run-time dependencies)
  • fully-qualified-methods.txt: generated by java-method-scanner, which ensures complete coverage of all project-defined methods (those written in the codebase) and their parameters.

If estimating the size of project-specific methods is the main goal, then fully-qualified-methods.txtt alone is sufficient, and the Dependency Finder input can be safely omitted.

  1. Place fully-qualified-methods.txt (required) in projects/<project_name>/.
  2. Place the Dependency Finder output XML as: projects/<project_name>/<project_name>.xml
  3. Update the project_name variable in estimate_param_sizes.py accordingly.
  4. Extract the <project_name>.war file into projects/<project_name>/target/<project_name>-war-extracted/. This is necessary to access third-party dependency classes used by your application.
  5. Add the compiled classes to projects/<project_name>/target/classes. This is essential because it contains the compiled application-specific classes required to instantiate and estimate parameter sizes correctly.
  6. Add the pom.xml to projects/<project_name> This will help include all run time dependency (dependencies that are not compiled or packaged with the project) in the projects/<project_name>/target/dependency folder.

⚠️ Without the extracted WAR, or the <project_name>/target/classes or the pom.xml, the size estimator cannot resolve all classes used in method signatures, leading to fallbacks and reduced accuracy.

3. Run the Estimation

python estimate_param_sizes.py

The script will:

  1. Parse methods from fully-qualified-methods.txt and <project_name>.xml
  2. Extract parameter types
  3. Write unique types to type_list.txt
  4. Invoke the Java agent to compute size estimates
  5. Write final size results to method_parameters_sizeOf.csv

📄 Output Format

method_parameters_sizeOf.csv

Method Signature Parameter Types Param Sizes Total Param Size
com.foo.Bar(x,y) int, String 4, 64 68

✅ Use Cases

  • Estimating data transfer size for inter-method or inter-service communication
  • Enhancing microservice decomposition tools by factoring in network overhead
  • Static profiling of parameter-heavy methods

🧠 Notes

  • Unknown types are assigned a fallback size of -1 bytes.
  • Arrays are instantiated with length 1 during size estimation.
  • The method works statically — no application execution is required.

About

Estimates the memory size of parameters passed to Java methods using static analysis and runtime instrumentation. Supports input from Dependency Finder and a custom method scanner to ensure complete method coverage for microservice decomposition and performance analysis.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published