Skip to main content
QUICK REVIEW

[Paper Review] Performance comparison between Java and JNI for optimal implementation of computational micro-kernels

Nassim Halli, Henri‐Pierre Charles|arXiv (Cornell University)|Dec 21, 2014
Parallel Computing and Optimization TechniquesComputer Science5 citations
TL;DR

This paper compares Java and JNI for implementing computational micro-kernels, analyzing performance trade-offs between JIT compilation and native code via JNI. It identifies that JNI outperforms Java for compute-intensive kernels due to superior optimization (vectorization, out-of-order execution), but JNI call overhead limits gains unless computation per invocation exceeds a threshold, with data alignment and native memory access significantly impacting performance.

ABSTRACT

General purpose CPUs used in high performance computing (HPC) support a vector instruction set and an out-of-order engine dedicated to increase the instruction level parallelism. Hence, related optimizations are currently critical to improve the performance of applications requiring numerical computation. Moreover, the use of a Java run-time environment such as the HotSpot Java Virtual Machine (JVM) in high performance computing is a promising alternative. It benefits from its programming flexibility, productivity and the performance is ensured by the Just-In-Time (JIT) compiler. Though, the JIT compiler suffers from two main drawbacks. First, the JIT is a black box for developers. We have no control over the generated code nor any feedback from its optimization phases like vectorization. Secondly, the time constraint narrows down the degree of optimization compared to static compilers like GCC or LLVM. So, it is compelling to use statically compiled code since it benefits from additional optimization reducing performance bottlenecks. Java enables to call native code from dynamic libraries through the Java Native Interface (JNI). Nevertheless, JNI methods are not inlined and require an additional cost to be invoked compared to Java ones. Therefore, to benefit from better static optimization, this call overhead must be leveraged by the amount of computation performed at each JNI invocation. In this paper we tackle this problem and we propose to do this analysis for a set of micro-kernels. Our goal is to select the most efficient implementation considering the amount of computation defined by the calling context. We also investigate the impact on performance of several different optimization schemes which are vectorization, out-of-order optimization, data alignment, method inlining and the use of native memory for JNI methods.

Motivation & Objective

  • To determine the optimal implementation (pure Java vs JNI) for computational micro-kernels in high-performance computing (HPC) using the HotSpot JVM.
  • To analyze the performance trade-off between JIT compilation limitations (lack of control, reduced optimization) and JNI's higher call overhead but deeper static optimization.
  • To quantify how factors like arithmetic intensity, vectorization, out-of-order execution, data alignment, and memory access (heap vs native) affect performance.
  • To identify the flop-per-invocation threshold where JNI becomes more efficient than pure Java due to better optimization opportunities.

Proposed method

  • Benchmarked a set of numerical micro-kernels (e.g., array addition, horizontal sum, Horner) on an x86-64 Sandy Bridge system with AVX support.
  • Measured performance in flop/s across multiple configurations: pure Java, JNI with heap memory, JNI with native memory, and varying optimization levels.
  • Used arithmetic intensity (AI = flop-per-invocation / memory-per-invocation) to classify kernels as memory-bound or CPU-bound.
  • Applied static compilation (GCC) for JNI code and analyzed vectorization, out-of-order execution, and inlining effects.
  • Evaluated data alignment impact by varying array alignment (8-byte vs 16-byte) and measuring performance degradation.
  • Measured call overhead by disabling inlining and comparing JNI vs Java method invocation costs.

Experimental results

Research questions

  • RQ1At what flop-per-invocation threshold does JNI outperform pure Java for micro-kernels?
  • RQ2How do vectorization and out-of-order execution in native code improve performance compared to JIT-compiled Java?
  • RQ3What is the performance impact of data misalignment on vectorized micro-kernels in Java and JNI?
  • RQ4How does using native memory instead of heap memory affect JNI call overhead and performance?
  • RQ5To what extent does method inlining reduce the performance penalty of JNI method calls?

Key findings

  • JNI outperforms pure Java by a speed-up factor of up to 2 for micro-kernels with memory-per-invocation below L3 cache size, due to effective vectorization and out-of-order optimization.
  • For the Horner data-1st kernel, combining vectorization and out-of-order execution in JNI enabled performance to reach the CPU peak, while JIT could not vectorize such idioms.
  • Data misalignment caused a 45% performance degradation in the Array addition kernel when one array was 8-byte aligned and the other 16-byte aligned, due to unaligned memory access.
  • JNI call overhead is dominated by heap memory access: retrieving and releasing array pointers from the Java heap incurs a ~40% performance penalty, which is reduced when using native memory.
  • Disabling inlining in Java methods reduced performance by ~20%, indicating that inlining significantly mitigates the cost of method calls.
  • The performance penalty for low-memory micro-kernels is call-bound, with the constant loop cost dominating; this penalty is more pronounced in JNI due to callback overhead.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.