diff options
author | Tom Tromey <tromey@gcc.gnu.org> | 2007-01-09 19:58:05 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2007-01-09 19:58:05 +0000 |
commit | 97b8365cafc3a344a22d3980b8ed885f5c6d8357 (patch) | |
tree | 996a5f57d4a68c53473382e45cb22f574cb3e4db /libjava/classpath/native/jni/java-lang | |
parent | c648dedbde727ca3f883bb5fd773aa4af70d3369 (diff) | |
download | gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.zip gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.tar.gz gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.tar.bz2 |
Merged gcj-eclipse branch to trunk.
From-SVN: r120621
Diffstat (limited to 'libjava/classpath/native/jni/java-lang')
5 files changed, 275 insertions, 288 deletions
diff --git a/libjava/classpath/native/jni/java-lang/.cvsignore b/libjava/classpath/native/jni/java-lang/.cvsignore new file mode 100644 index 0000000..e9f2658 --- /dev/null +++ b/libjava/classpath/native/jni/java-lang/.cvsignore @@ -0,0 +1,8 @@ +*.o +*.a +*.lo +*.la +.libs +.deps +Makefile +Makefile.in diff --git a/libjava/classpath/native/jni/java-lang/Makefile.am b/libjava/classpath/native/jni/java-lang/Makefile.am index 06deb62..366d72e 100644 --- a/libjava/classpath/native/jni/java-lang/Makefile.am +++ b/libjava/classpath/native/jni/java-lang/Makefile.am @@ -7,7 +7,8 @@ libjavalang_la_SOURCES = java_lang_VMSystem.c \ java_lang_VMProcess.c libjavalang_la_LIBADD = $(wildcard $(top_builddir)/native/fdlibm/*.lo) \ - $(top_builddir)/native/jni/classpath/jcl.lo + $(top_builddir)/native/jni/classpath/jcl.lo \ + $(top_builddir)/native/jni/native-lib/libclasspathnative.la libjavalangreflect_la_SOURCES = java_lang_reflect_VMArray.c diff --git a/libjava/classpath/native/jni/java-lang/Makefile.in b/libjava/classpath/native/jni/java-lang/Makefile.in index c8f3dab..4a99863 100644 --- a/libjava/classpath/native/jni/java-lang/Makefile.in +++ b/libjava/classpath/native/jni/java-lang/Makefile.in @@ -42,12 +42,14 @@ DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/../../config/depstand.m4 \ $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/no-executables.m4 \ $(top_srcdir)/../../libtool.m4 $(top_srcdir)/m4/acattribute.m4 \ $(top_srcdir)/m4/accross.m4 $(top_srcdir)/m4/acinclude.m4 \ $(top_srcdir)/m4/ax_create_stdint_h.m4 \ - $(top_srcdir)/m4/iconv.m4 $(top_srcdir)/m4/lib-ld.m4 \ - $(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \ - $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac + $(top_srcdir)/m4/gcc_attribute.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \ + $(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/pkg.m4 \ + $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs @@ -64,7 +66,8 @@ nativeexeclibLTLIBRARIES_INSTALL = $(INSTALL) LTLIBRARIES = $(nativeexeclib_LTLIBRARIES) libjavalang_la_DEPENDENCIES = $(wildcard \ $(top_builddir)/native/fdlibm/*.lo) \ - $(top_builddir)/native/jni/classpath/jcl.lo + $(top_builddir)/native/jni/classpath/jcl.lo \ + $(top_builddir)/native/jni/native-lib/libclasspathnative.la am_libjavalang_la_OBJECTS = java_lang_VMSystem.lo java_lang_VMFloat.lo \ java_lang_VMDouble.lo java_lang_VMMath.lo \ java_lang_VMProcess.lo @@ -191,6 +194,8 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION = @JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@ +JAVA_MAINTAINER_MODE_FALSE = @JAVA_MAINTAINER_MODE_FALSE@ +JAVA_MAINTAINER_MODE_TRUE = @JAVA_MAINTAINER_MODE_TRUE@ JAY = @JAY@ JAY_SKELETON = @JAY_SKELETON@ JIKES = @JIKES@ @@ -312,7 +317,6 @@ target_alias = @target_alias@ target_cpu = @target_cpu@ target_os = @target_os@ target_vendor = @target_vendor@ -toolexeclibdir = @toolexeclibdir@ vm_classes = @vm_classes@ nativeexeclib_LTLIBRARIES = libjavalang.la libjavalangreflect.la libjavalang_la_SOURCES = java_lang_VMSystem.c \ @@ -322,7 +326,8 @@ libjavalang_la_SOURCES = java_lang_VMSystem.c \ java_lang_VMProcess.c libjavalang_la_LIBADD = $(wildcard $(top_builddir)/native/fdlibm/*.lo) \ - $(top_builddir)/native/jni/classpath/jcl.lo + $(top_builddir)/native/jni/classpath/jcl.lo \ + $(top_builddir)/native/jni/native-lib/libclasspathnative.la libjavalangreflect_la_SOURCES = java_lang_reflect_VMArray.c AM_LDFLAGS = @CLASSPATH_MODULE@ diff --git a/libjava/classpath/native/jni/java-lang/java_lang_VMDouble.c b/libjava/classpath/native/jni/java-lang/java_lang_VMDouble.c index 8435c3fd..2ee1f31 100644 --- a/libjava/classpath/native/jni/java-lang/java_lang_VMDouble.c +++ b/libjava/classpath/native/jni/java-lang/java_lang_VMDouble.c @@ -37,6 +37,7 @@ obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ +#include <assert.h> #include <config.h> #include <stdlib.h> #include <stdio.h> @@ -121,17 +122,8 @@ Java_java_lang_VMDouble_doubleToLongBits { jvalue val; jlong e, f; - val.d = doubleValue; - -#if defined(__IEEE_BYTES_LITTLE_ENDIAN) - /* On little endian ARM processors when using FPA, word order of - doubles is still big endian. So take that into account here. When - using VFP, word order of doubles follows byte order. */ - -#define SWAP_DOUBLE(a) (((a) << 32) | (((a) >> 32) & 0x00000000ffffffff)) - val.j = SWAP_DOUBLE(val.j); -#endif + val.d = doubleValue; e = val.j & 0x7ff0000000000000LL; f = val.j & 0x000fffffffffffffLL; @@ -153,11 +145,8 @@ Java_java_lang_VMDouble_doubleToRawLongBits jclass cls __attribute__ ((__unused__)), jdouble doubleValue) { jvalue val; - val.d = doubleValue; -#if defined(__IEEE_BYTES_LITTLE_ENDIAN) - val.j = SWAP_DOUBLE(val.j); -#endif + val.d = doubleValue; return val.j; } @@ -173,52 +162,139 @@ Java_java_lang_VMDouble_longBitsToDouble jclass cls __attribute__ ((__unused__)), jlong longValue) { jvalue val; - val.j = longValue; -#if defined(__IEEE_BYTES_LITTLE_ENDIAN) - val.j = SWAP_DOUBLE(val.j); -#endif + val.j = longValue; return val.d; } -/* - * Class: java_lang_VMDouble - * Method: toString - * Signature: (DZ)Ljava/lang/String; +/** + * Parse a double from a char array. */ -JNIEXPORT jstring JNICALL -Java_java_lang_VMDouble_toString - (JNIEnv * env, jclass cls __attribute__ ((__unused__)), jdouble value, jboolean isFloat) +static jdouble +parseDoubleFromChars(JNIEnv * env, const char * buf) { - char buffer[50], result[50]; - int decpt, sign; - char *s, *d; - int i; + char *endptr; + jdouble val = 0.0; + const char *p = buf, *end, *last_non_ws, *temp; + int ok = 1; #ifdef DEBUG - fprintf (stderr, "java.lang.VMDouble.toString (%g)\n", value); + fprintf (stderr, "java.lang.VMDouble.parseDouble (%s)\n", buf); #endif - if ((*env)->CallStaticBooleanMethod (env, clsDouble, isNaNID, value)) - return (*env)->NewStringUTF (env, "NaN"); + /* Trim the buffer, similar to String.trim(). First the leading + characters. */ + while (*p && *p <= ' ') + ++p; - if (value == POSITIVE_INFINITY) - return (*env)->NewStringUTF (env, "Infinity"); + /* 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 (value == NEGATIVE_INFINITY) - return (*env)->NewStringUTF (env, "-Infinity"); + if (last_non_ws == NULL) + last_non_ws = p + strlen (p); + else + { + /* Skip past the last non-whitespace character. */ + ++last_non_ws; + } - _dtoa (value, 0, 20, &decpt, &sign, NULL, buffer, (int) isFloat); + /* 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); + + val = _strtod_r (&reent, p, &endptr); + +#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"); + } + + return val; +} + +#define MAXIMAL_DECIMAL_STRING_LENGTH 64 + +/** + * Use _dtoa to print a double or a float as a string with the given precision. + */ +static void +dtoa_toString +(char * buffer, jdouble value, jint precision, jboolean isFloat) +{ + const int DTOA_MODE = 2; + char result[MAXIMAL_DECIMAL_STRING_LENGTH]; + int decpt, sign; + char *s, *d; + int i; + + /* use mode 2 to get at the digit stream, all other modes are useless + * + * since mode 2 only gives us as many digits as we need in precision, we need to + * add the digits in front of the floating point to it, if there is more than one + * to be printed. That's the case if the value is going to be printed using the + * normal notation, i.e. if it is 0 or >= 1.0e-3 and < 1.0e7. + */ + int digits_in_front_of_floating_point = ceil(log10(value)); + + if (digits_in_front_of_floating_point > 1 && digits_in_front_of_floating_point < 7) + precision += digits_in_front_of_floating_point; + + _dtoa (value, DTOA_MODE, precision, &decpt, &sign, NULL, buffer, (int) isFloat); value = fabs (value); s = buffer; d = result; + /* Handle negative sign */ if (sign) *d++ = '-'; + /* Handle normal represenation */ if ((value >= 1e-3 && value < 1e7) || (value == 0)) { if (decpt <= 0) @@ -248,46 +324,111 @@ Java_java_lang_VMDouble_toString *d = 0; - return (*env)->NewStringUTF (env, result); } + /* Handle scientific representaiton */ + else + { + *d++ = *s++; + decpt--; + *d++ = '.'; + + if (*s == 0) + *d++ = '0'; - *d++ = *s++; - decpt--; - *d++ = '.'; + while (*s) + *d++ = *s++; - if (*s == 0) - *d++ = '0'; + *d++ = 'E'; - while (*s) - *d++ = *s++; + if (decpt < 0) + { + *d++ = '-'; + decpt = -decpt; + } - *d++ = 'E'; + { + char exp[4]; + char *e = exp + sizeof exp; + + *--e = 0; + do + { + *--e = '0' + decpt % 10; + decpt /= 10; + } + while (decpt > 0); + + while (*e) + *d++ = *e++; + } - if (decpt < 0) - { - *d++ = '-'; - decpt = -decpt; + *d = 0; } - { - char exp[4]; - char *e = exp + sizeof exp; + /* copy the result into the buffer */ + memcpy(buffer, result, MAXIMAL_DECIMAL_STRING_LENGTH); +} - *--e = 0; - do - { - *--e = '0' + decpt % 10; - decpt /= 10; - } - while (decpt > 0); +/* + * 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 buf[MAXIMAL_DECIMAL_STRING_LENGTH]; + const jint MAXIMAL_FLOAT_PRECISION = 10; + const jint MAXIMAL_DOUBLE_PRECISION = 19; - while (*e) - *d++ = *e++; - } + jint maximal_precision; + jint least_necessary_precision = 2; + jboolean parsed_value_unequal; + + 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"); + + if (isFloat) + maximal_precision = MAXIMAL_FLOAT_PRECISION; + else + maximal_precision = MAXIMAL_DOUBLE_PRECISION; + + /* Try to find the 'good enough' precision, + * that results in enough digits being printed to be able to + * convert the number back into the original double, but no + * further digits. + */ + + do { + jdouble parsed_value; - *d = 0; + assert(least_necessary_precision <= maximal_precision); - return (*env)->NewStringUTF (env, result); + /* Convert the value to a string and back. */ + dtoa_toString(buf, value, least_necessary_precision, isFloat); + + parsed_value = parseDoubleFromChars(env, buf); + + /* Check whether the original value, and the value after conversion match. */ + /* We need to cast floats to float to make sure that our ineqality check works + * well for floats as well as for doubles. + */ + parsed_value_unequal = ( isFloat ? + (float) parsed_value != (float) value : + parsed_value != value); + + least_necessary_precision++; + } + while (parsed_value_unequal); + + return (*env)->NewStringUTF (env, buf); } /* @@ -301,7 +442,6 @@ Java_java_lang_VMDouble_parseDouble { jboolean isCopy; const char *buf; - char *endptr; jdouble val = 0.0; if (str == NULL) @@ -317,83 +457,7 @@ Java_java_lang_VMDouble_parseDouble } 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); - - val = _strtod_r (&reent, p, &endptr); - -#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"); - } - + val = parseDoubleFromChars(env, buf); (*env)->ReleaseStringUTFChars (env, str, buf); } diff --git a/libjava/classpath/native/jni/java-lang/java_lang_VMProcess.c b/libjava/classpath/native/jni/java-lang/java_lang_VMProcess.c index f13a94f..a6076f2 100644 --- a/libjava/classpath/native/jni/java-lang/java_lang_VMProcess.c +++ b/libjava/classpath/native/jni/java-lang/java_lang_VMProcess.c @@ -38,7 +38,7 @@ exception statement from your version. */ #include <config.h> #include "java_lang_VMProcess.h" -#include "gnu_java_nio_channels_FileChannelImpl.h" +#include "gnu_java_nio_FileChannelImpl.h" #include <sys/types.h> #include <sys/wait.h> @@ -50,10 +50,8 @@ exception statement from your version. */ #include <fcntl.h> #include <stdio.h> -#include <jcl.h> - -#include "target_native.h" -#include "target_native_misc.h" +#include "cpnative.h" +#include "cpproc.h" /* Internal functions */ static char *copy_string (JNIEnv * env, jobject string); @@ -65,7 +63,6 @@ static char *copy_elem (JNIEnv * env, jobject stringArray, jint i); static char * copy_string (JNIEnv * env, jobject string) { - char errbuf[64]; const char *utf; jclass clazz; char *copy; @@ -89,12 +86,10 @@ copy_string (JNIEnv * env, jobject string) /* Copy it */ if ((copy = strdup (utf)) == NULL) { - TARGET_NATIVE_MISC_FORMAT_STRING1 (errbuf, sizeof (errbuf), - "strdup: %s", strerror (errno)); clazz = (*env)->FindClass (env, "java/lang/InternalError"); if ((*env)->ExceptionOccurred (env)) return NULL; - (*env)->ThrowNew (env, clazz, errbuf); + (*env)->ThrowNew (env, clazz, "strdup returned NULL"); (*env)->DeleteLocalRef (env, clazz); } @@ -131,8 +126,8 @@ Java_java_lang_VMProcess_nativeSpawn (JNIEnv * env, jobject this, jobjectArray envArray, jobject dirFile, jboolean redirect) { - int fds[3][2] = { {-1, -1}, {-1, -1}, {-1, -1} }; - jobject streams[3] = { NULL, NULL, NULL }; + int fds[CPIO_EXEC_NUM_PIPES]; + jobject streams[CPIO_EXEC_NUM_PIPES] = { NULL, NULL, NULL }; jobject dirString = NULL; char **newEnviron = NULL; jsize cmdArrayLen = 0; @@ -142,10 +137,11 @@ Java_java_lang_VMProcess_nativeSpawn (JNIEnv * env, jobject this, char *dir = NULL; pid_t pid = -1; char errbuf[64]; - jmethodID method; - jclass clazz; + jmethodID method, vmmethod; + jclass clazz, vmclazz; int i; int pipe_count = redirect ? 2 : 3; + int err; /* Check for null */ if (cmdArray == NULL) @@ -182,9 +178,7 @@ Java_java_lang_VMProcess_nativeSpawn (JNIEnv * env, jobject this, + (dirString != NULL ? 1 : 0)) * sizeof (*strings))) == NULL) { - TARGET_NATIVE_MISC_FORMAT_STRING1 (errbuf, - sizeof (errbuf), "malloc: %s", - strerror (errno)); + strncpy (errbuf, "malloc failed", sizeof(errbuf)); goto out_of_memory; } @@ -209,125 +203,43 @@ Java_java_lang_VMProcess_nativeSpawn (JNIEnv * env, jobject this, { if ((dir = copy_string (env, dirString)) == NULL) goto done; - strings[num_strings++] = dir; } /* Create inter-process pipes */ - for (i = 0; i < pipe_count; i++) - { - if (pipe (fds[i]) == -1) - { - TARGET_NATIVE_MISC_FORMAT_STRING1 (errbuf, - sizeof (errbuf), "pipe: %s", - strerror (errno)); - goto system_error; - } - } - - /* Set close-on-exec flag for parent's ends of pipes */ - (void) fcntl (fds[0][1], F_SETFD, 1); - (void) fcntl (fds[1][0], F_SETFD, 1); - if (pipe_count == 3) - (void) fcntl (fds[2][0], F_SETFD, 1); - - /* Fork into parent and child processes */ - if ((pid = fork ()) == (pid_t) - 1) + err = cpproc_forkAndExec(strings, newEnviron, fds, pipe_count, &pid, dir); + if (err != 0) { - TARGET_NATIVE_MISC_FORMAT_STRING1 (errbuf, - sizeof (errbuf), "fork: %s", - strerror (errno)); + strncpy(errbuf, cpnative_getErrorString (err), sizeof(errbuf)); goto system_error; } - /* Child becomes the new process */ - if (pid == 0) - { - char *const path = strings[0]; - - /* Move file descriptors to standard locations */ - if (fds[0][0] != 0) - { - if (dup2 (fds[0][0], 0) == -1) - { - fprintf (stderr, "dup2: %s", strerror (errno)); - exit (127); - } - close (fds[0][0]); - } - if (fds[1][1] != 1) - { - if (dup2 (fds[1][1], 1) == -1) - { - fprintf (stderr, "dup2: %s", strerror (errno)); - exit (127); - } - close (fds[1][1]); - } - if (pipe_count == 2) - { - /* Duplicate stdout to stderr. */ - if (dup2 (1, 2) == -1) - { - fprintf (stderr, "dup2: %s", strerror (errno)); - exit (127); - } - } - else if (fds[2][1] != 2) - { - if (dup2 (fds[2][1], 2) == -1) - { - fprintf (stderr, "dup2: %s", strerror (errno)); - exit (127); - } - close (fds[2][1]); - } - - /* Change into destination directory */ - if (dir != NULL && chdir (dir) == -1) - { - fprintf (stderr, "%s: %s", dir, strerror (errno)); - exit (127); - } - - /* Make argv[0] last component of executable pathname */ - /* XXX should use "file.separator" property here XXX */ - for (i = strlen (path); i > 0 && path[i - 1] != '/'; i--); - strings[0] = path + i; - - /* Set new environment */ - if (newEnviron != NULL) - environ = newEnviron; - - /* Execute new program (this will close the parent end of the pipes) */ - execvp (path, strings); - - /* Failed */ - fprintf (stderr, "%s: %s", path, strerror (errno)); - exit (127); - } - /* Create Input/OutputStream objects around parent file descriptors */ - clazz = (*env)->FindClass (env, "gnu/java/nio/channels/FileChannelImpl"); + vmclazz = (*env)->FindClass (env, "gnu/java/nio/VMChannel"); + clazz = (*env)->FindClass (env, "gnu/java/nio/FileChannelImpl"); if ((*env)->ExceptionOccurred (env)) goto done; - method = (*env)->GetMethodID (env, clazz, "<init>", "(II)V"); + vmmethod = (*env)->GetMethodID (env, vmclazz, "<init>", "(I)V"); + method = (*env)->GetMethodID (env, clazz, "<init>", "(Lgnu/java/nio/VMChannel;I)V"); if ((*env)->ExceptionOccurred (env)) goto done; for (i = 0; i < pipe_count; i++) { /* Mode is WRITE (2) for in and READ (1) for out and err. */ - const int fd = fds[i][i == 0]; - const int mode = ((i == 0) - ? gnu_java_nio_channels_FileChannelImpl_WRITE - : gnu_java_nio_channels_FileChannelImpl_READ); + const int fd = fds[i]; + const int mode = ((i == CPIO_EXEC_STDIN) ? 2 : 1); jclass sclazz; jmethodID smethod; - jobject channel = (*env)->NewObject (env, clazz, method, fd, mode); + jobject vmchannel; + jobject channel; + vmchannel = (*env)->NewObject (env, vmclazz, vmmethod, fd); + if ((*env)->ExceptionOccurred (env)) + goto done; + channel = (*env)->NewObject (env, clazz, method, vmchannel, mode); if ((*env)->ExceptionOccurred (env)) goto done; - if (mode == gnu_java_nio_channels_FileChannelImpl_WRITE) + if (mode == gnu_java_nio_FileChannelImpl_WRITE) sclazz = (*env)->FindClass (env, "java/io/FileOutputStream"); else sclazz = (*env)->FindClass (env, "java/io/FileInputStream"); @@ -335,7 +247,7 @@ Java_java_lang_VMProcess_nativeSpawn (JNIEnv * env, jobject this, goto done; smethod = (*env)->GetMethodID (env, sclazz, "<init>", - "(Lgnu/java/nio/channels/FileChannelImpl;)V"); + "(Lgnu/java/nio/FileChannelImpl;)V"); if ((*env)->ExceptionOccurred (env)) goto done; @@ -355,7 +267,10 @@ Java_java_lang_VMProcess_nativeSpawn (JNIEnv * env, jobject this, if ((*env)->ExceptionOccurred (env)) goto done; (*env)->CallVoidMethod (env, this, method, - streams[0], streams[1], streams[2], (jlong) pid); + streams[CPIO_EXEC_STDIN], + streams[CPIO_EXEC_STDOUT], + streams[CPIO_EXEC_STDERR], + (jlong) pid); if ((*env)->ExceptionOccurred (env)) goto done; @@ -365,15 +280,6 @@ done: * parent process. Our goal is to clean up the mess we created. */ - /* Close child's ends of pipes */ - for (i = 0; i < pipe_count; i++) - { - const int fd = fds[i][i != 0]; - - if (fd != -1) - close (fd); - } - /* * Close parent's ends of pipes if Input/OutputStreams never got created. * This can only happen in a failure case. If a Stream object @@ -382,7 +288,7 @@ done: */ for (i = 0; i < pipe_count; i++) { - const int fd = fds[i][i == 0]; + const int fd = fds[i]; if (fd != -1 && streams[i] == NULL) close (fd); @@ -392,7 +298,8 @@ done: while (num_strings > 0) free (strings[--num_strings]); free (strings); - + if (dir != NULL) + free(dir); /* Done */ return; @@ -431,19 +338,20 @@ Java_java_lang_VMProcess_nativeReap (JNIEnv * env, jclass clazz) jfieldID field; jint status; pid_t pid; + int err; /* Try to reap a child process, but don't block */ - if ((pid = waitpid ((pid_t) - 1, &status, WNOHANG)) == 0) + err = cpproc_waitpid((pid_t)-1, &status, &pid, WNOHANG); + if (err == 0 && pid == 0) return JNI_FALSE; /* Check result from waitpid() */ - if (pid == (pid_t) - 1) + if (err != 0) { - if (errno == ECHILD || errno == EINTR) + if (err == ECHILD || err == EINTR) return JNI_FALSE; - TARGET_NATIVE_MISC_FORMAT_STRING2 (ebuf, - sizeof (ebuf), "waitpid(%ld): %s", - (long) pid, strerror (errno)); + snprintf(ebuf, sizeof (ebuf), "waitpid(%ld): %s", + (long) pid, cpnative_getErrorString(errno)); clazz = (*env)->FindClass (env, "java/lang/InternalError"); if ((*env)->ExceptionOccurred (env)) return JNI_FALSE; @@ -485,12 +393,13 @@ JNIEXPORT void JNICALL Java_java_lang_VMProcess_nativeKill (JNIEnv * env, jclass clazz, jlong pid) { char ebuf[64]; - - if (kill ((pid_t) pid, SIGKILL) == -1) + int err; + + err = cpproc_kill((pid_t) pid, SIGKILL); + if (err != 0) { - TARGET_NATIVE_MISC_FORMAT_STRING2 (ebuf, - sizeof (ebuf), "kill(%ld): %s", - (long) pid, strerror (errno)); + snprintf (ebuf, sizeof (ebuf), "kill(%ld): %s", + (long) pid, cpnative_getErrorString (err)); clazz = (*env)->FindClass (env, "java/lang/InternalError"); if ((*env)->ExceptionOccurred (env)) return; |