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

Running skija with Java 8 #57

Closed
Jojal opened this issue Nov 19, 2020 · 18 comments
Closed

Running skija with Java 8 #57

Jojal opened this issue Nov 19, 2020 · 18 comments

Comments

@Jojal
Copy link

Jojal commented Nov 19, 2020

Hi everyone,

I was wondering if there is any possibility to make skija wordking with java 8 please ? Maybe a trick or something ? I need to swith to java 11, but due to some legacy code, i still need to wait a bit and i would love to try make skija working with my java 8 app.

Thank's a lot.

@tonsky
Copy link
Collaborator

tonsky commented Nov 19, 2020

Good question—have you tried it? What didn’t work?

@tonsky
Copy link
Collaborator

tonsky commented Nov 19, 2020

This is what we depend on https://docs.oracle.com/javase/9/docs/api/java/lang/ref/Cleaner.html, avaliable since 9. So I guess the minimal version is 9

@Jojal
Copy link
Author

Jojal commented Nov 19, 2020

Yeah i tried. I just modified the pom.xml to change the compiler version from 11 to 8, and i had an error about what you said.
java.lang.ref.Cleaner not found.

Thank you for the answer. Now i think there is no chance that this could be work with java 8.

@Jojal Jojal closed this as completed Nov 19, 2020
@yuhailong626
Copy link

yuhailong626 commented Dec 2, 2020

I tried to replace java.lang.ref.Cleaner with sun.misc.Cleaner and it worked.
Like this:
`import sun.misc.Cleaner;
public abstract class Managed extends Native implements AutoCloseable {
public Cleaner _cleaner;
public Managed(long ptr, long finalizer) {
this(ptr, finalizer, true);
}
public Managed(long ptr, long finalizer, boolean managed) {
super(ptr);
if (managed) {
assert ptr != 0L : "Managed ptr is 0";

        assert finalizer != 0L : "Managed finalizer is 0";

        String className = this.getClass().getSimpleName();
        Stats.onAllocated(className);
        this._cleaner = Cleaner.create(this, new Managed.CleanerThunk(className, ptr, finalizer));
    }

}
public void close() {
    if (0L == this._ptr) {
        throw new RuntimeException("Object already closed: " + this);
    } else if (null == this._cleaner) {
        throw new RuntimeException("Object is not managed in JVM, can't close(): " + this);
    } else {
        this._cleaner.clean();
        this._cleaner = null;
        this._ptr = 0L;
    }
}

public static native void _nInvokeFinalizer(long var0, long var2);

public static class CleanerThunk implements Runnable {
    public String _className;
    public long _ptr;
    public long _finalizerPtr;

    public CleanerThunk(String className, long ptr, long finalizer) {
        this._className = className;
        this._ptr = ptr;
        this._finalizerPtr = finalizer;
    }
    public void run() {
        Stats.onDeallocated(this._className);
        Stats.onNativeCall();
        Managed._nInvokeFinalizer(this._finalizerPtr, this._ptr);
    }
}

}`

@tonsky
Copy link
Collaborator

tonsky commented Dec 2, 2020

Great!

@Jojal
Copy link
Author

Jojal commented Dec 3, 2020

Yeah it's really good ! I'm gonna try that 👍
The only thing is we need to make this patch every time there is a new version ? Or could that be handled by the skija team maybe ?

Thanks again !

@tonsky
Copy link
Collaborator

tonsky commented Dec 3, 2020

I don’t know a way to make two different classes for two different JVM versions.

Out of curiosity, what are the reasons that make you stay on Java 8?

@Jojal
Copy link
Author

Jojal commented Dec 3, 2020

Just because of legacy :) I will take time to upgrade my app to java 11 but for huge application it's not so easy to do it unfortunately. That is why, it would have been easier if Skija could work directly with Java 8 in my case.

But it's now good to know that it can works with Java 8.
Thanks again for your help.
And really good job with Skija. Was waiting for that since a long time 👍

@magneticflux-
Copy link

I don’t know a way to make two different classes for two different JVM versions.

@tonsky Coincidentally, Java 9 introduced exactly that feature! 😄
You can create multi-release jars that include classes specifically for backwards compatibility. If Cleaner is the only API needed, I think it would be pretty easy to expose the sun.misc API as the modern one on Java 8 and not break anything on newer versions.

There's a great guide for Maven use here: https://www.baeldung.com/maven-multi-release-jars

@tonsky
Copy link
Collaborator

tonsky commented Jun 10, 2021

Great! Do you want to work on that? I’d be happy to review a PR

@Sm0keySa1m0n
Copy link

Any status on this?

@luojinrong
Copy link

Yeah it's really good ! I'm gonna try that 👍 The only thing is we need to make this patch every time there is a new version ? Or could that be handled by the skija team maybe ?

Thanks again !

@Jojal How do you modified the scripts to support compile? When I just replace java.lang.ref.Cleaner with sun.misc.Cleaner and run /script/build.py, it says there's no options like "--release", "--class-path" and "--module-path". After search I found these options only support in Java 9, cause I'm new in Java that do not have any idea to modify it. So if any help about how to compile it with Java 8.

Thanks in advance!

@tonsky
Copy link
Collaborator

tonsky commented Apr 14, 2022

@luojinrong I am curious what keeps you on Java 8? If you are new, why not start with the latest? Java 8 was released in 2014

@luojinrong
Copy link

Cause only I'm new, uhh...but my company use java 8 on its servers. We prefer using skija with java 8 than upgrading java version on servers.

@tonsky
Copy link
Collaborator

tonsky commented Apr 15, 2022

How do you plan to use Skija on the servers? Just curious

@Sculas
Copy link

Sculas commented Apr 27, 2022

I'd like to use Skija with the LWJGL backend on older versions of Minecraft, which still run on Java 8 and cannot be updated due to an outdated Netty dependency.

Is there any workaround for this so I can use Skija with Java 8?

@tonsky
Copy link
Collaborator

tonsky commented Apr 28, 2022

@Lucaskyy just at the beginning of this thread, there’s a workaround

@Glavo
Copy link

Glavo commented Dec 15, 2022

@Jojal @yuhailong626 @Magneticflux @Sm0keySa1m0n @luojinrong @Sculas

HumbleUI/Skija has provided Java 8 support since 0.109.0.

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

No branches or pull requests

8 participants