Dynamic C++ Classes

A lightweight mechanism to update code in a running program

Gísli Hjálmtýsson
AT&T Labs - Research
AT&T Shannon Laboratories
gisli@research.att.com

Robert Gray
Thayer School of Engineering
Dartmouth College
rgray@cs.dartmouth.edu

[ papers, talks, code ]

UPDATE 18 Aug 2000 Release 1.2 is now available on the Code Distribution page. Release 1.2 is a bug-fix release.

Abstract:

Techniques for dynamically adding new code to a run-ning program already exist in various operating sys-tems, programming languages and runtime environ-ments. Most of these systems have not found their way into common use, however, since they require pro-grammer retraining and invalidate previous software investments. In addition, many of the systems are too high-level for performance-critical applications. This paper presents an implementation of dynamic classes for the C++ language. Dynamic classes allow run-time updates of an executing C++ program at the class level. Our implementation is a lightweight proxy class that exploits only common C++ features and can be com-piled with most modern compilers. The proxy supports version updates of existing classes as well as the intro-duction of new classes. Our language choice and proxy implementation is targeted towards performance-critical applications such as low-level networking in which the use of C++ is already widespread.

Introduction:

Every modern organization has software systems that are critical to its mission and must operate continuously. A network provider, for example, loses both revenue and customer goodwill if its switches or service con-trollers are temporarily unavailable. Because of the need for continuous operation, planned downtime is hard to schedule, and unplanned downtime can have cataclysmic effects. When a new service or security threat makes changes unavoidable, the changes are de-signed to minimize downtime, reducing system mainte-nance to repetitious patching. Such patching breaks the program's data abstractions and encapsulation, reduces modularity and increases coupling. At the same time, ignoring needed maintenance and development leads to an outdated system, one that eventually will become an obstacle to organizational development.

Complicating the situation is that, as network computing has transformed many industries, continuous change has become just as important as continuous operation. Rapid introduction of new functionality and dynamic adaptation to volatile needs is essential. Systems, par-ticularly telecommunications systems, must be custom-ized on a very fine time scale, either due to user demand or to load and usage fluctuations.

An effective way to allow both continuous operation and continuous change is through dynamic code updates. New code is added to a running program without halting the program, thus introducing new functionality but avoiding downtime. The idea of adding new code to a running program dates back to the earliest elec-tronic computers, and dynamic linking is now available for nearly all operating systems and programming languages. However, since languages such as C++ do not directly support the creation of dynamically loadable modules, preserving program-level abstractions across the dynamic-linking interface is difficult. In particular, current dynamic linkers break the type safety of C++, since they are oriented towards functions rather than types and classes.

Recently, new environments and languages have been designed to dynamically download and execute pro-grams. In particular, Java has become extremely popular and is in widespread use. However, although a Java class loader can lazily load the classes that make up an application, it has no knowledge of class versions and can only load each class once. In addition, the relatively poor performance of Java makes it impractical for low-level applications.

Here we propose dynamic classes. Dynamic classes allow new functionality to be introduced into an exe-cuting C++ program without sacrificing type safety, performance or the object-oriented paradigm. Replacing an entire class, rather than individual functions, honors the semantic integrity of the program and minimizes interference between the update and the on-going computation. Although comparable techniques exist in interpreted languages and agent-based environments, our objective is to use these mechanisms in telecommunication (and other) systems where performance is the primary concern. We outline a C++ proxy-based implementation that requires only existing features of the language and is usable with any complete C++ compiler.

Papers:

Robert Gray and Gísli Hjálmtýsson, "Dynamic C++ Classes," to appear in C/C++ Users Journal, October 1999

Gísli Hjálmtýsson and Robert Gray, "Dynamic C++ classes - A Lightweight mechanism to update code in a running program," in proceedings of the USENIX Annual Technical Conference, pp. 65-76, June, 1998 (G. Hjalmtyssons' slides from Usenix)

Talks:

Dynamic C++ classes, given by Gísli Hjálmtýsson, Murray Hill, 1997

Dynamic C++ Classes, given by R. Gray at Murray Hill, NJ, 1996

Code:

The source code is available here. Please report problems and suggestions to Bob Gray. We would very much appreciate your feedback and example applications. We will put more example applications in the distribution as they become (publicly) available.



Last updated 30 November 1999, Gísli Hjálmtýsson, gisli@research.att.com