public static int readBytes(int fd, byte buf[], int off, int cnt, double totalWaitTime) throws VM_TimeoutException {  if (off < 0) throw new IndexOutOfBoundsException();      if (off + cnt > buf.length) cnt = buf.length - off;          VM_BootRecord bootRecord = VM_BootRecord.the_boot_record; boolean hasTimeout = (totalWaitTime >= 0.0); double lastWaitTime = hasTimeout ? VM_Time.now() : 0.0;  if (!blockingReadHack(fd))
public static int readBytes(int fd, byte buf[], int off, int cnt) { try { return readBytes(fd, buf, off, cnt, VM_ThreadEventConstants.WAIT_INFINITE); } catch (VM_TimeoutException e) { if (VM.VerifyAssertions) VM._assert(false);
  public static int readBytes(int fd, byte buf[], int off, int cnt, double totalWaitTime)    throws VM_TimeoutException {    if (off < 0)      throw new IndexOutOfBoundsException();    // trim request to fit array    // note: this behavior is the way the JDK does it (as of version 1.1.3)    // whereas the language spec says to throw IndexOutOfBounds exception...    //    if (off + cnt > buf.length)      cnt = buf.length - off;    // The canonical read loop.  Try the read repeatedly until either    //   - it succeeds,    //   - it returns EOF, or    //   - it returns with an error.    // If the read fails because it would have blocked, then    // put this thread on the IO queue, then try again if it    // looks like the fd is ready.    VM_BootRecord bootRecord = VM_BootRecord.the_boot_record;    boolean hasTimeout = (totalWaitTime >= 0.0);    double lastWaitTime = hasTimeout ? VM_Time.now() : 0.0;    if (!blockingReadHack(fd))      return -2;    for (;;) {      int rc = VM.sysCall3(bootRecord.sysReadBytesIP, fd,                         VM_Magic.objectAsAddress(buf).add(off).toInt(), cnt);      if (rc >= 0)	// Read succeeded, or EOF was reached	return rc;      else if (rc == -1) {	// Read would have blocked: put thread on IO wait queue	if (VM.VerifyAssertions) VM._assert(!hasTimeout || totalWaitTime >= 0.0);	VM_ThreadIOWaitData waitData = VM_Wait.ioWaitRead(fd, totalWaitTime);	// Did the wait time out?	if (waitData.timedOut())	  throw new VM_TimeoutException("read timed out");	// Did the file descriptor become ready?	if (!isFdReady(waitData.readFds[0]))	  // Fd not ready; presumably an error was detected while on the IO queue	  return -2;	else {	  // Fd appears to be ready, so update the wait time (if necessary)	  // and try the read again.	  if (hasTimeout) {	    double now = VM_Time.now();	    totalWaitTime -= (now - lastWaitTime);	    if (totalWaitTime < 0.0)	      throw new VM_TimeoutException("read timed out");	    lastWaitTime = now;	  }	  continue;	}      }      else	// Read returned an error	return -2;    }  }