25
26 /**
27 * @test
28 * @build Frame HeapMonitor
29 * @summary Verifies the JVMTI Heap Monitor Thread sanity
30 * @compile HeapMonitorThreadTest.java
31 * @run main/othervm/native -agentlib:HeapMonitor MyPackage.HeapMonitorThreadTest
32 */
33
34 import java.util.ArrayList;
35 import java.util.List;
36
37 public class HeapMonitorThreadTest {
38 private native static boolean checkSamples(int numThreads);
39
40 public static void main(String[] args) {
41 final int numThreads = 24;
42 ArrayList<Thread> list = new ArrayList<>();
43
44 // Remember a lot of garbage to have space for all thread samples.
45 HeapMonitor.enableSamplingRate();
46 HeapMonitor.setGarbageHistory(10000);
47
48 for (int i = 0 ; i < numThreads; i++) {
49 Thread thread = new Thread(new Allocator(i), "Allocator" + i);
50 thread.start();
51 list.add(thread);
52 }
53
54 for (Thread elem : list) {
55 try {
56 elem.join();
57 } catch(InterruptedException e) {
58 throw new RuntimeException("Thread got interrupted...");
59 }
60 }
61
62 if (!checkSamples(numThreads)) {
63 throw new RuntimeException("Problem with checkSamples...");
64 }
65 }
|
25
26 /**
27 * @test
28 * @build Frame HeapMonitor
29 * @summary Verifies the JVMTI Heap Monitor Thread sanity
30 * @compile HeapMonitorThreadTest.java
31 * @run main/othervm/native -agentlib:HeapMonitor MyPackage.HeapMonitorThreadTest
32 */
33
34 import java.util.ArrayList;
35 import java.util.List;
36
37 public class HeapMonitorThreadTest {
38 private native static boolean checkSamples(int numThreads);
39
40 public static void main(String[] args) {
41 final int numThreads = 24;
42 ArrayList<Thread> list = new ArrayList<>();
43
44 // Remember a lot of garbage to have space for all thread samples.
45 HeapMonitor.enableSamplingEvents();
46 HeapMonitor.setGarbageHistory(10000);
47
48 for (int i = 0 ; i < numThreads; i++) {
49 Thread thread = new Thread(new Allocator(i), "Allocator" + i);
50 thread.start();
51 list.add(thread);
52 }
53
54 for (Thread elem : list) {
55 try {
56 elem.join();
57 } catch(InterruptedException e) {
58 throw new RuntimeException("Thread got interrupted...");
59 }
60 }
61
62 if (!checkSamples(numThreads)) {
63 throw new RuntimeException("Problem with checkSamples...");
64 }
65 }
|