예제 #1
0
 // AllocThread only runs "Alloc" phase
 public void run() {
   Random random = new Random();
   while (MallocStressTest.phase == TestPhase.alloc) {
     int r = Math.abs(random.nextInt());
     // Only malloc small amount to avoid OOM
     int size = r % 32;
     if (is_64_bit_system()) {
       r = r % 32 * K;
     } else {
       r = r % 64;
     }
     if (size == 0) size = 1;
     long addr = MallocStressTest.whiteBox.NMTMallocWithPseudoStack(size, r);
     if (addr != 0) {
       MallocMemory mem = new MallocMemory(addr, size);
       synchronized (MallocStressTest.mallocd_memory) {
         MallocStressTest.mallocd_memory.add(mem);
         MallocStressTest.mallocd_total += size;
       }
     } else {
       System.out.println("Out of malloc memory");
       break;
     }
   }
   MallocStressTest.pause_count.incrementAndGet();
 }
예제 #2
0
 private void slow_release() {
   try {
     Thread.sleep(10);
   } catch (InterruptedException e) {
   }
   synchronized (MallocStressTest.mallocd_memory) {
     if (MallocStressTest.mallocd_memory.isEmpty()) return;
     int n = Math.abs(random.nextInt()) % MallocStressTest.mallocd_memory.size();
     MallocMemory mem = mallocd_memory.remove(n);
     MallocStressTest.whiteBox.NMTFree(mem.addr());
     MallocStressTest.mallocd_total -= mem.size();
   }
 }
예제 #3
0
 private void quick_release() {
   List<MallocMemory> free_list;
   while (true) {
     synchronized (MallocStressTest.mallocd_memory) {
       if (MallocStressTest.mallocd_memory.isEmpty()) return;
       int size = Math.min(MallocStressTest.mallocd_memory.size(), 5000);
       List<MallocMemory> subList = MallocStressTest.mallocd_memory.subList(0, size);
       free_list = new ArrayList<MallocMemory>(subList);
       subList.clear();
     }
     for (int index = 0; index < free_list.size(); index++) {
       MallocMemory mem = free_list.get(index);
       MallocStressTest.whiteBox.NMTFree(mem.addr());
     }
   }
 }