Arraybuffer

179 views
Skip to first unread message

litoki...@gmail.com

unread,
Sep 1, 2018, 9:30:37 AM9/1/18
to v8-users
array_buffer_builder.cc in src/third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_builder.cc 
the ArrayBufferBuilder::Append method will be called through a view on top of the arraybuffer? something like, there's a arraybuffer of 30bytes in length and we define a view on top of it (so a typedarray) wehn i call on the new typedarray object the .append method it will call ArrayBufferBuilder::Append  and then inside it's code it will execute ArrayBufferBuilder::ExpandCapacity if it needs to reallocate the array ?

if so inside the expandCapacity definition bytes_used referes to the elements inside the actual arraybuffer so if i have a arraybuffer which is 8 bytes in length [ ][ ][ ][ ][ ][ ][ ][ ] and i fill in only 3 bytes so 
[1][2][3][ ][ ][ ][ ][ ] the bytes_used when retrieved will be set to 3 bytes ??

ArrayBufferBuilder::ArrayBufferBuilder()
    : bytes_used_(0), variable_capacity_(true) {
  buffer_ = ArrayBuffer::Create(kDefaultBufferCapacity, 1);
}
here buffer_ will be equal to an arraybuffer of 32768 bytes in length ? since the KdefaultBuffer... is set to that value.
is std::numeric_limits<unsigned>::max(); referring to the max unsigned int value ? cause the source code won't find it

dan Med

unread,
Sep 3, 2018, 2:55:48 PM9/3/18
to v8-u...@googlegroups.com
Can someone help me out?

--
--
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.

Graham Reeves

unread,
Sep 4, 2018, 6:14:33 AM9/4/18
to v8-users
is std::numeric_limits<unsigned>::max(); referring to the max unsigned int value ? cause the source code won't find it
Yes, that's the maximum value unsigned (an unsigned int) can be, but what do you mean by, the source won't find it?

dan Med

unread,
Sep 9, 2018, 11:51:33 AM9/9/18
to v8-u...@googlegroups.com
I don't have understood this part, let me explain it to you.
This is how i get it tell me if i'm wrong at any part.

I need to understand how is the structure in memory of the arraybuffer how is it represented and if the data of the array are directly stored at an offset accessed by buffer_ -> data().


before the call to expand capacity it does create an array 


the arraybuffer in src/third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_builder.cc is called whenever the renderer  (has to execute some javascript which defines arraybuffers)
First when is arraybuffer::append  called, cause i know that if someone need to reallocate a bigger arraybuffer then a new instance will be created and filled with the old values if the length in the original array isn't has much as the user reqeusted ?

One more thing is, when this class is called, the arraybuffer is always set to the initial length of static const int kDefaultBufferCapacity = 32768; if in the javascript i declare an arraybuffer of 20bytes will it allocate of
32768bytes anyway =?






dan Med

unread,
Sep 9, 2018, 11:54:52 AM9/9/18
to v8-u...@googlegroups.com
Oh and one more thing, i've surfed perhaps the entire source code of v8 at least the interesting parts, but what i came across was just very short code execpt for some builtins written in javascript i believe, can't find all of the things i've found on the documentation such as the interpreter and the JIT compilers, one more thing i'd like to understand how the memory is handeled like how can i read about the JIT pages, or which memory allocator does v8 use and it's garbage collector

Thank you !

Jakob Kummerow

unread,
Sep 10, 2018, 2:45:47 PM9/10/18
to v8-users
On Sun, Sep 9, 2018 at 8:54 AM dan Med <litoki...@gmail.com> wrote:
Oh and one more thing, i've surfed perhaps the entire source code of v8 at least the interesting parts, but what i came across was just very short code execpt for some builtins written in javascript i believe, can't find all of the things i've found on the documentation such as the interpreter

src/interpreter/
 
and the JIT compilers,

src/compiler/
 
one more thing i'd like to understand how the memory is handeled like how can i read about the JIT pages,

What's a JIT page?
 
or which memory allocator does v8 use

It uses several allocation techniques for different purposes.
 
and it's garbage collector

src/heap/

dan Med

unread,
Sep 10, 2018, 3:22:17 PM9/10/18
to v8-u...@googlegroups.com
I don't quite see if this google group is useful or not, everybody keeps answering me with superficial things, i don't care about the trminology like tell me which allocator it uses when and why or at least if there's something i can read to understand.....
I'm surprised u don't know what a JIT page is, basically if you call a function foo() let's say 100 times then v8,had enough time to understand the parameters given to that specific function and how to optimize it efficently based on it's prediction/observation.

I'm not interested in the terminology of things, (that's just a matter of reading the source code ) i'm more in reading how it works when and why..


For example when is ArrayBufferBuilder::Append called ?? 

And i thing i've looked at the entire v8 source code but didn't find much, apart from the array.js file which describes some javascript function, i don't understand where's the rest.... 


dan Med

unread,
Sep 10, 2018, 3:22:46 PM9/10/18
to v8-u...@googlegroups.com
You call foo() 100 times

Jakob Kummerow

unread,
Sep 10, 2018, 3:53:42 PM9/10/18
to v8-users
On Mon, Sep 10, 2018 at 12:22 PM dan Med <litoki...@gmail.com> wrote:
I don't quite see if this google group is useful or not, everybody keeps answering me with superficial things,

You said you wanted to read the compiler's source but couldn't find it, so I told you that it's in src/compiler/. If that was not the answer you wanted, then try asking a different question?

Please also keep in mind that people's time is limited. The easier/quicker it is to answer your question, the more likely you are to get an answer. 

i don't care about the trminology like tell me which allocator it uses when and why or at least if there's something i can read to understand.....
I'm surprised u don't know what a JIT page is, basically if you call a function foo() let's say 100 times then v8,had enough time to understand the parameters given to that specific function and how to optimize it efficently based on it's prediction/observation.

I'm not interested in the terminology of things, (that's just a matter of reading the source code ) i'm more in reading how it works when and why..

It's great that you want to understand how things work. Terminology is an important aspect of that though, because it enables communication. If we use different words for the same thing, we won't understand each other.
Based on your explanation, I'm guessing that by "JIT page" you mean "the strategy V8 uses to select functions for optimization". The core of that logic is in MarkCandidatesForOptimization in src/runtime-profiler.cc.
 
For example when is ArrayBufferBuilder::Append called ?? 

I don't know; it's not part of V8. But you can use Code Search to find out where anything is called, just click the function in question to get a list of call sites: https://cs.chromium.org/chromium/src/third_party/blink/renderer/platform/wtf/typed_arrays/array_buffer_builder.h?q=ArrayBufferBuilder&sq=package:chromium&g=0&l=61

dan Med

unread,
Sep 10, 2018, 4:19:32 PM9/10/18
to v8-u...@googlegroups.com
i already did that and btw it is under the WTF/webkit .
I'm interested how v8 handles javascript into every detail if u can guide me...
Tell me which repository are being used by v8 on the related topic that would help me really much.

By when it is called i mean, which javascript code will enable me to call that funciton cause if u click u can't go any further than that,

dan Med

unread,
Sep 10, 2018, 4:25:37 PM9/10/18
to v8-u...@googlegroups.com
in this snippet for example
namespace WTF {

// A utility class to build an ArrayBuffer instance. Validity must be checked
// by isValid() before using an instance.
class WTF_EXPORT ArrayBufferBuilder final {
  // Disallow copying since it's expensive and we don't want code to do it by
  // accident.
  USING_FAST_MALLOC(ArrayBufferBuilder);

 public:
  // Creates an ArrayBufferBuilder using the default capacity.
  ArrayBufferBuilder();

  ArrayBufferBuilder(unsigned capacity)
      : bytes_used_(0), variable_capacity_(true) {
    buffer_ = ArrayBuffer::Create(capacity, 1);
  }

  bool IsValid() const { return buffer_.get(); }

  // Appending empty data is not allowed.
  unsigned Append(const char* data, unsigned length);

  // Returns the accumulated data as an ArrayBuffer instance. If needed,
  // creates a new ArrayBuffer instance and copies contents from the internal
  // buffer to it. Otherwise, returns a RefPtr pointing to the internal
  // buffer.
  scoped_refptr<ArrayBuffer> ToArrayBuffer();

  // Converts the accumulated data into a String using the default encoding.
  String ToString();

  // Number of bytes currently accumulated.
  unsigned ByteLength() const { return bytes_used_; }

  // Number of bytes allocated.
  unsigned Capacity() const { return buffer_->ByteLength(); }

  void ShrinkToFit();

  const void* Data() const { return buffer_->Data(); }

  // If set to false, the capacity won't be expanded and when appended data
  // overflows, the overflowed part will be dropped.
  void SetVariableCapacity(bool value) { variable_capacity_ = value; }

 private:
  // Expands the size of m_buffer to size + m_bytesUsed bytes. Returns true
  // iff successful. If reallocation is needed, copies only data in
  // [0, m_bytesUsed) range.
  bool ExpandCapacity(unsigned size);

  unsigned bytes_used_;
  bool variable_capacity_;
  scoped_refptr<ArrayBuffer> buffer_;

  DISALLOW_COPY_AND_ASSIGN(ArrayBufferBuilder);
};

}  // namespace WTF



How can i understand the structure in memory of an arraybuffer and how big is the data field which is pointed by this void pointerHow are they represented in memory....How big is the data field ?

@soylentgraham

unread,
Sep 10, 2018, 4:55:48 PM9/10/18
to v8-users
> How can i understand the structure in memory of an arraybuffer and how big is the data field which is pointed by this void pointerIt has no structure. It is just a series of linear bytes, raw memory, allocated by the memory allocator. (If you implement your own memory allocator you can catch when this happens)It's just the data(buffer) for an array.
> How are they represented in memory....It IS memory. It's nothing more (it's an array of bytes)
> How big is the data field ?If by "field", you mean, the data buffer... it's Capacity (capacity is how much it can fit) in length. But not how much is being used. (bytes_used)
If you're curious about when memory grows, reallocates, is written to, accessed... it might be worth setting up your environment so you can debug it by stepping through the code as it executes. You can watch memory, (this would show what memcpy changes) see the values passed around, track when memory gets allocated etc.
Your questions are a mix of very broad, ("How does v8 work") and very specific programming questions (what is memcpy() doing)Broad questions are very hard to answer in general. ("How does a car work")

I agree, simply browsing the code doesn't give a good overview of say, how the javascript compiler works, or how memory is utilised. (How it is allocated is very simple, on the C/++ side it doesn't implement any memory management, and the array buffer/view is a view of the C-side memory)But after using it for a little while, I have found v8 in general is pretty simple. It provides an interface to C functions and memory. This is kinda what it's for.
But the point of v8 is that it does a lot of that for you. I don't REALLY need to know how the memory is tracked on the javascript side, it just works (if I'm using the API correctly)Then again, if you NEED to know how it works for a specific purpose (very restricted memory, fixing a bug), we can help you a lot more easily by answering a very specific question. ("My car's low-oil light is blinking, where do I fill it up")
If you're just curious as to how the entire v8 engine works... that's a massive ask. A lot of people work on it, and there is a lot of work and topics involved.Your best bet is reading the (limited) documentation on the wiki, and read the blog posts https://v8project.blogspot.com/ which go into quite a lot of detail on each post topic.I've not seen any real general overview (the wiki itself says it's out of date) so, stepping through all the code as it executes is probably your best bet.

dan Med

unread,
Sep 10, 2018, 5:06:33 PM9/10/18
to v8-u...@googlegroups.com
So, the hole length of this raw memory is set to be Data ? And to use it i should create a view on top of it like with typedarrays?


So to call arraybuffer::append i should first, try to make the typed array bigger that action will call the arraybuffer::append  ?  i didn't ask how memcpy work, i didn't get the Data() thing, in the class that's all.

dan Med

unread,
Sep 10, 2018, 5:06:56 PM9/10/18
to v8-u...@googlegroups.com
But after using it for a little while, I have found v8 in general is pretty simple. It provides an interface to C functions and memory. This is kinda what it's for.  

so how can i see the memory management ? 
 

dan Med

unread,
Sep 10, 2018, 5:07:33 PM9/10/18
to v8-u...@googlegroups.com
Cause i saw the code but didn't find how it handles all the possible javascript i might write into a script file....

dan Med

unread,
Sep 10, 2018, 5:10:54 PM9/10/18
to v8-u...@googlegroups.com
How big is the offset from buffer to data ?
const void* Data() const { return buffer_->Data(); } 

sorry for spamming emails, i will try to condensate more 

@soylentgraham

unread,
Sep 10, 2018, 5:30:47 PM9/10/18
to v8-users
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 class declaration, but it's a little more complex than that) that was allocated somewhere sometime, (you can figure out where, but really you don't need to,  for this purpose it's just an object)
data is a member of that object, that points to some memory (somewhere else, maybe allocated by a different system, in a different place)
you have no idea (and you shouldn't need to know, or use the information) the "offset" from the buffer-object to the data. They are not necessarily related, or share the same memory space. (and in most cases, they're not even real memory addresses, they're more like identifiers)

Simple Javascript scripts can look like C sometimes (a few variables here and there, a few array creations), but underneath it's doing a lot more moving things around.
function x()
{
 var a = new array(10);
 var b = new array(100);
}
This may look like it allocates 2 arrays, but more than likely it's doing something radically different with actual memory.


> so how can i see the memory management ? 
As I said, you can't see the javascript side so easily (other than using the v8 debugging/inspector tools)
But if you want to see the C-side memory (which MAY be where the data that buffer points at came from) you can make your own allocator that v8 can use.
If you then breakpoint each call, you'll know when V8 is allocating some memory to use (which may or may not be a direct object in javascript, an array or typed array in javascript may not directly allocate here)


class TV8Allocator : public v8::ArrayBuffer::Allocator

{

public:

virtual void* Allocate(size_t length) override;

virtual void* AllocateUninitialized(size_t length) override;

virtual void Free(void* data, size_t length) override;

};


void* TV8Allocator::Allocate(size_t length)

{

auto* Bytes = new uint8_t[length];

for ( auto i=0; i<length; i++ )

Bytes[i] = 0;

return Bytes;

}


void* TV8Allocator::AllocateUninitialized(size_t length)

{

auto* Bytes = new uint8_t[length];

return Bytes;

}


void TV8Allocator::Free(void* data, size_t length)

{

auto* data8 = reinterpret_cast<uint8_t*>(data);

delete[] data8;

}


v8::Isolate::CreateParams create_params;

create_params.array_buffer_allocator = &mAllocator;



Cause i saw the code but didn't find how it handles all the possible javascript i might write into a script file....


Your computer most likely has more memory than you'll ever write in a script :)

If you're trying to work out where your script goes... arraybuffer isn't the right place.


Do you NEED to know? What exactly are you trying to achieve? (take a step back from the code and describe what you're trying to do;

are you trying to make an app? learn how memory works in c++? learn how memory is used in javascript? Why your app uses 1gb of memory?

dan Med

unread,
Sep 10, 2018, 5:38:16 PM9/10/18
to v8-u...@googlegroups.com
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 ? 

@soylentgraham

unread,
Sep 10, 2018, 5:46:34 PM9/10/18
to v8-users
> 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?

dan Med

unread,
Sep 10, 2018, 5:55:51 PM9/10/18
to v8-u...@googlegroups.com
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 ? 

--

@soylentgraham

unread,
Sep 10, 2018, 6:07:53 PM9/10/18
to v8-users
> 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.

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)

dan Med

unread,
Sep 11, 2018, 3:44:07 AM9/11/18
to v8-u...@googlegroups.com
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"

dan Med

unread,
Sep 11, 2018, 3:56:42 AM9/11/18
to v8-u...@googlegroups.com
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?

J Decker

unread,
Sep 11, 2018, 3:57:53 AM9/11/18
to v8-u...@googlegroups.com
On Tue, Sep 11, 2018 at 12:44 AM dan Med <litoki...@gmail.com> 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.

size_t len = sack_vfs_size( file );
uint8_t *buf = NewArray( uint8_t, len );
sack_vfs_read( file, (char*)buf, len );
Local<Object> 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...

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.

--

@soylentgraham

unread,
Sep 11, 2018, 6:32:09 AM9/11/18
to v8-users
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)

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 :)

dan Med

unread,
Sep 11, 2018, 6:41:23 AM9/11/18
to v8-u...@googlegroups.com
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 !






dan Med

unread,
Sep 11, 2018, 6:43:19 AM9/11/18
to v8-u...@googlegroups.com
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 ...

dan Med

unread,
Sep 11, 2018, 6:45:12 AM9/11/18
to v8-u...@googlegroups.com
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

dan Med

unread,
Sep 11, 2018, 4:09:54 PM9/11/18
to v8-u...@googlegroups.com
Would you suggest to build v8 such that I can debug it as I want ? 

Peter Schow

unread,
Sep 11, 2018, 6:12:05 PM9/11/18
to v8-u...@googlegroups.com
On Tue, Sep 11, 2018 at 2:09 PM dan Med <litoki...@gmail.com> 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.

dan Med

unread,
Sep 12, 2018, 7:15:19 AM9/12/18
to v8-u...@googlegroups.com
But can someone help me understand the arraybuffer part ? How to call arraybuffer::append and when I create an instance of a arraybuffer it will create it with maximum size so 37... bytes and will only say that the bytes used are the one which I’ve declared ?

dan Med

unread,
Sep 12, 2018, 1:09:37 PM9/12/18
to v8-u...@googlegroups.com
Oh one more thing, so each tab in chrome is handeled as a single process, but Is the same process sandboxes with the Windows 10 kernel. Security or there’s another process which is sandboxes and then the main tab process the ( renderer ) is executed inside of it ? 

Jakob Kummerow

unread,
Sep 12, 2018, 1:40:13 PM9/12/18
to v8-users
On Wed, 12 Sep 2018 at 13:15, dan Med <litoki...@gmail.com> wrote:
But can someone help me understand the arraybuffer part ? How to call arraybuffer::append and when I create an instance of a arraybuffer it will create it with maximum size so 37... bytes and will only say that the bytes used are the one which I’ve declared ?

There is no ArrayBuffer::Append. Read closely: you've found ArrayBufferBuilder::Append, which is some implementation detail in Blink (not V8). I don't know when it's called, but I've pointed out before how you can find out. When you use ArrayBuffer objects in JavaScript, then that code is not executed at all.

And when you create an ArrayBuffer(10) in JavaScript, it definitely does not allocate 32KB of memory. It'll round up to the nearest multiple of a pointer size.

On Wed, Sep 12, 2018 at 10:09 AM dan Med <litoki...@gmail.com> wrote:
Oh one more thing, so each tab in chrome is handeled as a single process, but Is the same process sandboxes with the Windows 10 kernel. Security or there’s another process which is sandboxes and then the main tab process the ( renderer ) is executed inside of it ? 

That's a completely unrelated question which has nothing to do with V8 and does not belong in this thread. I suggest to look around on http://dev.chromium.org/developers for a bunch of things that have been explained before.

dan Med

unread,
Sep 12, 2018, 2:34:59 PM9/12/18
to v8-u...@googlegroups.com
Yeah i meant   ArrayBufferBuilder::Append my bad.... but when it is actually called in blink ? 
Cause by the name it has to do with Arraybuffers..
Plus if i build v8 so i can examine the memory layout, where is the code on how v8 handeles arraybuffer ?
Where is the doc or some source where there's explained how v8 represents object in memory, how can i be sure that in memory i'm not starrying at a pointer instead of an object or something like that...

dan Med

unread,
Sep 13, 2018, 10:15:03 AM9/13/18
to v8-u...@googlegroups.com
No one is willingly to help me  ?

@soylentgraham

unread,
Sep 13, 2018, 10:23:48 AM9/13/18
to v8-users
You seem to be purposely ignoring the responses to your questions.

If you still want help, build v8, build a program, breakpoint the function you want to see is called, debug it (this alone answers all your questions), then come back if you still have a VERY SPECIFIC question.

dan Med

unread,
Sep 13, 2018, 10:32:05 AM9/13/18
to v8-u...@googlegroups.com
Okay I will but, how could I be sure when blink on the renderer process executes arraybufferbuilder ?? 
Or one more thing, can u redirect me to checkout how v8 represents data in memory, how would it handle arraybuffers? 
The only thing I’ve managed to find ( in the github repo ) was a JavaScript file which contained if I remember correctly, 2 definitions of sorting algorithms.

dan Med

unread,
Sep 13, 2018, 12:21:56 PM9/13/18
to v8-u...@googlegroups.com
Still no one ? 

J Decker

unread,
Sep 13, 2018, 12:42:13 PM9/13/18
to v8-u...@googlegroups.com


On Thu, Sep 13, 2018 at 9:21 AM dan Med <litoki...@gmail.com> wrote:
Still no one ? 
I dont know how I could have been more clear about the memory. 

Why do you think there is some magic to the buffer of an arraybuffer?  It's just continuous bytes in memory.  Especially well suited for communicating arrays of data to WebGL.

dan Med

unread,
Sep 13, 2018, 12:45:45 PM9/13/18
to v8-u...@googlegroups.com
That isn’t my question....
Arraybufferbuilder:append how could I get that to be called.
What I really need is a little guidance on how to understand how v8 will parse my JavaScript script and how it will allocate the data.
Maybe even how a buffer or if there’s something that describes how buffers are handeled or if there’s a file or code that tells me that not the memory I know... just how it will execute it that’s all 

Peter Schow

unread,
Sep 13, 2018, 7:14:37 PM9/13/18
to v8-u...@googlegroups.com
On Thu, Sep 13, 2018 at 10:45 AM dan Med <litoki...@gmail.com> wrote:
> That isn’t my question....
> Arraybufferbuilder:append how could I get that to be called.
> What I really need is a little guidance on how to understand how v8 will parse my JavaScript script and how it will allocate the data.
> Maybe even how a buffer or if there’s something that describes how buffers are handeled or if there’s a file or code that tells me that not the memory I know... just how it will execute it that’s all

Starting with the sample REPL code at:
https://github.com/v8/v8/blob/master/samples/shell.cc

could answer your questions. In the days that you've been pursuing
this, you could have traced all this by now. Good luck.

dan Med

unread,
Sep 14, 2018, 3:52:01 PM9/14/18
to v8-u...@googlegroups.com
Technica question, when Arraybufferbuilder:append will be called ?

dan Med

unread,
Sep 14, 2018, 3:53:49 PM9/14/18
to v8-u...@googlegroups.com
I don’t understand how that code could be helpful to me..

dan Med

unread,
Sep 15, 2018, 6:34:36 AM9/15/18
to v8-u...@googlegroups.com
That’s all.

dan Med

unread,
Sep 18, 2018, 3:54:41 PM9/18/18
to v8-u...@googlegroups.com
I know that i might have written the same thing over and over again but i didn't get an answer (which i really need)

When is ArrayBufferBuilder::Append called ?
Thank you

dan Med

unread,
Sep 18, 2018, 4:15:42 PM9/18/18
to v8-u...@googlegroups.com
I was reading this code but i can't figure outwhat av_..._.. stands for 
is it already opening the connection here?

static int tcp_open(URLContext *h, const char *uri, int flags) { struct addrinfo hints = { 0 }, *ai, *cur_ai; int port, fd = -1; TCPContext *s = h->priv_data; const char *p; char buf[256]; int ret; char hostname[1024],proto[1024],path[1024]; char portstr[10]; s->open_timeout = 5000000; av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), &port, path, sizeof(path), uri); if (strcmp(proto, "tcp")) return AVERROR(EINVAL); if (port <= 0 || port >= 65536) { av_log(h, AV_LOG_ERROR, "Port missing in uri\n"); return AVERROR(EINVAL); } p = strchr(uri, '?'); if (p) { if (av_find_info_tag(buf, sizeof(buf), "listen", p)) { char *endptr = NULL; s->listen = strtol(buf, &endptr, 10); /* assume if no digits were found it is a request to enable it */ if (buf == endptr) s->listen = 1; } if (av_find_info_tag(buf, sizeof(buf), "timeout", p)) { s->rw_timeout = strtol(buf, NULL, 10); } if (av_find_info_tag(buf, sizeof(buf), "listen_timeout", p)) { s->listen_timeout = strtol(buf, NULL, 10); } } if (s->rw_timeout >= 0) { s->open_timeout = h->rw_timeout = s->rw_timeout; } hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; snprintf(portstr, sizeof(portstr), "%d", port); if (s->listen) hints.ai_flags |= AI_PASSIVE; if (!hostname[0]) ret = getaddrinfo(NULL, portstr, &hints, &ai); else ret = getaddrinfo(hostname, portstr, &hints, &ai); if (ret) { av_log(h, AV_LOG_ERROR, "Failed to resolve hostname %s: %s\n", hostname, gai_strerror(ret)); return AVERROR(EIO); } cur_ai = ai; restart: #if HAVE_STRUCT_SOCKADDR_IN6 // workaround for IOS9 getaddrinfo in IPv6 only network use hardcode IPv4 address can not resolve port number. if (cur_ai->ai_family == AF_INET6){ struct sockaddr_in6 * sockaddr_v6 = (struct sockaddr_in6 *)cur_ai->ai_addr; if (!sockaddr_v6->sin6_port){ sockaddr_v6->sin6_port = htons(port); } } #endif fd = ff_socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol); if (fd < 0) { ret = ff_neterrno(); goto fail; } /* Set the socket's send or receive buffer sizes, if specified. If unspecified or setting fails, system default is used. */ if (s->recv_buffer_size > 0) { setsockopt (fd, SOL_SOCKET, SO_RCVBUF, &s->recv_buffer_size, sizeof (s->recv_buffer_size)); } if (s->send_buffer_size > 0) { setsockopt (fd, SOL_SOCKET, SO_SNDBUF, &s->send_buffer_size, sizeof (s->send_buffer_size)); } if (s->tcp_nodelay > 0) { setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &s->tcp_nodelay, sizeof (s->tcp_nodelay)); } if (s->listen == 2) { // multi-client if ((ret = ff_listen(fd, cur_ai->ai_addr, cur_ai->ai_addrlen)) < 0) goto fail1; } else if (s->listen == 1) { // single client if ((ret = ff_listen_bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen, s->listen_timeout, h)) < 0) goto fail1; // Socket descriptor already closed here. Safe to overwrite to client one. fd = ret; } else { if ((ret = ff_listen_connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen, s->open_timeout / 1000, h, !!cur_ai->ai_next)) < 0) { if (ret == AVERROR_EXIT) goto fail1; else goto fail; } } h->is_streamed = 1; s->fd = fd; freeaddrinfo(ai); return 0; fail: if (cur_ai->ai_next) { /* Retry with the next sockaddr */ cur_ai = cur_ai->ai_next; if (fd >= 0) closesocket(fd); ret = 0; goto restart; } fail1: if (fd >= 0) closesocket(fd); freeaddrinfo(ai); return ret; }

@soylentgraham

unread,
Sep 19, 2018, 6:36:49 AM9/19/18
to v8-users
Not sure where to start with this message

a) Not even vaguely related to the original topic, you should start a new thread when the topic is wildly different.
b) Do not start a new thread.
c) This code is from libav (or actually, maybe ffmpeg). av_XXX are macros, functions and other values. The AV prefix is a hint to the user (you) that it's part of the av library. AV stands for audio/visual (or I suppose, audio/video these days)
d) This is a question that should be on www.stackoverflow.com
e) Please do not reply to this message. (at least regarding this new topic)

dan Med

unread,
Sep 19, 2018, 12:39:32 PM9/19/18
to v8-u...@googlegroups.com
Ok so when is arraybufferbuilde:append called ?

dan Med

unread,
Sep 19, 2018, 4:36:40 PM9/19/18
to v8-u...@googlegroups.com
This is how I see it atm 
Each tab is a process that is composed of several threads, this process is sandboxed with the Windows kernel security ( on Windows )
Then we have WebKit which is the rendered thread inside of this main tab (thread) which as the name implies will render the page.
When in the renderer process is v8 called ? 
Or when WebKit is executing UI things v8 is also running JavaScript code ? 

Last thing is when ArrayBufferBuilder:append is called ? 

dan Med

unread,
Sep 19, 2018, 5:12:57 PM9/19/18
to v8-u...@googlegroups.com
Can you guide me the source codes for which all of this is defined? 

Peter Schow

unread,
Sep 19, 2018, 6:14:46 PM9/19/18
to v8-u...@googlegroups.com
On Wed, Sep 19, 2018 at 2:36 PM dan Med <litoki...@gmail.com> wrote:
> This is how I see it atm
> Each tab is a process that is composed of several threads, this process is sandboxed with the Windows kernel security ( on Windows )
> Then we have WebKit which is the rendered thread inside of this main tab (thread) which as the name implies will render the page.
> When in the renderer process is v8 called ?
> Or when WebKit is executing UI things v8 is also running JavaScript code ?

This mailing list is about V8 itself, not arbitrary consumers (there
are many) of V8. Do you understand the difference? V8 has no notion
of "tabs", "WebKit", "renderer process", or "UI". I suggest you find
another place to ask your questions.

dan Med

unread,
Sep 20, 2018, 1:04:02 AM9/20/18
to v8-u...@googlegroups.com
Ok but then can someone give me a big picture of the directories ? And how the code is generally structured ? 
Or how is ArrayBufferBuilder:append called ?

dan Med

unread,
Sep 24, 2018, 5:18:11 PM9/24/18
to v8-u...@googlegroups.com
When is it called ? 

J Decker

unread,
Sep 24, 2018, 7:58:58 PM9/24/18
to v8-u...@googlegroups.com
On Mon, Sep 24, 2018 at 2:18 PM dan Med <litoki...@gmail.com> wrote:
When is it called ? 
It never is; It doesn't even exist in V8.

Caitlin Potter

unread,
Sep 28, 2018, 1:06:17 AM9/28/18
to v8-users
You can find places where ArrayBufferBuilder::Append is called, by looking for the ArrayBufferBuilder symbol on cs.chromium.org.

For example, here’s one use of it: https://cs.chromium.org/chromium/src/third_party/blink/renderer/core/fileapi/file_reader_loader.cc?type=cs&g=0&l=260

I don’t have an answer for your other question regarding the memory layout (were you asking if the builder is a variably sized object, or if it just holds a pointer to the variably sized byte array, or something else?) — but hopefully you’ve had that cleared up already.

dan Med

unread,
Sep 28, 2018, 3:50:19 AM9/28/18
to v8-u...@googlegroups.com
Yes, i was looking at something like this ^^

dan Med

unread,
Sep 28, 2018, 5:14:34 AM9/28/18
to v8-u...@googlegroups.com
as far as i know for me to get the method FileReaderLoader::OnReceivedData called which will call the ArraybufferBuilder::Append this stack call has to happen :
BlobReaderClientInterceptorForTesting::OnCalculatedSize --> call --> OnCalculatedSize --> call --> OnDataPipeReadable --> call --> OnReceivedData --> ArraybufferBuilder::Append.
now beforereading the entire code cause i need it for a thing, can someone help me to understand when BlobReaderClientInterceptorForTesting i know it is from the mojo IPC but nothing more. Like i don't know if the thread will call this because there will be a file to read or what.

Caitlin Potter

unread,
Sep 28, 2018, 8:35:54 AM9/28/18
to v8-users
That question is probably out of scope for v8-users. The good news is, cs.chromium.org is very good at finding when things are called, how they’re used, etc.

dan Med

unread,
Sep 28, 2018, 8:39:31 AM9/28/18
to v8-u...@googlegroups.com
I appreciate your help, but still i can't seem to just understand the stack calls and if i do that then i like to understand what thing should i do in the code to get v8 execute those lines, well if my prievous question is out of scope for v8-users how can i understand how they work ? 
There is no doc

Il giorno ven 28 set 2018 alle ore 14:35 Caitlin Potter <ca...@igalia.com> ha scritto:
That question is probably out of scope for v8-users. The good news is, cs.chromium.org is very good at finding when things are called, how they’re used, etc.

Michael Hablich

unread,
Oct 1, 2018, 8:42:02 AM10/1/18
to v8-users
Hi Dan,

as already pointed out in this thread and other ones created by you: Please ask blink-related questions on blin...@chromium.org. A good way to understand how something works is to check existing code as Caitlin already pointed out. Please use cs.chromium.org for this. If after consulting blin...@chromium.org and cs.chromium.org you still have questions about the V8 codebase, feel free to ask questions on v8-u...@googlegroups.com.

Cheers,
Michael
Reply all
Reply to author
Forward
0 new messages