Skip to content

Commit

Permalink
8325613: CTW: Stale method cleanup requires GC after Sweeper removal
Browse files Browse the repository at this point in the history
Backport-of: 1281e18f1447848d7eb5e3bde508ac002b4c390d
  • Loading branch information
shipilev committed Mar 19, 2024
1 parent 2de8cfa commit 9e1840f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@
*/
public class Compiler {

// Call GC after compiling as many methods. This would remove the stale methods.
// This threshold should balance the GC overhead and the cost of keeping lots
// of stale methods around.
private static final long GC_METHOD_THRESHOLD = Long.getLong("gcMethodThreshold", 100);

private static final Unsafe UNSAFE = Unsafe.getUnsafe();
private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
private static final AtomicLong METHOD_COUNT = new AtomicLong(0L);
private static final AtomicLong METHOD_COUNT = new AtomicLong();
private static final AtomicLong METHODS_SINCE_LAST_GC = new AtomicLong();

private Compiler() { }

Expand Down Expand Up @@ -83,6 +89,21 @@ public static void compileClass(Class<?> aClass, long id, Executor executor) {
executor.execute(new CompileMethodCommand(id, e));
}
METHOD_COUNT.addAndGet(methodCount);

// See if we need to schedule a GC
while (true) {
long current = METHODS_SINCE_LAST_GC.get();
long update = current + methodCount;
if (update >= GC_METHOD_THRESHOLD) {
update = 0;
}
if (METHODS_SINCE_LAST_GC.compareAndSet(current, update)) {
if (update == 0) {
executor.execute(() -> System.gc());
}
break;
}
}
}

private static void preloadClasses(String className, long id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,10 @@ private String[] cmd(long classStart, long classStop) {
String.format("-XX:ReplayDataFile=replay_%s_%%p.log", phase),
// MethodHandle MUST NOT be compiled
"-XX:CompileCommand=exclude,java/lang/invoke/MethodHandle.*",
// Stress* are c2-specific stress flags, so IgnoreUnrecognizedVMOptions is needed
"-XX:+IgnoreUnrecognizedVMOptions",
// Do not pay extra zapping cost for explicit GC invocations
"-XX:-ZapUnusedHeapArea",
// Stress* are c2-specific stress flags, so IgnoreUnrecognizedVMOptions is needed
"-XX:+StressLCM",
"-XX:+StressGCM",
"-XX:+StressIGVN",
Expand Down

1 comment on commit 9e1840f

@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.