Using V8 to generate runtime calls in Functions

45 views
Skip to first unread message

Malek Musleh

unread,
Mar 13, 2015, 4:02:47 PM3/13/15
to v8-u...@googlegroups.com
Hi,

I have a 2 part (but semi-related question) here.

1)

I am looking at being able to generate specific runtime calls during the execution of certain JS functions. This can be thought of as having V8 insert calls (annotating function entry/exit points) with calls to an external system library/call (e.g. Calling "ls").

I see there are ways of doing the opposite: invoking v8 from within C++ code: 


But I am sort of looking for the opposite. Is something like the following possible:

 Runtime.getRuntime().exec("ls"); // example invoking runtime from android / Java


2)

My end goal here is to have the code-generator generate additional calls (at the prologue/epilogue) to this external function / library) for functions deemed to be "hot" by crankshaft. For this I presume, Would I need to edit the code-generator part (full-codegen.cc) to generate these extra calls inside these functions, or should it be done elsewhere, perhaps in the lithium generator part?

I should note that I have been able to compile this external library within v8 as a third party tool, and I verified invoking it within v8 works.


Malek

Malek Musleh

unread,
Mar 13, 2015, 7:18:04 PM3/13/15
to v8-u...@googlegroups.com
Doing some more investigating, I am able to narrow down the scope of
my question:
In lithium.cc / fullcode-gen.c I see calls to MakeCodePrologue() and
MakeCodeEpilogue(). Since I am interested in adding to the prologue of
optimized code, I can focus on the lithium.cc part.

Both those call void CodeGenerator::MakeCodePrologue() in codegen.cc,
but I don't see any actual code being "generated" or emitted there.
The call I want to emit is basically just 2 assembly instructions (I
use this as a hint driver for my simulator).

Can I just call emit() from within those makePrologue/Epilogue calls?


Malek
> --
> --
> v8-users mailing list
> v8-u...@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "v8-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/v8-users/SXJMJw7il3g/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> v8-users+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Flying Jester

unread,
Mar 13, 2015, 10:55:11 PM3/13/15
to v8-u...@googlegroups.com
Doing the first thing you suggest is really not at all related to dealing with the optimizer. Just putting strings from JS into a C++ system exec would not be very difficult.

Unless you want to do something to V8 itself, and are less concerned with actually doing things from JavaScript, I suggest you do not touch the guts of V8.

Malek Musleh

unread,
Mar 14, 2015, 12:26:04 PM3/14/15
to v8-u...@googlegroups.com
For 1) I was trying to do something like this initially:

http://stackoverflow.com/questions/20643470/execute-a-command-line-binary-in-node-js
but it doesn't seem to work with v8 standalone. Might seem like a
trivial example, but would you be able to provide an example that
would work with v8 standalone?
Reply all
Reply to author
Forward
0 new messages