Converting Java']Java programs to use generic libraries

被引:23
作者
Donovan, A [1 ]
Kiezun, A [1 ]
Tschantz, MS [1 ]
Ernst, MD [1 ]
机构
[1] MIT, Comp Sci & Artificial Intelligence Lab, Cambridge, MA 02139 USA
关键词
generic types; parameterized types; parametric polymorphism; type inference; instantiation types; !text type='JS']JS[!/text]R-14; !text type='Java']Java[!/text] 1.5; !text type='Java']Java[!/text] 5; raw types;
D O I
10.1145/1035292.1028979
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
Java 1.5 will include a type system (called JSR-14) that supports parametric polymorphism, or generic classes. This will bring many benefits to Java programmers, not least because current Java practice makes heavy use of logically-generic classes, including container classes. Translation of Java source code into semantically equivalent JSR-14 source code requires two steps: parameterization (adding type parameters to class definitions) and instantiation (adding the type arguments at each use of a parameterized class). Parameterization need be done only once for a class, whereas instantiation must be performed for each client, of which there are potentially many more. Therefore, this work focuses on the instantiation problem. We present a technique to determine sound and precise JSR-14 types at each use of a class for which a generic type specification is available. Our approach uses a precise and context-sensitive pointer analysis to determine possible types at allocation sites, and a set-constraint-based analysis (that incorporates guarded, or conditional, constraints) to choose consistent types for both allocation and declaration sites. The technique handles all features of the JSR-14 type system, notably the raw types that provide backward compatibility. We have implemented our analysis in a tool that automatically inserts type parameters into Java code, and we report its performance when applied to a number of real-world Java programs.
引用
收藏
页码:15 / 34
页数:20
相关论文
共 46 条
[1]  
AGESEN O, 1996, ECCOOP, P2
[2]  
Aiken A., 1993, FPCA '93. Conference on Functional Programming Languages and Computer Architecture, P31, DOI 10.1145/165180.165188
[3]  
BACON DF, 1996, OOPSLA, P324
[4]   Making the future safe for the past:: Adding genericity to the Java']Java™ programming language [J].
Bracha, G ;
Odersky, M ;
Stoutamire, D ;
Wadler, P .
ACM SIGPLAN NOTICES, 1998, 33 (10) :183-200
[5]  
BRACHA G, 1998, GJ SPECIFICATION
[6]  
BRACHA G, 2001, SUN MICROSYSTEM 0427
[7]   ON UNDERSTANDING TYPES, DATA ABSTRACTION, AND POLYMORPHISM. [J].
Cardelli, Luca ;
Wegner, Peter .
Computing surveys, 1985, 17 (04) :471-522
[8]  
CARTWRIGHT R, 1998, OOPSLA, P201
[9]  
Cartwright R., 1991, P ACM SIGPLAN 91 C P, P278, DOI DOI 10.1145/113445.113469
[10]  
CHAMBERS C, 1989, OOPSLA, P49