diff -r 13588c901957 -r 9cf78a70fa4f src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/CompilationWatchDog.java --- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/CompilationWatchDog.java Thu Oct 17 20:27:44 2019 +0100 +++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/CompilationWatchDog.java Thu Oct 17 20:53:35 2019 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2019, 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 @@ -28,6 +28,7 @@ import java.util.Arrays; +import org.graalvm.compiler.core.GraalServiceThread; import org.graalvm.compiler.debug.TTY; import org.graalvm.compiler.options.Option; import org.graalvm.compiler.options.OptionKey; @@ -49,10 +50,10 @@ * dog reports a long running compilation. Every * {@link Options#CompilationWatchDogStackTraceInterval} seconds after that point in time where the * same compilation is still executing, the watch dog takes a stack trace of the compiler thread. If - * more than {@value Options#NonFatalIdenticalCompilationSnapshots} contiguous identical stack - * traces are seen, the watch dog reports a stuck compilation and exits the VM. + * more than {@link Options#NonFatalIdenticalCompilationSnapshots} contiguous identical stack traces + * are seen, the watch dog reports a stuck compilation and exits the VM. */ -class CompilationWatchDog extends Thread implements AutoCloseable { +class CompilationWatchDog implements Runnable, AutoCloseable { public static class Options { // @formatter:off @@ -112,9 +113,6 @@ CompilationWatchDog(Thread compilerThread, long startDelayMilliseconds, long stackTraceIntervalMilliseconds, int nonFatalIdenticalCompilationSnapshots) { this.compilerThread = compilerThread; - this.setName("WatchDog" + getId() + "[" + compilerThread.getName() + "]"); - this.setPriority(Thread.MAX_PRIORITY); - this.setDaemon(true); this.startDelayMilliseconds = startDelayMilliseconds; this.stackTraceIntervalMilliseconds = stackTraceIntervalMilliseconds; this.nonFatalIdenticalCompilationSnapshots = nonFatalIdenticalCompilationSnapshots; @@ -185,7 +183,7 @@ @Override public String toString() { - return getName(); + return "WatchDog[" + compilerThread.getName() + "]"; } @Override @@ -240,7 +238,7 @@ TTY.printf("======================= WATCH DOG THREAD =======================%n" + "%s took %d identical stack traces, which indicates a stuck compilation (id=%d) of %s%n%sExiting VM%n", this, numberOfIdenticalStackTraces, currentId, fmt(currentMethod), fmt(lastStackTrace)); - System.exit(-1); + HotSpotGraalServices.exit(-1); } } else if (newStackTrace) { synchronized (CompilationWatchDog.class) { @@ -305,12 +303,16 @@ // Lazily get a watch dog thread for the current compiler thread CompilationWatchDog watchDog = WATCH_DOGS.get(); if (watchDog == null) { - Thread currentThread = currentThread(); + Thread currentThread = Thread.currentThread(); long stackTraceIntervalMilliseconds = ms(Options.CompilationWatchDogStackTraceInterval.getValue(options)); int nonFatalIdenticalCompilationSnapshots = Options.NonFatalIdenticalCompilationSnapshots.getValue(options); watchDog = new CompilationWatchDog(currentThread, startDelayMilliseconds, stackTraceIntervalMilliseconds, nonFatalIdenticalCompilationSnapshots); WATCH_DOGS.set(watchDog); - watchDog.start(); + GraalServiceThread thread = new GraalServiceThread(watchDog); + thread.setName(thread.getId() + " " + watchDog.toString()); + thread.setPriority(Thread.MAX_PRIORITY); + thread.setDaemon(true); + thread.start(); } watchDog.startCompilation(method, id); return watchDog;