Polymorphic Type Inference for the JNI

  • Michael Furr
  • Jeffrey S. Foster
Part of the Lecture Notes in Computer Science book series (LNCS, volume 3924)


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.


Type Inference Common Object Request Broker Architecture Java Object String Variable Java Method 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


  1. 1.
    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)Google Scholar
  2. 2.
    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)Google Scholar
  3. 3.
    Henglein, F.: Type Inference with Polymorphic Recursion. ACM Transactions on Programming Languages and Systems 15, 253–289 (1993)CrossRefGoogle Scholar
  4. 4.
    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)Google Scholar
  5. 5.
    Liang, S.: The Java Native Interface: Programmer’s Guide and Specification. Addison-Wesley, Reading (1999)Google Scholar
  6. 6.
    Furr, M., Foster, J.S.: Polymorphic Type Inference for the JNI. Technical Report CS-TR-4759, University of Maryland, Computer Science Department (2005)Google Scholar
  7. 7.
    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)Google Scholar
  8. 8.
    Cannasse, N.: (Ocaml javalib),
  9. 9.
    Java-Gnome Developers: (Java bindings for the gnome and gtk libraries),
  10. 10.
    Furr, M., Foster, J.S.: Java SE 6 ”Mustang” Bug 6362203 (2005),
  11. 11.
    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)Google Scholar
  12. 12.
    DeLine, R., Fähndrich, M.: The Fugue Protocol Checker: Is your software Baroque? Technical Report MSR-TR-2004-07, Microsoft Research (2004)Google Scholar
  13. 13.
    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)Google Scholar
  14. 14.
    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)Google Scholar
  15. 15.
    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)Google Scholar
  16. 16.
    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)Google Scholar
  17. 17.
    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)Google Scholar
  18. 18.
    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)Google Scholar
  19. 19.
    Huelsbergen, L.: A Portable C Interface for Standard ML of New Jersey (1996),
  20. 20.
    Leroy, X.: The Objective Caml system (2004) Release 3.08,
  21. 21.
    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)Google Scholar
  22. 22.
    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)Google Scholar
  23. 23.
    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)Google Scholar
  24. 24.
    Gray, D.N., Hotchkiss, J., LaForge, S., Shalit, A., Weinberg, T.: Modern Languages and Microsoft’s Component Object Model. cacm 41, 55–65 (1998)CrossRefGoogle Scholar
  25. 25.
    Hamilton, J.: Interlanguage Object Sharing with SOM. In: Proceedings of the Usenix 1996 Annual Technical Conference, San Diego, California (1996)Google Scholar
  26. 26.
    Object Management Group: Common Object Request Broker Architecture: Core Specification. Version 3.0.3 edn. (2004) Google Scholar
  27. 27.
    Barrett, D.J.: Polylingual Systems: An Approach to Seamless Interoperability. PhD thesis, University of Massachusetts Amherst (1998)Google Scholar
  28. 28.
    Hamilton, J.: Language Integration in the Common Language Runtime. ACM SIGPLAN Notices 38, 19–28 (2003)CrossRefGoogle Scholar
  29. 29.
    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)CrossRefGoogle Scholar
  30. 30.
    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)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2006

Authors and Affiliations

  • Michael Furr
    • 1
  • Jeffrey S. Foster
    • 1
  1. 1.University of MarylandCollege Park

Personalised recommendations