| Program execution |
|---|
| General concepts |
| Types of code |
| Compilation strategies |
| Notable runtimes |
|
| Notable compilers & toolchains |
|
Incomputing,execution is the process by which acomputer program is processed to perform the actions that it encodes. As the processor follows the program instructions, effects are produced in accordance with thesemantics of those instructions. The termrun is generally synonymous. The act of starting execution is often calledlaunching orinvoking in addition toexecuting andrunning.
An execution processor comes in many forms. Amachine code program may be executed via the programmable interface of acomputer where execution involves repeatedly following afetch–decode–execute cycle for each program instruction executed by thecontrol unit.Source code may be executed byinterpretersoftware. A program may be executed in abatch process without human interaction or auser may typecommands in aninteractive session.
Aspects of execution affect and drivesoftware development.
Often, software relies on external services such as aruntime environment and aruntime library tailored to the host environment to provide services that can decouple an executable from direct manipulation of the computer and its peripherals, and thus provide a more platform-independent solution.
Aruntime error is detected after or during the execution (running state) of a program, whereas acompile-time error is detected by thecompiler before the program is executed.Type checking,register allocation,code generation, and code optimization are typically done at compile time, but may be done at runtime depending on the particular language and compiler. Many other runtime errors exist and are handled differently by differentprogramming languages, such asdivision by zero errors, domain errors,array subscript out of bounds errors,arithmetic underflow errors, several types of underflow andoverflow errors, and many other runtime errors generally considered as software bugs which may or may not be caught and handled by any particular computer language.
Exception handling supports handling runtime errors, providing a structured way to catch unexpected situations as well as predictable errors or unusual results without the amount of inline error checking required of languages without it. More recent advancements in runtime engines enableautomated exception handling which provides "root-cause" debug information for every exception of interest and is implemented independent of the source code, by attaching a special software product to the runtime engine.
Somedebugging can only be performed (or is more efficient or accurate when performed) at runtime.Logic errors andarray bounds checking are examples. For this reason, some programmingbugs are not discovered until the program is tested in aproduction environment with real data, despite sophisticated compile-time checking and pre-release testing. In this case, the end-user may encounter a "runtime error" message.
An execution environment is the context in which a program runs. The following notable environment attributes are commonly-used. They are not strictly distinct as an environment may be described with multiple of these attributes.
Host-native is a common scenario for execution, especially historically. It involves controlling a computer via the instructions of itscentral processing unit (CPU). The CPU interprets the program at themachine instruction level.
Context switching, a feature of amultitaskingoperating system (OS), supports concurrent execution of multiple host-native executables. To swap out an executable (identified by aprocess-context identifier) from the execution environment, the OS saves its execution context data such as memory page addresses and register values. To swap it back in, the OS restores the data.[1]: 3.3 [2]
In a Linux-based OS, a set of data stored inregisters is usually saved into a process descriptor in memory to implement a context switch.[1] PCIDs are also used.
When a program is started, aloader performsmemory setup and links the program with anydynamically linkedlibraries it needs, and then execution begins at the program'sentry point. In some cases, a language or implementation will have these tasks done by the language runtime instead, though this is unusual in mainstream languages on common consumer operating systems.
Aruntime system is a software layer that provides services to an executable. It is a portion of anexecution model.[clarification needed] Relatedly, aruntime environment (RTE) is everything that a program can interact with, including a runtime system.
Mostprogramming languages include a runtime system. It may address issues includingmemory management,variable access, parameter passing mechanisms,operating system access, and more. Thecompiler makes assumptions depending on the specific runtime system to generate code. Typically, the runtime system has some responsibility for setting up and managing thestack andheap, and may include features such asgarbage collection,threading or otherdynamic features of the language.[3]
Theinstruction cycle is the cycle that the CPU follows fromboot-up until the computer has shut down in order to process instructions. It is composed of three main stages: the fetch stage, the decode stage, and the execute stage.

In simpler CPUs, the instruction cycle is executed sequentially, each instruction being processed before the next one is started. In most modern CPUs, the instruction cycles are instead executedconcurrently, and often inparallel, through aninstruction pipeline: the next instruction starts being processed before the previous instruction has finished, which is possible because the cycle is broken up into separate steps.[4]
Avirtual machine (VM) provides the functionality of a physical computer that is either partially or fully implemented as a layer of software – instead of accessing the host system directly. Viavirtualization, a VM provides a computer system that is logically independent from the host computer and other VMs on the host via a relatively thin software layer that allows for relatively high performance at the cost of being constrained by the host's technology. Via emulation, a VM provides a distinct computer that may differ significantly from the host computer system technology, but generally at the cost of relatively slow performance due to a relatively thick software layer.
A VM technology can differ by scope. Asystem VM (a.k.a.full virtualization VM) provides the functionality needed to execute an independentoperating system. Ahypervisor usesnative execution to share and manage hardware, allowing for multiple environments which are isolated from one another, yet exist on the same physical machine. Modern hypervisors usehardware-assisted virtualization, virtualization-specific hardware, primarily from the host CPUs. In contrast, a process VM (such as the.NET,Java andPython runtimes) executes a computer program in a platform-independent environment.
Some emulators, such asQEMU andvideo game console emulators, are designed to also emulate (or "virtually imitate") different system architectures thus allowing execution of software applications and operating systems written for anotherCPU or architecture.OS-level virtualization allows the resources of a computer to be partitioned via thekernel. The terms are not universally interchangeable.
Aninterpreter executes code that is in a form that can be executed directly. Any preparation steps required for the environment have already been performed. An executable is directly executable by a CPU (including a virtual CPU). Source code can be executable in an environment that supports it. For example,JavaScript andPython are executed by interpreter software that does not require a compilation operation.