Eliot Thanks for your response.
On Fri, Nov 26, 2010 at 5:49 PM, Eliot Miranda <[email protected]> wrote: > > > On Thu, Nov 25, 2010 at 1:14 PM, Igor Stasenko <[email protected]> wrote: >> >> On 25 November 2010 20:44, Gabriel Hernán Barbuto <[email protected]> >> wrote: >> > Hi >> > >> > I am trying to make a complete duplicate of a CompiledMethod. I >> > started with CompiledMethod>>#copyWithTrailerBytes: but I think that >> > this way still leaves some things to copy. It duplicates all the >> > literals, but I think that it doesn't duplicate a Pragma if for >> > example, the method has one. >> > >> AFAIR, pragmas are stored as one of literals. >> So, it actually should also make a copy of pragmas. > > Yes. pragmas are effectively referenced from literals. If a method needs ti > the penultimate literal (which otherwise is the method;s selector) holds an > AdditionalMethodState which refers back to its method. This needs to be > copied if one is copying a method, since the backpointer needs to refer to > the owning method, not the method form which the copy was made. >> >> > Is there a proper way to completely make deep copy of a >> > CompiledMethod? I mean, without writing my own. If there is a way to >> > do it, I don't want to duplicate it. >> > >> if you tell more, why #copy is not enough for you. > > If literals are read-only (and Array/ByteArray/String/Float literals are > conceptually read-only but not actually) you don't need to make a deep copy. > You only need to copy the AdditionalMethodState, if present, and the class > association, if you want to install the method somewhere else. Yes that was exactly what I did. I handle both Association and AdditionalMethodState in a special way and just send copy to all the other literals. I was not sure what I could encounter in the literals so I opted to send copy to them. Maybe they will just return themselves or make an unnecessary duplicate. I have also taken care of copying the Pragmas referenced from any AdditionalMethodState. Igor mentioned that there could be Pragmas directly on the literals but I am not sure about that. I will have to get all the CompiledMethods and check if anyone has a Pragma among its literals, but that is not enough, maybe my image doesn't have any. I understand that all the literals are conceptually read only, and that copying anything besides the Associations, AdditionalMethodStates and Pragmas can waste memory and CPU cycles, but I am not interested in speed nor memory consumption right now. But I will take a note, in case some day I need to improve the copy. After copying all the Associations, AdditionalMethodStates and Pragmas that I've found I fix the references of both AdditionalMethodStates and Pragmas to the new method in order to break all references to objects in the current image that I don't want to show up in the new image. Thanks again. Best Gabriel > best > Eliot >> >> > Thanks in advance. >> > Gabriel >> > >> > >> >> >> >> -- >> Best regards, >> Igor Stasenko AKA sig. >> > >
