[Vm-dev] Why primitive new have unexpected temp affectation

Adrian Lienhard adi at netstyle.ch
Mon Aug 13 08:08:30 UTC 2007

Hi Mathieu,

Not sure if I understand you correctly. Do you mean, why stackValue:  
1 is read twice?
The reason for this is because  
#sufficientSpaceToInstantiate:indexableSize: may trigger GC (as the  
comment says), and therefore the temp pointer to the class, which is  
read before, may not be valid anymore. In this case the simplest  
thing to do is to get the pointer from the stack again.  
Alternatively, you could also manually remap the temp (see  
#pushRemappableOop: and #popRemappableOop). So, it is really necessary.

Adrian Lienhard

On Aug 13, 2007, at 01:46 , Mathieu Suen wrote:

> Hi,
> I have look at the code of the primitiveNew and it seems that the  
> temporaries is affect twice which don't make sense:
> primitiveNewWithArg
> 	"Allocate a new indexable instance. Fail if the allocation would  
> leave less than lowSpaceThreshold bytes free."
> 	| size class spaceOkay |
> 	size := self positive32BitValueOf: self stackTop.
> 	class := self stackValue: 1.
> 	self success: size >= 0.
> 	successFlag
> 		ifTrue: ["The following may cause GC!"
> 			spaceOkay := self sufficientSpaceToInstantiate: class  
> indexableSize: size.
> 			self success: spaceOkay.
> 			class := self stackValue: 1].
> 	successFlag ifTrue: [self pop: 2 thenPush: (self instantiateClass:  
> class indexableSize: size)]
> The first affectation is not necessary. Isn't it?
> 	Mth

More information about the Vm-dev mailing list