You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ge...@apache.org on 2005/12/01 07:04:00 UTC

svn commit: r350181 [154/198] - in /incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core: ./ depends/ depends/files/ depends/jars/ depends/libs/ depends/libs/linux.IA32/ depends/libs/win.IA32/ depends/oss/ depends/oss/linux.IA32/ depends/oss/win....

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/dblparse.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/dblparse.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/dblparse.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/dblparse.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,876 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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 <string.h>
+#include <math.h>
+#include "jcl.h"
+#include "cbigint.h"
+#include "jclglob.h"
+
+#if defined(LINUX)
+#define USE_LL
+#endif
+
+#define LOW_I32_FROM_VAR(u64) LOW_I32_FROM_LONG64(u64)
+#define LOW_I32_FROM_PTR(u64ptr) LOW_I32_FROM_LONG64_PTR(u64ptr)
+#define HIGH_I32_FROM_VAR(u64) HIGH_I32_FROM_LONG64(u64)
+#define HIGH_I32_FROM_PTR(u64ptr) HIGH_I32_FROM_LONG64_PTR(u64ptr)
+
+#define MAX_ACCURACY_WIDTH 17
+
+#define DEFAULT_WIDTH MAX_ACCURACY_WIDTH
+
+JNIEXPORT jdouble JNICALL
+Java_com_ibm_oti_util_FloatingPointParser_parseDblImpl (JNIEnv * env,
+                                                        jclass clazz,
+                                                        jstring s, jint e);
+JNIEXPORT void JNICALL
+Java_com_ibm_oti_util_NumberConverter_bigIntDigitGeneratorInstImpl (JNIEnv *
+                                                                    env,
+                                                                    jobject
+                                                                    inst,
+                                                                    jlong f,
+                                                                    jint e,
+                                                                    jboolean
+                                                                    isDenormalized,
+                                                                    jboolean
+                                                                    mantissaIsZero,
+                                                                    jint p);
+
+jdouble createDouble (JNIEnv * env, const char *s, jint e);
+jdouble createDouble1 (JNIEnv * env, U_64 * f, IDATA length, jint e);
+jdouble doubleAlgorithm (JNIEnv * env, U_64 * f, IDATA length, jint e,
+                         jdouble z);
+U_64 dblparse_shiftRight64 (U_64 * lp, volatile int mbe);
+
+static const jdouble tens[] = {
+  1.0,
+  1.0e1,
+  1.0e2,
+  1.0e3,
+  1.0e4,
+  1.0e5,
+  1.0e6,
+  1.0e7,
+  1.0e8,
+  1.0e9,
+  1.0e10,
+  1.0e11,
+  1.0e12,
+  1.0e13,
+  1.0e14,
+  1.0e15,
+  1.0e16,
+  1.0e17,
+  1.0e18,
+  1.0e19,
+  1.0e20,
+  1.0e21,
+  1.0e22
+};
+
+#define tenToTheE(e) (*(tens + (e)))
+#define LOG5_OF_TWO_TO_THE_N 23
+#define INV_LOG_OF_TEN_BASE_2 (0.30102999566398114)
+#define DOUBLE_MIN_VALUE 5.0e-324
+
+#define sizeOfTenToTheE(e) (((e) / 19) + 1)
+
+#if defined(USE_LL)
+#define INFINITE_LONGBITS (0x7FF0000000000000LL)
+#else
+#if defined(USE_L)
+#define INFINITE_LONGBITS (0x7FF0000000000000L)
+#else
+#define INFINITE_LONGBITS (0x7FF0000000000000)
+#endif /* USE_L */
+#endif /* USE_LL */
+
+#define MINIMUM_LONGBITS (0x1)
+
+#if defined(USE_LL)
+#define MANTISSA_MASK (0x000FFFFFFFFFFFFFLL)
+#define EXPONENT_MASK (0x7FF0000000000000LL)
+#define NORMAL_MASK   (0x0010000000000000LL)
+#else
+#if defined(USE_L)
+#define MANTISSA_MASK (0x000FFFFFFFFFFFFFL)
+#define EXPONENT_MASK (0x7FF0000000000000L)
+#define NORMAL_MASK   (0x0010000000000000L)
+#else
+#define MANTISSA_MASK (0x000FFFFFFFFFFFFF)
+#define EXPONENT_MASK (0x7FF0000000000000)
+#define NORMAL_MASK   (0x0010000000000000)
+#endif /* USE_L */
+#endif /* USE_LL */
+
+#define DOUBLE_TO_LONGBITS(dbl) (*((U_64 *)(&dbl)))
+
+/* Keep a count of the number of times we decrement and increment to
+ * approximate the double, and attempt to detect the case where we
+ * could potentially toggle back and forth between decrementing and
+ * incrementing. It is possible for us to be stuck in the loop when
+ * incrementing by one or decrementing by one may exceed or stay below
+ * the value that we are looking for. In this case, just break out of
+ * the loop if we toggle between incrementing and decrementing for more
+ * than twice.
+ */
+#define INCREMENT_DOUBLE(_x, _decCount, _incCount) \
+	{ \
+		++DOUBLE_TO_LONGBITS(_x); \
+		_incCount++; \
+		if( (_incCount > 2) && (_decCount > 2) ) { \
+			if( _decCount > _incCount ) { \
+				DOUBLE_TO_LONGBITS(_x) += _decCount - _incCount; \
+			} else if( _incCount > _decCount ) { \
+				DOUBLE_TO_LONGBITS(_x) -= _incCount - _decCount; \
+			} \
+			break; \
+		} \
+	}
+#define DECREMENT_DOUBLE(_x, _decCount, _incCount) \
+	{ \
+		--DOUBLE_TO_LONGBITS(_x); \
+		_decCount++; \
+		if( (_incCount > 2) && (_decCount > 2) ) { \
+			if( _decCount > _incCount ) { \
+				DOUBLE_TO_LONGBITS(_x) += _decCount - _incCount; \
+			} else if( _incCount > _decCount ) { \
+				DOUBLE_TO_LONGBITS(_x) -= _incCount - _decCount; \
+			} \
+			break; \
+		} \
+	}
+#define ERROR_OCCURED(x) (HIGH_I32_FROM_VAR(x) < 0)
+
+#define allocateU64(x, n) if (!((x) = (U_64*) hymem_allocate_memory((n) * sizeof(U_64)))) goto OutOfMemory;
+#define release(r) if ((r)) hymem_free_memory((r));
+
+/*NB the Number converter methods are synchronized so it is possible to
+ *have global data for use by bigIntDigitGenerator */
+#define RM_SIZE 21
+#define STemp_SIZE 22
+static U_64 R[RM_SIZE], S[STemp_SIZE], M[RM_SIZE], Temp[STemp_SIZE];
+
+jdouble
+createDouble (JNIEnv * env, const char *s, jint e)
+{
+  /* assumes s is a null terminated string with at least one
+   * character in it */
+  U_64 def[DEFAULT_WIDTH];
+  U_64 defBackup[DEFAULT_WIDTH];
+  U_64 *f, *fNoOverflow, *g, *tempBackup;
+  U_32 overflow;
+  jdouble result;
+  IDATA index = 1;
+  int unprocessedDigits = 0;
+  PORT_ACCESS_FROM_ENV (env);
+
+  f = def;
+  fNoOverflow = defBackup;
+  *f = 0;
+  tempBackup = g = 0;
+  do
+    {
+      if (*s >= '0' && *s <= '9')
+        {
+          /* Make a back up of f before appending, so that we can
+           * back out of it if there is no more room, i.e. index >
+           * MAX_ACCURACY_WIDTH.
+           */
+          memcpy (fNoOverflow, f, sizeof (U_64) * index);
+          overflow =
+            simpleAppendDecimalDigitHighPrecision (f, index, *s - '0');
+          if (overflow)
+            {
+              f[index++] = overflow;
+              /* There is an overflow, but there is no more room
+               * to store the result. We really only need the top 52
+               * bits anyway, so we must back out of the overflow,
+               * and ignore the rest of the string.
+               */
+              if (index >= MAX_ACCURACY_WIDTH)
+                {
+                  index--;
+                  memcpy (f, fNoOverflow, sizeof (U_64) * index);
+                  break;
+                }
+              if (tempBackup)
+                {
+                  fNoOverflow = tempBackup;
+                }
+            }
+        }
+      else
+        index = -1;
+    }
+  while (index > 0 && *(++s) != '\0');
+
+  /* We've broken out of the parse loop either because we've reached
+   * the end of the string or we've overflowed the maximum accuracy
+   * limit of a double. If we still have unprocessed digits in the
+   * given string, then there are three possible results:
+   *   1. (unprocessed digits + e) == 0, in which case we simply
+   *      convert the existing bits that are already parsed
+   *   2. (unprocessed digits + e) < 0, in which case we simply
+   *      convert the existing bits that are already parsed along
+   *      with the given e
+   *   3. (unprocessed digits + e) > 0 indicates that the value is
+   *      simply too big to be stored as a double, so return Infinity
+   */
+  if ((unprocessedDigits = strlen (s)) > 0)
+    {
+      e += unprocessedDigits;
+      if (index > -1)
+        {
+          if (e == 0)
+            result = toDoubleHighPrecision (f, index);
+          else if (e < 0)
+            result = createDouble1 (env, f, index, e);
+          else
+            {
+              DOUBLE_TO_LONGBITS (result) = INFINITE_LONGBITS;
+            }
+        }
+      else
+        {
+          LOW_I32_FROM_VAR (result) = -1;
+          HIGH_I32_FROM_VAR (result) = -1;
+        }
+    }
+  else
+    {
+      if (index > -1)
+        {
+          if (e == 0)
+            result = toDoubleHighPrecision (f, index);
+          else
+            result = createDouble1 (env, f, index, e);
+        }
+      else
+        {
+          LOW_I32_FROM_VAR (result) = -1;
+          HIGH_I32_FROM_VAR (result) = -1;
+        }
+    }
+
+  return result;
+
+}
+
+jdouble
+createDouble1 (JNIEnv * env, U_64 * f, IDATA length, jint e)
+{
+  IDATA numBits;
+  jdouble result;
+
+#define APPROX_MIN_MAGNITUDE -309
+
+#define APPROX_MAX_MAGNITUDE 309
+
+  numBits = highestSetBitHighPrecision (f, length) + 1;
+  numBits -= lowestSetBitHighPrecision (f, length);
+  if (numBits < 54 && e >= 0 && e < LOG5_OF_TWO_TO_THE_N)
+    {
+      return toDoubleHighPrecision (f, length) * tenToTheE (e);
+    }
+  else if (numBits < 54 && e < 0 && (-e) < LOG5_OF_TWO_TO_THE_N)
+    {
+      return toDoubleHighPrecision (f, length) / tenToTheE (-e);
+    }
+  else if (e >= 0 && e < APPROX_MAX_MAGNITUDE)
+    {
+      result = toDoubleHighPrecision (f, length) * pow (10.0, e);
+    }
+  else if (e >= APPROX_MAX_MAGNITUDE)
+    {
+      /* Convert the partial result to make sure that the
+       * non-exponential part is not zero. This check fixes the case
+       * where the user enters 0.0e309! */
+      result = toDoubleHighPrecision (f, length);
+      /* Don't go straight to zero as the fact that x*0 = 0 independent of x might
+         cause the algorithm to produce an incorrect result.  Instead try the min value
+         first and let it fall to zero if need be. */
+
+      if (result == 0.0)
+
+        DOUBLE_TO_LONGBITS (result) = MINIMUM_LONGBITS;
+      else
+        DOUBLE_TO_LONGBITS (result) = INFINITE_LONGBITS;
+    }
+  else if (e > APPROX_MIN_MAGNITUDE)
+    {
+      result = toDoubleHighPrecision (f, length) / pow (10.0, -e);
+    }
+
+  if (e <= APPROX_MIN_MAGNITUDE)
+    {
+
+      result = toDoubleHighPrecision (f, length) * pow (10.0, e + 52);
+      result = result * pow (10.0, -52);
+
+    }
+
+  /* Don't go straight to zero as the fact that x*0 = 0 independent of x might
+     cause the algorithm to produce an incorrect result.  Instead try the min value
+     first and let it fall to zero if need be. */
+
+  if (result == 0.0)
+
+    DOUBLE_TO_LONGBITS (result) = MINIMUM_LONGBITS;
+
+  return doubleAlgorithm (env, f, length, e, result);
+}
+
+U_64
+dblparse_shiftRight64 (U_64 * lp, volatile int mbe)
+{
+  U_64 b1Value = 0;
+  U_32 hi = HIGH_U32_FROM_LONG64_PTR (lp);
+  U_32 lo = LOW_U32_FROM_LONG64_PTR (lp);
+  int srAmt;
+
+  if (mbe == 0)
+    return 0;
+  if (mbe >= 128)
+    {
+      HIGH_U32_FROM_LONG64_PTR (lp) = 0;
+      LOW_U32_FROM_LONG64_PTR (lp) = 0;
+      return 0;
+    }
+
+  /* Certain platforms do not handle de-referencing a 64-bit value
+   * from a pointer on the stack correctly (e.g. MVL-hh/XScale)
+   * because the pointer may not be properly aligned, so we'll have
+   * to handle two 32-bit chunks. */
+  if (mbe < 32)
+    {
+      LOW_U32_FROM_LONG64 (b1Value) = 0;
+      HIGH_U32_FROM_LONG64 (b1Value) = lo << (32 - mbe);
+      LOW_U32_FROM_LONG64_PTR (lp) = (hi << (32 - mbe)) | (lo >> mbe);
+      HIGH_U32_FROM_LONG64_PTR (lp) = hi >> mbe;
+    }
+  else if (mbe == 32)
+    {
+      LOW_U32_FROM_LONG64 (b1Value) = 0;
+      HIGH_U32_FROM_LONG64 (b1Value) = lo;
+      LOW_U32_FROM_LONG64_PTR (lp) = hi;
+      HIGH_U32_FROM_LONG64_PTR (lp) = 0;
+    }
+  else if (mbe < 64)
+    {
+      srAmt = mbe - 32;
+      LOW_U32_FROM_LONG64 (b1Value) = lo << (32 - srAmt);
+      HIGH_U32_FROM_LONG64 (b1Value) = (hi << (32 - srAmt)) | (lo >> srAmt);
+      LOW_U32_FROM_LONG64_PTR (lp) = hi >> srAmt;
+      HIGH_U32_FROM_LONG64_PTR (lp) = 0;
+    }
+  else if (mbe == 64)
+    {
+      LOW_U32_FROM_LONG64 (b1Value) = lo;
+      HIGH_U32_FROM_LONG64 (b1Value) = hi;
+      LOW_U32_FROM_LONG64_PTR (lp) = 0;
+      HIGH_U32_FROM_LONG64_PTR (lp) = 0;
+    }
+  else if (mbe < 96)
+    {
+      srAmt = mbe - 64;
+      b1Value = *lp;
+      HIGH_U32_FROM_LONG64_PTR (lp) = 0;
+      LOW_U32_FROM_LONG64_PTR (lp) = 0;
+      LOW_U32_FROM_LONG64 (b1Value) >>= srAmt;
+      LOW_U32_FROM_LONG64 (b1Value) |= (hi << (32 - srAmt));
+      HIGH_U32_FROM_LONG64 (b1Value) >>= srAmt;
+    }
+  else if (mbe == 96)
+    {
+      LOW_U32_FROM_LONG64 (b1Value) = hi;
+      HIGH_U32_FROM_LONG64 (b1Value) = 0;
+      HIGH_U32_FROM_LONG64_PTR (lp) = 0;
+      LOW_U32_FROM_LONG64_PTR (lp) = 0;
+    }
+  else
+    {
+      LOW_U32_FROM_LONG64 (b1Value) = hi >> (mbe - 96);
+      HIGH_U32_FROM_LONG64 (b1Value) = 0;
+      HIGH_U32_FROM_LONG64_PTR (lp) = 0;
+      LOW_U32_FROM_LONG64_PTR (lp) = 0;
+    }
+
+  return b1Value;
+}
+
+#if defined(WIN32)
+/* disable global optimizations on the microsoft compiler for the
+ * doubleAlgorithm function otherwise it won't compile */
+#pragma optimize("g",off)
+#endif
+
+/* The algorithm for the function doubleAlgorithm() below can be found
+ * in:
+ *
+ *      "How to Read Floating-Point Numbers Accurately", William D.
+ *      Clinger, Proceedings of the ACM SIGPLAN '90 Conference on
+ *      Programming Language Design and Implementation, June 20-22,
+ *      1990, pp. 92-101.
+ *
+ * There is a possibility that the function will end up in an endless
+ * loop if the given approximating floating-point number (a very small
+ * floating-point whose value is very close to zero) straddles between
+ * two approximating integer values. We modified the algorithm slightly
+ * to detect the case where it oscillates back and forth between
+ * incrementing and decrementing the floating-point approximation. It
+ * is currently set such that if the oscillation occurs more than twice
+ * then return the original approximation.
+ */
+jdouble
+doubleAlgorithm (JNIEnv * env, U_64 * f, IDATA length, jint e, jdouble z)
+{
+  U_64 m;
+  IDATA k, comparison, comparison2;
+  U_64 *x, *y, *D, *D2;
+  IDATA xLength, yLength, DLength, D2Length, decApproxCount, incApproxCount;
+  PORT_ACCESS_FROM_ENV (env);
+
+  x = y = D = D2 = 0;
+  xLength = yLength = DLength = D2Length = 0;
+  decApproxCount = incApproxCount = 0;
+
+  do
+    {
+      m = doubleMantissa (z);
+      k = doubleExponent (z);
+
+      if (x && x != f)
+        jclmem_free_memory (env, x);
+      release (y);
+      release (D);
+      release (D2);
+
+      if (e >= 0 && k >= 0)
+        {
+          xLength = sizeOfTenToTheE (e) + length;
+          allocateU64 (x, xLength);
+          memset (x + length, 0, sizeof (U_64) * (xLength - length));
+          memcpy (x, f, sizeof (U_64) * length);
+          timesTenToTheEHighPrecision (x, xLength, e);
+
+          yLength = (k >> 6) + 2;
+          allocateU64 (y, yLength);
+          memset (y + 1, 0, sizeof (U_64) * (yLength - 1));
+          *y = m;
+          simpleShiftLeftHighPrecision (y, yLength, k);
+        }
+      else if (e >= 0)
+        {
+          xLength = sizeOfTenToTheE (e) + length + ((-k) >> 6) + 1;
+          allocateU64 (x, xLength);
+          memset (x + length, 0, sizeof (U_64) * (xLength - length));
+          memcpy (x, f, sizeof (U_64) * length);
+          timesTenToTheEHighPrecision (x, xLength, e);
+          simpleShiftLeftHighPrecision (x, xLength, -k);
+
+          yLength = 1;
+          allocateU64 (y, 1);
+          *y = m;
+        }
+      else if (k >= 0)
+        {
+          xLength = length;
+          x = f;
+
+          yLength = sizeOfTenToTheE (-e) + 2 + (k >> 6);
+          allocateU64 (y, yLength);
+          memset (y + 1, 0, sizeof (U_64) * (yLength - 1));
+          *y = m;
+          timesTenToTheEHighPrecision (y, yLength, -e);
+          simpleShiftLeftHighPrecision (y, yLength, k);
+        }
+      else
+        {
+          xLength = length + ((-k) >> 6) + 1;
+          allocateU64 (x, xLength);
+          memset (x + length, 0, sizeof (U_64) * (xLength - length));
+          memcpy (x, f, sizeof (U_64) * length);
+          simpleShiftLeftHighPrecision (x, xLength, -k);
+
+          yLength = sizeOfTenToTheE (-e) + 1;
+          allocateU64 (y, yLength);
+          memset (y + 1, 0, sizeof (U_64) * (yLength - 1));
+          *y = m;
+          timesTenToTheEHighPrecision (y, yLength, -e);
+        }
+
+      comparison = compareHighPrecision (x, xLength, y, yLength);
+      if (comparison > 0)
+        {                       /* x > y */
+          DLength = xLength;
+          allocateU64 (D, DLength);
+          memcpy (D, x, DLength * sizeof (U_64));
+          subtractHighPrecision (D, DLength, y, yLength);
+        }
+      else if (comparison)
+        {                       /* y > x */
+          DLength = yLength;
+          allocateU64 (D, DLength);
+          memcpy (D, y, DLength * sizeof (U_64));
+          subtractHighPrecision (D, DLength, x, xLength);
+        }
+      else
+        {                       /* y == x */
+          DLength = 1;
+          allocateU64 (D, 1);
+          *D = 0;
+        }
+
+      D2Length = DLength + 1;
+      allocateU64 (D2, D2Length);
+      m <<= 1;
+      multiplyHighPrecision (D, DLength, &m, 1, D2, D2Length);
+      m >>= 1;
+
+      comparison2 = compareHighPrecision (D2, D2Length, y, yLength);
+      if (comparison2 < 0)
+        {
+          if (comparison < 0 && m == NORMAL_MASK)
+            {
+              simpleShiftLeftHighPrecision (D2, D2Length, 1);
+              if (compareHighPrecision (D2, D2Length, y, yLength) > 0)
+                {
+                  DECREMENT_DOUBLE (z, decApproxCount, incApproxCount);
+                }
+              else
+                {
+                  break;
+                }
+            }
+          else
+            {
+              break;
+            }
+        }
+      else if (comparison2 == 0)
+        {
+          if ((LOW_U32_FROM_VAR (m) & 1) == 0)
+            {
+              if (comparison < 0 && m == NORMAL_MASK)
+                {
+                  DECREMENT_DOUBLE (z, decApproxCount, incApproxCount);
+                }
+              else
+                {
+                  break;
+                }
+            }
+          else if (comparison < 0)
+            {
+              DECREMENT_DOUBLE (z, decApproxCount, incApproxCount);
+              break;
+            }
+          else
+            {
+              INCREMENT_DOUBLE (z, decApproxCount, incApproxCount);
+              break;
+            }
+        }
+      else if (comparison < 0)
+        {
+          DECREMENT_DOUBLE (z, decApproxCount, incApproxCount);
+        }
+      else
+        {
+          if (DOUBLE_TO_LONGBITS (z) == INFINITE_LONGBITS)
+            break;
+          INCREMENT_DOUBLE (z, decApproxCount, incApproxCount);
+        }
+    }
+  while (1);
+
+  if (x && x != f)
+    jclmem_free_memory (env, x);
+  release (y);
+  release (D);
+  release (D2);
+  return z;
+
+OutOfMemory:
+  if (x && x != f)
+    jclmem_free_memory (env, x);
+  release (y);
+  release (D);
+  release (D2);
+
+  DOUBLE_TO_LONGBITS (z) = -2;
+
+  return z;
+}
+
+#if defined(WIN32)
+#pragma optimize("",on)         /*restore optimizations */
+#endif
+
+JNIEXPORT jdouble JNICALL
+Java_com_ibm_oti_util_FloatingPointParser_parseDblImpl (JNIEnv * env,
+                                                        jclass clazz,
+                                                        jstring s, jint e)
+{
+  jdouble dbl;
+  const char *str = (*env)->GetStringUTFChars (env, s, 0);
+  dbl = createDouble (env, str, e);
+  (*env)->ReleaseStringUTFChars (env, s, str);
+
+  if (!ERROR_OCCURED (dbl))
+    {
+      return dbl;
+    }
+  else if (LOW_I32_FROM_VAR (dbl) == (I_32) - 1)
+    {                           /* NumberFormatException */
+      clazz = (*env)->FindClass (env, "java/lang/NumberFormatException");
+      if (clazz == 0)
+        return 0.0;
+      (*env)->ThrowNew (env, clazz, "");
+    }
+  else
+    {                           /* OutOfMemoryError */
+      clazz = (*env)->FindClass (env, "java/lang/OutOfMemoryError");
+      if (clazz == 0)
+        return 0.0;
+      (*env)->ThrowNew (env, clazz, "");
+    }
+
+  return 0.0;
+}
+
+/* The algorithm for this particular function can be found in:
+ *
+ *      Printing Floating-Point Numbers Quickly and Accurately, Robert
+ *      G. Burger, and R. Kent Dybvig, Programming Language Design and
+ *      Implementation (PLDI) 1996, pp.108-116.
+ *
+ * The previous implementation of this function combined m+ and m- into
+ * one single M which caused some inaccuracy of the last digit. The
+ * particular case below shows this inaccuracy:
+ *
+ *       System.out.println(new Double((1.234123412431233E107)).toString());
+ *       System.out.println(new Double((1.2341234124312331E107)).toString());
+ *       System.out.println(new Double((1.2341234124312332E107)).toString());
+ *
+ *       outputs the following:
+ *
+ *           1.234123412431233E107
+ *           1.234123412431233E107
+ *           1.234123412431233E107
+ *
+ *       instead of:
+ *
+ *           1.234123412431233E107
+ *           1.2341234124312331E107
+ *           1.2341234124312331E107
+ * 
+ */
+JNIEXPORT void JNICALL
+Java_com_ibm_oti_util_NumberConverter_bigIntDigitGeneratorInstImpl (JNIEnv *
+                                                                    env,
+                                                                    jobject
+                                                                    inst,
+                                                                    jlong f,
+                                                                    jint e,
+                                                                    jboolean
+                                                                    isDenormalized,
+                                                                    jboolean
+                                                                    mantissaIsZero,
+                                                                    jint p)
+{
+  int RLength, SLength, TempLength, mplus_Length, mminus_Length;
+  int high, low, i;
+  jint k, firstK, U;
+  jint getCount, setCount;
+  jint *uArray;
+
+  jclass clazz;
+  jfieldID fid;
+  jintArray uArrayObject;
+
+  U_64 R[RM_SIZE], S[STemp_SIZE], mplus[RM_SIZE], mminus[RM_SIZE],
+    Temp[STemp_SIZE];
+
+  memset (R, 0, RM_SIZE * sizeof (U_64));
+  memset (S, 0, STemp_SIZE * sizeof (U_64));
+  memset (mplus, 0, RM_SIZE * sizeof (U_64));
+  memset (mminus, 0, RM_SIZE * sizeof (U_64));
+  memset (Temp, 0, STemp_SIZE * sizeof (U_64));
+
+  if (e >= 0)
+    {
+      *R = f;
+      *mplus = *mminus = 1;
+      simpleShiftLeftHighPrecision (mminus, RM_SIZE, e);
+      if (f != (2 << (p - 1)))
+        {
+          simpleShiftLeftHighPrecision (R, RM_SIZE, e + 1);
+          *S = 2;
+          /*
+           * m+ = m+ << e results in 1.0e23 to be printed as
+           * 0.9999999999999999E23
+           * m+ = m+ << e+1 results in 1.0e23 to be printed as
+           * 1.0e23 (caused too much rounding)
+           *      470fffffffffffff = 2.0769187434139308E34
+           *      4710000000000000 = 2.076918743413931E34
+           */
+          simpleShiftLeftHighPrecision (mplus, RM_SIZE, e);
+        }
+      else
+        {
+          simpleShiftLeftHighPrecision (R, RM_SIZE, e + 2);
+          *S = 4;
+          simpleShiftLeftHighPrecision (mplus, RM_SIZE, e + 1);
+        }
+    }
+  else
+    {
+      if (isDenormalized || (f != (2 << (p - 1))))
+        {
+          *R = f << 1;
+          *S = 1;
+          simpleShiftLeftHighPrecision (S, STemp_SIZE, 1 - e);
+          *mplus = *mminus = 1;
+        }
+      else
+        {
+          *R = f << 2;
+          *S = 1;
+          simpleShiftLeftHighPrecision (S, STemp_SIZE, 2 - e);
+          *mplus = 2;
+          *mminus = 1;
+        }
+    }
+
+  k = (int) ceil ((e + p - 1) * INV_LOG_OF_TEN_BASE_2 - 1e-10);
+
+  if (k > 0)
+    {
+      timesTenToTheEHighPrecision (S, STemp_SIZE, k);
+    }
+  else
+    {
+      timesTenToTheEHighPrecision (R, RM_SIZE, -k);
+      timesTenToTheEHighPrecision (mplus, RM_SIZE, -k);
+      timesTenToTheEHighPrecision (mminus, RM_SIZE, -k);
+    }
+
+  RLength = mplus_Length = mminus_Length = RM_SIZE;
+  SLength = TempLength = STemp_SIZE;
+
+  memset (Temp + RM_SIZE, 0, (STemp_SIZE - RM_SIZE) * sizeof (U_64));
+  memcpy (Temp, R, RM_SIZE * sizeof (U_64));
+
+  while (RLength > 1 && R[RLength - 1] == 0)
+    --RLength;
+  while (mplus_Length > 1 && mplus[mplus_Length - 1] == 0)
+    --mplus_Length;
+  while (mminus_Length > 1 && mminus[mminus_Length - 1] == 0)
+    --mminus_Length;
+  while (SLength > 1 && S[SLength - 1] == 0)
+    --SLength;
+  TempLength = (RLength > mplus_Length ? RLength : mplus_Length) + 1;
+  addHighPrecision (Temp, TempLength, mplus, mplus_Length);
+
+  if (compareHighPrecision (Temp, TempLength, S, SLength) >= 0)
+    {
+      firstK = k;
+    }
+  else
+    {
+      firstK = k - 1;
+      simpleAppendDecimalDigitHighPrecision (R, ++RLength, 0);
+      simpleAppendDecimalDigitHighPrecision (mplus, ++mplus_Length, 0);
+      simpleAppendDecimalDigitHighPrecision (mminus, ++mminus_Length, 0);
+      while (RLength > 1 && R[RLength - 1] == 0)
+        --RLength;
+      while (mplus_Length > 1 && mplus[mplus_Length - 1] == 0)
+        --mplus_Length;
+      while (mminus_Length > 1 && mminus[mminus_Length - 1] == 0)
+        --mminus_Length;
+    }
+
+  clazz = (*env)->GetObjectClass (env, inst);
+  fid = (*env)->GetFieldID (env, clazz, "uArray", "[I");
+  uArrayObject = (jintArray) (*env)->GetObjectField (env, inst, fid);
+  uArray = (*env)->GetIntArrayElements (env, uArrayObject, 0);
+
+  getCount = setCount = 0;
+  do
+    {
+      U = 0;
+      for (i = 3; i >= 0; --i)
+        {
+          TempLength = SLength + 1;
+          Temp[SLength] = 0;
+          memcpy (Temp, S, SLength * sizeof (U_64));
+          simpleShiftLeftHighPrecision (Temp, TempLength, i);
+          if (compareHighPrecision (R, RLength, Temp, TempLength) >= 0)
+            {
+              subtractHighPrecision (R, RLength, Temp, TempLength);
+              U += 1 << i;
+            }
+        }
+
+      low = compareHighPrecision (R, RLength, mminus, mminus_Length) <= 0;
+
+      memset (Temp + RLength, 0, (STemp_SIZE - RLength) * sizeof (U_64));
+      memcpy (Temp, R, RLength * sizeof (U_64));
+      TempLength = (RLength > mplus_Length ? RLength : mplus_Length) + 1;
+      addHighPrecision (Temp, TempLength, mplus, mplus_Length);
+
+      high = compareHighPrecision (Temp, TempLength, S, SLength) >= 0;
+
+      if (low || high)
+        break;
+
+      simpleAppendDecimalDigitHighPrecision (R, ++RLength, 0);
+      simpleAppendDecimalDigitHighPrecision (mplus, ++mplus_Length, 0);
+      simpleAppendDecimalDigitHighPrecision (mminus, ++mminus_Length, 0);
+      while (RLength > 1 && R[RLength - 1] == 0)
+        --RLength;
+      while (mplus_Length > 1 && mplus[mplus_Length - 1] == 0)
+        --mplus_Length;
+      while (mminus_Length > 1 && mminus[mminus_Length - 1] == 0)
+        --mminus_Length;
+      uArray[setCount++] = U;
+    }
+  while (1);
+
+  simpleShiftLeftHighPrecision (R, ++RLength, 1);
+  if (low && !high)
+    uArray[setCount++] = U;
+  else if (high && !low)
+    uArray[setCount++] = U + 1;
+  else if (compareHighPrecision (R, RLength, S, SLength) < 0)
+    uArray[setCount++] = U;
+  else
+    uArray[setCount++] = U + 1;
+
+  (*env)->ReleaseIntArrayElements (env, uArrayObject, uArray, 0);
+
+  fid = (*env)->GetFieldID (env, clazz, "setCount", "I");
+  (*env)->SetIntField (env, inst, fid, setCount);
+
+  fid = (*env)->GetFieldID (env, clazz, "getCount", "I");
+  (*env)->SetIntField (env, inst, fid, getCount);
+
+  fid = (*env)->GetFieldID (env, clazz, "firstK", "I");
+  (*env)->SetIntField (env, inst, fid, firstK);
+
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/fltparse.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/fltparse.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/fltparse.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/fltparse.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,557 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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 <string.h>
+#include <math.h>
+#include "jcl.h"
+#include "cbigint.h"
+#include "jclglob.h"
+
+#if defined(LINUX)
+#define USE_LL
+#endif
+
+#define LOW_I32_FROM_PTR(ptr64) (*(I_32 *) (ptr64))
+
+#define MAX_ACCURACY_WIDTH 8
+
+#define DEFAULT_WIDTH MAX_ACCURACY_WIDTH
+
+JNIEXPORT jfloat JNICALL
+Java_com_ibm_oti_util_FloatingPointParser_parseFltImpl (JNIEnv * env,
+                                                        jclass clazz,
+                                                        jstring s, jint e);
+
+jfloat createFloat1 (JNIEnv * env, U_64 * f, IDATA length, jint e);
+jfloat floatAlgorithm (JNIEnv * env, U_64 * f, IDATA length, jint e,
+                       jfloat z);
+jfloat createFloat (JNIEnv * env, const char *s, jint e);
+
+static const U_32 tens[] = {
+  0x3f800000,
+  0x41200000,
+  0x42c80000,
+  0x447a0000,
+  0x461c4000,
+  0x47c35000,
+  0x49742400,
+  0x4b189680,
+  0x4cbebc20,
+  0x4e6e6b28,
+  0x501502f9                    /* 10 ^ 10 in float */
+};
+
+#define tenToTheE(e) (*((jfloat *) (tens + (e))))
+#define LOG5_OF_TWO_TO_THE_N 11
+
+#define sizeOfTenToTheE(e) (((e) / 19) + 1)
+
+#define INFINITE_INTBITS (0x7F800000)
+#define MINIMUM_INTBITS (1)
+
+#define MANTISSA_MASK (0x007FFFFF)
+#define EXPONENT_MASK (0x7F800000)
+#define NORMAL_MASK   (0x00800000)
+#define FLOAT_TO_INTBITS(flt) (*((U_32 *)(&flt)))
+
+/* Keep a count of the number of times we decrement and increment to
+ * approximate the double, and attempt to detect the case where we
+ * could potentially toggle back and forth between decrementing and
+ * incrementing. It is possible for us to be stuck in the loop when
+ * incrementing by one or decrementing by one may exceed or stay below
+ * the value that we are looking for. In this case, just break out of
+ * the loop if we toggle between incrementing and decrementing for more
+ * than twice.
+ */
+#define INCREMENT_FLOAT(_x, _decCount, _incCount) \
+    { \
+        ++FLOAT_TO_INTBITS(_x); \
+        _incCount++; \
+        if( (_incCount > 2) && (_decCount > 2) ) { \
+            if( _decCount > _incCount ) { \
+                FLOAT_TO_INTBITS(_x) += _decCount - _incCount; \
+            } else if( _incCount > _decCount ) { \
+                FLOAT_TO_INTBITS(_x) -= _incCount - _decCount; \
+            } \
+            break; \
+        } \
+    }
+#define DECREMENT_FLOAT(_x, _decCount, _incCount) \
+    { \
+        --FLOAT_TO_INTBITS(_x); \
+        _decCount++; \
+        if( (_incCount > 2) && (_decCount > 2) ) { \
+            if( _decCount > _incCount ) { \
+                FLOAT_TO_INTBITS(_x) += _decCount - _incCount; \
+            } else if( _incCount > _decCount ) { \
+                FLOAT_TO_INTBITS(_x) -= _incCount - _decCount; \
+            } \
+            break; \
+        } \
+    }
+
+#define allocateU64(ptr, n) if (!((ptr) = (U_64*) hymem_allocate_memory((n) * sizeof(U_64)))) goto OutOfMemory;
+#define release(r) if ((r)) hymem_free_memory((r));
+
+jfloat
+createFloat (JNIEnv * env, const char *s, jint e)
+{
+  /* assumes s is a null terminated string with at least one
+   * character in it */
+  U_64 def[DEFAULT_WIDTH];
+  U_64 defBackup[DEFAULT_WIDTH];
+  U_64 *f, *fNoOverflow, *g, *tempBackup;
+  U_32 overflow;
+  jfloat result;
+  IDATA index = 1;
+  int unprocessedDigits = 0;
+  PORT_ACCESS_FROM_ENV (env);
+
+  f = def;
+  fNoOverflow = defBackup;
+  *f = 0;
+  tempBackup = g = 0;
+  do
+    {
+      if (*s >= '0' && *s <= '9')
+        {
+          /* Make a back up of f before appending, so that we can
+           * back out of it if there is no more room, i.e. index >
+           * MAX_ACCURACY_WIDTH.
+           */
+          memcpy (fNoOverflow, f, sizeof (U_64) * index);
+          overflow =
+            simpleAppendDecimalDigitHighPrecision (f, index, *s - '0');
+          if (overflow)
+            {
+
+              f[index++] = overflow;
+              /* There is an overflow, but there is no more room
+               * to store the result. We really only need the top 52
+               * bits anyway, so we must back out of the overflow,
+               * and ignore the rest of the string.
+               */
+              if (index >= MAX_ACCURACY_WIDTH)
+                {
+                  index--;
+                  memcpy (f, fNoOverflow, sizeof (U_64) * index);
+                  break;
+                }
+              if (tempBackup)
+                {
+                  fNoOverflow = tempBackup;
+                }
+            }
+        }
+      else
+        index = -1;
+    }
+  while (index > 0 && *(++s) != '\0');
+
+  /* We've broken out of the parse loop either because we've reached
+   * the end of the string or we've overflowed the maximum accuracy
+   * limit of a double. If we still have unprocessed digits in the
+   * given string, then there are three possible results:
+   *   1. (unprocessed digits + e) == 0, in which case we simply
+   *      convert the existing bits that are already parsed
+   *   2. (unprocessed digits + e) < 0, in which case we simply
+   *      convert the existing bits that are already parsed along
+   *      with the given e
+   *   3. (unprocessed digits + e) > 0 indicates that the value is
+   *      simply too big to be stored as a double, so return Infinity
+   */
+  if ((unprocessedDigits = strlen (s)) > 0)
+    {
+      e += unprocessedDigits;
+      if (index > -1)
+        {
+          if (e <= 0)
+            {
+              result = createFloat1 (env, f, index, e);
+            }
+          else
+            {
+              FLOAT_TO_INTBITS (result) = INFINITE_INTBITS;
+            }
+        }
+      else
+        {
+          result = *(jfloat *) & index;
+        }
+    }
+  else
+    {
+      if (index > -1)
+        {
+          result = createFloat1 (env, f, index, e);
+        }
+      else
+        {
+        result = *(jfloat *) & index;
+        }
+    }
+
+  return result;
+
+}
+
+jfloat
+createFloat1 (JNIEnv * env, U_64 * f, IDATA length, jint e)
+{
+  IDATA numBits;
+  jdouble dresult;
+  jfloat result;
+
+  numBits = highestSetBitHighPrecision (f, length) + 1;
+  numBits -= lowestSetBitHighPrecision (f, length);
+  if (numBits < 25 && e >= 0 && e < LOG5_OF_TWO_TO_THE_N)
+    {
+      return ((jfloat) LOW_I32_FROM_PTR (f)) * tenToTheE (e);
+    }
+  else if (numBits < 25 && e < 0 && (-e) < LOG5_OF_TWO_TO_THE_N)
+    {
+      return ((jfloat) LOW_I32_FROM_PTR (f)) / tenToTheE (-e);
+    }
+  else if (e >= 0 && e < 39)
+    {
+      result = (jfloat) (toDoubleHighPrecision (f, length) * pow (10.0, e));
+    }
+  else if (e >= 39)
+    {
+      /* Convert the partial result to make sure that the
+       * non-exponential part is not zero. This check fixes the case
+       * where the user enters 0.0e309! */
+      result = (jfloat) toDoubleHighPrecision (f, length);
+
+      if (result == 0.0)
+
+        FLOAT_TO_INTBITS (result) = MINIMUM_INTBITS;
+      else
+        FLOAT_TO_INTBITS (result) = INFINITE_INTBITS;
+    }
+  else if (e > -309)
+    {
+      int dexp;
+      U_32 fmant, fovfl;
+      U_64 dmant;
+      dresult = toDoubleHighPrecision (f, length) / pow (10.0, -e);
+      if (IS_DENORMAL_DBL (dresult))
+        {
+          FLOAT_TO_INTBITS (result) = 0;
+          return result;
+        }
+      dexp = doubleExponent (dresult) + 51;
+      dmant = doubleMantissa (dresult);
+      /* Is it too small to be represented by a single-precision
+       * float? */
+      if (dexp <= -155)
+        {
+          FLOAT_TO_INTBITS (result) = 0;
+          return result;
+        }
+      /* Is it a denormalized single-precision float? */
+      if ((dexp <= -127) && (dexp > -155))
+        {
+          /* Only interested in 24 msb bits of the 53-bit double mantissa */
+          fmant = (U_32) (dmant >> 29);
+          fovfl = ((U_32) (dmant & 0x1FFFFFFF)) << 3;
+          while ((dexp < -127) && ((fmant | fovfl) != 0))
+            {
+              if ((fmant & 1) != 0)
+                {
+                  fovfl |= 0x80000000;
+                }
+              fovfl >>= 1;
+              fmant >>= 1;
+              dexp++;
+            }
+          if ((fovfl & 0x80000000) != 0)
+            {
+              if ((fovfl & 0x7FFFFFFC) != 0)
+                {
+                  fmant++;
+                }
+              else if ((fmant & 1) != 0)
+                {
+                  fmant++;
+                }
+            }
+          else if ((fovfl & 0x40000000) != 0)
+            {
+              if ((fovfl & 0x3FFFFFFC) != 0)
+                {
+                  fmant++;
+                }
+            }
+          FLOAT_TO_INTBITS (result) = fmant;
+        }
+      else
+        {
+          result = (jfloat) dresult;
+        }
+    }
+
+  /* Don't go straight to zero as the fact that x*0 = 0 independent
+   * of x might cause the algorithm to produce an incorrect result.
+   * Instead try the min  value first and let it fall to zero if need
+   * be.
+   */
+  if (e <= -309 || FLOAT_TO_INTBITS (result) == 0)
+    FLOAT_TO_INTBITS (result) = MINIMUM_INTBITS;
+
+  return floatAlgorithm (env, f, length, e, (jfloat) result);
+}
+
+#if defined(WIN32)
+/* disable global optimizations on the microsoft compiler for the
+ * floatAlgorithm function otherwise it won't properly compile */
+#pragma optimize("g",off)
+#endif
+
+/* The algorithm for the function floatAlgorithm() below can be found
+ * in:
+ *
+ *      "How to Read Floating-Point Numbers Accurately", William D.
+ *      Clinger, Proceedings of the ACM SIGPLAN '90 Conference on
+ *      Programming Language Design and Implementation, June 20-22,
+ *      1990, pp. 92-101.
+ *
+ * There is a possibility that the function will end up in an endless
+ * loop if the given approximating floating-point number (a very small
+ * floating-point whose value is very close to zero) straddles between
+ * two approximating integer values. We modified the algorithm slightly
+ * to detect the case where it oscillates back and forth between
+ * incrementing and decrementing the floating-point approximation. It
+ * is currently set such that if the oscillation occurs more than twice
+ * then return the original approximation.
+ */
+jfloat
+floatAlgorithm (JNIEnv * env, U_64 * f, IDATA length, jint e, jfloat z)
+{
+  U_64 m;
+  IDATA k, comparison, comparison2;
+  U_64 *x, *y, *D, *D2;
+  IDATA xLength, yLength, DLength, D2Length;
+  IDATA decApproxCount, incApproxCount;
+  PORT_ACCESS_FROM_ENV (env);
+
+  x = y = D = D2 = 0;
+  xLength = yLength = DLength = D2Length = 0;
+  decApproxCount = incApproxCount = 0;
+
+  do
+    {
+      m = floatMantissa (z);
+      k = floatExponent (z);
+
+      if (x && x != f)
+        jclmem_free_memory (env, x);
+      release (y);
+      release (D);
+      release (D2);
+
+      if (e >= 0 && k >= 0)
+        {
+          xLength = sizeOfTenToTheE (e) + length;
+          allocateU64 (x, xLength);
+          memset (x + length, 0, sizeof (U_64) * (xLength - length));
+          memcpy (x, f, sizeof (U_64) * length);
+          timesTenToTheEHighPrecision (x, xLength, e);
+
+          yLength = (k >> 6) + 2;
+          allocateU64 (y, yLength);
+          memset (y + 1, 0, sizeof (U_64) * (yLength - 1));
+          *y = m;
+          simpleShiftLeftHighPrecision (y, yLength, k);
+        }
+      else if (e >= 0)
+        {
+          xLength = sizeOfTenToTheE (e) + length + ((-k) >> 6) + 1;
+          allocateU64 (x, xLength);
+          memset (x + length, 0, sizeof (U_64) * (xLength - length));
+          memcpy (x, f, sizeof (U_64) * length);
+          timesTenToTheEHighPrecision (x, xLength, e);
+          simpleShiftLeftHighPrecision (x, xLength, -k);
+
+          yLength = 1;
+          allocateU64 (y, 1);
+          *y = m;
+        }
+      else if (k >= 0)
+        {
+          xLength = length;
+          x = f;
+
+          yLength = sizeOfTenToTheE (-e) + 2 + (k >> 6);
+          allocateU64 (y, yLength);
+          memset (y + 1, 0, sizeof (U_64) * (yLength - 1));
+          *y = m;
+          timesTenToTheEHighPrecision (y, yLength, -e);
+          simpleShiftLeftHighPrecision (y, yLength, k);
+        }
+      else
+        {
+          xLength = length + ((-k) >> 6) + 1;
+          allocateU64 (x, xLength);
+          memset (x + length, 0, sizeof (U_64) * (xLength - length));
+          memcpy (x, f, sizeof (U_64) * length);
+          simpleShiftLeftHighPrecision (x, xLength, -k);
+
+          yLength = sizeOfTenToTheE (-e) + 1;
+          allocateU64 (y, yLength);
+          memset (y + 1, 0, sizeof (U_64) * (yLength - 1));
+          *y = m;
+          timesTenToTheEHighPrecision (y, yLength, -e);
+        }
+
+      comparison = compareHighPrecision (x, xLength, y, yLength);
+      if (comparison > 0)
+        {                       /* x > y */
+          DLength = xLength;
+          allocateU64 (D, DLength);
+          memcpy (D, x, DLength * sizeof (U_64));
+          subtractHighPrecision (D, DLength, y, yLength);
+        }
+      else if (comparison)
+        {                       /* y > x */
+          DLength = yLength;
+          allocateU64 (D, DLength);
+          memcpy (D, y, DLength * sizeof (U_64));
+          subtractHighPrecision (D, DLength, x, xLength);
+        }
+      else
+        {                       /* y == x */
+          DLength = 1;
+          allocateU64 (D, 1);
+          *D = 0;
+        }
+
+      D2Length = DLength + 1;
+      allocateU64 (D2, D2Length);
+      m <<= 1;
+      multiplyHighPrecision (D, DLength, &m, 1, D2, D2Length);
+      m >>= 1;
+
+      comparison2 = compareHighPrecision (D2, D2Length, y, yLength);
+      if (comparison2 < 0)
+        {
+          if (comparison < 0 && m == NORMAL_MASK)
+            {
+              simpleShiftLeftHighPrecision (D2, D2Length, 1);
+              if (compareHighPrecision (D2, D2Length, y, yLength) > 0)
+                {
+                  DECREMENT_FLOAT (z, decApproxCount, incApproxCount);
+                }
+              else
+                {
+                  break;
+                }
+            }
+          else
+            {
+              break;
+            }
+        }
+      else if (comparison2 == 0)
+        {
+          if ((m & 1) == 0)
+            {
+              if (comparison < 0 && m == NORMAL_MASK)
+                {
+                  DECREMENT_FLOAT (z, decApproxCount, incApproxCount);
+                }
+              else
+                {
+                  break;
+                }
+            }
+          else if (comparison < 0)
+            {
+              DECREMENT_FLOAT (z, decApproxCount, incApproxCount);
+              break;
+            }
+          else
+            {
+              INCREMENT_FLOAT (z, decApproxCount, incApproxCount);
+              break;
+            }
+        }
+      else if (comparison < 0)
+        {
+          DECREMENT_FLOAT (z, decApproxCount, incApproxCount);
+        }
+      else
+        {
+          if (FLOAT_TO_INTBITS (z) == EXPONENT_MASK)
+            break;
+          INCREMENT_FLOAT (z, decApproxCount, incApproxCount);
+        }
+    }
+  while (1);
+
+  if (x && x != f)
+    jclmem_free_memory (env, x);
+  release (y);
+  release (D);
+  release (D2);
+  return z;
+
+OutOfMemory:
+  if (x && x != f)
+    jclmem_free_memory (env, x);
+  release (y);
+  release (D);
+  release (D2);
+
+  FLOAT_TO_INTBITS (z) = -2;
+
+  return z;
+}
+
+#if defined(WIN32)
+#pragma optimize("",on)         /*restore optimizations */
+#endif
+
+JNIEXPORT jfloat JNICALL
+Java_com_ibm_oti_util_FloatingPointParser_parseFltImpl (JNIEnv * env,
+                                                        jclass clazz,
+                                                        jstring s, jint e)
+{
+  jfloat flt;
+  const char *str = (*env)->GetStringUTFChars (env, s, 0);
+  flt = createFloat (env, str, e);
+  (*env)->ReleaseStringUTFChars (env, s, str);
+
+  if (((I_32) FLOAT_TO_INTBITS (flt)) >= 0)
+    {
+      return flt;
+    }
+  else if (((I_32) FLOAT_TO_INTBITS (flt)) == (I_32) - 1)
+    {
+      clazz = (*env)->FindClass (env, "java/lang/NumberFormatException");
+      if (clazz == 0)
+        return 0.0;
+      (*env)->ThrowNew (env, clazz, "");
+    }
+  else
+    {                           /* OutOfMemoryError */
+      clazz = (*env)->FindClass (env, "java/lang/OutOfMemoryError");
+      if (clazz == 0)
+        return 0.0;
+      (*env)->ThrowNew (env, clazz, "");
+    }
+
+  return 0.0;
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/hymath.exp
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/hymath.exp?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/hymath.exp (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/hymath.exp Wed Nov 30 21:29:27 2005
@@ -0,0 +1,17 @@
+HYMATH_0.1 {
+	global :
+		Java_com_ibm_oti_util_FloatingPointParser_parseDblImpl;
+		Java_com_ibm_oti_util_FloatingPointParser_parseFltImpl;
+		Java_com_ibm_oti_util_math_BigInteger_addImpl;
+		Java_com_ibm_oti_util_math_BigInteger_compImpl;
+		Java_com_ibm_oti_util_math_BigInteger_divImpl;
+		Java_com_ibm_oti_util_math_BigInteger_mulImpl;
+		Java_com_ibm_oti_util_math_BigInteger_negImpl;
+		Java_com_ibm_oti_util_math_BigInteger_remImpl;
+		Java_com_ibm_oti_util_math_BigInteger_shlImpl;
+		Java_com_ibm_oti_util_math_BigInteger_subImpl;
+		Java_com_ibm_oti_util_NumberConverter_bigIntDigitGeneratorInstImpl;
+		JNI_OnLoad;
+		JNI_OnUnload;
+	local : *;
+};

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/jclglob.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/jclglob.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/jclglob.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/jclglob.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,30 @@
+/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.
+ */
+
+#if !defined(jclglob_h)
+#define jclglob_h
+#include "jcl.h"
+extern void *Math_JCL_ID_CACHE;
+#define JCL_ID_CACHE Math_JCL_ID_CACHE
+typedef struct MathJniIDCache
+{
+
+  void *dummy;                  /* Placeholder. Some compilers reject empty structs. */
+
+} MathJniIDCache;
+#define JniIDCache MathJniIDCache
+/* Now that the module-specific defines are in place, include the shared file */
+#include "libglob.h"
+#endif /* jclglob_h */

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/makefile
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/makefile?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/makefile (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/makefile Wed Nov 30 21:29:27 2005
@@ -0,0 +1,71 @@
+# Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+# 
+# Licensed 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.
+
+#
+# Makefile for module 'math'
+#
+
+include ../makefile.include
+
+DLLFILENAME=libhymath.so# declaration
+
+DLLNAME=../libhymath.so# declaration
+
+LIBNAME=hymath# declaration
+
+LIBPATH=../lib/# declaration
+
+CFLAGS= -fpic  -DLINUX -D_REENTRANT -O1 -march=pentium3 -DIPv6_FUNCTION_SUPPORT  -DHYX86 -I../include -I../math -I../common -I../zlib -I../zip -I../fdlibm  $(VMDEBUG)
+
+
+.SUFFIXES:.cpp
+.cpp.o:
+	$(CXX)  -fpic  -DLINUX -D_REENTRANT -O1 -march=pentium3 -fno-exceptions -fno-rtti -DIPv6_FUNCTION_SUPPORT  -DHYX86 -I../include -I../math -I../common -I../zlib -I../zip -I../fdlibm  $(VMDEBUG) -c $<
+
+ASFLAGS= -o $@
+
+.SUFFIXES:.asm
+.asm.o:
+	perl ../masm2gas/masm2gas.pl   -I../include -I../math -I../common -I../zlib -I../zip -I../fdlibm $*.asm
+	$(AS) $(ASFLAGS) -o $*.o $*.s
+	-rm $*.s
+
+BUILDFILES1 = math_copyright.o fltparse.o mathglob.o dblparse.o bigint.o
+BUILDFILES2 = cbigint.o
+
+MDLLIBFILES1 = ../lib/libhycommon.a ../libhysig.so ../lib/libhyzip.a ../libhyzlib.so
+MDLLIBFILES2 = ../lib/libhypool.a ../lib/libhyfdlibm.a ../libhythr.so ../libvmi.so
+
+all: \
+	 $(DLLNAME)
+
+BUILDLIB: $(DLLNAME)
+
+$(DLLNAME):\
+	$(BUILDFILES1) $(BUILDFILES2) $(MDLLIBFILES1) $(MDLLIBFILES2) 
+	 $(DLL_LD) -shared -Wl,--version-script,$(LIBNAME).exp -Wl,-soname=$(DLLFILENAME) $(VMLINK) -L.  -L../lib -L.. -o $(DLLNAME) \
+	$(BUILDFILES1) $(BUILDFILES2) -Xlinker --start-group \
+	-lhycommon \
+	-lhysig \
+	-lhyzip \
+	-lhyzlib \
+	-lhycommon \
+	-lhypool \
+	-lhyfdlibm \
+	-lhythr \
+	-lvmi -Xlinker --end-group  -lc -lm -ldl
+
+clean:
+	-rm -f *.o
+	-rm -f ../libhymath.so

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/math_copyright.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/math_copyright.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/math_copyright.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/math_copyright.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,19 @@
+/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.
+ */
+
+/* A copyright string included in each DLL and executable */
+
+const char hyCopyright[] =
+  "(c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable.";

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/mathglob.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/mathglob.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/mathglob.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/math/mathglob.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,118 @@
+/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.
+ */
+
+/* HarmonyDoxygen */
+/**
+ * @file
+ * @ingroup HarmonyNatives
+ * @brief Harmony Math natives initialization API.
+ */
+
+#include <string.h>
+#include "jcl.h"
+#include "jclglob.h"
+
+static UDATA keyInitCount = 0;
+
+void *JCL_ID_CACHE = NULL;
+
+static void freeReferences (JNIEnv * env);
+
+/**
+ * This DLL is being loaded, do any initialization required.
+ * This may be called more than once.
+ */
+jint JNICALL
+JNI_OnLoad (JavaVM * vm, void *reserved)
+{
+  JniIDCache *idCache;
+  JNIEnv *env;
+  void *keyInitCountPtr = GLOBAL_DATA (keyInitCount);
+  void **jclIdCache = GLOBAL_DATA (JCL_ID_CACHE);
+
+  if ((*vm)->GetEnv (vm, (void **) &env, JNI_VERSION_1_2) == JNI_OK)
+    {
+      PORT_ACCESS_FROM_ENV (env);
+
+      if (HY_VMLS_FNTBL (env)->
+          HYVMLSAllocKeys (env, keyInitCountPtr, jclIdCache, NULL))
+        {
+          goto fail;
+        }
+
+      /* This allocate must actually be done by hymem_allocate_memory. */
+      idCache = (JniIDCache *) hymem_allocate_memory (sizeof (JniIDCache));
+      if (!idCache)
+        goto fail2;
+
+      memset (idCache, 0, sizeof (JniIDCache));
+      HY_VMLS_SET (env, *jclIdCache, idCache);
+
+      /* Attach to the common library */
+      if (JNI_OK != ClearLibAttach (env))
+        {
+          goto fail2;
+        }
+
+      return JNI_VERSION_1_2;
+    }
+
+fail2:
+  HY_VMLS_FNTBL (env)->HYVMLSFreeKeys (env, keyInitCountPtr, jclIdCache, NULL);
+fail:
+  return 0;
+}
+
+/**
+ * This DLL is being unloaded, do any clean up required.
+ * This may be called more than once!!
+ */
+void JNICALL
+JNI_OnUnload (JavaVM * vm, void *reserved)
+{
+  JNIEnv *env;
+  void *keyInitCountPtr = GLOBAL_DATA (keyInitCount);
+  void **jclIdCache = GLOBAL_DATA (JCL_ID_CACHE);
+
+  if ((*vm)->GetEnv (vm, (void **) &env, JNI_VERSION_1_2) == JNI_OK)
+    {
+      JniIDCache *idCache = (JniIDCache *) HY_VMLS_GET (env, *jclIdCache);
+
+      if (idCache)
+        {
+          PORT_ACCESS_FROM_ENV (env);
+
+          /* Detach from the common library */
+          ClearLibDetach (env);
+
+          /* Free any global references */
+          freeReferences (env);
+
+          /* Free VMLS keys */
+          idCache = (JniIDCache *) HY_VMLS_GET (env, *jclIdCache);
+          HY_VMLS_FNTBL (env)->HYVMLSFreeKeys (env, keyInitCountPtr,
+                                              jclIdCache, NULL);
+          hymem_free_memory (idCache);
+        }
+    }
+}
+
+/**
+ * @internal
+ */
+static void
+freeReferences (JNIEnv * env)
+{
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/IFileSystem.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/IFileSystem.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/IFileSystem.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/IFileSystem.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,62 @@
+/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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 <jni.h>
+/* Header for class com_ibm_platform_IFileSystem */
+
+#if !defined(_Included_com_ibm_platform_IFileSystem)
+#define _Included_com_ibm_platform_IFileSystem
+#if defined(__cplusplus)
+extern "C"
+{
+#endif
+#undef com_ibm_platform_IFileSystem_SHARED_LOCK_TYPE
+#define com_ibm_platform_IFileSystem_SHARED_LOCK_TYPE 1L
+#undef com_ibm_platform_IFileSystem_EXCLUSIVE_LOCK_TYPE
+#define com_ibm_platform_IFileSystem_EXCLUSIVE_LOCK_TYPE 2L
+#undef com_ibm_platform_IFileSystem_SEEK_SET
+#define com_ibm_platform_IFileSystem_SEEK_SET 1L
+#undef com_ibm_platform_IFileSystem_SEEK_CUR
+#define com_ibm_platform_IFileSystem_SEEK_CUR 2L
+#undef com_ibm_platform_IFileSystem_SEEK_END
+#define com_ibm_platform_IFileSystem_SEEK_END 4L
+#undef com_ibm_platform_IFileSystem_MMAP_READ_ONLY
+#define com_ibm_platform_IFileSystem_MMAP_READ_ONLY 1L
+#undef com_ibm_platform_IFileSystem_MMAP_READ_WRITE
+#define com_ibm_platform_IFileSystem_MMAP_READ_WRITE 2L
+#undef com_ibm_platform_IFileSystem_MMAP_WRITE_COPY
+#define com_ibm_platform_IFileSystem_MMAP_WRITE_COPY 4L
+#undef com_ibm_platform_IFileSystem_O_RDONLY
+#define com_ibm_platform_IFileSystem_O_RDONLY 0L
+#undef com_ibm_platform_IFileSystem_O_WRONLY
+#define com_ibm_platform_IFileSystem_O_WRONLY 1L
+#undef com_ibm_platform_IFileSystem_O_RDWR
+#define com_ibm_platform_IFileSystem_O_RDWR 16L
+#undef com_ibm_platform_IFileSystem_O_APPEND
+#define com_ibm_platform_IFileSystem_O_APPEND 256L
+#undef com_ibm_platform_IFileSystem_O_CREAT
+#define com_ibm_platform_IFileSystem_O_CREAT 4096L
+#undef com_ibm_platform_IFileSystem_O_EXCL
+#define com_ibm_platform_IFileSystem_O_EXCL 65536L
+#undef com_ibm_platform_IFileSystem_O_NOCTTY
+#define com_ibm_platform_IFileSystem_O_NOCTTY 1048576L
+#undef com_ibm_platform_IFileSystem_O_NONBLOCK
+#define com_ibm_platform_IFileSystem_O_NONBLOCK 16777216L
+#undef com_ibm_platform_IFileSystem_O_TRUNC
+#define com_ibm_platform_IFileSystem_O_TRUNC 268435456L
+#if defined(__cplusplus)
+}
+#endif
+#endif

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSFileSystem.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSFileSystem.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSFileSystem.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSFileSystem.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,150 @@
+/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.
+ */
+/*
+ * Common natives supporting the file system interface.
+ */
+
+#include <harmony.h>
+
+#include "OSFileSystem.h"
+#include "IFileSystem.h"
+
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    readDirectImpl
+ * Signature: (JJI)J
+ */
+JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_readDirectImpl
+  (JNIEnv * env, jobject thiz, jlong fd, jlong buf, jint nbytes)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  return (jlong) hyfile_read ((IDATA) fd, (void *) ((IDATA) buf), (IDATA) nbytes);
+}
+
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    writeDirectImpl
+ * Signature: (JJI)J
+ */
+JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_writeDirectImpl
+  (JNIEnv * env, jobject thiz, jlong fd, jlong buf, jint nbytes)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  return (jlong) hyfile_write ((IDATA) fd, (const void *) ((IDATA) buf),
+                               (IDATA) nbytes);
+}
+
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    readImpl
+ * Signature: (J[BII)J
+ */
+JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_readImpl
+  (JNIEnv * env, jobject thiz, jlong fd, jbyteArray byteArray, jint offset,
+   jint nbytes)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  jboolean isCopy;
+  jbyte *bytes = (*env)->GetByteArrayElements (env, byteArray, &isCopy);
+  jlong result;
+
+  result =
+    (jlong) hyfile_read ((IDATA) fd, (void *) (bytes + offset),
+                         (IDATA) nbytes);
+  if (isCopy == JNI_TRUE)
+    {
+      (*env)->ReleaseByteArrayElements (env, byteArray, bytes, 0);
+    }
+
+  return result;
+}
+
+/**
+ * Seeks a file descriptor to a given file position.
+ * 
+ * @param env pointer to Java environment
+ * @param thiz pointer to object receiving the message
+ * @param fd handle of file to be seeked
+ * @param offset distance of movement in bytes relative to whence arg
+ * @param whence enum value indicating from where the offset is relative
+ * The valid values are defined in fsconstants.h.
+ * @return the new file position from the beginning of the file, in bytes;
+ * or -1 if a problem occurs.
+ */
+JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_seekImpl
+  (JNIEnv * env, jobject thiz, jlong fd, jlong offset, jint whence)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  I_32 hywhence = 0;            // The HY PPL equivalent of our whence arg.
+
+  /* Convert whence argument */
+  switch (whence)
+    {
+    case com_ibm_platform_IFileSystem_SEEK_SET:
+      hywhence = HySeekSet;
+      break;
+    case com_ibm_platform_IFileSystem_SEEK_CUR:
+      hywhence = HySeekCur;
+      break;
+    case com_ibm_platform_IFileSystem_SEEK_END:
+      hywhence = HySeekEnd;
+      break;
+    default:
+      return -1;
+    }
+
+  return (jlong) hyfile_seek ((IDATA) fd, (IDATA) offset, hywhence);
+}
+
+/**
+ * Flushes a file state to disk.
+ *
+ * @param env pointer to Java environment
+ * @param thiz pointer to object receiving the message
+ * @param fd handle of file to be flushed
+ * @param metadata if true also flush metadata, otherwise just flush data is possible.
+ * @return zero on success and -1 on failure
+ *
+ * Method:    fflushImpl
+ * Signature: (JZ)I
+ */
+JNIEXPORT jint JNICALL Java_com_ibm_platform_OSFileSystem_fflushImpl
+  (JNIEnv * env, jobject thiz, jlong fd, jboolean metadata)
+{
+  PORT_ACCESS_FROM_ENV (env);
+
+  return (jint) hyfile_sync ((IDATA) fd);
+}
+
+/**
+ * Closes the given file handle
+ * 
+ * @param env pointer to Java environment
+ * @param thiz pointer to object receiving the message
+ * @param fd handle of file to be closed
+ * @return zero on success and -1 on failure
+ *
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    closeImpl
+ * Signature: (J)I
+ */
+JNIEXPORT jint JNICALL Java_com_ibm_platform_OSFileSystem_closeImpl
+  (JNIEnv * env, jobject thiz, jlong fd)
+{
+  PORT_ACCESS_FROM_ENV (env);
+
+  return (jint) hyfile_close ((IDATA) fd);
+}
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSFileSystem.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSFileSystem.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSFileSystem.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSFileSystem.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,91 @@
+/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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 <jni.h>
+/* Header for class com_ibm_platform_OSFileSystem */
+
+#if !defined(_Included_com_ibm_platform_OSFileSystem)
+#define _Included_com_ibm_platform_OSFileSystem
+#if defined(__cplusplus)
+extern "C"
+{
+#endif
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    lockImpl
+ * Signature: (JJJIZ)I
+ */
+  JNIEXPORT jint JNICALL Java_com_ibm_platform_OSFileSystem_lockImpl
+    (JNIEnv *, jobject, jlong, jlong, jlong, jint, jboolean);
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    unlockImpl
+ * Signature: (JJJ)I
+ */
+  JNIEXPORT jint JNICALL Java_com_ibm_platform_OSFileSystem_unlockImpl
+    (JNIEnv *, jobject, jlong, jlong, jlong);
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    fflushImpl
+ * Signature: (JZ)I
+ */
+  JNIEXPORT jint JNICALL Java_com_ibm_platform_OSFileSystem_fflushImpl
+    (JNIEnv *, jobject, jlong, jboolean);
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    seekImpl
+ * Signature: (JJI)J
+ */
+  JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_seekImpl
+    (JNIEnv *, jobject, jlong, jlong, jint);
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    readDirectImpl
+ * Signature: (JJI)J
+ */
+  JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_readDirectImpl
+    (JNIEnv *, jobject, jlong, jlong, jint);
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    writeDirectImpl
+ * Signature: (JJI)J
+ */
+  JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_writeDirectImpl
+    (JNIEnv *, jobject, jlong, jlong, jint);
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    readImpl
+ * Signature: (J[BII)J
+ */
+  JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_readImpl
+    (JNIEnv *, jobject, jlong, jbyteArray, jint, jint);
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    mmapImpl
+ * Signature: (JJJI)J
+ */
+  JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_mmapImpl
+    (JNIEnv *, jobject, jlong, jlong, jlong, jint);
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    closeImpl
+ * Signature: (J)I
+ */
+  JNIEXPORT jint JNICALL Java_com_ibm_platform_OSFileSystem_closeImpl
+    (JNIEnv *, jobject, jlong);
+#if defined(__cplusplus)
+}
+#endif
+#endif

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSFileSystemLinux32.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSFileSystemLinux32.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSFileSystemLinux32.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSFileSystemLinux32.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,123 @@
+/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.
+ */
+
+/*
+ * Linux32 specific natives supporting the file system interface.
+ */
+
+#include <fcntl.h>
+#include <bits/wordsize.h>
+#include <errno.h>
+
+#include <harmony.h>
+
+#include "IFileSystem.h"
+#include "OSFileSystem.h"
+
+/*
+ * Class:     com_ibm_platform_OSFileSystem
+ * Method:    mmapImpl
+ * Signature: (JJJI)J
+ */
+JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSFileSystem_mmapImpl
+  (JNIEnv * env, jobject thiz, jlong fd, jlong offset, jlong size, jint mmode)
+{
+  // TODO: 
+  return (jlong) - 1L;
+}
+
+/**
+ * Lock the file identified by the given handle.
+ * The range and lock type are given.
+ */
+JNIEXPORT jint JNICALL Java_com_ibm_platform_OSFileSystem_lockImpl
+  (JNIEnv * env, jobject thiz, jlong handle, jlong start, jlong length,
+   jint typeFlag, jboolean waitFlag)
+{
+  int rc;
+  int waitMode = (waitFlag) ? F_SETLKW : F_SETLK;
+  struct flock lock = { 0 };
+
+  // If start or length overflow the max values we can represent, then max them out.
+#if __WORDSIZE==32
+#define MAX_INT 0x7fffffffL
+  if (start > MAX_INT)
+    {
+      start = MAX_INT;
+    }
+  if (length > MAX_INT)
+    {
+      length = MAX_INT;
+    }
+#endif
+
+  lock.l_whence = SEEK_SET;
+  lock.l_start = start;
+  lock.l_len = length;
+
+  if ((typeFlag & com_ibm_platform_IFileSystem_SHARED_LOCK_TYPE) ==
+      com_ibm_platform_IFileSystem_SHARED_LOCK_TYPE)
+    {
+      lock.l_type = F_RDLCK;
+    }
+  else
+    {
+      lock.l_type = F_WRLCK;
+    }
+
+  do
+    {
+      rc = fcntl (handle, waitMode, &lock);
+    }
+  while ((rc < 0) && (errno == EINTR));
+
+  return (rc == -1) ? -1 : 0;
+}
+
+/**
+ * Unlocks the specified region of the file.
+ */
+JNIEXPORT jint JNICALL Java_com_ibm_platform_OSFileSystem_unlockImpl
+  (JNIEnv * env, jobject thiz, jlong handle, jlong start, jlong length)
+{
+  int rc;
+  struct flock lock = { 0 };
+
+  // If start or length overflow the max values we can represent, then max them out.
+#if __WORDSIZE==32
+#define MAX_INT 0x7fffffffL
+  if (start > MAX_INT)
+    {
+      start = MAX_INT;
+    }
+  if (length > MAX_INT)
+    {
+      length = MAX_INT;
+    }
+#endif
+
+  lock.l_whence = SEEK_SET;
+  lock.l_start = start;
+  lock.l_len = length;
+  lock.l_type = F_UNLCK;
+
+  do
+    {
+      rc = fcntl (handle, F_SETLKW, &lock);
+    }
+  while ((rc < 0) && (errno == EINTR));
+
+  return (rc == -1) ? -1 : 0;
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSMemory.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSMemory.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSMemory.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSMemory.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,161 @@
+/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.
+ */
+
+/*
+ * Common natives supporting the memory system interface.
+ */
+
+#include <string.h>
+#include <harmony.h>
+#include "OSMemory.h"
+
+JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSMemory_malloc
+  (JNIEnv * env, jobject thiz, jlong size)
+{
+  PORT_ACCESS_FROM_ENV (env);
+
+  jclass exceptionClazz;
+  void *address = hymem_allocate_memory ((UDATA) size);
+
+  if (address == NULL)
+    {
+      exceptionClazz = (*env)->FindClass (env, "java/lang/OutOfMemoryError");
+      (*env)->ThrowNew (env, exceptionClazz,
+			"Insufficient memory available.");
+    }
+
+  return (jlong) ((IDATA) address);
+}
+
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_free
+  (JNIEnv * env, jobject thiz, jlong address)
+{
+  PORT_ACCESS_FROM_ENV (env);
+
+  hymem_free_memory ((void *) ((IDATA) address));
+}
+
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_memmove
+  (JNIEnv * env, jobject thiz, jlong destAddress, jlong srcAddress,
+   jlong length)
+{
+  memmove ((void *) ((IDATA) destAddress),
+	   (const void *) ((IDATA) srcAddress), (size_t) length);
+}
+
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_memset
+  (JNIEnv * env, jobject thiz, jlong address, jbyte value, jlong length)
+{
+  memset ((void *) ((IDATA) address), (int) value, (size_t) length);
+}
+
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_getByteArray
+  (JNIEnv * env, jobject thiz, jlong address, jbyteArray byteArray,
+   jint offset, jint length)
+{
+  jboolean isCopy;
+  jbyte *bytes = (*env)->GetByteArrayElements (env, byteArray, &isCopy);
+  memcpy (bytes + offset, (const void *) ((IDATA) address), (size_t) length);
+  if (isCopy == JNI_TRUE)
+    {
+      (*env)->ReleaseByteArrayElements (env, byteArray, bytes, 0);
+    }
+}
+
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setByteArray
+  (JNIEnv * env, jobject thiz, jlong address, jbyteArray byteArray,
+   jint offset, jint length)
+{
+  jboolean isCopy;
+  jbyte *bytes = (*env)->GetByteArrayElements (env, byteArray, &isCopy);
+  memcpy ((void *) ((IDATA) address),
+	  (const jbyte *) ((IDATA) bytes + offset), (size_t) length);
+  if (isCopy == JNI_TRUE)
+    {
+      (*env)->ReleaseByteArrayElements (env, byteArray, bytes, JNI_ABORT);
+    }
+}
+
+JNIEXPORT jbyte JNICALL Java_com_ibm_platform_OSMemory_getByte
+  (JNIEnv * env, jobject thiz, jlong address)
+{
+  return *(jbyte *) ((IDATA) address);
+}
+
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setByte
+  (JNIEnv * env, jobject thiz, jlong address, jbyte value)
+{
+  *(jbyte *) ((IDATA) address) = value;
+}
+
+JNIEXPORT jshort JNICALL Java_com_ibm_platform_OSMemory_getShort
+  (JNIEnv * env, jobject thiz, jlong address)
+{
+  return *(jshort *) ((IDATA) address);
+}
+
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setShort
+  (JNIEnv * env, jobject thiz, jlong address, jshort value)
+{
+  *(jshort *) ((IDATA) address) = value;
+}
+
+JNIEXPORT jint JNICALL Java_com_ibm_platform_OSMemory_getInt
+  (JNIEnv * env, jobject thiz, jlong address)
+{
+  return *(jint *) ((IDATA) address);
+}
+
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setInt
+  (JNIEnv * env, jobject thiz, jlong address, jint value)
+{
+  *(jint *) ((IDATA) address) = value;
+}
+
+JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSMemory_getLong
+  (JNIEnv * env, jobject thiz, jlong address)
+{
+  return *(jlong *) ((IDATA) address);
+}
+
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setLong
+  (JNIEnv * env, jobject thiz, jlong address, jlong value)
+{
+  *(jlong *) ((IDATA) address) = value;
+}
+
+JNIEXPORT jfloat JNICALL Java_com_ibm_platform_OSMemory_getFloat
+  (JNIEnv * env, jobject thiz, jlong address)
+{
+  return *(jfloat *) ((IDATA) address);
+}
+
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setFloat
+  (JNIEnv * env, jobject thiz, jlong address, jfloat value)
+{
+  *(jfloat *) ((IDATA) address) = value;
+}
+
+JNIEXPORT jdouble JNICALL Java_com_ibm_platform_OSMemory_getDouble
+  (JNIEnv * env, jobject thiz, jlong address)
+{
+  return *(jdouble *) ((IDATA) address);
+}
+
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setDouble
+  (JNIEnv * env, jobject thiz, jlong address, jdouble value)
+{
+  *(jdouble *) ((IDATA) address) = value;
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSMemory.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSMemory.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSMemory.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSMemory.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,185 @@
+/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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 <jni.h>
+/* Header for class com_ibm_platform_OSMemory */
+
+#if !defined(_Included_com_ibm_platform_OSMemory)
+#define _Included_com_ibm_platform_OSMemory
+#if defined(__cplusplus)
+extern "C"
+{
+#endif
+/* Inaccessible static: POINTER_SIZE */
+/* Inaccessible static: NATIVE_ORDER */
+/* Inaccessible static: singleton */
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    isLittleEndianImpl
+ * Signature: ()Z
+ */
+  JNIEXPORT jboolean JNICALL Java_com_ibm_platform_OSMemory_isLittleEndianImpl
+    (JNIEnv *, jclass);
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    getPointerSizeImpl
+ * Signature: ()I
+ */
+  JNIEXPORT jint JNICALL Java_com_ibm_platform_OSMemory_getPointerSizeImpl
+    (JNIEnv *, jclass);
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    malloc
+ * Signature: (J)J
+ */
+  JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSMemory_malloc
+    (JNIEnv *, jobject, jlong);
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    free
+ * Signature: (J)V
+ */
+  JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_free
+    (JNIEnv *, jobject, jlong);
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    memset
+ * Signature: (JBJ)V
+ */
+  JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_memset
+    (JNIEnv *, jobject, jlong, jbyte, jlong);
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    memmove
+ * Signature: (JJJ)V
+ */
+  JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_memmove
+    (JNIEnv *, jobject, jlong, jlong, jlong);
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    getByteArray
+ * Signature: (J[BII)V
+ */
+  JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_getByteArray
+    (JNIEnv *, jobject, jlong, jbyteArray, jint, jint);
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    setByteArray
+ * Signature: (J[BII)V
+ */
+  JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setByteArray
+    (JNIEnv *, jobject, jlong, jbyteArray, jint, jint);
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    getByte
+ * Signature: (J)B
+ */
+  JNIEXPORT jbyte JNICALL Java_com_ibm_platform_OSMemory_getByte
+    (JNIEnv *, jobject, jlong);
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    setByte
+ * Signature: (JB)V
+ */
+  JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setByte
+    (JNIEnv *, jobject, jlong, jbyte);
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    getShort
+ * Signature: (J)S
+ */
+  JNIEXPORT jshort JNICALL Java_com_ibm_platform_OSMemory_getShort
+    (JNIEnv *, jobject, jlong);
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    setShort
+ * Signature: (JS)V
+ */
+  JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setShort
+    (JNIEnv *, jobject, jlong, jshort);
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    getInt
+ * Signature: (J)I
+ */
+  JNIEXPORT jint JNICALL Java_com_ibm_platform_OSMemory_getInt
+    (JNIEnv *, jobject, jlong);
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    setInt
+ * Signature: (JI)V
+ */
+  JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setInt
+    (JNIEnv *, jobject, jlong, jint);
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    getLong
+ * Signature: (J)J
+ */
+  JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSMemory_getLong
+    (JNIEnv *, jobject, jlong);
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    setLong
+ * Signature: (JJ)V
+ */
+  JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setLong
+    (JNIEnv *, jobject, jlong, jlong);
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    getFloat
+ * Signature: (J)F
+ */
+  JNIEXPORT jfloat JNICALL Java_com_ibm_platform_OSMemory_getFloat
+    (JNIEnv *, jobject, jlong);
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    setFloat
+ * Signature: (JF)V
+ */
+  JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setFloat
+    (JNIEnv *, jobject, jlong, jfloat);
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    getDouble
+ * Signature: (J)D
+ */
+  JNIEXPORT jdouble JNICALL Java_com_ibm_platform_OSMemory_getDouble
+    (JNIEnv *, jobject, jlong);
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    setDouble
+ * Signature: (JD)V
+ */
+  JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setDouble
+    (JNIEnv *, jobject, jlong, jdouble);
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    getAddress
+ * Signature: (J)J
+ */
+  JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSMemory_getAddress
+    (JNIEnv *, jobject, jlong);
+/*
+ * Class:     com_ibm_platform_OSMemory
+ * Method:    setAddress
+ * Signature: (JJ)V
+ */
+  JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setAddress
+    (JNIEnv *, jobject, jlong, jlong);
+#if defined(__cplusplus)
+}
+#endif
+#endif

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSMemoryLinux32.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSMemoryLinux32.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSMemoryLinux32.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/nio/OSMemoryLinux32.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,46 @@
+/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.
+ */
+
+/*
+ * Common natives supporting the memory system interface.
+ */
+
+#include <string.h>
+#include <harmony.h>
+#include "OSMemory.h"
+
+#define	OS_JNI(func) JNICALL Java_com_ibm_platform_OSMemory_##func
+
+JNIEXPORT jboolean OS_JNI (isLittleEndianImpl) (JNIEnv * env, jclass clazz)
+{
+  return JNI_TRUE;
+}
+
+JNIEXPORT jint OS_JNI (getPointerSizeImpl) (JNIEnv * env, jclass clazz)
+{
+  return 4;
+}
+
+JNIEXPORT jlong OS_JNI (getAddress)
+  (JNIEnv * env, jobject thiz, jlong address)
+{
+  return (jlong) * (long *) ((IDATA) address);
+}
+
+JNIEXPORT void OS_JNI (setAddress)
+  (JNIEnv * env, jobject thiz, jlong address, jlong value)
+{
+  *(long *) ((IDATA) address) = (long) value;
+}