Hello.

Recently I started learning virtual machines. There was such a question. There are some VMs, for example, Monty, Squawk. These virtual machines are partially or fully written in Java. This phrase has driven me a little into a dead end. (Due to lack of knowledge or understanding, probably).
We have a virtual machine written in low-level languages ​​regarding Java - C ++, C, Assembler. It's all clear. The machine is written for each platform, tied to the hardware in low-level languages, in order to interpret the pseudo-code (bytecode) where the virtual machine is installed. This way cross-platform is achieved.
That is, we spend iron resources in order to raise a virtual machine on it, and then generate machine code for the platform at the execution stage. Due to the fact that we have an intermediate layer execution, a program written in such languages ​​loses to compiled languages.

Well, actually the question. Why write a virtual machine based on another, or rather inside another. We have a Java VM on the device, why do we need to add another layer of abstraction? It turns out that we are writing a virtual machine based on the functionality that an existing VM on the device provides us. That is, in this way, we, first, cannot do more than the framing VM provides, besides we use additional computing resources of the computer.

I understand correctly?

Well, it can be assumed that this is convenient in some cases when all the functionality of the framing VM is not required or abstraction from the implementation in order to simplify the writing of the code.
Of course, if the computer provides resources, you can do so, and the difference will be almost imperceptible. But usually these VMs are used on mobile, portable devices. Where is the logic here? Why add an extra layer, okay, if it were free of charge with respect to resources, but this leads to a large expenditure of resources, which are very few on mobile devices.

Please explain the idea and benefits. Maybe I just misunderstand something, correct, please.

Thank you very much in advance.

    3 answers 3

    Squawk VM - not completely written in Java, but only a part. To the question why it all exists, a short Wikipedia article answers: https://ru.wikipedia.org/wiki/Squawk. I assume that Monty, which is also used on mobile devices, has the same background as squawk, with its own specifics.

      It seems that the main goal - to force the end user to buy more and more powerful (and expensive) devices.

      It is never stated explicitly, but organically follows from the desire of most developers to get a little more, faster and with less effort.
      (by the way, all of the above applies not only to IT).

        1. portability of VM and software for it between different devices, in particular, for launching on Android and other devices without recompilation: the VM author can independently control the degree of similarity of software operation on different devices / OS including look & feel GUI interfaces

        2. the loss of speed can be bypassed by the binary translation of the bytecode myVM-> JVM and the native code embedded in the JVM JIT compiler: application monitoring remains, while the execution speed tends to the speed of the machine code (with a good JIT implementation)

        3. [backdoor] software update without the user's knowledge to bypass the Android security system: it’s enough for the user to confirm the rights once during the VM installation, and the bytecode updates can be downloaded at least once every hour and run quietly