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

2018-09-12 Thread 'Deepti Gandluri' via v8-users
If you are looking to track Wasm allocations, there is a counter on the 
Isolate that wasm memory allocations are registered 

 
with - V8.WasmAddressSpaceUsageMiB. The page allocator is the catch all for 
allocations, so that should work too. 

For GetHeapStatistics 
(),
 
WasmMemory is accounted for under malloced memory, could you elaborate on 
the discrepancies that you are seeing? 

Ideally, Memory.Grow should honor the same resource constraints that a 
JSArrayBuffer allocation does, because it either adjusts the externally 
allocated memory, 

 
or allocates a new ArrayBuffer. The WasmMemoryTracker tracks wasm 
allocations 
,
 
apart from the isolate counters, there is no public API for the WasmEngine 
right now. 

On Wednesday, September 12, 2018 at 4:14:17 PM UTC-7, ken...@cloudflare.com 
wrote:
>
> Looking at the code, it looks like --wasm_max_mem_pages limits the size of 
> a particular Memory object, but a script can always allocate multiple 
> objects / create multiple instances. I need to limit the script's total 
> memory usage...
>
> I do need to track and limit per-isolate. But maybe I can use 
> PageAllocator combined with keeping track of the current isolate using 
> thread-locals? Or might it be called in background threads?
>
> -Kenton
>
> On Tuesday, September 11, 2018 at 11:19:13 AM UTC-7, Ben Noordhuis wrote:
>>
>> On Tue, Sep 11, 2018 at 6:34 PM, 'Kenton Varda' via v8-users 
>>  wrote: 
>> > 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 
>>
>> You should be able to control it with the `--wasm_max_mem_pages=...` 
>> flag (expressed in multiples of 64k) that you can set with 
>> `v8::V8::SetFlagsFromString()`.  I don't think there is currently any 
>> other way to configure it. 
>>
>> WASM allocations should be observable when you return a custom 
>> `v8::PageAllocator*` from `v8::Platform::GetPageAllocator()`.  Maybe 
>> not ideal but hopefully workable. 
>>
>> You can probably also limit memory growth that way, by returning 
>> nullptr when it's past a threshold, although not on a per-isolate 
>> basis. 
>>
>

-- 
-- 
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] Limiting WASM memory allocation as an embedder?

2018-09-12 Thread kenton via v8-users
Looking at the code, it looks like --wasm_max_mem_pages limits the size of 
a particular Memory object, but a script can always allocate multiple 
objects / create multiple instances. I need to limit the script's total 
memory usage...

I do need to track and limit per-isolate. But maybe I can use PageAllocator 
combined with keeping track of the current isolate using thread-locals? Or 
might it be called in background threads?

-Kenton

On Tuesday, September 11, 2018 at 11:19:13 AM UTC-7, Ben Noordhuis wrote:
>
> On Tue, Sep 11, 2018 at 6:34 PM, 'Kenton Varda' via v8-users 
> > wrote: 
> > 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 
>
> You should be able to control it with the `--wasm_max_mem_pages=...` 
> flag (expressed in multiples of 64k) that you can set with 
> `v8::V8::SetFlagsFromString()`.  I don't think there is currently any 
> other way to configure it. 
>
> WASM allocations should be observable when you return a custom 
> `v8::PageAllocator*` from `v8::Platform::GetPageAllocator()`.  Maybe 
> not ideal but hopefully workable. 
>
> You can probably also limit memory growth that way, by returning 
> nullptr when it's past a threshold, although not on a per-isolate 
> basis. 
>

-- 
-- 
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-12 Thread dan Med
Yeah i meant   ArrayBuffer*Builder*::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...

Il giorno mer 12 set 2018 alle ore 19:40 Jakob Kummerow <
jkumme...@chromium.org> ha scritto:

> On Wed, 12 Sep 2018 at 13:15, dan Med  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 ArrayBuffer
> *Builder*::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  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.
>
> On Wed, 12 Sep 2018 at 00:12, Peter Schow  wrote:
>>>
 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.

>>> --
>> --
>> 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 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-12 Thread Jakob Kummerow
On Wed, 12 Sep 2018 at 13:15, dan Med  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 ArrayBuffer
*Builder*::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  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.

On Wed, 12 Sep 2018 at 00:12, Peter Schow  wrote:
>>
>>> 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.
>>>
>> --
> --
> 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] Arraybuffer

2018-09-12 Thread dan Med
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 ?

On Wed, 12 Sep 2018 at 13:15, dan Med  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 ?
>
> On Wed, 12 Sep 2018 at 00:12, Peter Schow  wrote:
>
>> 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.
>>
>

-- 
-- 
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] Re: ChromeDevTools connected to Inspector, but error responses... missing native JS functions?

2018-09-12 Thread @soylentgraham
With a lot of back & forth help from Ibon/hyperandroid, we've got a bit 
further in working out which things are good, and which are bad. 
Feels like we're close, but things are still unstable, and a bit 
unresponsive.

I can kinda break into the code (which only shows *this *in sources)
Still get the assert above from trying to autocomplete too many times. 
(albeit after a RunMessageLoop callback now)
And if I add a script origin, I get a crash trying to stacktrace 
(immediately when connecting, still trying to figure this out, as my 
scriptorigin is okay)

More stripped back version here (cutting more dependencies out, but all my 
setup, inspector, frontend, messaging is in v8minimal.cpp)
https://github.com/SoylentGraham/V8InspectorMinimal

On Monday, 27 August 2018 13:49:37 UTC+1, @soylentgraham wrote:
>
> Through various sources (ie, googling & github) I've finally got a bit of 
> a grasp of the flow for connecting chrome dev tools to my v8 app. (which is 
> using a pretty recent HEAD build I've built myself with all default 
> settings other than compiling as a static lib[s]. v8-version.h says 7.0.0.0)
>
> I connect via an explicit url (can't quite get json/list/ to show up in 
> chrome yet)
> *chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:8008
>  
> *
> (Not sure how relevant the v8only=true and experiments=true are, couldn't 
> find any documentation on this)
>
> This connects to my websocket, and I pass all messages straight to 
> *Session->dispatchProtocolMessage*
>
> My channel then gets *sendResponse's* in return, which I send back to 
> chrome over my websocket.
>
> Chrome dev tools shows essentially an empty debugger, no sources, no 
> console output, no errors...
>
> The responses my isolate/context sends back, suggest maybe I have some JS 
> symbols/modules missing, which maybe I need to implement?
> I'm kinda assuming this, as the debugger. methods succeed, but things like 
> *Inspector.enable* (which I haven't found anyone implementing, but some 
> people are implementing Inspector objects, just with different methods) fail
>
> *Chrome tools message: {"id":16,"method":"Inspector.enable"}*
>
> *Channel response: {"error":{"code":-32601,"message":"'Inspector.enable' 
> wasn't found"},"id":16}*
> Is this why chrome isn't proceeding with anything?
> Am I supposed to implement these, or perhaps are they missing from my 
> native blobs when I built my v8 libraries?
>
> My overloads of the inspector client functions like 
> *runMessageLoopOnPause* aren't being called, but I assume that's just 
> because I haven't gotten to any stage where commands are being evaluated?
>
> Below is what I get when I connect chrome, but then it just sits there :)
>
> Thanks for any pointers in the right direction!
>
> *Chrome tools message: 
> {"id":1,"method":"Network.enable","params":{"maxPostDataSize":65536}}*
>
> *Channel response: {"error":{"code":-32601,"message":"'Network.enable' 
> wasn't found"},"id":1}*
>
> *Chrome tools message: {"id":2,"method":"Page.enable"}*
>
> *Channel response: {"error":{"code":-32601,"message":"'Page.enable' wasn't 
> found"},"id":2}*
>
> *Chrome tools message: {"id":3,"method":"Page.getResourceTree"}*
>
> *Chrome tools message: {"id":4,"method":"Profiler.enable"}*
>
> *Channel response: 
> {"error":{"code":-32601,"message":"'Page.getResourceTree' wasn't 
> found"},"id":3}*
>
> *Channel response: {"id":4,"result":{}}*
>
> *Chrome tools message: {"id":5,"method":"Runtime.enable"}*
>
> *Channel response: 
> {"method":"Runtime.executionContextCreated","params":{"context":{"id":1,"origin":"","name":"PopEngineContextName"}}}*
>
> *Channel response: {"id":5,"result":{}}*
>
> *Chrome tools message: {"id":6,"method":"Debugger.enable"}*
>
> *Channel response: 
> {"method":"Debugger.scriptParsed","params":{"scriptId":"9","url":"","startLine":0,"startColumn":0,"endLine":1,"endColumn":0,"executionContextId":1,"hash":"2a70962568dbbde00fb323decd63c2ca137b304c","isLiveEdit":false,"sourceMapURL":"","hasSourceURL":false,"isModule":false,"length":17}}*
>
> *Channel response: 
> {"id":6,"result":{"debuggerId":"(6B1A58050CBFAE70E5B41C5556E5520D)"}}*
>
> *Chrome tools message: 
> {"id":7,"method":"Debugger.setPauseOnExceptions","params":{"state":"uncaught"}}*
>
> *Channel response: {"id":7,"result":{}}*
>
> *Chrome tools message: 
> {"id":8,"method":"Debugger.setAsyncCallStackDepth","params":{"maxDepth":32}}*
>
> *Channel response: {"id":8,"result":{}}*
>
> *Chrome tools message: {"id":9,"method":"DOM.enable"}*
>
> *Channel response: {"error":{"code":-32601,"message":"'DOM.enable' wasn't 
> found"},"id":9}*
>
> *Chrome tools message: {"id":10,"method":"CSS.enable"}*
>
> *Channel response: {"error":{"code":-32601,"message":"'CSS.enable' wasn't 
> found"},"id":10}*
>
> *Chrome tools message: {"id":11,"method":"Overlay.enable"}*
>
> *Channel response: {"error":{"code":-32601,"message":"'Overlay.enable' 
> wasn't found"},"id":11}*
>
> *C

Re: [v8-users] Arraybuffer

2018-09-12 Thread dan Med
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 ?

On Wed, 12 Sep 2018 at 00:12, Peter Schow  wrote:

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

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