< prev index next >

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

Print this page
rev 47591 : [mq]: heap10a
rev 47593 : [mq]: heap15


  38     }
  39   }
  40 
  41   private static int g_tmp[];
  42 
  43   /** Enable heap monitoring sampling given a rate and maximum garbage to keep in memory. */
  44   public native static void enableSampling(int rate, int maximumGarbage);
  45 
  46   /** Enable heap monitoring sampling given a rate. */
  47   public static void enableSampling(int rate) {
  48     enableSampling(rate, 200);
  49   }
  50 
  51   /** Enable heap monitoring sampling with default values for rate and maximum garbage. */
  52   public static void enableSampling() {
  53     enableSampling(1 << 19);
  54   }
  55 
  56   public native static void disableSampling();
  57   public native static boolean areSamplingStatisticsZero();

  58 
  59   /** Do the frames provided exist in live, recent garbage, and frequent garbage. */
  60   public native static boolean framesExistEverywhere(Frame[] frames);
  61   /** Do the frames provided not exist in live, recent garbage, and frequent garbage. */
  62   public native static boolean framesExistNowhere(Frame[] frames);
  63 
  64   /**
  65    * Allocate memory but first create a stack trace of a particular depth.
  66    *
  67    * @return list of frames for the allocation.
  68    */
  69   public static List<Frame> allocate(int depth) {
  70     List<Frame> frames = new ArrayList<Frame>();
  71     if (depth > 1) {
  72       createStackDepth(depth - 1, frames);
  73       frames.add(new Frame("allocate", "(I)Ljava/util/List;", "HeapMonitor.java", 72));
  74     } else {
  75       actuallyAllocate(frames);
  76       frames.add(new Frame("actuallyAllocate", "(Ljava/util/List;)I", "HeapMonitor.java", 118));
  77       frames.add(new Frame("allocate", "(I)Ljava/util/List;", "HeapMonitor.java", 75));
  78     }
  79     return frames;
  80   }
  81 
  82   /**
  83    * Allocate memory but first create a stack trace.
  84    *
  85    * @return list of frames for the allocation.
  86    */
  87   public static List<Frame> allocate() {
  88     int sum = 0;
  89     List<Frame> frames = new ArrayList<Frame>();
  90     allocate(frames);
  91     frames.add(new Frame("allocate", "()Ljava/util/List;", "HeapMonitor.java", 90));
  92     return frames;
  93   }
  94 
  95   private static void createStackDepth(int depth, List<Frame> frames) {
  96     if (depth > 1) {
  97       createStackDepth(depth - 1, frames);
  98       frames.add(new Frame("createStackDepth", "(ILjava/util/List;)V", "HeapMonitor.java", 97));
  99     } else {
 100       allocate(frames);
 101       frames.add(new Frame("createStackDepth", "(ILjava/util/List;)V", "HeapMonitor.java", 100));
 102     }
 103   }
 104 
 105   private static void allocate(List<Frame> frames) {
 106     int sum = 0;
 107     for (int j = 0; j < 1000; j++) {
 108       sum += actuallyAllocate(frames);
 109     }
 110     frames.add(new Frame("actuallyAllocate", "(Ljava/util/List;)I", "HeapMonitor.java", 118));
 111     frames.add(new Frame("allocate", "(Ljava/util/List;)V", "HeapMonitor.java", 108));
 112   }
 113 
 114   private static int actuallyAllocate(List<Frame> frames) {
 115     int sum = 0;
 116     // Let us assume that the array is 24 bytes of memory.
 117     for (int i = 0; i < 127000 / 6; i++) {
 118       int tmp[] = new int[1];
 119       // Force it to be kept.
 120       g_tmp = tmp;
 121       sum += g_tmp[0];
 122     }
 123     return sum;
 124   }
 125 }


  38     }
  39   }
  40 
  41   private static int g_tmp[];
  42 
  43   /** Enable heap monitoring sampling given a rate and maximum garbage to keep in memory. */
  44   public native static void enableSampling(int rate, int maximumGarbage);
  45 
  46   /** Enable heap monitoring sampling given a rate. */
  47   public static void enableSampling(int rate) {
  48     enableSampling(rate, 200);
  49   }
  50 
  51   /** Enable heap monitoring sampling with default values for rate and maximum garbage. */
  52   public static void enableSampling() {
  53     enableSampling(1 << 19);
  54   }
  55 
  56   public native static void disableSampling();
  57   public native static boolean areSamplingStatisticsZero();
  58   public native static boolean statsHaveExpectedNumberSamples(int expected, int percentError);
  59 
  60   /** Do the frames provided exist in live, recent garbage, and frequent garbage. */
  61   public native static boolean framesExistEverywhere(Frame[] frames);
  62   /** Do the frames provided not exist in live, recent garbage, and frequent garbage. */
  63   public native static boolean framesExistNowhere(Frame[] frames);
  64 
  65   /**
  66    * Allocate memory but first create a stack trace of a particular depth.
  67    *
  68    * @return list of frames for the allocation.
  69    */
  70   public static List<Frame> allocate(int depth) {
  71     List<Frame> frames = new ArrayList<Frame>();
  72     if (depth > 1) {
  73       createStackDepth(depth - 1, frames);
  74       frames.add(new Frame("allocate", "(I)Ljava/util/List;", "HeapMonitor.java", 73));
  75     } else {
  76       actuallyAllocate(frames);
  77       frames.add(new Frame("actuallyAllocate", "(Ljava/util/List;)I", "HeapMonitor.java", 119));
  78       frames.add(new Frame("allocate", "(I)Ljava/util/List;", "HeapMonitor.java", 76));
  79     }
  80     return frames;
  81   }
  82 
  83   /**
  84    * Allocate memory but first create a stack trace.
  85    *
  86    * @return list of frames for the allocation.
  87    */
  88   public static List<Frame> allocate() {
  89     int sum = 0;
  90     List<Frame> frames = new ArrayList<Frame>();
  91     allocate(frames);
  92     frames.add(new Frame("allocate", "()Ljava/util/List;", "HeapMonitor.java", 91));
  93     return frames;
  94   }
  95 
  96   private static void createStackDepth(int depth, List<Frame> frames) {
  97     if (depth > 1) {
  98       createStackDepth(depth - 1, frames);
  99       frames.add(new Frame("createStackDepth", "(ILjava/util/List;)V", "HeapMonitor.java", 98));
 100     } else {
 101       allocate(frames);
 102       frames.add(new Frame("createStackDepth", "(ILjava/util/List;)V", "HeapMonitor.java", 101));
 103     }
 104   }
 105 
 106   private static void allocate(List<Frame> frames) {
 107     int sum = 0;
 108     for (int j = 0; j < 1000; j++) {
 109       sum += actuallyAllocate(frames);
 110     }
 111     frames.add(new Frame("actuallyAllocate", "(Ljava/util/List;)I", "HeapMonitor.java", 119));
 112     frames.add(new Frame("allocate", "(Ljava/util/List;)V", "HeapMonitor.java", 109));
 113   }
 114 
 115   private static int actuallyAllocate(List<Frame> frames) {
 116     int sum = 0;
 117     // Let us assume that the array is 24 bytes of memory.
 118     for (int i = 0; i < 127000 / 6; i++) {
 119       int tmp[] = new int[1];
 120       // Force it to be kept.
 121       g_tmp = tmp;
 122       sum += g_tmp[0];
 123     }
 124     return sum;
 125   }
 126 }
< prev index next >