Polymorphism Metrics

Last updated: November 27, 2002

Polymorphism is a salient feature of object-oriented languages like Java. A polymorphic call in Java takes the form of an invokeVirtual or invokeInterface byte code. The target method of a polymorphic call depends on the run time type of the object receiving the call. In programs that do not employ inheritance, this target never changes and no call is truly polymorphic. The amount of polymorphism can therefore serve as a measurement of a program's object-orientedness.

Some of the metrics have two variants. In the first variant, we take into consideration the number of receiver types, in the second we use the number of different target methods. There are more receiver types than targets, since two different object types may inherit the same method from a common super class. Some optimization techniques, such as class hierarchy analysis, optimize call sites with a restricted number of targets. Others, such as inline caching [13], optimize call sites with a restricted number of receiver types.

Polymorphism Metrics

Of these metrics, polymorphism.targetPolyDensity.value has the advantage that devirtualization studies often report this number. However, for a more dynamic measurement of run time polymorphic behavior, polymorphism.receiverCacheMissRate.value is preferred.

Back to Top