socketRecordSize is probably not 64-bit friendly

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

socketRecordSize is probably not 64-bit friendly

Nicolas Cellier
 
Hi,
I noticed that SocketPlugin>>socketRecordSize was so defined:
socketRecordSize
    "Return the size of a Smalltalk socket record in bytes."

    ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [12]


Shouldn't it have been like its brothers in OSProcessPlugin and AioPlugin:

socketRecordSize
    "Return the size of a Smalltalk socket record in bytes."

    ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [Smalltalk wordSize * 3]


I presume we don't use self sizeof: because the Smalltalk side does not have any idea of what a SQSocket is... (an opaque struct/handle)
Reply | Threaded
Open this post in threaded view
|

Re: socketRecordSize is probably not 64-bit friendly

David T. Lewis
 
On Sun, Mar 22, 2015 at 05:04:12PM +0100, Nicolas Cellier wrote:

>  
> Hi,
> I noticed that SocketPlugin>>socketRecordSize was so defined:
> socketRecordSize
>     "Return the size of a Smalltalk socket record in bytes."
>
>     ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [12]
>
>
> Shouldn't it have been like its brothers in OSProcessPlugin and AioPlugin:
>
> socketRecordSize
>     "Return the size of a Smalltalk socket record in bytes."
>
>     ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [Smalltalk wordSize * 3]
>
>
> I presume we don't use self sizeof: because the Smalltalk side does not
> have any idea of what a SQSocket is... (an opaque struct/handle)

On my machine, sizeof(SQSocket) is 16 for both 32 bits and 64 bits. I would
have expected it to be 12 for the 32-bit case, but maybe the compiler is
aligning it differently for some reason.

In any case, "Smalltalk wordSize * 3" would not be right, because the
actual data structure is this:

        typedef struct
        {
          int   sessionID;
          int   socketType;  /* 0 = TCP, 1 = UDP */
          void  *privateSocketPtr;
        }  SQSocket, *SocketPtr;


In order to cover the common cases, it might be best to just change
the implementation to this:

     ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [16]

Dave
Reply | Threaded
Open this post in threaded view
|

Re: socketRecordSize is probably not 64-bit friendly

David T. Lewis
 
On Sun, Mar 22, 2015 at 01:58:05PM -0400, David T. Lewis wrote:

>  
> On Sun, Mar 22, 2015 at 05:04:12PM +0100, Nicolas Cellier wrote:
> >  
> > Hi,
> > I noticed that SocketPlugin>>socketRecordSize was so defined:
> > socketRecordSize
> >     "Return the size of a Smalltalk socket record in bytes."
> >
> >     ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [12]
> >
> >
> > Shouldn't it have been like its brothers in OSProcessPlugin and AioPlugin:
> >
> > socketRecordSize
> >     "Return the size of a Smalltalk socket record in bytes."
> >
> >     ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [Smalltalk wordSize * 3]
> >
> >
> > I presume we don't use self sizeof: because the Smalltalk side does not
> > have any idea of what a SQSocket is... (an opaque struct/handle)
>
> On my machine, sizeof(SQSocket) is 16 for both 32 bits and 64 bits. I would
> have expected it to be 12 for the 32-bit case, but maybe the compiler is
> aligning it differently for some reason.
>
> In any case, "Smalltalk wordSize * 3" would not be right, because the
> actual data structure is this:
>
> typedef struct
> {
>  int   sessionID;
>  int   socketType;  /* 0 = TCP, 1 = UDP */
>  void  *privateSocketPtr;
> }  SQSocket, *SocketPtr;
>
>
> In order to cover the common cases, it might be best to just change
> the implementation to this:
>
>      ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [16]
>

Hmmm, that of course also means that I should fix it in the OSProcess
plugin. What on earth was I thinking when I wrote that?!?

Thanks for noticing.

Dave

Reply | Threaded
Open this post in threaded view
|

Re: socketRecordSize is probably not 64-bit friendly

Eliot Miranda-2
In reply to this post by David T. Lewis

Hi David,

On Mar 22, 2015, at 10:58 AM, "David T. Lewis" <[hidden email]> wrote:

>
> On Sun, Mar 22, 2015 at 05:04:12PM +0100, Nicolas Cellier wrote:
>>
>> Hi,
>> I noticed that SocketPlugin>>socketRecordSize was so defined:
>> socketRecordSize
>>    "Return the size of a Smalltalk socket record in bytes."
>>
>>    ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [12]
>>
>>
>> Shouldn't it have been like its brothers in OSProcessPlugin and AioPlugin:
>>
>> socketRecordSize
>>    "Return the size of a Smalltalk socket record in bytes."
>>
>>    ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [Smalltalk wordSize * 3]
>>
>>
>> I presume we don't use self sizeof: because the Smalltalk side does not
>> have any idea of what a SQSocket is... (an opaque struct/handle)
>
> On my machine, sizeof(SQSocket) is 16 for both 32 bits and 64 bits. I would
> have expected it to be 12 for the 32-bit case, but maybe the compiler is
> aligning it differently for some reason.
>
> In any case, "Smalltalk wordSize * 3" would not be right, because the
> actual data structure is this:
>
>    typedef struct
>    {
>      int   sessionID;
>      int   socketType;  /* 0 = TCP, 1 = UDP */
>      void  *privateSocketPtr;
>    }  SQSocket, *SocketPtr;
>
>
> In order to cover the common cases, it might be best to just change
> the implementation to this:
>
>     ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [16]

No, no and thrice no!  :). It should /always/ be written

     ^self sizeof: #SQSocket

and the size answered in a sizeof: implementation marked <doNotGenerate>.  That way
- there is one def not one in potentially multiple clients
- you don't even need the sizeOfSQSocket method in the first place.

Please see VMMaker.oscog

Eliot (phone)
Reply | Threaded
Open this post in threaded view
|

Re: socketRecordSize is probably not 64-bit friendly

David T. Lewis
In reply to this post by David T. Lewis
 
On Sun, Mar 22, 2015 at 01:58:05PM -0400, David T. Lewis wrote:

>  
> On Sun, Mar 22, 2015 at 05:04:12PM +0100, Nicolas Cellier wrote:
> >  
> > Hi,
> > I noticed that SocketPlugin>>socketRecordSize was so defined:
> > socketRecordSize
> >     "Return the size of a Smalltalk socket record in bytes."
> >
> >     ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [12]
> >
> >
> > Shouldn't it have been like its brothers in OSProcessPlugin and AioPlugin:
> >
> > socketRecordSize
> >     "Return the size of a Smalltalk socket record in bytes."
> >
> >     ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [Smalltalk wordSize * 3]
> >
> >
> > I presume we don't use self sizeof: because the Smalltalk side does not
> > have any idea of what a SQSocket is... (an opaque struct/handle)
>
> On my machine, sizeof(SQSocket) is 16 for both 32 bits and 64 bits. I would
> have expected it to be 12 for the 32-bit case, but maybe the compiler is
> aligning it differently for some reason.
>
> In any case, "Smalltalk wordSize * 3" would not be right, because the
> actual data structure is this:
>
> typedef struct
> {
>  int   sessionID;
>  int   socketType;  /* 0 = TCP, 1 = UDP */
>  void  *privateSocketPtr;
> }  SQSocket, *SocketPtr;
>
>
> In order to cover the common cases, it might be best to just change
> the implementation to this:
>
>      ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [16]

Forgive me, I just realized that I was accidentally running a 64-bit
VM when I thought it was a 32-bit VM. So the size of a SQSocket will
typically be 12 bytes on a 32-bit host, and 16 bytes on a 64-bit host,
regardless of whether the image word size is 32-bit or 64-bit.

Dave
Reply | Threaded
Open this post in threaded view
|

Re: socketRecordSize is probably not 64-bit friendly

Holger Freyther
In reply to this post by David T. Lewis
 
On Sun, Mar 22, 2015 at 01:58:05PM -0400, David T. Lewis wrote:

> On my machine, sizeof(SQSocket) is 16 for both 32 bits and 64 bits. I would
> have expected it to be 12 for the 32-bit case, but maybe the compiler is
> aligning it differently for some reason.

yes, it should be 12 :)



> In any case, "Smalltalk wordSize * 3" would not be right, because the
> actual data structure is this:
>
> typedef struct
> {
>  int   sessionID;
>  int   socketType;  /* 0 = TCP, 1 = UDP */
>  void  *privateSocketPtr;
> }  SQSocket, *SocketPtr;


$ vi test.c
struct SQSocket {
        int sessionID;
        int socketType;
        void *privateSocketPtr;
};

extern void bla(struct SQSocket*);

int foo(void)
{
        struct SQSocket sock;
        bla(&sock);
}

$ cc -o test.o -ggdb3 -c test.c

$ pahole test.o
struct SQSocket {
        int                        sessionID;            /*     0     4 */
        int                        socketType;           /*     4     4 */
        void *                     privateSocketPtr;     /*     8     4 */

        /* size: 12, cachelines: 1, members: 3 */
        /* last cacheline: 12 bytes */
};


Does it really say 16 for you on ia32?
Reply | Threaded
Open this post in threaded view
|

Re: socketRecordSize is probably not 64-bit friendly

David T. Lewis
In reply to this post by Eliot Miranda-2
 
On Sun, Mar 22, 2015 at 11:27:05AM -0700, Eliot Miranda wrote:

>
> Hi David,
>
> On Mar 22, 2015, at 10:58 AM, "David T. Lewis" <[hidden email]> wrote:
>
> >
> > On Sun, Mar 22, 2015 at 05:04:12PM +0100, Nicolas Cellier wrote:
> >>
> >> Hi,
> >> I noticed that SocketPlugin>>socketRecordSize was so defined:
> >> socketRecordSize
> >>    "Return the size of a Smalltalk socket record in bytes."
> >>
> >>    ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [12]
> >>
> >>
> >> Shouldn't it have been like its brothers in OSProcessPlugin and AioPlugin:
> >>
> >> socketRecordSize
> >>    "Return the size of a Smalltalk socket record in bytes."
> >>
> >>    ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [Smalltalk wordSize * 3]
> >>
> >>
> >> I presume we don't use self sizeof: because the Smalltalk side does not
> >> have any idea of what a SQSocket is... (an opaque struct/handle)
> >
> > On my machine, sizeof(SQSocket) is 16 for both 32 bits and 64 bits. I would
> > have expected it to be 12 for the 32-bit case, but maybe the compiler is
> > aligning it differently for some reason.
> >
> > In any case, "Smalltalk wordSize * 3" would not be right, because the
> > actual data structure is this:
> >
> >    typedef struct
> >    {
> >      int   sessionID;
> >      int   socketType;  /* 0 = TCP, 1 = UDP */
> >      void  *privateSocketPtr;
> >    }  SQSocket, *SocketPtr;
> >
> >
> > In order to cover the common cases, it might be best to just change
> > the implementation to this:
> >
> >     ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [16]
>
> No, no and thrice no!  :). It should /always/ be written
>
>      ^self sizeof: #SQSocket
>
> and the size answered in a sizeof: implementation marked <doNotGenerate>.  That way
> - there is one def not one in potentially multiple clients
> - you don't even need the sizeOfSQSocket method in the first place.
>
> Please see VMMaker.oscog
>

Ok.

I note for the record that SocketPlugin>>socketRecordSize has a time stamp
of 2/22/2000 ;-)

Dave

Reply | Threaded
Open this post in threaded view
|

Re: socketRecordSize is probably not 64-bit friendly

Eliot Miranda-2
 
Hi David,

On Sun, Mar 22, 2015 at 11:43 AM, David T. Lewis <[hidden email]> wrote:

On Sun, Mar 22, 2015 at 11:27:05AM -0700, Eliot Miranda wrote:
>
> Hi David,
>
> On Mar 22, 2015, at 10:58 AM, "David T. Lewis" <[hidden email]> wrote:
>
> >
> > On Sun, Mar 22, 2015 at 05:04:12PM +0100, Nicolas Cellier wrote:
> >>
> >> Hi,
> >> I noticed that SocketPlugin>>socketRecordSize was so defined:
> >> socketRecordSize
> >>    "Return the size of a Smalltalk socket record in bytes."
> >>
> >>    ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [12]
> >>
> >>
> >> Shouldn't it have been like its brothers in OSProcessPlugin and AioPlugin:
> >>
> >> socketRecordSize
> >>    "Return the size of a Smalltalk socket record in bytes."
> >>
> >>    ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [Smalltalk wordSize * 3]
> >>
> >>
> >> I presume we don't use self sizeof: because the Smalltalk side does not
> >> have any idea of what a SQSocket is... (an opaque struct/handle)
> >
> > On my machine, sizeof(SQSocket) is 16 for both 32 bits and 64 bits. I would
> > have expected it to be 12 for the 32-bit case, but maybe the compiler is
> > aligning it differently for some reason.
> >
> > In any case, "Smalltalk wordSize * 3" would not be right, because the
> > actual data structure is this:
> >
> >    typedef struct
> >    {
> >      int   sessionID;
> >      int   socketType;  /* 0 = TCP, 1 = UDP */
> >      void  *privateSocketPtr;
> >    }  SQSocket, *SocketPtr;
> >
> >
> > In order to cover the common cases, it might be best to just change
> > the implementation to this:
> >
> >     ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [16]
>
> No, no and thrice no!  :). It should /always/ be written
>
>      ^self sizeof: #SQSocket
>
> and the size answered in a sizeof: implementation marked <doNotGenerate>.  That way
> - there is one def not one in potentially multiple clients
> - you don't even need the sizeOfSQSocket method in the first place.
>
> Please see VMMaker.oscog
>

Ok.

I note for the record that SocketPlugin>>socketRecordSize has a time stamp
of 2/22/2000 ;-)

:)

Please find a version of the AioPlugin that has this change attached.  I can't commit to the repo.  I hope you'll find it fit to upload yourself :)
--
best,
Eliot

VMConstruction-Plugins-AioPlugin-eem.18.mcz (17K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: socketRecordSize is probably not 64-bit friendly

David T. Lewis
 

>  Hi David,
>
> On Sun, Mar 22, 2015 at 11:43 AM, David T. Lewis <[hidden email]>
> wrote:
>
>>
>> On Sun, Mar 22, 2015 at 11:27:05AM -0700, Eliot Miranda wrote:
>> >
>> > Hi David,
>> >
>> > On Mar 22, 2015, at 10:58 AM, "David T. Lewis" <[hidden email]>
>> wrote:
>> >
>> > >
>> > > On Sun, Mar 22, 2015 at 05:04:12PM +0100, Nicolas Cellier wrote:
>> > >>
>> > >> Hi,
>> > >> I noticed that SocketPlugin>>socketRecordSize was so defined:
>> > >> socketRecordSize
>> > >>    "Return the size of a Smalltalk socket record in bytes."
>> > >>
>> > >>    ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [12]
>> > >>
>> > >>
>> > >> Shouldn't it have been like its brothers in OSProcessPlugin and
>> AioPlugin:
>> > >>
>> > >> socketRecordSize
>> > >>    "Return the size of a Smalltalk socket record in bytes."
>> > >>
>> > >>    ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [Smalltalk
>> wordSize
>> * 3]
>> > >>
>> > >>
>> > >> I presume we don't use self sizeof: because the Smalltalk side does
>> not
>> > >> have any idea of what a SQSocket is... (an opaque struct/handle)
>> > >
>> > > On my machine, sizeof(SQSocket) is 16 for both 32 bits and 64 bits.
>> I
>> would
>> > > have expected it to be 12 for the 32-bit case, but maybe the
>> compiler
>> is
>> > > aligning it differently for some reason.
>> > >
>> > > In any case, "Smalltalk wordSize * 3" would not be right, because
>> the
>> > > actual data structure is this:
>> > >
>> > >    typedef struct
>> > >    {
>> > >      int   sessionID;
>> > >      int   socketType;  /* 0 = TCP, 1 = UDP */
>> > >      void  *privateSocketPtr;
>> > >    }  SQSocket, *SocketPtr;
>> > >
>> > >
>> > > In order to cover the common cases, it might be best to just change
>> > > the implementation to this:
>> > >
>> > >     ^ self cCode: 'sizeof(SQSocket)' inSmalltalk: [16]
>> >
>> > No, no and thrice no!  :). It should /always/ be written
>> >
>> >      ^self sizeof: #SQSocket
>> >
>> > and the size answered in a sizeof: implementation marked
>> <doNotGenerate>.  That way
>> > - there is one def not one in potentially multiple clients
>> > - you don't even need the sizeOfSQSocket method in the first place.
>> >
>> > Please see VMMaker.oscog
>> >
>>
>> Ok.
>>
>> I note for the record that SocketPlugin>>socketRecordSize has a time
>> stamp
>> of 2/22/2000 ;-)
>>
>
> :)
>
> Please find a version of the AioPlugin that has this change attached.  I
> can't commit to the repo.  I hope you'll find it fit to upload yourself :)
> --

Thanks Eliot,

I'll update it as soon as I can (probably tomorrow night).

Dave


Reply | Threaded
Open this post in threaded view
|

Re: socketRecordSize is probably not 64-bit friendly

David T. Lewis
In reply to this post by Eliot Miranda-2
 
On Mon, Mar 23, 2015 at 10:22:00AM -0700, Eliot Miranda wrote:

>  
> On Sun, Mar 22, 2015 at 11:43 AM, David T. Lewis <[hidden email]>
> wrote:
> >
> > On Sun, Mar 22, 2015 at 11:27:05AM -0700, Eliot Miranda wrote:
> > >
> > > No, no and thrice no!  :). It should /always/ be written
> > >
> > >      ^self sizeof: #SQSocket
> > >
> > > and the size answered in a sizeof: implementation marked
> > <doNotGenerate>.  That way
> > > - there is one def not one in potentially multiple clients
> > > - you don't even need the sizeOfSQSocket method in the first place.
> > >
> > > Please see VMMaker.oscog
> > >
> >
> > Ok.
> >
> > I note for the record that SocketPlugin>>socketRecordSize has a time stamp
> > of 2/22/2000 ;-)
> >
>
> :)
>
> Please find a version of the AioPlugin that has this change attached.  I
> can't commit to the repo.  I hope you'll find it fit to upload yourself :)


Thanks Eliot,

VMConstruction-Plugins-AioPlugin-eem.18 is moved into the repository.

I may have forgotten to mention it before, but you do indeed have write
access to the AioPlugin repository.

Dave

Reply | Threaded
Open this post in threaded view
|

Re: socketRecordSize is probably not 64-bit friendly

Eliot Miranda-2
 


On Tue, Mar 24, 2015 at 6:39 PM, David T. Lewis <[hidden email]> wrote:

On Mon, Mar 23, 2015 at 10:22:00AM -0700, Eliot Miranda wrote:
>
> On Sun, Mar 22, 2015 at 11:43 AM, David T. Lewis <[hidden email]>
> wrote:
> >
> > On Sun, Mar 22, 2015 at 11:27:05AM -0700, Eliot Miranda wrote:
> > >
> > > No, no and thrice no!  :). It should /always/ be written
> > >
> > >      ^self sizeof: #SQSocket
> > >
> > > and the size answered in a sizeof: implementation marked
> > <doNotGenerate>.  That way
> > > - there is one def not one in potentially multiple clients
> > > - you don't even need the sizeOfSQSocket method in the first place.
> > >
> > > Please see VMMaker.oscog
> > >
> >
> > Ok.
> >
> > I note for the record that SocketPlugin>>socketRecordSize has a time stamp
> > of 2/22/2000 ;-)
> >
>
> :)
>
> Please find a version of the AioPlugin that has this change attached.  I
> can't commit to the repo.  I hope you'll find it fit to upload yourself :)


Thanks Eliot,

VMConstruction-Plugins-AioPlugin-eem.18 is moved into the repository.

I may have forgotten to mention it before, but you do indeed have write
access to the AioPlugin repository.

Ah, I have to update my repository info in Monticello.  Sorry!
 

Dave




--
best,
Eliot