 |
Netbeans on Mac Tip
Posted by joshy on November 23, 2005 at 11:14 AM | Comments (14)
As some of you may know I'm a big Mac person. I split my time equally between my iBook (now heading back to the shop, alas) and my WinXP desktop. Being a dyed in the wool plain jane text editor type of programmer I've used jEdit for the past five years and have only recently started using an IDE like Netbeans. I've found Netbeans to a great productivity booster but on my iBook it seems to generate garbage at a mad pace. This is okay, it's just garbage, not a memory leak; but it's a pain when the editor locks up for five seconds to do garbage collection. Fortunately there is a solution.
I recently gave a talk on application optimization at JavaOne Tokyo. The last part of the presentation talks about how choose different garbage collectors to improve perceived performance. In particular the Mark and Sweep garbage collector will operate incrementally, meaning it won't lock your application while done one big GC. Instead it will do lots of tiny GCs which take a bit longer but improve the perceived performance of your app. And after all, what the user perceives is the most important thing. The cool part is you don't need to do any code changes to use this garbage collector. Just a commandline switch.
So, back to Netbeans. Yesterday I'd had it with the long GCs, remembered the commandline switch from my talk, and decided to do something about it.
Here's how to make Netbeans on a Mac use the Mark and Sweep GC.
- Fire up a text editor (maybe even vi from the command line) that can open application folders. On the Mac applications are really folders with a special structure that Finder makes look like single application files, so be sure to use a text editor which will show you the real folders and open them. I used JEdit.
- Open the
Netbeans.app/ folder, navigate to the Contents/MacOS/ directory, and open the netbeans file. This is the script that actually starts netbeans. I'd back file up before editing just in case you break something.
- Find section of the script that actually calls the Netbeans executable when running under Darwin (the unix name for MacOSX). In my copy of Netbeans (a recent beta of 5.0) this is line 74 of the script.
- Add this argument to the netbeans commandline (line 83 in my copy).
-J-XX:+UseConcMarkSweepGC \
Note the space and the trailing '\'. This is because the 10 lines or so right there are actually part of a single commandline and the '\'s make it all be one line.
- Save the file then launch Netbeans from Finder. It should come up as normal.
- Use Netbeans for a while and watch the memory. It should almost never get up to the max memory limit. Instead it will GC periodically and keep memory usage down to what's actually being used. And you should never experience a GC pause.
- Get back to coding. There's apps to be written!
For my Mac brethern out there I hope you find this useful. For those of you not using Netbeans 5 I urge you to try it out. It doesn't suck!
(and coming from a lifetime text editor guy that's saying a lot :)
- Josh
Bookmark blog post: del.icio.us Digg DZone Furl Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
-
Also worthwhile is putting:
netbeans_jdkhome=/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home
in the file ~/.netbeans/5.0beta2/etc/netbeans.conf (assuming you've installed JDK1.5).
Posted by: goron on November 23, 2005 at 02:41 PM
-
Great suggestion, I have tha same problem on my iBook G3 800MHz. Can't wait to try it when I'll be back at home.
Do you know if there is some drawback using this command line switch? If not, I think it should be the default.
Cheers
Posted by: nicfagn on November 24, 2005 at 07:14 AM
-
The reason why this switch is not the default in NetBeans (yet) is that it's not supported on all VMs. It also used to cause some JVM crashes with early 1.4 versions. May be fixed now. If you're on 1.5 and the VM supports it, you should definitely give it a try.
Posted by: honza on November 25, 2005 at 01:15 AM
-
Nice tips, Josh!
Regarding "Darwin (the unix name for MacOSX)."More precisely, Darwin is the open-source unix kernel (based on BSD unix and the Mach microkernel) for Mac OS X:
http://developer.apple.com/darwin/projects/darwin/
http://www.opendarwin.org/
- Craig
Posted by: mattocks on November 25, 2005 at 08:56 AM
-
definitely NOT a good idea to run Netbeans under JDK 1.5 on OSX at thye moment, I'm afraid. There is a phenomenally irritating bug in the Apple Swing implementation for 1.5 which results in losing keyboard focus quite a lot. The upshot is that when running under 1.5 if you click on (for instance) a quick-fix icon in the editor and choose a fix you will lose keyboard focus in your current document and the only way to get it back is to close the document and re-open it. I've had a few occasions when even this didn't fix it and the only thing to do was to quit netbeans a restart it. I can't believe Apple didn't fix this bug with the last release of 1.5.
Posted by: jportway on November 25, 2005 at 09:06 AM
-
I don't use a Mac, I don't use Netbeans.. but I do use:
-Xms128M -Xmx700M -XX:MaxGCPauseMillis=2000
with Eclipse and have had great results (in earlier days when I didn't have enough RAM I suffered).
I also used to run w/ -server but I'm not sure that's better (though it supposedly is faster).
I'm using jdk1.6 (an early build) but 1.5 works too.
Posted by: dog on November 25, 2005 at 11:12 AM
-
Also of interest:
Across the board, one consistently useful setting is -XX:PermSize=20M - this sets the permanent area memory size (where classes are stored) on NetBeans' startup and eliminates that area being grown during startup. Simulating the promoteall modifier appears to help as well- using -XXMaxTenuringThreshold=0 reduces garbage collection cycles by causing promotion of objects directly from the new area to the old area (without using the two survivor areas), thus eliminating two memory copies. Whether this has a deleterious effect on old generation gc's remains to be seen - as long as this is accompanied by raising the barrier to an object being copied to the old generation in the first place, it should provide a performance improvement.
Read the rest here.
Posted by: coxcu on November 25, 2005 at 11:46 AM
-
A netbeans / Mac OSX, good news.
Using release3, JVM Monitoring is working well!
http://blogs.sun.com/roller/page/jmxnetbeans/20051117
Posted by: jfdenise on November 28, 2005 at 02:52 AM
-
Generally it is safer to edit netbeans.conf file instead of the launcher script itself. It is much easier (having usually around 3 lines + some comments). Not sure where it is on the Mac but it should be there somewhere ;-) (Contents/Resources/NetBeans/etc???)
Posted by: dstrupl on November 29, 2005 at 01:47 PM
-
On the problems with focus, they are real. I filed a bug with netbeans. The new V5 is supposed to fix it. While annoying, you can get around it by clicking in another window or pane and clicking back to where you want to work.
The netbeans.conf file is in Contents/Resources/NetBeans/etc. I suggest a PermSize of 32M for a large system.
I'd be interested in experiences using -server with netbeans. The -server option is not optimized for UI, but some of the long processes might run faster.
I have a crash after running for a couple of days - usually from running out of memory. Anyone else have that problem?
Posted by: jboetje on November 30, 2005 at 08:21 PM
-
Hi folks: a quick NetBeans-on-Mac question.
The 5.0 version uses the Mac menu bar - yea!
But it does not use the Mac file browser - boo!
Any answer for how to configure NetBeans to use the file browser?
Thanks!
Posted by: backspaces on December 03, 2005 at 02:32 PM
-
Regarding the post of "backspaces". I agree Finder without a sidebar really sucks.
I've found a way to use the complete Finder features when opening a file in NetBeans.
NetBeans allows you to use a custom Look & Feel. There is a project called Quaqua(https://quaqua.dev.java.net/) that aims to provide a Mac L&F for Java applications. It also includes a JFileChooser that has almost all Finder features. By the way, if someone can tell me why the AWT FileDialog has a Finder sidebar and the normal JFileChooser has not, please leave a comment. Did Apple simply forget it when implementing the Apple JDK???
To use the Quaqua L&F show the package contents of your NetBeans installation (I use the 5.5 preview) and open the "/Contents/Resources/NetBeans/etc/netbeans.conf file
add
--cp:p /Users/Chris/Documents/java/quaqua/lib/quaqua.jar --laf ch.randelshofer.quaqua.QuaquaLookAndFeel
to the end of the "netbeans_default_options" property. (I use the JDK 5.0 version of this property, that also includes the tip mentioned in this article)
You have to replace the path to the quaqua.jar with the path on your file system of course.
The last thing you need to do is to put the "libquaqua.jnilib" file on your classpath. I couldn't figure out how to do that by changing the "netbeans_default_options" property (though it should be possible). Therefore I just copied it to the Libraries folder of my JDK installation ("/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/" in my case) using the terminal and restartet my Mac. When you start NetBeans now, you have a nice Finder with sidebar. I think it is slightly slower to use the Quaqua JFileChooser, but for me the ease of use compensate for this.
HtH
Chris
Posted by: allesmallachen on March 21, 2006 at 03:13 AM
-
After having some serious GC slowdowns on my PowerBook with Netbeans I found this article and went to change my netbeans.conf file only to find that I was already using these settings.
Is this a matter of the JDK (1.5.0_06) not taking care of things properly? I'm a bit lost here. I don't seem to have these problems when running with the Sun JVM under windows.
Any tips to solve this annoyance are welcome...
Posted by: jmelchio on August 01, 2006 at 07:27 AM
-
Finally found the answer to the riddle, following is from the release notes with the mentioned JDK ...
Radar #4413936
Non-default Garbage Collection issues
Description:
Applications that use the -XX:+UseConcMarkSweepGC (Concurrent Mark Sweep Garbage Collection
algorithm) or -XX:+useParallelGC (Parallel Garbage Collection algorithm) tend to be unstable.
Workaround:
None.
After removing the garbage collection instructions this version of the JVM runs great with Netbeans.
Cheers, Joris.
Posted by: jmelchio on September 18, 2006 at 06:30 PM
|