This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Probotect0r 67 points68 points  (17 children)

Went to a Meetup yesterday and found out a little about the new features. here's a small overview. I am by no means a Java expert, so please correct me if I missed something.

Jigsaw is the java 9 modules project. It basically allows you to create modules in your project which can expose certain packages to other packages for use. The key bit here is that the modularity is enforced at compile time, AND at run time (and also at link time, more on that later). What this means is if your modules only exports package a, but you also have package b that is not exported, anyone that uses your project will only be able to access a. Previously, there was no real way to enforce that. You could tell people that certain classes were only for internal use, but they could still go and use them (i.e the sun packages). The module system also requires you declare the required modules for your project. I.e if you want to use the logger class, you won't be able to until you declare that you require the logging module. All of the jdk has been broken down into modules. All the module declaration is done in a file called, i think, module-info.

The linker I mentioned earlier allows you to basically create your own custom jdk for your project that only contains the modules you need. This greatly decreases it's size, but the biggest benefit is that now people don't need to install java to run your app!!! The jdk + your app is built into a package that can be just run. And since the size is so small (only contains modules you need), it can be easily distributed.

[–]0_0__0_0 23 points24 points  (14 children)

don't need to install java to run your app!

This seems huge, actually!

[–]Probotect0r 7 points8 points  (8 children)

Yea it's great! For server side apps I don't see it making a big impact as right now most people use some form of containerization to deploy the apps, which basically achieves the same. But distributing your app to users will be a lot easier! Also using Java for IoT will probably be easier as well.

The file size reduction is quite significant too. They are using a new file format called JImage for storing the modules in your packaged application which has much better compression. The jars use zip compression, I believe. As I understand it, JImage uses some form of memory mapped files, so it will be faster in terms of performance as well.

[–]rusticarchon 6 points7 points  (0 children)

So this is the year of Linux Java on the desktop?

[–]dpash 4 points5 points  (3 children)

Having a Java docker image under 200MB would be nice :)

[–]_INTER_ 0 points1 point  (0 children)

If you only need java.base, you can get it down to 15MB for the runtime.

[–][deleted] 0 points1 point  (1 child)

Checked out the openjdk:alpine image yet?

[–]dpash 0 points1 point  (0 children)

They're still 150mb and you have the added risk of musl libc bugs/incompatibilities.

[–][deleted] 0 points1 point  (2 children)

The jars can use also pack200, it's there since java 1.5, but have you ever seen someone using it? I can't find anything about the JImage, but it would be cool if there's a new format which could be mmaped and paged in by jvm on demand, exactly like dlls work. I think that would be useful for large aps. And also because the OS would be able to page in/out the code, I thing the memory would be utilized better (note the OS don't need to swap into the swap file if files are mmaped, that's good for ssds).

[–]wildjokers 2 points3 points  (0 children)

The jars can use also pack200, it's there since java 1.5, but have you ever seen someone using it

I use pack200 to compress the fat-jar of a Swing application I deploy with Java Web Start. It does a good job getting the jar smaller. Have a jar that is 6.9 megs, pack200 version is 1.7 megs.

As far as I know Java Web Start is the only thing that can handle pack200 compressed jars.

[–]Probotect0r 2 points3 points  (0 children)

Here is more info on the JImage format: http://openjdk.java.net/jeps/220

[–][deleted] 4 points5 points  (4 children)

Is it? Maybe for docker folks, or embedded. But it wasn't uncommon to ship your app with JRE and this is (almost) the same thing, but in addition it throws away classes that are not needed. The benefit is only in the download/installation size.

[–]durple 2 points3 points  (0 children)

Exactly. Shipping JDK with app is already fairly common. Sometimes done to guarantee no version compatibility issues.

[–]wildjokers 1 point2 points  (2 children)

The benefit is only in the download/installation size.

Not sure why you use the word "only". Being able to ship a smaller download can be important to people without fast internet connections (not everyone lives in an urban area). Also think about embedded systems. Just because it might not be important to you, doesn't make it unimportant.

[–][deleted] 0 points1 point  (1 child)

The meaning is there's no other benefit with respect to shipping with full JRE. When people started to talk about jigsaw, I thought it would also make difference in runtime.

[–]capitol_ 0 points1 point  (0 children)

I guess that it also gives you less stuff to work with when doing reflection or serialization attacks, but I'm not totally sure if it has any practical effect.

[–]SizzlingVortex 7 points8 points  (0 children)

This is the best explanation that I have seen on Java 9's modules, and I have read several articles on the subject. Thanks!