Re: [Tutor] Virtual Machine Terminology

Magnus Lycka magnus at
Wed Apr 21 18:29:50 EDT 2004

Orbitz wrote:
> Python is a language.  A program written in Python is just a program.  A in
> python written with wxPython is just a program.  A virtual machine is what your
> python program will run in. It will interpret your python bytecode and offer
> your program an interface tothe actual machine.

Well, virtual machine is not the same thing as an interpreter, even if you 
might say that "virtual machine" is just a fancy name for an interpreter. :)

Vicki wrote:
> Is a BASH script which handles printing also then a virtual machine?

A bash script can't possibly be a virual machine, but the bash interpreter
is not a virual machine in the typical sense of the word either. The term 
virtual machine has been used for the Python interpreter, but the terminology 
isn't completely clear cut, see for instance:

When you write a program in e.g. C, you compile it into the machine language
of the hardware you intend to run the program on. This is a much lower level
language where you lack most of the abstractions of "normal" programming 
languages such as data types, loops etc. Here you shuffle individual bytes 
between various registers or memory locations, perform simple aritmetic and
logic operations, and do conditional jumps between memory addresses etc. Each
statement in C (or whatever) will typically translate into several machine
code statements.

This is the kind of instructions understood by the actual hardware you run
on, the CPU. (Actually, there might be something called microcode in the CPU
that interprets this, and that could be considered a kind of virtual machine
as well, Transmeta has driven this approach very far, but never mind that now.)

A Java program has to be compiled. The compiled java program consists of
something called bytecode. This is machine code for a Java CPU, just as the
code you get if you compile for a Pentium is machine code for a Intel Pentium.

While Java CPUs have been manufactured, they never became a big hit, since
Java turned out to be a programming language for normal computers, and not
for toasters as originally intended. ;)

So, the typical runtime environment for Java bytecode is not a Java chip, but
a program, a Java Virtual Machine (JVM), which behaves as if it was a Java CPU 
chip and translates the Java instructions into machine code for the real CPU 
that we are running the program on. This way you can compile Java programs once
and run them on many different hardware platforms. (At least in theory.)

Bash isn't like this at all. Bash interprets plain text, and runs different
routines based on how it interprets the text. Bash doesn't try to behave 
like a CPU at all.

Python is more like Java. When you run (or import) a Python module it is
compiled (if Python doesn't find an alreay compiled and uptodate .pyc or
.pyo file). The result of the compilation is called bytecode, just like in 
the case of Java, and it's not very different.

But python.exe *is* different from a JVM. First of all, Python bytecode
doesn't always look the same. You can't expect .pyc-files made under one
computer architecture to work on another computer architecture, it will
for instance look different on a 64 bit machine and on a 32 bit machine.

Secondly, the Python interpreter (or PVM) doesn't quite pretend to be 
a machine of its own the way Java does. It doesn't shield you from the 
surrounding operating system. A Python program can interact with the 
surrounding computer platform, and access native machine code programs 
on the current platform in a way Java programs can't. The PVM is not 
the kind of isolated island that the JVM is.

It seems the concept of virtual machines have confused people before.
See for instance (note the answer for the second question :).

Microsofts .NET environment contains a Virtual Machine called Common
Language Runtime (CLR), and C#, VB.NET, COBOL.NET etc all compile to 
CLR bytecode.

The Perl developers are constructing a Virtual Machine for the upcoming 
Perl version 6, which is called Parrot. (The name actually started as an 
April's fool's joke about a merger between Python and Perl.) The Parrot 
developers seems convinced that the Parrot Virtual Machine will be able 
to run Python programs faster than the Python interpreter, but few Python 
developers seem to believe that. We'll see during OSCON this summer when 
the Pie-Thon competition will take place. Either way, we win! :)

Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65  mailto:magnus at

More information about the Tutor mailing list