Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jblagden

macrumors 65816
Original poster
Aug 16, 2013
1,162
641
I've done some programming in Java. The only problem with Java is also its strength; it's not fully compiled. This is great because it makes it cross-compatible without the developer having to compile it for every operating system. But this also slows down the execution of Java programs. I'd like to be able to compile them to binary. I found out that there's a compiler called GCJ which can compile Java programs to OS X binary.

However, I don't know how to compile it. I found some instructions on the GCJ website, but they weren't very helpful.

How do you compile GCJ in OS X?
 

chown33

Moderator
Staff member
Aug 9, 2009
10,747
8,421
A sea of green
Please provide more details.

First:
Which OS version?
Which Java version?
Which Mac model? Capabilities: RAM, SSD/HD?

Second:
Exactly what is your program doing that's slow?


In my experience, there are at least 3 main contributors, and they don't always appear in every program.
1. Startup latency.
2. Computational constraints.
3. GUI: AWT, Swing, or SWT

Startup latency is rarely a significant factor. It takes a lot of jar files, with many many classes all actively being used, before it becomes noticeable. Startup latency can also appear when the RAM is too small for good caching, or a spinning HD is too slow.

Computational constraints can appear for any number of reasons, beyond just doing a gazillion calculations. Poor algorithm choice, thrashing due to GC, etc.

I have several command-line Java tools I wrote that I use every day for my embedded systems work. They are more than fast enough to be launched and run at every build, which is probably at least 100 times in a day. When performance is measured, any slowness is attributed to the file-system, since they operate on files, rather than anything attributable to byte-codes, JITC, startup latency, or computational constraints.

Then there's the GUI. It's always slow on OS X. You can try every trick you can find, and it still won't make a big difference: it will still be sluggish. So if your program is using any GUI at all, or even off-screen graphics, then it's slow for that reason, not because Java is compiled to byte-codes.

Also, make sure that whatever GUI you plan to use with GCJ is performant, and supports what you need:
https://en.wikipedia.org/wiki/GNU_Compiler_for_Java


Finally, what else did you try searching for?
I googled mac os gcj and came up with this:
http://sourceforge.net/projects/gcj-osx-intel/
 

jblagden

macrumors 65816
Original poster
Aug 16, 2013
1,162
641
Please provide more details.

First:
Which OS version?
Which Java version?
Which Mac model? Capabilities: RAM, SSD/HD?

Second:
Exactly what is your program doing that's slow?


In my experience, there are at least 3 main contributors, and they don't always appear in every program.
1. Startup latency.
2. Computational constraints.
3. GUI: AWT, Swing, or SWT

Startup latency is rarely a significant factor. It takes a lot of jar files, with many many classes all actively being used, before it becomes noticeable. Startup latency can also appear when the RAM is too small for good caching, or a spinning HD is too slow.

Computational constraints can appear for any number of reasons, beyond just doing a gazillion calculations. Poor algorithm choice, thrashing due to GC, etc.

I have several command-line Java tools I wrote that I use every day for my embedded systems work. They are more than fast enough to be launched and run at every build, which is probably at least 100 times in a day. When performance is measured, any slowness is attributed to the file-system, since they operate on files, rather than anything attributable to byte-codes, JITC, startup latency, or computational constraints.

Then there's the GUI. It's always slow on OS X. You can try every trick you can find, and it still won't make a big difference: it will still be sluggish. So if your program is using any GUI at all, or even off-screen graphics, then it's slow for that reason, not because Java is compiled to byte-codes.

Also, make sure that whatever GUI you plan to use with GCJ is performant, and supports what you need:
https://en.wikipedia.org/wiki/GNU_Compiler_for_Java


Finally, what else did you try searching for?
I googled mac os gcj and came up with this:
http://sourceforge.net/projects/gcj-osx-intel/
1. OS X 10.11.1 El Capitan
2. Java 1.7.0_40
3. Late 2011 13” MacBook Pro (model 8,1). 2.4 gigahertz processor. 8 gigabytes of RAM. 750 gigabyte 7200 RPM Seagate Momentus XT Solid State Hybrid drive(750 GB HDD & 8 GB flash cache).
 

chown33

Moderator
Staff member
Aug 9, 2009
10,747
8,421
A sea of green
1. OS X 10.11.1 El Capitan
2. Java 1.7.0_40
3. Late 2011 13” MacBook Pro (model 8,1). 2.4 gigahertz processor. 8 gigabytes of RAM. 750 gigabyte 7200 RPM Seagate Momentus XT Solid State Hybrid drive(750 GB HDD & 8 GB flash cache).
That sounds like a capable enough machine.


Now to the second part:
Please describe the program that's too slow.

What does it do? Does it use a GUI? Is it computationally intensive? Memory intensive? Does it show high initial latency but otherwise runs ok?

Have you profiled the program? What did that tell you?

What Java development tools do you use? Eclipse has readily accessible profiling:
http://www.eclipse.org/tptp/home/documents/tutorials/profilingtool/profilingexample_32.html
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.