From ecd8aaa3e9112e14516ce56e42330a485de2131a Mon Sep 17 00:00:00 2001 From: "Taro L. Saito" Date: Mon, 1 Aug 2011 15:47:02 +0900 Subject: [PATCH] Add comments --- .../java/org/xerial/snappy/SnappyLoader.java | 20 +++++++++++++++---- .../java/org/xerial/snappy/SnappyNative.java | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/xerial/snappy/SnappyLoader.java b/src/main/java/org/xerial/snappy/SnappyLoader.java index 67ccfe8..cc90aa8 100755 --- a/src/main/java/org/xerial/snappy/SnappyLoader.java +++ b/src/main/java/org/xerial/snappy/SnappyLoader.java @@ -114,8 +114,8 @@ public class SnappyLoader /** * Load SnappyNative and its JNI native implementation in the root class - * loader. This is necessary to avoid JNI multi-loading issues when the same - * JNI library is loaded by different class loaders in the same JVM. + * loader. This is necessary to avoid the JNI multi-loading issue when the + * same JNI library is loaded by different class loaders in the same JVM. * * In order to load native code in the root class loader, this method first * inject SnappyNativeLoader class into the root class loader, because @@ -123,14 +123,26 @@ public class SnappyLoader * class when loading native libraries. * *
-     * (root class loader) -> [SnappyNativeLoader, SnappyNative, SnappyNativeAPI, SnappyErrorCode]  (injected by this method)
+     * (root class loader) -> [SnappyNativeLoader (load JNI code), SnappyNative (has native methods), SnappyNativeAPI, SnappyErrorCode]  (injected by this method)
      *    |
      *    |
-     * (child class loader) -> See the above classes loaded by the root class loader.
+     * (child class loader) -> Sees the above classes loaded by the root class loader.
      *   Then creates SnappyNativeAPI implementation by instantiating SnappyNaitive class.
      * 
* * + *
+     * (root class loader) -> [SnappyNativeLoader, SnappyNative ...]  -> native code is loaded by once in this class loader 
+     *   |   \
+     *   |    (child2 class loader)      
+     * (child1 class loader)
+     * 
+     * child1 and child2 share the same SnappyNative code loaded by the root class loader.
+     * 
+ * + * Note that Java's class loader first delegates the class lookup to its + * parent class loader. So once SnappyNativeLoader is loaded by the root + * class loader, no child class loader initialize SnappyNativeLoader again. * * @return */ diff --git a/src/main/java/org/xerial/snappy/SnappyNative.java b/src/main/java/org/xerial/snappy/SnappyNative.java index 978e5e5..6dc055f 100755 --- a/src/main/java/org/xerial/snappy/SnappyNative.java +++ b/src/main/java/org/xerial/snappy/SnappyNative.java @@ -32,7 +32,7 @@ import java.nio.ByteBuffer; * method in this class is defined in SnappyNative.h (genereted by javah) and * SnappyNative.cpp * - * NEVER USE THIS CLASS DIRECTROY since it breaks the native library code + * NEVER USE THIS CLASS DIRECTLY since it breaks the native library code * loading. * * @author leo