What is the concept of virtual machine? What are the positives and negatives?

Asked

Viewed 295 times

1

I would like a purchase of a language that uses virtual machine and one that does not use.

  • To manieiro’s answer translates well what a virtual machine is. Nowadays, there is a lot of talk about containers, something worth you searching for. I usually summarize and VM in the following. If you need a laboratory to do some experiments, a VM is an excellent choice. Now for example, if Voce needs to use Windows and Linux on the same computer, using a VM for this purpose would not be interesting, for performance reasons. A dual boot in this second case would be more efficient.

1 answer

5


I will respond with application VM bias and ignore other types.

Virtual machine is a simulation of a real machine through software. Therefore a software is created that will run on the real machine (technically it could run on top of another virtual machine, but it makes little sense) as a normal application, and its function is to reproduce the characteristics of a real machine to run a code from another application. In some cases it’s just an intermediate step.

The virtual machine usually has a own assembly language as a processor has, and its applications are ultimately written in this language, but of course the source of the code may be in other languages. Usually the source code is compiled for this assembly before or during execution.

Some machines interpret this assembly and run in a loop deciding what to run in a huge switch with each instruction. Others use one Jitter which transform this assembly into the assembly of the physical processor it is running on (which will become machine code) or even direct machine code from it, the most common.

It is possible in some cases to have a virtual machine that takes place an interpretation where all translation takes place as it goes running. Or you might even have some VM that doesn’t have this whole process and only serves for greater application access control, so it can use the processor’s own assembly. But they are very unusual implementations.

Perks

  • The biggest advantage is the physical platform independence. In general it abstracts everything and becomes the platform where you program. It’s her problem how to make it run well on the physical platform and her way of programming is just to make her code according to the VM without worrying if it’s running on x86, x64, ARM, Windows, Linux, iOS, Android, etc. This may include greater ease by having simpler-to-use Apis.
  • Another great advantage is having a control over the execution that can limit what the application can access from the actual platform such as: having managed memory, having other controls, or having the code signed. Gives more security and robustness and can run even as part of other applications. And in this controlled environment it can be easier to run certain control, debugging, flexibility and analysis tools. This is not always true, it depends on implementation.
  • In some cases it is possible to give more performance by transforming into the most specific platform, or adapting the code, or giving a more specific bias. But in practice this does not end up happening when compared to advanced alternatives of applications that run 100% native. Only applies to some types.

In general the advantages given can be obtained in native applications, just not in the same way, with slightly different commitments. In both cases you have to give up some things, but you can have ease, performance, security and ability to run multiple platforms.

Disadvantages

  • Obviously it is an additional cost for someone to develop and maintain a VM, always a new source of problems and depends on a less established platform (although this tends to change over time in cases of Vms that are very successful).
  • It is a new platform to learn. It may or may not compensate.
  • It is common to have an extra cost because it is an application that goes together or needs to be previously installed to run your application.
  • There is a cost of execution somehow, in some cases quite expensive. But some may eliminate this before.

There are also a number of specific advantages and disadvantages of some VM or need-to-know.

What changes to the programming language

For the language itself little or nothing, unless its specification determines something specific about it, including having some requirement that requires it to be done only on a VM or that it is prohibited to use it.

Except as stated above, language implementations can be done either to run on a VM or not. Each will have its advantages and disadvantages as long as it meets the language specification.

Examples of known Vms:

  • JVM (various implementations and variations such as Dalvik)
  • CLR (some implementations of . NET and Mono)
  • LLVM (does not usually go along with your application)
  • Parrot (attempt to universalize Vms for dynamic languages)
  • Webassembly, Flash and JS (several that run on browsers and other ways using web platform)
  • SQL (almost all Dbs use VM, example)
  • BEAM (Erlang, Elixir and others)
  • Nekovm (well-used)
  • HHVM - (Hack and PHP Facebook)
  • p-code machine (initial implementation of Pascal)
  • Valgrind (used for environment control)

In essence all languages called dynamics run on a VM. Its use is not mandatory, but if the dynamism is very important it is much easier that way. This goes for JS, PHP, Python, Ruby, Perl, Lua, Smalltalk, VB (classic) and various Basics, xbase languages, various LISP implementations, etc.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.