Import rpm: bc45b0043af657bbd6c88ad2566a5f1abc9d6077

This commit is contained in:
James Antill 2022-08-08 12:39:28 -04:00
commit 120023b540
9 changed files with 3164 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
SOURCES/1.7.1.tar.gz
SOURCES/v1.9.2.tar.gz

797
0-remove-unsafe.patch Normal file
View File

@ -0,0 +1,797 @@
diff --git a/.classpath b/.classpath
index 5ee3f97..058b340 100644
--- a/.classpath
+++ b/.classpath
@@ -2,7 +2,6 @@
<classpath>
<classpathentry kind="src" path="src/java"/>
<classpathentry kind="src" path="build/java"/>
- <classpathentry kind="src" path="src/java-unsafe"/>
<classpathentry kind="src" path="src/test-resources"/>
<classpathentry kind="src" path="build/jni"/>
<classpathentry kind="src" path="src/test"/>
diff --git a/CHANGES.md b/CHANGES.md
index c7eed89..b71dc35 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -140,12 +140,6 @@
- [#99](https://github.com/lz4/lz4-java/pull/99)
LZ4FrameInputStream allows EndMark to be incompressible. (Charles Allen)
- - [#95](https://github.com/lz4/lz4-java/pull/95)
- Added unsafe instance support for aarch64. (Yuqi Gu)
-
- - [#93](https://github.com/lz4/lz4-java/pull/93)
- Added unsafe instance support for ppc64le. (Madhusudanan Kandasamy)
-
- [#90](https://github.com/lz4/lz4-java/issues/90)
LZ4 Java now supports 64-bit JNI build on Solaris. (cndcourt)
@@ -207,11 +201,6 @@
- [#39](https://github.com/jpountz/lz4-java/pull/39)
The JAR is now a valid OSGI bundle. (Simon Chemouil)
- - [#33](https://github.com/jpountz/lz4-java/pull/33)
- The implementation based on Java's sun.misc.Unsafe relies on unaligned
- memory access and is now only used on platforms that support it.
- (Dmitry Shohov)
-
## 1.2.0
diff --git a/README.md b/README.md
index 9a34ea6..b966d9a 100644
--- a/README.md
+++ b/README.md
@@ -24,12 +24,10 @@ decompressor instance.
## Implementations
-For LZ4 compressors, LZ4 HC compressors and decompressors, 3 implementations are
+For LZ4 compressors, LZ4 HC compressors and decompressors, 2 implementations are
available:
- JNI bindings to the original C implementation by Yann Collet,
- a pure Java port of the compression and decompression algorithms,
- - a Java port that uses the sun.misc.Unsafe API in order to achieve compression
- and decompression speeds close to the C implementation.
Have a look at LZ4Factory for more information.
@@ -94,8 +92,7 @@ score of 10) hash function.
## Implementations
-Similarly to LZ4, 3 implementations are available: JNI bindings, pure Java port
-and pure Java port that uses sun.misc.Unsafe.
+Unsimilarly to LZ4, 2 implementations are available: JNI bindings, pure Java port
Have a look at XXHashFactory for more information.
@@ -131,7 +128,7 @@ int hash = hash32.getValue();
You can download released artifacts from [Maven Central](https://search.maven.org/search?q=g:org.lz4%20a:lz4-java).
-You can download pure-Java lz4-java from [Maven Central](https://search.maven.org/search?q=g:org.lz4%20a:lz4-pure-java). These artifacts include the Safe and Unsafe Java versions but not JNI bindings. (Experimental)
+You can download pure-Java lz4-java from [Maven Central](https://search.maven.org/search?q=g:org.lz4%20a:lz4-pure-java). These artifacts include the Safe Java versions but not JNI bindings. (Experimental)
# Documentation
@@ -172,10 +169,8 @@ Then run `ant`. It will:
located under `src/build`,
- compile the lz4 and xxhash libraries and their JNI (Java Native Interface)
bindings,
- - compile Java sources in `src/java` (normal sources), `src/java-unsafe`
- (sources that make use of `sun.misc.Unsafe`) and `build/java`
- (auto-generated sources) to `build/classes`, `build/unsafe-classes` and
- `build/generated-classes`,
+ - compile Java sources in `src/java` (normal sources) and `build/java`
+ (auto-generated sources) to `build/classes` and `build/generated-classes`,
- generate a JAR file called lz4-${version}.jar under the `dist` directory.
The JAR file that is generated contains Java class files, the native library
diff --git a/build.xml b/build.xml
index 2a08ad8..1d4cff5 100644
--- a/build.xml
+++ b/build.xml
@@ -148,16 +148,6 @@
debug="true"
destdir="${build}/classes"
nativeHeaderDir="${build}/jni-headers"/>
- <mkdir dir="${build}/unsafe-classes" />
- <javac
- includeAntRuntime="false"
- srcdir="${src}/java-unsafe"
- source="${javac.source}"
- target="${javac.target}"
- encoding="UTF-8"
- debug="true"
- classpath="${build}/classes"
- destdir="${build}/unsafe-classes"/>
<mkdir dir="${build}/generated-classes" />
<javac
includeAntRuntime="false"
@@ -169,7 +159,6 @@
destdir="${build}/generated-classes">
<classpath>
<pathelement location="${build}/classes/" />
- <pathelement location="${build}/unsafe-classes" />
</classpath>
</javac>
</target>
@@ -234,7 +223,6 @@
<path id="compile.tests.classpath">
<pathelement path="${build}/classes" />
- <pathelement path="${build}/unsafe-classes" />
<pathelement path="${build}/generated-classes" />
<fileset dir="lib" includes="*.jar" />
</path>
@@ -249,7 +237,6 @@
<pathelement path="${src}/resources" />
<pathelement path="${src}/test-resources" />
<pathelement path="${build}/classes" />
- <pathelement path="${build}/unsafe-classes" />
<pathelement path="${build}/generated-classes" />
<pathelement path="${build}/test-classes" />
<fileset dir="${lib}" includes="*.jar" />
@@ -317,7 +304,6 @@
<jar
destfile="${dist}/${ivy.module}-${ivy.revision}-sources.jar">
<fileset dir="${src}/java" />
- <fileset dir="${src}/java-unsafe" />
</jar>
</target>
@@ -351,7 +337,6 @@
destfile="${dist}/${ivy.module}.jar">
<fileset dir="${src}/resources" erroronmissingdir="false" />
<fileset dir="${build}/classes" />
- <fileset dir="${build}/unsafe-classes" />
<fileset dir="${build}/generated-classes" />
<fileset dir="${build}/jni" erroronmissingdir="false" />
<manifest>
@@ -365,7 +350,6 @@
<jar
destfile="${dist}/${ivy.module}.jar">
<fileset dir="${build}/classes" />
- <fileset dir="${build}/unsafe-classes" />
<fileset dir="${build}/generated-classes" />
<manifest>
<attribute name="Automatic-Module-Name" value="org.lz4.pure.java"/>
@@ -411,15 +395,12 @@
<target name="forbidden-apis" description="check API usage" depends="install-forbidden-apis,compile">
<forbidden-apis internalRuntimeForbidden="true" classpathref="forbidden-apis.classpath">
- <bundledSignatures name="jdk-unsafe-${javac.target}"/>
<bundledSignatures name="jdk-deprecated-${javac.target}"/>
<fileset dir="${build}/classes" includes="**/*.class" />
</forbidden-apis>
<forbidden-apis classpathref="forbidden-apis.classpath">
- <bundledSignatures name="jdk-unsafe-${javac.target}"/>
<bundledSignatures name="jdk-deprecated-${javac.target}"/>
<fileset dir="${build}/classes" includes="**/*.class" />
- <fileset dir="${build}/unsafe-classes" includes="**/*.class" />
</forbidden-apis>
</target>
diff --git a/src/build/gen_sources.mvel b/src/build/gen_sources.mvel
index 0f32671..43ebb78 100644
--- a/src/build/gen_sources.mvel
+++ b/src/build/gen_sources.mvel
@@ -24,7 +24,7 @@ def dest_file(path) {
def generate_decompressors() {
compiledTemplate = get_template("decompressor.template");
- for (type : ["Safe", "Unsafe"]) {
+ for (type : ["Safe"]) {
for (size : ["Fast", "Safe"]) {
dest = dest_file("lz4/LZ4Java" + type + size + "Decompressor.java");
args = new HashMap();
@@ -37,7 +37,7 @@ def generate_decompressors() {
def generate_compressors() {
compiledTemplate = get_template("compressor.template");
- for (type : ["Safe", "Unsafe"]) {
+ for (type : ["Safe"]) {
dest = dest_file("lz4/LZ4Java" + type + "Compressor.java");
args = new HashMap();
args.put("type", type);
@@ -47,7 +47,7 @@ def generate_compressors() {
def generate_hc_compressors() {
compiledTemplate = get_template("compressor_hc.template");
- for (type : ["Safe", "Unsafe"]) {
+ for (type : ["Safe"]) {
dest = dest_file("lz4/LZ4HCJava" + type + "Compressor.java");
args = new HashMap();
args.put("type", type);
@@ -58,7 +58,7 @@ def generate_hc_compressors() {
def generate_xxhash() {
for (bitness : ["32", "64"]) {
compiledTemplate = get_template("xxhash" + bitness + ".template");
- for (type : ["Safe", "Unsafe"]) {
+ for (type : ["Safe"]) {
dest = dest_file("xxhash/XXHash" + bitness + "Java" + type + ".java");
args = new HashMap();
args.put("type", type);
@@ -70,7 +70,7 @@ def generate_xxhash() {
def generate_streaming_xxhash() {
for (bitness : ["32", "64"]) {
compiledTemplate = get_template("xxhash" + bitness + "_streaming.template");
- for (type : ["Safe", "Unsafe"]) {
+ for (type : ["Safe"]) {
dest = dest_file("xxhash/StreamingXXHash" + bitness + "Java" + type + ".java");
args = new HashMap();
args.put("type", type);
diff --git a/src/java-unsafe/net/jpountz/lz4/LZ4UnsafeUtils.java b/src/java-unsafe/net/jpountz/lz4/LZ4UnsafeUtils.java
deleted file mode 100644
index a5ad783..0000000
--- a/src/java-unsafe/net/jpountz/lz4/LZ4UnsafeUtils.java
+++ /dev/null
@@ -1,206 +0,0 @@
-package net.jpountz.lz4;
-
-/*
- * 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.
- */
-
-import static net.jpountz.lz4.LZ4Constants.COPY_LENGTH;
-import static net.jpountz.lz4.LZ4Constants.LAST_LITERALS;
-import static net.jpountz.lz4.LZ4Constants.ML_BITS;
-import static net.jpountz.lz4.LZ4Constants.ML_MASK;
-import static net.jpountz.lz4.LZ4Constants.RUN_MASK;
-import static net.jpountz.util.UnsafeUtils.readByte;
-import static net.jpountz.util.UnsafeUtils.readInt;
-import static net.jpountz.util.UnsafeUtils.readLong;
-import static net.jpountz.util.UnsafeUtils.readShort;
-import static net.jpountz.util.UnsafeUtils.writeByte;
-import static net.jpountz.util.UnsafeUtils.writeInt;
-import static net.jpountz.util.UnsafeUtils.writeLong;
-import static net.jpountz.util.UnsafeUtils.writeShort;
-import static net.jpountz.util.Utils.NATIVE_BYTE_ORDER;
-
-import java.nio.ByteOrder;
-
-enum LZ4UnsafeUtils {
- ;
-
- static void safeArraycopy(byte[] src, int srcOff, byte[] dest, int destOff, int len) {
- final int fastLen = len & 0xFFFFFFF8;
- wildArraycopy(src, srcOff, dest, destOff, fastLen);
- for (int i = 0, slowLen = len & 0x7; i < slowLen; i += 1) {
- writeByte(dest, destOff + fastLen + i, readByte(src, srcOff + fastLen + i));
- }
- }
-
- static void wildArraycopy(byte[] src, int srcOff, byte[] dest, int destOff, int len) {
- for (int i = 0; i < len; i += 8) {
- writeLong(dest, destOff + i, readLong(src, srcOff + i));
- }
- }
-
- static void wildIncrementalCopy(byte[] dest, int matchOff, int dOff, int matchCopyEnd) {
- if (dOff - matchOff < 4) {
- for (int i = 0; i < 4; ++i) {
- writeByte(dest, dOff+i, readByte(dest, matchOff+i));
- }
- dOff += 4;
- matchOff += 4;
- int dec = 0;
- assert dOff >= matchOff && dOff - matchOff < 8;
- switch (dOff - matchOff) {
- case 1:
- matchOff -= 3;
- break;
- case 2:
- matchOff -= 2;
- break;
- case 3:
- matchOff -= 3;
- dec = -1;
- break;
- case 5:
- dec = 1;
- break;
- case 6:
- dec = 2;
- break;
- case 7:
- dec = 3;
- break;
- default:
- break;
- }
- writeInt(dest, dOff, readInt(dest, matchOff));
- dOff += 4;
- matchOff -= dec;
- } else if (dOff - matchOff < COPY_LENGTH) {
- writeLong(dest, dOff, readLong(dest, matchOff));
- dOff += dOff - matchOff;
- }
- while (dOff < matchCopyEnd) {
- writeLong(dest, dOff, readLong(dest, matchOff));
- dOff += 8;
- matchOff += 8;
- }
- }
-
- static void safeIncrementalCopy(byte[] dest, int matchOff, int dOff, int matchLen) {
- for (int i = 0; i < matchLen; ++i) {
- dest[dOff + i] = dest[matchOff + i];
- writeByte(dest, dOff + i, readByte(dest, matchOff + i));
- }
- }
-
- static int readShortLittleEndian(byte[] src, int srcOff) {
- short s = readShort(src, srcOff);
- if (NATIVE_BYTE_ORDER == ByteOrder.BIG_ENDIAN) {
- s = Short.reverseBytes(s);
- }
- return s & 0xFFFF;
- }
-
- static void writeShortLittleEndian(byte[] dest, int destOff, int value) {
- short s = (short) value;
- if (NATIVE_BYTE_ORDER == ByteOrder.BIG_ENDIAN) {
- s = Short.reverseBytes(s);
- }
- writeShort(dest, destOff, s);
- }
-
- static boolean readIntEquals(byte[] src, int ref, int sOff) {
- return readInt(src, ref) == readInt(src, sOff);
- }
-
- static int commonBytes(byte[] src, int ref, int sOff, int srcLimit) {
- int matchLen = 0;
- while (sOff <= srcLimit - 8) {
- if (readLong(src, sOff) == readLong(src, ref)) {
- matchLen += 8;
- ref += 8;
- sOff += 8;
- } else {
- final int zeroBits;
- if (NATIVE_BYTE_ORDER == ByteOrder.BIG_ENDIAN) {
- zeroBits = Long.numberOfLeadingZeros(readLong(src, sOff) ^ readLong(src, ref));
- } else {
- zeroBits = Long.numberOfTrailingZeros(readLong(src, sOff) ^ readLong(src, ref));
- }
- return matchLen + (zeroBits >>> 3);
- }
- }
- while (sOff < srcLimit && readByte(src, ref++) == readByte(src, sOff++)) {
- ++matchLen;
- }
- return matchLen;
- }
-
- static int writeLen(int len, byte[] dest, int dOff) {
- while (len >= 0xFF) {
- writeByte(dest, dOff++, 0xFF);
- len -= 0xFF;
- }
- writeByte(dest, dOff++, len);
- return dOff;
- }
-
- static int encodeSequence(byte[] src, int anchor, int matchOff, int matchRef, int matchLen, byte[] dest, int dOff, int destEnd) {
- final int runLen = matchOff - anchor;
- final int tokenOff = dOff++;
- int token;
-
- if (runLen >= RUN_MASK) {
- token = (byte) (RUN_MASK << ML_BITS);
- dOff = writeLen(runLen - RUN_MASK, dest, dOff);
- } else {
- token = runLen << ML_BITS;
- }
-
- // copy literals
- wildArraycopy(src, anchor, dest, dOff, runLen);
- dOff += runLen;
-
- // encode offset
- final int matchDec = matchOff - matchRef;
- dest[dOff++] = (byte) matchDec;
- dest[dOff++] = (byte) (matchDec >>> 8);
-
- // encode match len
- matchLen -= 4;
- if (dOff + (1 + LAST_LITERALS) + (matchLen >>> 8) > destEnd) {
- throw new LZ4Exception("maxDestLen is too small");
- }
- if (matchLen >= ML_MASK) {
- token |= ML_MASK;
- dOff = writeLen(matchLen - RUN_MASK, dest, dOff);
- } else {
- token |= matchLen;
- }
-
- dest[tokenOff] = (byte) token;
-
- return dOff;
- }
-
- static int commonBytesBackward(byte[] b, int o1, int o2, int l1, int l2) {
- int count = 0;
- while (o1 > l1 && o2 > l2 && readByte(b, --o1) == readByte(b, --o2)) {
- ++count;
- }
- return count;
- }
-
- static int lastLiterals(byte[] src, int sOff, int srcLen, byte[] dest, int dOff, int destEnd) {
- return LZ4SafeUtils.lastLiterals(src, sOff, srcLen, dest, dOff, destEnd);
- }
-
-}
diff --git a/src/java-unsafe/net/jpountz/util/UnsafeUtils.java b/src/java-unsafe/net/jpountz/util/UnsafeUtils.java
deleted file mode 100644
index 30231ef..0000000
--- a/src/java-unsafe/net/jpountz/util/UnsafeUtils.java
+++ /dev/null
@@ -1,147 +0,0 @@
-package net.jpountz.util;
-
-/*
- * 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.
- */
-
-import static net.jpountz.util.Utils.NATIVE_BYTE_ORDER;
-
-import java.lang.reflect.Field;
-import java.nio.ByteOrder;
-
-import sun.misc.Unsafe;
-
-public enum UnsafeUtils {
- ;
-
- private static final Unsafe UNSAFE;
- private static final long BYTE_ARRAY_OFFSET;
- private static final int BYTE_ARRAY_SCALE;
- private static final long INT_ARRAY_OFFSET;
- private static final int INT_ARRAY_SCALE;
- private static final long SHORT_ARRAY_OFFSET;
- private static final int SHORT_ARRAY_SCALE;
-
- static {
- try {
- Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
- theUnsafe.setAccessible(true);
- UNSAFE = (Unsafe) theUnsafe.get(null);
- BYTE_ARRAY_OFFSET = UNSAFE.arrayBaseOffset(byte[].class);
- BYTE_ARRAY_SCALE = UNSAFE.arrayIndexScale(byte[].class);
- INT_ARRAY_OFFSET = UNSAFE.arrayBaseOffset(int[].class);
- INT_ARRAY_SCALE = UNSAFE.arrayIndexScale(int[].class);
- SHORT_ARRAY_OFFSET = UNSAFE.arrayBaseOffset(short[].class);
- SHORT_ARRAY_SCALE = UNSAFE.arrayIndexScale(short[].class);
- } catch (IllegalAccessException e) {
- throw new ExceptionInInitializerError("Cannot access Unsafe");
- } catch (NoSuchFieldException e) {
- throw new ExceptionInInitializerError("Cannot access Unsafe");
- } catch (SecurityException e) {
- throw new ExceptionInInitializerError("Cannot access Unsafe");
- }
- }
-
- public static void checkRange(byte[] buf, int off) {
- SafeUtils.checkRange(buf, off);
- }
-
- public static void checkRange(byte[] buf, int off, int len) {
- SafeUtils.checkRange(buf, off, len);
- }
-
- public static void checkLength(int len) {
- SafeUtils.checkLength(len);
- }
-
- public static byte readByte(byte[] src, int srcOff) {
- return UNSAFE.getByte(src, BYTE_ARRAY_OFFSET + BYTE_ARRAY_SCALE * srcOff);
- }
-
- public static void writeByte(byte[] src, int srcOff, byte value) {
- UNSAFE.putByte(src, BYTE_ARRAY_OFFSET + BYTE_ARRAY_SCALE * srcOff, (byte) value);
- }
-
- public static void writeByte(byte[] src, int srcOff, int value) {
- writeByte(src, srcOff, (byte) value);
- }
-
- public static long readLong(byte[] src, int srcOff) {
- return UNSAFE.getLong(src, BYTE_ARRAY_OFFSET + srcOff);
- }
-
- public static long readLongLE(byte[] src, int srcOff) {
- long i = readLong(src, srcOff);
- if (NATIVE_BYTE_ORDER == ByteOrder.BIG_ENDIAN) {
- i = Long.reverseBytes(i);
- }
- return i;
- }
-
- public static void writeLong(byte[] dest, int destOff, long value) {
- UNSAFE.putLong(dest, BYTE_ARRAY_OFFSET + destOff, value);
- }
-
- public static int readInt(byte[] src, int srcOff) {
- return UNSAFE.getInt(src, BYTE_ARRAY_OFFSET + srcOff);
- }
-
- public static int readIntLE(byte[] src, int srcOff) {
- int i = readInt(src, srcOff);
- if (NATIVE_BYTE_ORDER == ByteOrder.BIG_ENDIAN) {
- i = Integer.reverseBytes(i);
- }
- return i;
- }
-
- public static void writeInt(byte[] dest, int destOff, int value) {
- UNSAFE.putInt(dest, BYTE_ARRAY_OFFSET + destOff, value);
- }
-
- public static short readShort(byte[] src, int srcOff) {
- return UNSAFE.getShort(src, BYTE_ARRAY_OFFSET + srcOff);
- }
-
- public static int readShortLE(byte[] src, int srcOff) {
- short s = readShort(src, srcOff);
- if (NATIVE_BYTE_ORDER == ByteOrder.BIG_ENDIAN) {
- s = Short.reverseBytes(s);
- }
- return s & 0xFFFF;
- }
-
- public static void writeShort(byte[] dest, int destOff, short value) {
- UNSAFE.putShort(dest, BYTE_ARRAY_OFFSET + destOff, value);
- }
-
- public static void writeShortLE(byte[] buf, int off, int v) {
- writeByte(buf, off, (byte) v);
- writeByte(buf, off + 1, (byte) (v >>> 8));
- }
-
- public static int readInt(int[] src, int srcOff) {
- return UNSAFE.getInt(src, INT_ARRAY_OFFSET + INT_ARRAY_SCALE * srcOff);
- }
-
- public static void writeInt(int[] dest, int destOff, int value) {
- UNSAFE.putInt(dest, INT_ARRAY_OFFSET + INT_ARRAY_SCALE * destOff, value);
- }
-
- public static int readShort(short[] src, int srcOff) {
- return UNSAFE.getShort(src, SHORT_ARRAY_OFFSET + SHORT_ARRAY_SCALE * srcOff) & 0xFFFF;
- }
-
- public static void writeShort(short[] dest, int destOff, int value) {
- UNSAFE.putShort(dest, SHORT_ARRAY_OFFSET + SHORT_ARRAY_SCALE * destOff, (short) value);
- }
-}
diff --git a/src/java/net/jpountz/lz4/LZ4Factory.java b/src/java/net/jpountz/lz4/LZ4Factory.java
index e04867b..69f81fa 100644
--- a/src/java/net/jpountz/lz4/LZ4Factory.java
+++ b/src/java/net/jpountz/lz4/LZ4Factory.java
@@ -32,8 +32,6 @@ import static net.jpountz.lz4.LZ4Constants.MAX_COMPRESSION_LEVEL;
* <a href="https://github.com/lz4/lz4">the original LZ4 C implementation</a>.
* <li>a {@link #safeInstance() safe Java} instance which is a pure Java port
* of the original C library,</li>
- * <li>an {@link #unsafeInstance() unsafe Java} instance which is a Java port
- * using the unofficial {@link sun.misc.Unsafe} API.
* </ul>
* <p>
* 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 {
* <li>A compression level lower than 1 would be treated as 9.</li>
* </ol>
* Note that compression levels from different implementations
- * (native, unsafe Java, and safe Java) cannot be compared with one another.
+ * (native, and safe Java) cannot be compared with one another.
* Specifically, the native implementation of a high compression level
- * is not necessarily faster than the safe/unsafe Java implementation
+ * is not necessarily faster than the safe Java implementation
* of the same compression level.
*
* @param compressionLevel the compression level between [1, 17]; the higher the level, the higher the compression ratio
diff --git a/src/java/net/jpountz/xxhash/XXHashFactory.java b/src/java/net/jpountz/xxhash/XXHashFactory.java
index 9a9b4d1..9ccdf76 100644
--- a/src/java/net/jpountz/xxhash/XXHashFactory.java
+++ b/src/java/net/jpountz/xxhash/XXHashFactory.java
@@ -28,8 +28,6 @@ import net.jpountz.util.Utils;
* <a href="http://code.google.com/p/xxhash/">the original LZ4 C implementation</a>.
* <li>a {@link #safeInstance() safe Java} instance which is a pure Java port
* of the original C library,</li>
- * <li>an {@link #unsafeInstance() unsafe Java} instance which is a Java port
- * using the unofficial {@link sun.misc.Unsafe} API.
* </ul>
* <p>
* 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);
}

View File

@ -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;

98
2-remove-cpptasks.patch Normal file
View File

@ -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 @@
-->
<project name="lz4" default="dist" basedir="."
- xmlns:cpptasks="antlib:net.sf.antcontrib.cpptasks"
xmlns:ivy="antlib:org.apache.ivy.ant"
xmlns:junit4="antlib:com.carrotsearch.junit4"
xmlns:mvn="antlib:org.apache.maven.artifact.ant">
@@ -78,13 +77,6 @@
<get src="https://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.jar.version}/${ivy.jar.name}" dest="${user.home}/.ant/lib/${ivy.jar.name}"/>
</target>
- <target name="install-cpptasks" unless="cpptasks.available">
- <ivy:cachepath organisation="ant-contrib" module="cpptasks" revision="1.0b5"
- inline="true" conf="default" transitive="true" pathid="cpptasks.classpath"/>
- <taskdef uri="antlib:net.sf.antcontrib.cpptasks" resource="net/sf/antcontrib/cpptasks/antlib.xml" classpathref="cpptasks.classpath"/>
- <property name="cpptasks.available" value="true"/>
- </target>
-
<target name="install-maven-ant-tasks" unless="maven-ant-tasks.available">
<ivy:cachepath organisation="org.apache.maven" module="maven-ant-tasks" revision="2.1.3"
inline="true" conf="default" transitive="true" pathid="maven-ant-tasks.classpath"/>
@@ -184,27 +176,13 @@
</javah>
</target>
- <target name="compile-jni" depends="install-cpptasks,generate-headers" unless="${skip.jni}">
+ <target name="compile-jni" depends="generate-headers" unless="${skip.jni}">
<mkdir dir="${build}/objects" />
<mkdir dir="${build}/jni/net/jpountz/util/${platform}/${os.arch}" />
- <cpptasks:cc
- debug="false"
- optimize="extreme"
- objdir="${build}/objects"
- outfile="${build}/jni/net/jpountz/util/${platform}/${os.arch}/lz4-java"
- outtype="shared">
- <includepath path="${src}/lz4/lib" />
- <includepath path="${java.home}/../include" />
- <includepath path="${java.home}/../include/${platform}/" />
- <!-- In Java 9, java.home points not to jre/ but to the top directory -->
- <includepath path="${java.home}/include" />
- <includepath path="${java.home}/include/${platform}/" />
- <includepath path="${build}/jni-headers" />
- <fileset dir="${src}/lz4/lib" includes="lz4.c, lz4hc.c, xxhash.c" />
- <fileset dir="${src}/jni" includes="*.c" />
- <linker />
- <compilerarg value="-mmacosx-version-min=10.9" if="isMacOS"/>
- </cpptasks:cc>
+ <exec executable="make" failonerror="true">
+ <env key="ARCH" value="${os.arch}"/>
+ <env key="PLATFORM" value="${platform}"/>
+ </exec>
</target>
<target name="compile" depends="compile-java, compile-jni" />

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,15 @@
diff --git a/build.xml b/build.xml
index 8c08fd3..b46990d 100644
--- a/build.xml
+++ b/build.xml
@@ -54,10 +54,6 @@
<os family="mac"/>
</condition>
- <condition property="java10+">
- <javaversion atleast="10"/>
- </condition>
-
<target name="clean" description="clean working copy">
<delete dir="${build}" />
<delete dir="${dist}" />

44
5-build-libs.patch Normal file
View File

@ -0,0 +1,44 @@
diff --git a/Makefile b/Makefile
index 3495c8f..7b20f5c 100644
--- a/Makefile
+++ b/Makefile
@@ -4,22 +4,24 @@ 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
+LZ4_LIB_DIR = src/lz4/lib
+INCLUDE = -I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/linux -I $(LZ4_LIB_DIR)
-LIBS = -llz4 -lxxhash
JNI_PREFIX = net_jpountz_
default: all move_objects generate_so
all:
+ $(CC) -shared -o $(BUILD_DIR)/liblz4.so -fPIC $(LZ4_LIB_DIR)/lz4.c
+ $(CC) -shared -o $(BUILD_DIR)/liblz4hc.so -fPIC $(LZ4_LIB_DIR)/lz4hc.c
+ $(CC) -shared -o $(BUILD_DIR)/liblz4frame.so -fPIC $(LZ4_LIB_DIR)/lz4frame.c
+ $(CC) -shared -o $(BUILD_DIR)/libxxhash.so -fPIC $(LZ4_LIB_DIR)/xxhash.c
$(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:
@@ -28,6 +30,8 @@ move_objects:
generate_so:
gcc -fPIC -shared \
$(OBJECTS_DIR)/*.o \
- $(LIB_DIR)/liblz4.so \
- $(LIB_DIR)/libxxhash.so \
+ $(BUILD_DIR)/liblz4.so \
+ $(BUILD_DIR)/liblz4hc.so \
+ $(BUILD_DIR)/liblz4frame.so \
+ $(BUILD_DIR)/libxxhash.so \
-o $(BUILD_DIR)/jni/net/jpountz/util/$(PLATFORM)/$(ARCH)/liblz4-java.so

206
lz4-java.spec Normal file
View File

@ -0,0 +1,206 @@
# empty debuginfo
%global debug_package %nil
%global lz4_version 1.9.2
Name: lz4-java
Version: 1.7.1
Release: 14%{?dist}
Summary: LZ4 compression for Java
# GPL:
# src/lz4/
# BSD:
# src/lz4/libs
License: ASL 2.0 and (BSD and GPLv2+)
# GPLv2+ and BSD for lz4 and xxhash libs that are shared in liblz4-java.so
URL: https://github.com/lz4/lz4-java
Source0: https://github.com/lz4/lz4-java/archive/%{version}.tar.gz
Source1: https://github.com/lz4/lz4/archive/v%{lz4_version}.tar.gz
# lz4-java v1.3.0 introduced usage of sun.misc.Unsafe, which would later become
# depricated in jdk 9 and kept as an unexposed API in later jdk releases.
# lz4-java optionally uses Unsafe to achieve faster compression and decompression,
# however it's implementation is not critical to functionality, and can be removed.
Patch0: 0-remove-unsafe.patch
# After updating mvel to version 2.4.10, MVEL generated classes have formatting issues where
# code after comments are not being formatted with new lines. As a result, including comments
# in the templates results in classes with invalid code following the first comment.
# This patch simply removes comments from the templates so the classes can be generated as expected.
# Related bug: https://github.com/mvel/mvel/issues/152
Patch1: 1-remove-comments-from-templates.patch
# Adds a simple makefile to be run in-place of the cpptasks in the build.xml
Patch2: 2-remove-cpptasks.patch
# some lz4-java tests require randomizedtesting, which is not currently
# shipped or maintained in Fedora; remove those and use system ant-junit to run applicable tests
Patch3: 3-remove-randomizedtesting-tests.patch
# RHSCL: condition doesn't support the nested "javaversion" element
Patch4: 4-remove-javaversion.patch
# RHSCL: build missing lz4 and xxhash libs required for liblz4-java.so
Patch5: 5-build-libs.patch
ExclusiveArch: x86_64
# Build tools
BuildRequires: apache-parent
BuildRequires: ant
BuildRequires: ant-junit
BuildRequires: aqute-bnd
BuildRequires: gcc
BuildRequires: ivy-local
BuildRequires: java-devel
BuildRequires: javapackages-local
BuildRequires: lz4
BuildRequires: mvel
BuildRequires: objectweb-asm
BuildRequires: xerces-j2
Provides: bundled(xxhash) = r37
Provides: bundled(lz4) = 1.9.2
%description
LZ4 compression for Java, based on Yann Collet's work.
This library provides access to two compression methods
that both generate a valid LZ4 stream:
* fast scan (LZ4):
° low memory footprint (~ 16 KB),
° very fast (fast scan with skipping heuristics in case the
input looks incompressible),
° reasonable compression ratio (depending on the
redundancy of the input).
* high compression (LZ4 HC):
° medium memory footprint (~ 256 KB),
° rather slow (~ 10 times slower than LZ4),
° good compression ratio (depending on the size and
the redundancy of the input).
The streams produced by those 2 compression algorithms use the
same compression format, are very fast to decompress and can be
decompressed by the same decompressor instance.
%package javadoc
Summary: Javadoc for %{name}
BuildArch: noarch
%description javadoc
This package contains javadoc for %{name}.
%prep
%setup -q -n %{name}-%{version}
%setup -q -T -D -a 1 -n %{name}-%{version}
mv lz4-1.9.2/* src/lz4/
%patch0 -p1
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
# Cleanup
find -name '*.dylib' -print -delete
find -name '*.so' -print -delete
%build
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
ant -Divy.mode=local -Divy.revision=1.7.1 -Divy.pom.version=1.7.1 jar test docs makepom
bnd wrap -p lz4-java.bnd -o dist/lz4-java-%{version}.jar --version %{version} dist/lz4-java.jar
%install
%mvn_artifact dist/lz4-java-%{version}.pom dist/lz4-java-%{version}.jar
%mvn_install -J build/docs
%files -f .mfiles
%doc CHANGES.md README.md
%files javadoc -f .mfiles-javadoc
%license LICENSE.txt
%changelog
* Fri Feb 19 2021 Alex Macdonald <almacdon@redhat.com> 1.7.1-14
- Add ExclusiveArch: x86_64
* Wed Feb 17 2021 Alex Macdonald <almacdon@redhat.com> 1.7.1-13
- Bundle missing xxhash and lz4 components & adjust local Makefile
* Wed Jan 13 2021 Alex Macdonald <almacdon@redhat.com> 1.7.1-12
- remove hardcoded lib directory in the Makefile
* Fri Jan 08 2021 Alex Macdonald <almacdon@redhat.com> 1.7.1-11
- remove hardcoded "amd64" directory path in the Makefile
* Wed Dec 09 2020 Alex Macdonald <almacdon@redhat.com> 1.7.1-10
- remove BuildArch: noarch
* Tue Dec 01 2020 Alex Macdonald <almacdon@redhat.com> 1.7.1-9
- run unit tests on classes that do not require randomizedtesting
- add liblz4-java.so generation step to Makefile
- remove mvn_file macro for lz4
* Thu Nov 19 2020 Alex Macdonald <almacdon@redhat.com> 1.7.1-8
- remove dependency on cpptasks
* Mon Nov 16 2020 Alex Macdonald <almacdon@redhat.com> 1.7.1-7
- cleanup whitespace in the local patch to remove comments from templates
- use system lz4 and xxhash instead of bundling the dependencies
* Tue Oct 06 2020 Alex Macdonald <almacdon@redhat.com> 1.7.1-6
- include patch to strip comments from mvel templates
* Tue Sep 15 2020 Alex Macdonald <almacdon@redhat.com> 1.7.1-5
- add "BuildArch: noarch" to fix rpmlint error: no-binary
* Wed Sep 09 2020 Alex Macdonald <almacdon@redhat.com> 1.7.1-4
- fixed sources to have both lz4-java and lz4
* Wed Aug 05 2020 Alex Macdonald <almacdon@redhat.com> 1.7.1-3
- used commit from Jie Kang's fork of lz4-java to update to upstream 1.7.1
- this prevents tests from running; eliminates the need for randomizedtesting for f33 onward
- remove dependency on bea-stax
- remove all usage of sun.misc.Unsafe
* Tue Aug 04 2020 Alex Macdonald <almacdon@redhat.com> 1.7.1-2
- Included the lz4 submodule inside the lz4-java source tarball
* Thu Jul 30 2020 Alex Macdonald <almacdon@redhat.com> 1.7.1-1
- Update to version 1.7.1
* Wed Jan 29 2020 Fedora Release Engineering <releng@fedoraproject.org> - 1.3.0-13
- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild
* Wed Jul 24 2019 Fabio Valentini <decathorpe@gmail.com> - 1.3.0-12
- Add BuildRequires: gcc to fix FTBFS issue.
* Fri Feb 01 2019 Fedora Release Engineering <releng@fedoraproject.org> - 1.3.0-11
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild
* Fri Jul 13 2018 Fedora Release Engineering <releng@fedoraproject.org> - 1.3.0-10
- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild
* Thu Feb 08 2018 Fedora Release Engineering <releng@fedoraproject.org> - 1.3.0-9
- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild
* Thu Aug 03 2017 Fedora Release Engineering <releng@fedoraproject.org> - 1.3.0-8
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Binutils_Mass_Rebuild
* Wed Jul 26 2017 Fedora Release Engineering <releng@fedoraproject.org> - 1.3.0-7
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild
* Sun Feb 19 2017 gil cattaneo <puntogil@libero.it> 1.3.0-6
- disable test suite on ppc64
* Fri Feb 10 2017 Fedora Release Engineering <releng@fedoraproject.org> - 1.3.0-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild
* Mon Sep 12 2016 gil cattaneo <puntogil@libero.it> 1.3.0-4
- exclude aarch64
* Tue May 03 2016 gil cattaneo <puntogil@libero.it> 1.3.0-3
- fix test suite
* Tue May 03 2016 gil cattaneo <puntogil@libero.it> 1.3.0-2
- unbundle lz4 code (lz4-java issues#74)
* Mon Jul 20 2015 gil cattaneo <puntogil@libero.it> 1.3.0-1
- initial rpm

2
sources Normal file
View File

@ -0,0 +1,2 @@
SHA1 (1.7.1.tar.gz) = c0935ff2f1de0eb2c1762632af9c28b409cc5ff8
SHA1 (v1.9.2.tar.gz) = 4dc36f29d7b4e5b45b114be2674068200714abb3