27 import java.util.ArrayList; |
27 import java.util.ArrayList; |
28 |
28 |
29 import sun.hotspot.WhiteBox; |
29 import sun.hotspot.WhiteBox; |
30 import sun.hotspot.code.BlobType; |
30 import sun.hotspot.code.BlobType; |
31 import com.oracle.java.testlibrary.Asserts; |
31 import com.oracle.java.testlibrary.Asserts; |
|
32 import com.oracle.java.testlibrary.InfiniteLoop; |
32 |
33 |
33 /* |
34 /* |
34 * @test AllocationCodeBlobTest |
35 * @test AllocationCodeBlobTest |
35 * @bug 8059624 |
36 * @bug 8059624 8064669 |
36 * @library /testlibrary /testlibrary/whitebox |
37 * @library /testlibrary /testlibrary/whitebox |
37 * @build AllocationCodeBlobTest |
38 * @build AllocationCodeBlobTest |
38 * @run main ClassFileInstaller sun.hotspot.WhiteBox |
39 * @run main ClassFileInstaller sun.hotspot.WhiteBox |
39 * sun.hotspot.WhiteBox$WhiteBoxPermission |
40 * sun.hotspot.WhiteBox$WhiteBoxPermission |
40 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions |
41 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions |
51 = WHITE_BOX.getUintxVMFlag("ReservedCodeCacheSize"); |
52 = WHITE_BOX.getUintxVMFlag("ReservedCodeCacheSize"); |
52 private static final int SIZE = 1; |
53 private static final int SIZE = 1; |
53 |
54 |
54 public static void main(String[] args) { |
55 public static void main(String[] args) { |
55 // check that Sweeper handels dummy blobs correctly |
56 // check that Sweeper handels dummy blobs correctly |
56 new ForcedSweeper(500).start(); |
57 Thread t = new Thread( |
|
58 new InfiniteLoop(WHITE_BOX::forceNMethodSweep, 1L), |
|
59 "ForcedSweeper"); |
|
60 t.setDaemon(true); |
|
61 System.out.println("Starting " + t.getName()); |
|
62 t.start(); |
|
63 |
57 EnumSet<BlobType> blobTypes = BlobType.getAvailable(); |
64 EnumSet<BlobType> blobTypes = BlobType.getAvailable(); |
58 for (BlobType type : blobTypes) { |
65 for (BlobType type : blobTypes) { |
59 new AllocationCodeBlobTest(type).test(); |
66 new AllocationCodeBlobTest(type).test(); |
60 } |
67 } |
|
68 |
|
69 // check that deoptimization works well w/ dummy blobs |
|
70 t = new Thread( |
|
71 new InfiniteLoop(WHITE_BOX::deoptimizeAll, 1L), |
|
72 "Deoptimize Thread"); |
|
73 t.setDaemon(true); |
|
74 System.out.println("Starting " + t.getName()); |
|
75 t.start(); |
|
76 |
|
77 for (int i = 0; i < 10_000; ++i) { |
|
78 for (BlobType type : blobTypes) { |
|
79 long addr = WHITE_BOX.allocateCodeBlob(SIZE, type.id); |
|
80 } |
|
81 } |
|
82 |
61 } |
83 } |
62 |
84 |
63 private final BlobType type; |
85 private final BlobType type; |
64 private final MemoryPoolMXBean bean; |
86 private final MemoryPoolMXBean bean; |
65 private AllocationCodeBlobTest(BlobType type) { |
87 private AllocationCodeBlobTest(BlobType type) { |
103 } |
125 } |
104 |
126 |
105 private long getUsage() { |
127 private long getUsage() { |
106 return bean.getUsage().getUsed(); |
128 return bean.getUsage().getUsed(); |
107 } |
129 } |
108 |
|
109 private static class ForcedSweeper extends Thread { |
|
110 private final int millis; |
|
111 public ForcedSweeper(int millis) { |
|
112 super("ForcedSweeper"); |
|
113 setDaemon(true); |
|
114 this.millis = millis; |
|
115 } |
|
116 public void run() { |
|
117 try { |
|
118 while (true) { |
|
119 WHITE_BOX.forceNMethodSweep(); |
|
120 Thread.sleep(millis); |
|
121 } |
|
122 } catch (InterruptedException e) { |
|
123 Thread.currentThread().interrupt(); |
|
124 throw new Error(e); |
|
125 } |
|
126 } |
|
127 } |
|
128 } |
130 } |