[Vm-dev] byteSizeOf: is that correct for 64bit images? Also what about the (sqInt)(long)

David T. Lewis lewis at mail.msen.com
Mon Dec 21 00:17:11 UTC 2009


On Mon, Dec 21, 2009 at 12:56:01AM +0100, Bert Freudenberg wrote:
> 
> On 21.12.2009, at 00:44, David T. Lewis wrote:
> > 
> > 
> > On Sun, Dec 20, 2009 at 02:45:59PM -0800, John M McIntosh wrote:
> >> 
> >> Ok, I have to ask, is this correct?    Er 4 or 8 or does it matter, do we have other '4' values embedded in the interpreter? 
> >> byteSizeOf: oop
> >> 	| slots |
> >> self flag: #Dan.
> >> 	(self isIntegerObject: oop) ifTrue:[^0].
> >> 	slots := self slotSizeOf: oop.
> >> 	(self isBytesNonInt: oop)
> >> 		ifTrue:[^slots]
> >> 		ifFalse:[^slots * 4]
> >> 
> > 
> > No, this is not correct, good catch. It should be:
> > 
> >  byteSizeOf: oop
> >  	| slots |
> >  self flag: #Dan.
> >  	(self isIntegerObject: oop) ifTrue:[^0].
> >  	slots := self slotSizeOf: oop.
> >  	(self isBytesNonInt: oop)
> >  		ifTrue:[^slots]
> >  		ifFalse:[^slots * ObjectMemory bytesPerWord]
> > 
> > I've clean a lot of this crud out of the interpreter, but there are bound
> > to be a few more that we have not spotted yet.
> > 
> > Dave
> > 
> 
> Does "ObjectMemory bytesPerWord" compile to a constant?

Bert,

Obviously you are not using SlangBrowser ;-)

Yes, it answers a constant. The implementation is just this:

  /*	Answer the size of an object memory word in bytes. */
  sqInt bytesPerWord(void) {
  	return BytesPerWord;
  }

The method is inlined, so it basically translates into the CPP macro
BytesPerWord. Thus #bytesSizeOf: is translated as follows (this is with
MemoryAccess enabled so you can see the the full C code, not just the
macros):

  sqInt byteSizeOf(sqInt oop) {
      sqInt slots;
      sqInt header;
      sqInt sz;
  
  	flag("Dan");
  	if ((oop & 1)) {
  		return 0;
  	}
  	/* begin slotSizeOf: */
  	if ((oop & 1)) {
  		slots = 0;
  		goto l1;
  	}
  	/* begin lengthOf: */
  	header = ((sqInt) ((((sqInt *) ((sqMemoryBase) + oop)))[0]));
  	/* begin lengthOf:baseHeader:format: */
  	if ((header & TypeMask) == HeaderTypeSizeAndClass) {
  		sz = (((sqInt) ((((sqInt *) ((sqMemoryBase) + (oop - (BytesPerWord * 2)))))[0]))) & LongSizeMask;
  	} else {
  		sz = header & SizeMask;
  	}
  	sz -= header & Size4Bit;
  	if (((((usqInt) header) >> 8) & 15) <= 4) {
  		slots = ((usqInt) (sz - BaseHeaderSize)) >> ShiftForWord;
  		goto l2;
  	}
  	if (((((usqInt) header) >> 8) & 15) < 8) {
  		slots = ((usqInt) (sz - BaseHeaderSize)) >> 2;
  		goto l2;
  	} else {
  		slots = (sz - BaseHeaderSize) - (((((usqInt) header) >> 8) & 15) & 3);
  		goto l2;
  	}
  	slots = null;
  l2:	/* end lengthOf: */;
  l1:	/* end slotSizeOf: */;
  	if (((((usqInt) (((sqInt) ((((sqInt *) ((sqMemoryBase) + oop)))[0])))) >> 8) & 15) >= 8) {
  		return slots;
  	} else {
  		return slots * ( 4);
  	}
  }

Dave
 


More information about the Vm-dev mailing list