JDK-7126185 : Clean up lasterror handling, add os::get_last_error()
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: hs23
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-12-30
  • Updated: 2012-03-29
  • Resolved: 2012-03-29
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8 Other
7u4Fixed 8Fixed hs23Fixed
Description
In os_windows.cpp, os::lasterror and getLastErrorString are identical.  The
latter should be eliminated.  In addition, Java Flight Recorder uses errno
and its Windows equivalent for error reporting, so add os::get_last_error()
to retrieve it.

Comments
EVALUATION http://hg.openjdk.java.net/lambda/lambda/hotspot/rev/b16494a69d3d
22-03-2012

EVALUATION http://hg.openjdk.java.net/hsx/hotspot-main/hotspot/rev/b16494a69d3d
07-01-2012

EVALUATION http://hg.openjdk.java.net/hsx/hotspot-rt/hotspot/rev/b16494a69d3d
04-01-2012

EVALUATION Ok.
30-12-2011

SUGGESTED FIX > diff os.hpp 503d502 < static int get_last_error(); > diff os_posix.cpp 62,65d61 < int os::get_last_error() { < return errno; < } < > diff os_windows.cpp 134a135 > static int getLastErrorString(char *buf, size_t len); 1465c1466 < // else call os::lasterror to obtain system error message --- > // else call getLastErrorString to obtain system error message 1469c1470 < lasterror(ebuf, (size_t) ebuflen); --- > getLastErrorString(ebuf, (size_t) ebuflen); 1502c1503 < // file i/o error - report os::lasterror(...) msg --- > // file i/o error - report getLastErrorString(...) msg 1545c1546 < // but some other error took place - report os::lasterror(...) msg --- > // but some other error took place - report getLastErrorString(...) msg 1812,1818d1812 < int os::get_last_error() { < int error = GetLastError(); < if (error == 0) < error = errno; < return error; < } < 4786a4781,4819 > static int getLastErrorString(char *buf, size_t len) > { > long errval; > > if ((errval = GetLastError()) != 0) > { > /* DOS error */ > size_t n = (size_t)FormatMessage( > FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, > NULL, > errval, > 0, > buf, > (DWORD)len, > NULL); > if (n > 3) { > /* Drop final '.', CR, LF */ > if (buf[n - 1] == '\n') n--; > if (buf[n - 1] == '\r') n--; > if (buf[n - 1] == '.') n--; > buf[n] = '\0'; > } > return (int)n; > } > > if (errno != 0) > { > /* C runtime error that has no corresponding DOS error code */ > const char *s = strerror(errno); > size_t n = strlen(s); > if (n >= len) n = len - 1; > strncpy(buf, s, n); > buf[n] = '\0'; > return (int)n; > } > return 0; > } > >
30-12-2011