Skip to content

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

0 stars

Watchers

0 watching

Forks

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.
  • The rows of method_parameters_sizeOf.csv are written in sorted order of method signature, so every run gives the same file.1

Footnotes

  1. The committed method_parameters_sizeOf.csv files were generated when the rows were written in the iteration order of a Python set (list(set(...)) in estimate_param_sizes.py). That order changes from run to run (string hash randomisation), so the row order of the CSV was different each time. The rows themselves (signatures and sizes) are the same, but the order matters for overloaded methods: kiekerToMicroserviceLogParser looks up sizes by Class.method without parameter types (the Kieker graphs do not contain them), so when a method has several overloads, the size of the overload written last is used. With a different row order, an overloaded method can therefore get a slightly different size (e.g. 96 of the 4,861 Class.method keys of jforum on a regeneration). This is fixed by writing the rows with sorted(set(...)). The committed CSVs are the ones used for the log parser and toMicroservice results; regenerating them with the sorted order may change the sizes of some overloaded methods, so the log parser and toMicroservice should be rerun after regenerating them. ↩

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

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages