All Topics  
Self-modifying code

 

   Email Print
   Bookmark   Link






 

Self-modifying code



 
 
In computer science
Computer science

Computer science is the study of the theoretical foundations of information and computation, and of practical techniques for their implementation and application in computer systems....
, self-modifying code is code that alters its own instructions
Instruction (computer science)

In computer science, an instruction is a single operation of a central processing unit defined by an instruction set architecture. In a broader sense, an "instruction" may be any representation of an element of an executable program, such as a bytecode....
 while it is executing
Execution (computers)

Execution in computer engineering and software engineering is the Process by which a computer or a virtual machine carries out the instructions of a computer program....
 - usually to reduce the instruction path length
Instruction path length

In computer performance, the Instruction path length is the number of machine code instructions required to execute a section of a computer program....
 and improve performance
Performance

A performance, in performing arts, generally comprises an event in which one group of people behave in a particular way for another group of people ....
. The modifications may be performed only during initialization, based on input parameters (when the process is more commonly described as software 'configuration
Computer configuration

In information systems or computer systems, a configuration is an arrangement of functional units according to their nature, number, and chief characteristics....
' and is somewhat analagous, in hardware terms, to setting jumpers
Jumper (computing)

In electronics and particularly computing, a jumper is a short length of conductor used to close a break in or bypass part of an electrical circuit....
 for printed circuit board
Printed circuit board

A printed circuit board, or PCB, is used to mechanically support and electrically connect electronic components using Conductor pathways, or signal traces, industrial etchinged from copper sheets laminated onto a non-conductive substrate....
s). Alteration of program entry pointers is an equivalent indirect method of self-modification, requiring the co-existence of one or more alternative instruction paths.

Alternatively, the modifications may be performed to the machine code
Machine code

Machine code or machine language is a system of instructions and data executed directly by a computer's central processing unit. Machine code may be regarded as a primitive programming language or as the lowest-level representation of a compiled and/or assembly language computer program....
 instructions themselves throughout execution, 'on-the-fly', by overlaying new instructions over the existing ones (for example: altering a compare and branch to an unconditional branch or alternatively a 'noop').






Discussion
Ask a question about 'Self-modifying code'
Start a new discussion about 'Self-modifying code'
Answer questions from other users
Full Discussion Forum



Encyclopedia


In computer science
Computer science

Computer science is the study of the theoretical foundations of information and computation, and of practical techniques for their implementation and application in computer systems....
, self-modifying code is code that alters its own instructions
Instruction (computer science)

In computer science, an instruction is a single operation of a central processing unit defined by an instruction set architecture. In a broader sense, an "instruction" may be any representation of an element of an executable program, such as a bytecode....
 while it is executing
Execution (computers)

Execution in computer engineering and software engineering is the Process by which a computer or a virtual machine carries out the instructions of a computer program....
 - usually to reduce the instruction path length
Instruction path length

In computer performance, the Instruction path length is the number of machine code instructions required to execute a section of a computer program....
 and improve performance
Performance

A performance, in performing arts, generally comprises an event in which one group of people behave in a particular way for another group of people ....
. The modifications may be performed only during initialization, based on input parameters (when the process is more commonly described as software 'configuration
Computer configuration

In information systems or computer systems, a configuration is an arrangement of functional units according to their nature, number, and chief characteristics....
' and is somewhat analagous, in hardware terms, to setting jumpers
Jumper (computing)

In electronics and particularly computing, a jumper is a short length of conductor used to close a break in or bypass part of an electrical circuit....
 for printed circuit board
Printed circuit board

A printed circuit board, or PCB, is used to mechanically support and electrically connect electronic components using Conductor pathways, or signal traces, industrial etchinged from copper sheets laminated onto a non-conductive substrate....
s). Alteration of program entry pointers is an equivalent indirect method of self-modification, requiring the co-existence of one or more alternative instruction paths.

Alternatively, the modifications may be performed to the machine code
Machine code

Machine code or machine language is a system of instructions and data executed directly by a computer's central processing unit. Machine code may be regarded as a primitive programming language or as the lowest-level representation of a compiled and/or assembly language computer program....
 instructions themselves throughout execution, 'on-the-fly', by overlaying new instructions over the existing ones (for example: altering a compare and branch to an unconditional branch or alternatively a 'noop'). This may be in response to a particular program state
Program state

One of the key concepts in computer programming is the idea of state, essentially a snapshot of the measure of various conditions in the system....
 being reached.

Self modification is an alternative method of conditional program branching used primarily to reduce the number of times a condition needs to be tested for. The method is frequently used for conditionally invoking test/debugging code without requiring additional overhead
Overhead

Overhead may be:* Overhead , the ongoing operating costs of running a business* Engineering overhead, ancillary design features required by a component of a device...
 for every input/output
Input/output

In computing, input/output, or I/O, refers to the communication between an information processing system , and the outside world ? possibly a human, or another information processing system....
 cycle and also in just-in-time (JIT
JIT

JIT may refer to:* Various meanings of Just In Time:** Just-in-time compilation - a technique for improving the performance of virtual machines in computing....
) compilers.

Application in low and high level languages

Self-modifying code is quite straightforward to implement when using assembly language
Assembly language

An assembly language is a low-level language for programming computers. It implements a symbolic representation of the numeric machine codes and other constants needed to program a particular CPU architecture....
. Instructions can be dynamically created in memory
Memory

In psychology, memory is an organism's mental ability to store, retain and recall information. Traditional studies of memory began in the fields of philosophy, including techniques of mnemonic....
 (or else overlaid over existing code in program storage) in a sequence equivalent to the ones that a standard compiler may generate as the object code (/binary file
Binary file

A binary file is a computer file which may contain any type of data, encoded in Binary numeral system form for computer storage and processing purposes; for example, Document file format containing formatted text....
). With modern processors, there can be unintended side effects on the CPU cache
CPU cache

A CPU cache is a cache used by the central processing unit of a computer to reduce the average time to access computer storage. The cache is a smaller, faster memory which stores copies of the data from the most frequently used main memory locations....
 that have to be considered.

Some high level languages/ interpreters
Interpreter (computing)

In computer science, an interpreter normally means a computer program that execution , i.e. performs, instructions written in a programming language....
 such as SNOBOL4, the Lisp programming language
Lisp programming language

Lisp is a family of computer programming languages with a long history and a distinctive, fully parenthesized syntax. Originally specified in 1958, Lisp is the second-oldest high-level programming language in widespread use today; only Fortran is older....
, the ALTER verb
Alter

To alter generally means to change something but may also refer to:* Alter , people named Alter* Alter * Alter , a Japanese model and figure manufacturer...
 in COBOL
COBOL

COBOL is one of the oldest programming languages still in active use. Its name is an acronym for COmmon Business-Oriented Language, defining its primary domain in business, finance, and administrative systems for companies and governments....
 and the eval
Eval

In some programming languages, eval is a subroutine which evaluates a string as though it were an expression and returns a result; in others, it executes multiple lines of code as though they had been included instead of the line including the eval....
 statement in javascript
JavaScript

JavaScript is a scripting language widely used for client-side web development. It was the originating Programming language dialect of the ECMAScript standard....
 actively support self-modification. Self-modification can be more difficult to implement on certain compiler
Compiler

A compiler is a computer program that transforms source code written in a programming language into another computer language . The most common reason for wanting to transform source code is to create an executable program....
s but Clipper
Clipper programming language

Clipper is a computer programming language that is used to create computer programs that originally operated primarily under DOS. Although it is a powerful general-purpose programming language, it was primarily used to create database/business programs....
 and Spitbol are two that also provide it. Most scripting languages such as Perl
Perl

In computer programming, Perl is a high-level programming language, List of programming languages by category, Interpreter , dynamic programming language....
 and Python
Python (programming language)

Python is a general-purpose high-level programming language. Its design philosophy emphasizes code readability. Python's core syntax and semantics are Minimalism , while the standard library is large and comprehensive....
 are interpreted, which means that the program can generate new code dynamically and then execute it. Usually, the code is created in dynamic memory, but it can also be indirectly executed by first writing out a new file and then running the new file using the scripting language interpreter (a process actually more similar to 'compile and run' than true self-modification).

One batch
Batch file

In DOS, OS/2, and Microsoft Windows, a batch file is a text file containing a series of Command intended to be executed by the Command line interpreter....
 programming technique is to use self-modifying code.

History

In the early days of computers, self-modifying code was often used in order to reduce the usage of limited memory or improve performance or both. It was also sometimes used to implement subroutine calls and returns when the instruction set only provided simple branching or skipping instructions to vary the control flow
Control flow

In computer science control flow refers to the order in which the individual statement , Instruction or function calls of an imperative programming or functional programming computer program are execution or evaluated....
 (This application is still relevant in certain ultra-RISC architectures, at least theoretically; see for example One instruction set computer
One instruction set computer

A One Instruction Set Computer is a Turing-complete abstract machine that uses only one instruction . These universal computers are used primarily as a theoretical teaching aid ....
). Donald Knuth
Donald Knuth

Donald Ervin Knuth is a renowned computer science and Emeritus of the Art of Computer Programming at Stanford University.Author of the seminal multi-volume work The Art of Computer Programming , Knuth has been called the "father" of the run-time analysis, contributing to the development of, and systematizing formal mathematical techn...
's MIX
MIX

MIX is a hypothetical computer used in Donald Knuth’s monograph, The Art of Computer Programming . MIX’s model number is 1009, which was derived by combining the model numbers and names of several contemporaneous, commercial machines deemed significant by the author....
 architecture also used self-modifying code to implement subroutine calls.

Already, critical systems which are too complex for people to fully manage in real time, such as the Internet
Internet

The Internet is a global network of interconnected computers, enabling users to share information along multiple channels. Typically, a computer that connects to the Internet can access information from a vast array of available server and other computers by moving information from them to the computer's local memory....
 and electrical distribution networks routinely rely upon self-modifying behaviors (though not necessarily self-modifying code) in order to function acceptably.

Usage


Self-modifying code can be used for various purposes:

  • Semi-automatic optimization
    Optimization (computer science)

    In computing, optimization is the process of modifying a system to make some aspect of it work more efficiently or use fewer resources. For instance, a computer program may be optimized so that it executes more rapidly, or is capable of operating with less Computer data storage or other resources, or draw less power....
     of a state dependent loop.
  • Runtime
    Runtime

    In computer science, runtime or run time describes the operation of a computer program, the duration of its execution, from beginning to termination ....
     code generation, or specialization of an algorithm in runtime or loadtime (which is popular, for example, in the domain of real-time graphics) such as a general sort utility - preparing code to perform the key comparison described in a specific invocation.
  • JIT
    JIT

    JIT may refer to:* Various meanings of Just In Time:** Just-in-time compilation - a technique for improving the performance of virtual machines in computing....
     compilers building code 'on-the-fly'
  • Altering of inlined
    Inline function

    In computer science, an inline function is a programming language construct used to suggest to a compiler that a particular function be subjected to inline expansion; that is, it suggests that the compiler insert the complete body of the function in every context where that function is used....
     state of an object
    Object (computer science)

    In its simplest embodiment, an object is an allocated region of storage. Since programming languages use variable#Computer_programmings to access objects, the terms object and variable are often used interchangeably....
    , or simulating the high-level construction of closures
    Closure (computer science)

    In computer science, a closure is a function that is evaluated in an environment containing one or more bound variables. When called, the function can access these variables....
    .
  • Patching of subroutine
    Subroutine

    In computer science, a subroutine or subprogram is a portion of computer code within a larger computer program, which performs a specific task and is relatively independent of the remaining code....
     (pointer) address calling, usually as performed at load/initialization time of dynamic libraries, or else on each invocation, patching the subroutine's internal references to its parameters so as to use actual addresses of specific routines. (i.e. Indirect 'self-modification').
  • Evolutionary computing systems such as genetic programming
    Genetic programming

    In artificial intelligence, genetic programming is an evolutionary algorithm-based methodology bio-inspired computing by biological evolution to find computer programs that perform a user-defined task....
    .
  • Hiding of code to prevent reverse engineering
    Reverse engineering

    Reverse engineering is the process of discovering the technological principles of a device, object or system through analysis of its structure, function and operation....
    , as through use of a disassembler
    Disassembler

    A disassembler is a computer program that translates machine language into assembly language?the inverse operation to that of an Assembly language#Assembler....
     or debugger
    Debugger

    A debugger is a computer program that is used to test and debug other programs. The code to be examined might alternatively be running on an Instruction Set Simulator, a technique that allows great power in its ability to halt when specific conditions are encountered but which will typically be much slower than executing the code directly on...
    .
  • Hiding of code to evade detection by virus/spyware scanning software and the like.
  • Filling 100% of memory (in some architectures) with a rolling pattern of repeating opcodes, to erase all programs and data, or to burn-in hardware.
  • Compression
    Data compression

    In computer science and information theory, data compression or source coding is the process of encoding information using fewer bits than an code representation would use through use of specific encoding schemes....
     of code to be decompressed and executed at runtime, e.g., when memory or disk space is limited.
  • Some very limited instruction sets
    Instruction set

    An instruction set is a list of all the instruction , and all their variations, that a processor can execute.Instructions include:* Arithmetic such as add and subtract...
     leave no option but to use self-modifying code to achieve certain functionality. For example, a "One Instruction Set Computer" machine that uses only the subtract-and-branch-if-negative "instruction" cannot do an indirect copy (something like the equivalent of "*a = **b" in the C programming language
    C (programming language)

    C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
    ) without using self-modifying code.
  • Altering instructions for fault-tolerance


Optimizing a state-dependent loop

Pseudocode
Pseudocode

Pseudocode is a compact and informal high-level description of a computer programming algorithm that uses the structural conventions of some programming language, but is intended for human reading rather than machine reading....
 example:

repeat N times

Self-modifying code in this case would simply be a matter of rewriting the loop like this:

repeat N times

when STATE has to switch

Note that 2-state replacement of the opcode
Opcode

In computer technology, an opcode is the portion of a machine language instruction that specifies the operation to be performed. Their specification and format are laid out in the instruction set architecture of the processor in question ....
 can be easily written as 'xor var at address with the value "opcodeOf(Inc) xor opcodeOf(dec)"'.

Choosing this solution will have to depend of course on the value of 'N' and the frequency of state changing.

Use as camouflage

Self-modifying code was used to hide copy protection instructions in 1980s disk based programs for platforms such as IBM PC
IBM PC

The IBM Personal Computer, commonly known as the IBM PC, is the original version and progenitor of the IBM PC compatible hardware platform ....
 and Apple II. For example, on an IBM PC (or compatible
IBM PC compatible

IBM PC compatible computers are those generally similar to the original IBM Personal Computer, IBM Personal Computer XT, and IBM Personal Computer/AT....
), the floppy disk
Floppy disk

A floppy disk is a data storage medium that is composed of a disk of thin, flexible magnetic storage medium encased in a square or rectangle plastic shell....
 drive access instruction 'int
Interrupt

In computing, an interrupt is an asynchronous communication signal from hardware indicating the need for attention or a synchronous event in software indicating the need for a change in execution....
 0x13' would not appear in the executable program's image but it would be written into the executable's memory image after the program started executing.

Self-modifying code is also sometimes used by programs that do not want to reveal their presence — such as computer virus
Computer virus

A computer virus is a computer program that can copy itself and infect a computer without the permission or knowledge of the user. The term "virus" is also commonly but erroneously used to refer to other types of malware, adware and spyware programs that do not have the reproductive ability....
es and some shellcode
Shellcode

In computer security, a shellcode is a small piece of code used as the Payload in the exploit of a software Vulnerability . It is called "shellcode" because it typically starts a Shell from which the attacker can control the compromised machine....
s. Viruses and shellcodes that use self-modifying code mostly do this in combination with polymorphic code
Polymorphic code

In computer terminology, polymorphic code is code that mutates while keeping the original algorithm intact. This technique is sometimes used by computer viruses, shellcodes and computer worms to hide their presence....
. Polymorphic viruses are sometimes called primitive self-mutators. Modifying a piece of running code is also used in certain attacks, such as buffer overflow
Buffer overflow

In computer security and computer programming, a buffer overflow, or buffer overrun, is an Anomaly in software condition where a process attempts to store data beyond the boundaries of a fixed-length buffer ....
s.

Self-referential machine learning systems


Traditional machine learning
Machine learning

Machine learning is the subfield of artificial intelligence that is concerned with the design and development of algorithms that allow computers to improve their performance over time based on data, such as from sensor data or databases....
 systems have a fixed, pre-programmed learning algorithm
Algorithm

In mathematics, computing, linguistics and related subjects, an algorithm is a sequence of finite instructions, often used for calculation and data processing....
 to adjust their parameters. However, since the 1980s Jürgen Schmidhuber
Jürgen Schmidhuber

J?rgen Schmidhuber is a computer scientist and artist known for his work on machine learning, universal Artificial Intelligence , artificial neural networks, digital physics, and low-complexity art....
 has published several self-modifying systems with the ability to change their own learning algorithm. They avoid the danger of catastrophic self-rewrites by making sure that self-modifications will survive only if they are useful according to a user-given fitness function
Fitness function

A fitness function is a particular type of objective function that quantifies the optimality of a solution in a genetic algorithm so that that particular chromosome may be ranked against all the other chromosomes....
 or error function
Error function

In mathematics, the error function is a special function which occurs in probability, statistics, materials science, and partial differential equations....
 or reward
Reward

A reward may refer to:*Bounty , a reward, often money, offered as an incentive*Reward website, a website that offers rewards for performing tasks...
 function.

Operating systems

Because of the security implications of self-modifying code, all of the major operating system
Operating system

An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer....
s are careful to remove such vulnerabilities as they become known. The concern is typically not that programs will intentionally modify themselves, but that they could be maliciously changed by an exploit
Exploit (computer security)

An exploit is a piece of software, a chunk of data, or sequence of commands that take advantage of a software bug, glitch or vulnerability in order to cause unintended or unanticipated behavior to occur on computer software, hardware, or something electronic ....
.

As consequence of the troubles that can be caused by these exploits, an OS feature called W^X
W^X

W^X is the name of a Computer insecurity feature present in the OpenBSD operating system. It is a memory protection policy whereby every paging in a Process ' address space is either writable or executable, but not both simultaneously ....
 (for "write xor execute") has been developed which prohibits a program from making any page of memory both writable and executable. Some systems prevent a writable page from ever being changed to be executable, even if write permission is removed. Other systems provide a 'back door
Back Door

Back Door was a jazz fusion Trio , formed in 1971....
' of sorts, allowing multiple mappings of a page of memory to have different permissions. A relatively portable way to bypass W^X is to create a file with all permissions, then map the file into memory twice. On Linux, one may use an undocumented SysV shared memory flag to get executable shared memory without needing to create a file. On Windows Vista and Windows XP the W^X protection is named Data Execution Prevention
Data Execution Prevention

Data Execution Prevention is a security feature included in modern Microsoft Windows operating systems that is intended to prevent an Application software or service from executing code from a non-executable memory region....
 and can be disabled via the Control Panel.

Regardless, at a meta-level, programs can still modify their own behavior by changing data stored elsewhere (see Metaprogramming
Metaprogramming

Metaprogramming is the writing of computer programs that write or manipulate other programs as their data, or that do part of the work at runtime that would otherwise be done at compile time....
) or via use of polymorphism
Polymorphism

In general, polymorphism describes multiple possible states for a single property .Polymorphism may specifically refer to:In the biological sciences...
.

Just-in-time compilers

Just-in-time
Just-in-time compilation

In computing, just-in-time compilation , also known as dynamic translation, is a technique for improving the runtime performance of a computer program....
 compilers for Java
Java (programming language)

Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java ....
, .NET, ActionScript 3.0
ActionScript

ActionScript is a scripting language based on ECMAScript. ActionScript is used primarily for the development of websites and software using the Adobe Flash Player platform , but is also used in some database applications , and in basic robotics, as with the Make Controller Kit....
 and other programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
s compile blocks of byte-code or p-code
P-Code machine

In computer programming, a p-code machine or pseudo-code machine is a virtual machine designed to execute p-code . This term is applied both generically to all such machines , and to specific implementations, the most famous being the p-Machine of UCSD Pascal....
 into machine code suitable for the host processor and then immediately execute them. Fabrice Bellard's Tiny C Compiler
Tiny C Compiler

The Tiny C Compiler is an x86 C compiler created by Fabrice Bellard. It is designed to work for slow computers with little disk space . MS Windows operating system support has been added in version 0.9.23 ....
 can and has been used as C
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
-Just-in-Time-Compiler-Library, e.g. by TCCBOOT (a bootloader that can compile, load and run its operation system on-the-fly).

Graphics drivers for modern GPUs perform JIT-Compilation of DirectX or OpenGL/GLSL
GLSL

GLSL , also known as GLslang, is a High level programming language shading language based on the C . It was created by the OpenGL ARB to give developers more direct control of the graphics pipeline without having to use assembly language or hardware-specific languages....
 geometry and fragment shaders, and can thus be seen as self-modifying code, sometimes distributed over multiple processors and DSPs (or even self-modifying hardware).

Some CPU Architecture Emulators use similar techniques to JIT-Compilers (simulated instruction set as "programming language" that becomes compiled for the target processor).

Interaction of cache and self-modifying code

On architectures without coupled data and instruction cache (some ARM and MIPS cores) the cache synchronization must be explicitly performed by the modifying code (flush data cache and invalidate instruction cache for the modified memory area).

In some cases short sections of self-modifying code executes more slowly on modern processors. This is because a modern processor will usually try to keep blocks of code in its cache memory. Each time the program rewrites a part of itself, the rewritten part must be loaded into the cache again, which results in a slight delay, if the modified codelet shares the same cache line with the modifying code, as is the case when the modified memory address is located within a few bytes to the one of the modifying code.

The cache invalidation issue on modern processors usually means that self-modifying code would still be faster only when the modification will occur rarely, such as in the case of a state switching inside an inner loop.

Most modern processors load the machine code before they execute it, which means that if an instruction that is too near the instruction pointer is modified, the processor will not notice, but instead execute the code as it was before it was modified. See Prefetch Input Queue
Prefetch input queue

Most modern processors load their instructions some clock cycles before they execute them. This is achieved by pre-loading machine code from memory into a prefetch input queue ....
 (PIQ). PC processors have to handle self-modifying code correctly for backwards compatibility reasons but they are far from efficient at doing so.

Henry Massalin's Synthesis kernel

The Synthesis kernel written by Dr. Henry Massalin as his Ph.D.
Doctor of Philosophy

Doctor of Philosophy, abbreviated Ph.D. or PhD for the Latin , meaning "teacher of philosophy", is an postgraduate academic degree awarded by University....
 thesis is commonly viewed to be the "mother of all self-modifying code." Massalin's tiny Unix
Unix

Unix is a computer operating system originally developed in 1969 by a group of American Telephone & Telegraph employees at Bell Labs, including Ken Thompson , Dennis Ritchie, Douglas McIlroy, and Joe Ossanna....
 kernel takes a structured
Structured programming

Structured programming can be seen as a subset or subdiscipline of procedural programming, one of the major programming paradigms. It is most famous for removing or reducing reliance on the GOTO Statement ....
, or even object oriented
Object-oriented programming

Object-oriented programming is a programming paradigm that uses "Object_" and their interactions to design applications and computer programs....
, approach to self-modifying code, where code is created for individual quajects, like filehandles; generating code for specific tasks allows the Synthesis kernel to (as a JIT interpreter might) apply a number of optimizations
Compiler optimization

Compiler optimization is the process of tuning the output of a compiler to minimize or maximize some attribute of an executable computer program....
 such as constant folding
Constant folding

In compiler theory, constant folding and constant propagation are related compiler optimizations used by many modern compilers. A more advanced form of constant propagation known as sparse conditional constant propagation may be utilized to simultaneously remove dead code and more accurately propagate constants....
 or common subexpression elimination
Common subexpression elimination

In computer science, common subexpression elimination is a compiler optimization that searches for instances of identical Expression , and analyses whether it is worthwhile replacing them with a single variable holding the computed value....
.

The Synthesis kernel was extremely fast, but was written entirely in assembly. The resulting lack of portability has prevented Massalin's optimization ideas from being adopted by any production kernel. However, the structure of the techniques suggests that they could be captured by a higher level language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
, albeit one more complex than existing mid-level languages. Such a language and compiler could allow development of extremely fast operating systems and applications.

Paul Haeberli and Bruce Karsh have objected to the "marginalization" of self-modifying code, and optimization in general, in favor of reduced development costs, drawing a parallel to the "heavy religious atmosphere" which the Italian Futurist
Futurism (art)

Futurism was an art Art movement that originated in Italy in the early 20th century. It was largely an Italian phenomenon, though there were parallel movements in Russia, England and elsewhere....
 movement rebelled against.

Advantages

  • Fast path
    Fast path

    Fast path is a term used in computer science to describe an alternative 'faster' path through a progarm than the 'normal' path. It provides a shorter instruction path length, either by self-modifying code or other methods to improve algorithmic efficiency....
    s can be established for a programs execution, reducing some otherwise repetetive conditional branches and
  • JIT
    JIT

    JIT may refer to:* Various meanings of Just In Time:** Just-in-time compilation - a technique for improving the performance of virtual machines in computing....
     compilers can build programs that are more highly optimized than even an optimzing compiler
    Compiler optimization

    Compiler optimization is the process of tuning the output of a compiler to minimize or maximize some attribute of an executable computer program....
     can generate
improving algorithmic efficiency
Algorithmic efficiency

In computer science, efficiency is used to describe properties of an algorithm relating to how much of various types of resources it consumes. The two most frequently encountered are...

Disadvantages

Self-modifying code is seen by some as a bad practice
Best practice

Best practice is an idea that asserts that there is a wikt:technique, method, process, activity, incentive or reward that is more effective at delivering a particular outcome than any other technique, method, process, etc....
 which makes code harder to read and maintain. There are however ways in which self modification is nevertheless deemed acceptable, such as when sub routine pointers are dynamically altered - even though the effect is almost identical to direct modification. The subtle difference, in this case, is that a pointer variable
Variable

A variable is a symbol that stands for a value that may vary; the term usually occurs in opposition to constant, which is a symbol for a non-varying value, i.e....
 is altered, not actual program instructions. The change to the pointer is, in this case, equivalent to the setting of a 'flag
Flag (computing)

In computer programming, flag refers to one or more bits that are used to store a binary numeral system value or code that has an assigned meaning....
' (that might have been set as an alternative) - except that the flag does not need to be tested each time thereafter.

See also

  • Algorithmic efficiency
    Algorithmic efficiency

    In computer science, efficiency is used to describe properties of an algorithm relating to how much of various types of resources it consumes. The two most frequently encountered are...
  • Reflection (computer science)
    Reflection (computer science)

    In computer science, reflection is the process by which a computer program can observe and modify its own structure and behaviour. The programming paradigm driven by reflection is called reflective programming....
  • Self-replication
    Self-replication

    Self-replication is any process by which a thing might make a copy of itself. Cell s, given suitable environments, reproduce by cell division. During cell division, DNA is replicated and can be transmitted to offspring during reproduction....
  • Quine (computing)
  • PCASTL
    PCASTL

    The PCASTL is an interpreted high-level programming language. It was created in 2008 by Philippe Choquette. The PCASTL is designed to ease the writing of self-modifying code....


External links

  • : Henry Massalin's Ph.D. thesis on the Synthesis kernel
  • Jürgen Schmidhuber
    Jürgen Schmidhuber

    J?rgen Schmidhuber is a computer scientist and artist known for his work on machine learning, universal Artificial Intelligence , artificial neural networks, digital physics, and low-complexity art....
    's publications on