Skip to content

Commit

Permalink
8327180: Failed: java/io/ObjectStreamClass/ObjectStreamClassCaching.j…
Browse files Browse the repository at this point in the history
…ava#G1

Backport-of: 85fc47c81af81a595dc88e61454d8ba2d860f301
  • Loading branch information
GoeLin committed Apr 22, 2024
1 parent d19b1a4 commit 9b04df2
Showing 1 changed file with 8 additions and 32 deletions.
40 changes: 8 additions & 32 deletions test/jdk/java/io/ObjectStreamClass/ObjectStreamClassCaching.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -49,8 +49,12 @@
*/

/*
* Disabled for ZGC Generational.
* TODO: Find correct appropriate solution to the flakiness of this test.
* @test id=ZGenerational
* @requires vm.gc.ZGenerational
* @bug 8277072 8327180
* @library /test/lib/
* @summary ObjectStreamClass caches keep ClassLoaders alive (ZGC)
* @run testng/othervm -Xmx64m -XX:+UseZGC -XX:+ZGenerational ObjectStreamClassCaching
*/

/*
Expand All @@ -65,41 +69,13 @@
/*
* @test id=Serial
* @requires vm.gc.Serial
* @bug 8277072
* @bug 8277072 8327180
* @library /test/lib/
* @summary ObjectStreamClass caches keep ClassLoaders alive (Serial GC)
* @run testng/othervm -Xmx64m -XX:+UseSerialGC ObjectStreamClassCaching
*/
public class ObjectStreamClassCaching {

/**
* Test methods execute in same VM and are ordered by name.
* We test effectiveness 1st which is sensitive to previous allocations when ZGC is used.
*/
@Test
public void test1CacheEffectiveness() throws Exception {
var list = new ArrayList<>();
var ref1 = lookupObjectStreamClass(TestClass1.class);
var ref2 = newWeakRef();
boolean oome = false;
try {
while (!ref2.refersTo(null)) {
list.add(new byte[1024 * 1024 * 1]); // 1 MiB chunks
System.out.println("1MiB allocated...");
Thread.sleep(5L);
}
} catch (OutOfMemoryError e) {
// release
list = null;
oome = true;
}
assertFalse(oome, "WeakReference was not cleared although memory was pressed hard");
assertFalse(ref1.refersTo(null),
"Cache lost entry together with WeakReference being cleared although memory was not under pressure");
System.gc();
Thread.sleep(100L);
}

@Test
public void test2CacheReleaseUnderMemoryPressure() throws Exception {
var list = new ArrayList<>();
Expand Down

1 comment on commit 9b04df2

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.