Re: A bit confused with SoftReference - when exactly is it collected?
Twisted wrote:
The reference I've never seen much use for is the PhantomReference.
Even if you put it in a reference queue, by the time you get the phone
call it's gone! I'm not clear where it's useful where a WeakReference
won't do as well.
There's two ways of using References. The most obvious is you read the
reference and check it hasn't gone. The other way is to subclass and
ignore get. The point of subclassing is that when you pick the Reference
off the ReferenceQueue relevant information is available (although not
the actual target object). PhantomReference can be used for cleanup,
much the same as finalisers. Finalisers are, however, easier to write (I
say easier, but to get them correct still isn't easy).
On another note, I see mention of the "server VM". I'd always gathered
that that is just "what you get when you put -server on the command
line", but putting -server on the command line of any of the HotSpot
VMs I've gotten downloading Sun's JDKs and JREs produces an error
message. Apparently it's actually a separate VM implementation
altogether -- and I have no idea where to find it on Sun's site,
either. It's not obvious where it is, but it apparently has significant
advantages even on the desktop, such as better GC and memory usage,
saner SoftReference behavior, and better HotSpot optimization.
Let me guess. You are using Windows. IIRC, the server VM on Windows is
in the JDK but not the JRE. However, you can copy it from the JDK into
the JRE.
There is no AMD64 client VM, but taking the opposite approach from
Windows, if you ask for -d64 -client it silently gives the 64-bit server
VM instead (silently unless you use -showversion, of course).
(Someone
profiled some FP code for me and found that FP math in a tight loop
runs at C-native speeds with -server but not with a normal Hotspot VM
like what I have after there's been time for the JIT to kick in. A
normal Hotspot VM is never more than about half C-native speeds at FP
math it seems. For scientific applications and simulation work, this is
a big freaking deal.)
Yup. Also note trig functions in particular will run faster on non-x86
processors, as the x87 is too imprecise for the Java specification.
Tom Hawtin