From c44de8ab02bf815fb920a2e6f1e6e16aadf05b07 Mon Sep 17 00:00:00 2001 From: tromey Date: Thu, 9 Mar 2006 18:47:54 +0000 Subject: [PATCH] * win32.cc (_Jv_platform_nanotime): New function. * include/win32.h (_Jv_platform_nanotime): Declare. * posix.cc (_Jv_platform_nanotime): New function. * include/posix.h (_Jv_platform_nanotime): Declare. * java/lang/natSystem.cc (nanoTime): New method. * java/lang/System.java (nanoTime): Declare. * include/config.h.in, configure: Rebuilt. * configure.ac: Check for clock_gettime. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@111869 138bc75d-0d04-0410-961f-82ee72b054a4 --- libjava/ChangeLog | 11 ++++++ libjava/Makefile.in | 4 ++ libjava/configure | 84 ++++++++++++++++++++++++++++++++++++++++++ libjava/configure.ac | 8 ++++ libjava/gcj/Makefile.in | 4 ++ libjava/include/Makefile.in | 4 ++ libjava/include/config.h.in | 3 ++ libjava/include/posix.h | 3 +- libjava/include/win32.h | 3 +- libjava/java/lang/System.java | 11 +++++- libjava/java/lang/natSystem.cc | 8 +++- libjava/posix.cc | 18 ++++++++- libjava/testsuite/Makefile.in | 4 ++ libjava/win32.cc | 8 +++- 14 files changed, 167 insertions(+), 6 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 7e61dadecaa..64df6b69ba7 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,14 @@ +2006-03-09 Tom Tromey + + * win32.cc (_Jv_platform_nanotime): New function. + * include/win32.h (_Jv_platform_nanotime): Declare. + * posix.cc (_Jv_platform_nanotime): New function. + * include/posix.h (_Jv_platform_nanotime): Declare. + * java/lang/natSystem.cc (nanoTime): New method. + * java/lang/System.java (nanoTime): Declare. + * include/config.h.in, configure: Rebuilt. + * configure.ac: Check for clock_gettime. + 2006-03-08 David Daney * configure.ac (LD): Add AC_CHECK_TOOL for ld. diff --git a/libjava/Makefile.in b/libjava/Makefile.in index d9cc9b5fec0..40f77af9a01 100644 --- a/libjava/Makefile.in +++ b/libjava/Makefile.in @@ -469,7 +469,10 @@ JAVA_HOME = @JAVA_HOME@ JAVA_HOME_SET_FALSE = @JAVA_HOME_SET_FALSE@ JAVA_HOME_SET_TRUE = @JAVA_HOME_SET_TRUE@ JC1GCSPEC = @JC1GCSPEC@ +LD = @LD@ LDFLAGS = @LDFLAGS@ +LD_FINISH_STATIC_SPEC = @LD_FINISH_STATIC_SPEC@ +LD_START_STATIC_SPEC = @LD_START_STATIC_SPEC@ LIBART_CFLAGS = @LIBART_CFLAGS@ LIBART_LIBS = @LIBART_LIBS@ LIBFFI = @LIBFFI@ @@ -562,6 +565,7 @@ ac_ct_AS = @ac_ct_AS@ ac_ct_CC = @ac_ct_CC@ ac_ct_CXX = @ac_ct_CXX@ ac_ct_GCJ = @ac_ct_GCJ@ +ac_ct_LD = @ac_ct_LD@ ac_ct_RANLIB = @ac_ct_RANLIB@ ac_ct_STRIP = @ac_ct_STRIP@ am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ diff --git a/libjava/configure b/libjava/configure index 22cecde97c6..91e7318868d 100755 --- a/libjava/configure +++ b/libjava/configure @@ -12377,6 +12377,90 @@ fi fi done + + echo "$as_me:$LINENO: checking for clock_gettime in -lrt" >&5 +echo $ECHO_N "checking for clock_gettime in -lrt... $ECHO_C" >&6 +if test "${ac_cv_lib_rt_clock_gettime+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lrt $LIBS" +if test x$gcc_no_link = xyes; then + { { echo "$as_me:$LINENO: error: Link tests are not allowed after GCC_NO_EXECUTABLES." >&5 +echo "$as_me: error: Link tests are not allowed after GCC_NO_EXECUTABLES." >&2;} + { (exit 1); exit 1; }; } +fi +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char clock_gettime (); +int +main () +{ +clock_gettime (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_lib_rt_clock_gettime=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_lib_rt_clock_gettime=no +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +echo "$as_me:$LINENO: result: $ac_cv_lib_rt_clock_gettime" >&5 +echo "${ECHO_T}$ac_cv_lib_rt_clock_gettime" >&6 +if test $ac_cv_lib_rt_clock_gettime = yes; then + + +cat >>confdefs.h <<\_ACEOF +#define HAVE_CLOCK_GETTIME 1 +_ACEOF + + case "$THREADSPEC" in + *-lrt*) ;; + *) THREADSPEC="$THREADSPEC -lrt" ;; + esac +fi + + LIBS="$save_LIBS" # We can save a little space at runtime if the mutex has m_count diff --git a/libjava/configure.ac b/libjava/configure.ac index 94a528133aa..5816efec28d 100644 --- a/libjava/configure.ac +++ b/libjava/configure.ac @@ -1016,6 +1016,14 @@ else AC_DEFINE(HAVE_SCHED_YIELD) THREADLIBS="$THREADLIBS -lposix4" THREADSPEC="$THREADSPEC -lposix4"])])]) + + AC_CHECK_LIB(rt, clock_gettime, [ + AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [Define if you have clock_gettime()]) + case "$THREADSPEC" in + *-lrt*) ;; + *) THREADSPEC="$THREADSPEC -lrt" ;; + esac]) + LIBS="$save_LIBS" # We can save a little space at runtime if the mutex has m_count diff --git a/libjava/gcj/Makefile.in b/libjava/gcj/Makefile.in index e7b42586cc4..9f4998cec6e 100644 --- a/libjava/gcj/Makefile.in +++ b/libjava/gcj/Makefile.in @@ -142,7 +142,10 @@ JAVA_HOME = @JAVA_HOME@ JAVA_HOME_SET_FALSE = @JAVA_HOME_SET_FALSE@ JAVA_HOME_SET_TRUE = @JAVA_HOME_SET_TRUE@ JC1GCSPEC = @JC1GCSPEC@ +LD = @LD@ LDFLAGS = @LDFLAGS@ +LD_FINISH_STATIC_SPEC = @LD_FINISH_STATIC_SPEC@ +LD_START_STATIC_SPEC = @LD_START_STATIC_SPEC@ LIBART_CFLAGS = @LIBART_CFLAGS@ LIBART_LIBS = @LIBART_LIBS@ LIBFFI = @LIBFFI@ @@ -235,6 +238,7 @@ ac_ct_AS = @ac_ct_AS@ ac_ct_CC = @ac_ct_CC@ ac_ct_CXX = @ac_ct_CXX@ ac_ct_GCJ = @ac_ct_GCJ@ +ac_ct_LD = @ac_ct_LD@ ac_ct_RANLIB = @ac_ct_RANLIB@ ac_ct_STRIP = @ac_ct_STRIP@ am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ diff --git a/libjava/include/Makefile.in b/libjava/include/Makefile.in index 7a2a10a4feb..f5bea2fa682 100644 --- a/libjava/include/Makefile.in +++ b/libjava/include/Makefile.in @@ -141,7 +141,10 @@ JAVA_HOME = @JAVA_HOME@ JAVA_HOME_SET_FALSE = @JAVA_HOME_SET_FALSE@ JAVA_HOME_SET_TRUE = @JAVA_HOME_SET_TRUE@ JC1GCSPEC = @JC1GCSPEC@ +LD = @LD@ LDFLAGS = @LDFLAGS@ +LD_FINISH_STATIC_SPEC = @LD_FINISH_STATIC_SPEC@ +LD_START_STATIC_SPEC = @LD_START_STATIC_SPEC@ LIBART_CFLAGS = @LIBART_CFLAGS@ LIBART_LIBS = @LIBART_LIBS@ LIBFFI = @LIBFFI@ @@ -234,6 +237,7 @@ ac_ct_AS = @ac_ct_AS@ ac_ct_CC = @ac_ct_CC@ ac_ct_CXX = @ac_ct_CXX@ ac_ct_GCJ = @ac_ct_GCJ@ +ac_ct_LD = @ac_ct_LD@ ac_ct_RANLIB = @ac_ct_RANLIB@ ac_ct_STRIP = @ac_ct_STRIP@ am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ diff --git a/libjava/include/config.h.in b/libjava/include/config.h.in index 6f74e321def..891a713e214 100644 --- a/libjava/include/config.h.in +++ b/libjava/include/config.h.in @@ -61,6 +61,9 @@ /* Define to 1 if you have the `chmod' function. */ #undef HAVE_CHMOD +/* Define if you have clock_gettime() */ +#undef HAVE_CLOCK_GETTIME + /* Define to 1 if you have the header file. */ #undef HAVE_DIRENT_H diff --git a/libjava/include/posix.h b/libjava/include/posix.h index 28ac243e7c1..4ceb0081a18 100644 --- a/libjava/include/posix.h +++ b/libjava/include/posix.h @@ -1,6 +1,6 @@ // posix.h -- Helper functions for POSIX-flavored OSs. -/* Copyright (C) 2000, 2002, 2003 Free Software Foundation +/* Copyright (C) 2000, 2002, 2003, 2006 Free Software Foundation This file is part of libgcj. @@ -79,6 +79,7 @@ details. */ extern int _Jv_select (int n, fd_set *, fd_set *, fd_set *, struct timeval *); extern jlong _Jv_platform_gettimeofday (); +extern jlong _Jv_platform_nanotime (); extern void _Jv_platform_initialize (void); extern void _Jv_platform_initProperties (java::util::Properties*); diff --git a/libjava/include/win32.h b/libjava/include/win32.h index a660616ae4c..3e2beabe5d3 100644 --- a/libjava/include/win32.h +++ b/libjava/include/win32.h @@ -1,6 +1,6 @@ // win32.h -- Helper functions for Microsoft-flavored OSs. -/* Copyright (C) 2002, 2003 Free Software Foundation +/* Copyright (C) 2002, 2003, 2006 Free Software Foundation This file is part of libgcj. @@ -154,6 +154,7 @@ _Jv_ThrowSocketException (); extern void _Jv_platform_initialize (void); extern void _Jv_platform_initProperties (java::util::Properties*); extern jlong _Jv_platform_gettimeofday (); +extern jlong _Jv_platform_nanotime (); extern int _Jv_pipe (int filedes[2]); extern void diff --git a/libjava/java/lang/System.java b/libjava/java/lang/System.java index 005cba1397c..8ba0e8960cb 100644 --- a/libjava/java/lang/System.java +++ b/libjava/java/lang/System.java @@ -1,5 +1,5 @@ /* System.java -- useful methods to interface with the system - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -208,6 +208,15 @@ public final class System public static native long currentTimeMillis(); /** + * Get the current time, measured in nanoseconds. The result is as + * precise as possible, and is measured against a fixed epoch. + * However, unlike currentTimeMillis(), the epoch chosen is + * arbitrary and may vary by platform, etc. + * @since 1.5 + */ + public static native long nanoTime(); + + /** * Copy one array onto another from src[srcStart] ... * src[srcStart+len-1] to dest[destStart] ... * dest[destStart+len-1]. First, the arguments are validated: diff --git a/libjava/java/lang/natSystem.cc b/libjava/java/lang/natSystem.cc index 0a4c8b9a0f7..42a13258daf 100644 --- a/libjava/java/lang/natSystem.cc +++ b/libjava/java/lang/natSystem.cc @@ -1,6 +1,6 @@ // natSystem.cc - Native code implementing System class. -/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation +/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2006 Free Software Foundation This file is part of libgcj. @@ -124,6 +124,12 @@ java::lang::System::currentTimeMillis (void) return _Jv_platform_gettimeofday (); } +jlong +java::lang::System::nanoTime () +{ + return _Jv_platform_nanotime (); +} + jint java::lang::System::identityHashCode (jobject obj) { diff --git a/libjava/posix.cc b/libjava/posix.cc index 3b551966fca..15fc9c5c3f8 100644 --- a/libjava/posix.cc +++ b/libjava/posix.cc @@ -1,6 +1,6 @@ // posix.cc -- Helper functions for POSIX-flavored OSs. -/* Copyright (C) 2000, 2001, 2002 Free Software Foundation +/* Copyright (C) 2000, 2001, 2002, 2006 Free Software Foundation This file is part of libgcj. @@ -66,6 +66,22 @@ _Jv_platform_gettimeofday () #endif } +jlong +_Jv_platform_nanotime () +{ +#ifdef HAVE_CLOCK_GETTIME + struct timespec now; + if (clock_gettime (CLOCK_REALTIME, &now) == 0) + { + jlong result = (jlong) now.tv_sec; + result = result * 1000 * 1000 + now.tv_nsec; + return result; + } + // clock_gettime failed, but we can fall through. +#endif // HAVE_CLOCK_GETTIME + return _Jv_platform_gettimeofday () * 1000LL; +} + // Platform-specific VM initialization. void _Jv_platform_initialize (void) diff --git a/libjava/testsuite/Makefile.in b/libjava/testsuite/Makefile.in index 15b918fe101..4922a335556 100644 --- a/libjava/testsuite/Makefile.in +++ b/libjava/testsuite/Makefile.in @@ -130,7 +130,10 @@ JAVA_HOME = @JAVA_HOME@ JAVA_HOME_SET_FALSE = @JAVA_HOME_SET_FALSE@ JAVA_HOME_SET_TRUE = @JAVA_HOME_SET_TRUE@ JC1GCSPEC = @JC1GCSPEC@ +LD = @LD@ LDFLAGS = @LDFLAGS@ +LD_FINISH_STATIC_SPEC = @LD_FINISH_STATIC_SPEC@ +LD_START_STATIC_SPEC = @LD_START_STATIC_SPEC@ LIBART_CFLAGS = @LIBART_CFLAGS@ LIBART_LIBS = @LIBART_LIBS@ LIBFFI = @LIBFFI@ @@ -223,6 +226,7 @@ ac_ct_AS = @ac_ct_AS@ ac_ct_CC = @ac_ct_CC@ ac_ct_CXX = @ac_ct_CXX@ ac_ct_GCJ = @ac_ct_GCJ@ +ac_ct_LD = @ac_ct_LD@ ac_ct_RANLIB = @ac_ct_RANLIB@ ac_ct_STRIP = @ac_ct_STRIP@ am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ diff --git a/libjava/win32.cc b/libjava/win32.cc index c337922d296..a0ae0f0f9cb 100644 --- a/libjava/win32.cc +++ b/libjava/win32.cc @@ -1,6 +1,6 @@ // win32.cc - Helper functions for Microsoft-flavored OSs. -/* Copyright (C) 2002, 2003 Free Software Foundation +/* Copyright (C) 2002, 2003, 2006 Free Software Foundation This file is part of libgcj. @@ -279,6 +279,12 @@ _Jv_platform_gettimeofday () return t.time * 1000LL + t.millitm; } +jlong +_Jv_platform_nanotime () +{ + return _Jv_platform_gettimeofday () * 1000LL; +} + // The following definitions "fake out" mingw to think that -mthreads // was enabled and that mingwthr.dll was linked. GCJ-compiled // applications don't need this helper library because we can safely -- 2.11.0