A method to pack javafx apps in less than 5 MB (with jvm)
Shashaank Tulsyan
shashaanktulsyan at gmail.com
Thu Apr 9 13:11:08 UTC 2015
@Tobi Yes it can be used for robovm.
There is no particular link to java fx packager.
The main thing which it uses is some vm flags and supply an alternate
bootstrap classpath, which is rt.jar unzipped. And then we spy on javavm
using a virtual filesystem to know which classes are actually required by
the vm and which classes are not. Based on this knowledge we create a new
copy of the bootstrap classes contains only those classs files which are
actually required.
Typically in javafx packager configuration file we add 2 lines
1. vmarg.1=-Xbootclasspath:$APPDIR\rt
2. jvmarg.2=-Djava.ext.dirs=
So as long as your vm (assuming you are using a non-oracle jvm) supports
these flags, the approach which I shared will work. The best way to know is
to try it out. As far as I can think, I see no reason for this not to work.
Infact I had a discussion with the developers of robovm, and they
appreciated the concept. Here is what they had to say
--------------
Interesting approach! :-) We're working on improving the stripping done by
RoboVM to reduce file sizes. Recording which classes are actually used at
runtime is something we could do easily by patching RoboVM slightly. We're
currently looking into an approach which is much less aggressive, using
static analyses. One nice advantage with the dynamic approach is no special
handling is required for classes loaded via reflection. Maybe we could use
this for generating forceLinkClasses patterns automatically for users. The
drawback is of course that you have to make sure you touch all codepaths of
your app when recording.
Thanks for the info and links. We'll see where we end up eventually...
----------------
Best way to know what works best for your project is to try it out.
Regards
Shashank
On Thu, Apr 9, 2015 at 12:40 AM, Tobias Bley <tobi at ultramixer.com> wrote:
> HI,
>
> it’s awesome! Could we use this approach independently from JavaPackager
> via Gradle? And could we use it for javafxports.org / RoboVM?
>
> Best,
> Tobi
>
>
> Am 08.04.2015 um 20:46 schrieb Shashaank Tulsyan <
> shashaanktulsyan at gmail.com>:
>
> Hi,
>
> I am extremely excited to share something unimaginable.
> Inspired by various open source projects out there I tried to create an
> insanely stripped down vm distribution.
>
> The result :
> Java 8 FX app in less than 5MB !!!!!
>
> Don't believe me, just see it for yourself :
> https://github.com/s...0application.7z
> <
> https://github.com/shashaanktulsyan/spyfs/blob/master/sample%205MB%20java%20application.7z
> >
> *Note1 : This app has been packaged using javafx packer and for some reason
> will not run on 32bit OS.*
> *Note2 : This app does nothing, it will just show a javafx window, with a
> button that does nothing**.*
>
> For me having a *desktop* java app, along with java runtime, in less than
> 5MB is a big deal.
> You might not believe me, but I have been waiting for java modularization
> to happen since almost a decade.
> I started doing java when I was 15, and hated that I couldn't distribute
> stuff that I made like others were able to using other languages.
> Anyhow, I would like to share how I achieved this.
>
> I used following facts to my advantage :
>
> - Java classes are loaded in lazy fashion. So even if there is
> dependency to a class because of an import statement, the class itself
> will
> not be loaded until it is required !
> - Xbootclasspath can be used to change runtime classes. So instead of
> using heavy rt.jar and other heavy jar files we can use a highly stripped
> down runtime which has exactly those classes which we require. (Inspired
> by
> robovm, retrolamba and proguard)
> - So now the last part remains, is *how to find which classes are
> actually used*. For this purpose I don't use anything related to javavm.
> Instead I use kernel level *virtual filesystems*!!! This way I am also
> able to remove native libraries (dlls) and resources (configuration files
> etc) which are not required.
> - Finally these options can be set very easily in configuration file of
> a native java application created using javafx packager. Only 2 lines
> need
> to be added to do the trick.
>
>
>
> Here I am not going to share the details.
> But I am here to share the excitement. This is really insanely small !
> A Javafx application in 5MB!! That is crazy small.
>
> This is a very rigorous approach, only very greedy might go to this path.
> But when you see other platforms/vms/languages giving out small 5MB native
> apps, one feels why can't java also do this? :D
>
> It just shows how much room we have for stripping down jvm. It shows that
> the smallest base that we start off with can be very very small.
>
> What do you guys think?
> BTW if you are interested in knowing the exact steps, check out
> https://github.com/shashaanktulsyan/spyfs#java-in-5-mb
>
> Thanks
> Shashank [image: :D] [image: :D] [image: :D]
>
>
>
More information about the jigsaw-dev
mailing list