memory safety and weak references
rick.hudson at intel.com
Mon Apr 1 15:12:39 PDT 2013
If the compiler can prove x does not escape the block and it is not used again then it is dead and the compiler is free to reuse the stack slot holding the last reference.
So I am arguing that x = null; is not required to kill x.
If we agree on that then I think we agree that someWeakRef.get(); is allowed to return null.
From: Brendan Eich [mailto:brendan at mozilla.com]
Sent: Monday, April 01, 2013 5:56 PM
To: Hudson, Rick
Cc: Oliver Hunt; Marius Gundersen; es-discuss discussion
Subject: Re: memory safety and weak references
Hudson, Rick wrote:
> This brings up another interesting point. Do WeakRefs change a
> compiler's liveness analysis?
Yes, of course.
> This could complicate some apparently useful optimizations.
> var x = new Something();
> // Is x dead? (yes) Is x required to contribute to the root set? (I
> hope not.)
You dind't kill x yet. Did you forget
x = null;
> someWeakRef.get() // null or foo?
If x = null; happened before gc() then null else the original ref.
More information about the es-discuss