Index: include/Makefile.am =================================================================== RCS file: /cvsroot/classpath/classpath/include/Makefile.am,v retrieving revision 1.40 diff -u -r1.40 Makefile.am --- include/Makefile.am 11 Apr 2005 18:58:38 -0000 1.40 +++ include/Makefile.am 16 Apr 2005 09:17:56 -0000 @@ -75,9 +75,7 @@ $(top_srcdir)/include/java_io_ObjectInputStream.h \ $(top_srcdir)/include/java_io_VMFile.h \ $(top_srcdir)/include/java_io_VMObjectStreamClass.h \ -$(top_srcdir)/include/java_lang_Double.h \ $(top_srcdir)/include/java_lang_Math.h \ -$(top_srcdir)/include/java_lang_Object.h \ $(top_srcdir)/include/java_lang_VMDouble.h \ $(top_srcdir)/include/java_lang_VMFloat.h \ $(top_srcdir)/include/java_lang_VMProcess.h \ @@ -119,12 +117,8 @@ $(JAVAH) -o $@ java.io.VMFile $(top_srcdir)/include/java_io_VMObjectStreamClass.h: $(top_srcdir)/vm/reference/java/io/VMObjectStreamClass.java $(JAVAH) -o $@ java.io.VMObjectStreamClass -$(top_srcdir)/include/java_lang_Double.h: $(top_srcdir)/java/lang/Double.java - $(JAVAH) -o $@ java.lang.Double $(top_srcdir)/include/java_lang_Math.h: $(top_srcdir)/java/lang/Math.java $(JAVAH) -o $@ java.lang.Math -$(top_srcdir)/include/java_lang_Object.h: $(top_srcdir)/java/lang/Object.java - $(JAVAH) -o $@ java.lang.Object $(top_srcdir)/include/java_lang_VMDouble.h: $(top_srcdir)/vm/reference/java/lang/VMDouble.java $(JAVAH) -o $@ java.lang.VMDouble $(top_srcdir)/include/java_lang_VMFloat.h: $(top_srcdir)/vm/reference/java/lang/VMFloat.java Index: include/java_lang_Double.h =================================================================== RCS file: include/java_lang_Double.h diff -N include/java_lang_Double.h --- include/java_lang_Double.h 23 Dec 2004 14:15:45 -0000 1.6 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,33 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ - -#ifndef __java_lang_Double__ -#define __java_lang_Double__ - -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -JNIEXPORT jdouble JNICALL Java_java_lang_Double_parseDouble (JNIEnv *env, jclass, jstring); -JNIEXPORT jstring JNICALL Java_java_lang_Double_toString (JNIEnv *env, jclass, jdouble, jboolean); -JNIEXPORT void JNICALL Java_java_lang_Double_initIDs (JNIEnv *env, jclass); -#undef java_lang_Double_serialVersionUID -#define java_lang_Double_serialVersionUID -9172774392245257468LL -#undef java_lang_Double_MAX_VALUE -#define java_lang_Double_MAX_VALUE 0x1.fffffffffffffp+1023 -#undef java_lang_Double_MIN_VALUE -#define java_lang_Double_MIN_VALUE 0x0.0000000000001p-1022 -#undef java_lang_Double_NEGATIVE_INFINITY -#define java_lang_Double_NEGATIVE_INFINITY -#undef java_lang_Double_POSITIVE_INFINITY -#define java_lang_Double_POSITIVE_INFINITY -#undef java_lang_Double_NaN -#define java_lang_Double_NaN - -#ifdef __cplusplus -} -#endif - -#endif /* __java_lang_Double__ */ Index: include/java_lang_Object.h =================================================================== RCS file: include/java_lang_Object.h diff -N include/java_lang_Object.h --- include/java_lang_Object.h 28 May 2004 17:27:54 -0000 1.3 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,19 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ - -#ifndef __java_lang_Object__ -#define __java_lang_Object__ - -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -JNIEXPORT jclass JNICALL Java_java_lang_Object_getClass (JNIEnv *env, jobject); - -#ifdef __cplusplus -} -#endif - -#endif /* __java_lang_Object__ */ Index: include/java_lang_VMDouble.h =================================================================== RCS file: /cvsroot/classpath/classpath/include/java_lang_VMDouble.h,v retrieving revision 1.2 diff -u -r1.2 java_lang_VMDouble.h --- include/java_lang_VMDouble.h 28 May 2004 17:27:55 -0000 1.2 +++ include/java_lang_VMDouble.h 16 Apr 2005 09:17:56 -0000 @@ -13,6 +13,9 @@ JNIEXPORT jlong JNICALL Java_java_lang_VMDouble_doubleToLongBits (JNIEnv *env, jclass, jdouble); JNIEXPORT jlong JNICALL Java_java_lang_VMDouble_doubleToRawLongBits (JNIEnv *env, jclass, jdouble); JNIEXPORT jdouble JNICALL Java_java_lang_VMDouble_longBitsToDouble (JNIEnv *env, jclass, jlong); +JNIEXPORT jstring JNICALL Java_java_lang_VMDouble_toString (JNIEnv *env, jclass, jdouble, jboolean); +JNIEXPORT void JNICALL Java_java_lang_VMDouble_initIDs (JNIEnv *env, jclass); +JNIEXPORT jdouble JNICALL Java_java_lang_VMDouble_parseDouble (JNIEnv *env, jclass, jstring); #ifdef __cplusplus } Index: java/lang/Double.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/lang/Double.java,v retrieving revision 1.35 diff -u -r1.35 Double.java --- java/lang/Double.java 16 Feb 2005 11:18:37 -0000 1.35 +++ java/lang/Double.java 16 Apr 2005 09:17:57 -0000 @@ -103,18 +103,6 @@ private final double value; /** - * Load native routines necessary for this class. - */ - static - { - if (Configuration.INIT_LOAD_LIBRARY) - { - System.loadLibrary("javalang"); - initIDs(); - } - } - - /** * Create a Double from the primitive double * specified. * @@ -176,7 +164,7 @@ */ public static String toString(double d) { - return toString(d, false); + return VMDouble.toString(d, false); } /** @@ -243,7 +231,10 @@ * @see #NEGATIVE_INFINITY * @since 1.2 */ - public static native double parseDouble(String str); + public static double parseDouble(String str) + { + return VMDouble.parseDouble(str); + } /** * Return true if the double has the same @@ -527,20 +518,4 @@ return x > y ? 1 : -1; } - - /** - * Helper method to convert to string. - * - * @param d the double to convert - * @param isFloat true if the conversion is requested by Float (results in - * fewer digits) - */ - // Package visible for use by Float. - static native String toString(double d, boolean isFloat); - - /** - * Initialize JNI cache. This method is called only by the - * static initializer when using JNI. - */ - private static native void initIDs(); } Index: java/lang/Float.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/lang/Float.java,v retrieving revision 1.29 diff -u -r1.29 Float.java --- java/lang/Float.java 16 Feb 2005 11:18:37 -0000 1.29 +++ java/lang/Float.java 16 Apr 2005 09:17:57 -0000 @@ -173,7 +173,7 @@ */ public static String toString(float f) { - return Double.toString(f, true); + return VMDouble.toString(f, true); } /** Index: java/lang/Object.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/lang/Object.java,v retrieving revision 1.20 diff -u -r1.20 Object.java --- java/lang/Object.java 15 Oct 2004 07:44:17 -0000 1.20 +++ java/lang/Object.java 16 Apr 2005 09:17:57 -0000 @@ -1,5 +1,5 @@ /* java.lang.Object - The universal superclass in Java - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004 + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -326,7 +326,10 @@ * * @return the class of this Object */ - public final native Class getClass(); + public final Class getClass() + { + return VMObject.getClass(this); + } /** * Wakes up one of the address@hidden Thread}s that has called Index: native/jni/java-lang/Makefile.am =================================================================== RCS file: /cvsroot/classpath/classpath/native/jni/java-lang/Makefile.am,v retrieving revision 1.10 diff -u -r1.10 Makefile.am --- native/jni/java-lang/Makefile.am 26 Oct 2004 20:26:03 -0000 1.10 +++ native/jni/java-lang/Makefile.am 16 Apr 2005 09:17:57 -0000 @@ -1,9 +1,7 @@ pkglib_LTLIBRARIES = libjavalang.la libjavalangreflect.la libjavalang_la_SOURCES = java_lang_VMSystem.c \ - java_lang_Object.c \ java_lang_VMFloat.c \ - java_lang_Double.c \ java_lang_VMDouble.c \ java_lang_Math.c \ java_lang_VMProcess.c Index: native/jni/java-lang/java_lang_Double.c =================================================================== RCS file: native/jni/java-lang/java_lang_Double.c diff -N native/jni/java-lang/java_lang_Double.c --- native/jni/java-lang/java_lang_Double.c 9 Apr 2005 17:37:42 -0000 1.18 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,321 +0,0 @@ -/* Double.c - java.lang.Double native functions - Copyright (C) 1998, 1999, 2001, 2003, 2004 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include -#include -#include -#include - -#include "mprec.h" -#include "fdlibm.h" -#include "jcl.h" - -#include "java_lang_Double.h" - -static jmethodID isNaNID; -static jdouble NEGATIVE_INFINITY; -static jdouble POSITIVE_INFINITY; -static jdouble NaN; - -/* - * Class: java_lang_Double - * Method: initIDs - * Signature: ()V - */ -JNIEXPORT void JNICALL -Java_java_lang_Double_initIDs (JNIEnv * env, jclass cls) -{ - jfieldID negInfID; - jfieldID posInfID; - jfieldID nanID; - - isNaNID = (*env)->GetStaticMethodID (env, cls, "isNaN", "(D)Z"); - if (isNaNID == NULL) - { - DBG ("unable to determine method id of isNaN\n") return; - } - negInfID = (*env)->GetStaticFieldID (env, cls, "NEGATIVE_INFINITY", "D"); - if (negInfID == NULL) - { - DBG ("unable to determine field id of NEGATIVE_INFINITY\n") return; - } - posInfID = (*env)->GetStaticFieldID (env, cls, "POSITIVE_INFINITY", "D"); - if (posInfID == NULL) - { - DBG ("unable to determine field id of POSITIVE_INFINITY\n") return; - } - nanID = (*env)->GetStaticFieldID (env, cls, "NaN", "D"); - if (posInfID == NULL) - { - DBG ("unable to determine field id of NaN\n") return; - } - POSITIVE_INFINITY = (*env)->GetStaticDoubleField (env, cls, posInfID); - NEGATIVE_INFINITY = (*env)->GetStaticDoubleField (env, cls, negInfID); - NaN = (*env)->GetStaticDoubleField (env, cls, nanID); - -#ifdef DEBUG - fprintf (stderr, "java.lang.Double.initIDs() POSITIVE_INFINITY = %g\n", - POSITIVE_INFINITY); - fprintf (stderr, "java.lang.Double.initIDs() NEGATIVE_INFINITY = %g\n", - NEGATIVE_INFINITY); - fprintf (stderr, "java.lang.Double.initIDs() NaN = %g\n", NaN); -#endif -} - -/* - * Class: java_lang_Double - * Method: toString - * Signature: (DZ)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL -Java_java_lang_Double_toString - (JNIEnv * env, jclass cls, jdouble value, jboolean isFloat) -{ - char buffer[50], result[50]; - int decpt, sign; - char *s, *d; - int i; - -#ifdef DEBUG - fprintf (stderr, "java.lang.Double.toString (%g)\n", value); -#endif - - if ((*env)->CallStaticBooleanMethod (env, cls, isNaNID, value)) - return (*env)->NewStringUTF (env, "NaN"); - - if (value == POSITIVE_INFINITY) - return (*env)->NewStringUTF (env, "Infinity"); - - if (value == NEGATIVE_INFINITY) - return (*env)->NewStringUTF (env, "-Infinity"); - - _dtoa (value, 0, 20, &decpt, &sign, NULL, buffer, (int) isFloat); - - value = fabs (value); - - s = buffer; - d = result; - - if (sign) - *d++ = '-'; - - if ((value >= 1e-3 && value < 1e7) || (value == 0)) - { - if (decpt <= 0) - *d++ = '0'; - else - { - for (i = 0; i < decpt; i++) - if (*s) - *d++ = *s++; - else - *d++ = '0'; - } - - *d++ = '.'; - - if (*s == 0) - { - *d++ = '0'; - decpt++; - } - - while (decpt++ < 0) - *d++ = '0'; - - while (*s) - *d++ = *s++; - - *d = 0; - - return (*env)->NewStringUTF (env, result); - } - - *d++ = *s++; - decpt--; - *d++ = '.'; - - if (*s == 0) - *d++ = '0'; - - while (*s) - *d++ = *s++; - - *d++ = 'E'; - - if (decpt < 0) - { - *d++ = '-'; - decpt = -decpt; - } - - { - char exp[4]; - char *e = exp + sizeof exp; - - *--e = 0; - do - { - *--e = '0' + decpt % 10; - decpt /= 10; - } - while (decpt > 0); - - while (*e) - *d++ = *e++; - } - - *d = 0; - - return (*env)->NewStringUTF (env, result); -} - -/* - * Class: java_lang_Double - * Method: parseDouble - * Signature: (Ljava/lang/String;)D - */ -JNIEXPORT jdouble JNICALL -Java_java_lang_Double_parseDouble - (JNIEnv * env, jclass cls __attribute__ ((__unused__)), jstring str) -{ - jboolean isCopy; - const char *buf; - char *endptr; - jdouble val = 0.0; - - if (str == NULL) - { - JCL_ThrowException (env, "java/lang/NullPointerException", "null"); - return val; - } - - buf = (char *) (*env)->GetStringUTFChars (env, str, &isCopy); - if (buf == NULL) - { - /* OutOfMemoryError already thrown */ - } - else - { - const char *p = buf, *end, *last_non_ws, *temp; - int ok = 1; - -#ifdef DEBUG - fprintf (stderr, "java.lang.Double.parseDouble (%s)\n", buf); -#endif - - /* Trim the buffer, similar to String.trim(). First the leading - characters. */ - while (*p && *p <= ' ') - ++p; - - /* Find the last non-whitespace character. This method is safe - even with multi-byte UTF-8 characters. */ - end = p; - last_non_ws = NULL; - while (*end) - { - if (*end > ' ') - last_non_ws = end; - ++end; - } - - if (last_non_ws == NULL) - last_non_ws = p + strlen (p); - else - { - /* Skip past the last non-whitespace character. */ - ++last_non_ws; - } - - /* Check for infinity and NaN */ - temp = p; - if (temp[0] == '+' || temp[0] == '-') - temp++; - if (strncmp ("Infinity", temp, (size_t) 8) == 0) - { - if (p[0] == '-') - return NEGATIVE_INFINITY; - return POSITIVE_INFINITY; - } - if (strncmp ("NaN", temp, (size_t) 3) == 0) - return NaN; - - /* Skip a trailing `f' or `d'. */ - if (last_non_ws > p - && (last_non_ws[-1] == 'f' - || last_non_ws[-1] == 'F' - || last_non_ws[-1] == 'd' || last_non_ws[-1] == 'D')) - --last_non_ws; - - if (last_non_ws > p) - { - struct _Jv_reent reent; - memset (&reent, 0, sizeof reent); - -#ifdef KISSME_LINUX_USER - /* FIXME: The libc strtod may not be reliable. */ - val = strtod (p, &endptr); -#else - val = _strtod_r (&reent, p, &endptr); -#endif - -#ifdef DEBUG - fprintf (stderr, "java.lang.Double.parseDouble val = %g\n", val); - fprintf (stderr, "java.lang.Double.parseDouble %i != %i ???\n", - endptr, last_non_ws); -#endif - if (endptr != last_non_ws) - ok = 0; - } - else - ok = 0; - - if (!ok) - { - val = 0.0; - JCL_ThrowException (env, - "java/lang/NumberFormatException", - "unable to parse double"); - } - - (*env)->ReleaseStringUTFChars (env, str, buf); - } - - return val; -} Index: native/jni/java-lang/java_lang_Object.c =================================================================== RCS file: native/jni/java-lang/java_lang_Object.c diff -N native/jni/java-lang/java_lang_Object.c --- native/jni/java-lang/java_lang_Object.c 9 Apr 2005 17:37:42 -0000 1.7 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,50 +0,0 @@ -/* Object.c - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - - -#include "java_lang_Object.h" - -/* - * Class: java_lang_Object - * Method: getClass - * Signature: ()Ljava/lang/Class; - */ -JNIEXPORT jclass JNICALL -Java_java_lang_Object_getClass (JNIEnv * env, jobject thisObj) -{ - return (*env)->GetObjectClass (env, thisObj); -} Index: native/jni/java-lang/java_lang_VMDouble.c =================================================================== RCS file: /cvsroot/classpath/classpath/native/jni/java-lang/java_lang_VMDouble.c,v retrieving revision 1.8 diff -u -r1.8 java_lang_VMDouble.c --- native/jni/java-lang/java_lang_VMDouble.c 9 Apr 2005 17:37:42 -0000 1.8 +++ native/jni/java-lang/java_lang_VMDouble.c 16 Apr 2005 09:17:57 -0000 @@ -1,5 +1,6 @@ /* VMDouble.c - java.lang.VMDouble native functions - Copyright (C) 1998, 1999, 2001, 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2003, 2004i, 2005 + Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -37,10 +38,72 @@ #include +#include +#include +#include + +#include "mprec.h" +#include "fdlibm.h" +#include "jcl.h" -#include "java_lang_Double.h" #include "java_lang_VMDouble.h" +static jclass clsDouble; +static jmethodID isNaNID; +static jdouble NEGATIVE_INFINITY; +static jdouble POSITIVE_INFINITY; +static jdouble NaN; + +/* + * Class: java_lang_VMDouble + * Method: initIDs + * Signature: ()V + */ +JNIEXPORT void JNICALL +Java_java_lang_VMDouble_initIDs (JNIEnv * env, jclass cls __attribute__ ((__unused__))) +{ + jfieldID negInfID; + jfieldID posInfID; + jfieldID nanID; + + clsDouble = (*env)->FindClass (env, "java/lang/Double"); + if (clsDouble == NULL) + { + DBG ("unable to get class java.lang.Double\n") return; + } + isNaNID = (*env)->GetStaticMethodID (env, clsDouble, "isNaN", "(D)Z"); + if (isNaNID == NULL) + { + DBG ("unable to determine method id of isNaN\n") return; + } + negInfID = (*env)->GetStaticFieldID (env, clsDouble, "NEGATIVE_INFINITY", "D"); + if (negInfID == NULL) + { + DBG ("unable to determine field id of NEGATIVE_INFINITY\n") return; + } + posInfID = (*env)->GetStaticFieldID (env, clsDouble, "POSITIVE_INFINITY", "D"); + if (posInfID == NULL) + { + DBG ("unable to determine field id of POSITIVE_INFINITY\n") return; + } + nanID = (*env)->GetStaticFieldID (env, clsDouble, "NaN", "D"); + if (posInfID == NULL) + { + DBG ("unable to determine field id of NaN\n") return; + } + POSITIVE_INFINITY = (*env)->GetStaticDoubleField (env, clsDouble, posInfID); + NEGATIVE_INFINITY = (*env)->GetStaticDoubleField (env, clsDouble, negInfID); + NaN = (*env)->GetStaticDoubleField (env, clsDouble, nanID); + +#ifdef DEBUG + fprintf (stderr, "java.lang.Double.initIDs() POSITIVE_INFINITY = %g\n", + POSITIVE_INFINITY); + fprintf (stderr, "java.lang.Double.initIDs() NEGATIVE_INFINITY = %g\n", + NEGATIVE_INFINITY); + fprintf (stderr, "java.lang.Double.initIDs() NaN = %g\n", NaN); +#endif +} + /* * Class: java_lang_VMDouble * Method: doubleToLongBits @@ -93,3 +156,226 @@ val.j = longValue; return val.d; } + +/* + * Class: java_lang_VMDouble + * Method: toString + * Signature: (DZ)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL +Java_java_lang_VMDouble_toString + (JNIEnv * env, jclass cls __attribute__ ((__unused__)), jdouble value, jboolean isFloat) +{ + char buffer[50], result[50]; + int decpt, sign; + char *s, *d; + int i; + +#ifdef DEBUG + fprintf (stderr, "java.lang.VMDouble.toString (%g)\n", value); +#endif + + if ((*env)->CallStaticBooleanMethod (env, clsDouble, isNaNID, value)) + return (*env)->NewStringUTF (env, "NaN"); + + if (value == POSITIVE_INFINITY) + return (*env)->NewStringUTF (env, "Infinity"); + + if (value == NEGATIVE_INFINITY) + return (*env)->NewStringUTF (env, "-Infinity"); + + _dtoa (value, 0, 20, &decpt, &sign, NULL, buffer, (int) isFloat); + + value = fabs (value); + + s = buffer; + d = result; + + if (sign) + *d++ = '-'; + + if ((value >= 1e-3 && value < 1e7) || (value == 0)) + { + if (decpt <= 0) + *d++ = '0'; + else + { + for (i = 0; i < decpt; i++) + if (*s) + *d++ = *s++; + else + *d++ = '0'; + } + + *d++ = '.'; + + if (*s == 0) + { + *d++ = '0'; + decpt++; + } + + while (decpt++ < 0) + *d++ = '0'; + + while (*s) + *d++ = *s++; + + *d = 0; + + return (*env)->NewStringUTF (env, result); + } + + *d++ = *s++; + decpt--; + *d++ = '.'; + + if (*s == 0) + *d++ = '0'; + + while (*s) + *d++ = *s++; + + *d++ = 'E'; + + if (decpt < 0) + { + *d++ = '-'; + decpt = -decpt; + } + + { + char exp[4]; + char *e = exp + sizeof exp; + + *--e = 0; + do + { + *--e = '0' + decpt % 10; + decpt /= 10; + } + while (decpt > 0); + + while (*e) + *d++ = *e++; + } + + *d = 0; + + return (*env)->NewStringUTF (env, result); +} + +/* + * Class: java_lang_VMDouble + * Method: parseDouble + * Signature: (Ljava/lang/String;)D + */ +JNIEXPORT jdouble JNICALL +Java_java_lang_VMDouble_parseDouble + (JNIEnv * env, jclass cls __attribute__ ((__unused__)), jstring str) +{ + jboolean isCopy; + const char *buf; + char *endptr; + jdouble val = 0.0; + + if (str == NULL) + { + JCL_ThrowException (env, "java/lang/NullPointerException", "null"); + return val; + } + + buf = (char *) (*env)->GetStringUTFChars (env, str, &isCopy); + if (buf == NULL) + { + /* OutOfMemoryError already thrown */ + } + else + { + const char *p = buf, *end, *last_non_ws, *temp; + int ok = 1; + +#ifdef DEBUG + fprintf (stderr, "java.lang.VMDouble.parseDouble (%s)\n", buf); +#endif + + /* Trim the buffer, similar to String.trim(). First the leading + characters. */ + while (*p && *p <= ' ') + ++p; + + /* Find the last non-whitespace character. This method is safe + even with multi-byte UTF-8 characters. */ + end = p; + last_non_ws = NULL; + while (*end) + { + if (*end > ' ') + last_non_ws = end; + ++end; + } + + if (last_non_ws == NULL) + last_non_ws = p + strlen (p); + else + { + /* Skip past the last non-whitespace character. */ + ++last_non_ws; + } + + /* Check for infinity and NaN */ + temp = p; + if (temp[0] == '+' || temp[0] == '-') + temp++; + if (strncmp ("Infinity", temp, (size_t) 8) == 0) + { + if (p[0] == '-') + return NEGATIVE_INFINITY; + return POSITIVE_INFINITY; + } + if (strncmp ("NaN", temp, (size_t) 3) == 0) + return NaN; + + /* Skip a trailing `f' or `d'. */ + if (last_non_ws > p + && (last_non_ws[-1] == 'f' + || last_non_ws[-1] == 'F' + || last_non_ws[-1] == 'd' || last_non_ws[-1] == 'D')) + --last_non_ws; + + if (last_non_ws > p) + { + struct _Jv_reent reent; + memset (&reent, 0, sizeof reent); + +#ifdef KISSME_LINUX_USER + /* FIXME: The libc strtod may not be reliable. */ + val = strtod (p, &endptr); +#else + val = _strtod_r (&reent, p, &endptr); +#endif + +#ifdef DEBUG + fprintf (stderr, "java.lang.VMDouble.parseDouble val = %g\n", val); + fprintf (stderr, "java.lang.VMDouble.parseDouble %i != %i ???\n", + endptr, last_non_ws); +#endif + if (endptr != last_non_ws) + ok = 0; + } + else + ok = 0; + + if (!ok) + { + val = 0.0; + JCL_ThrowException (env, + "java/lang/NumberFormatException", + "unable to parse double"); + } + + (*env)->ReleaseStringUTFChars (env, str, buf); + } + + return val; +} Index: vm/reference/java/lang/VMDouble.java =================================================================== RCS file: /cvsroot/classpath/classpath/vm/reference/java/lang/VMDouble.java,v retrieving revision 1.1 diff -u -r1.1 VMDouble.java --- vm/reference/java/lang/VMDouble.java 16 Jul 2003 12:21:08 -0000 1.1 +++ vm/reference/java/lang/VMDouble.java 16 Apr 2005 09:17:57 -0000 @@ -1,5 +1,5 @@ /* VMDouble.java -- VM Specific Double methods - Copyright (C) 2003 Free Software Foundation + Copyright (C) 2003, 2005 Free Software Foundation This file is part of GNU Classpath. @@ -47,7 +47,7 @@ /** * Code relocated from java.lang.Double by - * @author Dave Grove + * @author Dave Grove (address@hidden) */ final class VMDouble { @@ -61,6 +61,8 @@ { System.loadLibrary("javalang"); } + + initIDs(); } /** @@ -110,5 +112,20 @@ */ public static native double longBitsToDouble(long bits); + /** + * Helper method to convert to string. + * + * @param d the double to convert + * @param isFloat true if the conversion is requested by Float (results in + * fewer digits) + */ + public static native String toString(double d, boolean isFloat); + + /** + * Initialize JNI cache. This method is called only by the + * static initializer when using JNI. + */ + public static native void initIDs(); -} // class VMDouble + public static native double parseDouble(String str); +} Index: vm/reference/java/lang/VMObject.java =================================================================== RCS file: /cvsroot/classpath/classpath/vm/reference/java/lang/VMObject.java,v retrieving revision 1.8 diff -u -r1.8 VMObject.java --- vm/reference/java/lang/VMObject.java 10 Sep 2002 21:19:37 -0000 1.8 +++ vm/reference/java/lang/VMObject.java 16 Apr 2005 09:17:57 -0000 @@ -1,5 +1,5 @@ /* VMObject.java -- Reference implementation for VM hooks used by Object - Copyright (C) 1998, 2002 Free Software Foundation + Copyright (C) 1998, 2002, 2005 Free Software Foundation This file is part of GNU Classpath. @@ -42,11 +42,20 @@ * As such, it needs help from the VM. * * @author John Keiser - * @author Eric Blake + * @author Eric Blake (address@hidden) */ final class VMObject { /** + * Returns the runtime address@hidden Class} of a given Object. + * + * @param obj the object to return the class for. + * + * @return the class of the Object. + */ + static native Class getClass(Object obj); + + /** * The VM is expected to make a field-for-field shallow copy of the * argument. Thus, the copy has the same runtime type as the argument. * Note, however, that the cloned object must still be finalizable, even