Java/C# smart pointer tests: Give GC more time to collect objects
This commit is contained in:
parent
785d93d9fb
commit
87963d2e68
6 changed files with 137 additions and 67 deletions
|
|
@ -13,6 +13,16 @@ public class java_director_runme {
|
|||
}
|
||||
}
|
||||
|
||||
private static void WaitForGC()
|
||||
{
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
try {
|
||||
java.lang.Thread.sleep(10);
|
||||
} catch (java.lang.InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[]) {
|
||||
QuuxContainer qc = createContainer();
|
||||
|
||||
|
|
@ -31,24 +41,21 @@ public class java_director_runme {
|
|||
qc = null;
|
||||
/* Watch qc get reaped, which causes the C++ object to delete
|
||||
objects from the internal vector */
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
|
||||
// Give the finalizers a chance to run
|
||||
try {
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException e) {
|
||||
{
|
||||
int countdown = 500;
|
||||
int expectedCount = 0;
|
||||
while (true) {
|
||||
WaitForGC();
|
||||
if (--countdown == 0)
|
||||
break;
|
||||
if (Quux.instances() == expectedCount)
|
||||
break;
|
||||
};
|
||||
int actualCount = Quux.instances();
|
||||
if (actualCount != expectedCount)
|
||||
throw new RuntimeException("Expected count: " + expectedCount + " Actual count: " + actualCount);
|
||||
}
|
||||
|
||||
/* Watch the Quux objects formerly in the QuuxContainer object
|
||||
get reaped */
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
|
||||
instances = Quux.instances();
|
||||
if (instances != 0)
|
||||
throw new RuntimeException("Quux instances should be 0, actually " + instances);
|
||||
|
||||
/* Test Quux1's director disconnect method rename */
|
||||
Quux1 quux1 = new Quux1("quux1");
|
||||
if (quux1.disconnectMethodCalled)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,16 @@ public class li_boost_intrusive_ptr_runme {
|
|||
// Debugging flag
|
||||
public final static boolean debug = false;
|
||||
|
||||
private static void WaitForGC()
|
||||
{
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
try {
|
||||
java.lang.Thread.sleep(10);
|
||||
} catch (java.lang.InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[])
|
||||
{
|
||||
if (debug)
|
||||
|
|
@ -39,12 +49,7 @@ public class li_boost_intrusive_ptr_runme {
|
|||
|
||||
int countdown = 50;
|
||||
while (true) {
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
try {
|
||||
java.lang.Thread.sleep(100);
|
||||
} catch (java.lang.InterruptedException e) {
|
||||
}
|
||||
WaitForGC();
|
||||
if (--countdown == 0)
|
||||
break;
|
||||
if (Klass.getTotal_count() == 1 && KlassWithoutRefCount.getTotal_count() == 0 &&
|
||||
|
|
@ -52,7 +57,7 @@ public class li_boost_intrusive_ptr_runme {
|
|||
KlassDerived.getTotal_count() == 0 && KlassDerivedDerived.getTotal_count() == 1)
|
||||
// Expect 1 Klass instance - the one global variable (GlobalValue)
|
||||
break;
|
||||
};
|
||||
}
|
||||
if (Klass.getTotal_count() != 1)
|
||||
throw new RuntimeException("Klass.total_count=" + Klass.getTotal_count());
|
||||
if (KlassWithoutRefCount.getTotal_count() != 0)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,16 @@ public class li_boost_shared_ptr_runme {
|
|||
// Debugging flag
|
||||
public final static boolean debug = false;
|
||||
|
||||
private static void WaitForGC()
|
||||
{
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
try {
|
||||
java.lang.Thread.sleep(10);
|
||||
} catch (java.lang.InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[])
|
||||
{
|
||||
if (debug)
|
||||
|
|
@ -37,21 +47,20 @@ public class li_boost_shared_ptr_runme {
|
|||
if (debug)
|
||||
System.out.println("Nearly finished");
|
||||
|
||||
int countdown = 100;
|
||||
while (true) {
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
try {
|
||||
java.lang.Thread.sleep(10);
|
||||
} catch (java.lang.InterruptedException e) {
|
||||
{
|
||||
int countdown = 500;
|
||||
int expectedCount = 1;
|
||||
while (true) {
|
||||
WaitForGC();
|
||||
if (--countdown == 0)
|
||||
break;
|
||||
if (Klass.getTotal_count() == expectedCount) // Expect the one global variable (GlobalValue)
|
||||
break;
|
||||
}
|
||||
if (--countdown == 0)
|
||||
break;
|
||||
if (Klass.getTotal_count() == 1) // Expect 1 instance - the one global variable (GlobalValue)
|
||||
break;
|
||||
};
|
||||
if (Klass.getTotal_count() != 1)
|
||||
throw new RuntimeException("Klass.total_count=" + Klass.getTotal_count());
|
||||
int actualCount = Klass.getTotal_count();
|
||||
if (actualCount != expectedCount)
|
||||
throw new RuntimeException("Expected count: " + expectedCount + " Actual count: " + actualCount);
|
||||
}
|
||||
|
||||
int wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count();
|
||||
if (wrapper_count != li_boost_shared_ptr.getNOT_COUNTING())
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public class li_std_auto_ptr_runme {
|
|||
System.gc();
|
||||
System.runFinalization();
|
||||
try {
|
||||
java.lang.Thread.sleep(1);
|
||||
java.lang.Thread.sleep(10);
|
||||
} catch (java.lang.InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
|
@ -31,18 +31,38 @@ public class li_std_auto_ptr_runme {
|
|||
throw new RuntimeException("number of objects should be 2");
|
||||
|
||||
k1 = null;
|
||||
WaitForGC();
|
||||
|
||||
if (Klass.getTotal_count() != 1)
|
||||
throw new RuntimeException("number of objects should be 1");
|
||||
{
|
||||
int countdown = 500;
|
||||
int expectedCount = 1;
|
||||
while (true) {
|
||||
WaitForGC();
|
||||
if (--countdown == 0)
|
||||
break;
|
||||
if (Klass.getTotal_count() == expectedCount)
|
||||
break;
|
||||
}
|
||||
int actualCount = Klass.getTotal_count();
|
||||
if (actualCount != expectedCount)
|
||||
throw new RuntimeException("Expected count: " + expectedCount + " Actual count: " + actualCount);
|
||||
}
|
||||
|
||||
if (!k2.getLabel().equals("second"))
|
||||
throw new RuntimeException("wrong object label");
|
||||
|
||||
k2 = null;
|
||||
WaitForGC();
|
||||
|
||||
if (Klass.getTotal_count() != 0)
|
||||
throw new RuntimeException("no objects should be left");
|
||||
{
|
||||
int countdown = 500;
|
||||
int expectedCount = 0;
|
||||
while (true) {
|
||||
WaitForGC();
|
||||
if (--countdown == 0)
|
||||
break;
|
||||
if (Klass.getTotal_count() == expectedCount)
|
||||
break;
|
||||
};
|
||||
int actualCount = Klass.getTotal_count();
|
||||
if (actualCount != expectedCount)
|
||||
throw new RuntimeException("Expected count: " + expectedCount + " Actual count: " + actualCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue