# The complexity of type analysis of object oriented programs

## Abstract

One of the price tags attached to the blessings that OO brings about is a drop in efficiency due to dynamic method dispatch. Much research effort is being spent on the problem of eliminating it, by applying static analysis to predict the set of dynamic types which a variable might store at any given program location. It was previously shown that the problem is NP-hard even if the program under analysis has no multi-level pointers. In this work, we show that under similar conditions, the problem is P-SPACE complete, provided that the program is not recursive. In the presence of recursion, the problem becomes EXP-TIME complete. (These two results also give an exponential time algorithm for a family of type analysis problems.) If multi-level pointers are allowed then the problem becomes EXP-SPACE complete without recursion and DEXP-TIME with it. Further, if the program under analysis may use recursive data structures then the problem becomes undedicable. Despite these, somewhat discouraging, results, we can prove that the type analysis becomes tractable, as evident from past practical experience, if the program under analysis obeys some few simple software engineering rules, while the analysis algorithm makes a corresponding simplifying assumption.

## Keywords

Turing Machine Global Variable Execution Path Instance Variable Dynamic Type## Preview

Unable to display preview. Download preview PDF.

## References

- [B78]Barth J., A Practical Interprocedural Data Flow Analysis Algorithm, CACM 21(9):724–736, 1978.Google Scholar
- [BS96]Bacon, D. F., and P. F. Sweeney,
*Fast Static Analysis of Virtual Function Calls in C++*, OOPSLA'96, pp. 324–341.Google Scholar - [C71]Cook S. A.,
*Characterizations of Pushdown Machines in Terms of Time-Bounded Computers*, JACM 18(1):4–18, Jan. 1971.MATHCrossRefGoogle Scholar - [CH95]Carini P. R. and M. Hind,
*Flow-sensitive interprocedural constant propagation*, PLDI'95, pp. 23–31.Google Scholar - [CGDD97]Chambers C., Grove D., DeFouw G., and J. Dean,
*Call Graph Construction in Object-Oriented Languages*, OOPSLA'97, pp. 108–124.Google Scholar - [DGC95]Dean J., Grove D. and C. Chambers,
*Optimization of Object-Oriented Programs Using Static Class Hierachy Analysis*, ECOOP'95, pp. 77–101.Google Scholar - [DMM96]Diwan, A., Moss J. E. B. and K. S. McKinley,
*Simple and Effective Analysis of Statically-Typed Object-Oriented Programmes*., OOPSLA'96, pp. 292–305.Google Scholar - [J90]Johnson, D.S.,
*A Catalog of Complexity Classes*, in Handbook of Theoretical Computer Science, ed. J.van Leuuwen, MIT Press 1990.Google Scholar - [G97]Golubski W.,
*Data-Flow Analysis in Object-Oriented Programs*, TOOLS USA'97.Google Scholar - [GP97]Golubski W. and B. Pohlers,
*SOLAT — A Simple Object-Oriented Language Analysing Tool*, TOOLS USA'97.Google Scholar - [HLS97]Harrison, T. H., Levine D. L., and D. C. Schimdt.,
*The Design and Performance of a Real-Time COBRA Event Service*, OOPSLA'97, pp. 184–200.Google Scholar - [H97]Horwitz S.,
*Precise Flow-Insensitive May-Alias Analysis is NP-Hard*, TOPLAS Jan. 1997.Google Scholar - [HCU91]Holzle U., Chambers C. and D. Ungar.,
*Optimizing Dynamically-Typed Object-Oriented Languages with Polymorphic Inline Caches*. ECOOP'91.Google Scholar - [HU79]Hopcroft, J.E., and J. D. Ullman,
*Introduction to Automata Theory, Languages and Computation*, Addison-Wesley 1979.Google Scholar - [L92]Landi W.,
*Undecidability of Static Analysis*, LOPLAS 1(4):323–337, Dec. 1992.CrossRefGoogle Scholar - [M92]Meyer B.,
*Eiffel-The Language*, Prentice-Hall, 1992.Google Scholar - [M95]Meyer B.,
*Beware of Polymorphic Catcalls*, White paper, Interactive Software Engineering, 1995. In*http://www.eiffel.com/doc/manuals/technology/typing/cat.html*Google Scholar - [MJ81]Muchnick S. S., and N. D. Jones eds.,
*Program Flow Analysis: Theory and Applications*, Prentice Hall 1981.Google Scholar - [ND81]Nygaard K. and O-J Dahl,
*Simula 1967*, In History of Prog. Lang., ed. R. W. Wexelblat, 1981.Google Scholar - [PBF96]Porat S., Bernstein D., Fedrov Y., and J. Rodrigue,
*Compiler Optimization of C++ Virtual Function Call*, COOTS'96, pp. 3–14.Google Scholar - [PR94]Pande H. D. and B. G. Ryder,
*Static Type Determination for C++*, Usenix C++ Conf. 1994, pp. 85–97.Google Scholar - [PS91]Palsberg J. and M. Schwartzbach,
*Object-Oriented Type Inference*, OOSPLA'91,pp. 146–161.Google Scholar - [S97]Stroustrup B.,
*The C++ Programming Language*. 3rd ed. Addison Wesley, 1997.Google Scholar - [SP82]Sharir M. and A. Pnueli,
*Two Approaches to Interprocedural Data Flow Analysis*, in [MJ81].Google Scholar - [VCH96]Verbrugge, C., Phong C., and L. Hendren.
*Generalized Constant Propagation—A Study in C*. In Proc. of the 6th International Conference on Compiler Construction (CC'96), pages 74–90, Link• ping, Sweden, Springer LNCS 1060, 1996.Google Scholar - [WZ91]Wegman, M. N. and F. K. Zadek,
*Constant Propagation with Conditional Branches*, ACM TOPLAS 13(2):181–210, Apr. 1991.CrossRefGoogle Scholar - [ZCC97]Zendra O., Colnet C, and S. Collin,
*Efficient Dynamic Dispatch without Virtual Function Tables: The Small Eiffel Compiler*, OOPSLA'97, pp. 125–141.Google Scholar