June 3, Tuesday
12:00 – 14:00
Are We Ready for a Safer Construction Environment?
Computer Science seminar
Lecturer : Yossi Gil
Affiliation : The Technion
Location : 202/37
Host : Prof. Mira Balaban
Women who have given birth can testify that the process is not infinitesimally short. Objects are no different than babies in this respect: it takes time to mature a raw memory block into a live object, and during that time computation may occur.
Consider a class /D/ that inherits from a class /B/. Then, (in most object oriented (OO) programming languages) the process of construction of a /D/-object includes an invocation of a suitable constructor of /B/, followed by an invocation of a constructor of /D/.
What is the status of the object in the course of the evaluation of the constructor of /B/? On one hand, this object cannot be thought of as a mature, ordinary object of class /D/, since /D/'s constructor was not invoked yet. On the other hand, thinking of the object as an instance of class /B/, may lead to surprising results, e.g., in the case that /B/ is an abstract class. Concretely, suppose that /B/'s constructor invokes a dynamically bound member function implemented in both /B/ and /D/. The dominating /thesis/, taken by languages such as Java and C#, is that of /dynamic binding/ within constructors, i.e., /D/'s implementation is executed. The /anti-thesis/ of /static binding,/ taken in languages such as C++, dictates that /B/'s implementation is executed.
This research sets its objective in understanding how such ``half-baked'' objects are used in actual programs. In a data set comprising a dozen software collection with over sixty thousand class, we found that although the potential for such a situation is non negligible i.e., there are many constructors that make calls to methods which /may /be overridden in derived classes, this potential is realized scarcely. We found this behavior in less than 1.5% of all constructors, inheriting from less than 0.5% of all constructors.
Further, we find that over 80% of these incidents fall into eight "patterns", which can be relatively easily transformed into equivalent code which does not make pre-mature calls to methods.
Another similarly undesirable situation occurs when a constructor exposes the self identity to external code, and this external code chooses to call methods overridden in the derived class.
Our estimates on the prevalence of this exposition are less accurate due to the complexity of interprocedural dataflow analysis. The resulting estimates are high, but there are indications that it arises from a relatively small number of base constructors.
Joint work with Tali Shragai