[Pharo-project] Ideas for CompiledMethod proxies?
siguctua at gmail.com
Sat Nov 20 00:04:26 CET 2010
On 19 November 2010 22:47, Mariano Martinez Peck <marianopeck at gmail.com> wrote:
> Hi. I am developing kind of proxies for unused compiled methods. I want to
> detect them, put a proxy instead of them, and swap them to disk. Then, in
> case they are used, I put back the original ones. With this, I want to
> realease memory. This is why I need the proxy objects to be as small as
> Right now, I do something like this:
> aProxy := CompiledMethodProxyReferenceStreamWithFileName installOn:
> ClassWith1Var selector: #foo.
> this will instantiate the proxy, do the ClassWith1Var methodAt: #foo put:
> proxy, write the original compiledMethod that was in #foo into a file,
> and then if I do "ClassWith1Var new foo", then using the #run:with:in I
> load the file from disk and I put back the original method. To know WHICH
> file I have to load, I have to store the fileName in the proxy object.
> In addition, if I DON'T execute the compiled method, but instead I send a
> message, for example:
> (ClassWith1Var >> #foo) literals
> this has to do the same: load and put back the original compiled method. To
> do this, I use the doesNotUnderstand:.
> This is easy to do if I store the fileName in the proxy instance. Right now,
> I am using as fileName this: CLASS >> SELECTOR. For example, in this case,
> the file would be named "ClassWith1Var >> #foo"
> Now.....with this solution, I need create an proxy instance for each
> compiled method, and these instances have also another instance for the
> filename. If I could use the same proxy instance for everybody, the amount
> of memory released would be muuuuch more. So I thought that maybe from the
> context I can "guess" the filename if I use conventions.
> For example, if you do "ClassWith1Var new foo" then in the #run:with:in I
> receive all the information to KNOW that the fileName should be
> "ClassWith1Var >> #foo". So, no problem here.
> But for the second case, suppose "(ClassWith1Var >> #foo) literals", I don't
> see a way to know this. In this case, #literals is intercepted by the
> doesNotUnderstand: of my proxy, and here I should load back the original
> compiled method from disk. The problem is that I cannot know in which CLASS
> and SELECTOR this proxy was put. The only way I know to do this, is to store
> the class + selector in the proxy instance....but it is the same...I will
> need an instance per compiled method. In such case is even easier to
> directly store the fileName.
> Anyway, if someone has a solution or advice on this, I would be appreciated
> that. I tried with thisContext, but it didn't help me.
A proxy actually should hold only some unique value (id), or as Eliot
suggested be a unique by itself.
This is enough to find a correspondence between any proxy and its
You can simply delegate loading the method to some object, which
'knows' how to load a method and where it is stored:
" id based lookup: "
| method |
method := MethodsProxyManager methodFor: id.
^ method literals
"or identity based lookup: "
| method |
method := MethodsProxyManager methodFor: self.
^ method literals
Igor Stasenko AKA sig.
More information about the Pharo-project