@@ -68,30 +68,33 @@ public static void main(String[] args) throws Exception {
68
68
69
69
final Random rand = new Random (1L );
70
70
71
- long sizeLeak1 , sizeLeak2 , sizeLeak3 ;
71
+ long sizeLeak1 = -1 ;
72
+ long sizeLeak2 = -1 ;
73
+ long sizeLeak3 = -1 ;
72
74
73
75
do {
74
- sizeLeak1 = -1 ;
75
- sizeLeak2 = -1 ;
76
- sizeLeak3 = -1 ;
77
-
78
76
try (Recording recording = new Recording ()) {
79
77
leak .clear ();
80
78
recording .enable (EventNames .OldObjectSample ).withStackTrace ().with ("cutoff" , "infinity" );
81
79
recording .start ();
82
80
83
81
for (int i = 0 ; i < 1000 ; i ++) {
84
- switch (rand .nextInt (3 )) {
85
- case 0 : leak .add (new Leak1 ()); break ;
86
- case 1 : leak .add (new Leak2 ()); break ;
87
- case 2 : leak .add (new Leak3 ()); break ;
82
+ if (sizeLeak1 == -1 ) {
83
+ leak .add (new Leak1 ());
84
+ continue ;
85
+ }
86
+ if (sizeLeak2 == -1 ) {
87
+ leak .add (new Leak2 ());
88
+ continue ;
89
+ }
90
+ if (sizeLeak3 == -1 ) {
91
+ leak .add (new Leak3 ());
88
92
}
89
93
}
90
94
91
95
recording .stop ();
92
96
93
97
List <RecordedEvent > events = Events .fromRecording (recording );
94
- Events .hasEvents (events );
95
98
for (RecordedEvent e : events ) {
96
99
RecordedObject object = e .getValue ("object" );
97
100
RecordedClass type = object .getValue ("type" );
@@ -100,13 +103,13 @@ public static void main(String[] args) throws Exception {
100
103
if (objectSize <= 0 ) {
101
104
throw new Exception ("Object size for " + type .getName () + " is lower or equal to 0" );
102
105
}
103
- if (type .getName ().equals (Leak1 .class .getName ())) {
106
+ if (type .getName ().equals (Leak1 .class .getName ()) && sizeLeak1 == - 1 ) {
104
107
sizeLeak1 = objectSize ;
105
108
}
106
- if (type .getName ().equals (Leak2 .class .getName ())) {
109
+ if (type .getName ().equals (Leak2 .class .getName ()) && sizeLeak2 == - 1 ) {
107
110
sizeLeak2 = objectSize ;
108
111
}
109
- if (type .getName ().equals (Leak3 .class .getName ())) {
112
+ if (type .getName ().equals (Leak3 .class .getName ()) && sizeLeak3 == - 1 ) {
110
113
sizeLeak3 = objectSize ;
111
114
}
112
115
}
0 commit comments