Skip to content
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

Support jdk11 #208

Merged
merged 3 commits into from Jan 18, 2023
Merged

Support jdk11 #208

merged 3 commits into from Jan 18, 2023

Conversation

Zwiterrion
Copy link
Contributor

Hi,

We want to use Extism on our project Otoroshi but we need to run it on jdk11

This pull request makes everything run smoothly on jdk11

If you have any suggestion about this pull request, i'm open to it

Thanks for your time

@@ -28,7 +28,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
java-version: '11'
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we perhaps setup a matrix here and test on both versions, or should we just be testing the lowest version and assuming the latest version is ok? I'm a bit unsure about what the best strategy is here for java.

Copy link
Member

Choose a reason for hiding this comment

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

I think having a matrix, consisting of the minimum supported version (v11 with this change) and at least a couple more recent versions (including the most recent version, v17 prior to this change) would be a good idea. The evolution of Java between version 11 and 17 is not something I am familiar with though, so this could be an impossible request. Feedback appreciated!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to use a version of Extism compiled with jdk17 on a jvm running on 11, and of course, I got the following error:

java.lang.RuntimeException: java.lang.UnsupportedClassVersionError: 
org/extism/sdk/wasm/WasmSourceResolver has been compiled by a more recent 
version of the Java Runtime (class file version 61.0), 
this version of the Java Runtime only recognizes class file versions up to 55.0

The solution may be to compile the library in two versions using a java version array in github actions..

Copy link
Member

Choose a reason for hiding this comment

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

Yea, I think the array of versions makes sense. I think we'd also need to inject that version from the matrix into the pom.xml on CI before running it though, right? Maybe other places too?

java/pom.xml Show resolved Hide resolved
@bhelx
Copy link
Contributor

bhelx commented Jan 9, 2023

Thanks @Zwiterrion !

@nilslice
Copy link
Member

nilslice commented Jan 10, 2023

@Zwiterrion - I've added the matrix for version testing in this branch: https://github.com/extism/extism/tree/test-java-versions

Within that new branch, I've updated the CI to manipulate pom.xml with the version being tested, but not sure if there are other files that need similar changes. Would you be able to rebase your PR off that branch and push to see if your current changes work across these versions too?

I've got it set up to run versions 8, 11, and 17. But I'm not sure we need to go down to 8.. just figured it would be a good experiment. Please advise which version support you think is worth supporting!

@bhelx
Copy link
Contributor

bhelx commented Jan 10, 2023

Perhaps @thomasdarimont has an opinion on this PR.

I support adding more version to the test matrix. But when it comes to publishing jars it gets unclear to me what the consequences are. I think priorities, in this order, would be:

  1. Support as many JVM versions as possible for our users
  2. Keep the build and release system as simple as possible
  3. Allow us to write the source in the newest language but still target older JVMs.

@thomasdarimont
Copy link
Contributor

Thanks for the ping. I think having support for JDK 11 is fine if we want to keep the JNA library for accessing the extism native lib.

So I'm fine with downgrading the current JDK version to 11.

Perhaps at a later stage we could ditch the JNA library and leverage the FFI support that's coming to the JDK.
I'm currently experimenting with leveraging the native FFI support from project panama that's already available with Java 19 and it already works quite well. JDK 21 will then be the next LTS (long term support) release for Java that will provide native support for FFI integrations.

Copy link
Contributor

@thomasdarimont thomasdarimont left a comment

Choose a reason for hiding this comment

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

A few remarks.

public record ManifestHttpRequest(String url, Map<String, String> header, String method) {
public class ManifestHttpRequest {

private String url;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private String url;
private final String url;


private String url;

private Map<String, String> header;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private Map<String, String> header;
private final Map<String, String> header;


private Map<String, String> header;

private String method;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private String method;
private final String method;

@@ -3,6 +3,12 @@
import java.util.Map;

// FIXME remove this and related stuff if not supported in java-sdk
public record ManifestHttpRequest(String url, Map<String, String> header, String method) {
public class ManifestHttpRequest {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd make the fields final, create accessor methods and create a constructor for passing the required parameters in.

public record MemoryOptions(@SerializedName("max") Integer max) {
public class MemoryOptions {

private @SerializedName("max") Integer max;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private @SerializedName("max") Integer max;
@SerializedName("max")
private final Integer max;

@Override
public String hash() {
return hash;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

provide an accessor method for data.

public record PathWasmSource(String name, String path, String hash) implements WasmSource {
public class PathWasmSource implements WasmSource {

private String name;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private String name;
private final String name;


private String name;

private String path;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private String path;
private final String path;


private String path;

private String hash;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private String hash;
private final String hash;

@Override
public String hash() {
return hash;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Provide an accessor method for path.

@chabala
Copy link

chabala commented Jan 11, 2023

@nilslice regarding:

I think we'd also need to inject that version from the matrix into the pom.xml on CI before running it though, right?

and

I've added the matrix for version testing in this branch: https://github.com/extism/extism/tree/test-java-versions

Within that new branch, I've updated the CI to manipulate pom.xml with the version being tested, but not sure if there are other files that need similar changes.

I don't think that's a good idea. Java is backward compatible in the sense that newer JREs can recognize older bytecode, but not vice versa. The pom.xml should contain the oldest version the project targets, and the produced JAR tested on multiple JRE versions, not changed on the fly and built multiple times. The JAR built with a pom specifying 17 will absolutely fail on earlier versions as @Zwiterrion noted.

@nilslice
Copy link
Member

@chabala - 😄 uh oh, my "I don't know Java" is showing...

I just wanted to make sure we continue to test newer versions as well. I assumed we'd need to update the pom.xml to coincide with the version of Java being used, but if that's not the case then that simplifies things!

@chabala
Copy link

chabala commented Jan 11, 2023

No worries 😆 I figured I'd chime in as things looked to be going in a weird direction. I had asked about why Java 17? in the r/java announcement post, so I figured I'd check in on how supporting earlier versions was going. I'd support your idea of going as far back as version 8 as well, unless you have other requirements that need newer language features; 8 will be in use for a long time yet.

@thomasdarimont
Copy link
Contributor

I suggest using at least Java 11. Java 8 is now almost 10 years old and many Java open source projects have removed support for Java 8.

@nilslice
Copy link
Member

I suggest using at least Java 11. Java 8 is now almost 10 years old and many Java open source projects have removed support for Java 8.

This sounds good to me. Unless someone feels very strongly about supporting Java 8, and would like to test & make whatever library changes are needed to support it, I think we can use Java 11 as the minimum supported version.

@nilslice
Copy link
Member

@Zwiterrion - thank you for your work on this! When you have a minute, would you be able to include the changes suggested by @thomasdarimont? Thanks to my new knowledge from @chabala, the pom.xml seems like it's already good as-is in your branch, and we should just add the matrix from my branch to include [11, 17] versions in the Java CI workflow.

What do you think?

@Zwiterrion
Copy link
Contributor Author

@nilslice - It's fine for me, i'll try to include all changes suggested by @thomasdarimont on my branch.

@nilslice
Copy link
Member

Hi @Zwiterrion - just wanted to check in on this. I looks like you made most of the changes - is my observation correct? We'd love to include this in the upcoming 0.2.0 release, but let me know if there is anything left here or if you would like some help!

@Zwiterrion
Copy link
Contributor Author

Hi @nilslice, I made the needed changes. The branch is ready to be merged.

@bhelx bhelx merged commit ac7e1ae into extism:main Jan 18, 2023
Zwiterrion added a commit to MAIF/extism that referenced this pull request Feb 2, 2023
Hi,

We want to use Extism on our project
[Otoroshi](https://github.com/MAIF/otoroshi) but we need to run it on
jdk11

This pull request makes everything run smoothly on jdk11

If you have any suggestion about this pull request, i'm open to it

Thanks for your time
Zwiterrion added a commit to MAIF/extism that referenced this pull request Feb 2, 2023
Hi,

We want to use Extism on our project
[Otoroshi](https://github.com/MAIF/otoroshi) but we need to run it on
jdk11

This pull request makes everything run smoothly on jdk11

If you have any suggestion about this pull request, i'm open to it

Thanks for your time
@Zwiterrion Zwiterrion deleted the support-jdk11 branch January 30, 2024 08:28
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.

None yet

5 participants