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]
= 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]
* 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)
* 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
* 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/
* Set PATH to the following commands in the downloaded archive:
- x86_64-w64-mingw32-g++
- x86_64-w64-mingw32-strip
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)]
* 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]
* 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 =
@ -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.
= Building native library =
= Building only the native library =
$ make native
= Rebuild native library =
= Rebuild the native library for your platform =
$ 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; }')
native: $(SNAPPY_UNPACKED) $(NATIVE_DLL)
snappy: $(TARGET)/$(snappy-jar-version).jar
snappy: native $(TARGET)/$(snappy-jar-version).jar
$(NATIVE_DLL): $(SNAPPY_OUT)/$(LIBNAME)
@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)
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)
sep := ;
else
@ -50,7 +50,7 @@ endif
Default_CXX := g++
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_LIBNAME := libsnappyjava.so
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 {
// Load a byte code
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);
for (String each : classesToPreload) {
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");
Method defineClass = classLoader.getDeclaredMethod("defineClass", new Class[] { String.class,
byte[].class, int.class, int.class, ProtectionDomain.class });
ClassLoader systemClassLoader = getSystemClassLoader();
// ClassLoader.defineClass is a protected method, so we have to make it accessible
defineClass.setAccessible(true);
try {
// Load SnappyNativeLoader
// Create a new class using a ClassLoader#defineClass
defineClass.invoke(systemClassLoader, nativeLoaderClassName, byteCode, 0, byteCode.length,
System.class.getProtectionDomain());
@ -149,16 +150,18 @@ public class SnappyLoader
}
}
finally {
// Reset the accessibility to defineClass method
defineClass.setAccessible(false);
}
// Load the loader class
// Load the snappy loader class
Class< ? > loaderClass = systemClassLoader.loadClass(nativeLoaderClassName);
if (loaderClass != null) {
Method loadMethod = loaderClass.getDeclaredMethod("load", new Class[] { String.class });
File nativeLib = findNativeLibrary();
loadMethod.invoke(null, nativeLib.getAbsolutePath());
// And also, preload the other dependent classes
for (String each : classesToPreload) {
systemClassLoader.loadClass(each);
}
@ -167,7 +170,7 @@ public class SnappyLoader
}
}
catch (Exception e2) {
e.printStackTrace();
e2.printStackTrace();
}
}

View File

@ -64,7 +64,7 @@ public class SnappyLoaderTest
ProtectionDomain systemPD = System.class.getProtectionDomain();
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.close();