diff --git a/src/java.base/share/native/libjava/jni_util.c b/src/java.base/share/native/libjava/jni_util.c index 1090170dff3..baeaf4883ab 100644 --- a/src/java.base/share/native/libjava/jni_util.c +++ b/src/java.base/share/native/libjava/jni_util.c @@ -176,7 +176,7 @@ JNU_ThrowByNameWithMessageAndLastError } /* - * Convenience method. + * Convenience function. * Call JNU_ThrowByNameWithLastError for java.io.IOException. */ JNIEXPORT void JNICALL @@ -185,6 +185,16 @@ JNU_ThrowIOExceptionWithLastError(JNIEnv *env, const char *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 JNU_CallStaticMethodByName(JNIEnv *env, diff --git a/src/java.base/share/native/libjava/jni_util.h b/src/java.base/share/native/libjava/jni_util.h index 4fcc50a1870..d924c05fc1a 100644 --- a/src/java.base/share/native/libjava/jni_util.h +++ b/src/java.base/share/native/libjava/jni_util.h @@ -92,6 +92,9 @@ JNU_ThrowByNameWithMessageAndLastError JNIEXPORT void JNICALL 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 */ JNIEXPORT const char * GetStringPlatformChars(JNIEnv *env, jstring jstr, jboolean *isCopy); diff --git a/src/java.base/unix/native/libnio/MappedMemoryUtils.c b/src/java.base/unix/native/libnio/MappedMemoryUtils.c index e90acd2863f..4c9b72e51ad 100644 --- a/src/java.base/unix/native/libnio/MappedMemoryUtils.c +++ b/src/java.base/unix/native/libnio/MappedMemoryUtils.c @@ -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. * * 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); int result = madvise((caddr_t)a, (size_t)len, MADV_WILLNEED); 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); int result = madvise((caddr_t)a, (size_t)len, MADV_DONTNEED); 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); int result = msync(a, (size_t)len, MS_SYNC); if (result == -1) { - JNU_ThrowIOExceptionWithLastError(env, "msync failed"); + JNU_ThrowIOExceptionWithMessageAndLastError(env, "msync with parameter MS_SYNC failed"); } }