Jump to content
  • Advertisement
Sign in to follow this  
Borneq

How to create virtual machine?

This topic is 2861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am planning to create virtual machine. How is better, use stack like Java or .Net vm or static single assignment form as LLVM has ?
How garbage collectors gets roots from local variables? In article http://www.artima.com/insidejvm/ed2/gcP.html is described only garbage collection while the root nodes are already found.
First I must stop all but GC threads. Next I should see through all stack frames and see local variables - how do this step ?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Borneq
I am planning to create virtual machine.
Why? Which need is unmet by existing VMs?

Quote:
How is better, use stack like Java or .Net vm or static single assignment form as LLVM has ?
It depends...

Quote:
How garbage collectors gets roots from local variables?
for (every static variable s) {
follow_pointers(s)
}
for (every stack s) {
for (every variable v in s)
follow_pointers(v);
}


Quote:
First I must stop all but GC threads.
Large majority of VMs is single threaded. It took Sun a decade to develop a decent concurrent GC.

Quote:
Next I should see through all stack frames and see local variables - how do this step ?

Aside from a huge number of academic articles, all popular VMs, excluding CLR, are open source.

Share this post


Link to post
Share on other sites
Quote:
Original post by Antheus

for (every stack s) {
for (every variable v in s)
follow_pointers(v);
}


I know follow_pointers but how work for (every stack s) and for (every variable v in s) ?

Quote:

Aside from a huge number of academic articles,

What article? In article http://www.artima.com/insidejvm/ed2/gcP.html is described only step follow_pointers

Quote:

all popular VMs, excluding CLR, are open source.

And many thousands code line to analyse.

Share this post


Link to post
Share on other sites
Quote:
Original post by Borneq
I know follow_pointers but how work for (every stack s)


By the time you are ready to implement the garbage collection, the answer to this will be about the most obvious thing you can possibly think of. You have to know where your VM stack is, and how it is structured, in order to get this far. You're going to be the one designing it!

Share this post


Link to post
Share on other sites
Quote:
Original post by Borneq

And many thousands code line to analyse.

Millions, actually. But only very few parts are related to GC.

Why are you trying to create a VM? To learn how it's done? Then it's a lot of work.

Otherwise make single-threaded ref-counted or mark-sweep GC, like Python does it. Trying to copy JVM's design is simply too complicated.

Share this post


Link to post
Share on other sites
Quote:
Original post by Borneq
I am planning to create virtual machine. How is better, use stack like Java or .Net vm or static single assignment form as LLVM has ?
How garbage collectors gets roots from local variables? In article http://www.artima.com/insidejvm/ed2/gcP.html is described only garbage collection while the root nodes are already found.
First I must stop all but GC threads. Next I should see through all stack frames and see local variables - how do this step ?


To get a root node set you need to examine the stack and registers of every program thread. Usually this is done with stack maps and register maps for jitted methods. Every method is divided into regions and every region has a stack map and register map that describes which stack slots and registers contain live objects. For purely interpreted methods you keep a list of live objects.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!