Repository: quarkusio/quarkus
Issue: Quarkus' DiagnosticPrinter incompatible with GraalVM / Mandrel 22.1-dev

### Describe the bug

A [recent GraalVM refactoring](https://github.com/oracle/graal/commit/56804e7227510acbfac9c658905cb614eec57d73) moved `com.oracle.svm.core.posix.thread.PosixJavaThreads#getPthreadIdentifier` and `com.oracle.svm.core.posix.thread.PosixJavaThreads#hasThreadIdentifier` to a new class `com.oracle.svm.core.posix.thread.PosixPlatformJavaThreads` making the following code to cause native-image failures since GraalVM fails to find the corresponding methods: https://github.com/quarkusio/quarkus/blob/5036e2f94f71f88f3e0a7415c7b2c519861a267c/core/runtime/src/main/java/io/quarkus/runtime/graal/DiagnosticPrinter.java#L18-L26 

### Expected behavior

Quarkus should work with the upcoming 22.1 GraalVM release

### Actual behavior

Quarkus fails with:

```
 Error: Could not find target method: static native com.oracle.svm.core.posix.headers.Pthread$pthread_t io.quarkus.runtime.graal.DiagnosticPrinter$Target_PosixJavaThreads.getPthreadIdentifier(java.lang.Thread)
com.oracle.svm.core.util.UserError$UserException: Could not find target method: static native com.oracle.svm.core.posix.headers.Pthread$pthread_t io.quarkus.runtime.graal.DiagnosticPrinter$Target_PosixJavaThreads.getPthreadIdentifier(java.lang.Thread)
	at com.oracle.svm.core.util.UserError.abort(UserError.java:72)
	at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.findOriginalMethod(AnnotationSubstitutionProcessor.java:764)
	at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleMethodInAliasClass(AnnotationSubstitutionProcessor.java:381)
	at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleAliasClass(AnnotationSubstitutionProcessor.java:353)
	at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleClass(AnnotationSubstitutionProcessor.java:323)
	at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.init(AnnotationSubstitutionProcessor.java:279)
	at com.oracle.svm.hosted.NativeImageGenerator.createAnnotationSubstitutionProcessor(NativeImageGenerator.java:923)
	at com.oracle.svm.hosted.NativeImageGenerator.setupNativeImage(NativeImageGenerator.java:836)
	at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:551)
	at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:511)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:423)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:598)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
	at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:628)
```

See https://github.com/graalvm/mandrel/runs/5103314555?check_suite_focus=true#step:11:177

### How to Reproduce?

1. Download latest nightly build of GraalVM from https://github.com/graalvm/graalvm-ce-dev-builds/releases/
2. Try to create a native Quarkus application or integration test with it

### Output of `uname -a` or `ver`

GH runner

### Output of `java -version`

11.0.14 and 17.0.2

### GraalVM version (if different from Java)

22.1.0-deva0db6e1

### Quarkus version or git rev

8de379736da497e2b971be853ec2c076509779b0

### Build tool (ie. output of `mvnw --version` or `gradlew --version`)

Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)

### Additional information

This issue is related to the discussion in https://github.com/oracle/graal/discussions/4146. `DiagnosticsPrinter` is relying on GraalVM internals, as a result it's expected for such code segments to cause issues from time to time.

The question is: Do Quarkus users and devs use the `DiagnosticsPrinter`? Is it worth performing version checks (and complicating things by not using public APIs) to make it work or is it something we could remove?

cc @geoand @gsmet @stuartwdouglas 

Changed files:
core/runtime/src/main/java/io/quarkus/runtime/graal/DiagnosticPrinter.java

diff --git a/core/runtime/src/main/java/io/quarkus/runtime/graal/DiagnosticPrinter.java b/core/runtime/src/main/java/io/quarkus/runtime/graal/DiagnosticPrinter.java
index b925372a100..98f5e5d9dba 100644
--- a/core/runtime/src/main/java/io/quarkus/runtime/graal/DiagnosticPrinter.java
+++ b/core/runtime/src/main/java/io/quarkus/runtime/graal/DiagnosticPrinter.java
@@ -4,27 +4,10 @@
 import java.time.Instant;
 import java.util.Map;
 
-import org.graalvm.nativeimage.Platform;
-import org.graalvm.nativeimage.Platforms;
-
-import com.oracle.svm.core.annotate.Alias;
-import com.oracle.svm.core.annotate.TargetClass;
-import com.oracle.svm.core.posix.headers.Pthread;
-
 /**
  * A signal handler that prints diagnostic thread info to standard output.
  */
 public final class DiagnosticPrinter {
-    @TargetClass(className = "com.oracle.svm.core.posix.thread.PosixJavaThreads")
-    @Platforms({ Platform.LINUX.class, Platform.DARWIN.class })
-    static final class Target_PosixJavaThreads {
-        @Alias
-        static native Pthread.pthread_t getPthreadIdentifier(Thread thread);
-
-        @Alias
-        static native boolean hasThreadIdentifier(Thread thread);
-    }
-
     public static void printDiagnostics(PrintStream w) {
         Map<Thread, StackTraceElement[]> allStackTraces = Thread.getAllStackTraces();
         w.println(Instant.now().toString());
@@ -42,15 +25,6 @@ public static void printDiagnostics(PrintStream w) {
                 w.print("daemon ");
             w.print("prio=");
             w.print(thread.getPriority());
-            w.print(" tid=");
-            if ((Platform.includedIn(Platform.LINUX.class) || Platform.includedIn(Platform.DARWIN.class))
-                    && Target_PosixJavaThreads.hasThreadIdentifier(thread)) {
-                final long nativeId = Target_PosixJavaThreads.getPthreadIdentifier(thread).rawValue();
-                w.print("0x");
-                w.println(Long.toHexString(nativeId));
-            } else {
-                w.println("(unknown)");
-            }
             w.print("   java.lang.thread.State: ");
             w.println(thread.getState());
             for (StackTraceElement element : stackTrace) {