You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fory.apache.org by "mengnankkkk (via GitHub)" <gi...@apache.org> on 2025/10/04 15:02:59 UTC

[PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

mengnankkkk opened a new pull request, #2701:
URL: https://github.com/apache/fory/pull/2701

   <!--
   **Thanks for contributing to Apache Fory™.**
   
   **If this is your first time opening a PR on fory, you can refer to [CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md).**
   
   Contribution Checklist
   
       - The **Apache Fory™** community has requirements on the naming of pr titles. You can also find instructions in [CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md).
   
       - Apache Fory™ has a strong focus on performance. If the PR you submit will have an impact on performance, please benchmark it first and provide the benchmark result here.
   -->
   
   ## Why?
   
   <!-- Describe the purpose of this PR. -->
   
   ## What does this PR do?
   
   <!-- Describe the details of this PR. -->
   
   ## Related issues
   Close #2697 
   <!--
   Is there any related issue? If this PR closes them you say say fix/closes:
   
   - #xxxx0
   - #xxxx1
   - Fixes #xxxx2
   -->
   
   ## Does this PR introduce any user-facing change?
   
   <!--
   If any user-facing interface changes, please [open an issue](https://github.com/apache/fory/issues/new/choose) describing the need to do so and update the document if necessary.
   
   Delete section if not applicable.
   -->
   
   - [ ] Does this PR introduce any public API change?
   - [ ] Does this PR introduce any binary protocol compatibility change?
   
   ## Benchmark
   
   <!--
   When the PR has an impact on performance (if you don't know whether the PR will have an impact on performance, you can submit the PR first, and if it will have impact on performance, the code reviewer will explain it), be sure to attach a benchmark data here.
   
   Delete section if not applicable.
   -->
   


-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] feat(java): Add ForyFeature for GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2453789384


##########
integration_tests/graalvm_tests/src/main/java/org/apache/fory/graalvm/FeatureTestExample.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fory.graalvm;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import org.apache.fory.Fory;
+import org.apache.fory.config.Language;
+import org.apache.fory.util.GraalvmSupport;
+
+public class FeatureTestExample {
+
+  public static class PrivateConstructorClass {
+    private String value;
+
+    private PrivateConstructorClass() {
+      // Private constructor
+    }
+
+    public PrivateConstructorClass(String value) {
+      this.value = value;
+    }
+
+    public String getValue() {
+      return value;
+    }
+
+    public void setValue(String value) {
+      this.value = value;
+    }
+  }
+
+  // Test interface for proxy
+  public interface TestInterface {
+    String getValue();
+
+    void setValue(String value);
+  }
+
+  // Simple invocation handler
+  public static class TestInvocationHandler implements InvocationHandler {
+    private String value;
+
+    public TestInvocationHandler(String value) {
+      this.value = value;
+    }
+
+    @Override
+    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+      if ("getValue".equals(method.getName())) {
+        return value;
+      } else if ("setValue".equals(method.getName())) {
+        value = (String) args[0];
+        return null;
+      }
+      return null;
+    }
+  }
+
+  public static void main(String[] args) {
+    System.out.println("Testing Fory GraalVM Feature...");
+
+    Fory fory =
+        Fory.builder().withLanguage(Language.JAVA).withRefTracking(true).withCodegen(false).build();
+
+    fory.register(PrivateConstructorClass.class);
+    fory.register(TestInvocationHandler.class);
+
+    // Register proxy interface
+    GraalvmSupport.registerProxySupport(TestInterface.class);
+
+    try {
+      // Test 1: Serialize/deserialize class with private constructor
+      PrivateConstructorClass original = new PrivateConstructorClass("test-value");
+      byte[] serialized = fory.serialize(original);
+      PrivateConstructorClass deserialized = (PrivateConstructorClass) fory.deserialize(serialized);

Review Comment:
   Please also assert `fory.getClassResolver().getSerializer(PrivateConstructorClass.class) instanceof Generated`



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "mengnankkkk (via GitHub)" <gi...@apache.org>.
mengnankkkk commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2426664250


##########
java/fory-core/src/main/java/org/apache/fory/util/GraalvmSupport.java:
##########
@@ -145,4 +145,37 @@ public static boolean isRecordConstructorPublicAccessible(Class<?> type) {
     }
     return false;
   }
+
+  /**
+   * Checks if a class is problematic for object creation and requires special handling in GraalVM.
+   *
+   * <p>A class is considered problematic if it lacks a public no-arg constructor and would
+   * typically require ReflectionFactory or unsafe allocation for instantiation.
+   *
+   * @param type the class to check
+   * @return true if the class is problematic for creation, false otherwise
+   */
+  public static boolean isProblematicForCreation(Class<?> type) {

Review Comment:
   Ok. I. will do it  thanks for your codereview and suggestions 💕💕



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2411118935


##########
java/fory-core/src/main/resources/META-INF/native-image/org.apache.fory/fory-core/reflection-config.json:
##########
@@ -5,5 +5,18 @@
     "allPublicConstructors": true,
     "allDeclaredMethods": true,
     "allPublicMethods": true
+  },
+  {
+    "name": "jdk.internal.reflect.ReflectionFactory",

Review Comment:
   those methods are executed at graalvm build time, they won't be executed at graalvm runtime. It's unnecessary to add reflection-config.
   
   I think the key is find out why the generated constructor don't work



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2412975809


##########
java/fory-core/src/main/resources/META-INF/native-image/org.apache.fory/fory-core/reflection-config.json:
##########
@@ -5,5 +5,18 @@
     "allPublicConstructors": true,
     "allDeclaredMethods": true,
     "allPublicMethods": true
+  },
+  {
+    "name": "jdk.internal.reflect.ReflectionFactory",

Review Comment:
   Looks good to me overall. We can use Fory existing registry to discover user's registered types, and add necessary metadata to graalvm for those types, so at graalvm runtime, the object creation will work as expected. 
   
   The most critical graal-meta would be :
   - `proxy` related meta, so we can create JDK proxy at runtime without users to configure `proxy.json`
   - configure `unsafeAllocated` in reflect-meta.json
   



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] feat(java): Add ForyFeature for GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on PR #2701:
URL: https://github.com/apache/fory/pull/2701#issuecomment-3448415698

   Hi @mengnankkkk, thanks for your hard work and for letting me know the situation. I understand that you’ve spent quite a bit of time on this bug, and I appreciate the effort you’ve put in.
   
   I’ll take a look at your branch, refactor the code, and work on fixing the bug so we can get the CI tests to pass. Don’t worry about the current state — debugging can be tricky, and each attempt helps us better understand the problem.
   
   Thanks again for your contributions! I’ll update the PR once I’ve made the necessary changes.
   
   


-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2447073970


##########
java/fory-core/src/main/java/org/apache/fory/resolver/TypeResolver.java:
##########
@@ -670,6 +674,82 @@ public final MetaStringResolver getMetaStringResolver() {
     return metaStringResolver;
   }
 
+  /**
+   * 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. This should be called
+   * from {@link org.apache.fory.Fory#register} methods.
+   *
+   * @param cls the class to register
+   * @param configHash the configuration hash for the Fory instance
+   */
+  public static void registerClassForGraalvm(Class<?> cls, int configHash) {

Review Comment:
   ditto,and we can also remove `ForGraalvm` if we move those methods into `GraalvmSupport`



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] feat(java): Add ForyFeature for GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2455253972


##########
integration_tests/graalvm_tests/pom.xml:
##########
@@ -64,6 +64,12 @@
       <artifactId>fory-graalvm-feature</artifactId>
       <version>${project.version}</version>
     </dependency>
+    <dependency>
+      <groupId>junit</groupId>

Review Comment:
   We use testng in fory



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "mengnankkkk (via GitHub)" <gi...@apache.org>.
mengnankkkk commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2411152438


##########
java/fory-core/src/main/resources/META-INF/native-image/org.apache.fory/fory-core/reflection-config.json:
##########
@@ -5,5 +5,18 @@
     "allPublicConstructors": true,
     "allDeclaredMethods": true,
     "allPublicMethods": true
+  },
+  {
+    "name": "jdk.internal.reflect.ReflectionFactory",

Review Comment:
   I will try it💕💕



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2412768190


##########
java/fory-core/src/main/resources/META-INF/native-image/org.apache.fory/fory-core/reflection-config.json:
##########
@@ -5,5 +5,18 @@
     "allPublicConstructors": true,
     "allDeclaredMethods": true,
     "allPublicMethods": true
+  },
+  {
+    "name": "jdk.internal.reflect.ReflectionFactory",

Review Comment:
   Maybe we need to create a new maven module to imply a graalvm Feature for fory. In that feature, we can generate unsafe meta for type without public no argument constructor.



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] feat(java): Add ForyFeature for GraalVM Native Image [fory]

Posted by "mengnankkkk (via GitHub)" <gi...@apache.org>.
mengnankkkk commented on PR #2701:
URL: https://github.com/apache/fory/pull/2701#issuecomment-3448425340

   > Hi @mengnankkkk, thanks for your hard work and for letting me know the situation. I understand that you’ve spent quite a bit of time on this bug, and I appreciate the effort you’ve put in.
   > 
   > I’ll take a look at your branch, refactor the code, and work on fixing the bug so we can get the CI tests to pass. Don’t worry about the current state — debugging can be tricky, and each attempt helps us better understand the problem.
   > 
   > Thanks again for your contributions! I’ll update the PR once I’ve made the necessary changes.
   
   I'm very sorry. I pushed AI to find a solution to the problem, but it didn't seem to solve it and made the code look even more shitty. I'm very sorry./(ㄒoㄒ)/~~


-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on PR #2701:
URL: https://github.com/apache/fory/pull/2701#issuecomment-3372625110

   `ParentNoArgCtrObjectCreator` should be able to generate a constructor of parent class to create instance of subclass using `jdk.internal.reflect.ReflectionFactory`. It's strange why it can't work


-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "mengnankkkk (via GitHub)" <gi...@apache.org>.
mengnankkkk commented on PR #2701:
URL: https://github.com/apache/fory/pull/2701#issuecomment-3375623431

   I was wrong. I should not use unsafe to escape this problem. I should use GraalVM's reachability metadata to solve the problem of ReflectionFactory.


-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] feat(java): Add ForyFeature for GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2453781951


##########
integration_tests/graalvm_tests/src/main/resources/META-INF/native-image/org.apache.fory/graalvm_tests/native-image.properties:
##########
@@ -33,4 +33,6 @@ Args=-H:+ReportExceptionStackTraces \
   org.apache.fory.graalvm.CollectionExample,\
   org.apache.fory.graalvm.ArrayExample,\
   org.apache.fory.graalvm.Benchmark,\
-  org.apache.fory.graalvm.Main
+  org.apache.fory.graalvm.FeatureTestExample,\
+  org.apache.fory.graalvm.Main,\
+  org.apache.fory.util.GraalvmSupport$GraalvmClassRegistry

Review Comment:
   this should be moved into `native-image.properties` under fory-core



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] feat(java): Add ForyFeature for GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2453784332


##########
java/fory-graalvm-feature/src/test/java/org/apache/fory/graalvm/feature/ForyGraalVMFeatureTest.java:
##########
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fory.graalvm.feature;
+
+import static org.junit.Assert.*;
+
+import org.apache.fory.Fory;
+import org.apache.fory.util.GraalvmSupport;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ForyGraalVMFeatureTest {

Review Comment:
   This file tested nothing, you should move it into graalvm-tests



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] feat(java): Add ForyFeature for GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on PR #2701:
URL: https://github.com/apache/fory/pull/2701#issuecomment-3441338366

   <img width="2012" height="1262" alt="image" src="https://github.com/user-attachments/assets/77cac223-89bb-4423-bb81-7c306cec5e84" />
   you can make it use Unsafe for object allocation 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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2424629217


##########
java/fory-core/src/main/java/org/apache/fory/reflect/ObjectCreators.java:
##########
@@ -77,16 +77,47 @@ public static <T> ObjectCreator<T> getObjectCreator(Class<T> type) {
     return (ObjectCreator<T>) cache.get(type, () -> creategetObjectCreator(type));
   }
 
+  /**
+   * Checks if a class is problematic for object creation and requires special handling in GraalVM.
+   *
+   * <p>A class is considered problematic if it lacks a public no-arg constructor and would
+   * typically require ReflectionFactory or unsafe allocation for instantiation.
+   *
+   * @param type the class to check
+   * @return true if the class is problematic for creation, false otherwise
+   */
+  public static boolean isProblematicForCreation(Class<?> type) {
+    if (type.isInterface()
+        || java.lang.reflect.Modifier.isAbstract(type.getModifiers())
+        || type.isArray()
+        || type.isEnum()
+        || type.isAnonymousClass()
+        || type.isLocalClass()
+        || RecordUtils.isRecord(type)) {
+      return false;
+    }
+    Constructor<?>[] constructors = type.getDeclaredConstructors();
+    if (constructors.length == 0) {
+      return true;
+    }
+    for (Constructor<?> constructor : constructors) {
+      if (constructor.getParameterCount() == 0) {
+        return false;

Review Comment:
   And this API could be move to GraalvmSupport class



##########
java/fory-core/src/main/java/org/apache/fory/reflect/ObjectCreators.java:
##########
@@ -77,16 +77,47 @@ public static <T> ObjectCreator<T> getObjectCreator(Class<T> type) {
     return (ObjectCreator<T>) cache.get(type, () -> creategetObjectCreator(type));
   }
 
+  /**
+   * Checks if a class is problematic for object creation and requires special handling in GraalVM.
+   *
+   * <p>A class is considered problematic if it lacks a public no-arg constructor and would
+   * typically require ReflectionFactory or unsafe allocation for instantiation.
+   *
+   * @param type the class to check
+   * @return true if the class is problematic for creation, false otherwise
+   */
+  public static boolean isProblematicForCreation(Class<?> type) {
+    if (type.isInterface()
+        || java.lang.reflect.Modifier.isAbstract(type.getModifiers())
+        || type.isArray()
+        || type.isEnum()
+        || type.isAnonymousClass()
+        || type.isLocalClass()
+        || RecordUtils.isRecord(type)) {
+      return false;
+    }
+    Constructor<?>[] constructors = type.getDeclaredConstructors();
+    if (constructors.length == 0) {
+      return true;
+    }
+    for (Constructor<?> constructor : constructors) {
+      if (constructor.getParameterCount() == 0) {
+        return false;

Review Comment:
   And this API could be moved to GraalvmSupport class



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] feat(java): Add ForyFeature for GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2453785891


##########
java/pom.xml:
##########
@@ -92,7 +92,13 @@
         <jdk>[17,]</jdk>
       </activation>
       <modules>
+        <module>fory-core</module>

Review Comment:
   this is wrong, please revert it. Only `fory-simd` use JDK17+



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] feat(java): Add ForyFeature for GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2458501990


##########
java/fory-core/src/test/java/org/apache/fory/util/GraalvmSupportRecordTest.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fory.util;
+
+import org.apache.fory.util.record.RecordUtils;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class GraalvmSupportRecordTest {

Review Comment:
   I suggest move this file to `graalvm_tests`



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2422536204


##########
java/fory-core/src/main/java/org/apache/fory/Fory.java:
##########
@@ -89,6 +93,10 @@
 public final class Fory implements BaseFory {
   private static final Logger LOG = LoggerFactory.getLogger(Fory.class);
 
+  // Static collections for GraalVM Feature support

Review Comment:
   Could we remove those fields, `TypeResolver` already has static variable to capture registered classes and generated serializers



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2447071608


##########
java/fory-core/src/main/java/org/apache/fory/resolver/TypeResolver.java:
##########
@@ -670,6 +674,82 @@ public final MetaStringResolver getMetaStringResolver() {
     return metaStringResolver;
   }
 
+  /**
+   * Get all registered classes across all GraalVM registries for native image compilation.
+   *
+   * @return unmodifiable set of all registered classes
+   */
+  public static Set<Class<?>> getAllRegisteredClasses() {

Review Comment:
   How about movign those methods into GraalvmSupport.java, and we can register all needs info into GraalvmSupport in `TypeResolver#enableSerialziersCcmpiled`. In thsi wya, the API is more clean



##########
java/fory-core/src/main/java/org/apache/fory/resolver/TypeResolver.java:
##########
@@ -670,6 +674,82 @@ public final MetaStringResolver getMetaStringResolver() {
     return metaStringResolver;
   }
 
+  /**
+   * 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() {

Review Comment:
   ditto



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] feat(java): Add ForyFeature for GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang merged PR #2701:
URL: https://github.com/apache/fory/pull/2701


-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2428437538


##########
java/fory-core/src/main/java/org/apache/fory/Fory.java:
##########
@@ -177,11 +177,13 @@ public Fory(ForyBuilder builder, ClassLoader classLoader) {
   @Override
   public void register(Class<?> cls) {
     _getTypeResolver().register(cls);
+    TypeResolver.registerClassForGraalvm(cls, config.getConfigHash());

Review Comment:
   We don't need to handle this here. TypeResolver should do everything for registry. `ensureSerializersCompiled` will create serializer for every register class, you can add registerClassForGraalvm here



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] feat(java): Add ForyFeature for GraalVM Native Image [fory]

Posted by "mengnankkkk (via GitHub)" <gi...@apache.org>.
mengnankkkk commented on PR #2701:
URL: https://github.com/apache/fory/pull/2701#issuecomment-3441191320

   What should I do? I always encounter a configuration problem. When running in the graalvm environment, there is always a problem of native-image command parsing error. What should I do? I have tried many methods (crying)


-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] feat(java): Add ForyFeature for GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2455560139


##########
java/fory-core/src/main/java/org/apache/fory/util/GraalvmSupport.java:
##########
@@ -54,6 +65,103 @@ 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) {
+    if (!IN_GRAALVM_NATIVE_IMAGE) {
+      return;
+    }
+    GraalvmClassRegistry registry =
+        GRAALVM_REGISTRY.computeIfAbsent(configHash, k -> new GraalvmClassRegistry());
+    registry.registeredClasses.add(cls);
+  }
+
+  /**
+   * Register a proxy interface in the GraalVM registry for native image compilation.
+   *
+   * @param proxyInterface the proxy interface to register
+   * @param configHash the configuration hash for the Fory instance
+   */
+  public static void registerProxyInterfaceForGraalvm(Class<?> proxyInterface, int configHash) {

Review Comment:
   The class is already GraalvmSupport, we don't need to replicate `graalvm` in teh method name



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "mengnankkkk (via GitHub)" <gi...@apache.org>.
mengnankkkk closed pull request #2701: fix(java): fix bugs and enhanced error reminders  in GraalVM Native Image
URL: https://github.com/apache/fory/pull/2701


-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "mengnankkkk (via GitHub)" <gi...@apache.org>.
mengnankkkk commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2412897660


##########
java/fory-core/src/main/resources/META-INF/native-image/org.apache.fory/fory-core/reflection-config.json:
##########
@@ -5,5 +5,18 @@
     "allPublicConstructors": true,
     "allDeclaredMethods": true,
     "allPublicMethods": true
+  },
+  {
+    "name": "jdk.internal.reflect.ReflectionFactory",

Review Comment:
   We can create a fory-graalvm-feature module specifically to adapt to the GraalVM Native Image environment. They need to depend on both fory-core and fory-graalvm-feature in the project. When they run the native-image build command, GraalVM automatically discovers and runs ForyGraalVMFeature through Service Loader, obtains all registered classes in Fory, identifies those "problematic classes" that rely on ReflectionFactory in the JVM, and registers the "blank instance" creation capability with GraalVM for the "problematic classes". In order to ensure that the subsequent field filling is correct, all fields can be registered at the same time for reflective write operations. Provide an entry point in fory-core to switch to using ForyGraalVMFeature. fory-core needs to expose static methods such as isProblematicForCreation. This is my design. You can add to it.



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2424618684


##########
integration_tests/graalvm_tests/src/main/java/org/apache/fory/graalvm/FeatureTestExample.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fory.graalvm;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import org.apache.fory.Fory;
+import org.apache.fory.config.Language;
+
+public class FeatureTestExample {
+
+  // Test class with private constructor (problematic for creation)
+  public static class ProblematicClass {

Review Comment:
   How about naming to PrivateConstructorClass



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2424627489


##########
java/fory-core/src/main/java/org/apache/fory/reflect/ObjectCreators.java:
##########
@@ -77,16 +77,47 @@ public static <T> ObjectCreator<T> getObjectCreator(Class<T> type) {
     return (ObjectCreator<T>) cache.get(type, () -> creategetObjectCreator(type));
   }
 
+  /**
+   * Checks if a class is problematic for object creation and requires special handling in GraalVM.
+   *
+   * <p>A class is considered problematic if it lacks a public no-arg constructor and would
+   * typically require ReflectionFactory or unsafe allocation for instantiation.
+   *
+   * @param type the class to check
+   * @return true if the class is problematic for creation, false otherwise
+   */
+  public static boolean isProblematicForCreation(Class<?> type) {
+    if (type.isInterface()
+        || java.lang.reflect.Modifier.isAbstract(type.getModifiers())
+        || type.isArray()
+        || type.isEnum()
+        || type.isAnonymousClass()
+        || type.isLocalClass()
+        || RecordUtils.isRecord(type)) {
+      return false;
+    }
+    Constructor<?>[] constructors = type.getDeclaredConstructors();
+    if (constructors.length == 0) {
+      return true;
+    }
+    for (Constructor<?> constructor : constructors) {
+      if (constructor.getParameterCount() == 0) {
+        return false;

Review Comment:
   For JDK17+ record, if its constructor is public accessible, then it can be invoked by Fory



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on PR #2701:
URL: https://github.com/apache/fory/pull/2701#issuecomment-3407546898

   We have a `integration_tests/graalvm_tests/src/main/resources/META-INF/native-image/org.apache.fory/graalvm_tests/proxy-config.json` config, could we remvoe that in this PR?


-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "mengnankkkk (via GitHub)" <gi...@apache.org>.
mengnankkkk closed pull request #2701: fix(java): fix bugs and enhanced error reminders  in GraalVM Native Image
URL: https://github.com/apache/fory/pull/2701


-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] feat(java): Add ForyFeature for GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2459126874


##########
java/fory-core/src/main/java/org/apache/fory/serializer/ObjectStreamSerializer.java:
##########
@@ -80,10 +80,60 @@
 public class ObjectStreamSerializer extends AbstractObjectSerializer {
   private static final Logger LOG = LoggerFactory.getLogger(ObjectStreamSerializer.class);
 
-  private final SlotsInfo[] slotsInfos;
+  private final SlotInfo[] slotsInfos;
+
+  /**
+   * Interface for slot information used in ObjectStreamSerializer. This allows both full SlotsInfo
+   * and minimal MinimalSlotsInfo implementations.
+   */
+  private interface SlotInfo {
+    Class<?> getCls();
+
+    StreamClassInfo getStreamClassInfo();
+
+    CompatibleSerializerBase getSlotsSerializer();
+
+    ForyObjectOutputStream getObjectOutputStream();
+
+    ForyObjectInputStream getObjectInputStream();
+
+    ObjectArray getFieldPool();
+
+    ObjectIntMap<String> getFieldIndexMap();
+
+    FieldResolver getPutFieldsResolver();
+
+    CompatibleSerializer getCompatibleStreamSerializer();
+  }
+
+  /**
+   * Safe wrapper for ObjectStreamClass.lookup that handles GraalVM native image limitations. In
+   * GraalVM native image, ObjectStreamClass.lookup may fail for certain classes like Throwable due
+   * to missing SerializationConstructorAccessor. This method catches such exceptions and returns
+   * null, allowing the serializer to use alternative approaches like Unsafe.allocateInstance.
+   */
+  private static ObjectStreamClass safeObjectStreamClassLookup(Class<?> type) {
+    if (GraalvmSupport.isGraalRuntime()) {

Review Comment:
   Just use `GraalvmSupport.IS_GRAALVM_NATIVE_IMAGE`



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] feat(java): Add ForyFeature for GraalVM Native Image [fory]

Posted by "mengnankkkk (via GitHub)" <gi...@apache.org>.
mengnankkkk commented on PR #2701:
URL: https://github.com/apache/fory/pull/2701#issuecomment-3446792367

   @chaokunyang I'm very sorry. My current coding skills aren't enough to completely fix this bug, and I haven't passed the CI test. Could you please make some changes on my branch to fix this bug? I've tried many methods, but the files are messed up. I'm sorry that after nearly two weeks, I still haven't solved this bug. I'm very sorry. Could you please refactor and upgrade my messy code?


-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2434479653


##########
integration_tests/graalvm_tests/src/main/java/org/apache/fory/graalvm/FeatureTestExample.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fory.graalvm;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import org.apache.fory.Fory;
+import org.apache.fory.config.Language;
+import org.apache.fory.resolver.TypeResolver;
+
+public class FeatureTestExample {
+
+  public static class PrivateConstructorClass {
+    private String value;
+
+    private PrivateConstructorClass() {
+      // Private constructor
+    }
+
+    public PrivateConstructorClass(String value) {
+      this.value = value;
+    }
+
+    public String getValue() {
+      return value;
+    }
+
+    public void setValue(String value) {
+      this.value = value;
+    }
+  }
+
+  // Test interface for proxy
+  public interface TestInterface {
+    String getValue();
+
+    void setValue(String value);
+  }
+
+  // Simple invocation handler
+  public static class TestInvocationHandler implements InvocationHandler {
+    private String value;
+
+    public TestInvocationHandler(String value) {
+      this.value = value;
+    }
+
+    @Override
+    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+      if ("getValue".equals(method.getName())) {
+        return value;
+      } else if ("setValue".equals(method.getName())) {
+        value = (String) args[0];
+        return null;
+      }
+      return null;
+    }
+  }
+
+  public static void main(String[] args) {
+    System.out.println("Testing Fory GraalVM Feature...");
+
+    Fory fory =
+        Fory.builder().withLanguage(Language.JAVA).withRefTracking(true).withCodegen(false).build();
+
+    fory.register(PrivateConstructorClass.class);
+    fory.register(TestInvocationHandler.class);
+
+    // Register proxy interface
+    TypeResolver.addProxyInterface(TestInterface.class);
+
+    try {
+      // Test 1: Serialize/deserialize class with private constructor
+      PrivateConstructorClass original = new PrivateConstructorClass("test-value");
+      byte[] serialized = fory.serialize(original);
+      PrivateConstructorClass deserialized = (PrivateConstructorClass) fory.deserialize(serialized);
+
+      if (!"test-value".equals(deserialized.getValue())) {
+        throw new RuntimeException("Private constructor class test failed");
+      }
+      System.out.println("Private constructor class serialization test passed");
+
+      // Test 2: Serialize/deserialize proxy object
+      TestInterface proxy =
+          (TestInterface)
+              Proxy.newProxyInstance(
+                  TestInterface.class.getClassLoader(),
+                  new Class[] {TestInterface.class},
+                  new TestInvocationHandler("proxy-value"));
+
+      byte[] proxySerialised = fory.serialize(proxy);
+      TestInterface deserializedProxy = (TestInterface) fory.deserialize(proxySerialised);
+
+      if (!"proxy-value".equals(deserializedProxy.getValue())) {
+        throw new RuntimeException("Proxy test failed");
+      }
+      System.out.println("Proxy serialization test passed");
+
+      System.out.println("All GraalVM Feature tests passed!");
+
+    } catch (Exception e) {
+      System.err.println("GraalVM Feature test failed: " + e.getMessage());
+      e.printStackTrace();
+      System.exit(1);

Review Comment:
   ```suggestion
         throw new RuntimeException(e);
   ```



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2426658818


##########
java/fory-core/src/main/java/org/apache/fory/util/GraalvmSupport.java:
##########
@@ -145,4 +145,37 @@ public static boolean isRecordConstructorPublicAccessible(Class<?> type) {
     }
     return false;
   }
+
+  /**
+   * Checks if a class is problematic for object creation and requires special handling in GraalVM.
+   *
+   * <p>A class is considered problematic if it lacks a public no-arg constructor and would
+   * typically require ReflectionFactory or unsafe allocation for instantiation.
+   *
+   * @param type the class to check
+   * @return true if the class is problematic for creation, false otherwise
+   */
+  public static boolean isProblematicForCreation(Class<?> type) {

Review Comment:
   ```suggestion
     public static boolean needReflectionRegisterForCreation(Class<?> type) {
   ```



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] feat(java): Add ForyFeature for GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2455565226


##########
java/fory-core/src/test/java/org/apache/fory/resolver/ClassResolverTest.java:
##########
@@ -539,4 +540,44 @@ public void testAbstractCustomSerializer() {
         fory.getClassResolver().getSerializer(abs2Test.getClass()).getClass(),
         AbstractCustomSerializer.class);
   }
+
+  static class GraalvmRegistrationBean {
+    int value;
+  }
+
+  @Test
+  public void testEnsureSerializersCompiledRegistersClassesForGraalvm() {

Review Comment:
   Move this test to graavm_tests



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] feat(java): Add ForyFeature for GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2458504760


##########
java/fory-graalvm-feature/src/main/java/org/apache/fory/graalvm/feature/ForyGraalVMFeature.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fory.graalvm.feature;
+
+import java.lang.reflect.Field;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.fory.util.GraalvmSupport;
+import org.graalvm.nativeimage.hosted.Feature;
+import org.graalvm.nativeimage.hosted.RuntimeReflection;
+
+/**
+ * GraalVM Feature for Apache Fory serialization framework.
+ *
+ * <p>This feature automatically registers necessary metadata for GraalVM native image compilation
+ * to ensure Fory serialization works correctly at runtime. It handles:
+ *
+ * <ul>
+ *   <li>Registering problematic classes for unsafe allocation

Review Comment:
   don't use `problematic` across this pr



##########
java/fory-core/src/test/java/org/apache/fory/util/GraalvmSupportRecordTest.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fory.util;
+
+import org.apache.fory.util.record.RecordUtils;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class GraalvmSupportRecordTest {

Review Comment:
   I suggest new move this file to `graalvm_tests`



##########
integration_tests/graalvm_tests/pom.xml:
##########
@@ -59,6 +58,22 @@
       <artifactId>fory-core</artifactId>
       <version>${project.version}</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.fory</groupId>
+      <artifactId>fory-graalvm-feature</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.graalvm.sdk</groupId>

Review Comment:
   `fory-graalvm-feature` should alreay has `org.graalvm.sdk` as provided , why add it again here? 



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2447075077


##########
integration_tests/graalvm_tests/src/main/java/org/apache/fory/graalvm/FeatureTestExample.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fory.graalvm;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import org.apache.fory.Fory;
+import org.apache.fory.config.Language;
+import org.apache.fory.resolver.TypeResolver;
+
+public class FeatureTestExample {
+
+  public static class PrivateConstructorClass {
+    private String value;
+
+    private PrivateConstructorClass() {
+      // Private constructor
+    }
+
+    public PrivateConstructorClass(String value) {
+      this.value = value;
+    }
+
+    public String getValue() {
+      return value;
+    }
+
+    public void setValue(String value) {
+      this.value = value;
+    }
+  }
+
+  // Test interface for proxy
+  public interface TestInterface {
+    String getValue();
+
+    void setValue(String value);
+  }
+
+  // Simple invocation handler
+  public static class TestInvocationHandler implements InvocationHandler {
+    private String value;
+
+    public TestInvocationHandler(String value) {
+      this.value = value;
+    }
+
+    @Override
+    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+      if ("getValue".equals(method.getName())) {
+        return value;
+      } else if ("setValue".equals(method.getName())) {
+        value = (String) args[0];
+        return null;
+      }
+      return null;
+    }
+  }
+
+  public static void main(String[] args) {
+    System.out.println("Testing Fory GraalVM Feature...");
+
+    Fory fory =
+        Fory.builder().withLanguage(Language.JAVA).withRefTracking(true).withCodegen(false).build();
+
+    fory.register(PrivateConstructorClass.class);
+    fory.register(TestInvocationHandler.class);
+
+    // Register proxy interface
+    TypeResolver.addProxyInterface(TestInterface.class);

Review Comment:
   ```suggestion
       GraalvmSupport.registerProxySupport(TestInterface.class);
   ```



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "mengnankkkk (via GitHub)" <gi...@apache.org>.
mengnankkkk commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2412546990


##########
java/fory-core/src/main/resources/META-INF/native-image/org.apache.fory/fory-core/reflection-config.json:
##########
@@ -5,5 +5,18 @@
     "allPublicConstructors": true,
     "allDeclaredMethods": true,
     "allPublicMethods": true
+  },
+  {
+    "name": "jdk.internal.reflect.ReflectionFactory",

Review Comment:
   > those methods are executed at graalvm build time, they won't be executed at graalvm runtime. It's unnecessary to add reflection-config.
   > 
   > I think the key is find out why the generated constructor don't work
   I found the problem:
   When GraalVM's AOT compiler attempts to statically compile this "handle" into native code, the constructor in the final executable file is actually corrupted and unusable because the dynamic JVM mechanism behind it does not exist in GraalVM's minimalist runtime (Substrate VM).
   I think it's possible to use the Unsafe downgrade solution exclusively in GraalVM Native Images. Please share your understanding and solution with me, and I'll consider it.



##########
java/fory-core/src/main/resources/META-INF/native-image/org.apache.fory/fory-core/reflection-config.json:
##########
@@ -5,5 +5,18 @@
     "allPublicConstructors": true,
     "allDeclaredMethods": true,
     "allPublicMethods": true
+  },
+  {
+    "name": "jdk.internal.reflect.ReflectionFactory",

Review Comment:
   > those methods are executed at graalvm build time, they won't be executed at graalvm runtime. It's unnecessary to add reflection-config.
   > 
   > I think the key is find out why the generated constructor don't work
   
   
   
   I found the problem:
   When GraalVM's AOT compiler attempts to statically compile this "handle" into native code, the constructor in the final executable file is actually corrupted and unusable because the dynamic JVM mechanism behind it does not exist in GraalVM's minimalist runtime (Substrate VM).
   I think it's possible to use the Unsafe downgrade solution exclusively in GraalVM Native Images. Please share your understanding and solution with me, and I'll consider it.



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2424619751


##########
integration_tests/graalvm_tests/src/main/java/org/apache/fory/graalvm/FeatureTestExample.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fory.graalvm;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import org.apache.fory.Fory;
+import org.apache.fory.config.Language;
+
+public class FeatureTestExample {
+
+  // Test class with private constructor (problematic for creation)
+  public static class ProblematicClass {
+    private String value;
+
+    private ProblematicClass() {
+      // Private constructor
+    }
+
+    public ProblematicClass(String value) {
+      this.value = value;
+    }
+
+    public String getValue() {
+      return value;
+    }
+
+    public void setValue(String value) {
+      this.value = value;
+    }
+  }
+
+  // Test interface for proxy
+  public interface TestInterface {
+    String getValue();
+
+    void setValue(String value);
+  }
+
+  // Simple invocation handler
+  public static class TestInvocationHandler implements InvocationHandler {
+    private String value;
+
+    public TestInvocationHandler(String value) {
+      this.value = value;
+    }
+
+    @Override
+    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+      if ("getValue".equals(method.getName())) {
+        return value;
+      } else if ("setValue".equals(method.getName())) {
+        value = (String) args[0];
+        return null;
+      }
+      return null;
+    }
+  }
+
+  public static void main(String[] args) {
+    System.out.println("Testing Fory GraalVM Feature...");
+
+    Fory fory =
+        Fory.builder().withLanguage(Language.JAVA).withRefTracking(true).withCodegen(false).build();
+
+    fory.register(ProblematicClass.class);
+    fory.register(TestInvocationHandler.class);
+
+    // Register proxy interface
+    Fory.addProxyInterface(TestInterface.class);
+
+    try {
+      // Test 1: Serialize/deserialize problematic class
+      ProblematicClass original = new ProblematicClass("test-value");
+      byte[] serialized = fory.serialize(original);
+      ProblematicClass deserialized = (ProblematicClass) fory.deserialize(serialized);
+
+      if (!"test-value".equals(deserialized.getValue())) {
+        throw new RuntimeException("Problematic class test failed");
+      }
+      System.out.println("✓ Problematic class serialization test passed");

Review Comment:
   ditto, don't use Problematic, since it's supproted by fory now with this PR



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): fix bugs and enhanced error reminders in GraalVM Native Image [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2701:
URL: https://github.com/apache/fory/pull/2701#discussion_r2424623491


##########
java/fory-core/src/main/java/org/apache/fory/Fory.java:
##########
@@ -1764,4 +1768,47 @@ public MetaCompressor getMetaCompressor() {
   public static ForyBuilder builder() {
     return new ForyBuilder();
   }
+
+  /**
+   * Get all registered classes for GraalVM native image compilation. This is a convenience method
+   * that delegates to {@link TypeResolver#getAllRegisteredClasses()}.
+   *
+   * @return unmodifiable set of all registered classes
+   */
+  public static Set<Class<?>> getRegisteredClasses() {
+    return TypeResolver.getAllRegisteredClasses();
+  }
+
+  /**
+   * Get all registered proxy interfaces for GraalVM native image compilation. This is a convenience
+   * method that delegates to {@link TypeResolver#getAllProxyInterfaces()}.
+   *
+   * @return unmodifiable set of all registered proxy interfaces
+   */
+  public static Set<Class<?>> getProxyInterfaces() {
+    return TypeResolver.getAllProxyInterfaces();
+  }
+
+  /**
+   * Register a proxy interface for GraalVM native image compilation. This is a convenience method
+   * that delegates to {@link TypeResolver#registerProxyInterfaceForGraalvm}.
+   *
+   * <p>Note: This registers the proxy interface globally across all Fory configurations. If you
+   * need per-configuration registration, use the TypeResolver methods directly.
+   *
+   * @param proxyInterface the proxy interface to register
+   * @throws NullPointerException if proxyInterface is null
+   * @throws IllegalArgumentException if proxyInterface is not an interface
+   */
+  public static void addProxyInterface(Class<?> proxyInterface) {

Review Comment:
   I prefer not adding API to Fory, since those API are just used by graalvm. We could let it at TypeResolver, and you invoke TypeResolver API directly in GraalVMmFeature



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org