From 2165a053e8bf56220af8ef1ef50708364f555931 Mon Sep 17 00:00:00 2001 From: Yudi Zheng Date: Wed, 19 Jun 2024 09:04:12 +0000 Subject: [PATCH] 8334399: [JVMCI] Implement JVMCICompiler::is_intrinsic_supported Reviewed-by: dnsimon --- src/hotspot/share/jvmci/jvmciCompiler.cpp | 11 +++++++- src/hotspot/share/jvmci/jvmciCompiler.hpp | 4 ++- src/hotspot/share/jvmci/jvmciEnv.cpp | 27 ++++++++++++++++++- src/hotspot/share/jvmci/jvmciEnv.hpp | 4 ++- src/hotspot/share/jvmci/jvmciJavaClasses.hpp | 3 ++- src/hotspot/share/jvmci/jvmciRuntime.cpp | 10 +++++++ src/hotspot/share/jvmci/jvmciRuntime.hpp | 3 +++ src/hotspot/share/jvmci/vmSymbols_jvmci.hpp | 3 ++- .../vm/ci/hotspot/HotSpotJVMCIRuntime.java | 8 +++++- .../vm/ci/hotspot/HotSpotVMConfigStore.java | 23 +++++++++++++++- .../jdk/vm/ci/runtime/JVMCICompiler.java | 13 ++++++++- 11 files changed, 100 insertions(+), 9 deletions(-) diff --git a/src/hotspot/share/jvmci/jvmciCompiler.cpp b/src/hotspot/share/jvmci/jvmciCompiler.cpp index 5be065aadad..2b8684f7ab8 100644 --- a/src/hotspot/share/jvmci/jvmciCompiler.cpp +++ b/src/hotspot/share/jvmci/jvmciCompiler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 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 @@ -200,6 +200,15 @@ void JVMCICompiler::print_timers() { _hosted_code_installs.print_on(tty, " Install Code: "); } +bool JVMCICompiler::is_intrinsic_supported(const methodHandle& method) { + vmIntrinsics::ID id = method->intrinsic_id(); + assert(id != vmIntrinsics::_none, "must be a VM intrinsic"); + JavaThread* thread = JavaThread::current(); + JVMCIEnv jvmciEnv(thread, __FILE__, __LINE__); + JVMCIRuntime* runtime = JVMCI::compiler_runtime(thread, false); + return runtime->is_intrinsic_supported(&jvmciEnv, (jint) id); +} + void JVMCICompiler::CodeInstallStats::print_on(outputStream* st, const char* prefix) const { double time = _timer.seconds(); st->print_cr("%s%7.3f s (installs: %d, CodeBlob total size: %d, CodeBlob code size: %d)", diff --git a/src/hotspot/share/jvmci/jvmciCompiler.hpp b/src/hotspot/share/jvmci/jvmciCompiler.hpp index bdb50cfc26a..0d03bd08bf6 100644 --- a/src/hotspot/share/jvmci/jvmciCompiler.hpp +++ b/src/hotspot/share/jvmci/jvmciCompiler.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 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 @@ -136,6 +136,8 @@ public: // Print compilation timers and statistics virtual void print_timers(); + virtual bool is_intrinsic_supported(const methodHandle& method); + // Gets the number of methods that have been successfully compiled by // a call to JVMCICompiler::compile_method(). int methods_compiled() { return _methods_compiled; } diff --git a/src/hotspot/share/jvmci/jvmciEnv.cpp b/src/hotspot/share/jvmci/jvmciEnv.cpp index 624b25b9e2c..01b78b45b2a 100644 --- a/src/hotspot/share/jvmci/jvmciEnv.cpp +++ b/src/hotspot/share/jvmci/jvmciEnv.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -967,6 +967,31 @@ jboolean JVMCIEnv::call_HotSpotJVMCIRuntime_isGCSupported (JVMCIObject runtime, } } +jboolean JVMCIEnv::call_HotSpotJVMCIRuntime_isIntrinsicSupported (JVMCIObject runtime, jint intrinsicIdentifier) { + JavaThread* THREAD = JavaThread::current(); // For exception macros. + if (is_hotspot()) { + JavaCallArguments jargs; + jargs.push_oop(Handle(THREAD, HotSpotJVMCI::resolve(runtime))); + jargs.push_int(intrinsicIdentifier); + JavaValue result(T_BOOLEAN); + JavaCalls::call_special(&result, + HotSpotJVMCI::HotSpotJVMCIRuntime::klass(), + vmSymbols::isIntrinsicSupported_name(), + vmSymbols::int_bool_signature(), &jargs, CHECK_0); + return result.get_jboolean(); + } else { + JNIAccessMark jni(this, THREAD); + jboolean result = jni()->CallNonvirtualBooleanMethod(runtime.as_jobject(), + JNIJVMCI::HotSpotJVMCIRuntime::clazz(), + JNIJVMCI::HotSpotJVMCIRuntime::isIntrinsicSupported_method(), + intrinsicIdentifier); + if (jni()->ExceptionCheck()) { + return false; + } + return result; + } +} + JVMCIObject JVMCIEnv::call_HotSpotJVMCIRuntime_compileMethod (JVMCIObject runtime, JVMCIObject method, int entry_bci, jlong compile_state, int id) { JavaThread* THREAD = JVMCI::compilation_tick(JavaThread::current()); // For exception macros. diff --git a/src/hotspot/share/jvmci/jvmciEnv.hpp b/src/hotspot/share/jvmci/jvmciEnv.hpp index b3aa487f34c..69f6647b0d6 100644 --- a/src/hotspot/share/jvmci/jvmciEnv.hpp +++ b/src/hotspot/share/jvmci/jvmciEnv.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -359,6 +359,8 @@ public: jboolean call_HotSpotJVMCIRuntime_isGCSupported(JVMCIObject runtime, jint gcIdentifier); + jboolean call_HotSpotJVMCIRuntime_isIntrinsicSupported(JVMCIObject runtime, jint intrinsicIdentifier); + void call_HotSpotJVMCIRuntime_postTranslation(JVMCIObject object, JVMCI_TRAPS); // Converts the JavaKind.typeChar value in `ch` to a BasicType diff --git a/src/hotspot/share/jvmci/jvmciJavaClasses.hpp b/src/hotspot/share/jvmci/jvmciJavaClasses.hpp index 3561093caaa..d5fcd2aaaba 100644 --- a/src/hotspot/share/jvmci/jvmciJavaClasses.hpp +++ b/src/hotspot/share/jvmci/jvmciJavaClasses.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 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 @@ -202,6 +202,7 @@ objectarray_field(HotSpotJVMCIRuntime, excludeFromJVMCICompilation, "[Ljava/lang/Module;") \ jvmci_method(CallNonvirtualObjectMethod, GetMethodID, call_special, JVMCIObject, HotSpotJVMCIRuntime, compileMethod, compileMethod_signature) \ jvmci_method(CallNonvirtualObjectMethod, GetMethodID, call_special, JVMCIObject, HotSpotJVMCIRuntime, isGCSupported, int_bool_signature) \ + jvmci_method(CallNonvirtualObjectMethod, GetMethodID, call_special, JVMCIObject, HotSpotJVMCIRuntime, isIntrinsicSupported, int_bool_signature) \ jvmci_method(CallNonvirtualVoidMethod, GetMethodID, call_special, void, HotSpotJVMCIRuntime, bootstrapFinished, void_method_signature) \ jvmci_method(CallNonvirtualVoidMethod, GetMethodID, call_special, void, HotSpotJVMCIRuntime, shutdown, void_method_signature) \ jvmci_method(CallStaticObjectMethod, GetStaticMethodID, call_static, JVMCIObject, HotSpotJVMCIRuntime, runtime, runtime_signature) \ diff --git a/src/hotspot/share/jvmci/jvmciRuntime.cpp b/src/hotspot/share/jvmci/jvmciRuntime.cpp index 9dc0e381df9..504fbfcb1b0 100644 --- a/src/hotspot/share/jvmci/jvmciRuntime.cpp +++ b/src/hotspot/share/jvmci/jvmciRuntime.cpp @@ -2050,6 +2050,16 @@ bool JVMCIRuntime::is_gc_supported(JVMCIEnv* JVMCIENV, CollectedHeap::Name name) return JVMCIENV->call_HotSpotJVMCIRuntime_isGCSupported(receiver, (int) name); } +bool JVMCIRuntime::is_intrinsic_supported(JVMCIEnv* JVMCIENV, jint id) { + JVMCI_EXCEPTION_CONTEXT + + JVMCIObject receiver = get_HotSpotJVMCIRuntime(JVMCIENV); + if (JVMCIENV->has_pending_exception()) { + fatal_exception(JVMCIENV, "Exception during HotSpotJVMCIRuntime initialization"); + } + return JVMCIENV->call_HotSpotJVMCIRuntime_isIntrinsicSupported(receiver, id); +} + // ------------------------------------------------------------------ JVMCI::CodeInstallResult JVMCIRuntime::register_method(JVMCIEnv* JVMCIENV, const methodHandle& method, diff --git a/src/hotspot/share/jvmci/jvmciRuntime.hpp b/src/hotspot/share/jvmci/jvmciRuntime.hpp index 123cfde15ac..bc5bee4edeb 100644 --- a/src/hotspot/share/jvmci/jvmciRuntime.hpp +++ b/src/hotspot/share/jvmci/jvmciRuntime.hpp @@ -431,6 +431,9 @@ class JVMCIRuntime: public CHeapObj { // Determines if the GC identified by `name` is supported by the JVMCI compiler. bool is_gc_supported(JVMCIEnv* JVMCIENV, CollectedHeap::Name name); + // Determines if the intrinsic identified by `id` is supported by the JVMCI compiler. + bool is_intrinsic_supported(JVMCIEnv* JVMCIENV, jint id); + // Register the result of a compilation. JVMCI::CodeInstallResult register_method(JVMCIEnv* JVMCIENV, const methodHandle& target, diff --git a/src/hotspot/share/jvmci/vmSymbols_jvmci.hpp b/src/hotspot/share/jvmci/vmSymbols_jvmci.hpp index 13d81d9f286..c0a7afe2b63 100644 --- a/src/hotspot/share/jvmci/vmSymbols_jvmci.hpp +++ b/src/hotspot/share/jvmci/vmSymbols_jvmci.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 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 @@ -81,6 +81,7 @@ template(compileMethod_name, "compileMethod") \ template(compileMethod_signature, "(Ljdk/vm/ci/hotspot/HotSpotResolvedJavaMethod;IJI)Ljdk/vm/ci/hotspot/HotSpotCompilationRequestResult;") \ template(isGCSupported_name, "isGCSupported") \ + template(isIntrinsicSupported_name, "isIntrinsicSupported") \ template(fromMetaspace_name, "fromMetaspace") \ template(method_fromMetaspace_signature, "(JLjdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl;)Ljdk/vm/ci/hotspot/HotSpotResolvedJavaMethod;") \ template(constantPool_fromMetaspace_signature, "(J)Ljdk/vm/ci/hotspot/HotSpotConstantPool;") \ diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java index 87cd10b400f..3dcf855ff23 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -987,6 +987,12 @@ public final class HotSpotJVMCIRuntime implements JVMCIRuntime { return getCompiler().isGCSupported(gcIdentifier); } + @SuppressWarnings("try") + @VMEntryPoint + private boolean isIntrinsicSupported(int intrinsicIdentifier) { + return getCompiler().isIntrinsicSupported(intrinsicIdentifier); + } + /** * Guard to ensure shut down actions are performed by at most one thread. */ diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfigStore.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfigStore.java index 0ee69f135c9..c6735cef5f6 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfigStore.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/hotspot/HotSpotVMConfigStore.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 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 @@ -82,6 +82,27 @@ public final class HotSpotVMConfigStore { return Collections.unmodifiableList(vmIntrinsics); } + /** + * Gets the VM intrinsic description by its ID. + */ + public VMIntrinsicMethod getIntrinsic(int intrinsicID) { + if (intrinsicID >= 1 && intrinsicID <= vmIntrinsics.size()) { + // valid intrinsicID starts from 1 + VMIntrinsicMethod intrinsic = vmIntrinsics.get(intrinsicID - 1); + // We speculate that vmIntrinsics are sorted by ID + if (intrinsic.id == intrinsicID) { + return intrinsic; + } + } + // Assumption failed, fall back to iteration + for (VMIntrinsicMethod intrinsic : vmIntrinsics) { + if (intrinsic.id == intrinsicID) { + return intrinsic; + } + } + return null; + } + final HashMap vmFields; final HashMap vmConstants; final HashMap vmAddresses; diff --git a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/runtime/JVMCICompiler.java b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/runtime/JVMCICompiler.java index bbb9c79e9f5..accd9e01490 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/runtime/JVMCICompiler.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/runtime/JVMCICompiler.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -44,4 +44,15 @@ public interface JVMCICompiler { default boolean isGCSupported(int gcIdentifier) { return true; } + + /** + * Determines if this compiler supports the {@code intrinsicIdentifier} intrinsic. The default + * implementation of this method returns false as that is the effective answer given by a + * {@link JVMCICompiler} before this method was added. + * + * @param intrinsicIdentifier intrinsic identifier defined in vmIntrinsics.hpp. + */ + default boolean isIntrinsicSupported(int intrinsicIdentifier) { + return false; + } }