< prev index next >

test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitor.java

Print this page
rev 49244 : [mq]: event-only
rev 49246 : [mq]: event4
rev 49247 : [mq]: event5

@@ -49,10 +49,12 @@
     setSamplingRate(0);
   }
 
   /** Set a specific sampling rate, 0 turns off sampling. */
   public native static void setSamplingRate(int rate);
+  /** Set a specific garbage history buffer. */
+  public native static void setGarbageHistory(int amount);
 
   public native static void enableSamplingEvents();
   public native static void disableSamplingEvents();
 
   /**

@@ -62,15 +64,15 @@
    */
   public static List<Frame> allocate(int depth) {
     List<Frame> frames = new ArrayList<Frame>();
     if (depth > 1) {
       createStackDepth(depth - 1, frames);
-      frames.add(new Frame("allocate", "(I)Ljava/util/List;", "HeapMonitor.java", 61));
+      frames.add(new Frame("allocate", "(I)Ljava/util/List;", "HeapMonitor.java", 68));
     } else {
       actuallyAllocate();
-      frames.add(new Frame("actuallyAllocate", "()I", "HeapMonitor.java", 126));
-      frames.add(new Frame("allocate", "(I)Ljava/util/List;", "HeapMonitor.java", 64));
+      frames.add(new Frame("actuallyAllocate", "()I", "HeapMonitor.java", 131));
+      frames.add(new Frame("allocate", "(I)Ljava/util/List;", "HeapMonitor.java", 71));
     }
     return frames;
   }
 
   /**

@@ -80,39 +82,39 @@
    */
   public static List<Frame> allocate() {
     int sum = 0;
     List<Frame> frames = new ArrayList<Frame>();
     allocate(frames);
-    frames.add(new Frame("allocate", "()Ljava/util/List;", "HeapMonitor.java", 79));
+    frames.add(new Frame("allocate", "()Ljava/util/List;", "HeapMonitor.java", 86));
     return frames;
   }
 
   private static void createStackDepth(int depth, List<Frame> frames) {
     if (depth > 1) {
       createStackDepth(depth - 1, frames);
-      frames.add(new Frame("createStackDepth", "(ILjava/util/List;)V", "HeapMonitor.java", 86));
+      frames.add(new Frame("createStackDepth", "(ILjava/util/List;)V", "HeapMonitor.java", 93));
     } else {
       allocate(frames);
-      frames.add(new Frame("createStackDepth", "(ILjava/util/List;)V", "HeapMonitor.java", 89));
+      frames.add(new Frame("createStackDepth", "(ILjava/util/List;)V", "HeapMonitor.java", 96));
     }
   }
 
   private static void allocate(List<Frame> frames) {
     int sum = 0;
     for (int j = 0; j < 1000; j++) {
       sum += actuallyAllocate();
     }
-    frames.add(new Frame("actuallyAllocate", "()I", "HeapMonitor.java", 124));
-    frames.add(new Frame("allocate", "(Ljava/util/List;)V", "HeapMonitor.java", 97));
+    frames.add(new Frame("actuallyAllocate", "()I", "HeapMonitor.java", 131));
+    frames.add(new Frame("allocate", "(Ljava/util/List;)V", "HeapMonitor.java", 104));
   }
 
   public static List<Frame> repeatAllocate(int max) {
     List<Frame> frames = null;
     for (int i = 0; i < max; i++) {
       frames = allocate();
     }
-    frames.add(new Frame("repeatAllocate", "(I)Ljava/util/List;", "HeapMonitor.java", 106));
+    frames.add(new Frame("repeatAllocate", "(I)Ljava/util/List;", "HeapMonitor.java", 113));
     return frames;
   }
 
   private static int actuallyAllocate() {
     int sum = 0;

@@ -132,14 +134,45 @@
       sum += arrays[0][0];
     }
     return sum;
   }
 
+  public static int allocateSize(int totalSize) {
+    int sum = 0;
+
+    // Let us assume that a 1-element array is 24 bytes.
+    int iterations = totalSize / 24;
+
+    if (arrays == null) {
+      arrays = new int[iterations][];
+    }
+
+    System.out.println("Allocating for " + iterations);
+    for (int i = 0; i < iterations; i++) {
+      int tmp[] = new int[1];
+
+      // Force it to be kept and, at the same time, wipe out any previous data.
+      arrays[i] = tmp;
+      sum += arrays[0][0];
+    }
+
+    return sum;
+  }
+
   /** Remove the reference to the global array to free data at the next GC. */
   public static void freeStorage() {
     arrays = null;
   }
 
   public native static boolean obtainedEvents(Frame[] frames);
+  public native static boolean garbageContains(Frame[] frames);
   public native static boolean eventStorageIsEmpty();
   public native static void resetEventStorage();
+  public native static int getEventStorageElementCount();
+  public native static void forceGarbageCollection();
+
+  public static boolean statsHaveExpectedNumberSamples(int expected, int acceptedErrorPercentage) {
+    double actual = getEventStorageElementCount();
+    double diffPercentage = Math.abs(actual - expected) / expected;
+    return diffPercentage < acceptedErrorPercentage;
+  }
 }
< prev index next >