Test passes fine with G1. But it fails with other GCs, for example Parallel, Shenandoah, etc:
$ CONF=linux-x86_64-server-fastdebug make test TEST=java/io/ObjectStreamClass/ObjectStreamClassCaching.java TEST_VM_OPTS="-XX:+UseParallelGC"
test ObjectStreamClassCaching.testCacheReleaseUnderMemoryPressure(): success
test ObjectStreamClassCaching.testCachingEffectiveness(): failure
java.lang.AssertionError: Cache lost entry although memory was not under pressure expected [false] but found [true]
at org.testng.Assert.fail(Assert.java:99)
at org.testng.Assert.failNotEquals(Assert.java:1037)
at org.testng.Assert.assertFalse(Assert.java:67)
This is probably because System.gc() request in the test is handled by different GCs differently.
In fact, the test fails with G1 if we do a second System.gc() in this test. So the test itself is flaky. We should probably stop doing GCs altogether there.