[Vm-dev] Return a value from the image to the VM

John M McIntosh johnmci at smalltalkconsulting.com
Thu Nov 26 05:13:11 UTC 2009


Well let's see likely you should have in 
ObjectMemory>>initializeObjectMemory: 
osErrorCode := 0 ;

just for completeness to ensure it has a explicit value you set, versus a supposed zero value. 

Now you need an accessor. 

So on 
Interpreter>>getOsErrorCode
	^osErrorCode;

and likely you need to add 
getOsErrorCode as a required method to the requiredList in 
Interpreter (class)>>requiredMethodNames. 

Otherwise the Slang logic will delete the method getOsErrorCode as not being used and it 
won't generate the expected "C" code. 

Then in your platform ioExit()  you need to add 
extern sqInt getOsErrorCode(void); 

sqInt myReturnErrorCode = getOsErrorCode();


To answer your other question, if an instance variable is declared in the ObjectMemory or Interpreter class it ends up 
as a static variable in interp.c (or in the global Foo structure), unless a unique condition is met. 

The Slang generator inlines methods so methods not in requiredMethodNames could be folded into the caller. 
This historically has generated better code than what compiler in-line optimization can do. 
If a method can be folded into the caller, then based on  requiredMethodNames it might not exist as a standalone method anymore. 

Now a special further optimization which greatly improved GC behaviour on register rich machines was to 
consider changing a instance variable from a static global to a procedure local variable if after code inlining it was discovered 
that all references to the variable are within a single method.  

In this case because you have two method primitiveSetOSErrorCode, and getOsErrorCode it will remain a global var, 
and change to requiredMethodNames ensures the getOsErrorCode procedure gets created. 


On 2009-11-25, at 8:49 PM, Rob Rothwell wrote:

> Oh...I just did:
> 
> Interpreter>>primitiveSetOSErrorCode
> 	| value |
> 	self export: true.
> 	value := self stackIntegerValue: 0.
> 	successFlag ifTrue:[
> 		osErrorCode  := value.
> 		self pop: argumentCount.
> 	].
> 
> where 
> 
> osErrorCode is an instvar in Interpreter...
> 
> (I found the variable declarations in interp.c, including gcBiasToGrowGCLimit like you pointed out, but I don't see how it ended up there!)
> 
> Rob
> 
> On Wed, Nov 25, 2009 at 11:08 PM, John M McIntosh <johnmci at smalltalkconsulting.com> wrote:
> How about pasting your smalltalk code for primitiveSetOSErrorCode
> 
> On 2009-11-25, at 7:06 PM, Rob Rothwell wrote:
> 
> > I miraculously managed to somehow load VMMaker in Pharo on Windows XP.
> >
> > Furthermore, I managed to create a new Primitive:  Interpreter>>primitiveSetOSErrorCode.
> >
> > I was even able to use that primitive without the VM crashing!
> >
> > But I can't seem to find the declaration of my instance variable osErrorCode outside the scope of the primitive so I can use it in ioExit...
> >
> > Any tips?  Is there something special you have to do to create the instance variables?
> >
> > Thanks again for pointing me in the right direction...
> >
> > Rob
> --
> ===========================================================================
> John M. McIntosh <johnmci at smalltalkconsulting.com>   Twitter:  squeaker68882
> Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
> ===========================================================================
> 
> 
> 
> 
> 

--
===========================================================================
John M. McIntosh <johnmci at smalltalkconsulting.com>   Twitter:  squeaker68882
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
===========================================================================






More information about the Vm-dev mailing list