Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding Google V8's Architecture

Tags:

c++

c#

v8

I'm not sure I understand V8's architecture (yes, I've read its documentation).

In C# with the v8sharp wrapper I write something like this, for example:

namespace App
{
    class Point
    {
        public Point() { }

        public Point(double x, double y) {
            this.X = x;
            this.Y = y;
        }

        public double X { get; set; }
        public double Y { get; set; }
    }
}

static class Program
{
    static void Main() {
        //registering with v8sharp
        V8Engine engine = V8Engine.Create();        
        engine.Register<App.Point>();

        //execute javascript
        object rtn = engine.Execute("new App.Point(10, 10);");
    }
}

How would I write the same thing in Standard C++ without this wrapper?

Thanks.

like image 314
Alon Gubkin Avatar asked Jun 27 '10 23:06

Alon Gubkin


People also ask

How does Google V8 engine work?

The V8 engine uses the Ignition interpreter, which takes in the Abstract Syntax Tree as the input and gives the byte code as the output, which further proceeds to the execution phase. When the code is being interpreted, the compiler tries to talk with the interpreter to optimize the code.

What is V8 architecture?

What is V8? V8 is Google's open source high-performance JavaScript and WebAssembly engine, written in C++. It is used in Chrome and in Node. js, among others. It implements ECMAScript and WebAssembly, and runs on Windows 7 or later, macOS 10.12+, and Linux systems that use x64, IA-32, ARM, or MIPS processors.

Why does Google use V8 engines?

V8 was first designed to increase the performance of JavaScript execution inside web browsers. In order to obtain speed, V8 translates JavaScript code into more efficient machine code instead of using an interpreter.

Why is V8 so fast?

However, V8 does it incrementally, i.e., for each GC stop, V8 tries to mark as many objects as possible. It makes everything faster because there's no need to stop the entire execution until the collection finishes. In large applications, the performance improvement makes a lot of difference.


1 Answers

If you look here: http://code.google.com/apis/v8/embed.html they have a sample that is identical to yours under "Accessing Dynamic Variables"

like image 151
Romain Hippeau Avatar answered Oct 05 '22 23:10

Romain Hippeau