Skip to content

Conversation

@tnikolai2
Copy link
Contributor

Lambda expressions are replaced by classes because GraalVM Native Image does not support the use of lambda expressions in jni callback functions.

Also need add to jni-config.json:

[
  {
    "name": "org.eclipse.swt.browser.Edge$HandleCoreWebView2SwtCallback",
    "methods": [
      {
        "name": "Invoke",
        "parameterTypes": ["long", "long"]
      }
    ]
  },
  {
    "name": "org.eclipse.swt.browser.Edge$HandleCoreWebView2SwtHost",
    "methods": [
      {
        "name": "CallJava",
        "parameterTypes": ["int", "long", "long"]
      }
    ]
  }
]

@github-actions
Copy link
Contributor

github-actions bot commented Jun 8, 2025

Test Results

   545 files  ±0     545 suites  ±0   29m 35s ⏱️ + 1m 55s
 4 400 tests ±0   4 382 ✅ ±0   18 💤 ±0  0 ❌ ±0 
16 727 runs  ±0  16 587 ✅ ±0  140 💤 ±0  0 ❌ ±0 

Results for commit 64562d5. ± Comparison against base commit 18eaec6.

♻️ This comment has been updated with latest results.

@merks merks requested a review from sratz June 8, 2025 05:45
Copy link
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution! This looks like a proper refactoring to me and if that helps to use Edge with GraalVM, that's of course fine.

@tnikolai2 can please properly format the lines of code that you have touched? In particular, the added lines use whitespaces for indentation while the surrounding code uses tabs. And it would be great if you could use a more expressive headline in your commit than "Update Edge.java".

You also refer to the necessity to add a jni-config.json. Is that something that needs to be done locally in an application executed on GraalVM? In that case, it might make sense that we add this specific knowledge about usage with GraalVM to the FAQ: https://github.com/eclipse-platform/eclipse.platform/blob/master/docs/FAQ/FAQ_How_do_I_use_Edge-IE_as_the_Browser's_underlying_renderer.md

@tnikolai2
Copy link
Contributor Author

I fix whitespaces.


If complile with GraalVM with mvn -Pnative package
will be many problems with java.lang.ClassNotFoundException. And this problem is not limited to the browser.

To fix java.lang.ClassNotFoundException, need provide reachability metadata files (e.g. reachability-metadata.json or legacy jni-config.json)
It must be placed under META-INF/native-image/<groupId>/<artifactId>/
This can be done either in the user project or inside a library, or both.

These metadata files can be auto-generated by running the application with the native image agent:
java -agentlib:native-image-agent=config-output-dir=./native-config -jar sample.jar

However, due to limitations in GraalVM, inline lambdas cannot be referenced in reachability metadata.
To address this, I replaced lambdas with separate inner classes.

But compiling with GraalVM and creating reachability metadata it is a big separate task.

@tnikolai2 tnikolai2 requested a review from HeikoKlare June 11, 2025 17:04
@tnikolai2
Copy link
Contributor Author

tnikolai2 commented Jun 12, 2025

Here is an example for Windows:
SequrFlySWT1.zip

target/SequrFly-1.0-SNAPSHOT-jar-with-dependencies.jar - full jar with updated Edge.java or can generate with mvn clean package


Set env variables

Set c compiler settings C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat
SET JAVA_HOME=path to GRAALVM
SET GRAALVM_HOME=path to GRAALVM

Use GraalVM for windows 64, java 24
GraalVM support only Visual Studio compiler!
Install visualstudio

Select the Desktop development with C++ checkbox in the main installation window. On the right side under Installation Details, make sure that the two requirements, Windows 11 SDK and MSVC (…) C++ x64/x86 build tools, are selected.
See Instructions


Gen native-config\reachability-metadata.json

%GRAALVM_HOME%\bin\java -agentlib:native-image-agent=config-output-dir=./native-config -jar target/SequrFly-1.0-SNAPSHOT-jar-with-dependencies.jar


build native image

%GRAALVM_HOME%\bin\native-image -jar target\SequrFly-1.0-SNAPSHOT-jar-with-dependencies.jar sequrfly --verbose -H:+ForeignAPISupport -H:+UnlockExperimentalVMOptions --no-fallback -H:ConfigurationFileDirectories=./native-config -Os -H:+ReportExceptionStackTraces -H:-ReduceImplicitExceptionStackTraceInformation -H:Class=org.mkura.seq.Main


run sequrfly.exe

@tnikolai2
Copy link
Contributor Author

If use original org.eclipse.swt.win32.win32.x86_64 3.129.0

need also add native-config\reflect-config.json

[
  {
    "name": "sun.security.x509.X509CertInfo",
    "allDeclaredFields": true,
    "allDeclaredMethods": true,
    "allDeclaredConstructors": true
  },
  {
    "name": "sun.security.x509.SubjectKeyIdentifierExtension",
    "allDeclaredConstructors": true,
    "allDeclaredMethods": true,
    "allDeclaredFields": true
  },
  {
    "name": "sun.security.x509.BasicConstraintsExtension",
    "allDeclaredMethods": true,
    "allDeclaredFields": true
  },
  {
    "name": "sun.security.x509.X509CertImpl",
    "allDeclaredConstructors": true,
    "allDeclaredMethods": true,
    "allDeclaredFields": true
  }
]

But anyway will appear error:

Exception in thread "main" java.lang.NoSuchMethodError: org.eclipse.swt.browser.Edge$$Lambda/0x3f6355f8138fb3ac4de8a85d8a641fae0.Invoke(JJ)I
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions$Support.getMethodID(JNIFunctions.java:1853)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions$Support.getMethodID(JNIFunctions.java:1838)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions.GetMethodID(JNIFunctions.java:443)
        at org.eclipse.swt.internal.ole.win32.COM.CreateSwtWebView2Callback(Native Method)
        at org.eclipse.swt.browser.Edge.newCallback(Edge.java:235)
        at org.eclipse.swt.browser.Edge.callAndWait(Edge.java:255)
        at org.eclipse.swt.browser.Edge.createEnvironment(Edge.java:587)
        at org.eclipse.swt.browser.Edge.createInstance(Edge.java:634)
        at org.eclipse.swt.browser.Edge.create(Edge.java:630)
        at org.eclipse.swt.browser.Browser.<init>(Browser.java:99)
        at org.mkura.seq.Main.main(Main.java:26)
        at [email protected]/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)

This cannot be fixed without changing Edge.java.

Copy link
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the explanations!
From my side, this looks fine now.
@sratz do you have any comments here?

Copy link
Member

@sratz sratz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me as well.

Would it make sense to add a small javadoc comment to the classes reminding that they should

  • not be converted to lambdas
  • ideally not be renamed to maximize compatibility
    ?

Contributes to supporting native images (GraalVM) for Edge.
@HeikoKlare
Copy link
Contributor

Would it make sense to add a small javadoc comment to the classes reminding that they should

  • not be converted to lambdas
  • ideally not be renamed to maximize compatibility
    ?

That definitely makes sense. I have just added comments to the two classes (also including references to this PR) and updated the PR accordingly.

@HeikoKlare HeikoKlare merged commit 649bb49 into eclipse-platform:master Jun 16, 2025
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants