Dynamic dispatching is a major source of run-time overhead in object-o
riented languages, due both to the direct cost of method lookup and to
the indirect effect of preventing other optimizations. To reduce this
overhead, optimizing compilers for object-oriented languages analyze
the classes of objects stored in program variables, with the goal of b
ounding the possible classes of message receivers enough so that the c
ompiler can uniquely determine the target of a message send at compile
time and replace the message send with a direct procedure call. Speci
alization is one important technique for improving the precision of th
is static class information: by compiling multiple versions of a metho
d, each applicable to a subset of the possible argument classes of the
method, more precise static information about the classes of the meth
od's arguments is obtained. Previous specialization strategies have no
t been selective about where this technique is applied, and therefore
tended to significantly increase compile time and code space usage, pa
rticularly for large applications. In this paper, we present a more ge
neral framework for specialization in object-oriented languages and de
scribe a goal-directed specialization algorithm that makes selective d
ecisions to apply specialization to those cases where;it provides the
highest benefit. Our results show that our algorithm improves the perf
ormance of a group of sizeable programs by 65% to 275% while increasin
g compiled code space requirements by only 4% to 10%. Moreover, when c
ompared to the previous state-of-the-art specialization scheme, our al
gorithm improves performance by 11% to 67% while simultaneously reduci
ng code space requirements by 65% to 73%.