Git Product home page Git Product logo

unsafe's Introduction

Unsafe Build Status Libraries.io

by Andrew Brampton (bramp.net)

GitHub | JavaDoc

This is a collection of tools that make use of the sun.misc.Unsafe class. This Unsafe class allows direct access to memory within the JVM, which is extremely dangerous, but fun :).

  • unsafe-helper - Contains some simple methods that make using sun.misc.Unsafe easier.
  • unsafe-collection - An example List modelled on the ArrayList, which instead of storing reference to objects within the collection, instead copies the elements directly into the list. This has a few interesting properties
    • Less total memory is required for the list and contained objects. Reducing GC overheads.
    • The objects are guranteed to be contingous in memory, which may provide some good CPU cache benefits.
    • Objects are copied into the list, this copy overhead may not be worth it, and you lose many of the reference semantics you would be used t
  • unsafe-unroller - At runtimes generates optomal bytecode to copy objects with the Unsafe class.
  • unsafe-benchmark - Code to benchmark everything using the JMH framework.
  • unsafe-tests - Some simple test classes to help with tests of the other modules.

Read about this in a series of articles:

Use

Requires Java 7 or higher. To include use the following Maven dependency:

<dependencies>
    <dependency>
        <groupId>net.bramp.unsafe</groupId>
        <artifactId>unsafe-helper</artifactId>
        <version>1.0</version>
    </dependency>
</dependencies>

Build

To build use maven, e.g mvn

To release to maven central, we use the Sonatype OSS repo, and maven-release-plugin:

mvn release:prepare
mvn release:perform

Benchmarks

Read more about the benchmarks at bramp.net

cd unsafe-benchmark
mvn
java -jar target/benchmarks.jar | tee logs
...
# JMH 1.10.3 (released 9 days ago)
# VM version: JDK 1.8.0_45-internal, VM 25.45-b02

Benchmark                                       Mode     Cnt     Score          Error  Units
UnrolledCopierBenchmark.HandUnrolledState.test  thrpt    25      438819259.527  ±      14364692.101  ops/s
UnrolledCopierBenchmark.LoopState.test          thrpt    25      196408390.244  ±      2173851.339   ops/s
UnrolledCopierBenchmark.UnrolledState.test      thrpt    25      458324068.892  ±      6192069.477   ops/s

Benchmark                                  (clazz)                      (size)    Mode   Cnt    Score   Error  Units
ArrayListBenchmark.testIterate             ArrayList<LongPoint>         80000000  avgt   5      2.266   ±      0.229  s/op
ArrayListBenchmark.testIterate             ArrayList<LongPoint>         20000000  avgt   5      0.552   ±      0.019  s/op
ArrayListBenchmark.testIterate             ArrayList<LongPoint>         5000000   avgt   5      0.136   ±      0.004  s/op
ArrayListBenchmark.testSort                ArrayList<LongPoint>         80000000  avgt   5      70.310  ±      3.939  s/op
ArrayListBenchmark.testSort                ArrayList<LongPoint>         20000000  avgt   5      14.754  ±      0.541  s/op
ArrayListBenchmark.testSort                ArrayList<LongPoint>         5000000   avgt   5      3.250   ±      0.139  s/op

Benchmark                                  (clazz)                      (size)    Mode   Cnt    Score   Error  Units
ArrayListBenchmark.testIterate             UnsafeArrayList<LongPoint>   80000000  avgt   5      1.790   ±      0.030  s/op
ArrayListBenchmark.testIterate             UnsafeArrayList<LongPoint>   20000000  avgt   5      0.449   ±      0.016  s/op
ArrayListBenchmark.testIterate             UnsafeArrayList<LongPoint>   5000000   avgt   5      0.112   ±      0.001  s/op
ArrayListBenchmark.testListIterateInPlace  UnsafeArrayList<LongPoint>   80000000  avgt   5      0.442   ±      0.023  s/op
ArrayListBenchmark.testListIterateInPlace  UnsafeArrayList<LongPoint>   20000000  avgt   5      0.110   ±      0.003  s/op
ArrayListBenchmark.testListIterateInPlace  UnsafeArrayList<LongPoint>   5000000   avgt   5      0.028   ±      0.002  s/op
ArrayListBenchmark.testSort                UnsafeArrayList<LongPoint>   80000000  avgt   5      18.690  ±      3.158  s/op
ArrayListBenchmark.testSort                UnsafeArrayList<LongPoint>   20000000  avgt   5      3.414   ±      0.034  s/op
ArrayListBenchmark.testSort                UnsafeArrayList<LongPoint>   5000000   avgt   5      0.682   ±      0.014  s/op

Benchmark                                  (clazz)                      (size)    Mode   Cnt    Score   Error  Units
ArrayListBenchmark.testIterate             ArrayList<FourLongs>         80000000  avgt   5      2.277   ±      0.211  s/op
ArrayListBenchmark.testIterate             ArrayList<FourLongs>         20000000  avgt   5      0.557   ±      0.023  s/op
ArrayListBenchmark.testIterate             ArrayList<FourLongs>         5000000   avgt   5      0.140   ±      0.007  s/op
ArrayListBenchmark.testSort                ArrayList<FourLongs>         80000000  avgt   5      79.673  ±      6.119  s/op
ArrayListBenchmark.testSort                ArrayList<FourLongs>         20000000  avgt   5      16.705  ±      1.353  s/op
ArrayListBenchmark.testSort                ArrayList<FourLongs>         5000000   avgt   5      3.673   ±      0.156  s/op

Benchmark                                  (clazz)                      (size)    Mode   Cnt    Score   Error  Units
ArrayListBenchmark.testIterate             UnsafeArrayList<FourLongs>   80000000  avgt   5      2.126   ±      0.019  s/op
ArrayListBenchmark.testIterate             UnsafeArrayList<FourLongs>   20000000  avgt   5      0.533   ±      0.004  s/op
ArrayListBenchmark.testIterate             UnsafeArrayList<FourLongs>   5000000   avgt   5      0.133   ±      0.002  s/op
ArrayListBenchmark.testListIterateInPlace  UnsafeArrayList<FourLongs>   80000000  avgt   5      0.648   ±      0.019  s/op
ArrayListBenchmark.testListIterateInPlace  UnsafeArrayList<FourLongs>   20000000  avgt   5      0.163   ±      0.005  s/op
ArrayListBenchmark.testListIterateInPlace  UnsafeArrayList<FourLongs>   5000000   avgt   5      0.040   ±      0.006  s/op
ArrayListBenchmark.testSort                UnsafeArrayList<FourLongs>   80000000  avgt   5      24.822  ±      0.790  s/op
ArrayListBenchmark.testSort                UnsafeArrayList<FourLongs>   20000000  avgt   5      4.843   ±      0.075  s/op
ArrayListBenchmark.testSort                UnsafeArrayList<FourLongs>   5000000   avgt   5      1.020   ±      0.017  s/op

Benchmark                                  (clazz)                      (size)    Mode   Cnt    Score   Error  Units
ArrayListBenchmark.testIterate             ArrayList<EightLongs>        80000000  avgt   5      2.792   ±      0.072  s/op
ArrayListBenchmark.testIterate             ArrayList<EightLongs>        20000000  avgt   5      0.564   ±      0.022  s/op
ArrayListBenchmark.testIterate             ArrayList<EightLongs>        5000000   avgt   5      0.138   ±      0.007  s/op
ArrayListBenchmark.testSort                ArrayList<EightLongs>        80000000  avgt   5      97.687  ±      4.860  s/op
ArrayListBenchmark.testSort                ArrayList<EightLongs>        20000000  avgt   5      20.084  ±      1.124  s/op
ArrayListBenchmark.testSort                ArrayList<EightLongs>        5000000   avgt   5      4.474   ±      0.248  s/op

Benchmark                                  (clazz)                      (size)    Mode   Cnt    Score   Error  Units
ArrayListBenchmark.testIterate             UnsafeArrayList<EightLongs>  80000000  avgt   5      2.672   ±      0.322  s/op
ArrayListBenchmark.testIterate             UnsafeArrayList<EightLongs>  20000000  avgt   5      0.688   ±      0.014  s/op
ArrayListBenchmark.testIterate             UnsafeArrayList<EightLongs>  5000000   avgt   5      0.171   ±      0.003  s/op
ArrayListBenchmark.testListIterateInPlace  UnsafeArrayList<EightLongs>  80000000  avgt   5      0.941   ±      0.032  s/op
ArrayListBenchmark.testListIterateInPlace  UnsafeArrayList<EightLongs>  20000000  avgt   5      0.236   ±      0.008  s/op
ArrayListBenchmark.testListIterateInPlace  UnsafeArrayList<EightLongs>  5000000   avgt   5      0.058   ±      0.002  s/op
ArrayListBenchmark.testSort                UnsafeArrayList<EightLongs>  80000000  avgt   5      40.697  ±      0.743  s/op
ArrayListBenchmark.testSort                UnsafeArrayList<EightLongs>  20000000  avgt   5      7.608   ±      0.267  s/op
ArrayListBenchmark.testSort                UnsafeArrayList<EightLongs>  5000000   avgt   5      1.729   ±      0.101  s/op

Further Reading

JMH

Licence (Simplified BSD License)

Copyright (c) 2016, Andrew Brampton
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

unsafe's People

Contributors

bramp avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unsafe's Issues

SIGSEGV on Maven Build

Output after after a fresh git pull and mvn clean and then mvn.

Running net.bramp.unsafe.UnrolledUnsafeCopierBuilderTest
#
# A fatal error has been detected by the Java Runtime Environment:
#
SUREFIRE-859: #  SIGSEGV (0xb) at pc=0x000000010d8fbedb, pid=6309, tid=4867
#
# JRE version: Java(TM) SE Runtime Environment (7.0_45-b18) (build 1.7.0_45-b18)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.45-b08 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# V  [libjvm.dylib+0x2fbedb]  jni_GetObjectClass+0x83
#
SUREFIRE-859: # Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /Users/aewhite/Workspace/unsafe/unsafe-unroller/hs_err_pid6309.log
#
SUREFIRE-859: # If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
#
/bin/sh: line 1:  6309 Abort trap: 6           /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/bin/java -jar /Users/aewhite/Workspace/unsafe/unsafe-unroller/target/surefire/surefirebooter530105423655139680.jar /Users/aewhite/Workspace/unsafe/unsafe-unroller/target/surefire/surefire8572191872144640609tmp /Users/aewhite/Workspace/unsafe/unsafe-unroller/target/surefire/surefire_08424476146213297588tmp

RuntimeException: Can't find requested test UnsafeArrayList EightLongs

I was trying to run the benchmarks when the following error appeared in several runs.

# JMH 1.10.4 (released 17 days ago)
# VM version: JDK 1.8.0_05, VM 25.5-b02
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/bin/java
# VM options: -Xmx16g
# Warmup: 2 iterations, 10 s each
# Measurement: 5 iterations, 60 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Average time, time/op
# Benchmark: net.bramp.unsafe.collection.ArrayListBenchmark.testSort
# Parameters: (list = UnsafeArrayList, size = 20000000, type = FourLongs)

# Run progress: 77.78% complete, ETA 00:00:20
# Fork: 1 of 1
# Warmup Iteration   1: <failure>

java.lang.RuntimeException: Can't find requested test UnsafeArrayList FourLongs
    at net.bramp.unsafe.collection.ArrayListBenchmark.setup(ArrayListBenchmark.java:55)
    at net.bramp.unsafe.collection.generated.ArrayListBenchmark_testSort._jmh_tryInit_f_arraylistbenchmark0_0(ArrayListBenchmark_testSort.java:309)
    at net.bramp.unsafe.collection.generated.ArrayListBenchmark_testSort.testSort_AverageTime(ArrayListBenchmark_testSort.java:118)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.openjdk.jmh.runner.BenchmarkHandler$BenchmarkTask.call(BenchmarkHandler.java:430)
    at org.openjdk.jmh.runner.BenchmarkHandler$BenchmarkTask.call(BenchmarkHandler.java:412)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.