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] Also what about byteSize := interpreterProxy byteSizeOf: fontFilePath cPtrAsOop. where we have, note the (sqInt)(long) generateCPtrAsOop: aNode on: aStream indent: anInteger aStream nextPutAll: '((sqInt)(long)('. self emitCExpression: aNode receiver on: aStream. aStream nextPutAll: ') - '; nextPutAll: ObjectMemory baseHeaderSize printString; nextPut: $). Translates to byteSize = interpreterProxy->byteSizeOf(((sqInt)(long)(fontFilePath) - 4)); which of course is wrong. See http://bugs.squeak.org/view.php?id=7431 -- =========================================================================== John M. McIntosh <[hidden email]> Twitter: squeaker68882 Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com =========================================================================== |
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 |
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 - |
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 |
On 21.12.2009, at 01:17, David T. Lewis wrote: > > > 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. Thanks :) I'd find it more readable and more revealing to use BytesPerWord directly, as is done in almost all other places: ... ifFalse:[^slots * BytesPerWord] - Bert - |
On Mon, Dec 21, 2009 at 01:32:52AM +0100, Bert Freudenberg wrote: > > On 21.12.2009, at 01:17, David T. Lewis wrote: > > > > > > On Mon, Dec 21, 2009 at 12:56:01AM +0100, Bert Freudenberg wrote: > >> > >> Does "ObjectMemory bytesPerWord" compile to a constant? > > > > Yes, it answers a constant. > > I'd find it more readable and more revealing to use BytesPerWord directly, as is done in almost all other places: > > ... ifFalse:[^slots * BytesPerWord] > You're right, I should have done it that way. I'll make a note to fix it next time I commit something to SqS. Dave |
Careful, this is a class var. This does not work on external plugins, so I think you'll find the proper pattern is self bytesPerWord which does the right thing if the code is in a plugin versus ObjectMemory or subclass of. On 2009-12-20, at 5:42 PM, David T. Lewis wrote: >> BytesPerWord -- =========================================================================== John M. McIntosh <[hidden email]> Twitter: squeaker68882 Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com =========================================================================== |
On Sun, Dec 20, 2009 at 06:11:11PM -0800, John M McIntosh wrote: > > On 2009-12-20, at 5:42 PM, David T. Lewis wrote: > > >> BytesPerWord > > Careful, this is a class var. > > This does not work on external plugins, so I think you'll find the proper pattern is > > self bytesPerWord which does the right thing if the code is in a plugin versus ObjectMemory or subclass of. Indeed. Thanks John. |
Free forum by Nabble | Edit this page |