Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/java/nio/MappedByteBuffer.c
47536 views
/*1* Copyright (c) 2001, 2010, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include "jni.h"26#include "jni_util.h"27#include "jvm.h"28#include "jlong.h"29#include "java_nio_MappedByteBuffer.h"30#include <sys/mman.h>31#include <stddef.h>32#include <stdlib.h>3334JNIEXPORT jboolean JNICALL35Java_java_nio_MappedByteBuffer_isLoaded0(JNIEnv *env, jobject obj, jlong address,36jlong len, jint numPages)37{38jboolean loaded = JNI_TRUE;39int result = 0;40int i = 0;41void *a = (void *) jlong_to_ptr(address);42#ifdef __linux__43unsigned char *vec = (unsigned char *)malloc(numPages * sizeof(char));44#else45char *vec = (char *)malloc(numPages * sizeof(char));46#endif4748if (vec == NULL) {49JNU_ThrowOutOfMemoryError(env, NULL);50return JNI_FALSE;51}5253result = mincore(a, (size_t)len, vec);54if (result == -1) {55JNU_ThrowIOExceptionWithLastError(env, "mincore failed");56free(vec);57return JNI_FALSE;58}5960for (i=0; i<numPages; i++) {61if (vec[i] == 0) {62loaded = JNI_FALSE;63break;64}65}66free(vec);67return loaded;68}697071JNIEXPORT void JNICALL72Java_java_nio_MappedByteBuffer_load0(JNIEnv *env, jobject obj, jlong address,73jlong len)74{75char *a = (char *)jlong_to_ptr(address);76int result = madvise((caddr_t)a, (size_t)len, MADV_WILLNEED);77if (result == -1) {78JNU_ThrowIOExceptionWithLastError(env, "madvise failed");79}80}818283JNIEXPORT void JNICALL84Java_java_nio_MappedByteBuffer_force0(JNIEnv *env, jobject obj, jobject fdo,85jlong address, jlong len)86{87void* a = (void *)jlong_to_ptr(address);88int result = msync(a, (size_t)len, MS_SYNC);89if (result == -1) {90JNU_ThrowIOExceptionWithLastError(env, "msync failed");91}92}939495