Freewind
Freewind

Reputation: 198368

How to read the source of DartVM?

I'm trying to learn more about Dart, so I want to read the source of dart. The dart vm is written in c++, and the code base is huge.

I get the source code from https://github.com/dart-lang/bleeding_edge

Following is just the code inside the runtime package, you can see it has more than 180K lines of c++ code.

➜  runtime git:(master) ✗ cloc .
     752 text files.
     746 unique files.
      47 files ignored.

http://cloc.sourceforge.net v 1.58  T=6.0 s (117.7 files/s, 52169.5 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
C++                            375          32722          21436         180070
C/C++ Header                   238          10936           8753          36452
Dart                            76           2785           1340          16661
Python                          13            254            211           1113
C                                2             28             28            107
Bourne Shell                     1             16             11             85
Assembly                         1              1              3              5
-------------------------------------------------------------------------------
SUM:                           706          46742          31782         234493
-------------------------------------------------------------------------------

I have learnt dart for one month, and I've several years of Java development experience, but I don't know c++. Could someone give me some advice about learning dart vm? I have a long term plan to learn dart vm.

My question is, to learn dart vm, what kind of knowledge is more important, that I'd better pay some time to learn it:

  1. Do I need to master c++ before I can really read the source of dart vm?
  2. Do I need to read some books about VM design? If there is any?
  3. Is there any documents or books or blogs about Dart VM that I should read?
  4. and any other advice

Upvotes: 4

Views: 907

Answers (2)

adam-singer
adam-singer

Reputation: 4847

I would say a functional way to get intimate with the dart vm (besides just reading the source) would be writing simple extensions and using the debugger to walk the vm. That kind of task will help you learn about how the dartvm boostraps, loads libraries, parse dart code, look up functions, create isolates, etc... I also found reading the V8 source as a good reference to the layout of the dart vm, it had some similarities in code structure and style. A list of influential vm related books would be a great question for some of the vm engineers, if you do get a list going please repost it.

Upvotes: 1

Chris Buckett
Chris Buckett

Reputation: 14398

Here's my take on it. Learning the structure and function from source code, just by reading a source code is hard, and takes time. If there were some design documents to guide you, that would be easier, but would still be hard.

It would be better (in my experience... so perhaps this isn't a good stackoverflow question) to focus your efforts in doing something with the VM. Pick a specific bug or enhancement and try and implement it. You'll learn much more by actually trying to maintain the code rather than just reading it.

I mentioned "in my experience". Like you, I'm primarily a Java / C# dev, and haven't really looked at C++ for 15 years.

Back in the early days of the Dart VM, there was a bug that was preventing me from doing something specific (I don't remember what, now). I had a stack trace to point me in the right direction, and by reading the code and trying a few things (using Google to check on specific syntax where I wasn't sure). I was able to modify the VM and work around my immediate problem (and the bug was refactored out in a later commit by someone else anyway). The point here being that it's good to have a purpose that you can hang your learning on.

For completeness, in answer to the "anything I should read" part of your question:

I also blogged about setting up a Dart build environment a couple of years ago. Tip: If you're a windows user, use an Ubuntu VM - it will save hours.

The "Fast Code is Always in Fashion" video from Google I/O 2013 is a good watch - it has the primary designers of the Dart VM talking about the VM. It might give you a bit of an overview.

Finally, the Dart Language Specification is worth a read, as the Dart VM is an implementation of the spec.

Upvotes: 6

Related Questions