diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 7e61dadecaaaae7680c00abb47f0b5f4c38a368d..64df6b69ba7c32fc12428d798d88051a731d54f2 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,14 @@
+2006-03-09  Tom Tromey  <tromey@redhat.com>
+
+	* 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  <ddaney@avtrex.com>
 
 	* configure.ac (LD): Add AC_CHECK_TOOL for ld.
diff --git a/libjava/Makefile.in b/libjava/Makefile.in
index d9cc9b5fec072680c1a051a8df8f9950f651ef18..40f77af9a01a0ab52f968e3a2840ca7b5a7248ad 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 22cecde97c6e4442ff8765eb3e026121c6c6030f..91e7318868d31a289e2c5421e79d7ba003e168d7 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 94a528133aaad599aa763a717f56366c7fa0d401..5816efec28df0b81588993ee5e99f8e4dd250768 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 e7b42586cc42ade2e3456a3d8e8d740f03bd841e..9f4998cec6e598fbbe3bed73c8d333b8336c7978 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 7a2a10a4febcbe9cf81cff3c9e650776bf6d084f..f5bea2fa682170f9e2a265c6d309bf57e9fd2fc9 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 6f74e321def21c195e94cb7199c028fc91f46c90..891a713e2140341fa2730bec6ccfe2ce5ef1740c 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 <dirent.h> header file. */
 #undef HAVE_DIRENT_H
 
diff --git a/libjava/include/posix.h b/libjava/include/posix.h
index 28ac243e7c17983bb2d72348dedf5a66b77f5ecf..4ceb0081a184f5193840de3f3a0de712615f39b2 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 a660616ae4c834aa58dcc0ac7fb7cc84ba060c7e..3e2beabe5d350403f5de508fb165326e783db661 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 005cba1397c5f93e8ca999e634e4dde5dc51be54..8ba0e8960cbc4862ac4ce6623c1eef66150fc4b9 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.
@@ -207,6 +207,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 <code>src[srcStart]</code> ...
    * <code>src[srcStart+len-1]</code> to <code>dest[destStart]</code> ...
diff --git a/libjava/java/lang/natSystem.cc b/libjava/java/lang/natSystem.cc
index 0a4c8b9a0f78efd26c5d816689012d7c5fcc165b..42a13258daff639e51ec4537dd6c34e6befd0901 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 3b551966fca3a930f208557aa5681b143cced463..15fc9c5c3f85fdc58c4c0a5797ac8d5a6532d2f2 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 15b918fe101e87dfa2e4331167ad951838beb9fb..4922a3355567c5af021c012dbb49b413a6425dce 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 c337922d2965606f73ae7e02eea581ca501f9fcb..a0ae0f0f9cb52c1c7097f5d863fe26c5e36a22ac 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