Mantis Bugtracker
  

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0007429 [Squeak] VM feature always 12-16-09 02:00 01-05-12 06:04
Reporter lewis View Status public  
Assigned To lewis
Priority normal Resolution open  
Status testing   Product Version
Summary 0007429: Add Mirror Primitives to the VM
Description Mirror primitives have been implemented by Eliot Miranda, and discussed on the squeak-dev list (September 2009 in "Mirror primitives" thread). Eliot posted a VM implementation (http://lists.squeakfoundation.org/pipermail/vm-dev/2009-September/003161.html), [^] which should be incorporated in the Squeak VM.
Additional Information Excerpt from Eliot's posting to vm-dev:
The idea is to add a set of mirror primitives, so called because they do reflection, to ContextPart. These primitives implement the basic operations of the object model needed for execution simulation, fetching an object's class, accessing its named and indexed instance variables, and the number of indexed instance variables, sending a message, but they take the object operated on as a parameter and so do function without sending messages to that object. These primitives are then used by the execution simulation machinery to correctly simulate the execution of the virtual machine irrespective of the class and/or messages implemented by the receiver.
Attached Files  MirrorPrimitivesVM.st [^] (11,208 bytes) 12-16-09 02:01
 MirrorPrimitives.st [^] (24,501 bytes) 12-16-09 02:02

- Relationships

- Notes
(0013434 - 261 - 261 - 467 - 467 - 467 - 467)
lewis
12-16-09 02:04

MirrorPrimitivesVM.st is Eliot's VM code from http://lists.squeakfoundation.org/pipermail/vm-dev/2009-September/003161.html, [^] which is the code that needs to be integrated into the VM. MirrorPrimitives.st is the image side code, included here for reference only.
 
(0013435 - 487 - 633 - 633 - 633 - 633 - 633)
lewis
12-16-09 04:54

A few things will need to be updated in order for this to work in the standard Squeak VM:
  move methods from StackInterpreter to class Interpreter
  change <inline: true> ==> self inline: true
  change <var: #addr declareC: 'void (*addr)()'> ==> self var: #addr declareC: 'void (*addr)()'
  primDoNamedPrimitiveWithArgs modified a lot, validate changes
  #primitiveFailFor: not implemented
  PrimErrBadArgument undefined
  PrimErrBadIndex undefined
  PrimErrBadNumArgs undefined
 
(0014206 - 2398 - 2624 - 2624 - 2624 - 2624 - 2624)
lewis
12-11-11 00:32

Additional information provided by Eliot to assist implementation (private email):

So here's the deal with the mirror primitives. If one uses instVarAt:
instVarAt:put: class et al in the simulation machinery to fetch and store
inst vars and lookup messages one is *not* doing what the VM does. The VM
does not send a message to access a field of an object, it directly
accesses that object. So if in the debugger one is e.g. operating on a
proxy then sending instVarAt: to fetch an inst var of that proxy instead
invokes the proxy's doesNotUnderstand: machinery and answers whatever that
answers. Instead the debugger should use a set of primitives that access
object state directly. These are the mirror primitives. They are
implemented on ContextPart so that a context says e.g. self object: self
receiver instVarAt: index put: self top to store an inst var. The message
object:instVarAt:put: isn't sent to self receiver, it is sent to the
context, so it will be understood. Inside the primitive it will access the
relevant field of the object: argument, and so will simulate what the VM
does when fetching an inst var.

For this to work the mirror primitives, which are similar to their
non-mirror counterparts, must a) fetch/store from/to their object: argument
and b) pop the extra argument. A reasonable way to do this in a Squeak VM,
where primitives can take variable number of arguments, is to have the
normal primitives for basicAt:, basicAt:put:, basicSize, instVarAt:,
instVarAt:put:, ==, class and perform:withArguments:inSuperclass:
(primitives 60, 61, 62, 73, 74, 110, 111, 100) use argumentCount to pop the
right number of arguments and not assume what their argument count is.
 This is trivial in all but the perform primitive. i.e. in all but the
perform: primitive we just do self pop: argumentCount thenPush: result.

In the case of perform:withArguments:inSuperclass: there are complications
to do with maintaining newMethod. One can't use pushRemapableOop: because
control may never return and so the remappable oop stack can overflow.
 Instead newMethod gets pushed onto the stack and popped off later on. See
StackInterpreter>>primitiveObject:perform:withArguments:lookedUpIn:. In
the Interpreter there needs to be an additional check to see that the
current context is large enough to have the arguments pushed on its stack.
 
(0014207 - 132 - 132 - 132 - 132 - 132 - 132)
lewis
12-11-11 19:31

As of VMMaker-dtl.261, five of six mirror primitive tests are passing. An update is still required for primitivePerformInSuperclass.
 
(0014212 - 60 - 66 - 66 - 66 - 66 - 66)
lewis
01-05-12 06:04

As of VMMaker-dtl.262 all mirror primitive tests now pass.
 

- Issue History
Date Modified Username Field Change
12-16-09 02:00 lewis New Issue
12-16-09 02:00 lewis Status new => assigned
12-16-09 02:00 lewis Assigned To  => lewis
12-16-09 02:01 lewis File Added: MirrorPrimitivesVM.st
12-16-09 02:02 lewis File Added: MirrorPrimitives.st
12-16-09 02:04 lewis Note Added: 0013434
12-16-09 04:54 lewis Note Added: 0013435
12-11-11 00:32 lewis Note Added: 0014206
12-11-11 19:31 lewis Note Added: 0014207
01-05-12 06:04 lewis Note Added: 0014212
01-05-12 06:04 lewis Status assigned => testing


Mantis 1.0.8[^]
Copyright © 2000 - 2007 Mantis Group
54 total queries executed.
36 unique queries executed.
Powered by Mantis Bugtracker