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 2011/04/14 16:11:31 UTC

svn commit: r1092255 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr/pointer.h include/acr/unsafe.h shared/pointer.c

Author: mturk
Date: Thu Apr 14 14:11:31 2011
New Revision: 1092255

URL: http://svn.apache.org/viewvc?rev=1092255&view=rev
Log:
Add native pointer setters

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr/pointer.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/unsafe.h
    commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/pointer.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/pointer.h?rev=1092255&r1=1092254&r2=1092255&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/pointer.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/pointer.h Thu Apr 14 14:11:31 2011
@@ -45,6 +45,13 @@ AcrNewHeapPointer(JNI_STDENV, void *ptr,
 jobject
 AcrNewSlicePointer(JNI_STDENV, void *ptr, size_t len);
 
+void *
+AcrGetPointer(JNI_STDARGS);
+int
+AcrSetPointer(JNI_STDARGS, void *val);
+int
+AcrSetPointerEx(JNI_STDARGS, void *val, size_t len);
+
 #ifdef __cplusplus
 }
 #endif

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/unsafe.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/unsafe.h?rev=1092255&r1=1092254&r2=1092255&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/unsafe.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/unsafe.h Thu Apr 14 14:11:31 2011
@@ -33,6 +33,9 @@
         _f##I##n.o = AcrUnsafeObjectFieldIdOffset(env, _clazzn.i, _f##I##n.i); \
     } else (void)(0)
 
+#define UNSAFE_HAS_OFF(I)  (_f##I##n.o != INVALID_FIELD_OFFSET)
+#define UNSAFE_FLD_OFF(I)  (ptrdiff_t)(_f##I##n.o)
+
 #ifdef __cplusplus
 extern "C" {
 #endif

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c?rev=1092255&r1=1092254&r2=1092255&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/pointer.c Thu Apr 14 14:11:31 2011
@@ -93,3 +93,67 @@ ACR_JNI_EXPORT(void, HeapPointer, free0)
 {
     AcrFree(J2P(ptr, void *));
 }
+
+void *
+AcrGetPointer(JNI_STDARGS)
+{
+    if (!CLAZZ_LOADED) {
+        ACR_THROW_MSG(ACR_EX_EINSTANCE, "Pointer not initialized");
+        return 0;
+    }
+    if (UNSAFE_HAS_OFF(0000)) {
+        char *oa = *(char **)obj;
+        if (oa != 0) {
+            char *pa = oa + UNSAFE_FLD_OFF(0000);
+            return J2P(*((jlong *)pa), void *);
+        }        
+    }
+    /* Fallback to a traditional method.
+     */
+    return GET_IFIELD_P(0000, obj, void *);
+}
+
+int
+AcrSetPointer(JNI_STDARGS, void *val)
+{
+    if (!CLAZZ_LOADED) {
+        ACR_THROW_MSG(ACR_EX_EINSTANCE, "Pointer not initialized");
+        return -1;
+    }
+    if (UNSAFE_HAS_OFF(0000)) {
+        char *oa = *(char **)obj;
+        if (oa != 0) {
+            char *pa = oa + UNSAFE_FLD_OFF(0000);
+            *((jlong *)pa) = P2J(val);
+            return 0;
+        }        
+    }
+    /* Fallback to a traditional method.
+     */
+    SET_IFIELD_P(0000, obj, val);
+    return 0;
+}
+
+int
+AcrSetPointerEx(JNI_STDARGS, void *val, size_t len)
+{
+    if (!CLAZZ_LOADED) {
+        ACR_THROW_MSG(ACR_EX_EINSTANCE, "Pointer not initialized");
+        return -1;
+    }
+    if (UNSAFE_HAS_OFF(0000) && UNSAFE_HAS_OFF(0001)) {
+        char *oa = *(char **)obj;
+        if (oa != 0) {
+            char *pa = oa + UNSAFE_FLD_OFF(0000);
+            *((jlong *)pa) = P2J(val);
+            pa = oa + UNSAFE_FLD_OFF(0001);
+            *((jlong *)pa) = P2J(len);
+            return 0;
+        }        
+    }
+    /* Fallback to a traditional method.
+     */
+    SET_IFIELD_P(0000, obj, val);
+    SET_IFIELD_P(0001, obj, len);
+    return 0;
+}