27
27
import java .lang .reflect .Method ;
28
28
import java .time .Instant ;
29
29
import java .util .ArrayList ;
30
- import java .util .Collections ;
31
30
import java .util .List ;
32
31
33
- import jdk .jfr .Event ;
34
- import jdk .jfr .consumer .RecordingStream ;
32
+ import jdk .jfr .Recording ;
35
33
import jdk .jfr .consumer .RecordedEvent ;
36
34
import jdk .test .lib .Asserts ;
37
35
import jdk .test .lib .jfr .EventNames ;
41
39
import jdk .test .whitebox .code .CodeBlob ;
42
40
43
41
/**
44
- * Test for events: jdk.CodeCacheFull jdk.CompilationFailure
42
+ * Test for events: vm/code_cache/full vm/compiler/failure
45
43
*
46
44
* We verify that we should get at least one of each of the events listed above.
47
45
*
60
58
*/
61
59
62
60
public class TestCodeSweeper {
63
- static class ProvocationEvent extends Event {
64
- }
65
61
private static final WhiteBox WHITE_BOX = WhiteBox .getWhiteBox ();
66
62
private static final int COMP_LEVEL_SIMPLE = 1 ;
67
63
private static final int COMP_LEVEL_FULL_OPTIMIZATION = 4 ;
68
64
private static final int SIZE = 1 ;
69
65
private static final String METHOD_NAME = "verifyFullEvent" ;
70
- private static final String EVENT_CODE_CACHE_FULL = EventNames .CodeCacheFull ;
71
- private static final String EVENT_COMPILATION_FAILURE = EventNames .CompilationFailure ;
66
+ private static final String pathFull = EventNames .CodeCacheFull ;
67
+ private static final String pathFailure = EventNames .CompilationFailure ;
72
68
public static final long SEGMENT_SIZE = WhiteBox .getWhiteBox ().getUintxVMFlag ("CodeCacheSegmentSize" );
73
69
public static final long MIN_BLOCK_LENGTH = WhiteBox .getWhiteBox ().getUintxVMFlag ("CodeCacheMinBlockLength" );
74
70
public static final long MIN_ALLOCATION = SEGMENT_SIZE * MIN_BLOCK_LENGTH ;
@@ -81,41 +77,26 @@ public static void main(String[] args) throws Throwable {
81
77
System .out .println ("This test will warn that the code cache is full." );
82
78
System .out .println ("That is expected and is the purpose of the test." );
83
79
System .out .println ("************************************************" );
84
- List <RecordedEvent > events = Collections .synchronizedList (new ArrayList <>());
85
- try (RecordingStream rs = new RecordingStream ()) {
86
- rs .setReuse (false );
87
- rs .enable (EVENT_CODE_CACHE_FULL );
88
- rs .enable (EVENT_COMPILATION_FAILURE );
89
- rs .onEvent (EVENT_CODE_CACHE_FULL , events ::add );
90
- rs .onEvent (EVENT_COMPILATION_FAILURE , events ::add );
91
- rs .onEvent (ProvocationEvent .class .getName (), e -> {
92
- if (!events .isEmpty ()) {
93
- rs .close ();
94
- return ;
95
- }
96
- // Retry if CodeCacheFull or CompilationFailure events weren't provoked
97
- try {
98
- provokeEvents ();
99
- } catch (Exception ex ) {
100
- ex .printStackTrace ();
101
- rs .close ();
102
- }
103
- });
104
- rs .startAsync ();
105
- provokeEvents ();
106
- rs .awaitTermination ();
107
- }
80
+
81
+ Recording r = new Recording ();
82
+ r .enable (pathFull );
83
+ r .enable (pathFailure );
84
+ r .start ();
85
+ provokeEvents ();
86
+ r .stop ();
108
87
109
88
int countEventFull = 0 ;
110
89
int countEventFailure = 0 ;
90
+
91
+ List <RecordedEvent > events = Events .fromRecording (r );
111
92
Events .hasEvents (events );
112
- for (RecordedEvent event : new ArrayList <>( events ) ) {
93
+ for (RecordedEvent event : events ) {
113
94
switch (event .getEventType ().getName ()) {
114
- case EVENT_CODE_CACHE_FULL :
95
+ case pathFull :
115
96
countEventFull ++;
116
97
verifyFullEvent (event );
117
98
break ;
118
- case EVENT_COMPILATION_FAILURE :
99
+ case pathFailure :
119
100
countEventFailure ++;
120
101
verifyFailureEvent (event );
121
102
break ;
@@ -134,8 +115,6 @@ private static boolean canAllocate(double size, long maxSize, MemoryPoolMXBean b
134
115
}
135
116
136
117
private static void provokeEvents () throws NoSuchMethodException , InterruptedException {
137
- System .out .println ("provokeEvents()" );
138
- ProvocationEvent provocationEvent = new ProvocationEvent ();
139
118
// Prepare for later, since we don't want to trigger any compilation
140
119
// setting this up.
141
120
Method method = TestCodeSweeper .class .getDeclaredMethod (METHOD_NAME , new Class [] { RecordedEvent .class });
@@ -180,7 +159,6 @@ private static void provokeEvents() throws NoSuchMethodException, InterruptedExc
180
159
for (Long blob : blobs ) {
181
160
WHITE_BOX .freeCodeBlob (blob );
182
161
}
183
- provocationEvent .commit ();
184
162
}
185
163
186
164
private static void verifyFullEvent (RecordedEvent event ) throws Throwable {
0 commit comments