reflection (was: Fare's response on threads)
Jecel Assumpcao Jr
jecel@tunes.org
Mon, 18 Sep 2000 21:45:13 -0300
Lynn,
let me give you an example of what I mean by a "model of its inner
operation". Even though you are not particularly fond of C, I will use
it to illustrate what I am talking about.
First we will group some numbers together:
struct memUsage { char * codeStart ;
int codeLength ;
char * stackTop, * stackBase
} aMem ;
Now I will imagine that my trusty OS has a procedure that I can call to
fill in these numbers for the calling application:
myCurrentMemoryUsage ( aMem ) ;
These four numbers are a simple model of the inner operation of the
running program. I never said it was a complete model, specially since
that is impossible. But in a way, the program now "knows" where it was
loaded in memory and what resources it is using.
We will make a change to our model:
aMem.codeStart += 512*1024 ;
So far, nothing interesting happened. But what if the OS also has a
procedure for "reflecting" changes from my simple model back into the
real world?
reflectMemoryUsage ( aMem ) ;
It might reject changes to codeLength, stackBase or stackTop (though
next year's release might handle them). But noting that we only changed
codeStart it might copy the program up half a megabyte and ajust
anything that is needed to make sure it can continue to run when the
call returns.
Why did I do this silly thing? I might be trying to run on an early
Amiga computer where the first 512KB were "chip" memory that was shared
with the video display. All memory above that wasn't shared and was
twice as fast. Does my program "know" about any of this? No! It is only
doing what it was told by a human who happens to know these details.
But it does have a small piece of information about its own operation
and the means to change it. And that is what I mean by reflection. No
more. No less.
All operating systems are reflective to some degree. They must be to
get their job done. And yes, you can build a system with any number of
reflective layers. I showed just one in my example, but it is easy to
imagine more complex cases.
-- Jecel