operating-systemruntime-environment

does every programme run in a runtime environment?


I know that some programmes like Java or .NET programmes use an extensive runtime system for execution. But I read something in a book about OS (which isnt explained in more detail there) that sounds like ANY programme written by a user runs in a runtime system and not directly on the operating system.

An example given is that when you read a file, you dont call an operating system function for each bit you read, instead you read the bits or bytes into a buffer managed by the runtime system and when that's empty, you call a system function again.

So does that mean that strictly speaking, any programme runs in a runtime environment of some kind (except maybe prgrammes written in assembly...)?


Solution

  • By definition, yes.

    Software requires some environment in which to execute, otherwise it is just a set of bits stored on some storage device. There are several categories of runtime environment, and sometimes the distinction between different types of environment is blurry.

    At one level, there is the environment provided by the hardware, which includes the instruction set architecture, services provided by devices, BIOS, etc.

    Then there is an environment provided by an operating system. Operating systems work at various levels of complexity, but typically sit as an intermediary between running programs and the host hardware. Some operating systems are pretty thin, in the sense that programs are able to do things without mediation by the operating system. Others prevent software from communicating directly with the hardware so programs must make a request (e.g. via an operating system facility or service) and the operating system then interacts directly with the hardware.

    At another level is an environment specified associated with a programming language. The semantics of numerous programming languages are represented in terms of execution on some abstract machine. Examples include C and C++, where every expression, every declaration, and every statement have a set of defined effects on an abstract machine. A number of instances of undefined behaviour (as specified in the standards) amounts to cases where language statements are able to go outside the bounds of what is acceptable to that abstract machine.

    Closely associated with the previous type of environment, there are languages that are associated with a library of some form. That standard library provides facilities to make the programmer's job easier. Almost all moderately high level languages are associated with a library - C, C++, Java, Ada, etc etc. A number of those features can be implemented in the language itself, but others require help of the host system (e.g. operating system, hardware, etc) so might be implemented in another language (e.g. assembler).

    The next level up are runtime environments (such as the Java virtual machine) in which programs (of some format) are executed. The programs (usually) only communicate with that runtime environment, which in turn requests actions from the system on which it is hosted. Sometimes programs can communicate directly with the host system (via mechanisms known as thunking, native interfaces, etc).

    Then there are programs that interpret code on the fly (e.g. language interpreters) so, in effect, the source code itself is the program, and the interpreter requests services from the environment in which it is hosted.

    Even programs written in assembly run in some environment. Assembly gets translated to machine-specific instructions that are specific to some host environment (consisting of hardware, possibly an operating system, possibly some other program hosted by an operating system).

    There are also special types of operating systems (e.g. hypervisors) that can host other operating systems - and often allow multiple operating systems to execute at the same time on a single hardware platform. When the operating system attempts to access hardware, the call is intercepted and mediated by the hypervisor, which in turn makes requests of the host hardware.

    The thing is, all of these things involve software making some assumption about an environment in which it executes. Even software written in assembler that communicates directly with hardware assumes a set of hardware and a means of communicating with that hardware. Firmware is a type of software that assumes it is running on some device (e.g. a motherboard, a memory controller, a hard drive controller, etc).