< prev index next >

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

Print this page
rev 48552 : [mq]: heap10a
rev 48557 : [mq]: heap17


  56       } catch(InterruptedException e) {
  57         throw new RuntimeException("Thread got interrupted...");
  58       }
  59     }
  60 
  61     int[] threads = new int[numThreads];
  62     if (!checkSamples(threads)) {
  63       throw new RuntimeException("Problem with checkSamples...");
  64     }
  65 
  66     for (int elem : threads) {
  67       if (elem == 0) {
  68         throw new RuntimeException("Missing at least one thread in the array...");
  69       }
  70     }
  71   }
  72 }
  73 
  74 class Allocator implements Runnable {
  75   private int depth;
  76   private int g_tmp[];
  77 
  78   public Allocator(int depth) {
  79     this.depth = depth;
  80   }
  81 
  82   private int helper() {
  83     int sum = 0;
  84     // Let us assume that the array is 24 bytes of memory.
  85     for (int i = 0; i < 127000 / 6; i++) {
  86       int tmp[] = new int[1];
  87       // Force it to be kept.
  88       g_tmp = tmp;
  89       sum += g_tmp[0];
  90     }
  91     return sum;
  92   }
  93 
  94   private int recursiveWrapper(int depth) {
  95     if (depth > 0) {
  96       return recursiveWrapper(depth - 1);
  97     }
  98     return helper();
  99   }
 100 
 101   public void run() {
 102     int sum = 0;
 103     for (int j = 0; j < 50; j++) {
 104       sum += recursiveWrapper(depth);
 105     }
 106     System.out.println(sum);
 107   }
 108 }


  56       } catch(InterruptedException e) {
  57         throw new RuntimeException("Thread got interrupted...");
  58       }
  59     }
  60 
  61     int[] threads = new int[numThreads];
  62     if (!checkSamples(threads)) {
  63       throw new RuntimeException("Problem with checkSamples...");
  64     }
  65 
  66     for (int elem : threads) {
  67       if (elem == 0) {
  68         throw new RuntimeException("Missing at least one thread in the array...");
  69       }
  70     }
  71   }
  72 }
  73 
  74 class Allocator implements Runnable {
  75   private int depth;
  76   private volatile int tmp[];
  77 
  78   public Allocator(int depth) {
  79     this.depth = depth;
  80   }
  81 
  82   private int helper() {
  83     int sum = 0;
  84     // Let us assume that the array is 24 bytes of memory.
  85     for (int i = 0; i < 127000 / 6; i++) {
  86       int newTmp[] = new int[1];
  87       // Force it to be kept.
  88       tmp = newTmp;
  89       sum += tmp[0];
  90     }
  91     return sum;
  92   }
  93 
  94   private int recursiveWrapper(int depth) {
  95     if (depth > 0) {
  96       return recursiveWrapper(depth - 1);
  97     }
  98     return helper();
  99   }
 100 
 101   public void run() {
 102     int sum = 0;
 103     for (int j = 0; j < 50; j++) {
 104       sum += recursiveWrapper(depth);
 105     }
 106     System.out.println(sum);
 107   }
 108 }
< prev index next >