0
$\begingroup$

We know that computer programs are either AOT compiled, JIT compiled or interpreted

And we also know that AOT compiled programs usually get compiled from its high level source code into machine code

Now the question is, if machine code is so hard to understand and write, why the idea of compilers wasn't to translate programs into a simpler language understood by the operating system instead of translating directly into machine code

And if such operating-system-dependent language existed, the OS should read the executables written in it and translate them into the corresponding machine code understood by the CPU

In other words, wouldn't the process of compiling into machine code have been easier if OSs had some kind of JIT compiler (VM?) that translated a specific kind of bytecode (which should exist) into machine code?

Are there any disadvantages of all this?

New contributor
Mario is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$

2 Answers 2

3
$\begingroup$

OS-independent layers (more precisely CPU-independent) introduce some overhead to achieve the exact specifications, so in many contexts this is just unacceptable. And computer manufacturers have no interest in making their solution too standardized, as this impairs customer retention.

Anyway, you can consider that the Java Virtual Machine is an extension of the OS that just does what you want.

$\endgroup$
3
  • $\begingroup$ .NET works the same way. $\endgroup$ Sep 23 at 16:59
  • $\begingroup$ @reinierpost: .NET code is first compiled into CLI instructions, but the latter are then compiled to the target. Hence the overhead of the CPU-independent layer is reduced. $\endgroup$ Sep 23 at 17:05
  • $\begingroup$ Java VMs perform JIT compilation as well - see e.g. stackoverflow.com/questions/2506969/… $\endgroup$ yesterday
0
$\begingroup$

The OS doesn't execute programs. The CPU does. The OS helps manage access to resources. Since the CPU executes programs, programs need to be translated (compiled) into a form that the CPU can execute.

I see no obvious benefit or advantage to the scheme you describe (compile the program to an intermediate language, and then OS does JIT compilation). You could certainly do it, but the lack of a clear benefit probably explains why it is not common.

However, you might be interested in Android apps, which used to use a Dalvik interpreter and/or just-in-time compiler to run Android apps. Android apps are often written in Java, which was compiled to the Dalvik intermediate language, and then at runtime the system interpreted this or applied a JiT compiler.

$\endgroup$

Your Answer

Mario is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.