PatchSet 5580 Date: 2005/03/21 17:14:58 Author: robilad Branch: HEAD Tag: (none) Log: Resynced with GNU Classpath: VMSelector implementation merged in
2005-03-21 Dalibor Topic <[EMAIL PROTECTED]> Resynced with GNU Classpath. 2005-03-18 Robert Schuster <[EMAIL PROTECTED]> * native/jni/java-nio/gnu_java_nio_VMSelector.c: Implemented Java_gnu_java_nio_VMSelector_select. * configure.ac: Added check for sys/select.h and strerro_r(). * libraries/clib/nio/SelectorImpl.c: Removed. Replaced by gnu_java_nio_VMSelector.c. Members: ChangeLog:1.3754->1.3755 configure:1.436->1.437 configure.ac:1.126->1.127 config/config.h.in:1.137->1.138 libraries/clib/nio/Makefile.am:1.10->1.11 libraries/clib/nio/Makefile.in:1.66->1.67 libraries/clib/nio/SelectorImpl.c:1.3->1.4(DEAD) libraries/clib/nio/gnu_java_nio_VMSelector.c:INITIAL->1.1 Index: kaffe/ChangeLog diff -u kaffe/ChangeLog:1.3754 kaffe/ChangeLog:1.3755 --- kaffe/ChangeLog:1.3754 Mon Mar 21 16:36:56 2005 +++ kaffe/ChangeLog Mon Mar 21 17:14:58 2005 @@ -2,6 +2,19 @@ Resynced with GNU Classpath. + 2005-03-18 Robert Schuster <[EMAIL PROTECTED]> + + * native/jni/java-nio/gnu_java_nio_VMSelector.c: Implemented + Java_gnu_java_nio_VMSelector_select. + * configure.ac: Added check for sys/select.h and strerro_r(). + + * libraries/clib/nio/SelectorImpl.c: Removed. Replaced by + gnu_java_nio_VMSelector.c. + +2005-03-21 Dalibor Topic <[EMAIL PROTECTED]> + + Resynced with GNU Classpath. + 2005-03-17 Chris Burdess <[EMAIL PROTECTED]> * gnu/xml/dom/html2/DomHTMLDocument.java: Fixed element creation and Index: kaffe/configure diff -u kaffe/configure:1.436 kaffe/configure:1.437 --- kaffe/configure:1.436 Mon Mar 21 01:21:33 2005 +++ kaffe/configure Mon Mar 21 17:15:02 2005 @@ -44095,7 +44095,8 @@ -for ac_func in strerror hstrerror + +for ac_func in strerror hstrerror strerror_r do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` echo "$as_me:$LINENO: checking for $ac_func" >&5 Index: kaffe/configure.ac diff -u kaffe/configure.ac:1.126 kaffe/configure.ac:1.127 --- kaffe/configure.ac:1.126 Mon Mar 21 01:21:36 2005 +++ kaffe/configure.ac Mon Mar 21 17:15:09 2005 @@ -1488,7 +1488,7 @@ AC_DEFINE(STRTOD_m0_BROKEN, 1, [Define if strtod(\"-0.0\") is broken]) fi -AC_CHECK_FUNCS([strerror hstrerror]) +AC_CHECK_FUNCS([strerror hstrerror strerror_r]) AC_CHECK_FUNCS([fcntl ioctl]) AC_CHECK_FUNCS([alarm setitimer]) AC_CHECK_FUNCS([sigprocmask sigsetmask sigemptyset sigaddset signal sigaction]) Index: kaffe/config/config.h.in diff -u kaffe/config/config.h.in:1.137 kaffe/config/config.h.in:1.138 --- kaffe/config/config.h.in:1.137 Wed Mar 16 10:30:55 2005 +++ kaffe/config/config.h.in Mon Mar 21 17:15:09 2005 @@ -512,6 +512,9 @@ /* Define to 1 if you have the `strerror' function. */ #undef HAVE_STRERROR +/* Define to 1 if you have the `strerror_r' function. */ +#undef HAVE_STRERROR_R + /* Define to 1 if you have the `strftime' function. */ #undef HAVE_STRFTIME Index: kaffe/libraries/clib/nio/Makefile.am diff -u kaffe/libraries/clib/nio/Makefile.am:1.10 kaffe/libraries/clib/nio/Makefile.am:1.11 --- kaffe/libraries/clib/nio/Makefile.am:1.10 Thu Jan 13 11:16:34 2005 +++ kaffe/libraries/clib/nio/Makefile.am Mon Mar 21 17:15:10 2005 @@ -23,7 +23,7 @@ libnio_la_SOURCES = \ java_nio_VMDirectByteBuffer.c \ - SelectorImpl.c \ + gnu_java_nio_VMSelector.c \ FileChannelImpl.c libnio_la_DEPENDENCIES = \ Index: kaffe/libraries/clib/nio/Makefile.in diff -u kaffe/libraries/clib/nio/Makefile.in:1.66 kaffe/libraries/clib/nio/Makefile.in:1.67 --- kaffe/libraries/clib/nio/Makefile.in:1.66 Wed Mar 16 10:31:25 2005 +++ kaffe/libraries/clib/nio/Makefile.in Mon Mar 21 17:15:10 2005 @@ -85,7 +85,8 @@ am__DEPENDENCIES_1 = \ $(top_builddir)/libraries/clib/classpath/libclasspath.la am_libnio_la_OBJECTS = libnio_la-java_nio_VMDirectByteBuffer.lo \ - libnio_la-SelectorImpl.lo libnio_la-FileChannelImpl.lo + libnio_la-gnu_java_nio_VMSelector.lo \ + libnio_la-FileChannelImpl.lo libnio_la_OBJECTS = $(am_libnio_la_OBJECTS) DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/config -I$(top_builddir)/include/kaffe depcomp = $(SHELL) $(top_srcdir)/scripts/depcomp @@ -395,7 +396,7 @@ libnio_la_SOURCES = \ java_nio_VMDirectByteBuffer.c \ - SelectorImpl.c \ + gnu_java_nio_VMSelector.c \ FileChannelImpl.c libnio_la_DEPENDENCIES = \ @@ -475,7 +476,7 @@ -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@ [EMAIL PROTECTED]@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@ [EMAIL PROTECTED]@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@ @AMDEP_TRUE@@am__include@ @[EMAIL PROTECTED]/$(DEPDIR)/[EMAIL PROTECTED]@ .c.o: @@ -506,12 +507,12 @@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnio_la_CFLAGS) $(CFLAGS) -c -o libnio_la-java_nio_VMDirectByteBuffer.lo `test -f 'java_nio_VMDirectByteBuffer.c' || echo '$(srcdir)/'`java_nio_VMDirectByteBuffer.c -libnio_la-SelectorImpl.lo: SelectorImpl.c [EMAIL PROTECTED]@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnio_la_CFLAGS) $(CFLAGS) -MT libnio_la-SelectorImpl.lo -MD -MP -MF "$(DEPDIR)/libnio_la-SelectorImpl.Tpo" -c -o libnio_la-SelectorImpl.lo `test -f 'SelectorImpl.c' || echo '$(srcdir)/'`SelectorImpl.c; \ [EMAIL PROTECTED]@ then mv -f "$(DEPDIR)/libnio_la-SelectorImpl.Tpo" "$(DEPDIR)/libnio_la-SelectorImpl.Plo"; else rm -f "$(DEPDIR)/libnio_la-SelectorImpl.Tpo"; exit 1; fi [EMAIL PROTECTED]@@am__fastdepCC_FALSE@ source='SelectorImpl.c' object='libnio_la-SelectorImpl.lo' libtool=yes @AMDEPBACKSLASH@ +libnio_la-gnu_java_nio_VMSelector.lo: gnu_java_nio_VMSelector.c [EMAIL PROTECTED]@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnio_la_CFLAGS) $(CFLAGS) -MT libnio_la-gnu_java_nio_VMSelector.lo -MD -MP -MF "$(DEPDIR)/libnio_la-gnu_java_nio_VMSelector.Tpo" -c -o libnio_la-gnu_java_nio_VMSelector.lo `test -f 'gnu_java_nio_VMSelector.c' || echo '$(srcdir)/'`gnu_java_nio_VMSelector.c; \ [EMAIL PROTECTED]@ then mv -f "$(DEPDIR)/libnio_la-gnu_java_nio_VMSelector.Tpo" "$(DEPDIR)/libnio_la-gnu_java_nio_VMSelector.Plo"; else rm -f "$(DEPDIR)/libnio_la-gnu_java_nio_VMSelector.Tpo"; exit 1; fi [EMAIL PROTECTED]@@am__fastdepCC_FALSE@ source='gnu_java_nio_VMSelector.c' object='libnio_la-gnu_java_nio_VMSelector.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ [EMAIL PROTECTED]@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnio_la_CFLAGS) $(CFLAGS) -c -o libnio_la-SelectorImpl.lo `test -f 'SelectorImpl.c' || echo '$(srcdir)/'`SelectorImpl.c [EMAIL PROTECTED]@ $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnio_la_CFLAGS) $(CFLAGS) -c -o libnio_la-gnu_java_nio_VMSelector.lo `test -f 'gnu_java_nio_VMSelector.c' || echo '$(srcdir)/'`gnu_java_nio_VMSelector.c libnio_la-FileChannelImpl.lo: FileChannelImpl.c @am__fastdepCC_TRUE@ if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libnio_la_CFLAGS) $(CFLAGS) -MT libnio_la-FileChannelImpl.lo -MD -MP -MF "$(DEPDIR)/libnio_la-FileChannelImpl.Tpo" -c -o libnio_la-FileChannelImpl.lo `test -f 'FileChannelImpl.c' || echo '$(srcdir)/'`FileChannelImpl.c; \ =================================================================== Checking out kaffe/libraries/clib/nio/SelectorImpl.c RCS: /home/cvs/kaffe/kaffe/libraries/clib/nio/Attic/SelectorImpl.c,v VERS: 1.3 *************** --- kaffe/libraries/clib/nio/SelectorImpl.c Mon Mar 21 17:24:35 2005 +++ /dev/null Sun Aug 4 19:57:58 2002 @@ -1,82 +0,0 @@ -/* - * SelectorImpl.c - * - * Copyright (c) 2003, 2004. - * The Kaffe.org's developers. See ChangeLog for details. - * - * See the file "license.terms" for information on usage and redistribution - * of this file. - */ - -#include "config.h" -#include "config-std.h" -#include "config-io.h" -#include "files.h" -#include "gnu_java_nio_SelectorImpl.h" -#include "jsyscall.h" -#include "native.h" -#include "Arrays.h" - -static void checkInSelectTable(HArrayOfInt* fdArray, fd_set *set, int *num_fd) -{ - jint *iarray; - int i; - - FD_ZERO(set); - - iarray = unhand_int_array(fdArray); - for (i=0;i<obj_length(fdArray);i++) - { - FD_SET(iarray[i], set); - if (iarray[i] >= (*num_fd)) - *num_fd = iarray[i]+1; - } -} - -static void checkOutSelectTable(HArrayOfInt* fdArray, fd_set *set, int *num_fd) -{ - int i; - jint *iarray; - - iarray = unhand_int_array(fdArray); - for (i=0;i<obj_length(fdArray);i++) - { - if (!FD_ISSET(iarray[i], set)) - iarray[i] = 0; - else - (*num_fd)++; - } -} - -jint -gnu_java_nio_VMSelector_select(HArrayOfInt* readA, HArrayOfInt* writeA, - HArrayOfInt* exceptA, jlong timeout) -{ - fd_set read_set, write_set, except_set; - int num_fd = 0; - int ret, r; - struct timeval tval; - - checkInSelectTable(readA, &read_set, &num_fd); - checkInSelectTable(writeA, &write_set, &num_fd); - checkInSelectTable(exceptA, &except_set, &num_fd); - - if (timeout < 0) - r = KSELECT(num_fd, &read_set, &write_set, &except_set, NULL, &ret); - else - { - tval.tv_sec = timeout / 1000; - tval.tv_usec = timeout * 1000; - r = KSELECT(num_fd, &read_set, &write_set, &except_set, &tval, &ret); - } - - if (r != 0) - SignalError("java.io.IOException", SYS_ERROR(r)); - - num_fd = 0; - checkOutSelectTable(readA, &read_set, &num_fd); - checkOutSelectTable(writeA, &write_set, &num_fd); - checkOutSelectTable(exceptA, &except_set, &num_fd); - - return num_fd; -} =================================================================== Checking out kaffe/libraries/clib/nio/gnu_java_nio_VMSelector.c RCS: /home/cvs/kaffe/kaffe/libraries/clib/nio/gnu_java_nio_VMSelector.c,v VERS: 1.1 *************** --- /dev/null Sun Aug 4 19:57:58 2002 +++ kaffe/libraries/clib/nio/gnu_java_nio_VMSelector.c Mon Mar 21 17:24:35 2005 @@ -0,0 +1,282 @@ +/* gnu_java_nio_VMSelector.c - Native methods for SelectorImpl class + Copyright (C) 2004, 2005 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 <sys/select.h> +#include <sys/time.h> + +#include <string.h> + +#include <config.h> +#include <errno.h> + +#include <jni.h> +#include <jcl.h> + +#include "gnu_java_nio_VMSelector.h" + +/* Amount of characters in the error message buffer for strerror_r. */ +#define BUF_SIZE 250 + +void +helper_put_filedescriptors(JNIEnv *, jintArray, fd_set *, int *); + +void +helper_get_filedescriptors (JNIEnv *, jintArray*, fd_set *); + +void +helper_reset (JNIEnv *, jintArray*); + +int +helper_select (JNIEnv *, jclass, jmethodID, + int, fd_set *, fd_set *, fd_set *, + struct timeval *); + +void +helper_put_filedescriptors(JNIEnv *env, jintArray fdArray, fd_set *fds, int *max_fd) +{ + jint *tmpFDArray = (*env)->GetIntArrayElements(env, fdArray, 0); + int size = (*env)->GetArrayLength(env, fdArray); + int index, fd; + + for( index = 0; index < size; index++) + { + fd = tmpFDArray [index]; + + if (fd > 0) + { + FD_SET (tmpFDArray [index], fds); + + if (tmpFDArray [index] > (*max_fd)) + (*max_fd) = tmpFDArray [index]; + } + } +} + +void +helper_get_filedescriptors (JNIEnv *env, jintArray* fdArray, fd_set *fds) +{ + jint *tmpFDArray = (*env)->GetIntArrayElements(env, fdArray, 0); + int size = (*env)->GetArrayLength(env, fdArray); + int index, fd; + + for (index = 0; index < size; index++) + { + fd = tmpFDArray [index]; + if (fd < 0 || !FD_ISSET (fd, fds)) + tmpFDArray [index] = 0; + } +} + +void +helper_reset (JNIEnv *env, jintArray* fdArray) +{ + jint* tmpFDArray = (*env)->GetIntArrayElements(env, fdArray, 0); + int size = (*env)->GetArrayLength(env, fdArray); + int index; + + for (index = 0; index < size; index++) + tmpFDArray [index] = 0; +} + +/* A wrapper for select() which ignores EINTR. + * Taken from gclib's posix.cc + */ +int +helper_select (JNIEnv *env, jclass thread_class, jmethodID thread_interrupted, + int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, + struct timeval *timeout) +{ +#ifdef HAVE_SYS_SELECT_H + /* If we have a timeout, compute the absolute ending time. */ + struct timeval end, delay, after; + int r; + + if (timeout) + { + gettimeofday (&end, NULL); + + end.tv_usec += timeout->tv_usec; + + if (end.tv_usec >= 1000000) + { + ++end.tv_sec; + end.tv_usec -= 1000000; + } + + end.tv_sec += timeout->tv_sec; + delay = *timeout; + } + else + { + /* Placate compiler. */ + delay.tv_sec = delay.tv_usec = 0; + } + + while (1) + { + r = select (n, readfds, writefds, exceptfds, + timeout ? &delay : NULL); + + if (r != -1 || errno != EINTR) + return r; + + /* Here we know we got EINTR. */ + if ( (*env)->CallStaticBooleanMethod(env, thread_class, thread_interrupted) ) + { + return EINTR; + } + + if (timeout) + { + gettimeofday (&after, NULL); + + /* Now compute new timeout argument. */ + delay.tv_usec = end.tv_usec - after.tv_usec; + delay.tv_sec = end.tv_sec - after.tv_sec; + + if (delay.tv_usec < 0) + { + --delay.tv_sec; + delay.tv_usec += 1000000; + } + + if (delay.tv_sec < 0) + { + /* We assume that the user wants a valid select() call + * more than precise timing. So if we get a series of + * EINTR we just keep trying with delay 0 until we get a + * valid result. + */ + delay.tv_sec = 0; + } + } + } +#else /* HAVE_SYS_SELECT_H */ + return 0; +#endif + +} + +JNIEXPORT jint JNICALL +Java_gnu_java_nio_VMSelector_select (JNIEnv *env, + jclass obj __attribute__ ((__unused__)), + jintArray read, + jintArray write, + jintArray except, + jlong timeout) +{ + jint result; + jclass thread_class = (*env)->FindClass(env, "java/lang/Thread"); + jmethodID thread_current_thread = (*env)->GetStaticMethodID(env, thread_class, "currentThread", "()Ljava/lang/Thread;"); + jmethodID thread_interrupt = (*env)->GetMethodID(env, thread_class, "interrupt", "()V"); + jmethodID thread_interrupted = (*env)->GetMethodID(env, thread_class, "interrupted", "()Z"); + jobject current_thread; + int max_fd = 0; + fd_set read_fds; + fd_set write_fds; + fd_set except_fds; + struct timeval real_time_data; + struct timeval *time_data = NULL; + char message_buf[BUF_SIZE+1]; + + /* If a legal timeout value isn't given, use NULL. + * This means an infinite timeout. The specification + * also says that a zero timeout should be treated + * as infinite. Otherwise (if the timeout value is legal), + * fill our timeval struct and use it for the select. + */ + if (timeout > 0) + { + real_time_data.tv_sec = timeout / 1000; + real_time_data.tv_usec = (timeout % 1000) * 1000; + time_data = &real_time_data; + } + + /* Reset all fd_set structures */ + FD_ZERO (&read_fds); + FD_ZERO (&write_fds); + FD_ZERO (&except_fds); + + /* Fill the fd_set data structures for the _Jv_select() call. */ + helper_put_filedescriptors (env, read, &read_fds, &max_fd); + helper_put_filedescriptors (env, write, &write_fds, &max_fd); + helper_put_filedescriptors (env, except, &except_fds, &max_fd); + + /* Actually do the select */ + result = helper_select (env, thread_class, thread_interrupted, max_fd + 1, &read_fds, &write_fds, + &except_fds, time_data); + + if( result == EINTR ) { + /* The behavior of JRE 1.4.1 is that no exception is thrown + * when the thread is interrupted, but the thread's interrupt + * status is set. Clear all of our select sets and return 0, + * indicating that nothing was selected. + */ + current_thread = (*env)->CallStaticObjectMethod(env, thread_class, thread_current_thread); + (*env)->CallVoidMethod(env, current_thread, thread_interrupt); + + helper_reset (env, read); + helper_reset (env, write); + helper_reset (env, except); + + return 0; + } + + if (result < 0) + { + if( strerror_r(errno, message_buf, BUF_SIZE) ) + { + /* This would mean that message_buf was to small + * to hold the error message. + */ + JCL_ThrowException(env, "java/lang/InternalError", + "Not enough space in message buffer."); + return 0; + } + + JCL_ThrowException (env, "java/io/IOException", message_buf); + return 0; + } + + /* Set the file descriptors according to the values returned from select(). */ + helper_get_filedescriptors (env, read, &read_fds); + helper_get_filedescriptors (env, write, &write_fds); + helper_get_filedescriptors (env, except, &except_fds); + + return result; +} + _______________________________________________ kaffe mailing list kaffe@kaffe.org http://kaffe.org/cgi-bin/mailman/listinfo/kaffe