commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1085554 - in /commons/sandbox/runtime/trunk/src/main/native: ./ include/acr/ os/linux/ os/unix/ shared/
Date Fri, 25 Mar 2011 20:38:26 GMT
Author: mturk
Date: Fri Mar 25 20:38:25 2011
New Revision: 1085554

URL: http://svn.apache.org/viewvc?rev=1085554&view=rev
Log:
Add more native methods. This is modified original code

Added:
    commons/sandbox/runtime/trunk/src/main/native/include/acr/time.h   (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/linux/misc.c   (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/unix/time.c   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
    commons/sandbox/runtime/trunk/src/main/native/include/acr/clazz.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/jnitypes.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/memory.h
    commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
    commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
    commons/sandbox/runtime/trunk/src/main/native/shared/object.c
    commons/sandbox/runtime/trunk/src/main/native/shared/string.c
    commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in?rev=1085554&r1=1085553&r2=1085554&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Fri Mar 25 20:38:25 2011
@@ -61,9 +61,11 @@ ASMSOURCES=\
 
 UNIX_SOURCES=\
 	$(TOPDIR)/os/unix/init.c \
-	$(TOPDIR)/os/unix/platform.c
+	$(TOPDIR)/os/unix/platform.c \
+	$(TOPDIR)/os/unix/time.c
 
 LINUX_SOURCES=\
+	$(TOPDIR)/os/linux/misc.c \
 	$(TOPDIR)/os/linux/os.c
 
 SOLARIS_SOURCES=

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/clazz.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/clazz.h?rev=1085554&r1=1085553&r2=1085554&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/clazz.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/clazz.h Fri Mar 25 20:38:25
2011
@@ -47,19 +47,16 @@ extern "C" {
 #endif
 
 /**
- * Add class to the local cache and create global
- * rference to it.
+ * Load Apache Commons Runtime classes into JVM.
  * @param env Current JNI environment.
- * @param lock Java Object use for synchronisation.
- * @param name JNI class name.
- * @remark Class name must follow the JNI convention of class naming
- * prefixing the class with 'L' and eventually terminating it with ';'
- * eg. "Ljava/lang/String;" or "[[B"
- * Consult the JNI manual for proper class naming.
+ * @remark This function MUST be called before any classes using
+ *         native methods are loaded by classloader.
  */
-jclass
-AcrAddClassToGlobalCache(JNI_STDENV,
-                         jobject lock, const char *name);
+int
+AcrInitCoreClasses(JNI_STDENV);
+
+int
+AcrInitOptionalClasses(JNI_STDENV);
 
 /**
  * Get core class instance.
@@ -69,6 +66,13 @@ jclass
 AcrGetCoreClass(int clazz);
 
 /**
+ * Get optional class instance.
+ * @param clazz Class to get. See acr_cclass_e enum
+ */
+jclass
+AcrGetOptionalClass(int clazz);
+
+/**
  * Get core object array instance.
  * @param env Current JNI environment.
  * @param clazz Class to get. See acr_cclass_e enum
@@ -97,24 +101,6 @@ void
 AcrUnloadClass(JNI_STDENV, JAVA_C_ID *clazz);
 
 /**
- * Load Apache Commons Runtime classes into JVM.
- * @param env Current JNI environment.
- * @remark This function MUST be called before any classes using
- *         native methods are loaded by classloader.
- */
-int
-AcrLoadRuntimeClasses(JNI_STDENV);
-
-/**
- * Unload Apache Commons Runtime classes referenced from JVM.
- * @param env Current JNI environment.
- * @remark After this function is called classes using native
- *         methods must not be used.
- */
-void
-AcrUnloadRuntimeClasses(JNI_STDENV);
-
-/**
  * Get the Class Flags. See ACR_CLASS_* defines.
  * @param env Current JNI environment.
  * @param obj Class to use.

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h?rev=1085554&r1=1085553&r2=1085554&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/jnidefs.h Fri Mar 25 20:38:25
2011
@@ -74,12 +74,13 @@
 #define ACR_CLASS_UNLOAD(CL)                        \
     acr_class_##CL##_unload(_E)
 
-#define J_DECLARE_CLAZZ   static JAVA_C_ID _clazzn
-#define J_DECLARE_F_ID(I) static JAVA_F_ID _f##I##n
-#define J_DECLARE_M_ID(I) static JAVA_M_ID _m##I##n
-#define J4MID(I)          _m##I##n.i
+#define J_DECLARE_CLAZZ         static JAVA_C_ID _clazzn
+#define J_DECLARE_F_ID(I)       static JAVA_F_ID _f##I##n
+#define J_DECLARE_M_ID(I)       static JAVA_M_ID _m##I##n
+#define J4MID(I)                _m##I##n.i
 
-#define IF_CLAZZ_LOADED() if (_clazzn.i != NULL && _m0000n.i != NULL)
+#define CLAZZ_LOADED()          (_clazzn.i != 0 && _m0000n.i != 0)
+#define CLAZZ_NOT_LOADED()      (_clazzn.i == 0 || _m0000n.i == 0)
 
 #define UTF8_TO_JSTRING(V)      AcrNewJavaStringU(_E, (const char *)(V))
 #define CSTR_TO_JSTRING(V)      AcrNewJavaStringA(_E, (const char *)(V))

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/jnitypes.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/jnitypes.h?rev=1085554&r1=1085553&r2=1085554&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/jnitypes.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/jnitypes.h Fri Mar 25 20:38:25
2011
@@ -27,8 +27,9 @@
  */
 
 typedef struct JAVA_C_ID {
-    jclass      i;
-    jclass      a;
+    int          o;
+    jclass       i;
+    jclass       a;
     const char  *n;
 } JAVA_C_ID;
 
@@ -39,7 +40,8 @@ typedef struct JAVA_M_ID {
 } JAVA_M_ID;
 
 typedef struct JAVA_F_ID {
-    jfieldID    i;
+    int          o;
+    jfieldID     i;
     const char  *n;
     const char  *s;
 } JAVA_F_ID;

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/memory.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/memory.h?rev=1085554&r1=1085553&r2=1085554&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/memory.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/memory.h Fri Mar 25 20:38:25
2011
@@ -28,7 +28,6 @@
  *
  */
 
-
 #if defined(DEBUG) || defined(_DEBUG)
 #define ACR_MALLOC(Type, Size)      \
                 ((Type *)AcrDebugMalloc(_E, sizeof(Type) * (size_t)(Size), __FILE_FUNC_LINE__))
@@ -49,6 +48,30 @@
                 ((Type *)AcrRealloc(_E, (Mem), sizeof(Type) * (size_t)(Size)))
 #endif
 
+#define ACR_FFREE(Mem) _pr_free((void *)(Mem))
+#define ACR_MEMZERO(Type, Mem, Size)                            \
+    do {                                                        \
+        if ((Mem) && (Size))                                    \
+            memset((Mem), 0, sizeof(Type) * (size_t)(Size));    \
+    } while(0)
+/* Memcpy with byte offsets */
+#define ACR_MEMCOPY(Dst, _Do, Src, _So, Size)                   \
+    do {                                                        \
+        if ((Dst) && (Src) && (Size))                           \
+             memcpy(((char *)(Dst)) + (_Do),                    \
+                    ((const char *)(Src)) + (_So),              \
+                    (size_t)(Size));                            \
+    } while(0)
+
+/* Memove with byte offsets */
+#define ACR_MEMMOVE(Dst, _Do, Src, _So, Size)                   \
+    do {                                                        \
+        if ((Dst) && (Src) && (Size))                           \
+            memmove(((char *)(Dst)) + (_Do),                    \
+                    ((const char *)(Src)) + (_So),              \
+                    (size_t)(Size));                            \
+} while(0)
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -56,29 +79,51 @@ extern "C" {
 void
 AcrMemoryAbort(JNI_STDENV, int retcode, size_t required,
                const char *filename, const char *funcname, int lineno);
-
 void *
 AcrDebugMalloc(JNI_STDENV, size_t size,
                const char *filename, const char *funcname, int lineno);
 void *
 AcrDebugCalloc(JNI_STDENV, size_t size,
                const char *filename, const char *funcname, int lineno);
-
 void *
 AcrDebugRealloc(JNI_STDENV, void *mem, size_t size,
                 const char *filename, const char *funcname, int lineno);
 
-void *
-AcrMalloc(JNI_STDENV, size_t size);
-
-void *
-AcrCalloc(JNI_STDENV, size_t size);
-
-void *
-AcrRelloc(JNI_STDENV, void *mem, size_t size);
+void    *AcrMalloc(JNI_STDENV, size_t size);
+void    *AcrCalloc(JNI_STDENV, size_t size);
+void    *AcrRelloc(JNI_STDENV, void *mem, size_t size);
+void    *AcrMemdup(JNI_STDENV, const void *src, int len);
+char    *AcrStrdup(JNI_STDENV, const char *str);
+wchar_t *AcrWcsdup(JNI_STDENV, const wchar_t *str);
+
+void  AcrFree(void *mem);
+void  AcrMemCleanse(void *p, size_t len);
+
+ACR_INLINE(int)
+AcrStrlen(const char *str)
+{
+    const char *s;
+
+    if (str == 0 || *str == '\0')
+        return 0;
+    for (s = str; *s != '\0'; s++)
+        ;
+    return (int)(s - str);
+}
 
-void
-AcrFree(void *mem);
+ACR_INLINE(int)
+AcrStrnlen(const char *str, int nmax)
+{
+    const char *s;
+
+    if (str == 0 || *str == '\0')
+        return 0;
+    if (nmax <= 0)
+        nmax = INT_MAX;
+    for (s = str; *s != '\0' && nmax != 0; s++, nmax--)
+        ;
+    return (int)(s - str);
+}
 
 #ifdef __cplusplus
 }

Added: commons/sandbox/runtime/trunk/src/main/native/include/acr/time.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/time.h?rev=1085554&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/time.h (added)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/time.h Fri Mar 25 20:38:25 2011
@@ -0,0 +1,76 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _ACR_TIME_H_
+#define _ACR_TIME_H_
+/**
+ * @file time.h
+ * @brief ACR time management
+ *
+ *
+ */
+
+#include "acr/stdtypes.h"
+
+#define ACR_USEC_PER_SEC        ACR_I64_C(1000000)
+#define ACR_MSEC_PER_SEC        ACR_I64_C(1000)
+#define ACR_INFINITE            ACR_I64_C(-1)
+/** @return acr_time_t as a seconds */
+#define AcrTimeSec(time)        ((time)  / ACR_USEC_PER_SEC)
+/** @return acr_time_t usec portion of a time */
+#define AcrTimeUsec(time)       ((time)  % ACR_USEC_PER_SEC)
+/** @return acr_time_t msec portion of a time */
+#define AcrTimeMsec(time)       (((time) / 1000) % 1000)
+/** @return milliseconds as an acr_time_t */
+#define AcrTimefromMsec(msec)   ((acr_time_t)(msec) * 1000)
+/** @return seconds as an acr_time_t */
+#define AcrTimeFromSec(sec)     ((acr_time_t)(sec) * ACR_USEC_PER_SEC)
+/** @return a second and usec combination as an acr_time_t */
+#define AcrTimeMake(sec, usec)  ((acr_time_t)(sec) * ACR_USEC_PER_SEC + \
+                                 (acr_time_t)(usec))
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+acr_time_t      AcrTimeNow(void);
+acr_time_t      AcrTimeMilliseconds(void);
+acr_time_t      AcrDOSTimeToTime(acr_uint32_t t);
+acr_uint32_t    AcrTimeToDOSTime(acr_time_t t);
+void            AcrSleep(acr_time_t usec);
+
+ACR_INLINE(int)
+AcrTimeAsMsec(acr_time_t time)
+{
+    if (time == ACR_INFINITE)
+        return -1;
+    else
+        return (int)(time / ACR_I64_C(1000));
+}
+
+ACR_INLINE(int)
+AcrTimeAsSec(acr_time_t time)
+{
+    if (time == ACR_INFINITE)
+        return -1;
+    else
+        return (int)(time / ACR_USEC_PER_SEC);
+}
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* _ACR_TIME_H_ */

Propchange: commons/sandbox/runtime/trunk/src/main/native/include/acr/time.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/native/os/linux/misc.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/linux/misc.c?rev=1085554&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/linux/misc.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/linux/misc.c Fri Mar 25 20:38:25 2011
@@ -0,0 +1,40 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr/stdinc.h"
+
+/* Use dynamic loading mechanism if not linked to -lselinux
+ */
+typedef int (*is_selinux_enabled_t)(void);
+static int _no_selinux_found(void)
+{
+    return 0;
+}
+
+int IsSelinuxEnabled()
+{
+    static is_selinux_enabled_t sef = 0;
+    static void                *sel = 0;
+
+    if (sef == 0) {
+        sel = dlopen("libselinux.so", RTLD_LAZY);
+        if (sel != 0)
+            sef = (is_selinux_enabled_t)dlsym(sel, "is_selinux_enabled");
+        if (sef == 0)
+            sef = _no_selinux_found;
+    }
+    return (*sef)();
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/linux/misc.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/native/os/unix/time.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/time.c?rev=1085554&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/time.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/time.c Fri Mar 25 20:38:25 2011
@@ -0,0 +1,128 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr/time.h"
+
+acr_time_t
+AcrTimeNow()
+{
+    struct timeval tv;
+
+    gettimeofday(&tv, 0);
+    return (acr_time_t)(tv.tv_sec * ACR_USEC_PER_SEC + tv.tv_usec);
+}
+
+acr_time_t
+AcrTimeMilliseconds()
+{
+    struct timeval tv;
+
+    gettimeofday(&tv, 0);
+    return (acr_time_t)(tv.tv_sec * ACR_MSEC_PER_SEC + tv.tv_usec / 1000);
+}
+
+static acr_time_t tm2time(struct tm *tm)
+{
+    acr_time_t year = tm->tm_year;
+    acr_time_t days;
+    static const int dayoffset[12] =
+    { 306, 337, 0, 31, 61, 92, 122, 153, 184, 214, 245, 275 };
+
+    /* shift new year to 1st March in order to make leap year calc easy */
+
+    if (tm->tm_mon < 2)
+        year--;
+
+    /* Find number of days since 1st March 1900 (in the Gregorian calendar). */
+    days  = year * 365 + year / 4 - year / 100 + (year / 100 + 3) / 4;
+    days += dayoffset[tm->tm_mon] + tm->tm_mday - 1;
+    days -= 25508;              /* 1 jan 1970 is 25508 days since 1 mar 1900 */
+    days  = ((days * 24 + tm->tm_hour) * 60 + tm->tm_min) * 60 + tm->tm_sec;
+
+    if (days < 0) {
+        return 0;
+    }
+    return days * ACR_USEC_PER_SEC;
+}
+
+acr_time_t
+AcrDOSTimeToTime(acr_uint32_t t)
+{
+    struct tm  tm;
+    acr_time_t rv;
+
+    tm.tm_year = ((t & 0xFE000000) >> 25) + 80;
+    tm.tm_mon  = ((t & 0x01E00000) >> 21) - 1;
+    tm.tm_mday = ((t & 0x001F0000) >> 16);
+    tm.tm_hour = ((t & 0x0000F800) >> 11);
+    tm.tm_min  = ((t & 0x000007E0) >>  5);
+    tm.tm_sec  = ((t & 0x0000001F) <<  1);
+
+    rv = tm2time(&tm);
+    if (rv < ACR_I64_C(315532800000000)) {
+        /* January 1st 1980 as unix time in microseconds */
+        rv = ACR_I64_C(315532800000000);
+    }
+    return rv;
+}
+
+acr_uint32_t
+AcrTimeToDOSTime(acr_time_t t)
+{
+    struct tm    tm;
+    acr_uint32_t rv;
+    time_t       tt;
+
+    /* Round up to two seconds */
+    tt = (time_t)ACR_ALIGN((t / ACR_USEC_PER_SEC), 2);
+#if HAVE_GMTIME_R
+    gmtime_r(&tt, &tm);
+#else
+    tm = *gmtime(&tt);
+#endif
+    if (tm.tm_year >= 1900)
+        tm.tm_year -= 1900;
+    if (tm.tm_year < 80) {
+        /* January 1st 1980 is the
+        * minimum date DOS format can handle.
+        */
+        return 0x00210000;
+    }
+    else
+        tm.tm_year -= 80;
+    if (tm.tm_year > 127) {
+        /* December 31st 2107 is the
+        * maximum date DOS format can handle.
+        */
+        return 0xFF9FBF7D;
+    }
+    rv = ((acr_uint32_t)(tm.tm_year) << 25) |
+          ((acr_uint32_t)(tm.tm_mon + 1) << 21) |
+          ((acr_uint32_t)(tm.tm_mday) << 16) |
+          ((acr_uint32_t)(tm.tm_hour) << 11) |
+          ((acr_uint32_t)(tm.tm_min)  <<  5) |
+          ((acr_uint32_t)(tm.tm_sec)  >>  1);
+    return rv;
+}
+
+void
+AcrSleep(acr_time_t usec)
+{
+    struct timeval tv;
+    tv.tv_usec = AcrTimeUsec(usec);
+    tv.tv_sec  = AcrTimeSec(usec);
+    select(0, 0, 0, 0, &tv);
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/unix/time.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c?rev=1085554&r1=1085553&r2=1085554&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/clazz.c Fri Mar 25 20:38:25 2011
@@ -20,98 +20,99 @@
 #include "acr/string.h"
 
 J_DECLARE_CLAZZ = {
-    NULL,
-    NULL,
+    0,
+    0,
+    0,
     "java/lang/Class"
 };
 
 J_DECLARE_M_ID(0000) = {
-    NULL,
+    0,
     "getName",
     "()Ljava/lang/String;"
 };
 
 J_DECLARE_M_ID(0001) = {
-    NULL,
+    0,
     "getSimpleName",
     "()Ljava/lang/String;"
 };
 
 J_DECLARE_M_ID(0002) = {
-    NULL,
+    0,
     "getComponentType",
     "()Ljava/lang/Class;"
 };
 
 J_DECLARE_M_ID(0003) = {
-    NULL,
+    0,
     "getDeclaringClass",
     "()Ljava/lang/Class;"
 };
 
 J_DECLARE_M_ID(0004) = {
-    NULL,
+    0,
     "getEnclosingClass",
     "()Ljava/lang/Class;"
 };
 
 
 J_DECLARE_M_ID(0005) = {
-    NULL,
+    0,
     "getSuperclass",
     "()Ljava/lang/Class;"
 };
 
 J_DECLARE_M_ID(0006) = {
-    NULL,
+    0,
     "isAnnotation",
     "()Z"
 };
 
 J_DECLARE_M_ID(0007) = {
-    NULL,
+    0,
     "isAnonymousClass",
     "()Z"
 };
 
 J_DECLARE_M_ID(0008) = {
-    NULL,
+    0,
     "isArray",
     "()Z"
 };
 
 J_DECLARE_M_ID(0009) = {
-    NULL,
+    0,
     "isEnum",
     "()Z"
 };
 
 J_DECLARE_M_ID(0010) = {
-    NULL,
+    0,
     "isInterface",
     "()Z"
 };
 
 J_DECLARE_M_ID(0011) = {
-    NULL,
+    0,
     "isLocalClass",
     "()Z"
 };
 
 J_DECLARE_M_ID(0012) = {
-    NULL,
+    0,
     "isMemberClass",
     "()Z"
 };
 
 J_DECLARE_M_ID(0013) = {
-    NULL,
+    0,
     "isPrimitive",
     "()Z"
 };
 
 J_DECLARE_M_ID(0014) = {
-    NULL,
+    0,
     "isSynthetic",
     "()Z"
 };
@@ -120,35 +121,34 @@ static struct {
     const char *name;
     jclass      clazz;
 } core_classes[] = {
-    { "java/lang/Object",           NULL },
-    { "java/lang/Class",            NULL },
-    { "java/lang/reflect/Field",    NULL },
-    { "java/lang/reflect/Method",   NULL },
-    { "java/lang/String",           NULL },
-    { "java/nio/ByteBuffer",        NULL },
-    { "java/io/File",               NULL },
-    { "[Z",                         NULL },
-    { "[B",                         NULL },
-    { "[C",                         NULL },
-    { "[I",                         NULL },
-    { "[J",                         NULL },
-    { "[Ljava/lang/Object;",        NULL },
-    { "[Ljava/lang/String;",        NULL },
-    { "[[Z",                        NULL },
-    { "[[B",                        NULL },
-    { "[[C",                        NULL },
-    { "[[I",                        NULL },
-    { "[[J",                        NULL },
-    { NULL,                         NULL }
+    { "java/lang/Object",           0 },
+    { "java/lang/Class",            0 },
+    { "java/lang/reflect/Field",    0 },
+    { "java/lang/reflect/Method",   0 },
+    { "java/lang/String",           0 },
+    { "java/nio/ByteBuffer",        0 },
+    { "java/io/File",               0 },
+    { "[Z",                         0 },
+    { "[B",                         0 },
+    { "[C",                         0 },
+    { "[I",                         0 },
+    { "[J",                         0 },
+    { "[Ljava/lang/Object;",        0 },
+    { "[Ljava/lang/String;",        0 },
+    { "[[Z",                        0 },
+    { "[[B",                        0 },
+    { "[[C",                        0 },
+    { "[[I",                        0 },
+    { "[[J",                        0 },
+    { 0,                            0 }
 };
 
 static struct {
     const char *name;
     jclass      clazz;
 } opts_classes[] = {
-    { "sun/misc/Unsafe",            NULL },
-    { "java/nio/Path",              NULL },
-    { NULL,                         NULL }
+    { "java/nio/Path",              0 },
+    { 0,                            0 }
 };
 
 ACR_CLASS_CTOR(Class)
@@ -185,10 +185,10 @@ AcrInitCoreClasses(JNI_STDENV)
         return 0;
     while (core_classes[i].name) {
         jobject o = (jobject)(*_E)->FindClass(_E, core_classes[i].name);
-        if (o != NULL) {
+        if (o != 0) {
             core_classes[i].clazz = (jclass)(*_E)->NewGlobalRef(_E, o);
             (*_E)->DeleteLocalRef(_E, o);
-            if (core_classes[i].clazz == NULL) {
+            if (core_classes[i].clazz == 0) {
                 /* Reference failed */
                 return ACR_ENOMEM;
             }
@@ -203,7 +203,6 @@ AcrInitCoreClasses(JNI_STDENV)
     ACR_CLASS_LOAD(Object);
     ACR_CLASS_LOAD(Class);
     ACR_CLASS_LOAD(String);
-    ACR_CLASS_LOPT(Unsafe);
     return 0;
 }
 
@@ -216,10 +215,10 @@ AcrInitOptionalClasses(JNI_STDENV)
         return 0;
     while (opts_classes[i].name) {
         jobject o = (jobject)(*_E)->FindClass(_E, opts_classes[i].name);
-        if (o != NULL) {
+        if (o != 0) {
             opts_classes[i].clazz = (jclass)(*_E)->NewGlobalRef(_E, o);
             (*_E)->DeleteLocalRef(_E, o);
-            if (opts_classes[i].clazz == NULL) {
+            if (opts_classes[i].clazz == 0) {
                 /* Reference failed */
                 return ACR_ENOMEM;
             }
@@ -233,7 +232,7 @@ AcrInitOptionalClasses(JNI_STDENV)
         i++;
     }
     /* Init some core Objects and it's methods */
-
+    ACR_CLASS_LOPT(Unsafe);
     return 0;
 }
 
@@ -243,7 +242,7 @@ AcrGetCoreClass(int clazz)
     if (clazz >= 0 && clazz < ACR_CC_MAX)
         return core_classes[clazz].clazz;
     else
-        return NULL;
+        return 0;
 }
 
 jclass
@@ -252,7 +251,7 @@ AcrGetOptionalClass(int clazz)
     if (clazz >= 0 && clazz < ACR_CO_MAX)
         return opts_classes[clazz].clazz;
     else
-        return NULL;
+        return 0;
 }
 
 jobjectArray
@@ -260,9 +259,9 @@ AcrNewCoreObjectArray(JNI_STDENV, int cl
 {
     jclass cc = AcrGetCoreClass(clazz);
     if (cc)
-        return (*_E)->NewObjectArray(_E, len, cc, NULL);
+        return (*_E)->NewObjectArray(_E, len, cc, 0);
     else
-        return NULL;
+        return 0;
 }
 
 int
@@ -270,7 +269,7 @@ AcrLoadClass(JNI_STDENV, JAVA_C_ID *claz
 {
     jobject c;
 
-    if (clazz->i != NULL) {
+    if (clazz->i != 0) {
         /* Already inited */
         return 0;
     }
@@ -279,14 +278,14 @@ AcrLoadClass(JNI_STDENV, JAVA_C_ID *claz
     }
     /* Init class */
     c = (jobject)(*_E)->FindClass(_E, clazz->n);
-    if (c == NULL) {
+    if (c == 0) {
         /* Exception has been thrown
          * We could clear the exception here.
          */
         goto failed;
     }
     clazz->i = (jclass)(*_E)->NewGlobalRef(_E, c);
-    if (clazz->i == NULL) {
+    if (clazz->i == 0) {
         goto failed;
     }
     (*_E)->DeleteLocalRef(_E, c);
@@ -296,24 +295,25 @@ AcrLoadClass(JNI_STDENV, JAVA_C_ID *claz
         /* Init class array */
         snprintf(an, ACR_SBUFF_SIZ, "[L%s;", clazz->n);
         c = (jobject)(*_E)->FindClass(_E, an);
-        if (c == NULL) {
+        if (c == 0) {
             goto failed;
         }
         clazz->a = (jclass)(*_E)->NewGlobalRef(_E, c);
-        if (clazz->a == NULL) {
+        if (clazz->a == 0) {
             goto failed;
         }
     }
     else {
         /* We don't need Objec[][] arrays */
-        clazz->a = NULL;
+        clazz->a = 0;
     }
+    clazz->o = 0;
     return 0;
 
 failed:
-    if (clazz->i != NULL) {
+    if (clazz->i != 0) {
         (*_E)->DeleteGlobalRef(_E, clazz->i);
-        clazz->i = NULL;
+        clazz->i = 0;
     }
     return ACR_NOTFOUND;
 }
@@ -321,39 +321,16 @@ failed:
 void
 AcrUnloadClass(JNI_STDENV, JAVA_C_ID *clazz)
 {
-    if (clazz->i != NULL) {
+    if (clazz->i != 0) {
         (*_E)->DeleteGlobalRef(_E, clazz->i);
-        clazz->i = NULL;
+        clazz->i = 0;
     }
-    if (clazz->a != NULL) {
+    if (clazz->a != 0) {
         (*_E)->DeleteGlobalRef(_E, clazz->a);
-        clazz->a = NULL;
+        clazz->a = 0;
     }
 }
 
-/* Forward class loading declarations */
-
-int
-AcrLoadRuntimeClasses(JNI_STDENV)
-{
-
-#ifdef WIN32
-
-#endif
-
-    return 0;
-}
-
-void
-AcrUnloadRuntimeClasses(JNI_STDENV)
-{
-
-#ifdef WIN32
-
-#endif
-
-}
-
 int
 AcrClassGetFlags(JNI_STDARGS)
 {
@@ -361,7 +338,7 @@ AcrClassGetFlags(JNI_STDARGS)
     if (IS_JOBJECT_NULL(_E, _O))
         return 0;
 
-    IF_CLAZZ_LOADED() {
+    if (CLAZZ_LOADED()) {
         if (CALL_METHOD0(Boolean, 0006, _O) == JNI_TRUE)
             flags |= ACR_CLASS_ANNOTATION;
         if (CALL_METHOD0(Boolean, 0007, _O) == JNI_TRUE)
@@ -387,18 +364,18 @@ AcrClassGetFlags(JNI_STDARGS)
 char *
 AcrClassGetName(JNI_STDARGS, int simple)
 {
-    char *name = NULL;
+    char *name = 0;
     if (IS_JOBJECT_NULL(_E, _O))
-        return NULL;
+        return 0;
 
-    IF_CLAZZ_LOADED() {
+    if (CLAZZ_LOADED()) {
         jstring sn;
         if (simple)
              sn = CALL_METHOD0(Object, 0001, _O);
         else
              sn = CALL_METHOD0(Object, 0000, _O);
         if (sn)
-            name = AcrGetJavaStringA(_E, sn, NULL);
+            name = AcrGetJavaStringA(_E, sn, 0);
     }
     return name;
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/memory.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/memory.c?rev=1085554&r1=1085553&r2=1085554&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/memory.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/memory.c Fri Mar 25 20:38:25 2011
@@ -95,6 +95,27 @@ AcrDebugCalloc(JNI_STDENV, size_t size,
 }
 
 void *
+AcrDebugRealloc(JNI_STDENV, void *ptr, size_t size,
+               const char *filename, const char *funcname, int lineno)
+{
+    if (ptr == acr_zero_string_ptr) {
+        /* Call malloc if reallocating zero string */
+        return AcrMalloc(_E, size);
+    }
+    else if (size > 0 && size < SIZE_T_MAX) {
+        void *rv = realloc(ptr, size);
+        if (rv == 0)
+            AcrMemoryAbort(_E, ACR_ENOMEM, size, filename, funcname, lineno);
+        return rv;
+    }
+    else if (size == 0)
+        AcrFree(ptr);
+    else
+        AcrMemoryAbort(_E, ACR_ERANGE, size, filename, funcname, lineno);
+    return 0;
+}
+
+void *
 AcrMalloc(JNI_STDENV, size_t size)
 {
     if (size > 0 && size < SIZE_T_MAX) {
@@ -123,3 +144,98 @@ AcrCalloc(JNI_STDENV, size_t size)
         return 0;
     }
 }
+
+void *
+AcrRealloc(JNI_STDENV, void *ptr, size_t size)
+{
+    if (ptr == acr_zero_string_ptr) {
+        /* Call malloc if reallocating zero string */
+        return AcrMalloc(_E, size);
+    }
+    else if (size > 0 && size < SIZE_T_MAX) {
+        void *rv = realloc(ptr, size);
+        if (rv == 0)
+            AcrMemoryAbort(_E, ACR_ENOMEM, size, 0, 0, 0);
+        return rv;
+    }
+    else if (size == 0)
+        AcrFree(ptr);
+    else
+        AcrMemoryAbort(_E, ACR_ERANGE, size, 0, 0, 0);
+    return 0;
+}
+
+void
+AcrMemCleanse(void *p, size_t len)
+{
+    static unsigned char cleanse_ctr = 0;
+    volatile unsigned char *ptr = (volatile unsigned char *)p;
+
+    if (p != 0) {
+        size_t loop = len;
+        size_t cctr = cleanse_ctr;
+        /* Suppose compiler won't rule that out */
+        while (loop-- != 0) {
+            *(ptr++) = (unsigned char)cctr;
+            cctr += (17 + ((size_t)ptr & 0x0f));
+        }
+        ptr = memchr(p, (unsigned char)cctr, len);
+        if(ptr)
+            cctr += (63 + (size_t)ptr);
+        cleanse_ctr = (unsigned char)cctr;
+    }
+}
+
+void *
+AcrMemdup(JNI_STDENV, const void *src, int len)
+{
+    void *rv;
+    if (src == 0)
+        return 0;
+    if (len == 0)
+        return acr_zero_string_ptr;
+    rv = malloc(len);
+    if (rv == 0)
+        AcrMemoryAbort(_E, ACR_ENOMEM, len, 0, 0, 0);
+    else
+        memcpy(rv, src, len);
+    return rv;
+}
+
+char *
+AcrStrdup(JNI_STDENV, const char *str)
+{
+    char *rv;
+    if (str == 0)
+        return 0;
+    if (*str == '\0')
+        rv = acr_zero_string_ptr;
+    else
+        rv = strdup(str);
+    if (rv == 0)
+        AcrMemoryAbort(_E, ACR_ENOMEM, strlen(str), 0, 0, 0);
+    return rv;
+}
+
+wchar_t *
+AcrWcsdup(JNI_STDENV, const wchar_t *str)
+{
+    wchar_t *rv;
+    if (str == 0)
+        return 0;
+    if (*str == 0)
+        rv = (wchar_t *)acr_zero_string_ptr;
+    else {
+#if HAVE_WCSDUP
+        rv = wcsdup(str);
+#else
+        size_t len = wcslen(str) + 1;
+        rv = (wchar_t *)AcrMalloc(_E, len * sizeof(wchar_t));
+        if (rv != 0)
+            memcpy(rv, str, len * sizeof(wchar_t));
+#endif
+    }
+    if (rv == 0)
+        AcrMemoryAbort(_E, ACR_ENOMEM, wcslen(str) * sizeof(wchar_t), 0, 0, 0);
+    return rv;
+}

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/object.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/object.c?rev=1085554&r1=1085553&r2=1085554&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/object.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/object.c Fri Mar 25 20:38:25 2011
@@ -19,55 +19,56 @@
 #include "acr/string.h"
 
 J_DECLARE_CLAZZ = {
-    NULL,
-    NULL,
+    0,
+    0,
+    0,
     "java/lang/Object"
 };
 
 J_DECLARE_M_ID(0000) = {
-    NULL,
+    0,
     "<init>",
     "()V"
 };
 
 J_DECLARE_M_ID(0001) = {
-    NULL,
+    0,
     "notify",
     "()V"
 };
 
 J_DECLARE_M_ID(0002) = {
-    NULL,
+    0,
     "notifyAll",
     "()V"
 };
 
 J_DECLARE_M_ID(0003) = {
-    NULL,
+    0,
     "wait",
     "(J)V"
 };
 
 J_DECLARE_M_ID(0004) = {
-    NULL,
+    0,
     "wait",
     "(JI)V"
 };
 
 J_DECLARE_M_ID(0005) = {
-    NULL,
+    0,
     "wait",
     "()V"
 };
 
 J_DECLARE_M_ID(0006) = {
-    NULL,
+    0,
     "finalize",
     "()V"
 };
 
 J_DECLARE_M_ID(0007) = {
-    NULL,
+    0,
     "getClass",
     "()Ljava/lang/Class;"
 };

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/string.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/string.c?rev=1085554&r1=1085553&r2=1085554&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Fri Mar 25 20:38:25 2011
@@ -21,6 +21,7 @@
 J_DECLARE_CLAZZ = {
     0,
     0,
+    0,
     "java/lang/String"
 };
 
@@ -45,7 +46,7 @@ ACR_CLASS_CTOR(String)
     J_LOAD_METHOD(0000);
     J_LOAD_METHOD(0001);
 
-    return ACR_SUCCESS;
+    return 0;
 }
 
 ACR_CLASS_DTOR(String)
@@ -702,7 +703,7 @@ static char *get_string_default(JNIEnv *
     jbyteArray sb = 0;
     char *rs = 0;
 
-    if (!_clazzn.i || !J4MID(0000)) {
+    if (CLAZZ_NOT_LOADED()) {
         ACR_SET_OS_ERROR(ACR_EINIT);
         return 0;
     }
@@ -749,15 +750,16 @@ static jstring new_string_default(JNIEnv
 static jstring new_string_iso_8859_1(JNIEnv *_E, const char *s)
 {
     jstring rs = 0;
-    if (s) {
-        size_t l = strlen(s);
+
+    if (s != 0) {
+        jsize l = (jsize)strlen(s);
         if (l < ACR_MBUFF_SIZ) {
             jchar  cc[ACR_MBUFF_SIZ];
-            size_t  i;
+            jsize  i;
             for (i = 0; i < l; i++) {
                 cc[i] = s[i];
             }
-            rs = (*_E)->NewString(_E, cc, (jsize)l);
+            rs = (*_E)->NewString(_E, cc, l);
         }
         else {
             jchar  *cc;
@@ -766,7 +768,7 @@ static jstring new_string_iso_8859_1(JNI
                 for (i = 0; i < l; i++) {
                     cc[i] = s[i];
                 }
-                rs = (*_E)->NewString(_E, cc, (jsize)l);
+                rs = (*_E)->NewString(_E, cc, l);
                 AcrFree(cc);
             }
         }
@@ -777,8 +779,9 @@ static jstring new_string_iso_8859_1(JNI
 static jstring new_string_utf_8(JNIEnv *_E, const char *s)
 {
     jstring rs = 0;
-    if (s) {
-          int ex;
+
+    if (s != 0) {
+        int ex;
         jsize sl = (jsize)strlen(s);
         if (sl < ACR_MBUFF_SIZ) {
             jchar  cc[ACR_MBUFF_SIZ];
@@ -811,7 +814,7 @@ AcrGetJavaStringW(JNIEnv *_E, jstring st
     const jchar *sr;
     wchar_t *rv = 0;
 
-    if (!str) {
+    if (str == 0) {
         return 0;
     }
     if ((*_E)->EnsureLocalCapacity(_E, 2) < 0) {
@@ -853,11 +856,8 @@ char *
 AcrGetJavaStringA(JNIEnv *_E, jstring str, char *b)
 {
     char *rv = 0;
-    if (!str) {
-        return 0;
-    }
-    if ((*_E)->EnsureLocalCapacity(_E, 2) < 0) {
-        /* JNI out of memory error */
+
+    if (str == 0) {
         return 0;
     }
     switch (acr_native_codepage) {
@@ -878,7 +878,8 @@ jstring
 AcrNewJavaStringW(JNIEnv *_E, const wchar_t *s)
 {
     jstring r = 0;
-    if (s) {
+
+    if (s != 0) {
         size_t l = wcslen(s);
 #if CC_SIZEOF_WCHAR_T == 2
         r = (*_E)->NewString(_E, (const jchar *)s, (jsize)l);

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=1085554&r1=1085553&r2=1085554&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/unsafe.c Fri Mar 25 20:38:25 2011
@@ -21,11 +21,13 @@
 J_DECLARE_CLAZZ = {
     0,
     0,
+    0,
     "sun/misc/Unsafe"
 };
 
 J_DECLARE_F_ID(0000) = {
     0,
+    0,
     "theUnsafe",
     "Lsun/misc/Unsafe;"
 };
@@ -136,6 +138,34 @@ AcrUnsafeStaticFieldOffset(JNI_STDARGS)
         return 0;
 }
 
+jint
+AcrUnsafeObjectFieldIdOffset(JNI_STDENV, jclass cls, jfieldID fid)
+{
+    jobject fld;
+    int     off = 0;
+
+    fld = (*_E)->ToReflectedField(_E, cls, fid, JNI_FALSE);
+    if (fld != 0) {
+        off = AcrUnsafeObjectFieldOffset(_E, fld);
+        (*_E)->DeleteLocalRef(_E, fld);
+    }
+    return off;
+}
+
+jint
+AcrUnsafeStaticFieldIdOffset(JNI_STDENV, jclass cls, jfieldID fid)
+{
+    jobject fld;
+    int     off = 0;
+
+    fld = (*_E)->ToReflectedField(_E, cls, fid, JNI_TRUE);
+    if (fld != 0) {
+        off = AcrUnsafeStaticFieldOffset(_E, fld);
+        (*_E)->DeleteLocalRef(_E, fld);
+    }
+    return off;
+}
+
 ACR_JNI_EXPORT(jobject, Unsafe, get0)(JNI_STDARGS)
 {
     return _get_unsafe(_E);



Mime
View raw message