< prev index next >
test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorThreadTest.java
Print this page
rev 49267 : [mq]: event5
rev 49268 : [mq]: event6
rev 49269 : [mq]: event7
@@ -41,11 +41,10 @@
final int numThreads = 24;
ArrayList<Thread> list = new ArrayList<>();
// Remember a lot of garbage to have space for all thread samples.
HeapMonitor.enableSamplingEvents();
- HeapMonitor.setGarbageHistory(10000);
for (int i = 0 ; i < numThreads; i++) {
Thread thread = new Thread(new Allocator(i), "Allocator" + i);
thread.start();
list.add(thread);
@@ -65,38 +64,41 @@
}
}
class Allocator implements Runnable {
private int depth;
- private volatile int tmp[];
+ private List<int[]> currentList;
public Allocator(int depth) {
this.depth = depth;
}
- private int helper() {
- int sum = 0;
- // Let us assume that the array is 24 bytes of memory.
- for (int i = 0; i < 127000 / 6; i++) {
+ private void helper() {
+ List<int[]> newList = new ArrayList<>();
+ // Let us assume that the array is 24 bytes of memory, by default we sample at 512k, keep in
+ // memory at least 2MB without counting the link-list itself, which adds to this.
+ int iterations = (1 << 21) / 24;
+ for (int i = 0; i < iterations; i++) {
int newTmp[] = new int[1];
// Force it to be kept.
- tmp = newTmp;
- sum += tmp[0];
+ newList.add(newTmp);
}
- return sum;
+
+ // Replace old list with new list, which provokes two things:
+ // Old list will get GC'd at some point.
+ // New list forces that this thread has some allocations still sampled.
+ currentList = newList;
}
- private int recursiveWrapper(int depth) {
+ private void recursiveWrapper(int depth) {
if (depth > 0) {
- return recursiveWrapper(depth - 1);
+ recursiveWrapper(depth - 1);
}
- return helper();
+ helper();
}
public void run() {
- int sum = 0;
for (int j = 0; j < 50; j++) {
- sum += recursiveWrapper(depth);
+ recursiveWrapper(depth);
}
- System.out.println(sum);
}
}
< prev index next >