Skip to content

Commit 87a1af0

Browse files
committed
Added the Java Agent Example
1 parent 085ed68 commit 87a1af0

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.baeldung.objectsize;
2+
3+
public class InstrumentedSize {
4+
5+
public static void main(String[] args) {
6+
String ds = "Data Structures";
7+
Course course = new Course(ds);
8+
9+
System.out.println(ObjectSizeCalculator.sizeOf(course));
10+
}
11+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Premain-Class: com.baeldung.objectsize.ObjectSizeCalculator
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.objectsize;
2+
3+
import java.lang.instrument.Instrumentation;
4+
5+
public class ObjectSizeCalculator {
6+
7+
private static Instrumentation instrumentation;
8+
9+
public static void premain(String args, Instrumentation inst) {
10+
instrumentation = inst;
11+
}
12+
13+
public static long sizeOf(Object o) {
14+
return instrumentation.getObjectSize(o);
15+
}
16+
}

0 commit comments

Comments
 (0)