-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathInstrumentationExample.java
More file actions
68 lines (54 loc) · 1.4 KB
/
InstrumentationExample.java
File metadata and controls
68 lines (54 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class InstrumentationExample {
public static void printObjectSize(Object object) {
System.out.println("Object type: " + object.getClass() +
", size: " + InstrumentationAgent.getObjectSize(object) + " bytes");
}
public static void main(String[] arguments) {
class Person {
String name;
int age;
long phone;
boolean female;
byte[] password = {1, 2, 3, 4};
}
Person p = new Person();
int[] a0 = {};
int[] a1 = {1};
int[] a2 = {1, 2};
int[] a3 = new int[100];
String[] b0 = {};
String[] b1 = {"1"};
String[] b2 = {"1", "2"};
String[] b3 = new String[100];
String s0 = "";
String s1 = "hello";
List<Person> al0 = new ArrayList<>(0);
List<Person> al1 = new ArrayList<>(1);
al1.add(new Person());
List<Person> al2 = new ArrayList<>(2);
al2.add(new Person());
al2.add(new Person());
List<Person> al3 = new ArrayList<>(100);
for (int i = 0; i < 100; i++) {
al3.add(new Person());
}
printObjectSize(p);
printObjectSize(a0);
printObjectSize(a1);
printObjectSize(a2);
printObjectSize(a3);
printObjectSize(b0);
printObjectSize(b1);
printObjectSize(b2);
printObjectSize(b3);
printObjectSize(al0);
printObjectSize(al1);
printObjectSize(al2);
printObjectSize(al3);
printObjectSize(s0);
printObjectSize(s1);
}
}