Ejemplo n.º 1
0
  @Test
  public void testCopyReferenceLoadTest() {
    assertEquals(0, JNIMemoryManager.getMgr().getNumPinnedObjects());

    RefCounted obj = RefCountedTester.make();

    for (int i = 0; i < 100000; i++) {
      RefCounted copy = obj.copyReference();
      copy.delete();
    }
    obj.delete();
    assertEquals(0, JNIMemoryManager.getMgr().getNumPinnedObjects());
  }
Ejemplo n.º 2
0
  @Test
  public void testCopyReferenceLoadTestMultiThreaded() throws InterruptedException {
    assertEquals(0, JNIMemoryManager.getMgr().getNumPinnedObjects());
    final RefCounted obj = RefCountedTester.make();

    final int NUM_THREADS = 100;
    final int NUM_ITERS = 10000;
    final AtomicBoolean start = new AtomicBoolean(false);

    Thread[] threads = new Thread[NUM_THREADS];
    for (int i = 0; i < threads.length; i++) {
      threads[i] =
          new Thread(
              new Runnable() {
                public void run() {
                  synchronized (start) {
                    while (!start.get())
                      try {
                        start.wait();
                      } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
                      }
                  }
                  //              System.out.println("Thread started:
                  // "+Thread.currentThread().getName());
                  for (int i = 0; i < NUM_ITERS; i++) {
                    RefCounted copy = obj.copyReference();
                    copy.delete();
                  }
                }
              },
              "thread_" + i);
    }
    for (int i = 0; i < threads.length; i++) {
      threads[i].start();
    }
    synchronized (start) {
      start.set(true);
      start.notifyAll();
    }
    for (int i = 0; i < threads.length; i++) {
      threads[i].join();
      //      System.out.println("Thread finished: "+threads[i].getName());
    }
    obj.delete();
    assertEquals(0, JNIMemoryManager.getMgr().getNumPinnedObjects());
  }