mirror of
https://github.com/xerial/snappy-java.git
synced 2025-04-08 19:35:08 +02:00
Add BitShuffleNative for the JNI interfaces of bitshuffle
This commit is contained in:
parent
b695e378b1
commit
0df5e90422
48
Makefile
48
Makefile
@ -16,15 +16,13 @@ SNAPPY_GIT_REV:=2b9152d9c5bed71dffb7f7f6c7a3ec48b058ff2d # 1.1.3 with autogen.sh
|
|||||||
SNAPPY_UNPACKED:=$(TARGET)/snappy-extracted.log
|
SNAPPY_UNPACKED:=$(TARGET)/snappy-extracted.log
|
||||||
SNAPPY_GIT_UNPACKED:=$(TARGET)/snappy-git-extracted.log
|
SNAPPY_GIT_UNPACKED:=$(TARGET)/snappy-git-extracted.log
|
||||||
|
|
||||||
ifdef ENABLE_BITSHUFFLE
|
# TODO: Upgrade to a stable release
|
||||||
# TODO: Upgrade to a stable release
|
BITSHUFFLE_VERSION:=55f9b4caec73fa21d13947cacea1295926781440
|
||||||
BITSHUFFLE_VERSION:=55f9b4caec73fa21d13947cacea1295926781440
|
BITSHUFFLE_ARCHIVE:=$(TARGET)/bitshuffle-$(BITSHUFFLE_VERSION).tar.gz
|
||||||
BITSHUFFLE_ARCHIVE:=$(TARGET)/bitshuffle-$(BITSHUFFLE_VERSION).tar.gz
|
BITSHUFFLE_C:=bitshuffle_core.c iochain.c
|
||||||
BITSHUFFLE_C:=bitshuffle_core.c iochain.c
|
BITSHUFFLE_SRC_DIR:=$(TARGET)/bitshuffle-$(BITSHUFFLE_VERSION)/src
|
||||||
BITSHUFFLE_SRC_DIR:=$(TARGET)/bitshuffle-$(BITSHUFFLE_VERSION)/src
|
BITSHUFFLE_SRC:=$(addprefix $(BITSHUFFLE_SRC_DIR)/,$(BITSHUFFLE_C))
|
||||||
BITSHUFFLE_SRC:=$(addprefix $(BITSHUFFLE_SRC_DIR)/,$(BITSHUFFLE_C))
|
BITSHUFFLE_UNPACKED:=$(TARGET)/bitshuffle-extracted.log
|
||||||
BITSHUFFLE_UNPACKED:=$(TARGET)/bitshuffle-extracted.log
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifdef USE_GIT
|
ifdef USE_GIT
|
||||||
ifndef GIT_REPO_URL
|
ifndef GIT_REPO_URL
|
||||||
@ -35,29 +33,23 @@ ifdef USE_GIT
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifdef ENABLE_BITSHUFFLE
|
$(BITSHUFFLE_ARCHIVE):
|
||||||
$(BITSHUFFLE_ARCHIVE):
|
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
curl -L -o$@ https://github.com/kiyo-masui/bitshuffle/archive/$(BITSHUFFLE_VERSION).tar.gz
|
curl -L -o$@ https://github.com/kiyo-masui/bitshuffle/archive/$(BITSHUFFLE_VERSION).tar.gz
|
||||||
|
|
||||||
$(BITSHUFFLE_UNPACKED): $(BITSHUFFLE_ARCHIVE)
|
$(BITSHUFFLE_UNPACKED): $(BITSHUFFLE_ARCHIVE)
|
||||||
$(TAR) xvfz $< -C $(TARGET)
|
$(TAR) xvfz $< -C $(TARGET)
|
||||||
touch $@
|
touch $@
|
||||||
|
|
||||||
$(BITSHUFFLE_SRC): $(BITSHUFFLE_UNPACKED)
|
$(BITSHUFFLE_SRC): $(BITSHUFFLE_UNPACKED)
|
||||||
|
|
||||||
$(SNAPPY_OUT)/%.o : $(BITSHUFFLE_SRC_DIR)/%.c
|
$(SNAPPY_OUT)/%.o : $(BITSHUFFLE_SRC_DIR)/%.c
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||||
|
|
||||||
SNAPPY_OBJ:=$(addprefix $(SNAPPY_OUT)/,$(patsubst %.cc,%.o,$(SNAPPY_CC)) $(patsubst %.c,%.o,$(BITSHUFFLE_C)) SnappyNative.o)
|
SNAPPY_OBJ:=$(addprefix $(SNAPPY_OUT)/,$(patsubst %.cc,%.o,$(SNAPPY_CC)) $(patsubst %.c,%.o,$(BITSHUFFLE_C)) SnappyNative.o)
|
||||||
|
|
||||||
CXXFLAGS:=$(CXXFLAGS) -DSNAPPY_BITSHUFFLE_ENABLED -I$(SNAPPY_SRC_DIR) -I$(BITSHUFFLE_SRC_DIR)
|
CXXFLAGS:=$(CXXFLAGS) -DSNAPPY_BITSHUFFLE_ENABLED -I$(SNAPPY_SRC_DIR) -I$(BITSHUFFLE_SRC_DIR)
|
||||||
else
|
|
||||||
SNAPPY_OBJ:=$(addprefix $(SNAPPY_OUT)/,$(patsubst %.cc,%.o,$(SNAPPY_CC)) SnappyNative.o)
|
|
||||||
|
|
||||||
CXXFLAGS:=$(CXXFLAGS) -I$(SNAPPY_SRC_DIR)
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(OS_NAME),SunOS)
|
ifeq ($(OS_NAME),SunOS)
|
||||||
TAR:= gtar
|
TAR:= gtar
|
||||||
@ -82,7 +74,7 @@ $(SNAPPY_GIT_UNPACKED):
|
|||||||
cd $(SNAPPY_SRC_DIR) && ./autogen.sh && ./configure
|
cd $(SNAPPY_SRC_DIR) && ./autogen.sh && ./configure
|
||||||
touch $@
|
touch $@
|
||||||
|
|
||||||
jni-header: $(SRC)/org/xerial/snappy/SnappyNative.h
|
jni-header: $(SRC)/org/xerial/snappy/SnappyNative.h $(SRC)/org/xerial/snappy/BitShuffleNative.h
|
||||||
|
|
||||||
$(TARGET)/jni-classes/org/xerial/snappy/SnappyNative.class : $(SRC)/org/xerial/snappy/SnappyNative.java
|
$(TARGET)/jni-classes/org/xerial/snappy/SnappyNative.class : $(SRC)/org/xerial/snappy/SnappyNative.java
|
||||||
@mkdir -p $(TARGET)/jni-classes
|
@mkdir -p $(TARGET)/jni-classes
|
||||||
@ -91,17 +83,25 @@ $(TARGET)/jni-classes/org/xerial/snappy/SnappyNative.class : $(SRC)/org/xerial/s
|
|||||||
$(SRC)/org/xerial/snappy/SnappyNative.h: $(TARGET)/jni-classes/org/xerial/snappy/SnappyNative.class
|
$(SRC)/org/xerial/snappy/SnappyNative.h: $(TARGET)/jni-classes/org/xerial/snappy/SnappyNative.class
|
||||||
$(JAVAH) -force -classpath $(TARGET)/jni-classes -o $@ org.xerial.snappy.SnappyNative
|
$(JAVAH) -force -classpath $(TARGET)/jni-classes -o $@ org.xerial.snappy.SnappyNative
|
||||||
|
|
||||||
|
|
||||||
|
$(TARGET)/jni-classes/org/xerial/snappy/BitShuffleNative.class : $(SRC)/org/xerial/snappy/BitShuffleNative.java
|
||||||
|
@mkdir -p $(TARGET)/jni-classes
|
||||||
|
$(JAVAC) -source 1.6 -target 1.6 -d $(TARGET)/jni-classes -sourcepath $(SRC) $<
|
||||||
|
|
||||||
|
$(SRC)/org/xerial/snappy/BitShuffleNative.h: $(TARGET)/jni-classes/org/xerial/snappy/BitShuffleNative.class
|
||||||
|
$(JAVAH) -force -classpath $(TARGET)/jni-classes -o $@ org.xerial.snappy.BitShuffleNative
|
||||||
|
|
||||||
$(SNAPPY_SRC): $(SNAPPY_GIT_UNPACKED)
|
$(SNAPPY_SRC): $(SNAPPY_GIT_UNPACKED)
|
||||||
|
|
||||||
$(SNAPPY_OUT)/%.o : $(SNAPPY_SRC_DIR)/%.cc
|
$(SNAPPY_OUT)/%.o : $(SNAPPY_SRC_DIR)/%.cc
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||||
|
|
||||||
$(SNAPPY_OUT)/SnappyNative.o : $(SRC)/org/xerial/snappy/SnappyNative.cpp $(SRC)/org/xerial/snappy/SnappyNative.h
|
#$(SNAPPY_OUT)/SnappyNative.o : $(SRC)/org/xerial/snappy/SnappyNative.cpp $(SRC)/org/xerial/snappy/SnappyNative.h $(SRC)/org/xerial/snappy/BitShufflenative.h
|
||||||
|
$(SNAPPY_OUT)/SnappyNative.o : $(SRC)/org/xerial/snappy/SnappyNative.cpp jni-header
|
||||||
@mkdir -p $(@D)
|
@mkdir -p $(@D)
|
||||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
|
||||||
$(SNAPPY_OUT)/$(LIBNAME): $(SNAPPY_OBJ)
|
$(SNAPPY_OUT)/$(LIBNAME): $(SNAPPY_OBJ)
|
||||||
$(CXX) $(CXXFLAGS) -o $@ $+ $(LINKFLAGS)
|
$(CXX) $(CXXFLAGS) -o $@ $+ $(LINKFLAGS)
|
||||||
$(STRIP) $@
|
$(STRIP) $@
|
||||||
|
@ -30,7 +30,7 @@ public class BitShuffle
|
|||||||
{
|
{
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
impl = SnappyLoader.load();
|
impl = SnappyLoader.loadBitShuffleApi();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
throw new ExceptionInInitializerError(e);
|
throw new ExceptionInInitializerError(e);
|
||||||
@ -38,9 +38,9 @@ public class BitShuffle
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An instance of SnappyNative
|
* An instance of BitShuffleNative
|
||||||
*/
|
*/
|
||||||
private static SnappyNative impl;
|
private static BitShuffleNative impl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply a bit-shuffling filter into the input short array.
|
* Apply a bit-shuffling filter into the input short array.
|
||||||
|
37
src/main/java/org/xerial/snappy/BitShuffleNative.h
Normal file
37
src/main/java/org/xerial/snappy/BitShuffleNative.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||||
|
#include <jni.h>
|
||||||
|
/* Header for class org_xerial_snappy_BitShuffleNative */
|
||||||
|
|
||||||
|
#ifndef _Included_org_xerial_snappy_BitShuffleNative
|
||||||
|
#define _Included_org_xerial_snappy_BitShuffleNative
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
/*
|
||||||
|
* Class: org_xerial_snappy_BitShuffleNative
|
||||||
|
* Method: supportBitSuffle
|
||||||
|
* Signature: ()Z
|
||||||
|
*/
|
||||||
|
JNIEXPORT jboolean JNICALL Java_org_xerial_snappy_BitShuffleNative_supportBitSuffle
|
||||||
|
(JNIEnv *, jobject);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_xerial_snappy_BitShuffleNative
|
||||||
|
* Method: bitShuffle
|
||||||
|
* Signature: (Ljava/lang/Object;IIILjava/lang/Object;I)I
|
||||||
|
*/
|
||||||
|
JNIEXPORT jint JNICALL Java_org_xerial_snappy_BitShuffleNative_bitShuffle
|
||||||
|
(JNIEnv *, jobject, jobject, jint, jint, jint, jobject, jint);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_xerial_snappy_BitShuffleNative
|
||||||
|
* Method: bitUnShuffle
|
||||||
|
* Signature: (Ljava/lang/Object;IIILjava/lang/Object;I)I
|
||||||
|
*/
|
||||||
|
JNIEXPORT jint JNICALL Java_org_xerial_snappy_BitShuffleNative_bitUnShuffle
|
||||||
|
(JNIEnv *, jobject, jobject, jint, jint, jint, jobject, jint);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
58
src/main/java/org/xerial/snappy/BitShuffleNative.java
Normal file
58
src/main/java/org/xerial/snappy/BitShuffleNative.java
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/*--------------------------------------------------------------------------
|
||||||
|
* Copyright 2011 Taro L. Saito
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*--------------------------------------------------------------------------*/
|
||||||
|
//--------------------------------------
|
||||||
|
// snappy-java Project
|
||||||
|
//
|
||||||
|
// BitShuffleNative.java
|
||||||
|
// Since: 2016/03/31
|
||||||
|
//
|
||||||
|
// $URL$
|
||||||
|
// $Author$
|
||||||
|
//--------------------------------------
|
||||||
|
package org.xerial.snappy;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JNI interfaces of the {@link BitShuffle} implementation. The native method in this class is
|
||||||
|
* defined in BitShuffleNative.h (genereted by javah) and BitShuffleNative.cpp
|
||||||
|
* <p/>
|
||||||
|
* <p>
|
||||||
|
* <b> DO NOT USE THIS CLASS since the direct use of this class might break the
|
||||||
|
* native library code loading in {@link SnappyLoader}. </b>
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author leo
|
||||||
|
*/
|
||||||
|
public class BitShuffleNative
|
||||||
|
{
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
// Bit-shuffling routines to improve compression of typed binary data.
|
||||||
|
// A quick benchmark result can be found in a gist below;
|
||||||
|
// https://gist.github.com/maropu/01103215df34b317a7a7
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Returns true iff a native library loaded in JVMs can run bit-shuffling.
|
||||||
|
// Bit-shuffling is executable only in x86 environments that support SSE/AVX instructions.
|
||||||
|
public native boolean supportBitSuffle();
|
||||||
|
|
||||||
|
public native int bitShuffle(Object input, int inputOffset, int typeSize, int byteLength, Object output, int outputOffset)
|
||||||
|
throws IOException;
|
||||||
|
|
||||||
|
public native int bitUnShuffle(Object input, int inputOffset, int typeSize, int byteLength, Object output, int outputOffset)
|
||||||
|
throws IOException;
|
||||||
|
}
|
@ -44,7 +44,7 @@ public class Snappy
|
|||||||
{
|
{
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
impl = SnappyLoader.load();
|
impl = SnappyLoader.loadSnappyApi();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
throw new ExceptionInInitializerError(e);
|
throw new ExceptionInInitializerError(e);
|
||||||
@ -66,7 +66,7 @@ public class Snappy
|
|||||||
public static void cleanUp()
|
public static void cleanUp()
|
||||||
{
|
{
|
||||||
SnappyLoader.cleanUpExtractedNativeLib();
|
SnappyLoader.cleanUpExtractedNativeLib();
|
||||||
SnappyLoader.setApi(null);
|
SnappyLoader.setSnappyApi(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,13 +56,13 @@ public class SnappyBundleActivator
|
|||||||
library = library.replace(".dylib", ".jnilib");
|
library = library.replace(".dylib", ".jnilib");
|
||||||
}
|
}
|
||||||
System.loadLibrary(library);
|
System.loadLibrary(library);
|
||||||
SnappyLoader.setApi(new SnappyNative());
|
SnappyLoader.setSnappyApi(new SnappyNative());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop(BundleContext context)
|
public void stop(BundleContext context)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
SnappyLoader.setApi(null);
|
SnappyLoader.setSnappyApi(null);
|
||||||
SnappyLoader.cleanUpExtractedNativeLib();
|
SnappyLoader.cleanUpExtractedNativeLib();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,9 @@ public class SnappyLoader
|
|||||||
public static final String KEY_SNAPPY_DISABLE_BUNDLED_LIBS = "org.xerial.snappy.disable.bundled.libs"; // Depreciated, but preserved for backward compatibility
|
public static final String KEY_SNAPPY_DISABLE_BUNDLED_LIBS = "org.xerial.snappy.disable.bundled.libs"; // Depreciated, but preserved for backward compatibility
|
||||||
|
|
||||||
private static volatile boolean isLoaded = false;
|
private static volatile boolean isLoaded = false;
|
||||||
private static volatile SnappyNative api = null;
|
private static volatile SnappyNative snappyApi = null;
|
||||||
|
// TODO: Do we need a separate loader for [[BitShuffleNative]]?
|
||||||
|
private static volatile BitShuffleNative bitshuffleApi = null;
|
||||||
|
|
||||||
private static File nativeLibFile = null;
|
private static File nativeLibFile = null;
|
||||||
|
|
||||||
@ -95,13 +97,23 @@ public class SnappyLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the api instance.
|
* Set the `snappyApi` instance.
|
||||||
*
|
*
|
||||||
* @param nativeCode
|
* @param nativeCode
|
||||||
*/
|
*/
|
||||||
static synchronized void setApi(SnappyNative nativeCode)
|
static synchronized void setSnappyApi(SnappyNative nativeCode)
|
||||||
{
|
{
|
||||||
api = nativeCode;
|
snappyApi = nativeCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the `bitshuffleApi` instance.
|
||||||
|
*
|
||||||
|
* @param nativeCode
|
||||||
|
*/
|
||||||
|
static synchronized void setBitShuffleApi(BitShuffleNative nativeCode)
|
||||||
|
{
|
||||||
|
bitshuffleApi = nativeCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -142,16 +154,16 @@ public class SnappyLoader
|
|||||||
loadSnappySystemProperties();
|
loadSnappySystemProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
static synchronized SnappyNative load()
|
static synchronized SnappyNative loadSnappyApi()
|
||||||
{
|
{
|
||||||
if (api != null) {
|
if (snappyApi != null) {
|
||||||
return api;
|
return snappyApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
loadNativeLibrary();
|
loadNativeLibrary();
|
||||||
|
|
||||||
setApi(new SnappyNative());
|
setSnappyApi(new SnappyNative());
|
||||||
isLoaded = true;
|
isLoaded = true;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
@ -159,7 +171,27 @@ public class SnappyLoader
|
|||||||
throw new SnappyError(SnappyErrorCode.FAILED_TO_LOAD_NATIVE_LIBRARY, e.getMessage());
|
throw new SnappyError(SnappyErrorCode.FAILED_TO_LOAD_NATIVE_LIBRARY, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return api;
|
return snappyApi;
|
||||||
|
}
|
||||||
|
|
||||||
|
static synchronized BitShuffleNative loadBitShuffleApi()
|
||||||
|
{
|
||||||
|
if (bitshuffleApi != null) {
|
||||||
|
return bitshuffleApi;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
loadNativeLibrary();
|
||||||
|
|
||||||
|
setBitShuffleApi(new BitShuffleNative());
|
||||||
|
isLoaded = true;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new SnappyError(SnappyErrorCode.FAILED_TO_LOAD_NATIVE_LIBRARY, e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return bitshuffleApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <snappy.h>
|
#include <snappy.h>
|
||||||
#include "SnappyNative.h"
|
#include "SnappyNative.h"
|
||||||
|
#include "BitShuffleNative.h"
|
||||||
|
|
||||||
#ifdef SNAPPY_BITSHUFFLE_ENABLED
|
#ifdef SNAPPY_BITSHUFFLE_ENABLED
|
||||||
#include <bitshuffle.h>
|
#include <bitshuffle.h>
|
||||||
@ -34,7 +35,6 @@ void throw_exception(JNIEnv *env, jobject self, int errorCode)
|
|||||||
env->CallVoidMethod(self, mth_throwex, (jint) errorCode);
|
env->CallVoidMethod(self, mth_throwex, (jint) errorCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JNIEXPORT jstring JNICALL Java_org_xerial_snappy_SnappyNative_nativeLibraryVersion
|
JNIEXPORT jstring JNICALL Java_org_xerial_snappy_SnappyNative_nativeLibraryVersion
|
||||||
(JNIEnv * env, jobject self)
|
(JNIEnv * env, jobject self)
|
||||||
{
|
{
|
||||||
@ -46,9 +46,7 @@ JNIEXPORT jlong JNICALL Java_org_xerial_snappy_SnappyNative_rawCompress__JJJ
|
|||||||
size_t compressedLength;
|
size_t compressedLength;
|
||||||
snappy::RawCompress((char*) srcAddr, (size_t) length, (char*) destAddr, &compressedLength);
|
snappy::RawCompress((char*) srcAddr, (size_t) length, (char*) destAddr, &compressedLength);
|
||||||
return (jlong) compressedLength;
|
return (jlong) compressedLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
JNIEXPORT jlong JNICALL Java_org_xerial_snappy_SnappyNative_rawUncompress__JJJ
|
JNIEXPORT jlong JNICALL Java_org_xerial_snappy_SnappyNative_rawUncompress__JJJ
|
||||||
(JNIEnv* env, jobject self, jlong srcAddr, jlong length, jlong destAddr) {
|
(JNIEnv* env, jobject self, jlong srcAddr, jlong length, jlong destAddr) {
|
||||||
@ -63,9 +61,7 @@ JNIEXPORT jlong JNICALL Java_org_xerial_snappy_SnappyNative_rawUncompress__JJJ
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (jlong) uncompressedLength;
|
return (jlong) uncompressedLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_xerial_snappy_Snappy
|
* Class: org_xerial_snappy_Snappy
|
||||||
@ -87,7 +83,6 @@ JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_rawCompress__Ljava_ni
|
|||||||
return (jint) compressedLength;
|
return (jint) compressedLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_rawCompress__Ljava_lang_Object_2IILjava_lang_Object_2I
|
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_rawCompress__Ljava_lang_Object_2IILjava_lang_Object_2I
|
||||||
(JNIEnv * env, jobject self, jobject input, jint inputOffset, jint inputLen, jobject output, jint outputOffset)
|
(JNIEnv * env, jobject self, jobject input, jint inputOffset, jint inputLen, jobject output, jint outputOffset)
|
||||||
{
|
{
|
||||||
@ -146,7 +141,6 @@ JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_rawUncompress__Ljava_
|
|||||||
return (jint) uncompressedLength;
|
return (jint) uncompressedLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_xerial_snappy_Snappy
|
* Class: org_xerial_snappy_Snappy
|
||||||
* Method: uncompress
|
* Method: uncompress
|
||||||
@ -173,102 +167,6 @@ JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_rawUncompress__Ljava_
|
|||||||
return (jint) decompressedLength;
|
return (jint) decompressedLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: org_xerial_snappy_SnappyNative
|
|
||||||
* Method: supportBitSuffle
|
|
||||||
* Signature: ()Z
|
|
||||||
*/
|
|
||||||
JNIEXPORT jboolean JNICALL Java_org_xerial_snappy_SnappyNative_supportBitSuffle
|
|
||||||
(JNIEnv *, jobject) {
|
|
||||||
#ifdef SNAPPY_BITSHUFFLE_ENABLED
|
|
||||||
return (jboolean) true;
|
|
||||||
#else
|
|
||||||
return (jboolean) false;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: org_xerial_snappy_SnappyNative
|
|
||||||
* Method: bitShuffle
|
|
||||||
* Signature: (Ljava/lang/Object;IIILjava/lang/Object;I)I
|
|
||||||
*/
|
|
||||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_bitShuffle
|
|
||||||
(JNIEnv * env, jobject self, jobject input, jint inputOffset, jint typeSize, jint length, jobject output, jint outputOffset)
|
|
||||||
{
|
|
||||||
#ifdef SNAPPY_BITSHUFFLE_ENABLED
|
|
||||||
char* in = (char*) env->GetPrimitiveArrayCritical((jarray) input, 0);
|
|
||||||
char* out = (char*) env->GetPrimitiveArrayCritical((jarray) output, 0);
|
|
||||||
if(in == 0 || out == 0) {
|
|
||||||
// out of memory
|
|
||||||
if(in != 0) {
|
|
||||||
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
|
||||||
}
|
|
||||||
if(out != 0) {
|
|
||||||
env->ReleasePrimitiveArrayCritical((jarray) output, out, 0);
|
|
||||||
}
|
|
||||||
throw_exception(env, self, 4);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t processedBytes = bshuf_bitshuffle(
|
|
||||||
in + inputOffset, out + outputOffset, (size_t) (length / typeSize), (size_t) typeSize, 0);
|
|
||||||
|
|
||||||
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
|
||||||
env->ReleasePrimitiveArrayCritical((jarray) output, out, 0);
|
|
||||||
|
|
||||||
return (jint) processedBytes;
|
|
||||||
#else
|
|
||||||
// Returns an error code for unsupported operations
|
|
||||||
throw_exception(env, self, 1);
|
|
||||||
return (jint) 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: org_xerial_snappy_SnappyNative
|
|
||||||
* Method: bitUnShuffle
|
|
||||||
* Signature: (Ljava/lang/Object;IIILjava/lang/Object;I)I
|
|
||||||
*/
|
|
||||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_bitUnShuffle
|
|
||||||
(JNIEnv * env, jobject self, jobject input, jint inputOffset, jint typeSize, jint length, jobject output, jint outputOffset)
|
|
||||||
{
|
|
||||||
#ifdef SNAPPY_BITSHUFFLE_ENABLED
|
|
||||||
char* in = (char*) env->GetPrimitiveArrayCritical((jarray) input, 0);
|
|
||||||
char* out = (char*) env->GetPrimitiveArrayCritical((jarray) output, 0);
|
|
||||||
if(in == 0 || out == 0) {
|
|
||||||
// out of memory
|
|
||||||
if(in != 0) {
|
|
||||||
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
|
||||||
}
|
|
||||||
if(out != 0) {
|
|
||||||
env->ReleasePrimitiveArrayCritical((jarray) output, out, 0);
|
|
||||||
}
|
|
||||||
throw_exception(env, self, 4);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t processedBytes = bshuf_bitunshuffle(
|
|
||||||
in + inputOffset, out + outputOffset, (size_t) (length / typeSize), (size_t) typeSize, 0);
|
|
||||||
|
|
||||||
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
|
||||||
env->ReleasePrimitiveArrayCritical((jarray) output, out, 0);
|
|
||||||
|
|
||||||
return (jint) processedBytes;
|
|
||||||
#else
|
|
||||||
// Returns an error code for unsupported operations
|
|
||||||
throw_exception(env, self, 1);
|
|
||||||
return (jint) 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_xerial_snappy_Snappy
|
* Class: org_xerial_snappy_Snappy
|
||||||
* Method: maxCompressedLength
|
* Method: maxCompressedLength
|
||||||
@ -339,8 +237,7 @@ JNIEXPORT jlong JNICALL Java_org_xerial_snappy_SnappyNative_uncompressedLength__
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (jint) result;
|
return (jint) result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JNIEXPORT jboolean JNICALL Java_org_xerial_snappy_SnappyNative_isValidCompressedBuffer__Ljava_nio_ByteBuffer_2II
|
JNIEXPORT jboolean JNICALL Java_org_xerial_snappy_SnappyNative_isValidCompressedBuffer__Ljava_nio_ByteBuffer_2II
|
||||||
(JNIEnv * env, jobject self, jobject compressed, jint cpos, jint clen)
|
(JNIEnv * env, jobject self, jobject compressed, jint cpos, jint clen)
|
||||||
@ -405,4 +302,91 @@ JNIEXPORT void JNICALL Java_org_xerial_snappy_SnappyNative_arrayCopy
|
|||||||
env->ReleasePrimitiveArrayCritical((jarray) output, dest, 0);
|
env->ReleasePrimitiveArrayCritical((jarray) output, dest, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_xerial_snappy_SnappyNative
|
||||||
|
* Method: supportBitSuffle
|
||||||
|
* Signature: ()Z
|
||||||
|
*/
|
||||||
|
JNIEXPORT jboolean JNICALL Java_org_xerial_snappy_BitShuffleNative_supportBitSuffle
|
||||||
|
(JNIEnv *, jobject) {
|
||||||
|
#ifdef SNAPPY_BITSHUFFLE_ENABLED
|
||||||
|
return (jboolean) true;
|
||||||
|
#else
|
||||||
|
return (jboolean) false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_xerial_snappy_SnappyNative
|
||||||
|
* Method: bitShuffle
|
||||||
|
* Signature: (Ljava/lang/Object;IIILjava/lang/Object;I)I
|
||||||
|
*/
|
||||||
|
JNIEXPORT jint JNICALL Java_org_xerial_snappy_BitShuffleNative_bitShuffle
|
||||||
|
(JNIEnv * env, jobject self, jobject input, jint inputOffset, jint typeSize, jint length, jobject output, jint outputOffset)
|
||||||
|
{
|
||||||
|
#ifdef SNAPPY_BITSHUFFLE_ENABLED
|
||||||
|
char* in = (char*) env->GetPrimitiveArrayCritical((jarray) input, 0);
|
||||||
|
char* out = (char*) env->GetPrimitiveArrayCritical((jarray) output, 0);
|
||||||
|
if(in == 0 || out == 0) {
|
||||||
|
// out of memory
|
||||||
|
if(in != 0) {
|
||||||
|
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
||||||
|
}
|
||||||
|
if(out != 0) {
|
||||||
|
env->ReleasePrimitiveArrayCritical((jarray) output, out, 0);
|
||||||
|
}
|
||||||
|
throw_exception(env, self, 4);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t processedBytes = bshuf_bitshuffle(
|
||||||
|
in + inputOffset, out + outputOffset, (size_t) (length / typeSize), (size_t) typeSize, 0);
|
||||||
|
|
||||||
|
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
||||||
|
env->ReleasePrimitiveArrayCritical((jarray) output, out, 0);
|
||||||
|
|
||||||
|
return (jint) processedBytes;
|
||||||
|
#else
|
||||||
|
// Returns an error code for unsupported operations
|
||||||
|
throw_exception(env, self, 1);
|
||||||
|
return (jint) 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_xerial_snappy_SnappyNative
|
||||||
|
* Method: bitUnShuffle
|
||||||
|
* Signature: (Ljava/lang/Object;IIILjava/lang/Object;I)I
|
||||||
|
*/
|
||||||
|
JNIEXPORT jint JNICALL Java_org_xerial_snappy_BitShuffleNative_bitUnShuffle
|
||||||
|
(JNIEnv * env, jobject self, jobject input, jint inputOffset, jint typeSize, jint length, jobject output, jint outputOffset)
|
||||||
|
{
|
||||||
|
#ifdef SNAPPY_BITSHUFFLE_ENABLED
|
||||||
|
char* in = (char*) env->GetPrimitiveArrayCritical((jarray) input, 0);
|
||||||
|
char* out = (char*) env->GetPrimitiveArrayCritical((jarray) output, 0);
|
||||||
|
if(in == 0 || out == 0) {
|
||||||
|
// out of memory
|
||||||
|
if(in != 0) {
|
||||||
|
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
||||||
|
}
|
||||||
|
if(out != 0) {
|
||||||
|
env->ReleasePrimitiveArrayCritical((jarray) output, out, 0);
|
||||||
|
}
|
||||||
|
throw_exception(env, self, 4);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t processedBytes = bshuf_bitunshuffle(
|
||||||
|
in + inputOffset, out + outputOffset, (size_t) (length / typeSize), (size_t) typeSize, 0);
|
||||||
|
|
||||||
|
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
||||||
|
env->ReleasePrimitiveArrayCritical((jarray) output, out, 0);
|
||||||
|
|
||||||
|
return (jint) processedBytes;
|
||||||
|
#else
|
||||||
|
// Returns an error code for unsupported operations
|
||||||
|
throw_exception(env, self, 1);
|
||||||
|
return (jint) 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -63,30 +63,6 @@ JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_rawUncompress__Ljava_
|
|||||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_rawUncompress__Ljava_lang_Object_2IILjava_lang_Object_2I
|
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_rawUncompress__Ljava_lang_Object_2IILjava_lang_Object_2I
|
||||||
(JNIEnv *, jobject, jobject, jint, jint, jobject, jint);
|
(JNIEnv *, jobject, jobject, jint, jint, jobject, jint);
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: org_xerial_snappy_SnappyNative
|
|
||||||
* Method: supportBitSuffle
|
|
||||||
* Signature: ()Z
|
|
||||||
*/
|
|
||||||
JNIEXPORT jboolean JNICALL Java_org_xerial_snappy_SnappyNative_supportBitSuffle
|
|
||||||
(JNIEnv *, jobject);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: org_xerial_snappy_SnappyNative
|
|
||||||
* Method: bitShuffle
|
|
||||||
* Signature: (Ljava/lang/Object;IIILjava/lang/Object;I)I
|
|
||||||
*/
|
|
||||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_bitShuffle
|
|
||||||
(JNIEnv *, jobject, jobject, jint, jint, jint, jobject, jint);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Class: org_xerial_snappy_SnappyNative
|
|
||||||
* Method: bitUnShuffle
|
|
||||||
* Signature: (Ljava/lang/Object;IIILjava/lang/Object;I)I
|
|
||||||
*/
|
|
||||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_bitUnShuffle
|
|
||||||
(JNIEnv *, jobject, jobject, jint, jint, jint, jobject, jint);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_xerial_snappy_SnappyNative
|
* Class: org_xerial_snappy_SnappyNative
|
||||||
* Method: maxCompressedLength
|
* Method: maxCompressedLength
|
||||||
|
@ -66,21 +66,6 @@ public class SnappyNative
|
|||||||
public native int rawUncompress(Object input, int inputOffset, int inputLength, Object output, int outputOffset)
|
public native int rawUncompress(Object input, int inputOffset, int inputLength, Object output, int outputOffset)
|
||||||
throws IOException;
|
throws IOException;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
// Bit-shuffling routines to improve compression of typed binary data.
|
|
||||||
// A quick benchmark result can be found in a gist below;
|
|
||||||
// https://gist.github.com/maropu/01103215df34b317a7a7
|
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Returns true iff a native library loaded in JVMs can run bit-shuffling.
|
|
||||||
// Bit-shuffling is executable only in x86 environments that support SSE/AVX instructions.
|
|
||||||
public native boolean supportBitSuffle();
|
|
||||||
|
|
||||||
public native int bitShuffle(Object input, int inputOffset, int typeSize, int byteLength, Object output, int outputOffset)
|
|
||||||
throws IOException;
|
|
||||||
|
|
||||||
public native int bitUnShuffle(Object input, int inputOffset, int typeSize, int byteLength, Object output, int outputOffset)
|
|
||||||
throws IOException;
|
|
||||||
|
|
||||||
// Returns the maximal size of the compressed representation of
|
// Returns the maximal size of the compressed representation of
|
||||||
// input data that is "source_bytes" bytes in length;
|
// input data that is "source_bytes" bytes in length;
|
||||||
|
Binary file not shown.
@ -117,7 +117,7 @@ public class SnappyLoaderTest
|
|||||||
public void load()
|
public void load()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
SnappyLoader.load();
|
SnappyLoader.loadSnappyApi();
|
||||||
_logger.debug(Snappy.maxCompressedLength(1024));
|
_logger.debug(Snappy.maxCompressedLength(1024));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user