If you are curious about how Dart VM compiles your Dart code into native
code. (spoiler alert: most of these ideas are coming from Self VM from 90s).
AOT is a completely different story. There will be a talk about Dart VM AOT
mode on the Dart Summit this year. Make sure you see it - if you are
interested in the challenges that AOT compilation is facing.
Post by Daniel MorilhaThis question comes once in a while and unfortunately I have never found a
good high level document explaining the vm internals.
Dart is more than its VM. It is a programming language project led by
google.
As pointed out, the original vm was originally designed to replace
javascript on the browser, the language however is purpose free. Dartino
implements a very different vm yet relying on the same language.
The dart vm which runs on the server and most recently has been adapted to
run on mobile consists of a C++ runtime (memory manager, scheduler,
profiler, snapshots, libraries...) and the compiler part (parser, compiler,
optimizer, assembler). The core of the VM[1] can be easily embedded with
only limited dependencies into their host OS. When running on the server
(aka standalone[2]) dart exposes additional libraries to deal with IO.
There is a considerable amount of dart written libraries as well[3].
Libraries written in dart use the same infrastructure as the code that the
user writes.
the DartVM implements AOT, JIT and a Dart Byte Code (DBC) interpreter for
a mix of architectures. The language was designed to rely on JIT techniques
so performance for AOT may not compare. However keep in mind AOT part of
the project is new and work has been done to speed it up[4]. In fact the
whole introduction for AOT started when the project started pursuing the
mobile platform rather than web.
The compiler infrastructure within the VM is robust and massive. IMO it is
what makes reading the source code complicated. If you are not into
compilers, it is very difficult to keep up with all the concepts
(intrinsics, arity, canonicalization, class hierarchy, different call
conventions). Nevertheless it is a very well designed project yet pragmatic
given all it does.
The hello world program, gets parsed and compiled to the machine's
architecture. Your console calls tie with the libraries for your operating
system. In the end it is just the same kernel call you would see with your
C code. There are lots of abstractions and layers for that to happen. The
key for performance is to remove the abstraction as much as possible for
heavily executed code. Once you have machine code the C++ runtime jumps
into it and your compiled code takes over the CPU, for certain operations
it goes back to the C++ runtime or even to something external to the vm.
There is a short video which helps to understand the single compiler[5].
Bear in mind that at that time there was a lot of comparisons with
javascript, which IMO should not make sense at this point given their
different goals.
HTH
[1]: https://github.com/dart-lang/sdk/tree/master/runtime/vm
[2]: https://github.com/dart-lang/sdk/tree/master/runtime/bin
[3]: https://github.com/dart-lang/sdk/tree/master/sdk/lib
[4]: https://codereview.chromium.org/2379733002/#msg11
[5]: http://youtu.be/bNESI-d-tBQ
Hi,
Thanks! That's pretty interesting. Is there a Dart VM developer we could
ping to add some more to the discussion?
They hang around here. I'm not aware of any articles or videos talking
about the Dart VM in detail, though.
You could try to compare what they have done in the Dart VM by studying up
the JS VM which seems to
be talked about more.
https://www.youtube.com/user/blinkontalks/videos
http://youtu.be/r5OWCtuKiAk
Like I said before, the Dart VM and the JS VM share many properties and
concerns. They have started
diverging more as of late once the JS VM introduced a new engine called
TurboFan which is said to
deal with a Sea of Nodes. But TurboFan was more targeted at high
performance math and will have to
catch up to the "traditional" engine used by both JS and Dart that does a
better job at "normal" code. If
you watch the video about Ignition, you will know that the challenge they
have is kind of interesting.
The Dart VM had maybe around 5 core designers. A couple of them may be
left maintaining it now. They
may be helped by some new developers though. Since the interest in the
Dart VM died down a little once
they could not have it on the browser, some of them may have moved on a
little bit. They tried their hands
at other VMs instead like Dartino for IoT which didn't pan out.
As Anders Hejlsberg from Microsoft alluded to in a recent video when
talking about modern day compilers,
some of these compilers are not found in the books yet. They are being
invented by these top technological
companies. When Chrome innovated the JS VM, all the other browser
companies took notice and started
borrowing ideas so that they could improve their own engines too. These
days, Firefox and Edge (IE) have
caught up. That may partly explain why these developers are not in the
teaching business.
If you want, you can try to talk to one of the JS and Dart VM developers
https://twitter.com/mraleph
https://twitter.com/bmeurer
Beware though that the VM has both the lower level tidbits and the higher
level stuff to make it work. A single
developer may not cover all of it.
I share your curiosity though. On the NodeJS project, they have debugging
tools that help to explain how it
all works. The Dart VM may have some debug APIs too. You could try to find
some of those. Be on the
lookout for material explaining how the JS VM JIT works. It should be
similar.
https://github.com/dartino/sdk
But the Dartino VM was still interpreted. So it was relatively slow. But
Dart kind of needed an Interpreter.
The Ignition VM for JavaScript is also based on bytecodes and interpreted.
JavaScript also needs an
interpreter for devices that don't allow for JIT or that have
restrictions. An interpreter supposedly helps with
the faster startup too. With the Ignition VM, they will use the TurboFan
compiler to generate optimized
code. Maybe they wanted to have an extra layer of optimization on top of
Dartino too, but they didn't get
to that point unfortunately. My feeling is that they are on that treadmill
of we have 5 standards, we need to
fix them, we create a new standard and we now have 6 standards instead. :-)
Cheers,
Joao
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an