+ * Only the {@link #safeInstance() safe instance} is guaranteed to work on your +@@ -55,7 +53,6 @@ public final class LZ4Factory { + } + + private static LZ4Factory NATIVE_INSTANCE, +- JAVA_UNSAFE_INSTANCE, + JAVA_SAFE_INSTANCE; + + /** +@@ -107,42 +104,15 @@ public final class LZ4Factory { + return JAVA_SAFE_INSTANCE; + } + +- /** +- * Returns a {@link LZ4Factory} instance that returns compressors and +- * decompressors that may use {@link sun.misc.Unsafe} to speed up compression +- * and decompression. +- * +- * @return a {@link LZ4Factory} instance that returns compressors and +- * decompressors that may use {@link sun.misc.Unsafe} to speed up compression +- * and decompression. +- */ +- public static synchronized LZ4Factory unsafeInstance() { +- if (JAVA_UNSAFE_INSTANCE == null) { +- JAVA_UNSAFE_INSTANCE = instance("JavaUnsafe"); +- } +- return JAVA_UNSAFE_INSTANCE; +- } +- + /** + * Returns the fastest available {@link LZ4Factory} instance which does not +- * rely on JNI bindings. It first tries to load the +- * {@link #unsafeInstance() unsafe instance}, and then the +- * {@link #safeInstance() safe Java instance} if the JVM doesn't have a +- * working {@link sun.misc.Unsafe}. ++ * rely on JNI bindings. It loads {@link #safeInstance() safe Java instance} + * + * @return the fastest available {@link LZ4Factory} instance which does not + * rely on JNI bindings. + */ + public static LZ4Factory fastestJavaInstance() { +- if (Utils.isUnalignedAccessAllowed()) { +- try { +- return unsafeInstance(); +- } catch (Throwable t) { +- return safeInstance(); +- } +- } else { + return safeInstance(); +- } + } + + /** +@@ -249,9 +219,9 @@ public final class LZ4Factory { + *
+ * Only the {@link #safeInstance() safe instance} is guaranteed to work on your
+@@ -51,7 +49,6 @@ public final class XXHashFactory {
+ }
+
+ private static XXHashFactory NATIVE_INSTANCE,
+- JAVA_UNSAFE_INSTANCE,
+ JAVA_SAFE_INSTANCE;
+
+ /**
+@@ -96,40 +93,15 @@ public final class XXHashFactory {
+ return JAVA_SAFE_INSTANCE;
+ }
+
+- /**
+- * Returns a {@link XXHashFactory} that returns {@link XXHash32} instances that
+- * may use {@link sun.misc.Unsafe} to speed up hashing.
+- *
+- * @return a {@link XXHashFactory} that returns {@link XXHash32} instances that
+- * may use {@link sun.misc.Unsafe} to speed up hashing.
+- */
+- public static synchronized XXHashFactory unsafeInstance() {
+- if (JAVA_UNSAFE_INSTANCE == null) {
+- JAVA_UNSAFE_INSTANCE = instance("JavaUnsafe");
+- }
+- return JAVA_UNSAFE_INSTANCE;
+- }
+-
+ /**
+ * Returns the fastest available {@link XXHashFactory} instance which does not
+- * rely on JNI bindings. It first tries to load the
+- * {@link #unsafeInstance() unsafe instance}, and then the
+- * {@link #safeInstance() safe Java instance} if the JVM doesn't have a
+- * working {@link sun.misc.Unsafe}.
++ * rely on JNI bindings. It loads {@link #safeInstance() safe instance}
+ *
+ * @return the fastest available {@link XXHashFactory} instance which does not
+ * rely on JNI bindings.
+ */
+ public static XXHashFactory fastestJavaInstance() {
+- if (Utils.isUnalignedAccessAllowed()) {
+- try {
+- return unsafeInstance();
+- } catch (Throwable t) {
+- return safeInstance();
+- }
+- } else {
+ return safeInstance();
+- }
+ }
+
+ /**
+diff --git a/src/test/net/jpountz/lz4/Instances.java b/src/test/net/jpountz/lz4/Instances.java
+index b9caae5..44f7809 100644
+--- a/src/test/net/jpountz/lz4/Instances.java
++++ b/src/test/net/jpountz/lz4/Instances.java
+@@ -21,21 +21,17 @@ enum Instances {
+ static LZ4Compressor[] COMPRESSORS = new LZ4Compressor[] {
+ LZ4Factory.nativeInstance().fastCompressor(),
+ LZ4Factory.nativeInstance().highCompressor(),
+- LZ4Factory.unsafeInstance().fastCompressor(),
+- LZ4Factory.unsafeInstance().highCompressor(),
+ LZ4Factory.safeInstance().fastCompressor(),
+ LZ4Factory.safeInstance().highCompressor()
+ };
+
+ static LZ4FastDecompressor[] FAST_DECOMPRESSORS = new LZ4FastDecompressor[] {
+ LZ4Factory.nativeInstance().fastDecompressor(),
+- LZ4Factory.unsafeInstance().fastDecompressor(),
+ LZ4Factory.safeInstance().fastDecompressor()
+ };
+
+ static LZ4SafeDecompressor[] SAFE_DECOMPRESSORS = new LZ4SafeDecompressor[] {
+ LZ4Factory.nativeInstance().safeDecompressor(),
+- LZ4Factory.unsafeInstance().safeDecompressor(),
+ LZ4Factory.safeInstance().safeDecompressor()
+ };
+
+diff --git a/src/test/net/jpountz/lz4/LZ4FactoryTest.java b/src/test/net/jpountz/lz4/LZ4FactoryTest.java
+index c4ef05e..b8b33d7 100644
+--- a/src/test/net/jpountz/lz4/LZ4FactoryTest.java
++++ b/src/test/net/jpountz/lz4/LZ4FactoryTest.java
+@@ -21,17 +21,13 @@ public class LZ4FactoryTest extends TestCase {
+ public void test() {
+ assertEquals(LZ4JNICompressor.INSTANCE, LZ4Factory.nativeInstance().fastCompressor());
+ assertEquals(LZ4HCJNICompressor.INSTANCE, LZ4Factory.nativeInstance().highCompressor());
+- assertEquals(LZ4JavaUnsafeCompressor.INSTANCE, LZ4Factory.unsafeInstance().fastCompressor());
+- assertEquals(LZ4HCJavaUnsafeCompressor.INSTANCE, LZ4Factory.unsafeInstance().highCompressor());
+ assertEquals(LZ4JavaSafeCompressor.INSTANCE, LZ4Factory.safeInstance().fastCompressor());
+ assertEquals(LZ4HCJavaSafeCompressor.INSTANCE, LZ4Factory.safeInstance().highCompressor());
+
+ assertEquals(LZ4JNIFastDecompressor.INSTANCE, LZ4Factory.nativeInstance().fastDecompressor());
+- assertEquals(LZ4JavaUnsafeFastDecompressor.INSTANCE, LZ4Factory.unsafeInstance().fastDecompressor());
+ assertEquals(LZ4JavaSafeFastDecompressor.INSTANCE, LZ4Factory.safeInstance().fastDecompressor());
+
+ assertEquals(LZ4JNISafeDecompressor.INSTANCE, LZ4Factory.nativeInstance().safeDecompressor());
+- assertEquals(LZ4JavaUnsafeSafeDecompressor.INSTANCE, LZ4Factory.unsafeInstance().safeDecompressor());
+ assertEquals(LZ4JavaSafeSafeDecompressor.INSTANCE, LZ4Factory.safeInstance().safeDecompressor());
+ }
+
+diff --git a/src/test/net/jpountz/xxhash/XXHashFactoryTest.java b/src/test/net/jpountz/xxhash/XXHashFactoryTest.java
+index c410220..2aae562 100644
+--- a/src/test/net/jpountz/xxhash/XXHashFactoryTest.java
++++ b/src/test/net/jpountz/xxhash/XXHashFactoryTest.java
+@@ -21,14 +21,10 @@ public class XXHashFactoryTest extends TestCase {
+ public void test() {
+ assertEquals(XXHash32JNI.INSTANCE, XXHashFactory.nativeInstance().hash32());
+ assertTrue(XXHashFactory.nativeInstance().newStreamingHash32(0) instanceof StreamingXXHash32JNI);
+- assertEquals(XXHash32JavaUnsafe.INSTANCE, XXHashFactory.unsafeInstance().hash32());
+- assertTrue(XXHashFactory.unsafeInstance().newStreamingHash32(0) instanceof StreamingXXHash32JavaUnsafe);
+ assertEquals(XXHash32JavaSafe.INSTANCE, XXHashFactory.safeInstance().hash32());
+ assertTrue(XXHashFactory.safeInstance().newStreamingHash32(0) instanceof StreamingXXHash32JavaSafe);
+ assertEquals(XXHash64JNI.INSTANCE, XXHashFactory.nativeInstance().hash64());
+ assertTrue(XXHashFactory.nativeInstance().newStreamingHash64(0) instanceof StreamingXXHash64JNI);
+- assertEquals(XXHash64JavaUnsafe.INSTANCE, XXHashFactory.unsafeInstance().hash64());
+- assertTrue(XXHashFactory.unsafeInstance().newStreamingHash64(0) instanceof StreamingXXHash64JavaUnsafe);
+ assertEquals(XXHash64JavaSafe.INSTANCE, XXHashFactory.safeInstance().hash64());
+ assertTrue(XXHashFactory.safeInstance().newStreamingHash64(0) instanceof StreamingXXHash64JavaSafe);
+ }
diff --git a/SOURCES/1-remove-comments-from-templates.patch b/SOURCES/1-remove-comments-from-templates.patch
new file mode 100644
index 0000000..83fb640
--- /dev/null
+++ b/SOURCES/1-remove-comments-from-templates.patch
@@ -0,0 +1,311 @@
+diff --git a/src/build/source_templates/compress.template b/src/build/source_templates/compress.template
+index 32008e9..09a5df4 100644
+--- a/src/build/source_templates/compress.template
++++ b/src/build/source_templates/compress.template
+@@ -31,7 +31,6 @@
+ main:
+ while (true) {
+
+- // find a match
+ int forwardOff = sOff;
+
+ int ref;
+@@ -51,15 +50,12 @@
+ ${type}Utils.writeShort(hashTable, h, sOff - srcOff);
+ } while (!LZ4${utils}.readIntEquals(src, ref, sOff));
+
+- // catch up
+ final int excess = LZ4${utils}.commonBytesBackward(src, ref, sOff, srcOff, anchor);
+ sOff -= excess;
+ ref -= excess;
+
+- // sequence == refsequence
+ final int runLen = sOff - anchor;
+
+- // encode literal length
+ int tokenOff = dOff++;
+
+ if (dOff + runLen + (2 + 1 + LAST_LITERALS) + (runLen >>> 8) > destEnd) {
+@@ -73,16 +69,13 @@
+ ${utils}.writeByte(dest, tokenOff, runLen << ML_BITS);
+ }
+
+- // copy literals
+ LZ4${utils}.wildArraycopy(src, anchor, dest, dOff, runLen);
+ dOff += runLen;
+
+ while (true) {
+- // encode offset
+ ${utils}.writeShortLE(dest, dOff, (short) (sOff - ref));
+ dOff += 2;
+
+- // count nb matches
+ sOff += MIN_MATCH;
+ ref += MIN_MATCH;
+ final int matchLen = LZ4${utils}.commonBytes(src, ref, sOff, srcLimit);
+@@ -91,7 +84,6 @@
+ }
+ sOff += matchLen;
+
+- // encode match len
+ if (matchLen >= ML_MASK) {
+ ${utils}.writeByte(dest, tokenOff, ${utils}.readByte(dest, tokenOff) | ML_MASK);
+ dOff = LZ4${utils}.writeLen(matchLen - ML_MASK, dest, dOff);
+@@ -99,16 +91,13 @@
+ ${utils}.writeByte(dest, tokenOff, ${utils}.readByte(dest, tokenOff) | matchLen);
+ }
+
+- // test end of chunk
+ if (sOff > mflimit) {
+ anchor = sOff;
+ break main;
+ }
+
+- // fill table
+ ${type}Utils.writeShort(hashTable, hash64k(${utils}.readInt(src, sOff - 2)), sOff - 2 - srcOff);
+
+- // test next position
+ final int h = hash64k(${utils}.readInt(src, sOff));
+ ref = srcOff + ${type}Utils.readShort(hashTable, h);
+ ${type}Utils.writeShort(hashTable, h, sOff - srcOff);
+@@ -121,7 +110,6 @@
+ ${utils}.writeByte(dest, tokenOff, 0);
+ }
+
+- // prepare next loop
+ anchor = sOff++;
+ }
+ }
+@@ -160,7 +148,6 @@
+ main:
+ while (true) {
+
+- // find a match
+ int forwardOff = sOff;
+
+ int ref;
+@@ -187,10 +174,8 @@
+ sOff -= excess;
+ ref -= excess;
+
+- // sequence == refsequence
+ final int runLen = sOff - anchor;
+
+- // encode literal length
+ int tokenOff = dOff++;
+
+ if (dOff + runLen + (2 + 1 + LAST_LITERALS) + (runLen >>> 8) > destEnd) {
+@@ -204,16 +189,13 @@
+ ${utils}.writeByte(dest, tokenOff, runLen << ML_BITS);
+ }
+
+- // copy literals
+ LZ4${utils}.wildArraycopy(src, anchor, dest, dOff, runLen);
+ dOff += runLen;
+
+ while (true) {
+- // encode offset
+ ${utils}.writeShortLE(dest, dOff, back);
+ dOff += 2;
+
+- // count nb matches
+ sOff += MIN_MATCH;
+ final int matchLen = LZ4${utils}.commonBytes(src, ref + MIN_MATCH, sOff, srcLimit);
+ if (dOff + (1 + LAST_LITERALS) + (matchLen >>> 8) > destEnd) {
+@@ -221,7 +203,6 @@
+ }
+ sOff += matchLen;
+
+- // encode match len
+ if (matchLen >= ML_MASK) {
+ ${utils}.writeByte(dest, tokenOff, ${utils}.readByte(dest, tokenOff) | ML_MASK);
+ dOff = LZ4${utils}.writeLen(matchLen - ML_MASK, dest, dOff);
+@@ -229,16 +210,13 @@
+ ${utils}.writeByte(dest, tokenOff, ${utils}.readByte(dest, tokenOff) | matchLen);
+ }
+
+- // test end of chunk
+ if (sOff > mflimit) {
+ anchor = sOff;
+ break main;
+ }
+
+- // fill table
+ ${type}Utils.writeInt(hashTable, hash(${utils}.readInt(src, sOff - 2)), sOff - 2);
+
+- // test next position
+ final int h = hash(${utils}.readInt(src, sOff));
+ ref = ${type}Utils.readInt(hashTable, h);
+ ${type}Utils.writeInt(hashTable, h, sOff);
+@@ -252,7 +230,6 @@
+ ${utils}.writeByte(dest, tokenOff, 0);
+ }
+
+- // prepare next loop
+ anchor = sOff++;
+ }
+
+diff --git a/src/build/source_templates/compress_hc.template b/src/build/source_templates/compress_hc.template
+index 7179db3..7976ad1 100644
+--- a/src/build/source_templates/compress_hc.template
++++ b/src/build/source_templates/compress_hc.template
+@@ -47,7 +47,6 @@
+ continue;
+ }
+
+- // saved, in case we would skip too much
+ copyTo(match1, match0);
+
+ search2:
+@@ -55,20 +54,19 @@
+ assert match1.start >= anchor;
+ if (match1.end() >= mfLimit
+ || !ht.insertAndFindWiderMatch(src, match1.end() - 2, match1.start + 1, matchLimit, match1.len, match2)) {
+- // no better match
+ dOff = LZ4${utils}.encodeSequence(src, anchor, match1.start, match1.ref, match1.len, dest, dOff, destEnd);
+ anchor = sOff = match1.end();
+ continue main;
+ }
+
+ if (match0.start < match1.start) {
+- if (match2.start < match1.start + match0.len) { // empirical
++ if (match2.start < match1.start + match0.len) {
+ copyTo(match0, match1);
+ }
+ }
+ assert match2.start > match1.start;
+
+- if (match2.start - match1.start < 3) { // First Match too small : removed
++ if (match2.start - match1.start < 3) {
+ copyTo(match2, match1);
+ continue search2;
+ }
+@@ -91,21 +89,18 @@
+
+ if (match2.start + match2.len >= mfLimit
+ || !ht.insertAndFindWiderMatch(src, match2.end() - 3, match2.start, matchLimit, match2.len, match3)) {
+- // no better match -> 2 sequences to encode
+ if (match2.start < match1.end()) {
+ match1.len = match2.start - match1.start;
+ }
+- // encode seq 1
+ dOff = LZ4${utils}.encodeSequence(src, anchor, match1.start, match1.ref, match1.len, dest, dOff, destEnd);
+ anchor = sOff = match1.end();
+- // encode seq 2
+ dOff = LZ4${utils}.encodeSequence(src, anchor, match2.start, match2.ref, match2.len, dest, dOff, destEnd);
+ anchor = sOff = match2.end();
+ continue main;
+ }
+
+- if (match3.start < match1.end() + 3) { // Not enough space for match 2 : remove it
+- if (match3.start >= match1.end()) { // // can write Seq1 immediately ==> Seq2 is removed, so Seq3 becomes Seq1
++ if (match3.start < match1.end() + 3) {
++ if (match3.start >= match1.end()) {
+ if (match2.start < match1.end()) {
+ final int correction = match1.end() - match2.start;
+ match2.fix(correction);
+@@ -127,7 +122,6 @@
+ continue search3;
+ }
+
+- // OK, now we have 3 ascending matches; let's write at least the first one
+ if (match2.start < match1.end()) {
+ if (match2.start - match1.start < ML_MASK) {
+ if (match1.len > OPTIMAL_ML) {
+diff --git a/src/build/source_templates/decompress.template b/src/build/source_templates/decompress.template
+index f1c2890..1e2aa23 100644
+--- a/src/build/source_templates/decompress.template
++++ b/src/build/source_templates/decompress.template
+@@ -55,7 +55,6 @@
+ final int token = ${utils}.readByte(src, sOff) & 0xFF;
+ ++sOff;
+
+- // literals
+ int literalLen = token >>> ML_BITS;
+ if (literalLen == RUN_MASK) {
+ byte len = (byte) 0xFF;
+@@ -81,7 +80,7 @@
+ LZ4${utils}.safeArraycopy(src, sOff, dest, dOff, literalLen);
+ sOff += literalLen;
+ dOff = literalCopyEnd;
+- break; // EOF
++ break;
+ }
+ }
+
+@@ -89,7 +88,6 @@
+ sOff += literalLen;
+ dOff = literalCopyEnd;
+
+- // matchs
+ final int matchDec = ${utils}.readShortLE(src, sOff);
+ sOff += 2;
+ int matchOff = dOff - matchDec;
+diff --git a/src/build/source_templates/hashtable.template b/src/build/source_templates/hashtable.template
+index 174f8e8..91935f5 100644
+--- a/src/build/source_templates/hashtable.template
++++ b/src/build/source_templates/hashtable.template
+@@ -92,8 +92,8 @@
+
+ int ref = hashPointer(buf, off);
+
+- if (ref >= off - 4 && ref <= off && ref >= base) { // potential repetition
+- if (LZ4${utils}.readIntEquals(buf, ref, off)) { // confirmed
++ if (ref >= off - 4 && ref <= off && ref >= base) {
++ if (LZ4${utils}.readIntEquals(buf, ref, off)) {
+ delta = off - ref;
+ repl = match.len = MIN_MATCH + LZ4${utils}.commonBytes(buf, ref + MIN_MATCH, off + MIN_MATCH, matchLimit);
+ match.ref = ref;
+@@ -119,7 +119,7 @@
+ int ptr = off;
+ final int end = off + repl - (MIN_MATCH - 1);
+ while (ptr < end - delta) {
+- chainTable[ptr & MASK] = (short) delta; // pre load
++ chainTable[ptr & MASK] = (short) delta;
+ ++ptr;
+ }
+ do {
+diff --git a/src/build/source_templates/xxhash32_streaming.template b/src/build/source_templates/xxhash32_streaming.template
+index 6166758..9fa55e8 100644
+--- a/src/build/source_templates/xxhash32_streaming.template
++++ b/src/build/source_templates/xxhash32_streaming.template
+@@ -66,7 +66,7 @@ final class StreamingXXHash32Java${type} extends AbstractStreamingXXHash32Java {
+
+ totalLen += len;
+
+- if (memSize + len < 16) { // fill in tmp buffer
++ if (memSize + len < 16) {
+ System.arraycopy(buf, off, memory, memSize, len);
+ memSize += len;
+ return;
+@@ -74,7 +74,7 @@ final class StreamingXXHash32Java${type} extends AbstractStreamingXXHash32Java {
+
+ final int end = off + len;
+
+- if (memSize > 0) { // data left from previous update
++ if (memSize > 0) {
+ System.arraycopy(buf, off, memory, memSize, 16 - memSize);
+
+ v1 += readIntLE(memory, 0) * PRIME2;
+diff --git a/src/build/source_templates/xxhash64_streaming.template b/src/build/source_templates/xxhash64_streaming.template
+index 2789ae0..e781746 100644
+--- a/src/build/source_templates/xxhash64_streaming.template
++++ b/src/build/source_templates/xxhash64_streaming.template
+@@ -90,7 +90,7 @@ final class StreamingXXHash64Java${type} extends AbstractStreamingXXHash64Java {
+
+ totalLen += len;
+
+- if (memSize + len < 32) { // fill in tmp buffer
++ if (memSize + len < 32) {
+ System.arraycopy(buf, off, memory, memSize, len);
+ memSize += len;
+ return;
+@@ -98,7 +98,7 @@ final class StreamingXXHash64Java${type} extends AbstractStreamingXXHash64Java {
+
+ final int end = off + len;
+
+- if (memSize > 0) { // data left from previous update
++ if (memSize > 0) {
+ System.arraycopy(buf, off, memory, memSize, 32 - memSize);
+
+ v1 += readLongLE(memory, 0) * PRIME64_2;
diff --git a/SOURCES/2-remove-cpptasks.patch b/SOURCES/2-remove-cpptasks.patch
new file mode 100644
index 0000000..f896d55
--- /dev/null
+++ b/SOURCES/2-remove-cpptasks.patch
@@ -0,0 +1,98 @@
+diff --git a/Makefile b/Makefile
+new file mode 100644
+index 0000000..01934f1
+--- /dev/null
++++ b/Makefile
+@@ -0,0 +1,33 @@
++CC = gcc
++
++BUILD_DIR = build
++OBJECTS_DIR = $(BUILD_DIR)/objects
++JNI_HEADERS_DIR = $(BUILD_DIR)/jni-headers
++JNI_SOURCES_DIR = src/jni
++INCLUDE = -I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/linux
++
++LIBS = -llz4 -lxxhash
++JNI_PREFIX = net_jpountz_
++
++default: all move_objects generate_so
++
++all:
++ $(CC) -fPIC -I $(JNI_HEADERS_DIR) \
++ $(INCLUDE) \
++ $(LIBS) \
++ -c $(JNI_SOURCES_DIR)/$(JNI_PREFIX)lz4_LZ4JNI.c
++
++ $(CC) -fPIC -I $(JNI_HEADERS_DIR) \
++ $(INCLUDE) \
++ $(LIBS) \
++ -c $(JNI_SOURCES_DIR)/$(JNI_PREFIX)xxhash_XXHashJNI.c
++
++move_objects:
++ mv *.o $(OBJECTS_DIR)
++
++generate_so:
++ gcc -fPIC -shared \
++ $(OBJECTS_DIR)/*.o \
++ $(LIB_DIR)/liblz4.so \
++ $(LIB_DIR)/libxxhash.so \
++ -o $(BUILD_DIR)/jni/net/jpountz/util/$(PLATFORM)/$(ARCH)/liblz4-java.so
+diff --git a/build.xml b/build.xml
+index 1d4cff5..13d8ce3 100644
+--- a/build.xml
++++ b/build.xml
+@@ -13,7 +13,6 @@
+ -->
+
+