CS 4448 - Spring 1998
Object-Oriented Programming and Design
Talk 10.2.1
by
Phil Hugger
Unreachable Procedures in OOP
Introduction
- Unreachable procedures unnecessarily bloat an executable.
- Requiring more disk space
- Changes the cache/paging behavior - more swaps
- Programmers do not write code they don't intend to use.
- Object-oriented writing may contain unreachable code, since not
all behavior patterns might be used.
- Statically linked languages are primarily affected
- All procedures in an object module are linked if any of them
are referenced.
- To minimize library sizes, programmers split modules into smaller
groups.
- Library splitting is not always possible
- Destroys organizational structure
- Not suitable for OOP
- Dead code elimination
- Useless/unreachable code is removed
- Detection of dead code requires entire program to be present.
- Global procedures have a scope larger than a single file,
so the compiler cannot detect usage.
Three main sources of unreachable procedures
- OOP programming style
- Behavior of objects is more important than implementation
- Class design - all possible interfaces and manipulations are defined,
but only a few may be used.
- Inheritance - Program might not use inherited methods
- Longer inheritance chains = higher probability of unused code
- Virtual functions - derived classes may redefine methods, the original
definitions are inherited but unused.
- Design of libraries
- Many common methods for fundamental data types are defined, but
not all of them may be used
- Debugging
- In a released program, debugging routines are never called and
are unreachable
Detection of unreachable code
- Build a directed call graph
- Nodes are procedures
- Edges are statically present procedure calls
- A conservative algorithm cannot detect dynamically unreachable code.
Code analysis
- Large programs were selected, since small ones give misleading
results
- C/Fortran programs without system libraries have 0-5% unreachable
code, C++ OOP programs have up to 26% unreachable code.
- In programs with system libraries, percentages are similar but C++
is consistently higher.
- Unreachable procedure analysis - two groups
- Never called (no predecessors) - 45-82%, average 64%
- Have predecessors, no predecessor is reachable from program.
- Libraries/File splitting
- Splitting library files decreases unused methods
- Unreachable user routines will still include library routines
- Splitting is inconvenient or impossible at times
- Shared variables/procedures (static) between routines mean
that they cannot be separated
Copyright © University of Colorado. All rights reserved.
Revised: April 14, 1998