Edit documentation

This commit is contained in:
Taro L. Saito 2011-06-24 09:06:20 +09:00
parent 073ac31424
commit 244e2183b6
6 changed files with 36 additions and 26 deletions

36
INSTALL
View File

@ -1,42 +1,43 @@
[Installation note of snappy-java] [Installation note of snappy-java]
= Required libraries for building snappy-java = If your OS platform is one of the Windows/Linux/Mac OS X (32/64 bit Intel CPUs), the installation process described here is unnecessary. Simply put snappy-java-(version).jar to your Java classpath. If your OS is not in the above list, create your own snappy-java-(version).jar file as follows.
= Required tools for building snappy-java =
[For all platforms] [For all platforms]
* Java 6 (JDK1.6) http://java.sun.com/ * Java 6 (JDK1.6) http://java.sun.com/
- set JAVA_HOME environment variable to the Java installation folder (e.g. JAVA_HOME=C:/Program Files/Java/jdk1.6.0_24 in Windows) - set JAVA_HOME environment variable to the Java installation folder (e.g. JAVA_HOME=C:/Program Files/Java/jdk1.6.0_24 in Windows)
* Maven 3.x http://maven.apache.org/ * Maven 3.x http://maven.apache.org/
- Check mvn command can be run from your command line. - Check mvn command can be used from your command line.
[Windows (32-bit)] [Windows (32/64-bit)]
* GNU make * GNU make
* And also tar, curl, cp, rm, grep commands are needed. (I use Cygwin for building snappy-java in Windows) * And also tar, curl, cp, rm, grep commands are needed. (I use Cygwin for building snappy-java in Windows)
[Windows (64-bit)] [Windows (32-bit only)]
* Install MinGW http://www.mingw.org/
* Set PATH to the following command in MinGW package
- mingw32-g++
- strip
To build x86 (32bit) dll under 64-bit Windows, use "make win32" target.
[Windows (64-bit only)]
* Download MinGW-w64 http://sourceforge.net/projects/mingw-w64/ * Download MinGW-w64 http://sourceforge.net/projects/mingw-w64/
* Set PATH to the following commands in the downloaded archive: * Set PATH to the following commands in the downloaded archive:
- x86_64-w64-mingw32-g++ - x86_64-w64-mingw32-g++
- x86_64-w64-mingw32-strip - x86_64-w64-mingw32-strip
NOTICE: Do not use the Cygwin version of MinGW-w64. It fails to build assemblies for 64bit environment. NOTICE: Do not use the Cygwin version of MinGW-w64. It fails to build assemblies for 64bit environment.
[Windows (32-bit)]
* Install MinGW http://www.mingw.org/
* Set PATH to the following command in MinGW package
- mingw32-g++
- strip
To build x86 (32bit) dll using 64-bit Windows, use "make win32" target.
[Linux (32/64-bit)] [Linux (32/64-bit)]
* gcc-4.5.x or higher is necessary because snappy-java uses -static-libstdc++ option. * gcc-4.5.x or higher is necessary because snappy-java uses -static-libstdc++ option.
* You can build 32-bit native library with 64-bit Linux machine (do make linux32)
[Mac] [Mac]
* Install gcc, make, etc. included in Mac OS X install disk. (X Code) * Install gcc, make, etc. included in Mac OS X install disk. (X Code)
* Install mercurial using Mac Porsts http://www.macports.org/ * Install mercurial using Mac Ports http://www.macports.org/
= Building snappy-java = = Building snappy-java =
@ -45,9 +46,10 @@ $ make
A native library for your machine environment and a jar package target/snappy-java-(version).jar are produced in the target folder. A native library for your machine environment and a jar package target/snappy-java-(version).jar are produced in the target folder.
= Building native library = = Building only the native library =
$ make native $ make native
= Rebuild native library = = Rebuild the native library for your platform =
$ make clean-native native $ make clean-native native

View File

@ -58,7 +58,7 @@ NATIVE_DLL:=$(NATIVE_DIR)/$(LIBNAME)
snappy-jar-version:=snappy-java-$(shell $(JAVA) -jar lib/silk-weaver.jar find 'project(artifactId, version)' pom.xml | grep snappy-java | awk '{ print $$2; }') snappy-jar-version:=snappy-java-$(shell $(JAVA) -jar lib/silk-weaver.jar find 'project(artifactId, version)' pom.xml | grep snappy-java | awk '{ print $$2; }')
native: $(SNAPPY_UNPACKED) $(NATIVE_DLL) native: $(SNAPPY_UNPACKED) $(NATIVE_DLL)
snappy: $(TARGET)/$(snappy-jar-version).jar snappy: native $(TARGET)/$(snappy-jar-version).jar
$(NATIVE_DLL): $(SNAPPY_OUT)/$(LIBNAME) $(NATIVE_DLL): $(SNAPPY_OUT)/$(LIBNAME)
@mkdir -p $(@D) @mkdir -p $(@D)

View File

@ -23,7 +23,7 @@ OS_NAME := $(shell $(JAVA) -cp lib $(OSINFO_CLASS) --os)
OS_ARCH := $(shell $(JAVA) -cp lib $(OSINFO_CLASS) --arch) OS_ARCH := $(shell $(JAVA) -cp lib $(OSINFO_CLASS) --arch)
LIB_FOLDER := $(shell $(JAVA) -cp lib $(OSINFO_CLASS)) LIB_FOLDER := $(shell $(JAVA) -cp lib $(OSINFO_CLASS))
# Windows uses different path separators, because they hate me # Windows uses different path separators
ifeq ($(OS_NAME),Windows) ifeq ($(OS_NAME),Windows)
sep := ; sep := ;
else else
@ -50,7 +50,7 @@ endif
Default_CXX := g++ Default_CXX := g++
Default_STRIP := strip Default_STRIP := strip
Default_CXXFLAGS := -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC Default_CXXFLAGS := -I$(JAVA_HOME)/include -Ilib/inc_mac -O2 -fPIC -fvisibility=hidden
Default_LINKFLAGS := -shared -static Default_LINKFLAGS := -shared -static
Default_LIBNAME := libsnappyjava.so Default_LIBNAME := libsnappyjava.so
Default_SNAPPY_FLAGS := Default_SNAPPY_FLAGS :=

5
lib/include/config.h Normal file → Executable file
View File

@ -0,0 +1,5 @@
#ifndef __CONFIG_H
#define __CONFIG_H
#endif // __CONFIG_H

View File

@ -124,21 +124,22 @@ public class SnappyLoader
try { try {
// Load a byte code // Load a byte code
byte[] byteCode = getByteCode("/org/xerial/snappy/SnappyNativeLoader.bytecode"); byte[] byteCode = getByteCode("/org/xerial/snappy/SnappyNativeLoader.bytecode");
// In addition, load the SnappyNative and SnappyException class in the system class loader // In addition, we need to load the other dependent classes (e.g., SnappyNative and SnappyException) using the system class loader
List<byte[]> preloadClassByteCode = new ArrayList<byte[]>(classesToPreload.length); List<byte[]> preloadClassByteCode = new ArrayList<byte[]>(classesToPreload.length);
for (String each : classesToPreload) { for (String each : classesToPreload) {
preloadClassByteCode.add(getByteCode(String.format("/%s.class", each.replaceAll("\\.", "/")))); preloadClassByteCode.add(getByteCode(String.format("/%s.class", each.replaceAll("\\.", "/"))));
} }
// Create a new class to the system class loader // Create a new class from a byte code
Class< ? > classLoader = Class.forName("java.lang.ClassLoader"); Class< ? > classLoader = Class.forName("java.lang.ClassLoader");
Method defineClass = classLoader.getDeclaredMethod("defineClass", new Class[] { String.class, Method defineClass = classLoader.getDeclaredMethod("defineClass", new Class[] { String.class,
byte[].class, int.class, int.class, ProtectionDomain.class }); byte[].class, int.class, int.class, ProtectionDomain.class });
ClassLoader systemClassLoader = getSystemClassLoader(); ClassLoader systemClassLoader = getSystemClassLoader();
// ClassLoader.defineClass is a protected method, so we have to make it accessible
defineClass.setAccessible(true); defineClass.setAccessible(true);
try { try {
// Load SnappyNativeLoader // Create a new class using a ClassLoader#defineClass
defineClass.invoke(systemClassLoader, nativeLoaderClassName, byteCode, 0, byteCode.length, defineClass.invoke(systemClassLoader, nativeLoaderClassName, byteCode, 0, byteCode.length,
System.class.getProtectionDomain()); System.class.getProtectionDomain());
@ -149,16 +150,18 @@ public class SnappyLoader
} }
} }
finally { finally {
// Reset the accessibility to defineClass method
defineClass.setAccessible(false); defineClass.setAccessible(false);
} }
// Load the loader class // Load the snappy loader class
Class< ? > loaderClass = systemClassLoader.loadClass(nativeLoaderClassName); Class< ? > loaderClass = systemClassLoader.loadClass(nativeLoaderClassName);
if (loaderClass != null) { if (loaderClass != null) {
Method loadMethod = loaderClass.getDeclaredMethod("load", new Class[] { String.class }); Method loadMethod = loaderClass.getDeclaredMethod("load", new Class[] { String.class });
File nativeLib = findNativeLibrary(); File nativeLib = findNativeLibrary();
loadMethod.invoke(null, nativeLib.getAbsolutePath()); loadMethod.invoke(null, nativeLib.getAbsolutePath());
// And also, preload the other dependent classes
for (String each : classesToPreload) { for (String each : classesToPreload) {
systemClassLoader.loadClass(each); systemClassLoader.loadClass(each);
} }
@ -167,7 +170,7 @@ public class SnappyLoader
} }
} }
catch (Exception e2) { catch (Exception e2) {
e.printStackTrace(); e2.printStackTrace();
} }
} }

View File

@ -64,7 +64,7 @@ public class SnappyLoaderTest
ProtectionDomain systemPD = System.class.getProtectionDomain(); ProtectionDomain systemPD = System.class.getProtectionDomain();
byte[] bytecode = cl.toBytecode(); byte[] bytecode = cl.toBytecode();
// FileOutputStream f = new FileOutputStream("src/main/java/org/xerial/snappy/SnappyNativeLoader.bytecode"); // FileOutputStream f = new FileOutputStream("src/main/resources/org/xerial/snappy/SnappyNativeLoader.bytecode");
// f.write(bytecode); // f.write(bytecode);
// f.close(); // f.close();