You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/06/22 08:05:03 UTC

svn commit: r787147 - in /commons/sandbox/runtime/trunk/src: main/java/org/apache/commons/runtime/ main/native/shared/ test/org/apache/commons/runtime/

Author: mturk
Date: Mon Jun 22 06:05:03 2009
New Revision: 787147

URL: http://svn.apache.org/viewvc?rev=787147&view=rev
Log:
By default disable exception handling.
Enabling it can lower down the performance, so use only for testing purposes

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java
    commons/sandbox/runtime/trunk/src/main/native/shared/native.c
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestDirectByteBuffer.java
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java?rev=787147&r1=787146&r2=787147&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Native.java Mon Jun 22 06:05:03 2009
@@ -24,7 +24,8 @@
  * @since Runtime 1.0
  *
  */
-public final class Native {
+public final class Native
+{
 
     private Native()
     {
@@ -34,7 +35,7 @@
     private static boolean initialized = false;
     private static native boolean init0()
         throws Throwable;
-    private static native void    sseh0(boolean on);
+    private static native boolean sseh0(boolean on);
 
     /**
      * Initialize Apache Commons Runtime native library.
@@ -62,14 +63,17 @@
         return initialized;
     }
 
-    public static void enableExceptionHandler()
+    public static boolean enableExceptionHandler()
     {
-        sseh0(true);
+        return sseh0(true);
     }
 
-    public static void disableExceptionHandler()
+    public static boolean disableExceptionHandler()
     {
         sseh0(false);
+        // Disable is always success.
+        return true;
     }
 
 }
+

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java?rev=787147&r1=787146&r2=787147&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer32.java Mon Jun 22 06:05:03 2009
@@ -30,7 +30,11 @@
 
     protected Pointer32()
     {
+        POINTER = 0;
+        CLEANUP = 0;
+        PLENGTH = 0;
     }
+
     /*
      * Only created from JNI code.
      */

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java?rev=787147&r1=787146&r2=787147&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Pointer64.java Mon Jun 22 06:05:03 2009
@@ -28,6 +28,12 @@
     protected long    POINTER;
     protected long    PLENGTH;
 
+    protected Pointer64()
+    {
+        POINTER = 0L;
+        CLEANUP = 0L;
+        PLENGTH = 0L;
+    }
     /*
      * Only created from JNI code.
      */

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/native.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/native.c?rev=787147&r1=787146&r2=787147&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/native.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/native.c Mon Jun 22 06:05:03 2009
@@ -35,7 +35,13 @@
     return rv;
 }
 
-ACR_JNI_EXPORT_DECLARE(void, Native, sseh0)(ACR_JNISTDARGS, jboolean on)
+ACR_JNI_EXPORT_DECLARE(jboolean, Native, sseh0)(ACR_JNISTDARGS, jboolean on)
 {
+#ifdef ACR_ENABLE_SEH
     ACR_SetExceptionHandlerMode(on ? ACR_SEH_THROW : ACR_SEH_NONE);
+    return JNI_TRUE;
+#else
+    return JNI_FALSE;
+#endif
 }
+

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestDirectByteBuffer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestDirectByteBuffer.java?rev=787147&r1=787146&r2=787147&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestDirectByteBuffer.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestDirectByteBuffer.java Mon Jun 22 06:05:03 2009
@@ -86,8 +86,7 @@
         assertTrue("Direct", bb.isDirect());
         assertEquals("Capacity", 1000, bb.capacity());
         try {
-            boolean test_me = false;
-            Native.enableExceptionHandler();
+            boolean test_me = Native.enableExceptionHandler();
             ptr.free();
             // This is double free. Don't do this!
             // Exception handler won't help here.

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java?rev=787147&r1=787146&r2=787147&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java Mon Jun 22 06:05:03 2009
@@ -587,13 +587,14 @@
     public void testMempotect()
         throws Throwable
     {
-        Native.enableExceptionHandler();
-        try {
-            test030(0);
-            fail("Exception not thrown");
-        } catch (Throwable t) {
-            assertSame("Wrong Exception class",
-                java.lang.RuntimeException.class, t.getClass());
+        if (Native.enableExceptionHandler()) {
+            try {
+                test030(0);
+                fail("Exception not thrown");
+            } catch (Throwable t) {
+                assertSame("Wrong Exception class",
+                    java.lang.RuntimeException.class, t.getClass());
+            }
         }
     }