< prev index next >

src/os/windows/vm/os_windows.cpp

Print this page

        

*** 3101,3110 **** --- 3101,3171 ---- cleanup_after_large_page_init(); UseLargePages = success; } + // Helper function to create a temp file in the given directory + int os::create_tmpfile(const char* dir, size_t size, bool exec) { + + char name_template[] = "/jvmheap.XXXXXX"; + + char *fullname = (char*)alloca(strlen(dir) + sizeof(name_template)); + (void)strcpy(fullname, dir); + (void)strcat(fullname, name_template); + os::native_path(fullname); + + char *path = _mktemp(fullname); + if (path == NULL) + return -1; + + int fd = _open(path, O_RDWR | O_CREAT | O_EXCL, S_IWRITE | S_IREAD); + + if (fd < 0) { + warning("Could not create file for heap"); + return -1; + } + + // delete the name from the filesystem. When 'fd' is closed, the file (and space) will be deleted + _unlink(fullname); + + // allocate space for the file + if (_chsize(fd, (long)size) != 0) { + warning("Could not allocate sufficient disk space for heap"); + return -1; + } + + return fd; + } + + // Map the given address range to a temporary file created at the specified directory. + // 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 + bool os::map_memory_to_file(char* base, size_t size, const char* backingFileDir) { + + int fd = os::create_tmpfile(backingFileDir, size, false); + if (fd == -1) { + vm_exit_during_initialization(err_msg("Could not create temporary file in %s for object heap", backingFileDir)); + return false; + } + + HANDLE fh = (HANDLE)_get_osfhandle(fd); + HANDLE fileMapping = CreateFileMapping(fh, NULL, PAGE_READWRITE, + (DWORD)(size >> 32), (DWORD)(size & 0xFFFFFFFF), NULL); + if (fileMapping == NULL) + return false; + + // release the memory address range and map again at the same address + pd_release_memory(base, size); + LPVOID addr = MapViewOfFileEx(fileMapping, FILE_MAP_WRITE, 0, 0, size, base); + + if (addr == NULL || addr != base) { + CloseHandle(fileMapping); + return false; + } + + return true; + } + // On win32, one cannot release just a part of reserved memory, it's an // all or nothing deal. When we split a reservation, we must break the // reservation into two reservations. void os::pd_split_reserved_memory(char *base, size_t size, size_t split, bool realloc) {
< prev index next >