Sparkles

that were shone when I got tempered!

Measuring Memory of JAVA objects

leave a comment »

Build the JAMM Master Project.

This project includes all the implemnetation to measure the memoory of the Java Objects. We are going to build it and package it to a jar file so that we can use in our client to do memory measurements.

1. Get the jeblis-jamm client project from here.

2. Build it and package it to a jar file.

3. Specify the org.github.jamm.MemoryMeter class as the Premain-Class in jar file’s MANIFEST.MF.

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: namal
Build-Jdk: 1.7.0_03
Premain-Class: org.github.jamm.MemoryMeter

Now your jar is ready to use (jamm-0.3.2-SNAPSHOT.jar).

I have added my project also built using above steps in here.

Build the JAMM Client Project.

1. Create a new JAVA project and add the JAMM-Master jar file built in above step.

TestMemory.java


public class TestMemory {

public static void main(String[] args) {

String str = "Namal Fernando";

ArrayList<String> strList = new ArrayList<String>();
strList.add(str);
strList.add(str+"1");
strList.add(str+"2");
strList.add(str+"3");
strList.add(str+"4");

MemoryMeter memoryMeter = new MemoryMeter().enableDebug();
System.out.println("main().General Measure : " + memoryMeter.measure(strList));
System.out.println("main().Deep Measure : " + memoryMeter.measureDeep(strList));
System.out.println("main().Count Child : " + memoryMeter.countChildren(strList));

}

}

2. Run the TestMemory class giving the below VM Arguments to point the JAMM-Master jar file (jamm-0.3.2-SNAPSHOT.jar) built in above step as javaagent for memory measurement.

-javaagent:/rezsystem/workspace/jamm-client/lib/jamm-0.3.2-SNAPSHOT.jar

Output will be looked like this.

main().General Measure : 24

root [java.util.ArrayList] 432 bytes (24 bytes)
|
+–elementData [java.lang.Object[]] 408 bytes (56 bytes)
|
+–0 [java.lang.String] 64 bytes (24 bytes)
| |
| +–value [char[]] 40 bytes (40 bytes)
|
+–1 [java.lang.String] 72 bytes (24 bytes)
| |
| +–value [char[]] 48 bytes (48 bytes)
|
+–2 [java.lang.String] 72 bytes (24 bytes)
| |
| +–value [char[]] 48 bytes (48 bytes)
|
+–3 [java.lang.String] 72 bytes (24 bytes)
| |
| +–value [char[]] 48 bytes (48 bytes)
|
+–4 [java.lang.String] 72 bytes (24 bytes)
|
+–value [char[]] 48 bytes (48 bytes)

main().Deep Measure : 432

root [java.util.ArrayList]
|
+–elementData [java.lang.Object[]]
|
+–0 [java.lang.String]
| |
| +–value [char[]]
|
+–1 [java.lang.String]
| |
| +–value [char[]]
|
+–2 [java.lang.String]
| |
| +–value [char[]]
|
+–3 [java.lang.String]
| |
| +–value [char[]]
|
+–4 [java.lang.String]
|
+–value [char[]]

main().Count Child : 12

This JAMM Client Project is available in here.

Advertisements

Written by Namal Fernando

December 23, 2015 at 8:56 am

Posted in Java, Performance

Tagged with , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Ruth's Reflections

Contemplations from quakey quirky Christchurch

TED Blog

The TED Blog shares interesting news about TED, TED Talks video, the TED Prize and more.

Ziplok

Learn and discover simple things

Meihta Dwiguna Saputra's Knowledge Base

~In learning you will teach and in teaching you will (re)learn~

The Java Blog

Thoughts, tips and tricks about the Java programming language

Sparkles

that were shone when I got tempered!

%d bloggers like this: