// Path: ohc-core/src/main/java/org/caffinitas/ohc/alloc/IAllocator.java
// public interface IAllocator
// {
//     long allocate(long size);
//     void free(long peer);
//     long getTotalAllocated();
// }
// 
// Path: ohc-core/src/main/java/org/caffinitas/ohc/alloc/JNANativeAllocator.java
// public final class JNANativeAllocator implements IAllocator
// {
//     public long allocate(long size)
//     {
//         try
//         {
//             return Native.malloc(size);
//         }
//         catch (OutOfMemoryError oom)
//         {
//             return 0L;
//         }
//     }
// 
//     public void free(long peer)
//     {
//         Native.free(peer);
//     }
// 
//     public long getTotalAllocated()
//     {
//         return -1L;
//     }
// }
// 
// Path: ohc-core/src/main/java/org/caffinitas/ohc/alloc/UnsafeAllocator.java
// public final class UnsafeAllocator implements IAllocator
// {
//     static final Unsafe unsafe;
// 
//     static
//     {
//         try
//         {
//             Field field = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
//             field.setAccessible(true);
//             unsafe = (sun.misc.Unsafe) field.get(null);
//         }
//         catch (Exception e)
//         {
//             throw new AssertionError(e);
//         }
//     }
// 
//     public long allocate(long size)
//     {
//         try
//         {
//             return unsafe.allocateMemory(size);
//         }
//         catch (OutOfMemoryError oom)
//         {
//             return 0L;
//         }
//     }
// 
//     public void free(long peer)
//     {
//         unsafe.freeMemory(peer);
//     }
// 
//     public long getTotalAllocated()
//     {
//         return -1L;
//     }
// }


import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import org.caffinitas.ohc.alloc.IAllocator;
import org.caffinitas.ohc.alloc.JNANativeAllocator;
import org.caffinitas.ohc.alloc.UnsafeAllocator;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Warmup;
/*
 *      Copyright (C) 2014 Robert Stupp, Koeln, Germany, robert-stupp.de
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package org.caffinitas.ohc.jmh;



@BenchmarkMode({ /*Mode.AverageTime, */Mode.Throughput })
@State(Scope.Benchmark)
@Warmup(iterations = 2)
@Measurement(iterations = 3)
@Threads(4)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@Fork(value = 1, jvmArgsAppend = "-Xmx512M")
public class AllocatorBenchmark
{
    @Param({ "128", /*"256", "512", "1024", "1536", "2048", "4096", */"8192" })
    private int size = 128;
    @Param({ "Unsafe", "JNA" })
    private String allocatorType = "JNA";

// Path: ohc-core/src/main/java/org/caffinitas/ohc/alloc/IAllocator.java
// public interface IAllocator
// {
//     long allocate(long size);
//     void free(long peer);
//     long getTotalAllocated();
// }
// 
// Path: ohc-core/src/main/java/org/caffinitas/ohc/alloc/JNANativeAllocator.java
// public final class JNANativeAllocator implements IAllocator
// {
//     public long allocate(long size)
//     {
//         try
//         {
//             return Native.malloc(size);
//         }
//         catch (OutOfMemoryError oom)
//         {
//             return 0L;
//         }
//     }
// 
//     public void free(long peer)
//     {
//         Native.free(peer);
//     }
// 
//     public long getTotalAllocated()
//     {
//         return -1L;
//     }
// }
// 
// Path: ohc-core/src/main/java/org/caffinitas/ohc/alloc/UnsafeAllocator.java
// public final class UnsafeAllocator implements IAllocator
// {
//     static final Unsafe unsafe;
// 
//     static
//     {
//         try
//         {
//             Field field = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
//             field.setAccessible(true);
//             unsafe = (sun.misc.Unsafe) field.get(null);
//         }
//         catch (Exception e)
//         {
//             throw new AssertionError(e);
//         }
//     }
// 
//     public long allocate(long size)
//     {
//         try
//         {
//             return unsafe.allocateMemory(size);
//         }
//         catch (OutOfMemoryError oom)
//         {
//             return 0L;
//         }
//     }
// 
//     public void free(long peer)
//     {
//         unsafe.freeMemory(peer);
//     }
// 
//     public long getTotalAllocated()
//     {
//         return -1L;
//     }
// }


// Path: ohc-jmh/src/main/java/org/caffinitas/ohc/jmh/AllocatorBenchmark.java
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import org.caffinitas.ohc.alloc.IAllocator;
import org.caffinitas.ohc.alloc.JNANativeAllocator;
import org.caffinitas.ohc.alloc.UnsafeAllocator;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Warmup;

/*
 *      Copyright (C) 2014 Robert Stupp, Koeln, Germany, robert-stupp.de
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package org.caffinitas.ohc.jmh;



@BenchmarkMode({ /*Mode.AverageTime, */Mode.Throughput })
@State(Scope.Benchmark)
@Warmup(iterations = 2)
@Measurement(iterations = 3)
@Threads(4)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@Fork(value = 1, jvmArgsAppend = "-Xmx512M")
public class AllocatorBenchmark
{
    @Param({ "128", /*"256", "512", "1024", "1536", "2048", "4096", */"8192" })
    private int size = 128;
    @Param({ "Unsafe", "JNA" })
    private String allocatorType = "JNA";

    private IAllocator allocator;