-
Couldn't load subscription status.
- Fork 320
feat(java): Add ForyFeature for GraalVM Native Image #2701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mengnankkkk
wants to merge
50
commits into
apache:main
Choose a base branch
from
mengnankkkk:fix-mengnankk
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
ce38d2a
feat: add fory-graalvm-feature
mengnankkkk c8be5a3
fix: ci bug
mengnankkkk 8d10234
fix: ci bugs
mengnankkkk 9caacb7
fix: checkstyle
mengnankkkk 2e78cdf
Update pom.xml
mengnankkkk de00781
fix: ci bugs
mengnankkkk ed2b97a
fix: ci bug
mengnankkkk 6960c25
Merge branch 'main' into fix-mengnankk
mengnankkkk 191d2a8
Merge branch 'main' into fix-mengnankk
mengnankkkk 3a261fc
fix: ci bugs
mengnankkkk 0c5e82b
feat: fix Timing issue in GraalVM Feature
mengnankkkk 1592b3a
feat: remove static fields
mengnankkkk ab25f6d
fix: chectstyle
mengnankkkk e9f8ef4
fix: Api bug
mengnankkkk 21d7de8
fix: adapt jdk17
mengnankkkk 56e00e7
fix: adapt jdk17
mengnankkkk 95abbde
Merge branch 'main' into fix-mengnankk
mengnankkkk 021b1c5
fix:APi moved to GraalvmSupport
mengnankkkk 25d3203
Update java/fory-core/src/main/java/org/apache/fory/util/GraalvmSuppo…
mengnankkkk f896fef
fix: replace name
mengnankkkk e4a9852
fix: checkstyle
mengnankkkk 39ad1b7
fix: move registerClassForGraalvm
mengnankkkk d5c62e5
fix: ci test bug
mengnankkkk fa7c904
Update integration_tests/graalvm_tests/src/main/java/org/apache/fory/…
mengnankkkk 9db3ce4
fix: move something to GraalvmSupport
mengnankkkk 4ef6f86
Merge branch 'main' into fix-mengnankk
mengnankkkk e39fff8
fix: only init in Graalvm
mengnankkkk cf7f88d
fix: test up
mengnankkkk 761dc74
fix: modules bug
mengnankkkk f079030
fix: pom test
mengnankkkk 9984a8f
fix: pom bug
mengnankkkk 5992a1c
Update pom.xml
mengnankkkk 545bb13
fix: pom.xml
mengnankkkk d3d0e2b
fix: test bugs
mengnankkkk 11e4d95
Update native-image.properties
mengnankkkk cb789a5
fix: move someting
mengnankkkk 69f3a25
Update pom.xml
mengnankkkk d276915
feat: replace junit
mengnankkkk 23c81c9
fix: something error
mengnankkkk 332c960
fix: test in graalvm
mengnankkkk e787e3f
fix: test
mengnankkkk 287df20
fix: use unsafe to solve
mengnankkkk b1cb3c8
fix: add ObjectCreator and ObjectCreators imports and use interface i…
mengnankkkk 7bb71eb
style: apply code formatting with spotless
mengnankkkk 21cd616
docs: add missing Javadoc comments for inner classes
mengnankkkk fe8aaa7
fix: configure javadoc plugin to handle incubating modules in GraalVM
mengnankkkk 7643cec
fix: ci bug
mengnankkkk bb3c396
fix: ci bug from pom
mengnankkkk 4114145
fix: ci bug use unsafe
mengnankkkk 7bc5d40
fix: ci bug?
mengnankkkk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
...gration_tests/graalvm_tests/src/main/java/org/apache/fory/graalvm/FeatureTestExample.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"); | ||
mengnankkkk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // 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); | ||
mengnankkkk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.