Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.arch Subject: Re: self-modifying code Message-ID: <666@cresswell.quintus.UUCP> Date: 19 Feb 88 09:48:24 GMT References: <486@taux01.UUCP> Organization: Quintus Computer Systems, Mountain View, CA Lines: 39 Summary: clarification In article <486@taux01.UUCP>, yuval@taux01.UUCP (Gideon Yuval) writes: > Is good support for self-modifying code a real issue? all CPUs support a > "modify code -- invalidate all caches -- execute" cycle, which is enough to > run (say) loaders & debuggers; i THINK this is enough for all real > applications, but want to be sure. > > Are any exceptions to this (AI or other) known? Historically, "self-modification" has referred to modifying instructions which will then be executed again. For example, walking down an array on an IBM 650 without index registers required changing address fields in instructions. What languages like Pop-2, Lisp, Prolog, SmallTalk, &c &c require is the ability to (a) dynamically add *new* code; if the operating system provided a "load this .obj file whereever you please and protect it as executable code, but tell me where you put everything" facility, that would be fine. (b) reclaim old code which will never be used again; if the operating system provided an "unload this chunk that you loaded for me before, and if you protect it so that attempts to exceute it will trap, so much the better" facility, that would be fine. Note that separate I&D doesn't mean you can't have dynamically loaded code; it just means that an ordinary user program can't do it, and many operating systems vendors never think to provide it. Some implementations of SmallTalk and Lisp do use a self-modifying scheme. For example, one technique for handling Object msg in SmallTalk is to have instructions like load Object call usual_handler_for_msg ^^^^^^^^^^^^^^^^^^^^^ where the handler checks to see if it is the right one, and if it isn't, does a full method lookup to find the right handler, and then pokes the address of the right handler back in the call instruction. A similar technique has been used in some Lisp systems ("snapping links"). Indirection can be used instead, at a price.