An efficient native function interface for Java

Hanspeter Mössenböck, Matthias Grimmer, Manuel Rigger, Lukas Stadler, Roland Schatz

Research output: Chapter in Book/Report/Conference proceedingConference proceedingspeer-review

Abstract

We present an efficient and dynamic approach for calling native functions from within Java. Traditionally, programmers use the Java Native Interface(JNI) to call such functions. This paper in- troduces a new mechanism which we tailored specifically towards calling native functions from Java. We call it the Graal Native Function Interface (GNFI). It is faster than JNI in all relevant cases and more flexible because it avoids the JNI boiler-plate code. GNFI enables the user to directly invoke native code from Java applications. We describe how GNFI creates call stubs for na- tive functions that a just-in-time (JIT) compiler can optimize and how we embed these stubs into Java code. We introduce differ- ent approaches for calling native functions from within compiled and interpreted Java code. In particular, we describe how our ap- proach embeds the call stubs into a Java application so that the JIT-compiled code consists of a direct call to a native function. We evaluate the call overhead of GNFI . The measurements demonstrate a significant performance advantage of GNFI com-pared to JNI and the Java Native Access (JNA). Also, we evaluate our approach against JNI and JNA on a jblas matrix multiplication benchmark. The evaluation shows that GNFI outperforms JNI and JNA in compiled and interpreted mode by a factor of 1.9 in the best case.
Original languageEnglish
Title of host publicationPPPJ´13 Proceedings of the 2013 International Conference on Principles and Practices of Programming on the Java Platform: Virual Machines, Languages, and Tools
PublisherACM New York
Pages35-44
Number of pages10
ISBN (Print)9781450321112
DOIs
Publication statusPublished - 2013

Fields of science

  • 102 Computer Sciences
  • 102009 Computer simulation
  • 102011 Formal languages
  • 102013 Human-computer interaction
  • 102029 Practical computer science
  • 102022 Software development
  • 102024 Usability research

JKU Focus areas

  • Computation in Informatics and Mathematics
  • Engineering and Natural Sciences (in general)

Cite this