8230090: ZGC: Introduce ZSyscall

Reviewed-by: stefank
This commit is contained in:
Per Lidén 2019-08-28 09:50:20 +02:00
parent 87eefe2e00
commit 1a76c72367
6 changed files with 159 additions and 40 deletions

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include "precompiled.hpp"
#include "gc/z/zSyscall_linux.hpp"
#include OS_CPU_HEADER(gc/z/zSyscall)
#include <unistd.h>
int ZSyscall::memfd_create(const char *name, unsigned int flags) {
return syscall(SYS_memfd_create, name, flags);
}
int ZSyscall::fallocate(int fd, int mode, size_t offset, size_t length) {
return syscall(SYS_fallocate, fd, mode, offset, length);
}

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#ifndef OS_LINUX_GC_Z_ZSYSCALL_LINUX_HPP
#define OS_LINUX_GC_Z_ZSYSCALL_LINUX_HPP
#include "memory/allocation.hpp"
class ZSyscall : public AllStatic {
public:
static int memfd_create(const char *name, unsigned int flags);
static int fallocate(int fd, int mode, size_t offset, size_t length);
};
#endif // OS_LINUX_GC_Z_ZSYSCALL_LINUX_HPP

View File

@ -28,6 +28,7 @@
#include "gc/z/zErrno.hpp"
#include "gc/z/zGlobals.hpp"
#include "gc/z/zLargePages.inline.hpp"
#include "gc/z/zSyscall_linux.hpp"
#include "logging/log.hpp"
#include "runtime/init.hpp"
#include "runtime/os.hpp"
@ -38,7 +39,6 @@
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
@ -46,14 +46,6 @@
// Support for building on older Linux systems
//
// System calls
#ifndef SYS_fallocate
#define SYS_fallocate 47
#endif
#ifndef SYS_memfd_create
#define SYS_memfd_create 279
#endif
// memfd_create(2) flags
#ifndef MFD_CLOEXEC
#define MFD_CLOEXEC 0x0001U
@ -113,14 +105,6 @@ static const char* z_preferred_hugetlbfs_mountpoints[] = {
static int z_fallocate_hugetlbfs_attempts = 3;
static bool z_fallocate_supported = true;
static int z_fallocate(int fd, int mode, size_t offset, size_t length) {
return syscall(SYS_fallocate, fd, mode, offset, length);
}
static int z_memfd_create(const char *name, unsigned int flags) {
return syscall(SYS_memfd_create, name, flags);
}
ZBackingFile::ZBackingFile() :
_fd(-1),
_size(0),
@ -197,7 +181,7 @@ int ZBackingFile::create_mem_fd(const char* name) const {
// Create file
const int extra_flags = ZLargePages::is_explicit() ? MFD_HUGETLB : 0;
const int fd = z_memfd_create(filename, MFD_CLOEXEC | extra_flags);
const int fd = ZSyscall::memfd_create(filename, MFD_CLOEXEC | extra_flags);
if (fd == -1) {
ZErrno err;
log_debug(gc, init)("Failed to create memfd file (%s)",
@ -416,7 +400,7 @@ ZErrno ZBackingFile::fallocate_fill_hole_compat(size_t offset, size_t length) {
ZErrno ZBackingFile::fallocate_fill_hole_syscall(size_t offset, size_t length) {
const int mode = 0; // Allocate
const int res = z_fallocate(_fd, mode, offset, length);
const int res = ZSyscall::fallocate(_fd, mode, offset, length);
if (res == -1) {
// Failed
return errno;
@ -471,7 +455,7 @@ ZErrno ZBackingFile::fallocate_punch_hole(size_t offset, size_t length) {
}
const int mode = FALLOC_FL_PUNCH_HOLE|FALLOC_FL_KEEP_SIZE;
if (z_fallocate(_fd, mode, offset, length) == -1) {
if (ZSyscall::fallocate(_fd, mode, offset, length) == -1) {
// Failed
return errno;
}

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#ifndef OS_CPU_LINUX_AARCH64_GC_Z_ZSYSCALL_LINUX_AARCH64_HPP
#define OS_CPU_LINUX_AARCH64_GC_Z_ZSYSCALL_LINUX_AARCH64_HPP
#include <sys/syscall.h>
//
// Support for building on older Linux systems
//
#ifndef SYS_memfd_create
#define SYS_memfd_create 279
#endif
#ifndef SYS_fallocate
#define SYS_fallocate 47
#endif
#endif // OS_CPU_LINUX_AARCH64_GC_Z_ZSYSCALL_LINUX_AARCH64_HPP

View File

@ -28,6 +28,7 @@
#include "gc/z/zErrno.hpp"
#include "gc/z/zGlobals.hpp"
#include "gc/z/zLargePages.inline.hpp"
#include "gc/z/zSyscall_linux.hpp"
#include "logging/log.hpp"
#include "runtime/init.hpp"
#include "runtime/os.hpp"
@ -38,7 +39,6 @@
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
@ -46,14 +46,6 @@
// Support for building on older Linux systems
//
// System calls
#ifndef SYS_fallocate
#define SYS_fallocate 285
#endif
#ifndef SYS_memfd_create
#define SYS_memfd_create 319
#endif
// memfd_create(2) flags
#ifndef MFD_CLOEXEC
#define MFD_CLOEXEC 0x0001U
@ -113,14 +105,6 @@ static const char* z_preferred_hugetlbfs_mountpoints[] = {
static int z_fallocate_hugetlbfs_attempts = 3;
static bool z_fallocate_supported = true;
static int z_fallocate(int fd, int mode, size_t offset, size_t length) {
return syscall(SYS_fallocate, fd, mode, offset, length);
}
static int z_memfd_create(const char *name, unsigned int flags) {
return syscall(SYS_memfd_create, name, flags);
}
ZBackingFile::ZBackingFile() :
_fd(-1),
_size(0),
@ -197,7 +181,7 @@ int ZBackingFile::create_mem_fd(const char* name) const {
// Create file
const int extra_flags = ZLargePages::is_explicit() ? MFD_HUGETLB : 0;
const int fd = z_memfd_create(filename, MFD_CLOEXEC | extra_flags);
const int fd = ZSyscall::memfd_create(filename, MFD_CLOEXEC | extra_flags);
if (fd == -1) {
ZErrno err;
log_debug(gc, init)("Failed to create memfd file (%s)",
@ -416,7 +400,7 @@ ZErrno ZBackingFile::fallocate_fill_hole_compat(size_t offset, size_t length) {
ZErrno ZBackingFile::fallocate_fill_hole_syscall(size_t offset, size_t length) {
const int mode = 0; // Allocate
const int res = z_fallocate(_fd, mode, offset, length);
const int res = ZSyscall::fallocate(_fd, mode, offset, length);
if (res == -1) {
// Failed
return errno;
@ -471,7 +455,7 @@ ZErrno ZBackingFile::fallocate_punch_hole(size_t offset, size_t length) {
}
const int mode = FALLOC_FL_PUNCH_HOLE|FALLOC_FL_KEEP_SIZE;
if (z_fallocate(_fd, mode, offset, length) == -1) {
if (ZSyscall::fallocate(_fd, mode, offset, length) == -1) {
// Failed
return errno;
}

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#ifndef OS_CPU_LINUX_X86_GC_Z_ZSYSCALL_LINUX_X86_HPP
#define OS_CPU_LINUX_X86_GC_Z_ZSYSCALL_LINUX_X86_HPP
#include <sys/syscall.h>
//
// Support for building on older Linux systems
//
#ifndef SYS_memfd_create
#define SYS_memfd_create 319
#endif
#ifndef SYS_fallocate
#define SYS_fallocate 285
#endif
#endif // OS_CPU_LINUX_X86_GC_Z_ZSYSCALL_LINUX_X86_HPP