Abstract
We present a multi-lingual type inference system for checking type safety of programs that use the Java Native Interface (JNI). The JNI uses specially-formatted strings to represent class and field names as well as method signatures, and so our type system tracks the flow of string constants through the program. Our system embeds string variables in types, and as those variables are resolved to string constants during inference they are replaced with the structured types the constants represent. This restricted form of dependent types allows us to directly assign type signatures to each of the more than 200 functions in the JNI. Moreover, it allows us to infer types for user-defined functions that are parameterized by Java type strings, which we have found to be common practice. Our inference system allows such functions to be treated polymorphically by using instantiation constraints, solved with semi-unification, at function calls. Finally, we have implemented our system and applied it to a small set of benchmarks. Although semi-unification is undecidable, we found our system to be scalable and effective in practice. We discovered 155 errors and 36 cases of suspicious programming practices in our benchmarks.
This research was supported in part by NSF CCF-0346982 and CCF-0430118.
Chapter PDF
References
Rehof, J., Fähndrich, M.: Type-Based Flow Analysis: From Polymorphic Subtyping to CFL-Reachability. In: Proceedings of the 28th Annual ACM Symposium on Principles of Programming Languages, London, United Kingdom (2001)
Fähndrich, M., Rehof, J., Das, M.: Scalable Context-Sensitive Flow Analysis using Instantiation Constraints. In: Proceedings of the 2000 ACM Conference on Programming Language Design and Implementation, Vancouver B.C., Canada (2000)
Henglein, F.: Type Inference with Polymorphic Recursion. ACM Transactions on Programming Languages and Systems 15, 253–289 (1993)
Furr, M., Foster, J.S.: Checking Type Safety of Foreign Function Calls. In: Proceedings of the 2005 ACM Conference on Programming Language Design and Implementation, Chicago, Illinois, pp. 62–72 (2005)
Liang, S.: The Java Native Interface: Programmer’s Guide and Specification. Addison-Wesley, Reading (1999)
Furr, M., Foster, J.S.: Polymorphic Type Inference for the JNI. Technical Report CS-TR-4759, University of Maryland, Computer Science Department (2005)
Necula, G.C., McPeak, S., Rahul, S.P., Weimer, W.: CIL: Intermediate Language and Tools for Analysis and Transformation of C Programs. In: Compiler Construction, 11th International Conference, Grenoble, France (2002)
Cannasse, N.: (Ocaml javalib), http://team.motion-twin.com/ncannasse/javaLib/
Java-Gnome Developers: (Java bindings for the gnome and gtk libraries), http://java-gnome.sourceforge.net
Furr, M., Foster, J.S.: Java SE 6 ”Mustang” Bug 6362203 (2005), http://bugs.sun.com/bugdatabase/viewbug.do?bugid=6362203
Christensen, A.S., Møller, A., Schwartzbach, M.I.: Precise Analysis of String Expressions. In: Static Analysis, 10th International Symposium, San Diego, CA, USA (2003)
DeLine, R., Fähndrich, M.: The Fugue Protocol Checker: Is your software Baroque? Technical Report MSR-TR-2004-07, Microsoft Research (2004)
Gould, C., Su, Z., Devanbu, P.: Static Checking of Dynamically Generated Queries in Database Applications. In: Proceedings of the 26th International Conference on Software Engineering, Edinburgh, Scotland, UK, pp. 645–654 (2004)
Thiemann, P.: Grammar-Based Analysis of String Expressions. In: Proceedings of the 2005 ACM SIGPLAN International Workshop on Types in Language Design and Implementation, Long Beach, CA, USA (2005)
Ernst, S.N.: Static Typing for Dynamic Messages. In: Proceedings of the 25th Annual ACM Symposium on Principles of Programming Languages, San Diego, California (1998)
Blume, M.: No-Longer-Foreign: Teaching an ML compiler to speak C “natively”. In: BABEL 2001: First International Workshop on Multi-Language Infrastructure and Interoperability, Firenze, Italy (2001)
Finne, S., Leijen, D., Meijer, E., Jones, S.P.: Calling hell from heaven and heaven from hell. In: Proceedings of the Fourth ACM SIGPLAN International Conference on Functional Programming, Paris, France, pp. 114–125 (1999)
Fisher, K., Pucella, R., Reppy, J.: A framework for interoperability. In: BABEL 2001: First International Workshop on Multi-Language Infrastructure and Interoperability, Firenze, Italy (2001)
Huelsbergen, L.: A Portable C Interface for Standard ML of New Jersey (1996), http://www.smlnj.org//doc/SMLNJ-C/smlnj-c.ps
Leroy, X.: The Objective Caml system (2004) Release 3.08, http://caml.inria.fr/distrib/ocaml-3.08/ocaml-3.08-refman.pdf
Beazley, D.M.:SWIG: An easy to use tool for integrating scripting languages with C and C++. In: USENIX Fourth Annual Tcl/Tk Workshop (1996)
Bubba, J.F., Kaplan, A., Wileden, J.C.: The Exu Approach to Safe, Transparent and Lightweight Interoperability. In: 25th International Computer Software and Applications Conference (COMPSAC 2001), Chicago, IL, USA (2001)
Auerbach, J., Barton, C., Chu-Carroll, M., Raghavachari, M.: Mockingbird: Flexible stub compilation from paris of declarations. In: Proceedings of the 19th International Conference on Distributed Computing Systems, Austin, TX, USA (1999)
Gray, D.N., Hotchkiss, J., LaForge, S., Shalit, A., Weinberg, T.: Modern Languages and Microsoft’s Component Object Model. cacm 41, 55–65 (1998)
Hamilton, J.: Interlanguage Object Sharing with SOM. In: Proceedings of the Usenix 1996 Annual Technical Conference, San Diego, California (1996)
Object Management Group: Common Object Request Broker Architecture: Core Specification. Version 3.0.3 edn. (2004)
Barrett, D.J.: Polylingual Systems: An Approach to Seamless Interoperability. PhD thesis, University of Massachusetts Amherst (1998)
Hamilton, J.: Language Integration in the Common Language Runtime. ACM SIGPLAN Notices 38, 19–28 (2003)
Meijer, E., Perry, N., van Yzendoorn, A.: Scripting.NET using mondrian. In: Knudsen, J.L. (ed.) ECOOP 2001. LNCS, vol. 2072, p. 150. Springer, Heidelberg (2001)
Grechanik, M., Batory, D., Perry, D.E.: Design of large-scale polylingual systems. In: Proceedings of the 26th International Conference on Software Engineering, Edinburgh, Scotland, UK, pp. 357–366 (2004)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2006 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Furr, M., Foster, J.S. (2006). Polymorphic Type Inference for the JNI. In: Sestoft, P. (eds) Programming Languages and Systems. ESOP 2006. Lecture Notes in Computer Science, vol 3924. Springer, Berlin, Heidelberg. https://doi.org/10.1007/11693024_21
Download citation
DOI: https://doi.org/10.1007/11693024_21
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-33095-0
Online ISBN: 978-3-540-33096-7
eBook Packages: Computer ScienceComputer Science (R0)