コード例 #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());
  }
コード例 #2
0
 @Test
 public void testFloatGetPut() {
   // free up any references from other tests
   JNIMemoryManager.getMgr().flush();
   float[] in = new float[] {0x38, 0x2C, 0x18, 0x7F};
   float[] out = new float[in.length];
   Buffer buf = Buffer.make(null, 1024);
   buf.put(in, 0, 0, in.length);
   buf.get(0, out, 0, in.length);
   for (int i = 0; i < in.length; i++) assertEquals("mismatched bytes at " + i, in[i], out[i]);
   buf.delete();
   assertEquals(
       "more objects around than expected", 0, JNIMemoryManager.getMgr().getNumPinnedObjects());
 }
コード例 #3
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());
  }
コード例 #4
0
 @Before
 public void setUp() {
   JNIMemoryManager.getMgr().flush();
 }
コード例 #5
0
 public RefCountedExhaustiveTest(JNIMemoryManager.MemoryModel model) {
   JNIMemoryManager.setMemoryModel(model);
 }
コード例 #6
0
 @Test(timeout = 5 * 60 * 1000)
 public void testJNIMemoryManagerHeapExpansion() {
   LinkedList<RefCountedTester> heldRefs = new LinkedList<RefCountedTester>();
   JNIMemoryManager mgr = JNIMemoryManager.getMgr();
   mgr.flush();
   mgr.setMinimumReferencesToCache(1024);
   int maxItems = 10000;
   // 10000 should cause several heap expansions to occur
   for (int i = 0; i < maxItems; i++) {
     heldRefs.add(RefCountedTester.make());
   }
   assertEquals("didn't pin as many as it should", maxItems, mgr.getNumPinnedObjects());
   // now release them.
   heldRefs.clear();
   while (mgr.getNumPinnedObjects() != 0) {
     MemoryTestHelper.forceJavaHeapWeakReferenceClear();
     // Do a collection
     mgr.gc(true);
   }
   assertEquals("didn't pin as many as it should", 0, mgr.getNumPinnedObjects());
   // this should cause the heap to shrink, and then grow
   for (int i = 0; i < maxItems / 2; i++) {
     heldRefs.add(RefCountedTester.make());
   }
   assertEquals("didn't pin as many as it should", maxItems / 2, mgr.getNumPinnedObjects());
   // now release them.
   heldRefs.clear();
   // and force a collection
   while (mgr.getNumPinnedObjects() != 0) {
     MemoryTestHelper.forceJavaHeapWeakReferenceClear();
     // Do a collection
     mgr.gc(true);
   }
   assertEquals("didn't pin as many as it should", 0, mgr.getNumPinnedObjects());
 }