JNI faster than Unsafe?

Robert Stupp snazy at snazy.de
Sat Feb 7 09:46:19 UTC 2015


I think I found the reason why Unsafe.allocateMemory is slower in os::malloc : inc_stat_counter

> Am 07.02.2015 um 10:02 schrieb Robert Stupp <snazy at snazy.de>:
> 
> Hi there,
> 
> I've setup a single microbenchmark just to know which off-heap memory allocation is faster on Linux + OSX. Candidates were Unsafe.allocateMemory and JNA's Native.malloc(). Both either against "raw" OS and against a preloaded jemalloc (LD_PRELOAD).
> 
> My initial suspicion was, that both (Unsafe vs. Native) should perform quite equally since both methods are basically just wrappers for C malloc(). But they don't.
> 
> Native.malloc() is much faster compared to Unsafe.allocateMemory().
> Depending on the individual microbenchmark, Native.malloc() is up to 3 times faster than Unsafe.allocateMemory().
> 
> Here's a spreadsheet, that I've worked out during the benchmark.
> https://docs.google.com/spreadsheets/d/1kHqPArBXKI1izSRBcGyfomuQqq5VJHQUkrMxulqOpQc/edit#gid=0 <https://docs.google.com/spreadsheets/d/1kHqPArBXKI1izSRBcGyfomuQqq5VJHQUkrMxulqOpQc/edit#gid=0>
> (you may safely ignore the jemalloc-via-JNA stuff)
> 
> The JMH source is here: https://github.com/snazy/cassandra/blob/8714-row-cache-jemalloc/test/microbench/org/apache/cassandra/test/microbench/OffHeapAllocationBench.java <https://github.com/snazy/cassandra/blob/8714-row-cache-jemalloc/test/microbench/org/apache/cassandra/test/microbench/OffHeapAllocationBench.java>
> 
>> Robert Stupp
> @snazy
> 

—
Robert Stupp
@snazy



More information about the hotspot-dev mailing list