harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r350181 [184/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....
Date Thu, 01 Dec 2005 06:04:00 GMT
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/dblparse.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/dblparse.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/dblparse.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/dblparse.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,859 @@
+/* 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
+
+/* We are building for a desktop version, let the DEFAULT_WIDTH to
+ * be the MAX_ACCURACY_WIDTH to prevent unnecessary memory allocation
+ * calls.
+ */
+#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 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
+   * 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 to much rounding).
+	   * Double.toString() precision
+	   *      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/win.IA32/math/fltparse.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/fltparse.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/fltparse.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.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
+
+/* We are building for a desktop version, let the DEFAULT_WIDTH
+ * be the MAX_ACCURACY_WIDTH to prevent unnecessary memory allocation
+ * calls.
+ */
+#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/win.IA32/math/hymath.def
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/hymath.def?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/hymath.def (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/hymath.def Wed Nov 30 21:29:27 2005
@@ -0,0 +1,20 @@
+LIBRARY	HYMATH
+
+SECTIONS
+	.data	READ WRITE
+	.text	EXECUTE READ
+
+EXPORTS
+	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

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/hymath.rc
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/hymath.rc?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/hymath.rc (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/hymath.rc Wed Nov 30 21:29:27 2005
@@ -0,0 +1,47 @@
+;
+; 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 <windows.h>
+#include <winver.h>
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION 0,1,0,0
+ PRODUCTVERSION 0,1,0,0
+ FILEFLAGSMASK 0x3fL
+ FILEFLAGS 0x0L
+ FILEOS VOS_NT_WINDOWS32
+ FILETYPE VFT_DLL
+ FILESUBTYPE 0x0L
+BEGIN
+	BLOCK "StringFileInfo"
+	BEGIN
+		BLOCK "040904b0"
+		BEGIN
+			VALUE "CompanyName", "The Apache Software Foundation.\0"
+			VALUE "FileDescription", "Math native code\0"
+			VALUE "FileVersion", "0.1\0"
+			VALUE "InternalName", "math\0"
+			VALUE "LegalCopyright", "(c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable.\0"
+			VALUE "OriginalFilename", "hymath.dll\0"
+			VALUE "ProductName", "Apache Harmony\0"
+			VALUE "ProductVersion", "0.1\0"
+		END
+	END
+	BLOCK "VarFileInfo"
+	BEGIN
+		VALUE "Translation", 0x0409, 1200
+	END
+END

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/jcl.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/jcl.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/jcl.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/jcl.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,22 @@
+/* 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(jcl_h)
+#define jcl_h
+
+#define USING_VMI
+#include "vmi.h"
+
+#endif /* jcl_h */

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/jclglob.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/jclglob.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/jclglob.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/jclglob.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,35 @@
+/* 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/win.IA32/math/makefile
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/makefile?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/makefile (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/makefile Wed Nov 30 21:29:27 2005
@@ -0,0 +1,84 @@
+# 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'
+#
+
+APPVER=4.0
+TARGETOS=WIN95
+_WIN32_IE=0x0500
+SEHMAP = TRUE
+!include <win32.mak>
+
+DLLFILENAME=hymath.dll# declaration
+
+DLLNAME=..\hymath.dll# declaration
+
+LIBNAME=hymath# declaration
+
+LIBPATH=..\lib\# declaration
+
+.c.obj:
+	$(cc) -DWINVER=0x0400 -D_WIN32_WINNT=0x0400 $(cflags) -D_MT -D_DLL -MD -D_WINSOCKAPI_ -DWIN32 -Ogityb1 -Gs -GF -Zm400 -WX -Zi  /I..\include /I..\math /I..\common /I..\zlib /I..\zip /I..\fdlibm  $(VMDEBUG) $*.c
+
+.cpp.obj:
+	$(cc) -DWINVER=0x0400 -D_WIN32_WINNT=0x0400 $(cflags) -D_MT -D_DLL -MD -D_WINSOCKAPI_ -DWIN32 -Ogityb1 -Gs -GF -Zm400 -WX -Zi  /I..\include /I..\math /I..\common /I..\zlib /I..\zip /I..\fdlibm  $(VMDEBUG) $*.cpp
+
+.asm.obj:
+	ml /c /Cp /W3 /nologo /coff /Zm /Zd /Zi /Gd  $(VMASMDEBUG) -DWIN32  $<
+
+.rc.res:
+	rc -I..\include $<
+
+BUILDFILES1 = math_copyright.obj fltparse.obj mathglob.obj dblparse.obj bigint.obj
+BUILDFILES2 = cbigint.obj
+
+VIRTFILES1 = hymath.res
+
+SYSLIBFILES1 = ws2_32.lib Iphlpapi.lib
+
+MDLLIBFILES1 = ..\lib\hycommon.lib ..\lib\hysig.lib
+MDLLIBFILES2 = ..\lib\hypool.lib ..\lib\hyfdlibm.lib ..\lib\hythr.lib ..\lib\vmi.lib
+
+all: \
+	 ..\lib\$(LIBNAME).lib $(DLLNAME)
+
+BUILDLIB: $(LIBPATH)$(LIBNAME).lib
+
+$(LIBPATH)$(LIBNAME).lib:\
+	$(BUILDFILES1) $(BUILDFILES2) $(VIRTFILES1) $(MDLLIBFILES1) $(MDLLIBFILES2) 
+	$(implib) /NOLOGO -subsystem:windows -out:$(LIBPATH)$(LIBNAME).lib -def:$(LIBNAME).def -machine:$(CPU) \
+	$(BUILDFILES1) $(BUILDFILES2) $(VIRTFILES1) $(MDLLIBFILES1) $(MDLLIBFILES2) 
+
+
+$(DLLNAME): $(LIBPATH)$(LIBNAME).lib \
+	$(BUILDFILES1) $(BUILDFILES2) $(VIRTFILES1) $(MDLLIBFILES1) $(MDLLIBFILES2) 
+	link $(VMLINK) /debug /opt:icf /opt:ref /INCREMENTAL:NO /NOLOGO -entry:_DllMainCRTStartup@12 -dll /BASE:0x13300000 -machine:$(CPU) \
+	/comment:"Math component native code. (c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable." \
+	-subsystem:windows -out:$(DLLNAME) -map:$(LIBNAME).map  \
+	$(BUILDFILES1) $(BUILDFILES2) $(VIRTFILES1) $(MDLLIBFILES1) $(MDLLIBFILES2) \
+	$(SYSLIBFILES1)  \
+	kernel32.lib  ws2_32.lib advapi32.lib user32.lib gdi32.lib comdlg32.lib winspool.lib  $(LIBPATH)$(LIBNAME).exp
+
+clean:
+	-del *.map
+	-del *.obj
+	-del *.res
+	-del *.pdb
+	-del ..\lib\$(LIBNAME).lib
+	-del ..\lib\$(LIBNAME).exp
+	-del ..\$(LIBNAME).pdb
+	-del $(DLLNAME)
+	

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/math_copyright.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/math_copyright.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/math_copyright.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.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/win.IA32/math/mathglob.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/mathglob.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/mathglob.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/math/mathglob.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,117 @@
+/* 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.
+ */
+
+/**
+ * @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;
+	}
+
+      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)
+{
+/* empty */
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/nio/IFileSystem.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/nio/IFileSystem.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/nio/IFileSystem.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/nio/IFileSystem.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,63 @@
+/* Copyright 2004 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.
+ */
+
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#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/win.IA32/nio/OSFileSystem.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/nio/OSFileSystem.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/nio/OSFileSystem.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/nio/OSFileSystem.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,151 @@
+/* Copyright 2004 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 *) 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 *) 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;
+
+  /* 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/win.IA32/nio/OSFileSystem.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/nio/OSFileSystem.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/nio/OSFileSystem.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/nio/OSFileSystem.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,92 @@
+/* Copyright 2004 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.
+ */
+
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#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/win.IA32/nio/OSFileSystemWin32.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/nio/OSFileSystemWin32.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/nio/OSFileSystemWin32.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/nio/OSFileSystemWin32.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,167 @@
+/* Copyright 2004 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.
+ */
+
+/*
+ * Win32 specific natives supporting the file system interface.
+ */
+
+#include <windows.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)
+{
+
+  DWORD flProtect = 0;
+  DWORD dwDesiredAccess = 0;    /* Access control for mapping view. */
+  HANDLE hFileMappingObject = 0;
+  LPVOID mapAddress = 0;
+  DWORD dwFileOffsetLow = (DWORD) (offset & 0xFFFFFFFF);
+  DWORD dwFileOffsetHigh = (DWORD) ((offset >> 0x20) & 0x7FFFFFFF);
+
+  // Convert from Java mapping mode to windows mapping mode.
+  switch (mmode)
+    {
+      case com_ibm_platform_IFileSystem_MMAP_READ_ONLY:
+        flProtect = PAGE_READONLY;
+        dwDesiredAccess = FILE_MAP_READ;
+        break;
+      case com_ibm_platform_IFileSystem_MMAP_READ_WRITE:
+        flProtect = PAGE_READWRITE;
+        dwDesiredAccess = FILE_MAP_WRITE;
+        break;
+      case com_ibm_platform_IFileSystem_MMAP_WRITE_COPY:
+        flProtect = PAGE_WRITECOPY;
+        dwDesiredAccess = FILE_MAP_COPY;
+        break;
+      default:
+        return -1;
+    }
+
+  /* First create a file mapping handle. */
+  hFileMappingObject = CreateFileMapping ((HANDLE) fd,  /* [in] file handle */
+                                          (LPSECURITY_ATTRIBUTES) NULL, /* [in] mapping is not inherited */
+                                          flProtect,    /* [in] protection mode for mapped data */
+                                          (DWORD) 0,    /* [in] maximum size high */
+                                          (DWORD) 0,    /* [in] maximum size low */
+                                          (LPCTSTR) NULL);      /* [in] name for mapping object */
+
+  if (!hFileMappingObject || hFileMappingObject == INVALID_HANDLE_VALUE)
+    {
+      return -1;
+    }
+
+  /* Secondly create a view on that mapping object. */
+
+  mapAddress = MapViewOfFile (hFileMappingObject,       /* [in] open file mapping object */
+                              dwDesiredAccess,  /* [in] access to the file view */
+                              dwFileOffsetHigh, /* [in] high offset where mapping is to begin */
+                              dwFileOffsetLow,  /* [in] low offset where mapping is to begin */
+                              (SIZE_T) size);   /* [in] number of bytes to map */
+
+  if (mapAddress == NULL)
+    {
+      return -1;
+    }
+
+  return (jlong) mapAddress;
+}
+
+/**
+ * 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)
+{
+  DWORD dwFlags = 0;
+  OVERLAPPED overlapped;
+  BOOL rc;
+  const DWORD offsetLow = (DWORD) (start & 0xFFFFFFFF);
+  const DWORD offsetHigh = (DWORD) ((start >> 0x20) & 0x7FFFFFFF);
+  const DWORD nNumberOfBytesToLockLow = (DWORD) (length & 0xFFFFFFFF);
+  const DWORD nNumberOfBytesToLockHigh =
+    (DWORD) ((length >> 0x20) & 0x7FFFFFFF);
+
+  if (waitFlag == JNI_FALSE)
+    {
+      dwFlags |= LOCKFILE_FAIL_IMMEDIATELY;
+    }
+
+  if (typeFlag & com_ibm_platform_IFileSystem_EXCLUSIVE_LOCK_TYPE)
+    {
+      dwFlags |= LOCKFILE_EXCLUSIVE_LOCK;
+    }
+
+  memset (&overlapped, 0, sizeof (overlapped));
+  overlapped.Offset = offsetLow;
+  overlapped.OffsetHigh = offsetHigh;
+
+  rc = LockFileEx ((HANDLE) handle,     /* [in] file handle to lock */
+                   dwFlags,     /* [in] flags describing lock type */
+                   (DWORD) 0,   /* [in] reserved */
+                   nNumberOfBytesToLockLow,     /* [in] number of bytes to lock (low) */
+                   nNumberOfBytesToLockHigh,    /* [in] number of bytes to lock (high) */
+                   (LPOVERLAPPED) & overlapped);        /* [in] contains file offset to lock start */
+
+  if (rc != 0)
+    {
+      // Success
+      return (jint) 0;
+    }
+  return (jint) - 1;
+}
+
+/**
+ * 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)
+{
+  OVERLAPPED overlapped;
+  BOOL rc;
+  const DWORD offsetLow = (DWORD) (start & 0xFFFFFFFF);
+  const DWORD offsetHigh = (DWORD) ((start >> 0x20) & 0x7FFFFFFF);
+  const DWORD nNumberOfBytesToUnlockLow = (DWORD) (length & 0xFFFFFFFF);
+  const DWORD nNumberOfBytesToUnlockHigh =
+    (DWORD) ((length >> 0x20) & 0x7FFFFFFF);
+
+  memset (&overlapped, 0, sizeof (overlapped));
+  overlapped.Offset = offsetLow;
+  overlapped.OffsetHigh = offsetHigh;
+
+  rc = UnlockFileEx ((HANDLE) handle,   /* [in] file handle to lock */
+                     (DWORD) 0, /* [in] reserved */
+                     nNumberOfBytesToUnlockLow, /* [in] number of bytes to lock (low) */
+                     nNumberOfBytesToUnlockHigh,        /* [in] number of bytes to lock (high) */
+                     (LPOVERLAPPED) & overlapped);      /* [in] contains file offset to lock start */
+
+  if (rc != 0)
+    {
+      // Success
+      return (jint) 0;
+    }
+  return (jint) - 1;
+}
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/nio/OSMemory.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/nio/OSMemory.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/nio/OSMemory.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/nio/OSMemory.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,160 @@
+/* Copyright 2004 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) 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 *) address);
+}
+
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_memmove
+  (JNIEnv * env, jobject thiz, jlong destAddress, jlong srcAddress,
+   jlong length)
+{
+  memmove ((void *) destAddress, (const void *) 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 *) 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 *) 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 *) address, (const jbyte *) 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 *) address;
+}
+
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setByte
+  (JNIEnv * env, jobject thiz, jlong address, jbyte value)
+{
+  *(jbyte *) address = value;
+}
+
+JNIEXPORT jshort JNICALL Java_com_ibm_platform_OSMemory_getShort
+  (JNIEnv * env, jobject thiz, jlong address)
+{
+  return *(jshort *) address;
+}
+
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setShort
+  (JNIEnv * env, jobject thiz, jlong address, jshort value)
+{
+  *(jshort *) address = value;
+}
+
+JNIEXPORT jint JNICALL Java_com_ibm_platform_OSMemory_getInt
+  (JNIEnv * env, jobject thiz, jlong address)
+{
+  return *(jint *) address;
+}
+
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setInt
+  (JNIEnv * env, jobject thiz, jlong address, jint value)
+{
+  *(jint *) address = value;
+}
+
+JNIEXPORT jlong JNICALL Java_com_ibm_platform_OSMemory_getLong
+  (JNIEnv * env, jobject thiz, jlong address)
+{
+  return *(jlong *) address;
+}
+
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setLong
+  (JNIEnv * env, jobject thiz, jlong address, jlong value)
+{
+  *(jlong *) address = value;
+}
+
+JNIEXPORT jfloat JNICALL Java_com_ibm_platform_OSMemory_getFloat
+  (JNIEnv * env, jobject thiz, jlong address)
+{
+  return *(jfloat *) address;
+}
+
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setFloat
+  (JNIEnv * env, jobject thiz, jlong address, jfloat value)
+{
+  *(jfloat *) address = value;
+}
+
+JNIEXPORT jdouble JNICALL Java_com_ibm_platform_OSMemory_getDouble
+  (JNIEnv * env, jobject thiz, jlong address)
+{
+  return *(jdouble *) address;
+}
+
+JNIEXPORT void JNICALL Java_com_ibm_platform_OSMemory_setDouble
+  (JNIEnv * env, jobject thiz, jlong address, jdouble value)
+{
+  *(jdouble *) address = value;
+}
+

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/nio/OSMemory.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/nio/OSMemory.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/nio/OSMemory.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/nio/OSMemory.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,186 @@
+/* Copyright 2004 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.
+ */
+
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#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



Mime
View raw message