Index: /trunk/openjdk/hotspot/src/cpu/x86/vm/jniFastGetField_x86_32.cpp
===================================================================
--- /trunk/openjdk/hotspot/src/cpu/x86/vm/jniFastGetField_x86_32.cpp	(revision 57)
+++ /trunk/openjdk/hotspot/src/cpu/x86/vm/jniFastGetField_x86_32.cpp	(revision 58)
@@ -30,5 +30,5 @@
 #define BUFFER_SIZE 30
 
-#ifdef _WINDOWS
+#if defined(_WINDOWS) || defined(OS2)
 GetBooleanField_t JNI_FastGetField::jni_fast_GetBooleanField_fp;
 GetByteField_t    JNI_FastGetField::jni_fast_GetByteField_fp;
@@ -110,5 +110,5 @@
   __ jcc (Assembler::notEqual, slow);
 
-#ifndef _WINDOWS
+#if !defined(_WINDOWS) && !defined(__WIN32OS2__)
   __ ret (0);
 #else
@@ -132,5 +132,5 @@
   __ flush ();
 
-#ifndef _WINDOWS
+#if !defined(_WINDOWS) && !defined(OS2)
   return fast_entry;
 #else
@@ -227,5 +227,5 @@
   __ pop (rsi);
 
-#ifndef _WINDOWS
+#if !defined(_WINDOWS) && !defined(__WIN32OS2__)
   __ ret (0);
 #else
@@ -244,5 +244,5 @@
   __ flush ();
 
-#ifndef _WINDOWS
+#if !defined(_WINDOWS) && !defined(OS2)
   return fast_entry;
 #else
@@ -321,5 +321,5 @@
   __ jcc (Assembler::notEqual, slow_with_pop);
 
-#ifndef _WINDOWS
+#if !defined(_WINDOWS) && !defined(__WIN32OS2__)
   __ ret (0);
 #else
@@ -345,5 +345,5 @@
   __ flush ();
 
-#ifndef _WINDOWS
+#if !defined(_WINDOWS) && !defined(OS2)
   return fast_entry;
 #else
Index: /trunk/openjdk/hotspot/src/os/windows/vm/os_windows.cpp
===================================================================
--- /trunk/openjdk/hotspot/src/os/windows/vm/os_windows.cpp	(revision 57)
+++ /trunk/openjdk/hotspot/src/os/windows/vm/os_windows.cpp	(revision 58)
@@ -56,4 +56,12 @@
 #include <vdmdbg.h>
 
+#ifdef __WIN32OS2__
+#include <mmsystem.h>
+#include <wincon.h>
+#include <basetsd.h>
+#define _M_IX86
+#define _lseeki64 lseek
+#endif
+
 // for timer info max values which include all bits
 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
@@ -531,4 +539,13 @@
 
   HANDLE thread_handle =
+#ifdef __WIN32OS2__
+    // @todo probably need to cause some per-thread LIBC initialization routine
+    CreateThread(NULL,
+                 stack_size,
+                 (LPTHREAD_START_ROUTINE) java_start,
+                 thread,
+                 CREATE_SUSPENDED | STACK_SIZE_PARAM_IS_A_RESERVATION,
+                 (LPDWORD)&thread_id);
+#else
     (HANDLE)_beginthreadex(NULL,
                            (unsigned)stack_size,
@@ -536,9 +553,19 @@
                            thread,
                            CREATE_SUSPENDED | STACK_SIZE_PARAM_IS_A_RESERVATION,
-                           &thread_id);
+                           (PDWORD)&thread_id);
+#endif  
   if (thread_handle == NULL) {
     // perhaps STACK_SIZE_PARAM_IS_A_RESERVATION is not supported, try again
     // without the flag.
     thread_handle =
+#ifdef __WIN32OS2__
+    // @todo probably need to cause some per-thread LIBC initialization routine
+    CreateThread(NULL,
+                 stack_size,
+                 (LPTHREAD_START_ROUTINE) java_start,
+                 thread,
+                 CREATE_SUSPENDED,
+                 (LPDWORD)&thread_id);
+#else
     (HANDLE)_beginthreadex(NULL,
                            (unsigned)stack_size,
@@ -547,4 +574,5 @@
                            CREATE_SUSPENDED,
                            &thread_id);
+#endif  
   }
   if (thread_handle == NULL) {
@@ -621,4 +649,11 @@
 
 julong os::win32::available_memory() {
+#ifdef __WIN32OS2__
+  MEMORYSTATUS ms;
+  ms.dwLength = sizeof(ms);
+  GlobalMemoryStatus(&ms);
+
+  return ms.dwAvailPhys;
+#else    
   // Use GlobalMemoryStatusEx() because GlobalMemoryStatus() may return incorrect
   // value if total memory is larger than 4GB
@@ -628,4 +663,5 @@
 
   return (julong)ms.ullAvailPhys;
+#endif
 }
 
@@ -644,6 +680,8 @@
 
 // VC6 lacks DWORD_PTR
+#ifndef __WIN32OS2__
 #if _MSC_VER < 1300
 typedef UINT_PTR DWORD_PTR;
+#endif
 #endif
 
@@ -703,5 +741,5 @@
 
 // Constant offset - calculated using offset()
-static jlong  _offset   = 116444736000000000;
+static jlong  _offset   = 116444736000000000LL;
 // Fake time counter for reproducible results when debugging
 static jlong  fake_time = 0;
@@ -1331,5 +1369,5 @@
 
 void* os::dll_lookup(void* handle, const char* name) {
-  return GetProcAddress((HMODULE)handle, name);
+  return CAST_FROM_FN_PTR(void *, GetProcAddress((HMODULE)handle, name));
 }
 
@@ -1446,6 +1484,8 @@
   static const arch_t arch_array[]={
     {IMAGE_FILE_MACHINE_I386,      (char*)"IA 32"},
+#ifndef __WIN32OS2__
     {IMAGE_FILE_MACHINE_AMD64,     (char*)"AMD 64"},
-    {IMAGE_FILE_MACHINE_IA64,      (char*)"IA 64"}
+    {IMAGE_FILE_MACHINE_IA64,      (char*)"IA 64"},
+#endif
   };
   #if   (defined _M_IA64)
@@ -1530,4 +1570,5 @@
     case 5000: st->print(" Windows 2000"); break;
     case 5001: st->print(" Windows XP"); break;
+#ifndef __WIN32OS2__      
     case 5002:
     case 6000:
@@ -1573,4 +1614,5 @@
       break;
     }
+#endif
     default: // future windows, print out its major and minor versions
       st->print(" Windows NT %d.%d", osvi.dwMajorVersion, osvi.dwMinorVersion);
@@ -1594,4 +1636,9 @@
   st->print(" %dk page", os::vm_page_size()>>10);
 
+#ifdef __WIN32OS2__
+  MEMORYSTATUS ms;
+  ms.dwLength = sizeof(ms);
+  GlobalMemoryStatus(&ms);
+#else    
   // Use GlobalMemoryStatusEx() because GlobalMemoryStatus() may return incorrect
   // value if total memory is larger than 4GB
@@ -1599,10 +1646,16 @@
   ms.dwLength = sizeof(ms);
   GlobalMemoryStatusEx(&ms);
+#endif
 
   st->print(", physical %uk", os::physical_memory() >> 10);
   st->print("(%uk free)", os::available_memory() >> 10);
 
+#ifdef __WIN32OS2__
+  st->print(", swap %uk", ms.dwTotalPageFile >> 10);
+  st->print("(%uk free)", ms.dwAvailPageFile >> 10);
+#else    
   st->print(", swap %uk", ms.ullTotalPageFile >> 10);
   st->print("(%uk free)", ms.ullAvailPageFile >> 10);
+#endif
   st->cr();
 }
@@ -2450,4 +2503,6 @@
 }
 
+#ifndef __WIN32OS2__
+
 // Windows large page support is available on Windows 2003. In order to use
 // large page memory, the administrator must first assign additional privilege
@@ -2555,4 +2610,6 @@
 }
 
+#endif // ifndef __WIN32OS2__
+
 bool os::large_page_init() {
   if (!UseLargePages) return false;
@@ -2564,4 +2621,8 @@
 
 # define WARN(msg) if (warn_on_failure) { warning(msg); }
+
+#ifdef __WIN32OS2__
+    WARN("Large page is not supported by the operating system.");
+#else
   if (resolve_functions_for_large_page_init()) {
     if (request_lock_memory_privilege()) {
@@ -2601,4 +2662,6 @@
 
   cleanup_after_large_page_init();
+#endif // ifdef __WIN32OS2__
+
   return success;
 }
@@ -2639,5 +2702,9 @@
 
 size_t os::large_page_size() {
+#ifdef __WIN32OS2__
+  return 0;
+#else
   return _large_page_size;
+#endif
 }
 
@@ -2657,4 +2724,5 @@
   const DWORD prot = exec ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
 
+#ifndef __WIN32OS2__
   if (UseLargePagesIndividualAllocation) {
     if (TracePageSizes && Verbose) {
@@ -2751,4 +2819,10 @@
     return res;
   }
+#else // ifndef __WIN32OS2__
+  // normal policy just allocate it all at once
+  DWORD flag = MEM_RESERVE | MEM_COMMIT;
+  char * res = (char *)VirtualAlloc(NULL, bytes, flag, prot);
+  return res;
+#endif // ifndef __WIN32OS2__
 }
 
@@ -3158,4 +3232,11 @@
   _processor_count = si.dwNumberOfProcessors;
 
+#ifdef __WIN32OS2__
+  MEMORYSTATUS ms;
+  ms.dwLength = sizeof(ms);
+
+  GlobalMemoryStatus(&ms);
+  _physical_memory = ms.dwTotalPhys;
+#else    
   MEMORYSTATUSEX ms;
   ms.dwLength = sizeof(ms);
@@ -3165,4 +3246,5 @@
   GlobalMemoryStatusEx(&ms);
   _physical_memory = ms.ullTotalPhys;
+#endif
 
   OSVERSIONINFO oi;
@@ -3253,5 +3335,9 @@
   void *code_ptr = (void *)code;
   __try {
+#ifdef __EMX__
+    __asm__("call *%0" : : "m"(code_ptr));
+#else
     __asm call code_ptr
+#endif
   } __except(nx_exception_filter((_EXCEPTION_POINTERS*)_exception_info())) {
     tty->print_raw_cr("NX protection detected.");
@@ -3283,5 +3369,5 @@
   // Initialize main_process and main_thread
   main_process = GetCurrentProcess();  // Remember main_process is a pseudo handle
- if (!DuplicateHandle(main_process, GetCurrentThread(), main_process,
+  if (!DuplicateHandle(main_process, GetCurrentThread(), main_process,
                        &main_thread, THREAD_ALL_ACCESS, false, 0)) {
     fatal("DuplicateHandle failed\n");
@@ -3349,5 +3435,9 @@
 #ifndef  _WIN64
     static long fp_control_word = 0;
+#ifdef __EMX__
+    __asm__("fstcw %0" : "=m"(fp_control_word));
+#else
     __asm { fstcw fp_control_word }
+#endif    
     // see Intel PPro Manual, Vol. 2, p 7-16
     const long precision = 0x20;
@@ -3358,5 +3448,9 @@
     const long invalid   = 0x01;
     fp_control_word |= invalid;
+#ifdef __EMX__
+    __asm__("fldcw %0" : : "m"(fp_control_word));
+#else
     __asm { fldcw fp_control_word }
+#endif
 #endif
   }
Index: /trunk/openjdk/hotspot/src/os/windows/vm/perfMemory_windows.cpp
===================================================================
--- /trunk/openjdk/hotspot/src/os/windows/vm/perfMemory_windows.cpp	(revision 57)
+++ /trunk/openjdk/hotspot/src/os/windows/vm/perfMemory_windows.cpp	(revision 58)
@@ -218,4 +218,5 @@
   }
 
+#ifndef __WIN32OS2__
   if (fa & FILE_ATTRIBUTE_REPARSE_POINT) {
     // we don't accept any redirection for the user specific directory
@@ -229,4 +230,5 @@
     return false;
   }
+#endif
 
   if (fa & FILE_ATTRIBUTE_DIRECTORY) {
@@ -566,4 +568,5 @@
   }
 
+#ifndef __WIN32OS2__
   if ((flags & FS_PERSISTENT_ACLS) == 0) {
     // file system doesn't support ACLs, declare file system unsafe
@@ -583,4 +586,5 @@
     return false;
   }
+#endif
 
   return true;
@@ -744,5 +748,5 @@
   if (lpSA != NULL) {
     // free the contained security descriptor and the ACL
-    free_security_desc(lpSA->lpSecurityDescriptor);
+    free_security_desc((PSECURITY_DESCRIPTOR)lpSA->lpSecurityDescriptor);
     lpSA->lpSecurityDescriptor = NULL;
 
@@ -801,5 +805,5 @@
 
   DWORD nbytes = GetLengthSid(token_buf->User.Sid);
-  PSID pSID = NEW_C_HEAP_ARRAY(char, nbytes);
+  PSID pSID = (PSID)NEW_C_HEAP_ARRAY(char, nbytes);
 
   if (!CopySid(nbytes, pSID, token_buf->User.Sid)) {
@@ -926,5 +930,5 @@
       int matches = 0;
       for (int i = 0; i < ace_count; i++) {
-        if (EqualSid(aces[i].pSid, &(((ACCESS_ALLOWED_ACE *)ace)->SidStart))) {
+        if (EqualSid(aces[i].pSid, (PSID)&(((ACCESS_ALLOWED_ACE *)ace)->SidStart))) {
           matches++;
           break;
@@ -995,4 +999,5 @@
   }
 
+#ifndef __WIN32OS2__
   // if running on windows 2000 or later, set the automatic inheritance
   // control flags.
@@ -1015,4 +1020,5 @@
     }
   }
+#endif  
    // Note, the security descriptor maintains a reference to the newACL, not
    // a copy of it. Therefore, the newACL is not freed here. It is freed when
@@ -1226,5 +1232,6 @@
       // DACLs might fix the corrupted the DACLs.
       SECURITY_INFORMATION secInfo = DACL_SECURITY_INFORMATION;
-      if (!SetFileSecurity(dirname, secInfo, pDirSA->lpSecurityDescriptor)) {
+      if (!SetFileSecurity(dirname, secInfo,
+                          (PSECURITY_DESCRIPTOR)pDirSA->lpSecurityDescriptor)) {
         if (PrintMiscellaneous && Verbose) {
           lasterror = GetLastError();
Index: /trunk/openjdk/hotspot/src/os_cpu/windows_x86/vm/os_windows_x86.cpp
===================================================================
--- /trunk/openjdk/hotspot/src/os_cpu/windows_x86/vm/os_windows_x86.cpp	(revision 57)
+++ /trunk/openjdk/hotspot/src/os_cpu/windows_x86/vm/os_windows_x86.cpp	(revision 58)
@@ -58,4 +58,10 @@
     if ( ThreadLocalStorage::get_thread_ptr_offset() == 0 ) {
       int thread_ptr_offset;
+#ifdef __EMX__
+      __asm__("leal %1, %%eax; "
+              "subl %%fs:0, %%eax; "
+              "movl %%eax, %0; "
+              : "=m"(thread_ptr_offset) : "m"(wrapperthread) : "%eax");
+#else
       __asm {
         lea eax, dword ptr wrapperthread;
@@ -63,4 +69,5 @@
         mov thread_ptr_offset, eax
       };
+#endif      
       ThreadLocalStorage::set_thread_ptr_offset(thread_ptr_offset);
     }
@@ -71,4 +78,10 @@
     else {
       int test_thread_ptr_offset;
+#ifdef __EMX__
+      __asm__("leal %1, %%eax; "
+              "subl %%fs:0, %%eax; "
+              "movl %%eax, %0; "
+              : "=m"(test_thread_ptr_offset) : "m"(wrapperthread) : "%eax");
+#else
       __asm {
         lea eax, dword ptr wrapperthread;
@@ -76,4 +89,5 @@
         mov test_thread_ptr_offset, eax
       };
+#endif
       assert(test_thread_ptr_offset == ThreadLocalStorage::get_thread_ptr_offset(),
              "thread pointer offset from SEH changed");
@@ -340,7 +354,11 @@
 intptr_t* _get_previous_fp() {
   intptr_t **frameptr;
+#ifdef __EMX__
+  __asm("movl %%ebp, %0" : "=m"(frameptr));
+#else
   __asm {
     mov frameptr, ebp
   };
+#endif  
   return *frameptr;
 }
@@ -423,5 +441,5 @@
 extern "C" int SafeFetch32 (int * adr, int Err) {
    int rv = Err ;
-   _try {
+   __try {
        rv = *((volatile int *) adr) ;
    } __except(EXCEPTION_EXECUTE_HANDLER) {
@@ -432,5 +450,5 @@
 extern "C" intptr_t SafeFetchN (intptr_t * adr, intptr_t Err) {
    intptr_t rv = Err ;
-   _try {
+   __try {
        rv = *((volatile intptr_t *) adr) ;
    } __except(EXCEPTION_EXECUTE_HANDLER) {
@@ -446,7 +464,11 @@
    // On systems that don't support pause a rep:nop
    // is executed as a nop.  The rep: prefix is ignored.
+#ifdef __EMX__
+   __asm__("pause; ");
+#else
    _asm {
       pause ;
    };
+#endif
    return 1 ;
 #endif // AMD64
@@ -457,5 +479,9 @@
 #ifndef AMD64
   int fpu_cntrl_word = StubRoutines::fpu_cntrl_wrd_std();
+#ifdef __EMX__
+  __asm__("fldcw %0; " : : "m"(fpu_cntrl_word));
+#else  
   __asm fldcw fpu_cntrl_word;
+#endif  
 #endif // !AMD64
 }
Index: /trunk/openjdk/hotspot/src/share/vm/prims/forte.cpp
===================================================================
--- /trunk/openjdk/hotspot/src/share/vm/prims/forte.cpp	(revision 57)
+++ /trunk/openjdk/hotspot/src/share/vm/prims/forte.cpp	(revision 58)
@@ -618,5 +618,5 @@
 
 
-#ifndef _WINDOWS
+#if !defined(_WINDOWS) && !defined(OS2)
 // Support for the Forte(TM) Peformance Tools collector.
 //
@@ -637,5 +637,5 @@
 #define collector_func_load(x0,x1,x2,x3,x4,x5,x6) \
         ( collector_func_load ? collector_func_load(x0,x1,x2,x3,x4,x5,x6),0 : 0 )
-#endif // !_WINDOWS
+#endif // !_WINDOWS && !OS2
 
 } // end extern "C"
@@ -643,5 +643,5 @@
 
 void Forte::register_stub(const char* name, address start, address end) {
-#if !defined(_WINDOWS) && !defined(IA64)
+#if !defined(_WINDOWS) && !defined(OS2) && !defined(IA64)
   assert(pointer_delta(end, start, sizeof(jbyte)) < INT_MAX,
     "Code size exceeds maximum range")
@@ -649,4 +649,4 @@
   collector_func_load((char*)name, NULL, NULL, start,
     pointer_delta(end, start, sizeof(jbyte)), 0, NULL);
-#endif // !_WINDOWS && !IA64
-}
+#endif // !_WINDOWS && !OS2 && !IA64
+}
Index: /trunk/openjdk/hotspot/src/share/vm/prims/jniFastGetField.hpp
===================================================================
--- /trunk/openjdk/hotspot/src/share/vm/prims/jniFastGetField.hpp	(revision 57)
+++ /trunk/openjdk/hotspot/src/share/vm/prims/jniFastGetField.hpp	(revision 58)
@@ -61,5 +61,5 @@
 
  public:
-#if defined(_WINDOWS) && !defined(_WIN64)
+#if (defined(_WINDOWS) && !defined(_WIN64)) || defined(OS2)
   static GetBooleanField_t jni_fast_GetBooleanField_fp;
   static GetByteField_t    jni_fast_GetByteField_fp;
Index: /trunk/openjdk/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp
===================================================================
--- /trunk/openjdk/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp	(revision 57)
+++ /trunk/openjdk/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp	(revision 58)
@@ -82,7 +82,39 @@
 
 #ifdef OS2
+#include <sys/types.h>
 #ifdef __WIN32OS2__
 #include <excpt.h>
+// compiler's select() would conflict with Winsock
+#define select __io_select
 #include <io.h>
+#undef select
+#ifdef __EMX__
+// we disable BSD visibility for the compiler so define these manually
+int	finite(double) __pure2;
+int	isnanf(float) __pure2;
+#define S_IREAD     S_IRUSR
+#define S_IWRITE    S_IWUSR
+#define S_IEXEC     S_IXUSR
+#include <alloca.h> // <stdlib.h> defines alloca only in BSD mode
+#endif
+#else // __WIN32OS2__
+#include <io.h>
+#endif // __WIN32OS2__
+#ifdef __EMX__
+#include <strings.h> // strcasecmp()
+// EMX doesn't provide some ANSI declarations
+#define _alloca     alloca
+#define _fileno     fileno
+#define _O_BINARY   O_BINARY
+#define _O_TEXT     O_TEXT
+#define _O_CREAT    O_CREAT
+#define _O_TRUNC    O_TRUNC
+#define _O_EXCL     O_TRUNC
+#define _O_WRONLY   O_WRONLY
+#define _O_RDONLY   O_RDONLY
+#define _O_RDWR     O_RDWR
+#define _S_IREAD    S_IREAD
+#define _S_IWRITE   S_IWRITE
+#define _S_IEXEC    S_IEXEC
 #endif
 #endif // OS2
Index: /trunk/openjdk/hotspot/src/share/vm/utilities/ostream.cpp
===================================================================
--- /trunk/openjdk/hotspot/src/share/vm/utilities/ostream.cpp	(revision 57)
+++ /trunk/openjdk/hotspot/src/share/vm/utilities/ostream.cpp	(revision 58)
@@ -835,4 +835,8 @@
 #endif
 
+#ifdef __WIN32OS2__
+#include <winsock.h>
+#endif
+
 // Network access
 networkStream::networkStream() : bufferedStream(1024*10, 1024*10) {
