> I'm working on a tool that trace the excecution of the block (I need to know 
> all the objects and methods touched by the block and the methodes inside 
> these 
> methods). With something like this :
> 
> [ blablabla ] trace.
> 
> So I want to mark the context with a flag to know if the current context is 
> traced or not and in the method send_message I simply look at the flag in the 
> current context and store the result or not.
> 
> I've looked at the VM code and it seems that the contexts are allocated with 
> the method  alloc_stack_context. So in this method I initialise the trace 
> variable with 0.

Have you checked that using DebugTools is too slow?

Initialization of the new context is done in activate_new_context,
that's probably a better place.

Also, alternatively you can use the checks that are already in place for
the profiler, so that you don't introduce more ifs on a very hpt path.

Alternatively, what about instrumenting the methods and replacing them
dynamically?  That is, rewrite something like:

   self abc.
   self def: 3.
to

   Tracer current on: self perform: #abc.
   Tracer current on: self perform: #def: with: 3.

Inside the tracer object, you keep a mapping between untraced methods
and traced methods, and do something like:

   on: receiver perform: aSymbol
       | method |
       "Make this a primitive if it is too slow."
       method := receiver class lookupSelector: aSymbol.
       method isNil ifTrue: [ ... handle doesNotUnderstand ... ].
       self on: receiver trace: method.
       ^receiver perform: (self tracingMethodAt: method)

Right now there is no instruction stream class (it's all in STCompiler
in the Parser package), but maybe you have already written one? :-)

Paolo


_______________________________________________
help-smalltalk mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

Reply via email to