1 /*
   2  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef OS_WINDOWS_VM_OS_WINDOWS_HPP
  26 #define OS_WINDOWS_VM_OS_WINDOWS_HPP
  27 
  28 // Win32_OS defines the interface to windows operating systems
  29 
  30 class win32 {
  31 
  32  protected:
  33   static int    _vm_page_size;
  34   static int    _vm_allocation_granularity;
  35   static int    _processor_type;
  36   static int    _processor_level;
  37   static julong _physical_memory;
  38   static size_t _default_stack_size;
  39   static bool   _is_nt;
  40   static bool   _is_windows_2003;
  41 
  42  public:
  43   // Windows-specific interface:
  44   static void   initialize_system_info();
  45   static void   setmode_streams();
  46 
  47   // Processor info as provided by NT
  48   static int processor_type()  { return _processor_type;  }
  49   // Processor level may not be accurate on non-NT systems
  50   static int processor_level() {
  51     assert(is_nt(), "use vm_version instead");
  52     return _processor_level;
  53   }
  54   static julong available_memory();
  55   static julong physical_memory() { return _physical_memory; }
  56 
  57  public:
  58   // Generic interface:
  59 
  60   // Trace number of created threads
  61   static          intx  _os_thread_limit;
  62   static volatile intx  _os_thread_count;
  63 
  64   // Tells whether the platform is NT or Windown95
  65   static bool is_nt() { return _is_nt; }
  66 
  67   // Tells whether the platform is Windows 2003
  68   static bool is_windows_2003() { return _is_windows_2003; }
  69 
  70   // Returns the byte size of a virtual memory page
  71   static int vm_page_size() { return _vm_page_size; }
  72 
  73   // Returns the size in bytes of memory blocks which can be allocated.
  74   static int vm_allocation_granularity() { return _vm_allocation_granularity; }
  75 
  76   // Read the headers for the executable that started the current process into
  77   // the structure passed in (see winnt.h).
  78   static void read_executable_headers(PIMAGE_NT_HEADERS);
  79 
  80   // Default stack size for the current process.
  81   static size_t default_stack_size() { return _default_stack_size; }
  82 
  83 #ifndef _WIN64
  84   // A wrapper to install a structured exception handler for fast JNI accesors.
  85   static address fast_jni_accessor_wrapper(BasicType);
  86 #endif
  87 
  88   // filter function to ignore faults on serializations page
  89   static LONG WINAPI serialize_fault_filter(struct _EXCEPTION_POINTERS* e);
  90 };
  91 
  92 class PlatformEvent : public CHeapObj {
  93   private:
  94     double CachePad [4] ;   // increase odds that _Event is sole occupant of cache line
  95     volatile int _Event ;
  96     HANDLE _ParkHandle ;
  97 
  98   public:       // TODO-FIXME: make dtor private
  99     ~PlatformEvent() { guarantee (0, "invariant") ; }
 100 
 101   public:
 102     PlatformEvent() {
 103       _Event   = 0 ;
 104       _ParkHandle = CreateEvent (NULL, false, false, NULL) ;
 105       guarantee (_ParkHandle != NULL, "invariant") ;
 106     }
 107 
 108     // Exercise caution using reset() and fired() - they may require MEMBARs
 109     void reset() { _Event = 0 ; }
 110     int  fired() { return _Event; }
 111     void park () ;
 112     void unpark () ;
 113     int  park (jlong millis) ;
 114 } ;
 115 
 116 
 117 
 118 class PlatformParker : public CHeapObj {
 119   protected:
 120     HANDLE _ParkEvent ;
 121 
 122   public:
 123     ~PlatformParker () { guarantee (0, "invariant") ; }
 124     PlatformParker  () {
 125       _ParkEvent = CreateEvent (NULL, true, false, NULL) ;
 126       guarantee (_ParkEvent != NULL, "invariant") ;
 127     }
 128 
 129 } ;
 130 
 131 #endif // OS_WINDOWS_VM_OS_WINDOWS_HPP