TL;DR: The direct cost of virtual function calls in C++ programs, assuming the standard implementation using virtual function tables is standard, is measured experimentally using a combination of executable inspection and processor simulation.
Abstract: We study the direct cost of virtual function calls in C++ programs, assuming the standard implementation using virtual function tables. We measure this overhead experimentally for a number of large benchmark programs, using a combination of executable inspection and processor simulation. Our results show that the C++ programs measured spend a median of 5.2% of their time and 3.7% of their instructions in dispatch code. For "all virtuals" versions of the programs, the median overhead rises to 13.7% (13% of the instructions). The "thunk" variant of the virtual function table implementation reduces the overhead by a median of 21% relative to the standard implementation. On future processors, these overheads are likely to increase moderately.
TL;DR: Optimistic Evaluation complements compile-time analyses with run-time experiments: it evaluates a thunk speculatively, but has an abortion mechanism to back out if it makes a bad choice.
Abstract: Lazy programs are beautiful, but they are slow because they build many thunks. Simple measurements show that most of these thunks are unnecessary: they are in fact always evaluated, or are always cheap. In this paper we describe Optimistic Evaluation --- an evaluation strategy that exploits this observation. Optimistic Evaluation complements compile-time analyses with run-time experiments: it evaluates a thunk speculatively, but has an abortion mechanism to back out if it makes a bad choice. A run-time adaption mechanism records expressions found to be unsuitable for speculative evaluation, and arranges for them to be evaluated more lazily in the future.We have implemented optimistic evaluation in the Glasgow Haskell Compiler. The results are encouraging: many programs speed up significantly (5-25%), some improve dramatically, and none go more than 15% slower.
TL;DR: This work forms flow analysis as an inference problem in a type system built using type inclusion constraints and an algorithm for solving these constraints is given.
Abstract: Nonstrict higher order functional programming languages are notorious for their low run time efficiency. Optimizations based on flow analysis, which determines for each variable x in a program which expressions could have originated the value of x, can improve the situation by removing redundant eval and thunk operations, avoiding thunk updates, and allowing the use of unboxed representations of some data. We formulate flow analysis as an inference problem in a type system built using type inclusion constraints and an algorithm for solving these constraints is also given.
TL;DR: In this paper, a method and apparatus for emulating instructions of a microprocessor (legacy instructions) with an incompatible instruction set which provides increased throughput relative to known emulation systems is presented.
Abstract: A method and apparatus for emulating instructions of a microprocessor (“legacy instructions”) with an incompatible instruction set which provides increased throughput relative to known emulation systems. In particular, each word of legacy memory is translated into an opcode/operand field and a dual function vector/tag field. The vector field represent addresses to legacy instruction emulation routines. The tag field is indexed to table of “thunk” objects, which can be used for various purposes. Such purposes include a disabling part of the legacy software, augmenting the legacy software with native software, and gathering execution statistics without modifying the legacy software.
TL;DR: In this paper, a hybrid virtual function table, incorporating entries created by both legacy and adjustor thunk methods, is presented, which permits backwards compatibility with previously compiled classes, while taking advantage of the faster adjustor-thunk implementation for new code.
Abstract: A system and method for accessing virtual functions from classes compiled with compilers using different virtual function table layouts and/or different function member call protocols. A hybrid virtual function table, incorporating entries created by both legacy and adjustor thunk methods, is disclosed. The hybrid virtual function table permits backwards compatibility with previously compiled classes, while taking advantage of the faster adjustor thunk implementation for new code.