question regarding call sites and garbage collection

Jochen Theodorou blackdrag at gmx.org
Wed Mar 16 03:36:02 PDT 2011


Am 15.03.2011 23:41, schrieb Rémi Forax:
[...]
>> If the callsite is inlined, won't
>> that mean that then we have those types hard referenced as well and that
>> I cannot do anything against that?
>
> A callsite can be inlined more than once.
> So the reference to the mh can not be dropt

I ask because I was thinking of a certain artificial case

let us assume I have a class that does this:

Script1:

Object foo(x) {
   return x
}
Object bar(x) {
   x.foo(this) // done by call site logic using MethodHandle
}

Then, if I understood correctly, whatever the class of x is, the class 
will be referenced from this call site and has to live as long as this 
class here does.

Now assume I will do the following:

Object lastScript = null
bigNumber.times {
     MyLoader cl = new CustomClassLoaderOfSomeKind()
     def scriptn = cl.defineClass(...).newInstance()
     scriptn.bar(lastScript==null?scriptn:lastScript)
     lastScript = scriptn
}

The result, should I have understood correctly, will be, that each 
scriptn will cause the former scriptn (lastScript) to be referenced in a 
way that prefents that from being garbage collected, even though scriptn 
does not reference lastScript directly and there will be no reference to 
the class loader as well. So in theory the last script could be garbage 
collected but the MethodHandles prevent that from happening.

bye Jochen

-- 
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead
http://blackdragsview.blogspot.com/
For Groovy programming sources visit http://groovy.codehaus.org



More information about the mlvm-dev mailing list