Re: [v8-users] Arraybuffer

2018-09-11 Thread Peter Schow
On Tue, Sep 11, 2018 at 2:09 PM dan Med  wrote:
>
> Would you suggest to build v8 such that I can debug it as I want ?

It's difficult to go wrong with this approach if you want to better
understand V8 or any large, complex system.

-- 
-- 
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] Arraybuffer

2018-09-11 Thread dan Med
Would you suggest to build v8 such that I can debug it as I want ?

On Tue, 11 Sep 2018 at 12:44, dan Med  wrote:

> I've already read that  guide and watched those videos, but i'm not
> interested at a HIGH level definition, i wan't to see the hole picture
> starting from the very buttom or at least at a low level
> In those presentation they just give the very top of the iceberg which
> isn't really helpful
>
> Il giorno mar 11 set 2018 alle ore 12:42 dan Med 
> ha scritto:
>
>> Ok so to answer the memory side i believe i should build v8 and then
>> debug it and see the memory.
>> But another question arises, how is data/pointers or anything else
>> represented in memory ? There should be i guide i hope ...
>>
>> Il giorno mar 11 set 2018 alle ore 12:41 dan Med 
>> ha scritto:
>>
>>> So the location of the length regarding my allocation is base on which
>>> algorithm v8 uses to find the free space it needs?
>>>
>>> Anyway, i still don't get when arraybuffer::append will be called or can
>>> be called 
>>> One more thing when i create a new instance let's say this example again:
>>> Arraybuffer foo = new arraybuffer(10)
>>>
>>> so an arraybuffer of CAPACITY will be allocated so static const int
>>> kDefaultBufferCapacity
>>> 
>>> = 32768;
>>> 32768 bytes will be allocated but only 10 of those will be marked as
>>> BYTE_USED hence i will only be able to access those with
>>> a proper typedarray.
>>>
>>> If i start reading the code on how v8 compiles i will have even more
>>> questions, i think i need the low stuff, something like how does it create
>>> the machine code that will be executed where will it be stored such and
>>> such ...
>>>
>>>
>>> Another developer replied to me that the basic structure of v8 is a loop
>>> that reacts when certain events happen..
>>>
>>> I'm really glad you're answering my questions !
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> Il giorno mar 11 set 2018 alle ore 12:32 @soylentgraham <
>>> gra...@grahamreeves.com> ha scritto:
>>>
 Let's not confuse matters by adding Node into the mix! :)

 > by doing buffer_->Data() i'm accessing a defined length space
 somewhere in memory but on the heap since there's the new operator
 involded..

 It uses the new operator, but this can, and is, overloaded. (in v8). As
 I said above, it will use the memory allocator, which you can override with
 your own (the code I provided), so, it is most likely on a heap, but it may
 not. For your purposes, it is memory allocated SOMEWHERE, by SOMETHING.


 > and where data points to the length of that space is the same as the
 one declared for example as
 > Arraybuffer a = new arraybuffer(10) so data will point to a space in
 memory who's length is 10 bytes?

 As I keep saying, this MAY NOT be the case. It depends on many things.
 As you've seen from the code, an arraybuffer has a memory-allocation of
 size CAPACITY, and the number of bytes used is BYTES_USED (in this case,
 10). The usage can grow and shrink, to save reallocation (which is
 traditionally an expensive thing)
 The most likely case, is that yes, it will probably point at some
 memory allocated by the allocator assigned to the isolate of 10 bytes. The
 only way you can verify that in your case is by debugging it, stepping into
 the code and seeing what it does.


 > So, what i'd like to understand is how v8 would compile a javascript
 "file" by that i mean how it would be
 > represented in memory which methods will be called and so on

 This is quite different from the use of array buffers!
 This question is more about compiling. How the memory is laid out after
 compilation... is going to be a very difficult thing to delve into even for
 the engine developers (they may know there's lists of functions, scripts,
 but how it's laid out EXACTLY probably isn't of concern to them)

 If you want to learn more about how the script compiles, how the
 virtual machine executes, delve into this page, and the videos at the
 bottom (while they're from 2008, the fundamentals probably haven't changed
 that much)

 http://thibaultlaurens.github.io/javascript/2013/04/29/how-the-v8-engine-works/

 If you're interested in finding out how v8 compiles, and executes code,
 I would totally ignore the memory side of things and get a grasp on what
 it's doing at a high level, (ie. the theory) then low level (what gets
 stored, how things are found, and arranged) first.
 

[v8-users] Limiting WASM memory allocation as an embedder?

2018-09-11 Thread 'Kenton Varda' via v8-users
Hi v8-users,

I noticed that WASM seems to ignore the ResourceConstraints I've set on my
isolate -- a WebAssembly.Memory object can grow to far beyond the heap
constraint I've set, and I don't see any constraint specific to WASM. The
JS code can, of course, specify a maximum memory limit when creating the
Memory object, but that's an API exposed to the script. As as embedder, I
need to enforce my own constraint.

Relatedly, it appears that GetHeapStatistics() does not include WASM memory
in the counts. As an embedder I need to keep track of the memory an isolate
has allocated.

I've searched through v8.h and haven't been able to find any alternate APIs
for these. Is there one I missed, or is this something I'll need to add
myself?

-Kenton

-- 
-- 
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] Need help with handlers in ObjectTemplate.

2018-09-11 Thread Andrei Vinogradov
Result is the same. It tries to execute NamedGetter first. Thanks for your 
advice, but I still need another solution. I can't remove 
NamedPropertyHandler in my case. I just need to make 
NamedPropertyHandler process functions correctly as well or ignore them in 
any way.

вторник, 11 сентября 2018 г., 16:39:10 UTC+3 пользователь J Decker написал:
>
> I found it esaier to work with 
> SetAccessorProperty 
>  
> https://v8docs.nodesource.com/node-0.12/db/df7/classv8_1_1_template.html#a25856e3bf1b8b0d3ee7865687a8e6d97
>
> example 
> https://github.com/d3x0r/sack.vfs/blob/master/src/gui/sack_image_module.cc#L134
> defines some get/set methods on an image class; that works with the 
> prototype template, but it's part of Template should also be availble on an 
> ObjectTemplate
>
> the setter has a default of 0 (NULL) 
>
> but like imageTemplate->PrototypeTemplate()->SetAccessorProperty( 
> String::NewFromUtf8( isolate, "jpgQuality" )
> , FunctionTemplate::New( isolate, ImageObject::getJpegQuality )
> , FunctionTemplate::New( isolate, ImageObject::setJpegQuality ), 
> DontDelete );
>
> But they just take 'regular' function definitions
>
> void ImageObject::getJpegQuality( const FunctionCallbackInfo& args 
> ) { }
>  void ImageObject::setJpegQuality( const FunctionCallbackInfo& 
> args ) {}
>
> Now, what happens if you also define a function of the same name I don't 
> know.
>
>
> On Tue, Sep 11, 2018 at 6:24 AM Andrei Vinogradov  > wrote:
>
>> Hello.
>> I'm trying to create new template that should match required behaviour 
>> but now i'm stuck with NamedPropertyHandler.
>> What I need to achieve:
>> 1. All property access calls should be processed by unified handlers 
>> (getter/setter for indexed access and getter/setter for named access). 
>> (This part is working).
>> 2. Template also should have a set of predefined functions with different 
>> handlers for each. (This part is not working).
>>
>> What I am doing. Assume that we have code like following:
>>
>> void NamedGetter(Local name, const PropertyCallbackInfo &
>> info) { ... }
>> void NamedSetter(Local name, Local value, const 
>> PropertyCallbackInfo ) { ... }
>> void IndexedGetter(uint32_t index, const PropertyCallbackInfo &
>> info) { ... }
>> void IndexedSetter(uint32_t index, Local value, const 
>> PropertyCallbackInfo ) { ... }
>> void FunctionAHandler(const FunctionCallbackInfo ) { ... }
>>
>> //Lets skip initialization code...
>>
>> Local funcName = String::NewFromUtf8(isolate, "FunctionA", v8::
>> NewStringType::kNormal).ToLocalChecked();
>>
>> Local templ = ObjectTemplate::New(isolate);
>> templ->Set(funcName, FunctionTemplate::New(isolate, FunctionAHandler, 
>> funcName));
>> templ->SetHandler(NamedPropertyHandlerConfiguration(NamedGetter, 
>> NamedSetter));
>> templ->SetHandler(IndexedPropertyHandlerConfiguration(IndexedGetter, 
>> IndexedSetter));
>>
>> //Creating instance of template in current context with name 
>> my_instance...
>>
>> Then, when i'm executing JS like "my_instance.FunctionA();" this is 
>> proccessed by V8 like i'm accessing property with name "FunctionA". I mean 
>> it's starting to execute NamedGetter function. 
>> And after that it fails with error:
>>
>> :10: Uncaught TypeError: my_instance.FunctionA is not a function
>>
>> If I'm not adding NamedPropertyHandler to template - FunctionAHandler is 
>> invoked like expected.
>> So my question is - how to avoid executing NamedGetter when function with 
>> such name is defined on template? Or maybe i't possible to proccess 
>> function calls inside NamedGetter and avoid creating handlers for each 
>> function I need in template?
>> I would appreciate any help with this.
>>
>> -- 
>> -- 
>> v8-users mailing list
>> v8-u...@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+u...@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] Need help with handlers in ObjectTemplate.

2018-09-11 Thread J Decker
I found it esaier to work with
SetAccessorProperty

https://v8docs.nodesource.com/node-0.12/db/df7/classv8_1_1_template.html#a25856e3bf1b8b0d3ee7865687a8e6d97

example
https://github.com/d3x0r/sack.vfs/blob/master/src/gui/sack_image_module.cc#L134
defines some get/set methods on an image class; that works with the
prototype template, but it's part of Template should also be availble on an
ObjectTemplate

the setter has a default of 0 (NULL)

but like imageTemplate->PrototypeTemplate()->SetAccessorProperty(
String::NewFromUtf8( isolate, "jpgQuality" )
, FunctionTemplate::New( isolate, ImageObject::getJpegQuality )
, FunctionTemplate::New( isolate, ImageObject::setJpegQuality ), DontDelete
);

But they just take 'regular' function definitions

void ImageObject::getJpegQuality( const FunctionCallbackInfo& args )
{ }
 void ImageObject::setJpegQuality( const FunctionCallbackInfo& args
) {}

Now, what happens if you also define a function of the same name I don't
know.


On Tue, Sep 11, 2018 at 6:24 AM Andrei Vinogradov 
wrote:

> Hello.
> I'm trying to create new template that should match required behaviour but
> now i'm stuck with NamedPropertyHandler.
> What I need to achieve:
> 1. All property access calls should be processed by unified handlers
> (getter/setter for indexed access and getter/setter for named access).
> (This part is working).
> 2. Template also should have a set of predefined functions with different
> handlers for each. (This part is not working).
>
> What I am doing. Assume that we have code like following:
>
> void NamedGetter(Local name, const PropertyCallbackInfo 
> ) { ... }
> void NamedSetter(Local name, Local value, const
> PropertyCallbackInfo ) { ... }
> void IndexedGetter(uint32_t index, const PropertyCallbackInfo 
> ) { ... }
> void IndexedSetter(uint32_t index, Local value, const
> PropertyCallbackInfo ) { ... }
> void FunctionAHandler(const FunctionCallbackInfo ) { ... }
>
> //Lets skip initialization code...
>
> Local funcName = String::NewFromUtf8(isolate, "FunctionA", v8::
> NewStringType::kNormal).ToLocalChecked();
>
> Local templ = ObjectTemplate::New(isolate);
> templ->Set(funcName, FunctionTemplate::New(isolate, FunctionAHandler,
> funcName));
> templ->SetHandler(NamedPropertyHandlerConfiguration(NamedGetter,
> NamedSetter));
> templ->SetHandler(IndexedPropertyHandlerConfiguration(IndexedGetter,
> IndexedSetter));
>
> //Creating instance of template in current context with name my_instance...
>
> Then, when i'm executing JS like "my_instance.FunctionA();" this is
> proccessed by V8 like i'm accessing property with name "FunctionA". I mean
> it's starting to execute NamedGetter function.
> And after that it fails with error:
>
> :10: Uncaught TypeError: my_instance.FunctionA is not a function
>
> If I'm not adding NamedPropertyHandler to template - FunctionAHandler is
> invoked like expected.
> So my question is - how to avoid executing NamedGetter when function with
> such name is defined on template? Or maybe i't possible to proccess
> function calls inside NamedGetter and avoid creating handlers for each
> function I need in template?
> I would appreciate any help with this.
>
> --
> --
> 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.


[v8-users] Need help with handlers in ObjectTemplate.

2018-09-11 Thread Andrei Vinogradov
Hello.
I'm trying to create new template that should match required behaviour but 
now i'm stuck with NamedPropertyHandler.
What I need to achieve:
1. All property access calls should be processed by unified handlers 
(getter/setter for indexed access and getter/setter for named access). 
(This part is working).
2. Template also should have a set of predefined functions with different 
handlers for each. (This part is not working).

What I am doing. Assume that we have code like following:

void NamedGetter(Local name, const PropertyCallbackInfo ) 
{ ... }
void NamedSetter(Local name, Local value, const 
PropertyCallbackInfo ) { ... }
void IndexedGetter(uint32_t index, const PropertyCallbackInfo ) 
{ ... }
void IndexedSetter(uint32_t index, Local value, const 
PropertyCallbackInfo ) { ... }
void FunctionAHandler(const FunctionCallbackInfo ) { ... }

//Lets skip initialization code...

Local funcName = String::NewFromUtf8(isolate, "FunctionA", v8::
NewStringType::kNormal).ToLocalChecked();

Local templ = ObjectTemplate::New(isolate);
templ->Set(funcName, FunctionTemplate::New(isolate, FunctionAHandler, 
funcName));
templ->SetHandler(NamedPropertyHandlerConfiguration(NamedGetter, NamedSetter
));
templ->SetHandler(IndexedPropertyHandlerConfiguration(IndexedGetter, 
IndexedSetter));

//Creating instance of template in current context with name my_instance...

Then, when i'm executing JS like "my_instance.FunctionA();" this is 
proccessed by V8 like i'm accessing property with name "FunctionA". I mean 
it's starting to execute NamedGetter function. 
And after that it fails with error:

:10: Uncaught TypeError: my_instance.FunctionA is not a function

If I'm not adding NamedPropertyHandler to template - FunctionAHandler is 
invoked like expected.
So my question is - how to avoid executing NamedGetter when function with 
such name is defined on template? Or maybe i't possible to proccess 
function calls inside NamedGetter and avoid creating handlers for each 
function I need in template?
I would appreciate any help with this.

-- 
-- 
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] Arraybuffer

2018-09-11 Thread dan Med
I've already read that  guide and watched those videos, but i'm not
interested at a HIGH level definition, i wan't to see the hole picture
starting from the very buttom or at least at a low level
In those presentation they just give the very top of the iceberg which
isn't really helpful

Il giorno mar 11 set 2018 alle ore 12:42 dan Med 
ha scritto:

> Ok so to answer the memory side i believe i should build v8 and then debug
> it and see the memory.
> But another question arises, how is data/pointers or anything else
> represented in memory ? There should be i guide i hope ...
>
> Il giorno mar 11 set 2018 alle ore 12:41 dan Med 
> ha scritto:
>
>> So the location of the length regarding my allocation is base on which
>> algorithm v8 uses to find the free space it needs?
>>
>> Anyway, i still don't get when arraybuffer::append will be called or can
>> be called 
>> One more thing when i create a new instance let's say this example again:
>> Arraybuffer foo = new arraybuffer(10)
>>
>> so an arraybuffer of CAPACITY will be allocated so static const int
>> kDefaultBufferCapacity
>> 
>> = 32768;
>> 32768 bytes will be allocated but only 10 of those will be marked as
>> BYTE_USED hence i will only be able to access those with
>> a proper typedarray.
>>
>> If i start reading the code on how v8 compiles i will have even more
>> questions, i think i need the low stuff, something like how does it create
>> the machine code that will be executed where will it be stored such and
>> such ...
>>
>>
>> Another developer replied to me that the basic structure of v8 is a loop
>> that reacts when certain events happen..
>>
>> I'm really glad you're answering my questions !
>>
>>
>>
>>
>>
>>
>>
>> Il giorno mar 11 set 2018 alle ore 12:32 @soylentgraham <
>> gra...@grahamreeves.com> ha scritto:
>>
>>> Let's not confuse matters by adding Node into the mix! :)
>>>
>>> > by doing buffer_->Data() i'm accessing a defined length space
>>> somewhere in memory but on the heap since there's the new operator
>>> involded..
>>>
>>> It uses the new operator, but this can, and is, overloaded. (in v8). As
>>> I said above, it will use the memory allocator, which you can override with
>>> your own (the code I provided), so, it is most likely on a heap, but it may
>>> not. For your purposes, it is memory allocated SOMEWHERE, by SOMETHING.
>>>
>>>
>>> > and where data points to the length of that space is the same as the
>>> one declared for example as
>>> > Arraybuffer a = new arraybuffer(10) so data will point to a space in
>>> memory who's length is 10 bytes?
>>>
>>> As I keep saying, this MAY NOT be the case. It depends on many things.
>>> As you've seen from the code, an arraybuffer has a memory-allocation of
>>> size CAPACITY, and the number of bytes used is BYTES_USED (in this case,
>>> 10). The usage can grow and shrink, to save reallocation (which is
>>> traditionally an expensive thing)
>>> The most likely case, is that yes, it will probably point at some memory
>>> allocated by the allocator assigned to the isolate of 10 bytes. The only
>>> way you can verify that in your case is by debugging it, stepping into the
>>> code and seeing what it does.
>>>
>>>
>>> > So, what i'd like to understand is how v8 would compile a javascript
>>> "file" by that i mean how it would be
>>> > represented in memory which methods will be called and so on
>>>
>>> This is quite different from the use of array buffers!
>>> This question is more about compiling. How the memory is laid out after
>>> compilation... is going to be a very difficult thing to delve into even for
>>> the engine developers (they may know there's lists of functions, scripts,
>>> but how it's laid out EXACTLY probably isn't of concern to them)
>>>
>>> If you want to learn more about how the script compiles, how the virtual
>>> machine executes, delve into this page, and the videos at the bottom (while
>>> they're from 2008, the fundamentals probably haven't changed that much)
>>>
>>> http://thibaultlaurens.github.io/javascript/2013/04/29/how-the-v8-engine-works/
>>>
>>> If you're interested in finding out how v8 compiles, and executes code,
>>> I would totally ignore the memory side of things and get a grasp on what
>>> it's doing at a high level, (ie. the theory) then low level (what gets
>>> stored, how things are found, and arranged) first.
>>> THEN you could browse the allocations and see WHERE everything is (I'm
>>> not sure what use this would be to anyone who is working with more than
>>> 50mb of ram though :)
>>>
>>> I would really encourage you to step through the 

Re: [v8-users] Arraybuffer

2018-09-11 Thread dan Med
Ok so to answer the memory side i believe i should build v8 and then debug
it and see the memory.
But another question arises, how is data/pointers or anything else
represented in memory ? There should be i guide i hope ...

Il giorno mar 11 set 2018 alle ore 12:41 dan Med 
ha scritto:

> So the location of the length regarding my allocation is base on which
> algorithm v8 uses to find the free space it needs?
>
> Anyway, i still don't get when arraybuffer::append will be called or can
> be called 
> One more thing when i create a new instance let's say this example again:
> Arraybuffer foo = new arraybuffer(10)
>
> so an arraybuffer of CAPACITY will be allocated so static const int
> kDefaultBufferCapacity
> 
> = 32768;
> 32768 bytes will be allocated but only 10 of those will be marked as
> BYTE_USED hence i will only be able to access those with
> a proper typedarray.
>
> If i start reading the code on how v8 compiles i will have even more
> questions, i think i need the low stuff, something like how does it create
> the machine code that will be executed where will it be stored such and
> such ...
>
>
> Another developer replied to me that the basic structure of v8 is a loop
> that reacts when certain events happen..
>
> I'm really glad you're answering my questions !
>
>
>
>
>
>
>
> Il giorno mar 11 set 2018 alle ore 12:32 @soylentgraham <
> gra...@grahamreeves.com> ha scritto:
>
>> Let's not confuse matters by adding Node into the mix! :)
>>
>> > by doing buffer_->Data() i'm accessing a defined length space somewhere
>> in memory but on the heap since there's the new operator involded..
>>
>> It uses the new operator, but this can, and is, overloaded. (in v8). As I
>> said above, it will use the memory allocator, which you can override with
>> your own (the code I provided), so, it is most likely on a heap, but it may
>> not. For your purposes, it is memory allocated SOMEWHERE, by SOMETHING.
>>
>>
>> > and where data points to the length of that space is the same as the
>> one declared for example as
>> > Arraybuffer a = new arraybuffer(10) so data will point to a space in
>> memory who's length is 10 bytes?
>>
>> As I keep saying, this MAY NOT be the case. It depends on many things. As
>> you've seen from the code, an arraybuffer has a memory-allocation of size
>> CAPACITY, and the number of bytes used is BYTES_USED (in this case, 10).
>> The usage can grow and shrink, to save reallocation (which is traditionally
>> an expensive thing)
>> The most likely case, is that yes, it will probably point at some memory
>> allocated by the allocator assigned to the isolate of 10 bytes. The only
>> way you can verify that in your case is by debugging it, stepping into the
>> code and seeing what it does.
>>
>>
>> > So, what i'd like to understand is how v8 would compile a javascript
>> "file" by that i mean how it would be
>> > represented in memory which methods will be called and so on
>>
>> This is quite different from the use of array buffers!
>> This question is more about compiling. How the memory is laid out after
>> compilation... is going to be a very difficult thing to delve into even for
>> the engine developers (they may know there's lists of functions, scripts,
>> but how it's laid out EXACTLY probably isn't of concern to them)
>>
>> If you want to learn more about how the script compiles, how the virtual
>> machine executes, delve into this page, and the videos at the bottom (while
>> they're from 2008, the fundamentals probably haven't changed that much)
>>
>> http://thibaultlaurens.github.io/javascript/2013/04/29/how-the-v8-engine-works/
>>
>> If you're interested in finding out how v8 compiles, and executes code, I
>> would totally ignore the memory side of things and get a grasp on what it's
>> doing at a high level, (ie. the theory) then low level (what gets stored,
>> how things are found, and arranged) first.
>> THEN you could browse the allocations and see WHERE everything is (I'm
>> not sure what use this would be to anyone who is working with more than
>> 50mb of ram though :)
>>
>> I would really encourage you to step through the code though! (find
>> script::compile and just step through from there)
>> This will make lots of things make sense! (because everything is named
>> properly in the code :)
>>
>>
>> On Tuesday, 11 September 2018 08:57:53 UTC+1, J Decker wrote:
>>>
>>>
>>>
>>> On Tue, Sep 11, 2018 at 12:44 AM dan Med  wrote:
>>>
 First of all, i'd like to say that for me the documentation is
 really. useless from a real technical point of view.
 So, what i'd 

Re: [v8-users] Arraybuffer

2018-09-11 Thread dan Med
So the location of the length regarding my allocation is base on which
algorithm v8 uses to find the free space it needs?

Anyway, i still don't get when arraybuffer::append will be called or can be
called 
One more thing when i create a new instance let's say this example again:
Arraybuffer foo = new arraybuffer(10)

so an arraybuffer of CAPACITY will be allocated so static const int
kDefaultBufferCapacity

= 32768;
32768 bytes will be allocated but only 10 of those will be marked as
BYTE_USED hence i will only be able to access those with
a proper typedarray.

If i start reading the code on how v8 compiles i will have even more
questions, i think i need the low stuff, something like how does it create
the machine code that will be executed where will it be stored such and
such ...


Another developer replied to me that the basic structure of v8 is a loop
that reacts when certain events happen..

I'm really glad you're answering my questions !







Il giorno mar 11 set 2018 alle ore 12:32 @soylentgraham <
gra...@grahamreeves.com> ha scritto:

> Let's not confuse matters by adding Node into the mix! :)
>
> > by doing buffer_->Data() i'm accessing a defined length space somewhere
> in memory but on the heap since there's the new operator involded..
>
> It uses the new operator, but this can, and is, overloaded. (in v8). As I
> said above, it will use the memory allocator, which you can override with
> your own (the code I provided), so, it is most likely on a heap, but it may
> not. For your purposes, it is memory allocated SOMEWHERE, by SOMETHING.
>
>
> > and where data points to the length of that space is the same as the one
> declared for example as
> > Arraybuffer a = new arraybuffer(10) so data will point to a space in
> memory who's length is 10 bytes?
>
> As I keep saying, this MAY NOT be the case. It depends on many things. As
> you've seen from the code, an arraybuffer has a memory-allocation of size
> CAPACITY, and the number of bytes used is BYTES_USED (in this case, 10).
> The usage can grow and shrink, to save reallocation (which is traditionally
> an expensive thing)
> The most likely case, is that yes, it will probably point at some memory
> allocated by the allocator assigned to the isolate of 10 bytes. The only
> way you can verify that in your case is by debugging it, stepping into the
> code and seeing what it does.
>
>
> > So, what i'd like to understand is how v8 would compile a javascript
> "file" by that i mean how it would be
> > represented in memory which methods will be called and so on
>
> This is quite different from the use of array buffers!
> This question is more about compiling. How the memory is laid out after
> compilation... is going to be a very difficult thing to delve into even for
> the engine developers (they may know there's lists of functions, scripts,
> but how it's laid out EXACTLY probably isn't of concern to them)
>
> If you want to learn more about how the script compiles, how the virtual
> machine executes, delve into this page, and the videos at the bottom (while
> they're from 2008, the fundamentals probably haven't changed that much)
>
> http://thibaultlaurens.github.io/javascript/2013/04/29/how-the-v8-engine-works/
>
> If you're interested in finding out how v8 compiles, and executes code, I
> would totally ignore the memory side of things and get a grasp on what it's
> doing at a high level, (ie. the theory) then low level (what gets stored,
> how things are found, and arranged) first.
> THEN you could browse the allocations and see WHERE everything is (I'm not
> sure what use this would be to anyone who is working with more than 50mb of
> ram though :)
>
> I would really encourage you to step through the code though! (find
> script::compile and just step through from there)
> This will make lots of things make sense! (because everything is named
> properly in the code :)
>
>
> On Tuesday, 11 September 2018 08:57:53 UTC+1, J Decker wrote:
>>
>>
>>
>> On Tue, Sep 11, 2018 at 12:44 AM dan Med  wrote:
>>
>>> First of all, i'd like to say that for me the documentation is
>>> really. useless from a real technical point of view.
>>> So, what i'd like to understand is how v8 would compile a javascript
>>> "file" by that i mean how it would be
>>> represented in memory which methods will be called and so on
>>> (In the classes defined in the various v8 files, you don't get that sort
>>> of feeling about the memory allocator and such...
>>> i'd like to understand how to gather that knowledge.)
>>> Now, u said "kind of" for my question which was, when i 

Re: [v8-users] Arraybuffer

2018-09-11 Thread J Decker
On Tue, Sep 11, 2018 at 12:44 AM dan Med  wrote:

> First of all, i'd like to say that for me the documentation is really.
> useless from a real technical point of view.
> So, what i'd like to understand is how v8 would compile a javascript
> "file" by that i mean how it would be
> represented in memory which methods will be called and so on
> (In the classes defined in the various v8 files, you don't get that sort
> of feeling about the memory allocator and such...
> i'd like to understand how to gather that knowledge.)
> Now, u said "kind of" for my question which was, when i allocate an
> arraybuffer in javascript will v8 call arraybufferbuilder ?
> But then one of my questions was how to invoke the append method?
> I know that if someone want's to expand an arraybuffer it will have to
> create another one and copy there those values...
> This is how i have a rough vision of the arraybuffer in memory:
>
> buffer > [   DATA ]
> "simple pointer" "size of the bytes which i can manipulate with a
> typedarray"
>

There's really nothing special about the memory gets the size of a
file, allocates a buffer and reads the file into it.
https://github.com/d3x0r/sack.vfs/blob/master/src/vfs_module.cc#L479

size_t len = sack_vfs_size( file );
uint8_t *buf = NewArray( uint8_t, len );
sack_vfs_read( file, (char*)buf, len );
Local arrayBuffer = ArrayBuffer::New( isolate, buf, len );

where buf is allocated from some allocator V8 doesn't even know about
the next few lines of code wrap it in a weak persistent holder that tracks
when the object gets deleted to be able to delete the 'buf' allocated...
https://github.com/d3x0r/sack.vfs/blob/master/src/vfs_module.cc#L447
(releaseBuffer)

You can find information about ArrayBuffer by searching for 'nodejs addon
arraybuffer'   Node is a handy platform for writing code that extends V8;
99% of the code you will write is actually interfacing to V8 and not Node.


> Il giorno mar 11 set 2018 alle ore 00:07 @soylentgraham <
> gra...@grahamreeves.com> ha scritto:
>
>> > When I talk about typedarray or anything else I referr to the
>> JavaScript side, so create an arraybuffer it will invoke that class in v8,
>> Kind of.
>>
>> > then build a view or not it depends how do I make v8 to call the append
>> method ?
>> I don't understand this question.
>> An array buffer in javascript is fixed in length. You cannot make it grow
>> or shrink on the javascript side.
>> To do anything, you need a view, so the code knows how to manipulate the
>> raw bytes in the array buffer.
>> See javascript documentation on array buffers;
>> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
>>
>> You personally shouldn't TRY to make it call the append method. If it
>> needs to grow, it'll grow. Why do you think you need to? Back to previous
>> messages, what are you trying to achieve??
>>
>> Gather your thoughts, and try and answer some of the questions I've asked
>> in previous emails; I asked them to help guide you so people can help with
>> your problem! (I'm still not exactly sure what you're trying to do)
>>
>>
>> On Monday, 10 September 2018 22:55:51 UTC+1, dan Med wrote:
>>>
>>> ATM I’m writing with my phone, here in EU is almost midnight so I will
>>> write u an email tomorrow fully detailed.
>>>
>>> Btw how do I call append ???
>>> I’m interested in how v8 works and manages JavaScript code that’s all.
>>>
>>> When I talk about typedarray or anything else I referr to the JavaScript
>>> side, so create an arraybuffer it will invoke that class in v8, then build
>>> a view or not it depends how do I make v8 to call the append method ?
>>>
>>> On Mon, 10 Sep 2018 at 23:46, @soylentgraham 
>>> wrote:
>>>
 > First, how big is the data member of the object ?

 As I said before. Capacity is the size of the memory allocated that
 data points at.


 > Is it as big as the actual array buffer length which I declare on
 JavaScript

 It will be either as big, or bigger. It can grow.
 bytes_used will be the size that matches javascript.


 > which I can build on top of it a typedarray ?

 This is a slightly different question, (and needs clarifying)
 When you create a typedarray in C++, it needs an array buffer.
 When you create a typedarray in javascript, it will have an array
 buffer behind it. (which you may or may not have created in javascript or
 c++, there are several ways of approaching this)


 > So, when a typedarray is build on top of an areaybuffer instance, how
 do I get to call the arraybufferbuilder::append ?

 Aha! a more specific question!
 Are you trying to call arraybufferbuilder::append in javascript, or c++?
 Why? are you trying to make a typedarray bigger? (in javascript or c++?)
 I believe once created they're a fixed size in javascript.
 I have a feeling on the c++ side, 

Re: [v8-users] Arraybuffer

2018-09-11 Thread dan Med
by doing buffer_->Data() i'm accessing a defined length space somewhere in
memory but on the heap since there's the new operator involded..
and where data points to the length of that space is the same as the one
declared for example as
Arraybuffer a = new arraybuffer(10) so data will point to a space in memory
who's length is 10 bytes?

Il giorno mar 11 set 2018 alle ore 09:43 dan Med 
ha scritto:

> First of all, i'd like to say that for me the documentation is really.
> useless from a real technical point of view.
> So, what i'd like to understand is how v8 would compile a javascript
> "file" by that i mean how it would be
> represented in memory which methods will be called and so on
> (In the classes defined in the various v8 files, you don't get that sort
> of feeling about the memory allocator and such...
> i'd like to understand how to gather that knowledge.)
> Now, u said "kind of" for my question which was, when i allocate an
> arraybuffer in javascript will v8 call arraybufferbuilder ?
> But then one of my questions was how to invoke the append method?
> I know that if someone want's to expand an arraybuffer it will have to
> create another one and copy there those values...
> This is how i have a rough vision of the arraybuffer in memory:
>
> buffer > [   DATA ]
> "simple pointer" "size of the bytes which i can manipulate with a
> typedarray"
>
> Il giorno mar 11 set 2018 alle ore 00:07 @soylentgraham <
> gra...@grahamreeves.com> ha scritto:
>
>> > When I talk about typedarray or anything else I referr to the
>> JavaScript side, so create an arraybuffer it will invoke that class in v8,
>> Kind of.
>>
>> > then build a view or not it depends how do I make v8 to call the append
>> method ?
>> I don't understand this question.
>> An array buffer in javascript is fixed in length. You cannot make it grow
>> or shrink on the javascript side.
>> To do anything, you need a view, so the code knows how to manipulate the
>> raw bytes in the array buffer.
>> See javascript documentation on array buffers;
>> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
>>
>> You personally shouldn't TRY to make it call the append method. If it
>> needs to grow, it'll grow. Why do you think you need to? Back to previous
>> messages, what are you trying to achieve??
>>
>> Gather your thoughts, and try and answer some of the questions I've asked
>> in previous emails; I asked them to help guide you so people can help with
>> your problem! (I'm still not exactly sure what you're trying to do)
>>
>>
>> On Monday, 10 September 2018 22:55:51 UTC+1, dan Med wrote:
>>>
>>> ATM I’m writing with my phone, here in EU is almost midnight so I will
>>> write u an email tomorrow fully detailed.
>>>
>>> Btw how do I call append ???
>>> I’m interested in how v8 works and manages JavaScript code that’s all.
>>>
>>> When I talk about typedarray or anything else I referr to the JavaScript
>>> side, so create an arraybuffer it will invoke that class in v8, then build
>>> a view or not it depends how do I make v8 to call the append method ?
>>>
>>> On Mon, 10 Sep 2018 at 23:46, @soylentgraham 
>>> wrote:
>>>
 > First, how big is the data member of the object ?

 As I said before. Capacity is the size of the memory allocated that
 data points at.


 > Is it as big as the actual array buffer length which I declare on
 JavaScript

 It will be either as big, or bigger. It can grow.
 bytes_used will be the size that matches javascript.


 > which I can build on top of it a typedarray ?

 This is a slightly different question, (and needs clarifying)
 When you create a typedarray in C++, it needs an array buffer.
 When you create a typedarray in javascript, it will have an array
 buffer behind it. (which you may or may not have created in javascript or
 c++, there are several ways of approaching this)


 > So, when a typedarray is build on top of an areaybuffer instance, how
 do I get to call the arraybufferbuilder::append ?

 Aha! a more specific question!
 Are you trying to call arraybufferbuilder::append in javascript, or c++?
 Why? are you trying to make a typedarray bigger? (in javascript or c++?)
 I believe once created they're a fixed size in javascript.
 I have a feeling on the c++ side, you can't change the size once
 created (but I may be wrong, you have direct access to the buffer's
 buffercontents via the bufferview...)

 Can you make your question a lot more specific? post some code?


 On Monday, 10 September 2018 22:38:16 UTC+1, dan Med wrote:
>
> First, how big is the data member of the object ? Is it as big as the
> actual array buffer length which I declare on JavaScript and which I can
> build on top of it a typedarray ?
>
> No, I’m just trying to understand how v8 

Re: [v8-users] Arraybuffer

2018-09-11 Thread dan Med
First of all, i'd like to say that for me the documentation is really.
useless from a real technical point of view.
So, what i'd like to understand is how v8 would compile a javascript "file"
by that i mean how it would be
represented in memory which methods will be called and so on
(In the classes defined in the various v8 files, you don't get that sort of
feeling about the memory allocator and such...
i'd like to understand how to gather that knowledge.)
Now, u said "kind of" for my question which was, when i allocate an
arraybuffer in javascript will v8 call arraybufferbuilder ?
But then one of my questions was how to invoke the append method?
I know that if someone want's to expand an arraybuffer it will have to
create another one and copy there those values...
This is how i have a rough vision of the arraybuffer in memory:

buffer > [   DATA ]
"simple pointer" "size of the bytes which i can manipulate with a
typedarray"

Il giorno mar 11 set 2018 alle ore 00:07 @soylentgraham <
gra...@grahamreeves.com> ha scritto:

> > When I talk about typedarray or anything else I referr to the JavaScript
> side, so create an arraybuffer it will invoke that class in v8,
> Kind of.
>
> > then build a view or not it depends how do I make v8 to call the append
> method ?
> I don't understand this question.
> An array buffer in javascript is fixed in length. You cannot make it grow
> or shrink on the javascript side.
> To do anything, you need a view, so the code knows how to manipulate the
> raw bytes in the array buffer.
> See javascript documentation on array buffers;
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
>
> You personally shouldn't TRY to make it call the append method. If it
> needs to grow, it'll grow. Why do you think you need to? Back to previous
> messages, what are you trying to achieve??
>
> Gather your thoughts, and try and answer some of the questions I've asked
> in previous emails; I asked them to help guide you so people can help with
> your problem! (I'm still not exactly sure what you're trying to do)
>
>
> On Monday, 10 September 2018 22:55:51 UTC+1, dan Med wrote:
>>
>> ATM I’m writing with my phone, here in EU is almost midnight so I will
>> write u an email tomorrow fully detailed.
>>
>> Btw how do I call append ???
>> I’m interested in how v8 works and manages JavaScript code that’s all.
>>
>> When I talk about typedarray or anything else I referr to the JavaScript
>> side, so create an arraybuffer it will invoke that class in v8, then build
>> a view or not it depends how do I make v8 to call the append method ?
>>
>> On Mon, 10 Sep 2018 at 23:46, @soylentgraham 
>> wrote:
>>
>>> > First, how big is the data member of the object ?
>>>
>>> As I said before. Capacity is the size of the memory allocated that data
>>> points at.
>>>
>>>
>>> > Is it as big as the actual array buffer length which I declare on
>>> JavaScript
>>>
>>> It will be either as big, or bigger. It can grow.
>>> bytes_used will be the size that matches javascript.
>>>
>>>
>>> > which I can build on top of it a typedarray ?
>>>
>>> This is a slightly different question, (and needs clarifying)
>>> When you create a typedarray in C++, it needs an array buffer.
>>> When you create a typedarray in javascript, it will have an array buffer
>>> behind it. (which you may or may not have created in javascript or c++,
>>> there are several ways of approaching this)
>>>
>>>
>>> > So, when a typedarray is build on top of an areaybuffer instance, how
>>> do I get to call the arraybufferbuilder::append ?
>>>
>>> Aha! a more specific question!
>>> Are you trying to call arraybufferbuilder::append in javascript, or c++?
>>> Why? are you trying to make a typedarray bigger? (in javascript or c++?)
>>> I believe once created they're a fixed size in javascript.
>>> I have a feeling on the c++ side, you can't change the size once created
>>> (but I may be wrong, you have direct access to the buffer's buffercontents
>>> via the bufferview...)
>>>
>>> Can you make your question a lot more specific? post some code?
>>>
>>>
>>> On Monday, 10 September 2018 22:38:16 UTC+1, dan Med wrote:

 First, how big is the data member of the object ? Is it as big as the
 actual array buffer length which I declare on JavaScript and which I can
 build on top of it a typedarray ?

 No, I’m just trying to understand how v8 works, I know it is a big
 thing but at least how it moves then I might read the code and understand,
 extra parts.

 So, when a typedarray is build on top of an areaybuffer instance, how
 do I get to call the arraybufferbuilder::append ?





 On Mon, 10 Sep 2018 at 23:30, @soylentgraham 
 wrote:

> I'm guessing you may be a bit new to unmanaged-memory
> languages/systems.
>
> buffer is an object, (it's structure/layout will look a bit like it's
>