mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8308300: enhance exceptions in MappedMemoryUtils.c
Reviewed-by: alanb, clanger, bpb
This commit is contained in:
parent
c4408278d1
commit
69f508a2ac
3 changed files with 18 additions and 5 deletions
|
@ -176,7 +176,7 @@ JNU_ThrowByNameWithMessageAndLastError
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Convenience method.
|
* Convenience function.
|
||||||
* Call JNU_ThrowByNameWithLastError for java.io.IOException.
|
* Call JNU_ThrowByNameWithLastError for java.io.IOException.
|
||||||
*/
|
*/
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
|
@ -185,6 +185,16 @@ JNU_ThrowIOExceptionWithLastError(JNIEnv *env, const char *defaultDetail)
|
||||||
JNU_ThrowByNameWithLastError(env, "java/io/IOException", defaultDetail);
|
JNU_ThrowByNameWithLastError(env, "java/io/IOException", defaultDetail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Throw java.io.IOException using a given message and the string
|
||||||
|
* returned by getLastErrorString to construct the detail string.
|
||||||
|
*/
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
JNU_ThrowIOExceptionWithMessageAndLastError(JNIEnv *env, const char *message)
|
||||||
|
{
|
||||||
|
JNU_ThrowByNameWithMessageAndLastError(env, "java/io/IOException", message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
JNIEXPORT jvalue JNICALL
|
JNIEXPORT jvalue JNICALL
|
||||||
JNU_CallStaticMethodByName(JNIEnv *env,
|
JNU_CallStaticMethodByName(JNIEnv *env,
|
||||||
|
|
|
@ -92,6 +92,9 @@ JNU_ThrowByNameWithMessageAndLastError
|
||||||
JNIEXPORT void JNICALL
|
JNIEXPORT void JNICALL
|
||||||
JNU_ThrowIOExceptionWithLastError(JNIEnv *env, const char *defaultDetail);
|
JNU_ThrowIOExceptionWithLastError(JNIEnv *env, const char *defaultDetail);
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
JNU_ThrowIOExceptionWithMessageAndLastError(JNIEnv *env, const char *message);
|
||||||
|
|
||||||
/* Convert between Java strings and i18n C strings */
|
/* Convert between Java strings and i18n C strings */
|
||||||
JNIEXPORT const char *
|
JNIEXPORT const char *
|
||||||
GetStringPlatformChars(JNIEnv *env, jstring jstr, jboolean *isCopy);
|
GetStringPlatformChars(JNIEnv *env, jstring jstr, jboolean *isCopy);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -110,7 +110,7 @@ Java_java_nio_MappedMemoryUtils_load0(JNIEnv *env, jobject obj, jlong address,
|
||||||
char *a = (char *)jlong_to_ptr(address);
|
char *a = (char *)jlong_to_ptr(address);
|
||||||
int result = madvise((caddr_t)a, (size_t)len, MADV_WILLNEED);
|
int result = madvise((caddr_t)a, (size_t)len, MADV_WILLNEED);
|
||||||
if (result == -1) {
|
if (result == -1) {
|
||||||
JNU_ThrowIOExceptionWithLastError(env, "madvise failed");
|
JNU_ThrowIOExceptionWithMessageAndLastError(env, "madvise with advise MADV_WILLNEED failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ Java_java_nio_MappedMemoryUtils_unload0(JNIEnv *env, jobject obj, jlong address,
|
||||||
char *a = (char *)jlong_to_ptr(address);
|
char *a = (char *)jlong_to_ptr(address);
|
||||||
int result = madvise((caddr_t)a, (size_t)len, MADV_DONTNEED);
|
int result = madvise((caddr_t)a, (size_t)len, MADV_DONTNEED);
|
||||||
if (result == -1) {
|
if (result == -1) {
|
||||||
JNU_ThrowIOExceptionWithLastError(env, "madvise failed");
|
JNU_ThrowIOExceptionWithMessageAndLastError(env, "madvise with advise MADV_DONTNEED failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,6 +132,6 @@ Java_java_nio_MappedMemoryUtils_force0(JNIEnv *env, jobject obj, jobject fdo,
|
||||||
void* a = (void *)jlong_to_ptr(address);
|
void* a = (void *)jlong_to_ptr(address);
|
||||||
int result = msync(a, (size_t)len, MS_SYNC);
|
int result = msync(a, (size_t)len, MS_SYNC);
|
||||||
if (result == -1) {
|
if (result == -1) {
|
||||||
JNU_ThrowIOExceptionWithLastError(env, "msync failed");
|
JNU_ThrowIOExceptionWithMessageAndLastError(env, "msync with parameter MS_SYNC failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue