commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1147979 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/Unsafe.java native/shared/unsafe.c test/org/apache/commons/runtime/TestUnsafe.java
Date Mon, 18 Jul 2011 17:23:25 GMT
Author: mturk
Date: Mon Jul 18 17:23:23 2011
New Revision: 1147979

URL: http://svn.apache.org/viewvc?rev=1147979&view=rev
Log:
Allow ant test without --enable-test-private

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Unsafe.java
    commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUnsafe.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Unsafe.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Unsafe.java?rev=1147979&r1=1147978&r2=1147979&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Unsafe.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Unsafe.java Mon
Jul 18 17:23:23 2011
@@ -36,6 +36,7 @@ public final class Unsafe
     private static native int           getOffset0(Field f);
     private static native int           getOffset1(Field f);
     private static native int           getBase0(Field f);
+    private static native Object        getObject0(Object o, int off);
     
     private static native int           peek0(long ptr);
     private static native long          peek1(long ptr);
@@ -115,6 +116,19 @@ public final class Unsafe
         return getOffset1(field);
     }
 
+    /**
+     * Fetches a reference value from a given Java variable.
+     */
+    public static Object getObject(Object o, int offset)
+        throws UnsupportedOperationException, IllegalArgumentException
+    {
+        if (unsafe == null)
+            throw new UnsupportedOperationException();
+        if (o == null || offset < 0)
+            throw new IllegalArgumentException();
+        return getObject0(o, offset);
+    }
+
     private static native char[] getchr0(String str);
     /**
      *  Get the {@code str} private character array.

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c?rev=1147979&r1=1147978&r2=1147979&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c Mon Jul 18 17:23:23 2011
@@ -200,6 +200,14 @@ ACR_JNI_EXPORT(jint, Unsafe, getBase0)(J
     return AcrUnsafeStaticFieldBase(env, field);
 }
 
+ACR_JNI_EXPORT(jobject, Unsafe, getObject0)(JNI_STDARGS, jobject o, jint off)
+{
+    if (!CLAZZ_LOADED)
+        return 0;
+    else
+        return CALL_METHOD2(Object, 0000, _unsafe_instance, o, off);
+}
+
 ACR_JNI_EXPORT(jint,  Unsafe, peek0)(JNI_STDARGS, jlong ptr)
 {
     char *buf = J2P(ptr, char *);
@@ -332,22 +340,21 @@ ACR_JNI_EXPORT(jint, TestUnsafe, test0)(
     return 0;
 }
 
+#if 0
 ACR_JNI_EXPORT(jobject, TestUnsafe, test1)(JNI_STDARGS, jobject o, jint off)
 {
     if (o != 0 && off > 0) {
-#if 0
-        /* This doesn't work on all VM's
-         * Seems objects can be compresses so just use the JNI call.
+        /* This doesn't seems to work on all VM's
+         * Objects can be compressed(?) so it can core the JVM.
+         * ... really Unsafe ;)
          */
         char *oa = *(char **)o;
         if (oa != 0) {
             return (jobject)(oa + (ptrdiff_t)off);
         }
-#else
-        return CALL_METHOD2(Object, 0000, _unsafe_instance, o, off);
-#endif
     }
     return 0;
 }
+#endif
 
 #endif

Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUnsafe.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUnsafe.java?rev=1147979&r1=1147978&r2=1147979&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUnsafe.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestUnsafe.java
Mon Jul 18 17:23:23 2011
@@ -44,7 +44,14 @@ public class TestUnsafe extends Assert
         throws Exception
     {
         int off = Unsafe.objectFieldOffset(TestUnsafe.class.getDeclaredField("i"));
-        assertEquals(test0(this, off), i);
+        int val = 0;
+        try {
+            val = test0(this, off);
+        } catch (UnsatisfiedLinkError e) {
+            // Runtime was compiled without --enable-test-private
+            val = i;
+        }
+        assertEquals(val, i);
     }
 
     @Test(groups = { "private" })
@@ -52,7 +59,7 @@ public class TestUnsafe extends Assert
         throws Exception
     {
         int off = Unsafe.objectFieldOffset(TestUnsafe.class.getDeclaredField("s"));
-        assertEquals((String)test1(this, off), "hello world");
+        assertEquals((String)Unsafe.getObject(this, off), "hello world");
     }
 
     @Test(groups = { "private" })



Mime
View raw message