42
43 /**
44 * Test for events: vm/code_sweeper/sweep vm/code_cache/full vm/compiler/failure
45 *
46 * We verify: 1. That sweptCount >= flushedCount + zombifiedCount 2. That
47 * sweepIndex increases by 1. 3. We should get at least one of each of the
48 * events listed above.
49 *
50 * NOTE! The test is usually able to trigger the events but not always. If an
51 * event is received, the event is verified. If an event is missing, we do NOT
52 * fail.
53 */
54 /**
55 * @test TestCodeSweeper
56 * @key jfr
57 *
58 * @library /lib /
59 * @build sun.hotspot.WhiteBox
60 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
61 * sun.hotspot.WhiteBox$WhiteBoxPermission
62 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:-SegmentedCodeCache -XX:+WhiteBoxAPI jdk.jfr.event.compiler.TestCodeSweeper
63 */
64
65 public class TestCodeSweeper {
66 private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
67 private static final int COMP_LEVEL_SIMPLE = 1;
68 private static final int COMP_LEVEL_FULL_OPTIMIZATION = 4;
69 private static final int SIZE = 1;
70 private static final String METHOD_NAME = "verifyFullEvent";
71 private static final String pathSweep = EventNames.SweepCodeCache;
72 private static final String pathFull = EventNames.CodeCacheFull;
73 private static final String pathFailure = EventNames.CompilationFailure;
74 public static final long SEGMENT_SIZE = WhiteBox.getWhiteBox().getUintxVMFlag("CodeCacheSegmentSize");
75 public static final long MIN_BLOCK_LENGTH = WhiteBox.getWhiteBox().getUintxVMFlag("CodeCacheMinBlockLength");
76 public static final long MIN_ALLOCATION = SEGMENT_SIZE * MIN_BLOCK_LENGTH;
77 private static final double CACHE_USAGE_COEF = 0.95d;
78
79 public static void main(String[] args) throws Throwable {
80 Asserts.assertTrue(BlobType.getAvailable().contains(BlobType.All), "Test does not support SegmentedCodeCache");
81
82 System.out.println("************************************************");
142 long minAllocationUnit = Math.max(1, MIN_ALLOCATION - headerSize);
143 long stopAt = max - minAllocationUnit;
144 long addr = 0;
145
146 // First allocate big blobs to speed things up
147 for (long size = 100_000 * minAllocationUnit; size > 0; size /= 10) {
148 while (canAllocate(size, max, bean) &&
149 (addr = WHITE_BOX.allocateCodeBlob(size, BlobType.All.id)) != 0) {
150 blobs.add(addr);
151 }
152 }
153
154 // Now allocate small blobs until the heap is almost full
155 while (bean.getUsage().getUsed() < stopAt &&
156 (addr = WHITE_BOX.allocateCodeBlob(SIZE, BlobType.All.id)) != 0) {
157 blobs.add(addr);
158 }
159
160 // Trigger the vm/code_cache/full event by compiling one more
161 // method. This also triggers the vm/compiler/failure event.
162 Asserts.assertTrue(WHITE_BOX.addCompilerDirective(directive) == 1);
163 try {
164 if (!WHITE_BOX.enqueueMethodForCompilation(method, COMP_LEVEL_FULL_OPTIMIZATION)) {
165 WHITE_BOX.enqueueMethodForCompilation(method, COMP_LEVEL_SIMPLE);
166 }
167 } finally {
168 WHITE_BOX.removeCompilerDirective(1);
169 }
170
171 // Free memory
172 for (Long blob : blobs) {
173 WHITE_BOX.freeCodeBlob(blob);
174 }
175 }
176
177 private static void verifyFullEvent(RecordedEvent event) throws Throwable {
178 Events.assertField(event, "codeBlobType").notEmpty();
179 Events.assertField(event, "unallocatedCapacity").atLeast(0L);
180 Events.assertField(event, "entryCount").atLeast(0);
181 Events.assertField(event, "methodCount").atLeast(0);
182 Events.assertField(event, "adaptorCount").atLeast(0);
183 Events.assertField(event, "fullCount").atLeast(0);
184
185 // Verify startAddress <= commitedTopAddress <= reservedTopAddress.
186 // Addresses may be so big that they overflow a long (treated as a
187 // negative value), convert value to an octal string and compare the
188 // string.
189 String startAddress = Long.toOctalString(Events.assertField(event, "startAddress").getValue());
|
42
43 /**
44 * Test for events: vm/code_sweeper/sweep vm/code_cache/full vm/compiler/failure
45 *
46 * We verify: 1. That sweptCount >= flushedCount + zombifiedCount 2. That
47 * sweepIndex increases by 1. 3. We should get at least one of each of the
48 * events listed above.
49 *
50 * NOTE! The test is usually able to trigger the events but not always. If an
51 * event is received, the event is verified. If an event is missing, we do NOT
52 * fail.
53 */
54 /**
55 * @test TestCodeSweeper
56 * @key jfr
57 *
58 * @library /lib /
59 * @build sun.hotspot.WhiteBox
60 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
61 * sun.hotspot.WhiteBox$WhiteBoxPermission
62 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI jdk.jfr.event.compiler.TestCodeSweeper
63 */
64
65 public class TestCodeSweeper {
66 private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
67 private static final int COMP_LEVEL_SIMPLE = 1;
68 private static final int COMP_LEVEL_FULL_OPTIMIZATION = 4;
69 private static final int SIZE = 1;
70 private static final String METHOD_NAME = "verifyFullEvent";
71 private static final String pathSweep = EventNames.SweepCodeCache;
72 private static final String pathFull = EventNames.CodeCacheFull;
73 private static final String pathFailure = EventNames.CompilationFailure;
74 public static final long SEGMENT_SIZE = WhiteBox.getWhiteBox().getUintxVMFlag("CodeCacheSegmentSize");
75 public static final long MIN_BLOCK_LENGTH = WhiteBox.getWhiteBox().getUintxVMFlag("CodeCacheMinBlockLength");
76 public static final long MIN_ALLOCATION = SEGMENT_SIZE * MIN_BLOCK_LENGTH;
77 private static final double CACHE_USAGE_COEF = 0.95d;
78
79 public static void main(String[] args) throws Throwable {
80 Asserts.assertTrue(BlobType.getAvailable().contains(BlobType.All), "Test does not support SegmentedCodeCache");
81
82 System.out.println("************************************************");
142 long minAllocationUnit = Math.max(1, MIN_ALLOCATION - headerSize);
143 long stopAt = max - minAllocationUnit;
144 long addr = 0;
145
146 // First allocate big blobs to speed things up
147 for (long size = 100_000 * minAllocationUnit; size > 0; size /= 10) {
148 while (canAllocate(size, max, bean) &&
149 (addr = WHITE_BOX.allocateCodeBlob(size, BlobType.All.id)) != 0) {
150 blobs.add(addr);
151 }
152 }
153
154 // Now allocate small blobs until the heap is almost full
155 while (bean.getUsage().getUsed() < stopAt &&
156 (addr = WHITE_BOX.allocateCodeBlob(SIZE, BlobType.All.id)) != 0) {
157 blobs.add(addr);
158 }
159
160 // Trigger the vm/code_cache/full event by compiling one more
161 // method. This also triggers the vm/compiler/failure event.
162 if (!WHITE_BOX.enqueueMethodForCompilation(method, COMP_LEVEL_FULL_OPTIMIZATION)) {
163 WHITE_BOX.enqueueMethodForCompilation(method, COMP_LEVEL_SIMPLE);
164 }
165
166 Thread.sleep(5000);
167
168 // Free memory
169 for (Long blob : blobs) {
170 WHITE_BOX.freeCodeBlob(blob);
171 }
172 }
173
174 private static void verifyFullEvent(RecordedEvent event) throws Throwable {
175 Events.assertField(event, "codeBlobType").notEmpty();
176 Events.assertField(event, "unallocatedCapacity").atLeast(0L);
177 Events.assertField(event, "entryCount").atLeast(0);
178 Events.assertField(event, "methodCount").atLeast(0);
179 Events.assertField(event, "adaptorCount").atLeast(0);
180 Events.assertField(event, "fullCount").atLeast(0);
181
182 // Verify startAddress <= commitedTopAddress <= reservedTopAddress.
183 // Addresses may be so big that they overflow a long (treated as a
184 // negative value), convert value to an octal string and compare the
185 // string.
186 String startAddress = Long.toOctalString(Events.assertField(event, "startAddress").getValue());
|