Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Virtual Machine Design and Implementation in C/C++

timothy posted more than 12 years ago | from the truly dept.

Programming 240

wackybrit writes: "The concept of the virtual machine is one of the most important concepts in computer science today. Emulators use virtual machines, operating systems use virtual machines (Microsoft's .NET), and programming languages use virtual machines (Perl, Java)". Read on for his review of Virtual Machine Design and Implementation in C/C++, an attempt to examine and explain virtual machines and the concepts which allow them to exist.

Virtual machines are, in effect, a software model of a whole system architecture and processor. They take in bytecode (formed of opcodes, operands, and other data) and execute it, much in the same way a real system executes code. Running these operations in software, however, gives you more security, and total control over how the system works.

Virtual machines are popular for a number of reasons. The first is that they give programmers a third compiler option. You don't have to either go the dynamic interpreted route or the static compiled route, you can compile for a virtual machine instead. Another is that virtual machines aid portability. If you compile your code for a virtual machine, you can run that binary on any system to which the virtual machine has been ported.

Few books have been written on virtual machines, with only a few Java Virtual Machine titles available. Virtual Machine Design and Implementation by Bill Blunden is therefore a landmark book for anyone with an interest in virtual machines, or even system and processor architecture as a whole.

What's to Like?

Blunden makes sure to cover every topic related to virtual machines in extreme depth. The beauty of this is that you're not left in the dark, but that experts can simply skip sections. The book is well divided up, and off topic rants or notes are clearly marked with dividers. This is an easy book to read, even though it runs to some 650 pages.

To lead the reader through the entire production of a virtual machine, Blunden showcases the development of his own 'HEC' virtual machine (HEC being one of the fictional companies in 'CPU Wars'). Initially he starts slowly, and introduces the reader to how CPUs work, how memory works, how paging works, and how almost any other system process you can imagine works. Nothing is missed out. Multitasking, threads, processes, porting.. he covers it all. This is excellent for those new to some of these topics, and makes this an advanced book that's actually quite readable by someone with a modicum of computer science experience.

After laying down the foundations for the design of the virtual machine, the actual development starts in Chapter 3. All of the code in this book is in C or C++, and nearly all of the code is talks about is actually printed on the right pages in the book. No more flipping between code on your computer and the book, it's all just where it should be!

Further on in the book, a number of extremely advanced concepts are introduced, but even these need not be out of the reach of an intermediate programmer. Blunden presents the most vivid insight into how assemblers and debuggers are created, and the book is worth it for this information alone.

Another important thing about this book is that it looks at creating a register based virtual machine. Stack based virtual machines are covered, but the author makes a compelling argument for using registers. This makes a refreshing change from the Java Virtual Machine books that ram stack based theory down your throat. It's also useful if you're interested in the Perl 6 'Parrot' project, which is also an in-development register based virtual machine, and bound to become rather important over the next few years.

What's to Consider?

Virtual machines aren't for everyone. If you're a high level programmer working with database apps, this isn't really for you. This book is primarily for system engineers, low level programmers, and hobbyists with an interest in compilation, assembler, and virtual machine theory.

This is not a book for beginners. You need to have a reasonable knowledge of C to understand the plentiful examples and source code in the book. C++ is also useful, although OOP is clearly explained, so even a standard C programmer could follow it. That said, this is an excellent book for intermediate programmers or computer science students, as a number of advanced topics (garbage collection, memory management, assembler construction, paging, token parsing) are dealt with in a very easy to understand way.

The Summary

Released in March 2002, this book is extremely up to date. This is good news, as virtual machines are clearly going to take up a good part of future compiler and operating system technology, and this makes it important to learn about their construction and operation now. These technologies are already in the marketplace; Microsoft's .NET, and JVM, for example. Perl 6's 'Parrot' is also going to become a big player, with languages like Ruby, Python, and Scheme being able to run on it in the future.

Whether you want to learn about system architecture, assembler construction, or just have a reasonably fun programming-related read, this book is great.

Table of Contents
  1. History and Goals
  2. Basic Execution Environment
  3. Virtual Machine Implementation
  4. The HEC Debugger
  5. Assembler Implementation
  6. Virtual Machine Interrupts
  7. HEC Assembly Language
  8. Advanced Topics

You can purchase Virtual Machine Design and Implementation in C/C++ from Slashdot welcomes readers' book reviews -- to submit yours, read the book review guidelines, then visit the submission page.

cancel ×


Sorry! There are no comments related to the filter you selected.

♬ First musical post! ♫ (-1)

Mr F J Musical-Troll (582606) | more than 12 years ago | (#3762376)

Another one from Warp Records [] . Hope y'all like it.

Re:♬ First musical post! ♫ (-1)

News For Turds (580751) | more than 12 years ago | (#3762419)

u r teh rawx.

Everybody love NAZIs! (-1)

Thud457 (234763) | more than 12 years ago | (#3762485)

NAZI [] s! We have NAZI [] s! Here at crazy uncle Sam's project Paperclip, we have the finest NAZI [] s your taxpayer money could buy!

We've got big name NAZI [] super-scientists like Wernher von Braun, who single-handedly built the US space program when we couldn't get even a mouse into space without blowing up on the pad! And don't you believe those who would cast aspersions on his character! He used concentration camp slave labor to build his V1s & V2s that he blew up innocent Londoners with!

If you're looking to beef up your intelligence services, Reinhard Gehlen is the NAZI [] for you! He's the NAZI [] that can make those commie bastards talk! He comes with a vast cache of intelligence documents on the USSR compilled by the pain-staking tourture and interrogation of red commie-bastard prisoners. Why do your own legwork when it's already been done for you?!! This man would be a great addition to any spy agency, and a sterling influence upon your junior agents!

If you're a US presidential candidate, and want to ensure that you crush your ineffectual, peanut-farming Democratic competitor, Heinrich Rupp is the NAZI [] for you! With strong ties to the Arab community, he can manage complex three-cornered schemes that will ensure that those hostages aren't released while there's a Democrat in the Oval Office. As a bonus, you can use the proceeds to fund anti-communist fascists in Central America.

We also have such all-stars as Arthur Rudolph, Kurt Blome, Walter Schreiber and Licio Gelli! We have everything you need to build an enlightened, democratic new world order [] ! So hurry on down to crazy uncle Sam's before all of our NAZI [] s are gone!

(One of our most notorious NAZI [] s now works for Microsoft [] where he continues to commit crimes against humanity.)

Re:♬ First musical post! ♫ (-1)

L0rdkariya (562469) | more than 12 years ago | (#3762595)

And a fine Troll Tuesday to you, sir.

Operating Systems (-1, Redundant)

Anonymous Coward | more than 12 years ago | (#3762387)

Sorry but .NET is NOT an operating system.

Jeez... if you are going to make fun of something, at least you should learn about it first.

Re:Operating Systems (-1, Offtopic)

Anonymous Coward | more than 12 years ago | (#3762486)

At least you should read carefully before posting this stupid comment!

Re:Operating Systems (2, Interesting)

queh (538682) | more than 12 years ago | (#3762514)

Define operating system. Don't mix it up with boot loaders or kernels. Now explain how Microsoft's .NET isn't an operating system.

.NET is a code interface for M$'s new runtime (0)

Anonymous Coward | more than 12 years ago | (#3762565)

M$'s new runtime being CLR (Common Language Runtime, or something like that)

.NET is NOT an Operating System.

Re:Operating Systems (0)

Anonymous Coward | more than 12 years ago | (#3762573)

Yessir it is. .NET is a blanket term for everything MS is coming out with these days, including the upcoming successor to Win2k, the .NET Server range.

Re:Operating Systems (1)

Shalda (560388) | more than 12 years ago | (#3762905)

.NET is (for purposes here) a runtime environment/API. It's predicated upon Microsoft Intermediate Language (MSIL): basically, code that's easily compiled for a specific CPU or Operating system. The whole system is based upon a Just-In-Time compiler. It's all compiled to native code and executed as a normal program.

As for whether or not this constitutes an Operating System, that's a little vague. It does provide some memory management functions (garbage collection), but it certainly doesn't do a lot of OS type things (device drivers, file systems). An operating system is many things, and .NET is just a small but growing part of the Windows(tm) operating system.

Re:Operating Systems (0)

TweeKinDaBahx (583007) | more than 12 years ago | (#3762519)

Well, not yet at least.

Lets remember, XP is kinda like ME in the sense that it's just an interface update. The actual OS behind XP is essentially just Win2k. 'Whistler' AKA .NET is still in the works.

I'm actually interested in seeing what it's like, in all seriousness, I've heard M$ programmers refer to it as MS UNIX. I can only imagine what that means...

Re:Operating Systems (2, Interesting)

Tikiman (468059) | more than 12 years ago | (#3762623)

I don't think you read the quote correctly:

Emulators use virtual machines, operating systems use virtual machines (Microsoft's .NET), and programming languages use virtual machines (Perl, Java)".

Microsoft's .NET is an example of a virtual machine used by a particular operating system - there are no claims that .NET is an operating system by itself. Similarly, the Perl and Java programing languages have been implemented on virtual machines - the JVM, and the stack-based (soon to be register-based) Perl virtual machine.

A replacement for C (-1, Troll)

Anonymous Coward | more than 12 years ago | (#3762389)

I'm a first year programming student at an Ivy League school and I've just finished my Visual Basic classes. This term I'll be moving onto C++. However I've noticed some issues with C++ that I'd like to discuss with the rest of the programming community. Please do not think of me as being technically ignorant. In addition to VB, I am very skilled at HTML programming, one of the most challenging languages out there!

C++ is based on a concept known as Object Oriented Programming. In this style of programming (also known as OOPS in the coding community) a programmer builds "objects" or "glasses" out of his code, and then manipulates these "glasses". Since I'm assuming that you, dear reader, are as skilled at programming as I am, I'll skip further explanation of these "glasses".

Please allow me to make a brief aside here and discuss the origins C++ for a moment. My research shows that this language is one of the oldest languages in existance, pre-dating even assembly! It was created in the early 70s when AT&T began looking for a new language to write BSD, its Unix Operation System (later on, other companies would "borrow" the BSD source code to build both Solaris and Linux!) Interestingly, the name C++ is a pun by the creator of the language. When the first beta was released, it was remarked that the language would be graded as a C+, because of how hideously complex and unwieldy it was. The extra plus was tacked on during a later release when some of these issues were fixed. The language would still be graded a C, but it was the highest C possible! Truly a clever name for this language.

Back to the topic on hand, I feel that C++ - despite its flaws - has been a very valuable tool to the world of computers. Unfortunately its starting to show its age, and I feel that it should be retired as COBOL, ADA and Smalltalk seem to have been. Recently I've become aquainted with another language that's quite recently been developed. Its one that promises to greatly simplify programming. This new language is called C.

Although syntactically borrowing a great deal from its predecessor C++, C greatly simplifies things (thus its name, which hints at its simpler nature by striping off the klunky double-pluses.) Its biggest strength is that it abandons an OOPS-style of programming. No more awkward "objects" or "glasses". Instead C uses what are called structs. Vaguely similiar to a C++ "glass", a struct does away with anachronisms like inheiritance, namespaces and the whole private/public/protected/friend access issues of its variables and routines. By freeing the programmer from the requirement to juggle all these issues, the coder can focus on implementing his algorithm and rapidly developing his application.

While C lacks the speed and robustness of C++, I think these are petty issues. Given the speed of modern computers, the relative sluggishness of C shouldn't be an issue. Robustness and stability will occur as C becomes more pervasive amongst the programming community and it becomes more fine-tuned. Eventually C should have stablity rivalling that of C++.

I'm hoping to see C adopted as the de facto standard of programming. Based on what I've learned of this language, the future seems very bright indeed for C! Eventually, many years from now, perhaps we'll even see an operating system coded in this langauage.

Thank you for your time. Your feedback is greatly appreciated.

Re:A replacement for C (-1)

boltar (263391) | more than 12 years ago | (#3762445)

You or someone else posted this the other week and it wasn't exactly hilarious then.

Re:A replacement for C (2)

smagoun (546733) | more than 12 years ago | (#3762468)

Dear sir, That was one of the most informative posts I have seen on Slashdot in a long time, perhaps since the days of TheGloriousMeept! It truly captures the spirit of discussion. Thank you again kind sir, me

So what moderator is hooking you up today? (-1, Offtopic)

Anonymous Coward | more than 12 years ago | (#3762677)


Re:So what moderator is hooking you up today? (0)

Anonymous Coward | more than 12 years ago | (#3762704)

I wish I knew. I fucked up the formatting and forgot to check "post anonymously".

I rule.


Anonymous Coward | more than 12 years ago | (#3762587)

Where did you come up with all this nonsense ? There isn't almost one
bit of correct information in what you write. You learn how to
research because what you did is not one.

Let me help strate up some facts:
Object Oriented Programming = OOP not OOPS.
Object types are called classes not "glasses"
The language that was developed at the 70's was C which is a
procedural language, OOP is a more recent concept of programming
(which in the case of C++ was developed at the beginning of the 80's
by Bjarne Stroustrup - NOT Microsoft). (BTW, VB is supposed to be OO
language (object oriented) but it isn't fully since it doesn't have
inheritance in it).
C is compiled to a much faster code (since it is much closer to
machine code than C++).
The name C and/or C++ has nothing to do with grading the language.
C/C++ flaws are compiler flaws - not the language's, and speaking of
flaws, lets not start with the ones inside Microsoft's compilers...
C++ is a very good language - but like any other language you should
know to what purposes it is fits best.
Assembly is the most basic computer language (beside the actuall
machine code) a person can use - it is almost direcly translated into
machine code, hence it is technically the earliest computer language.
C (not C++) was developed in order to write out the first UNIX
operating systems, many of today's operating systems are written in C,
and some are beginning to adopt also some C++. For example, if any one
would like the source code of the Linux operating system (which is
mainly written using C) can be obtaind easily.

Next time before you write stupid things check out the real facts, and
this is without even getting into all the advatages OOP has over
regular procedural programming, and the advantages C++ has over many
other computer languages.

YHBT. YHL. HAND. (-1, Offtopic)

Anonymous Coward | more than 12 years ago | (#3762604)


YHBT. YHL. HAND. (-1, Offtopic)

Anonymous Coward | more than 12 years ago | (#3762612)

No, im sorry you have been the one trolled.


Anonymous Coward | more than 12 years ago | (#3762634)

No way, you've just been trolled.

Re:YHBT. YHL. HAND. (-1, Offtopic)

Anonymous Coward | more than 12 years ago | (#3762639)

You've been trolled times infinity

PuNK!# (0)

Anonymous Coward | more than 12 years ago | (#3762729)

for(;;){cout"YHBT. YHL. HAND."endl;}

What language? (0)

Anonymous Coward | more than 12 years ago | (#3762804)

What language is that written in, Visual Basic gave me a compile error

But not as stupid as you are (-1, Offtopic)

Anonymous Coward | more than 12 years ago | (#3762610)



Anonymous Coward | more than 12 years ago | (#3762697)

Don't be so sure (0)

Anonymous Coward | more than 12 years ago | (#3762756)

Never overestimate the intelligence of a slashbot.


Anonymous Coward | more than 12 years ago | (#3762618)

Please don't feed the trolls.


Anonymous Coward | more than 12 years ago | (#3762661)

Re:A replacement for C (-1, Offtopic)

Anonymous Coward | more than 12 years ago | (#3762605)

I have 2 things against this post:
  1. It's old, we've seen it before
  2. You don't give proper credit to the originating troll
  3. It might have been kind of funny the first time, but it's not anymore.
(oops make that three)

Re:A replacement for C (-1)

neal n bob (531011) | more than 12 years ago | (#3762638)

this belongs to egg troll i believe - and it is funny every single time.

UML is dying (-1, Offtopic)

Big Dogs Cock (539391) | more than 12 years ago | (#3762396)

Despite the popularity of tools such as Together Control Center and Rational Rose, it is clear the UML is dying. Despite the bloat which occured between versions 1.2 and 1.4, the "language" is still incomplete in many places whilst still containing multiple notations in others.

UML will never be able to implement the feature sets which are vital to modern programming. These include multiple thread representation (which can be done clumsily using coloured sequence diagrams) and multiple view representation (such as the private and remote interfaces to an EJB). Even Peter Coad's group admit this [] .

The promise of the so-called "unified" modelling language has led to individual developers adding their own ad-hoc notations for the missing concepts - or, in many cases, abandoning UML altogether in favour of a home-grown notation. UML needs to be scrapped and replaced with a notation which is capable of representing the concepts which affect software developers today.

Re:UML is dying (-1)

boltar (263391) | more than 12 years ago | (#3762463)

Fascinating, but , uh , whats that got to do with VM implementation?

Re:UML is dying (0)

Anonymous Coward | more than 12 years ago | (#3762649)

You need UML to design a VM. IF UML dies, all VMs die as well.

♬ Fifth post also musical ..? ♪ (-1)

Mr F J Musical-Troll (582606) | more than 12 years ago | (#3762401)

Yes? No? []

Wouldn't this lead us to... (1)

dmarien (523922) | more than 12 years ago | (#3762410)

Mainstream operating systems which drop support [] for the virtual machines?

Re:Wouldn't this lead us to... (-1, Offtopic)

yatest5 (455123) | more than 12 years ago | (#3762561)

Mainstream operating systems which drop support [] for the virtual machines?

Yay! First off-topic anti-MS post - mod this up!!!

Re:Wouldn't this lead us to... (0)

Anonymous Coward | more than 12 years ago | (#3762617)

This post was neither off-topic, nor anti-MS.

Virtual Machine (2, Interesting)

JohnHegarty (453016) | more than 12 years ago | (#3762411)

Can anyone give me a substantial difference between a virtual machine, and an emulator...

because I can't see whats different between my mame and java virutal machine...

Re:Virtual Machine (1, Informative)

Anonymous Coward | more than 12 years ago | (#3762449)

a vm passes appropriate instructions directly to the CPU, while an emulator simulates each and every instruction.

this is why (in Java, and VMWare) it's a VM, not an emulator.

Re:Virtual Machine (3, Informative)

Wolfier (94144) | more than 12 years ago | (#3762472)

An emulator is a virtual machine with a pre-existing non-virtual counterpart.

Re:Virtual Machine (4, Interesting)

Anonymous Coward | more than 12 years ago | (#3762496)

An emulator is a specific type of virtual machine. VMs don't necessarily reproduce a real machine, while emulators do. Also, many emulators reproduce the original machine down to the timing of instructions.

For example, some of the nuclear power plants here in Canada are using or switching over to an emulator to run the plants because they are running out of spare parts for their 1972 control machines. Without the use of an emulator, they'd each have to rewrite shelves and shelves of assembler code.

You can imagine that some of the code is timing critical, so the emulator must be exact down to the timing.

Re:Virtual Machine (0, Informative)

boltar (263391) | more than 12 years ago | (#3762497)

An emulator simulates an entire machine in that it displays the virtual screen in a window, does the I/O etc. A VM merely simulates a ficticious architecture just enough to be able to get a
program running on the host system.

Re:Virtual Machine (5, Informative)

ranulf (182665) | more than 12 years ago | (#3762569)

Yeah, they're basically the same, but the distinction is fundamentally on the original intention.

A virtual machine is designed specifically to be general and run in different environments, whereas an emulator is designed to emulate the environment of some existing hardware or software to trick software into beleiving that it genuinely is running on the original device.

So, whereas a virtual machine will have a fairly abstract policy towards doing things (compare Java's AWT - I'd like to open a window, I'd like a button here, I'd like a menu there) and an emulator will get really bogged down emualting details, e.g. memory address $DFF180 changes the background colour.

Both can be easily emulated by a state machine (hence why they come up in this book), however virtual machines can be made more efficient as they are intentionally abstract. e.g. in the JVM, you know what is code and what isn't, so you can translate blocks of code into native machine code and run that directly instead of interpreting every instruction. If you try that with an emulator, you'll come unstuck when you come across self-modifying code, or things that access memory mapped registers (e.g. on a 68000 the instruction mov d0,4(a0) offers no clue as to whether the write is to hardware or memory.

Generally, you'll find that most virtual machine designs aim to reduce the instruction set down to a bare minimum. This allows a virtual machine (if it chooses) to effectively re-build the original parse tree and generate native code. However, emulators are generally trying to emulate CISC processors where as much is squashed into an instruction set as possible. Similarly, most virtual machines are heavily stack based, so as not to make any assumptions about register availability.

Re:Virtual Machine (2)

JCCyC (179760) | more than 12 years ago | (#3762710)

(...) virtual machines can be made more efficient as they are intentionally abstract. e.g. in the JVM, you know what is code and what isn't, so you can translate blocks of code into native machine code and run that directly instead of interpreting every instruction.

Isn't that called JIT? Also, if I remember correctly, didn't the first version of Java come without this? (and were therefore unspeakably slow?)

Re:Virtual Machine (2, Informative)

Java Pimp (98454) | more than 12 years ago | (#3762838)

Sort of...

A Just in Time compiler will compile all the byte code to native code before it is executed and run it on the hardware. Performance hit at the start of each execution but ultimately faster than interpreting byte code. Note that the JIT is probably not the best optimizer so it still won't be as efficient as platform specific binaries. (among other reasons...)

An optimized VM will recognize instructions or code sequences within the bytecode that can be directly mapped to native code and execute it directly on the hardware. Not as fast as JIT but faster than interpreting everything.

Both are still slower than platform specific binaries but that's just the nature of the beast.

Pipelining the KVM (2, Informative)

BobLenon (67838) | more than 12 years ago | (#3762836)

Yea, so for a class project we took the kvm and (Java VM for embeded devices), and turned it into a pipelined architecture. It was very educational, but the practicality is lacking ... You at least need a 4 proc machine to be useful, as it was a simple 4-stage. But the speed was soo lacking.

It was worthwile experience, though I do wish java was reg based. ;) .... as it was only a learning experince no big deal. By the end i could've written my java in assembly ;)

C: A Dead Language? (-1, Troll)

Anonymous Coward | more than 12 years ago | (#3762412)

Gentlemen, the time has come for a serious discussion on whether or not to continue using C for serious programming projects. As I will explain, I feel that C needs to be retired, much the same way that Fortran, Cobol and Perl have been. Furthermore, allow me to be so bold as to suggest a superior replacement to this outdated language.

To give you a little background on this subject, I was recently asked to develop a client/server project on a Unix platform for a Fortune 500 company. While I've never coded in C before I have coded in VB for fifteen years, and in Java for over ten, I was stunned to see how poorly C fared compared to these two, more low-level languages.

C's biggest difficulty, as we all know, is the fact that it is by far one of the slowest languages in existance, especially when compared to more modern languages such as Java and C#. Although the reasons for this are varied, the main reasons seems to be the way C requires a programmer to laboriously work with chunks of memory.

Requiring a programmer to manipulate blocks of memory is a tedious way to program. This was satisfactory back in the early days of coding, but then again, so were punchcards. By using what are called "pointers" a C programmer is basically requiring the computer to do three sets of work rather than one. The first time requires the computer to duplicate whatever is stored in the memory space "pointed to" by the pointer. The second time requires it to perform the needed operation on this space. Finally the computer must delete the duplicate set and set the values of the original accordingly.

Clearly this is a horrendous use of resources and the chief reason why C is so slow. When one looks at a more modern (and a more serious) programming language like Java, C# or - even better - Visual Basic that lacks such archaic coding styles, one will also note a serious speed increase over C.

So what does this mean for the programming community? I think clearly that C needs to be abandonded. There are two candidates that would be a suitable replacement for it. Those are Java and Visual Basic.

Having programmed in both for many years, I believe that VB has the edge. Not only is it slightly faster than Java its also much easier to code in. I found C to be confusing, frightening and intimidating with its non-GUI-based coding style. Furthermore, I like to see the source code of the projects I work with. Java's source seems to be under the monopolistic thumb of Sun much the way that GCC is obscured from us by the marketing people at the FSF. Microsoft's "shared source" under which Visual Basic is released definately seems to be the most fair and reasonable of all the licenses in existance, with none of the harsh restrictions of the BSD license. It also lacks the GPLs requirement that anything coded with its tools becomes property of the FSF.

I hope to see a switch to VB very soon. I've already spoken with various luminaries in the *nix coding world and most are eager to begin to transition. Having just gotten off the phone with Mr. Alan Cox, I can say that he is quite thrilled with the speed increases that will occur when the Linux kernel is completely rewritten in Visual Basic. Richard Stallman plans to support this, and hopes that the great Swede himself, Linux Torvaldis, won't object to renaming Linux to VB/Linux. Although not a C coder himself, I'm told that Slashdot's very own Admiral Taco will support this on his web site. Finally, Dennis Ritchie is excited about the switch!

Thank you for your time. Happy coding.

thank you! (2, Interesting)

jeffy124 (453342) | more than 12 years ago | (#3762423)

I must say I'm pleased to hear about this book. I actually would like to do something with VMs in my upcoming academic life (read: grad school), but am having trouble getting started, nor am sure if this is what i want to study. Every search engine out there returns everything Java for the phrase "virtual machine," which is not exactly what I'm looking for.

How to use Google (1, Informative)

Anonymous Coward | more than 12 years ago | (#3762493)

So you want more info on searching on virtual machines on Google, not using Java ?

Search on : "virtual machine -java"

It's simple & off topic.


Re:How to use Google (1)

jeffy124 (453342) | more than 12 years ago | (#3762549)

yes, I'm aware of how to exclude certain tokens from a google search. Unfortunately, one mention of the word "java" in a document (like the review above, or the book's webpage), and the page is eliminated from the result set, leaving behind very little to work with.

I want to run a virtual Machine (2, Funny)

TheDick (453572) | more than 12 years ago | (#3762429)

Inside my virtual machine, where then I can run some sort of virtual reality program where I can interface with Eliza.

OT: Perl Virtual Machine? (-1, Offtopic)

TheFlyingGoat (161967) | more than 12 years ago | (#3762446)

I was under the impression that Perl is compiled at runtime to machine code, not for a virtual machine. Am I completely off the mark?

Slightly more on topic, the idea of a vm for C/C++ is great, but isn't this going to become outdated once (if) .NET and its open source counterparts catch on?

Re:OT: Perl Virtual Machine? (0)

Anonymous Coward | more than 12 years ago | (#3762477)

C/C++ (for use in enterprise apps) is already being outdated because of Java. .NET (and it's oss clones) is really just a mocking of Java and the J2EE.

also, perl is a VM. It compiles into bytecode, then executes the bytecode. Perl 6 is actually supposed to be able to compile Java .class files, allowing you to throw the .class files into a JVM like it were a Java program, and allowing easy interfacing with a Java program.

Re:OT: Perl Virtual Machine? (0)

Anonymous Coward | more than 12 years ago | (#3762516)

Slightly more on topic, the idea of a vm for C/C++ is great, but isn't this going to become outdated once (if) .NET and its open source counterparts catch on?

Um, no. It is an implementation written in c/c++ (as opposed to Fortran for instance...) not a VM for c/c++.

Re:OT: Perl Virtual Machine? (-1)

Anonymous Coward | more than 12 years ago | (#3762594)

Is c/c++ some new programming language?

Re:OT: Perl Virtual Machine? (0)

TweeKinDaBahx (583007) | more than 12 years ago | (#3762552)

Isn't perl technically an interperted language like basic?

I'm not trying to troll, but I guess I should have stayed awake in my CS class because i was under the impression the 'scripting' languages were not compiled.

I guess that would be why it runs on a virtual machine, if I'm right (and I think i may be way outta whack).

Someone throw me a bone here.

Re:OT: Perl Virtual Machine? (2)

cxreg (44671) | more than 12 years ago | (#3762641)

Perl is a hybrid. It's interpreted at run-time like a scripting language, but before execution, it's pre-compiled to a VM-like bytecode. The idea is to get the best of all worlds. Things like mod_perl benefit from this a lot by only having to compile once but running many times.

Re:OT: Perl Virtual Machine? (0)

Anonymous Coward | more than 12 years ago | (#3762562)

Perl 6 is supposed to be compiled to Parrot instead of machine code.

Re:OT: Perl Virtual Machine? (1)

god (5628) | more than 12 years ago | (#3762923)

We might as well get the terminology right. Perl 5 compiles the source code at compile time (at sometimes at runtime for eval STRING) into opcodes for the terribly-undocumented and very-well-hidden Perl 5 virtual machine. You just don't notice it 'cos it compiles it and runs it in one step.

Perl 6 (not finished yet) aims to seperate the virtual machine ( from rest of the language.

Hopefully this clears things up.

Alternate titles (3, Funny)

eyepeepackets (33477) | more than 12 years ago | (#3762447)

Some alternate titles for this tome might be:

1. Reversi: C64 Speed on a Pentium IV
2. Double Your Code, Halve Your Speed
3. Real Men Don't Use Real Computers
4. VM:Very Macho or Verily laMe
5. Atari ST Rebirth: a 20 Year Reversal

etc., etc.

Ack, I'm turning into a crank! Oy.

Re:Alternate titles (-1, Offtopic)

Anonymous Coward | more than 12 years ago | (#3762484)

will a moderator please troll that guy, thx

Re:Alternate titles (1)

IndependentVik (582582) | more than 12 years ago | (#3762615)

Why should he be marked as a troll? I don't necessarily agree with him, but I certainly thought his post was funny. Just b/c you have a VM fetish is no reason penalize the guy.

Re:Alternate titles (1, Insightful)

Anonymous Coward | more than 12 years ago | (#3762547)

You forgot:

Maintainable code
Faster time to market
Minimum breakage during enhancements
Ability to easily port to other platforms

If you owned a software business would these things be important to you? I don't think performance would be the primary concern.

Another use (5, Interesting)

Erbo (384) | more than 12 years ago | (#3762599)

Another thing virtual machines have historically been used for is to assist in the development of new computers, by creating a perfect model of the new computer's hardware in software, so the microcode authors (and maybe the OS authors, too) can get their code working before the hardware's completely debugged. In this guise they're called "simulators," and there was mention of them in Tracy Kidder's seminal work The Soul of A New Machine. As the book says, "A simulator makes a slow computer, but a fast tool."

Also, don't forget the UCSD P-System, which used a virtual machine to run code compiled in that environment. I know of at least one commercial product that used the P-System; I believe there were many.

Virtual machines have been around awhile; they're an interesting field, made newly relevant by the ascendancy of environments such as Java and the MS CLR. I just wish I had a good excuse to drop $50 on this book...:-)


A crank eater... (0)

Anonymous Coward | more than 12 years ago | (#3762739)


Dirty yenta (-1)

Ralph JewHater Nader (450769) | more than 12 years ago | (#3762455)

Woot! []

Re:Dirty yenta (-1)

Thud457 (234763) | more than 12 years ago | (#3762548)

Insulting her royal highness!
You're treading on dangerous ground there, R(jh)N. If you're not careful, you could lose your mandate from teh troll masses.

weee (0)

TweeKinDaBahx (583007) | more than 12 years ago | (#3762457)

virtual machines are leet because you can test your virus code without actually damaging your own system. Unless you're clueless, in which case you'll probably infect yourself and the rest of the internet and get ass raped in prison.

waste of time (-1)

neal n bob (531011) | more than 12 years ago | (#3762461)

why not review a relevant book - something about C# perhaps.

Why *virtual* machines? (3, Interesting)

Anonymous Coward | more than 12 years ago | (#3762465)

One of the things that has surprised me about virtual machines ever since Java became a buzzword was that no one had ever thought to eliminate the relative performance penalty by implementing the VM as hardware on a PCI card (or a licensed chipset to put on the mobo. I can understand the portability implications of using VM's, and I'm glad that much work is being developed in this area.

My question to anyone qualified to comment: Is there a reason why these virtual machines aren't taken as a blueprint for real hardware and implemented as such? I can imagine real performance benefits happening with such an idea...

Re:Why *virtual* machines? (3, Informative)

JohnnyCannuk (19863) | more than 12 years ago | (#3762508)

Zuccotto and a few other companies have done just that...the JVM is an actual hardware chip. There were at least 5 companies doing the same at Java One

Re:Why *virtual* machines? (-1)

boltar (263391) | more than 12 years ago | (#3762517)

Sun tried it with the java chip, it was a market flop. Besides , the whole point of VMs is to
allow cross platform programs. Having to buy specific hardware to run these programs turns the
whole idea on its head and makes it utterly pointless.

Re:Why *virtual* machines? (-1)

Big Dogs Cock (539391) | more than 12 years ago | (#3762803)

Cross-platform? Like the .NET VM then. It does run on a range of Microsoft operating systems.

Re:Why *virtual* machines? (0)

Anonymous Coward | more than 12 years ago | (#3762558)

Hardware based VMs? Transmeta makes them (you know, Linus's employer).

Re:Why *virtual* machines? (1)

stackdump (553408) | more than 12 years ago | (#3762679)

Hardware virtual machine, doesnt that defeat the purpose. I mean wasn't the whole concept developed so that the sofware could be MACHINE INDEPENDANT.

It seems to me that the only application of such a piece of hardware was when you want to use code written in a certain language exclusively , like that semi-new Sharp pda with a linux based Java VM.

Re:Why *virtual* machines? (1)

timeOday (582209) | more than 12 years ago | (#3762799)

Oh, certainly.

X86 was originally just a vertual machine, but as slow as Bochs is, you can imagine that on a VAX. So eventually they broke down and came out with the 8088.

The downside of virtual machines (1)

PhysicsGenius (565228) | more than 12 years ago | (#3762502)

At the lab, we do simulations of nuclear bomb explosions, particle interactions, etc all the time. The "virtual events" are critical in making sure our equations are accurate and save a lot of resources and money vs actually exploding a bomb. However, keep in mind that the simulation is only as accurate as our knowledge of it. We don't actually gain new information from the simulation (new insight, yes, new information no).

The same is true of virtual machines. Simulating how a computer might react to certain error codes and so forth is all right in small doses, but the only way to get real data is go out there and buy some actual hardware.

Just my $.02.

Re:The downside of virtual machines (-1)

Fucky the troll (528068) | more than 12 years ago | (#3762538)

It's a shame those nuclear explosions are only simulations.

Re:The downside of virtual machines (-1, Offtopic)

Anonymous Coward | more than 12 years ago | (#3762586)

You're continuing trollage shows a dedication that few have.

Re:The downside of virtual machines (2)

proj_2501 (78149) | more than 12 years ago | (#3762602)

I think you may have missed the point a little. Virtual machines are not necessarily used to simulate hardware. (Although they can be used for that. The N64 dev kit was an SGI Onyx running an emulator, IIRC)

Plus, digital circuits are a little less complicated and better understood than nuclear explosions and particle interactions.

Implementation of the Icon Programming Language (2, Informative)

Anonymous Coward | more than 12 years ago | (#3762532)

The Implementation of the Icon Programming Language

This book describes the implementation of Icon in detail. Highlights include:

* Icon's virtual machine
* the interpreter for the virtual machine
* generators and goal-directed evaluation
* data representation
* string manipulation
* structures
* memory management

Information on the Icon programming language itself can be found at

Re:Implementation of the Icon Programming Language (-1, Offtopic)

Anonymous Coward | more than 12 years ago | (#3762579)

whomever gave this guy an Informative, please go out back for a photo session []

umm (2)

selderrr (523988) | more than 12 years ago | (#3762541)

All of the code in this book is in C or C++, and nearly all of the code is talks about is actually printed on the right pages in the book. No more flipping between code on your computer and the book, it's all just where it should be!

Practically all coding books do this, and I mostly find it a cheap way to poop out thick books and massive volumes... Not a measure of quality in any way.

Re:umm (0)

TweeKinDaBahx (583007) | more than 12 years ago | (#3762584)

Unless you're trying to learn how to code, in which case a lot of well documented code in a book such as this one can make all the difference.

Not like my CS text, which promptly introduced such concepts as templates before anyone in the class could even use a class in C++...

Ah well, I like code in books, that way I can compare my code to someone elses without having to use another terminal (ALT+F* baby)

Take a Further look at this! (4, Interesting)

idfrsr (560314) | more than 12 years ago | (#3762567)

I program in Java mostly right now, and so when people begin the usual 'vm is slow' crank I am curious about what they exactly mean.

Programs written to run on vm's can be significantly slower due to the extra layer. Yet, if the design of the vm is done well enough (by perhaps reading this tome?) then the vm should be comparable. Certainly C is faster generally than an interpreted language. But there are native compilers out there than provide very comparable results, and the advantage of a language that forces careful programing. Here is the slashdot link []

If adding layers to programs automatically makes them slower, and so slow that they are useless, we all would code in assembly.

Good design is important. A badly written C program of which there are thousands, will be just as slow (read bad) as a badly written vm program.

Re:Take a Further look at this! (-1)

boltar (263391) | more than 12 years ago | (#3762588)

Whatever you want to call a VM , ultimately it is an assembler interpreter. And hence slower than
running a native binary. A badly written C program will probably still be faster (all other things
being equal) than a badly written Java program for this reason.

Re:Take a Further look at this! (1)

shadow303 (446306) | more than 12 years ago | (#3762783)

Although bad C can be as bad as bad vm programs, good C is better than good vm programs. Sure native compilation helps, but that is moving away from a true vm. As far as languages that force careful programming, that isn't relevant to since there is nothing stopping you from making a such a language that gets compiled to native code.
That said, I think that vm's are becoming more and more viable now that computers are becoming so blazing fast. It is getting so the overhead doesn't matter so much for things like office apps or simpler games (of course the games will likely always lag behind the cutting edge of the time). There was a time when many things were written in assembler since it was faster than C, but as machines grew more powerful, and compilers improved, the added speed just wasn't worth the effort any more.

Why are current VMs preoccupied with GC? (1, Interesting)

Anonymous Coward | more than 12 years ago | (#3762576)

It seems that everyone assumes that VMs these days (JVM, CLR, Mono, Parrot) must include garbage collection and not use pointer-based ops. Why is that? Knuth's MMIX VM is modelled after a traditional RISC CPU which modern compilers like GCC can target. C, C++, FORTH, Objective C can be targetted toward it out of the box.
I think that VMs these days are getting bloated with everything including the kitchen sink. This makes them harder to port and test. Performance suffers. What ever happened to keep it simple stupid?

Re:Why are current VMs preoccupied with GC? (1)

Tune (17738) | more than 12 years ago | (#3762701)

Good point. ' Guess that answers the question [] about the subtle difference between an emulator and a VM. VMs tend to include more high level concepts than emulators.

Still, as much as (software) emulators emulate existing hardware there have also been several attempts to create "virtual" machines in hardware. (For example: P-code interpreters (low-level Pascal) and Sun's attempts to hard wire a Java VM.)

Re:Why are current VMs preoccupied with GC? (0)

Anonymous Coward | more than 12 years ago | (#3762834)

It seems that everyone assumes that VMs these days (JVM, CLR, Mono, Parrot) must include garbage collection and not use pointer-based ops.

What ? Both CLR and Mono allow you to use pointers, how do you think C++ could be run on CLR if it didn't support raw pointers ?

Low-resolution thread concurrency? (4, Interesting)

magi (91730) | more than 12 years ago | (#3762601)

Are there any VMs currently, for Java, Python or some other language, that can execute each thread one VM instruction at a time?

It would also be nice to have language-level support for parallel processing, like in Occam.

For example, in a Python implementation, the following code would execute the two for-statements in the "par"-block in parallel:

for a in range (0, 3):
print "a = %d" % (a)
for b in range (0, 3):
print "b = %d" % (b)

As the two threads would be executed exactly at the same speed, the output would be:

a = 0
b = 0
a = 1
b = 1
a = 2
b = 2

Re:Low-resolution thread concurrency? (2, Interesting)

Anonymous Coward | more than 12 years ago | (#3762627)

You're assuming print is atomic.
The output would more likely be:

a =b 0
a= 0
b= =1
b =
= 2

Occam is an interesting language, but I think it has a too restrictive view. No global variables, no mutexes, everything uses channels - even shutting down a multithreaded Occam program is a major pain in the ass - message passing nightmare.

Re:Low-resolution thread concurrency? (2, Informative)

Anonymous Coward | more than 12 years ago | (#3762685)

While I'm sure someone could write a VM that did that, I don't think anyone would want to use it. On an x86, a context switch costs enough that one instruction per context switch would give you a bit more than 95% overhead lost on context switching. This means your programs would run at 1/20th speed at best.

Sad news ... Stephen King dead at 54 (-1, Troll)

Anonymous Coward | more than 12 years ago | (#3762630)

I just heard some sad news on talk radio - Horror/Sci Fi writer Stephen King was found dead in his Maine home this morning. There weren't any more details. I'm sure everyone in the Slashdot community will miss him - even if you didn't enjoy his work, there's no denying his contributions to popular culture. First Ann Landers, now this. Truly an American icon.

Chips are virtual machines (0)

Anonymous Coward | more than 12 years ago | (#3762700)

one slippery computer science concept that seems very hard for the vocationally inclined to understand is that hardware itself, processor chips, bitslice architectures, very long word, RISC, CISC, you name it, all of them, implement virtual machines! we don't "program the movement of electric fields and electrons". Rather, we code to the virtual machine that they implement.

and that's part of the reason that you should go to college and study CS rather than teaching yourself.

Mainframe mentality creeping back in (3, Insightful)

totallygeek (263191) | more than 12 years ago | (#3762719)

I for one am happy to see the influx of ideas that are representative of what mainframes and minicomputers of old were accomplishing. The use of virtual computers or machines along with centralized processing has been a welcome change from the mentality of the PC market for about the last 15 years.

People had said for a long time that personal computers connected to file servers was a lower-cost, better system. However, now many places are going to web-based or host-based connections because of buggy issues at the desktop and the unmanageability of the personal computer. Couple this with the fact that licensing manangement is such a bear and you see why us Unix folks are glad to see the turn-around.

Mainframes had been on their way out before the personal computer, in favor of smaller satellite processing via minicomputers. However, now people are realizing that virtual computers in a big iron case gives you a better managed array of computing power for multiple users or processes. I for one welcome this back, and hope that we will continue to see vitual computing take over the personal computer business market approach. Bring in the network computers!

Best non-stadard use for a vm? (1)

stevey (64018) | more than 12 years ago | (#3762721)

I'd like to nominate some software I wrote for the most random use of a virtual machine.

I was asked to code a registration routine for a piece of software - after getting the username + serial number from the user I would have typically done some magic to calculate a checksum from the name and see if it matched the given key.

Instead I wrote a small virtual machine which executed z80 machine code. The protection routine litererally started the VM - where all the magic happened. Each opcode was fetched decoded and executed. I think it would have been a real pain to decode ;)

(I guess the clever cracker could have disassembled my windows binary with a z80 disassembler and gotten lucky; but it would have been hard to see what was being executed - unless they could do clever things like disassemble z80 in their head...)

Readablilty for Non-CS majors? (-1)

Fuck You Faggot (560952) | more than 12 years ago | (#3762732)

I progressed a little along the cs curicula but have since changed my major to a non-technical one, however I still have an interest in vms and lower level architectural issues.

How readable is the book for someone whos taken basic courses like digital design (boolean algebra, k-maps, etc) and data structures(from linked lists thru trees and graphs)?

VMs in the OS (1)

miraj31415 (579016) | more than 12 years ago | (#3762754)

It seems to me that more and more languages nowadays are designed for a VM, thus adding a level in between the OS and the application. Of course, this leads to a slowdown because the JIT has to do its thing AND the compiled code that runs has to use system calls to do what it wants to. But has anybody given any thought to making a VM that runs almost on top of the hardware with almost no system calls? Perhaps the only interference the OS would make is scheduling and possibly memory management. This kind of approach (like the exokernel approach in the EROS [] project) would allow a VM to greatly speed up its resultant code because it would have almost direct control of the hardware, and the VM would be optimized for that hardware. I am working on an OS (Middle Earth OS [] ) that is looking into this kind of design, and would appreciate your input either here or in the project's forums as to whether you think this would work (well) or not.
Load More Comments
Slashdot Login

Need an Account?

Forgot your password?