From 244e2183b6d835127a5fb01bf3bcf566c52b9630 Mon Sep 17 00:00:00 2001 From: "Taro L. Saito" Date: Fri, 24 Jun 2011 09:06:20 +0900 Subject: [PATCH] Edit documentation --- INSTALL | 36 ++++++++++--------- Makefile | 2 +- Makefile.common | 4 +-- lib/include/config.h | 5 +++ .../java/org/xerial/snappy/SnappyLoader.java | 13 ++++--- .../org/xerial/snappy/SnappyLoaderTest.java | 2 +- 6 files changed, 36 insertions(+), 26 deletions(-) mode change 100644 => 100755 lib/include/config.h diff --git a/INSTALL b/INSTALL index 82e71e0..c00de6d 100755 --- a/INSTALL +++ b/INSTALL @@ -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 + diff --git a/Makefile b/Makefile index b67855a..816f5bd 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/Makefile.common b/Makefile.common index 6fb34f8..f4a3fdd 100755 --- a/Makefile.common +++ b/Makefile.common @@ -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 := diff --git a/lib/include/config.h b/lib/include/config.h old mode 100644 new mode 100755 index e69de29..137e71f --- a/lib/include/config.h +++ b/lib/include/config.h @@ -0,0 +1,5 @@ + +#ifndef __CONFIG_H +#define __CONFIG_H + +#endif // __CONFIG_H diff --git a/src/main/java/org/xerial/snappy/SnappyLoader.java b/src/main/java/org/xerial/snappy/SnappyLoader.java index 83b37d4..a1c7701 100755 --- a/src/main/java/org/xerial/snappy/SnappyLoader.java +++ b/src/main/java/org/xerial/snappy/SnappyLoader.java @@ -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 preloadClassByteCode = new ArrayList(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(); } } diff --git a/src/test/java/org/xerial/snappy/SnappyLoaderTest.java b/src/test/java/org/xerial/snappy/SnappyLoaderTest.java index a47c302..13452ad 100755 --- a/src/test/java/org/xerial/snappy/SnappyLoaderTest.java +++ b/src/test/java/org/xerial/snappy/SnappyLoaderTest.java @@ -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();