Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/native/java/nio/MappedByteBuffer.c
32287 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 <stdlib.h>3132JNIEXPORT jboolean JNICALL33Java_java_nio_MappedByteBuffer_isLoaded0(JNIEnv *env, jobject obj, jlong address,34jlong len, jint numPages)35{36jboolean loaded = JNI_FALSE;37/* Information not available?38MEMORY_BASIC_INFORMATION info;39void *a = (void *) jlong_to_ptr(address);40int result = VirtualQuery(a, &info, (DWORD)len);41*/42return loaded;43}4445JNIEXPORT void JNICALL46Java_java_nio_MappedByteBuffer_load0(JNIEnv *env, jobject obj, jlong address,47jlong len)48{49// no madvise available50}5152JNIEXPORT void JNICALL53Java_java_nio_MappedByteBuffer_force0(JNIEnv *env, jobject obj, jobject fdo,54jlong address, jlong len)55{56void *a = (void *) jlong_to_ptr(address);57BOOL result;58int retry;5960/*61* FlushViewOfFile can fail with ERROR_LOCK_VIOLATION if the memory62* system is writing dirty pages to disk. As there is no way to63* synchronize the flushing then we retry a limited number of times.64*/65retry = 0;66do {67result = FlushViewOfFile(a, (DWORD)len);68if ((result != 0) || (GetLastError() != ERROR_LOCK_VIOLATION))69break;70retry++;71} while (retry < 3);7273/**74* FlushViewOfFile only initiates the writing of dirty pages to disk75* so we have to call FlushFileBuffers to and ensure they are written.76*/77if (result != 0) {78// by right, the jfieldID initialization should be in a static79// initializer but we do it here instead to avoiding needing to80// load nio.dll during startup.81static jfieldID handle_fdID;82HANDLE h;83if (handle_fdID == NULL) {84jclass clazz = (*env)->FindClass(env, "java/io/FileDescriptor");85CHECK_NULL(clazz); //exception thrown86handle_fdID = (*env)->GetFieldID(env, clazz, "handle", "J");87CHECK_NULL(handle_fdID);88}89h = jlong_to_ptr((*env)->GetLongField(env, fdo, handle_fdID));90result = FlushFileBuffers(h);91if (result == 0 && GetLastError() == ERROR_ACCESS_DENIED) {92// read-only mapping93result = 1;94}95}9697if (result == 0) {98JNU_ThrowIOExceptionWithLastError(env, "Flush failed");99}100}101102103