Implementing Libhandy and PHOSH

My employer has a few programs that are not open source, but that are free for anyone to download and use. These programs run in Linux and I think they are written in Java. When I get my Librem 5, I might be able as an insider there, to have someone compile these programs to run efficiently and in a mobile phone environment on my Librem 5.

Does anyone here know how difficult or easy this might be? Would I give them the libraries, they list the libraries in the program headers, and then recompile the program? A few edits, a recompile, and you’re good to go? Or would there be a lot of re-write and debugging work to do? What are the requirements?

I see the Codeweavers business model and realize that if there are advocates for libhandy and phosh for specific programs, that these tools might perpetuate themselves as the L5 grows in popularity.

How much efford is needed to port a program to the L5 depends on what kind of program it is. As PureOS isn’t very special most programs should basically run if they do so on desktop. To make a program adapt to mobile screens may take a bit more work.

I tried to run a Java program with Swing GUI on postmarkedOS with phosh on PinePhone. While Java runs fine Swing seems not to run on wayland. If somebody knows a workaround, please tell me. Maybe some X compatibility thingy? Other programs may use other GUIs, modules or dependencies, hence the result may differ.

I would simply give it a try and look how it works, identify problems and see if they can be solved with a reasonable amount of effort. If the program is pure Java it should be portable automatically. Native code like C/C++ would need compilation for ARM64 architecture.

I did not use libhandy so far. I don’t know if there are Java adapters or bindings for it. It should always be possible to bridge the gap by JNI. Wasn’t there are plan for some more modern native interface from Java?

A few years ago, I got a few smaller Linux Desktop programs running on a rooted Android phone using an x86 emulation layer. On a third and much larger program, the installer ran flawlessly. But the application was broken when I tried to execute it, given the wrong architecture. I think that if you compile a large Java program monolithic, any Java code should compile and run on any OS that supports Java. But I think that most larger programs are compiled modular by default. So when the compiled program can’t find expected file system directories and other OS-specific elements, it crashes.

So I contacted Oracle in attempts to get my hands on an Arm compiler for Java. They said they could give me thirty days free trial use of an Arm compiler for Java, but they wanted to know what company I represented first. This was a hobby project and I didn’t want them contacting my employer about my free trial using their name. So I passed because my employer already has business relations with them and I do not have access to that compiler as a part of my job. Besides, everything they do at work is x86 Java and not Arm. The purchase of an Arm Java compiler would have been something like $40K. So where does one get a good Arm compiler for Java without re-mortgaging your home to purchase it? I got the feeling that Oracle not only wanted the money, but the license itself may have been restricted. You can spend a lot more than $40K for an Oracle Arm compiler. Is there a free open source one that works just as well? From the responses I got from the people at Oracle, they seem to know that not many people compile programs to run on Arm processors and they seemed to act like they own that arena and they wanted to know more exactly what I wanted it for as a condition of their even continuing to talk to me. They quickly lost interest in even talking to me when I told them it was for a hobby project. I think that most of their customers are cell phone manufacturers.

Amazon has a jdk (Amazon Corretto) that runs on arm.

I think OpenJDK has been ported to ARM and you can easily install them it from the repos. Aren’t most JDKs are derived from OpenJDK?

1 Like

It does not depend on the size of the program. If it is pure Java (bytecode) no recompilation is needed. Of course there might be parts of not Java (bytecode). With Java it should be possible to develop pretty OS and HW independent software. Unfortunately sometimes programmers do bad stuff like depending on JDK specific internal implementations, path’s or environment variables to JDK. I don’t like that. Maybe programmers have a good reason that I don’t see.

Also there are ahead of time (AOT) compilers that generate native code. This has the advantage of shorter startup times, which can be relevant for non server software. The cost can be to loose some runtime optimizations, AFAI understand.

The community edition of the GraalVM comes with one called “native-image”, because it creates native images alias executable binaries. I can’t say anything about it’s license. native-image doesn’t compile source code but bytecode of any JVM language. It might be necessary to configure the build to find classes that can’t be found by static analysis at compile time, because those classes are determined at runtime like by reflection (Meta programming).

I think you should look what it actually is and try it, or we may talk in the wrong direction.

Yes, which is what corretto is. Ironically, their license is the most free (I had to research a new JDK for work since Oracle changed their license recently and now charges a fee for their JDK use), at least among those entities who both offer the JDK and support it (“support” here meaning I can go to them if I find a bug in the JDK or something and get assistance).