chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2448809698


##########
java/fory-core/src/main/java/org/apache/fory/util/GraalvmSupport.java:
##########
@@ -54,6 +65,97 @@ public static boolean isGraalRuntime() {
         && 
GRAAL_IMAGE_RUNTIME.equals(System.getProperty(GRAAL_IMAGE_CODE_KEY));
   }
 
+  /**
+   * Returns all classes registered for GraalVM native image compilation 
across all configurations.
+   */
+  public static Set<Class<?>> getRegisteredClasses() {
+    return getAllRegisteredClasses();
+  }
+
+  /** Returns all proxy interfaces registered for GraalVM native image 
compilation. */
+  public static Set<Class<?>> getProxyInterfaces() {
+    return getAllProxyInterfaces();
+  }
+
+  /** Clears all GraalVM native image registrations. Primarily for testing 
purposes. */
+  public static void clearRegistrations() {
+    clearGraalvmRegistrations();
+  }
+
+  /**
+   * Get all registered classes across all GraalVM registries for native image 
compilation.
+   *
+   * @return unmodifiable set of all registered classes
+   */
+  public static Set<Class<?>> getAllRegisteredClasses() {
+    Set<Class<?>> allClasses = ConcurrentHashMap.newKeySet();
+    for (GraalvmClassRegistry registry : GRAALVM_REGISTRY.values()) {
+      allClasses.addAll(registry.registeredClasses);
+    }
+    return Collections.unmodifiableSet(allClasses);
+  }
+
+  /**
+   * Get all registered proxy interfaces across all GraalVM registries for 
native image compilation.
+   *
+   * @return unmodifiable set of all registered proxy interfaces
+   */
+  public static Set<Class<?>> getAllProxyInterfaces() {
+    Set<Class<?>> allInterfaces = ConcurrentHashMap.newKeySet();
+    for (GraalvmClassRegistry registry : GRAALVM_REGISTRY.values()) {
+      allInterfaces.addAll(registry.proxyInterfaces);
+    }
+    return Collections.unmodifiableSet(allInterfaces);
+  }
+
+  /**
+   * Register a class in the GraalVM registry for native image compilation.
+   *
+   * @param cls the class to register
+   * @param configHash the configuration hash for the Fory instance
+   */
+  public static void registerClassForGraalvm(Class<?> cls, int configHash) {
+    GraalvmClassRegistry registry =

Review Comment:
   Needs a check `IS_GRAALVM_NATIVE_IMAGE`, if not, this should be a no-op. 
Otherwise it hold strong reference to class, which will make class gc not work.
   
   Please check whether similiar issues exist too



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to