< prev index next >

src/os/windows/vm/os_windows.cpp

Print this page




3086 #endif
3087     } else {
3088       WARN("Large page is not supported by the processor.");
3089     }
3090   } else {
3091     WARN("JVM cannot use large page memory because it does not have enough privilege to lock pages in memory.");
3092   }
3093 #undef WARN
3094 
3095   const size_t default_page_size = (size_t) vm_page_size();
3096   if (success && _large_page_size > default_page_size) {
3097     _page_sizes[0] = _large_page_size;
3098     _page_sizes[1] = default_page_size;
3099     _page_sizes[2] = 0;
3100   }
3101 
3102   cleanup_after_large_page_init();
3103   UseLargePages = success;
3104 }
3105 





























































3106 // On win32, one cannot release just a part of reserved memory, it's an
3107 // all or nothing deal.  When we split a reservation, we must break the
3108 // reservation into two reservations.
3109 void os::pd_split_reserved_memory(char *base, size_t size, size_t split,
3110                                   bool realloc) {
3111   if (size > 0) {
3112     release_memory(base, size);
3113     if (realloc) {
3114       reserve_memory(split, base);
3115     }
3116     if (size != split) {
3117       reserve_memory(size - split, base + split);
3118     }
3119   }
3120 }
3121 
3122 // Multiple threads can race in this code but it's not possible to unmap small sections of
3123 // virtual space to get requested alignment, like posix-like os's.
3124 // Windows prevents multiple thread from remapping over each other so this loop is thread-safe.
3125 char* os::reserve_memory_aligned(size_t size, size_t alignment) {




3086 #endif
3087     } else {
3088       WARN("Large page is not supported by the processor.");
3089     }
3090   } else {
3091     WARN("JVM cannot use large page memory because it does not have enough privilege to lock pages in memory.");
3092   }
3093 #undef WARN
3094 
3095   const size_t default_page_size = (size_t) vm_page_size();
3096   if (success && _large_page_size > default_page_size) {
3097     _page_sizes[0] = _large_page_size;
3098     _page_sizes[1] = default_page_size;
3099     _page_sizes[2] = 0;
3100   }
3101 
3102   cleanup_after_large_page_init();
3103   UseLargePages = success;
3104 }
3105 
3106 // Helper function to create a temp file in the given directory
3107 int os::create_tmpfile(const char* dir, size_t size, bool exec) {
3108 
3109   char name_template[] = "/jvmheap.XXXXXX";
3110 
3111   char *fullname = (char*)alloca(strlen(dir) + sizeof(name_template));
3112   (void)strcpy(fullname, dir);
3113   (void)strcat(fullname, name_template);
3114   os::native_path(fullname);
3115 
3116   char *path = _mktemp(fullname);
3117   if (path == NULL)
3118     return -1;
3119 
3120   int fd = _open(path, O_RDWR | O_CREAT | O_EXCL, S_IWRITE | S_IREAD);
3121 
3122   if (fd < 0) {
3123     warning("Could not create file for heap");
3124     return -1;
3125   }
3126 
3127   // delete the name from the filesystem. When 'fd' is closed, the file (and space) will be deleted
3128   _unlink(fullname);
3129 
3130   // allocate space for the file
3131   if (_chsize(fd, (long)size) != 0) {
3132     warning("Could not allocate sufficient disk space for heap");
3133     return -1;
3134   }
3135 
3136   return fd;
3137 }
3138 
3139 // Map the given address range to a temporary file created at the specified directory.
3140 // The address range must already be reserved for guaranteed success. If it not reserved, their could be an error while mapping leading to JVM shutdown
3141 bool os::map_memory_to_file(char* base, size_t size, const char* backingFileDir) {
3142 
3143   int fd = os::create_tmpfile(backingFileDir, size, false);
3144   if (fd == -1) {
3145     vm_exit_during_initialization(err_msg("Could not create temporary file in %s for object heap", backingFileDir));
3146     return false;
3147   }
3148 
3149   HANDLE fh = (HANDLE)_get_osfhandle(fd);
3150   HANDLE fileMapping = CreateFileMapping(fh, NULL, PAGE_READWRITE,
3151                                          (DWORD)(size >> 32), (DWORD)(size & 0xFFFFFFFF), NULL);
3152   if (fileMapping == NULL)
3153     return false;
3154 
3155   // release the memory address range and map again at the same address 
3156   pd_release_memory(base, size);
3157   LPVOID addr = MapViewOfFileEx(fileMapping, FILE_MAP_WRITE, 0, 0, size, base);
3158 
3159   if (addr == NULL || addr != base) {
3160     CloseHandle(fileMapping);
3161     return false;
3162   }
3163 
3164   return true;
3165 }
3166 
3167 // On win32, one cannot release just a part of reserved memory, it's an
3168 // all or nothing deal.  When we split a reservation, we must break the
3169 // reservation into two reservations.
3170 void os::pd_split_reserved_memory(char *base, size_t size, size_t split,
3171                                   bool realloc) {
3172   if (size > 0) {
3173     release_memory(base, size);
3174     if (realloc) {
3175       reserve_memory(split, base);
3176     }
3177     if (size != split) {
3178       reserve_memory(size - split, base + split);
3179     }
3180   }
3181 }
3182 
3183 // Multiple threads can race in this code but it's not possible to unmap small sections of
3184 // virtual space to get requested alignment, like posix-like os's.
3185 // Windows prevents multiple thread from remapping over each other so this loop is thread-safe.
3186 char* os::reserve_memory_aligned(size_t size, size_t alignment) {


< prev index next >