Skip to content

Commit b590846

Browse files
committed
Flag for printing warnings when using deprecated APIs.
1 parent af47f6d commit b590846

File tree

14 files changed

+223
-58
lines changed

14 files changed

+223
-58
lines changed

sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/hosted/RuntimeForeignAccess.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,15 @@
4747
import org.graalvm.nativeimage.Platform;
4848
import org.graalvm.nativeimage.Platforms;
4949
import org.graalvm.nativeimage.dynamicaccess.ForeignAccess;
50+
import org.graalvm.nativeimage.impl.APIDeprecationSupport;
5051
import org.graalvm.nativeimage.dynamicaccess.AccessCondition;
5152
import org.graalvm.nativeimage.impl.RuntimeForeignAccessSupport;
5253

5354
@Platforms(Platform.HOSTED_ONLY.class)
5455
public final class RuntimeForeignAccess {
5556

57+
private static final APIDeprecationSupport deprecationFlag = ImageSingletons.lookup(APIDeprecationSupport.class);
58+
5659
/**
5760
* Registers the provided function descriptor and options pair at image build time for downcalls
5861
* into foreign code. Required to get a downcall method handle using
@@ -63,14 +66,15 @@ public final class RuntimeForeignAccess {
6366
* performed to ensure that the arguments have the expected type. It will be deprecated in favor
6467
* of strongly typed variant as soon as possible.
6568
* <p>
66-
* This API is deprecated; use {@link ForeignAccess} instead.
69+
* This API is deprecated; use the {@link ForeignAccess} instead.
6770
*
6871
* @param desc A {@link java.lang.foreign.FunctionDescriptor} to register for downcalls.
6972
* @param options An array of {@link java.lang.foreign.Linker.Option} used for the downcalls.
7073
*
7174
* @since 23.1
7275
*/
7376
public static void registerForDowncall(Object desc, Object... options) {
77+
deprecationFlag.printDeprecationWarning();
7478
ImageSingletons.lookup(RuntimeForeignAccessSupport.class).registerForDowncall(AccessCondition.unconditional(), desc, options);
7579
}
7680

@@ -83,14 +87,15 @@ public static void registerForDowncall(Object desc, Object... options) {
8387
* performed to ensure that the arguments have the expected type. It will be deprecated in favor
8488
* of strongly typed variant as soon as possible.
8589
* <p>
86-
* This API is deprecated; use {@link ForeignAccess} instead.
90+
* This API is deprecated; use the {@link ForeignAccess} instead.
8791
*
8892
* @param desc A {@link java.lang.foreign.FunctionDescriptor} to register for upcalls.
8993
* @param options An array of {@link java.lang.foreign.Linker.Option} used for the upcalls.
9094
*
9195
* @since 24.1
9296
*/
9397
public static void registerForUpcall(Object desc, Object... options) {
98+
deprecationFlag.printDeprecationWarning();
9499
ImageSingletons.lookup(RuntimeForeignAccessSupport.class).registerForUpcall(AccessCondition.unconditional(), desc, options);
95100
}
96101

@@ -112,7 +117,7 @@ public static void registerForUpcall(Object desc, Object... options) {
112117
* of strongly typed variant as soon as possible.
113118
* </p>
114119
* <p>
115-
* This API is deprecated; use {@link ForeignAccess} instead.
120+
* This API is deprecated; use the {@link ForeignAccess} instead.
116121
*
117122
* @param target A direct method handle denoting a static method.
118123
* @param desc A {@link java.lang.foreign.FunctionDescriptor} to register for upcalls.
@@ -121,6 +126,7 @@ public static void registerForUpcall(Object desc, Object... options) {
121126
* @since 24.2
122127
*/
123128
public static void registerForDirectUpcall(MethodHandle target, Object desc, Object... options) {
129+
deprecationFlag.printDeprecationWarning();
124130
ImageSingletons.lookup(RuntimeForeignAccessSupport.class).registerForDirectUpcall(AccessCondition.unconditional(), target, desc, options);
125131
}
126132

sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/hosted/RuntimeJNIAccess.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.graalvm.nativeimage.Platform;
4848
import org.graalvm.nativeimage.Platforms;
4949
import org.graalvm.nativeimage.dynamicaccess.JNIAccess;
50+
import org.graalvm.nativeimage.impl.APIDeprecationSupport;
5051
import org.graalvm.nativeimage.dynamicaccess.AccessCondition;
5152
import org.graalvm.nativeimage.impl.RuntimeJNIAccessSupport;
5253

@@ -59,16 +60,19 @@
5960
@Platforms(Platform.HOSTED_ONLY.class)
6061
public final class RuntimeJNIAccess {
6162

63+
private static final APIDeprecationSupport deprecationFlag = ImageSingletons.lookup(APIDeprecationSupport.class);
64+
6265
/**
6366
* Makes the provided classes available for JNI access at run time. Needed when native code
6467
* looks up Java classes via <a href=
6568
* "https://docs.oracle.com/en/java/javase/17/docs/specs/jni/functions.html#findclass">FindClass</a>.
6669
* <p>
67-
* This API is deprecated; use {@link JNIAccess} instead.
70+
* This API is deprecated; use the {@link JNIAccess} instead.
6871
*
6972
* @since 22.3
7073
*/
7174
public static void register(Class<?>... classes) {
75+
deprecationFlag.printDeprecationWarning();
7276
ImageSingletons.lookup(RuntimeJNIAccessSupport.class).register(AccessCondition.unconditional(), classes);
7377
}
7478

@@ -79,11 +83,12 @@ public static void register(Class<?>... classes) {
7983
* or <a href=
8084
* "https://docs.oracle.com/en/java/javase/17/docs/specs/jni/functions.html#getstaticmethodid">GetStaticMethodID</a>.
8185
* <p>
82-
* This API is deprecated; use {@link JNIAccess} instead.
86+
* This API is deprecated; use the {@link JNIAccess} instead.
8387
*
8488
* @since 22.3
8589
*/
8690
public static void register(Executable... methods) {
91+
deprecationFlag.printDeprecationWarning();
8792
ImageSingletons.lookup(RuntimeJNIAccessSupport.class).register(AccessCondition.unconditional(), false, methods);
8893
}
8994

@@ -94,11 +99,12 @@ public static void register(Executable... methods) {
9499
* or <a href=
95100
* "https://docs.oracle.com/en/java/javase/17/docs/specs/jni/functions.html#getstaticfieldid">GetStaticFieldID</a>.
96101
* <p>
97-
* This API is deprecated; use {@link JNIAccess} instead.
102+
* This API is deprecated; use the {@link JNIAccess} instead.
98103
*
99104
* @since 22.3
100105
*/
101106
public static void register(Field... fields) {
107+
deprecationFlag.printDeprecationWarning();
102108
ImageSingletons.lookup(RuntimeJNIAccessSupport.class).register(AccessCondition.unconditional(), false, fields);
103109
}
104110

sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/hosted/RuntimeProxyCreation.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.graalvm.nativeimage.Platforms;
4646
import org.graalvm.nativeimage.dynamicaccess.ReflectiveAccess;
4747
import org.graalvm.nativeimage.dynamicaccess.AccessCondition;
48+
import org.graalvm.nativeimage.impl.APIDeprecationSupport;
4849
import org.graalvm.nativeimage.impl.RuntimeProxyCreationSupport;
4950

5051
/**
@@ -55,16 +56,19 @@
5556
@Platforms(Platform.HOSTED_ONLY.class)
5657
public final class RuntimeProxyCreation {
5758

59+
private static final APIDeprecationSupport deprecationFlag = ImageSingletons.lookup(APIDeprecationSupport.class);
60+
5861
/**
5962
* Enables registering specifications of {@link java.lang.reflect.Proxy} classes during the
6063
* image build so that matching proxy objects can be created at runtime. The proxy class is
6164
* fully specified by the interfaces it implements.
6265
* <p>
63-
* This API is deprecated; use {@link ReflectiveAccess} instead.
66+
* This API is deprecated; use the {@link ReflectiveAccess} instead.
6467
*
6568
* @since 22.3
6669
*/
6770
public static void register(Class<?>... interfaces) {
71+
deprecationFlag.printDeprecationWarning();
6872
ImageSingletons.lookup(RuntimeProxyCreationSupport.class).addProxyClass(AccessCondition.unconditional(), interfaces);
6973
}
7074

0 commit comments

Comments
 (0)