Re: [v8-users] internal fields

2017-11-06 Thread J Decker
On Mon, Nov 6, 2017 at 12:47 PM, Jakob Kummerow 
wrote:

> 3. What difference does it make to v8 if the internal field is an aligned
>>> pointer or not? Is the ability to set/get aligned pointers a consistency
>>> check so assumptions can be made? Does the interface check the alignment?
>>> (Not critical for me, I don't think, but I'd like to understand.)
>>>
>>
>> I doubt it matters... basically internal fields seem to be user-data
>> fields that store the value so your user code can later retrieve it.
>> Internally I wouldn't expect V8 to ever actually do anything with those
>> fields. Since they are usually pointers that are stored, aligned buffers
>> will be more optimal.
>>
>
> It actually does matter, and the interface does check for alignment. The
> reason is that V8 relies on those pointers being aligned: it uses this fact
> as part of the mechanism for deciding to ignore them.
>

Well 'aligned' is pretty generous... it only requires being 16 bit
aligned...  (2 byte)


from https://github.com/v8/v8/blob/master/src/api.cc#L1186

const int kSmiTag = 0;
const int kSmiTagSize = 1;
const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;

#define HAS_SMI_TAG(value) \
  ((reinterpret_cast(value) & ::i::kSmiTagMask) == ::i::kSmiTag)

bool Object::IsSmi() const { return HAS_SMI_TAG(this); }

Utils::ApiCheck(smi->IsSmi(), location, "Pointer is not aligned");

Which since this is ObjectWrap feature, it's passed a pointer to a class,
which I would imagine 'new' will return a 4 or 8 byte aligned pointer; but
on further research there is no guarantee.

-- 
> --
> v8-users mailing list
> v8-users@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to v8-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [v8-users] internal fields

2017-11-06 Thread Jakob Kummerow
>
> 3. What difference does it make to v8 if the internal field is an aligned
>> pointer or not? Is the ability to set/get aligned pointers a consistency
>> check so assumptions can be made? Does the interface check the alignment?
>> (Not critical for me, I don't think, but I'd like to understand.)
>>
>
> I doubt it matters... basically internal fields seem to be user-data
> fields that store the value so your user code can later retrieve it.
> Internally I wouldn't expect V8 to ever actually do anything with those
> fields. Since they are usually pointers that are stored, aligned buffers
> will be more optimal.
>

It actually does matter, and the interface does check for alignment. The
reason is that V8 relies on those pointers being aligned: it uses this fact
as part of the mechanism for deciding to ignore them.

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.