Mercurial > hg > truffle
diff src/os/windows/vm/os_windows.cpp @ 4970:33df1aeaebbf
Merge with http://hg.openjdk.java.net/hsx/hsx24/hotspot/
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Mon, 27 Feb 2012 13:10:13 +0100 |
parents | acf7d88327fa 379b22e03c32 |
children | 18a5539bf19b |
line wrap: on
line diff
--- a/src/os/windows/vm/os_windows.cpp Fri Feb 24 18:30:42 2012 -0800 +++ b/src/os/windows/vm/os_windows.cpp Mon Feb 27 13:10:13 2012 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -132,7 +132,6 @@ // save DLL module handle, used by GetModuleFileName HINSTANCE vm_lib_handle; -static int getLastErrorString(char *buf, size_t len); BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved) { switch (reason) { @@ -820,17 +819,15 @@ } } -#define NANOS_PER_SEC CONST64(1000000000) -#define NANOS_PER_MILLISEC 1000000 jlong os::javaTimeNanos() { if (!has_performance_count) { - return javaTimeMillis() * NANOS_PER_MILLISEC; // the best we can do. + return javaTimeMillis() * NANOSECS_PER_MILLISEC; // the best we can do. } else { LARGE_INTEGER current_count; QueryPerformanceCounter(¤t_count); double current = as_long(current_count); double freq = performance_frequency; - jlong time = (jlong)((current/freq) * NANOS_PER_SEC); + jlong time = (jlong)((current/freq) * NANOSECS_PER_SEC); return time; } } @@ -846,15 +843,15 @@ info_ptr->may_skip_forward = true; } else { jlong freq = performance_frequency; - if (freq < NANOS_PER_SEC) { + if (freq < NANOSECS_PER_SEC) { // the performance counter is 64 bits and we will // be multiplying it -- so no wrap in 64 bits info_ptr->max_value = ALL_64_BITS; - } else if (freq > NANOS_PER_SEC) { + } else if (freq > NANOSECS_PER_SEC) { // use the max value the counter can reach to // determine the max value which could be returned julong max_counter = (julong)ALL_64_BITS; - info_ptr->max_value = (jlong)(max_counter / (freq / NANOS_PER_SEC)); + info_ptr->max_value = (jlong)(max_counter / (freq / NANOSECS_PER_SEC)); } else { // the performance counter is 64 bits and we will // be using it directly -- so no wrap in 64 bits @@ -1393,7 +1390,7 @@ bool os::dll_address_to_function_name(address addr, char *buf, int buflen, int *offset) { - if (Decoder::decode(addr, buf, buflen, offset) == Decoder::no_error) { + if (Decoder::decode(addr, buf, buflen, offset)) { return true; } if (offset != NULL) *offset = -1; @@ -1453,7 +1450,7 @@ return result; } - long errcode = GetLastError(); + DWORD errcode = GetLastError(); if (errcode == ERROR_MOD_NOT_FOUND) { strncpy(ebuf, "Can't find dependent libraries", ebuflen-1); ebuf[ebuflen-1]='\0'; @@ -1464,11 +1461,11 @@ // If we can read dll-info and find that dll was built // for an architecture other than Hotspot is running in // - then print to buffer "DLL was built for a different architecture" - // else call getLastErrorString to obtain system error message + // else call os::lasterror to obtain system error message // Read system error message into ebuf // It may or may not be overwritten below (in the for loop and just above) - getLastErrorString(ebuf, (size_t) ebuflen); + lasterror(ebuf, (size_t) ebuflen); ebuf[ebuflen-1]='\0'; int file_descriptor=::open(name, O_RDONLY | O_BINARY, 0); if (file_descriptor<0) @@ -1501,7 +1498,7 @@ ::close(file_descriptor); if (failed_to_get_lib_arch) { - // file i/o error - report getLastErrorString(...) msg + // file i/o error - report os::lasterror(...) msg return NULL; } @@ -1544,7 +1541,7 @@ "Didn't find runing architecture code in arch_array"); // If the architure is right - // but some other error took place - report getLastErrorString(...) msg + // but some other error took place - report os::lasterror(...) msg if (lib_arch == running_arch) { return NULL; @@ -1776,12 +1773,12 @@ // This method is a copy of JDK's sysGetLastErrorString // from src/windows/hpi/src/system_md.c -size_t os::lasterror(char *buf, size_t len) { - long errval; +size_t os::lasterror(char* buf, size_t len) { + DWORD errval; if ((errval = GetLastError()) != 0) { - /* DOS error */ - int n = (int)FormatMessage( + // DOS error + size_t n = (size_t)FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errval, @@ -1790,7 +1787,7 @@ (DWORD)len, NULL); if (n > 3) { - /* Drop final '.', CR, LF */ + // Drop final '.', CR, LF if (buf[n - 1] == '\n') n--; if (buf[n - 1] == '\r') n--; if (buf[n - 1] == '.') n--; @@ -1800,17 +1797,25 @@ } if (errno != 0) { - /* C runtime error that has no corresponding DOS error code */ - const char *s = strerror(errno); + // 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 n; } + return 0; } +int os::get_last_error() { + DWORD error = GetLastError(); + if (error == 0) + error = errno; + return (int)error; +} + // sun.misc.Signal // NOTE that this is a workaround for an apparent kernel bug where if // a signal handler for SIGBREAK is installed then that signal handler @@ -2082,7 +2087,6 @@ #elif _M_AMD64 PCONTEXT ctx = exceptionInfo->ContextRecord; address pc = (address)ctx->Rip; - NOT_PRODUCT(Events::log("idiv overflow exception at " INTPTR_FORMAT , pc)); //assert(pc[0] == 0xF7 || (pc[1] == 0xF7 && (pc[0] == 0x41 || pc[0] == 0x49)), "not an idiv opcode"); //assert((pc[1] & ~0x7) == 0xF8, "cannot handle non-register operands"); //assert((long)ctx->Rax == (long)min_jint || pc[0] == 0x49, "unexpected idiv exception"); @@ -2094,7 +2098,6 @@ #else PCONTEXT ctx = exceptionInfo->ContextRecord; address pc = (address)ctx->Eip; - NOT_PRODUCT(Events::log("idiv overflow exception at " INTPTR_FORMAT , pc)); assert(pc[0] == 0xF7, "not an idiv opcode"); assert((pc[1] & ~0x7) == 0xF8, "cannot handle non-register operands"); assert(ctx->Eax == min_jint, "unexpected idiv exception"); @@ -3131,7 +3134,7 @@ } void os::realign_memory(char *addr, size_t bytes, size_t alignment_hint) { } -void os::free_memory(char *addr, size_t bytes) { } +void os::free_memory(char *addr, size_t bytes, size_t alignment_hint) { } void os::numa_make_global(char *addr, size_t bytes) { } void os::numa_make_local(char *addr, size_t bytes, int lgrp_hint) { } bool os::numa_topology_changed() { return false; } @@ -3290,7 +3293,7 @@ // so we compress Java's ten down to seven. It would be better // if we dynamically adjusted relative priorities. -int os::java_to_os_priority[MaxPriority + 1] = { +int os::java_to_os_priority[CriticalPriority + 1] = { THREAD_PRIORITY_IDLE, // 0 Entry should never be used THREAD_PRIORITY_LOWEST, // 1 MinPriority THREAD_PRIORITY_LOWEST, // 2 @@ -3301,10 +3304,11 @@ THREAD_PRIORITY_ABOVE_NORMAL, // 7 THREAD_PRIORITY_ABOVE_NORMAL, // 8 THREAD_PRIORITY_HIGHEST, // 9 NearMaxPriority - THREAD_PRIORITY_HIGHEST // 10 MaxPriority + THREAD_PRIORITY_HIGHEST, // 10 MaxPriority + THREAD_PRIORITY_HIGHEST // 11 CriticalPriority }; -int prio_policy1[MaxPriority + 1] = { +int prio_policy1[CriticalPriority + 1] = { THREAD_PRIORITY_IDLE, // 0 Entry should never be used THREAD_PRIORITY_LOWEST, // 1 MinPriority THREAD_PRIORITY_LOWEST, // 2 @@ -3315,17 +3319,21 @@ THREAD_PRIORITY_ABOVE_NORMAL, // 7 THREAD_PRIORITY_HIGHEST, // 8 THREAD_PRIORITY_HIGHEST, // 9 NearMaxPriority - THREAD_PRIORITY_TIME_CRITICAL // 10 MaxPriority + THREAD_PRIORITY_TIME_CRITICAL, // 10 MaxPriority + THREAD_PRIORITY_TIME_CRITICAL // 11 CriticalPriority }; static int prio_init() { // If ThreadPriorityPolicy is 1, switch tables if (ThreadPriorityPolicy == 1) { int i; - for (i = 0; i < MaxPriority + 1; i++) { + for (i = 0; i < CriticalPriority + 1; i++) { os::java_to_os_priority[i] = prio_policy1[i]; } } + if (UseCriticalJavaThreadPriority) { + os::java_to_os_priority[MaxPriority] = os::java_to_os_priority[CriticalPriority] ; + } return 0; } @@ -4747,7 +4755,7 @@ fatal("corrupted C heap"); } } - int err = GetLastError(); + DWORD err = GetLastError(); if (err != ERROR_NO_MORE_ITEMS && err != ERROR_CALL_NOT_IMPLEMENTED) { fatal(err_msg("heap walk aborted with error %d", err)); } @@ -4779,45 +4787,6 @@ return EXCEPTION_CONTINUE_SEARCH; } -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; -} - - // We don't build a headless jre for Windows bool os::is_headless_jre() { return false; } @@ -4850,7 +4819,7 @@ ::mutexUnlock(&sockFnTableMutex); } -struct hostent* os::get_host_by_name(char* name) { +struct hostent* os::get_host_by_name(char* name) { if (!sock_initialized) { initSock(); } @@ -4881,39 +4850,39 @@ return 0; } -int os::connect(int fd, struct sockaddr *him, int len) { +int os::connect(int fd, struct sockaddr* him, socklen_t len) { ShouldNotReachHere(); return 0; } -int os::accept(int fd, struct sockaddr *him, int *len) { +int os::accept(int fd, struct sockaddr* him, socklen_t* len) { ShouldNotReachHere(); return 0; } -int os::sendto(int fd, char *buf, int len, int flags, - struct sockaddr *to, int tolen) { +int os::sendto(int fd, char* buf, size_t len, uint flags, + struct sockaddr* to, socklen_t tolen) { ShouldNotReachHere(); return 0; } -int os::recvfrom(int fd, char *buf, int nBytes, int flags, - sockaddr *from, int *fromlen) { +int os::recvfrom(int fd, char *buf, size_t nBytes, uint flags, + sockaddr* from, socklen_t* fromlen) { ShouldNotReachHere(); return 0; } -int os::recv(int fd, char *buf, int nBytes, int flags) { +int os::recv(int fd, char* buf, size_t nBytes, uint flags) { ShouldNotReachHere(); return 0; } -int os::send(int fd, char *buf, int nBytes, int flags) { +int os::send(int fd, char* buf, size_t nBytes, uint flags) { ShouldNotReachHere(); return 0; } -int os::raw_send(int fd, char *buf, int nBytes, int flags) { +int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) { ShouldNotReachHere(); return 0; } @@ -4933,24 +4902,24 @@ return 0; } -int os::bind(int fd, struct sockaddr *him, int len) { +int os::bind(int fd, struct sockaddr* him, socklen_t len) { ShouldNotReachHere(); return 0; } -int os::get_sock_name(int fd, struct sockaddr *him, int *len) { +int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) { ShouldNotReachHere(); return 0; } int os::get_sock_opt(int fd, int level, int optname, - char *optval, int* optlen) { + char* optval, socklen_t* optlen) { ShouldNotReachHere(); return 0; } int os::set_sock_opt(int fd, int level, int optname, - const char *optval, int optlen) { + const char* optval, socklen_t optlen) { ShouldNotReachHere(); return 0; } @@ -5364,4 +5333,3 @@ } #endif -