Path: blob/master/src/hotspot/os/windows/gc/z/zSyscall_windows.cpp
40948 views
/*1* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include "precompiled.hpp"24#include "gc/shared/gcLogPrecious.hpp"25#include "gc/z/zSyscall_windows.hpp"26#include "runtime/java.hpp"27#include "runtime/os.hpp"2829ZSyscall::CreateFileMappingWFn ZSyscall::CreateFileMappingW;30ZSyscall::CreateFileMapping2Fn ZSyscall::CreateFileMapping2;31ZSyscall::VirtualAlloc2Fn ZSyscall::VirtualAlloc2;32ZSyscall::VirtualFreeExFn ZSyscall::VirtualFreeEx;33ZSyscall::MapViewOfFile3Fn ZSyscall::MapViewOfFile3;34ZSyscall::UnmapViewOfFile2Fn ZSyscall::UnmapViewOfFile2;3536static void* lookup_kernelbase_library() {37const char* const name = "KernelBase";38char ebuf[1024];39void* const handle = os::dll_load(name, ebuf, sizeof(ebuf));40if (handle == NULL) {41log_error_p(gc)("Failed to load library: %s", name);42}43return handle;44}4546static void* lookup_kernelbase_symbol(const char* name) {47static void* const handle = lookup_kernelbase_library();48if (handle == NULL) {49return NULL;50}51return os::dll_lookup(handle, name);52}5354static bool has_kernelbase_symbol(const char* name) {55return lookup_kernelbase_symbol(name) != NULL;56}5758template <typename Fn>59static void install_kernelbase_symbol(Fn*& fn, const char* name) {60fn = reinterpret_cast<Fn*>(lookup_kernelbase_symbol(name));61}6263template <typename Fn>64static void install_kernelbase_1803_symbol_or_exit(Fn*& fn, const char* name) {65install_kernelbase_symbol(fn, name);66if (fn == NULL) {67log_error_p(gc)("Failed to lookup symbol: %s", name);68vm_exit_during_initialization("ZGC requires Windows version 1803 or later");69}70}7172void ZSyscall::initialize() {73// Required74install_kernelbase_1803_symbol_or_exit(CreateFileMappingW, "CreateFileMappingW");75install_kernelbase_1803_symbol_or_exit(VirtualAlloc2, "VirtualAlloc2");76install_kernelbase_1803_symbol_or_exit(VirtualFreeEx, "VirtualFreeEx");77install_kernelbase_1803_symbol_or_exit(MapViewOfFile3, "MapViewOfFile3");78install_kernelbase_1803_symbol_or_exit(UnmapViewOfFile2, "UnmapViewOfFile2");7980// Optional - for large pages support81install_kernelbase_symbol(CreateFileMapping2, "CreateFileMapping2");82}8384bool ZSyscall::is_supported() {85// Available in Windows version 1803 and later86return has_kernelbase_symbol("VirtualAlloc2");87}8889bool ZSyscall::is_large_pages_supported() {90// Available in Windows version 1809 and later91return has_kernelbase_symbol("CreateFileMapping2");92}939495