Mercurial > hg > openjdk > aarch64-port > jdk
changeset 9999:e80aa063429f
8046545: JNI exception pending in jdk/src/share/bin/java.c
Reviewed-by: darcy, ksrini
Contributed-by: neil.toda@oracle.com
author | ksrini |
---|---|
date | Fri, 29 Aug 2014 15:25:20 -0700 |
parents | eec42b39b081 |
children | 9e3cc4611c2d |
files | src/share/bin/java.c src/share/bin/java.h |
diffstat | 2 files changed, 53 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/bin/java.c Thu Aug 28 13:26:04 2014 +0200 +++ b/src/share/bin/java.c Fri Aug 29 15:25:20 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2014, 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 @@ -1248,11 +1248,13 @@ (*env)->SetByteArrayRegion(env, ary, 0, len, (jbyte *)s); if (!(*env)->ExceptionOccurred(env)) { if (makePlatformStringMID == NULL) { - NULL_CHECK0(makePlatformStringMID = (*env)->GetStaticMethodID(env, + CHECK_JNI_RETURN_0( + makePlatformStringMID = (*env)->GetStaticMethodID(env, cls, "makePlatformString", "(Z[B)Ljava/lang/String;")); } - str = (*env)->CallStaticObjectMethod(env, cls, - makePlatformStringMID, USE_STDERR, ary); + CHECK_JNI_RETURN_0( + str = (*env)->CallStaticObjectMethod(env, cls, + makePlatformStringMID, USE_STDERR, ary)); (*env)->DeleteLocalRef(env, ary); return str; } @@ -1303,7 +1305,9 @@ "(ZILjava/lang/String;)Ljava/lang/Class;")); str = NewPlatformString(env, name); - result = (*env)->CallStaticObjectMethod(env, cls, mid, USE_STDERR, mode, str); + CHECK_JNI_RETURN_0( + result = (*env)->CallStaticObjectMethod( + env, cls, mid, USE_STDERR, mode, str)); if (JLI_IsTraceLauncher()) { end = CounterGet();
--- a/src/share/bin/java.h Thu Aug 28 13:26:04 2014 +0200 +++ b/src/share/bin/java.h Fri Aug 29 15:25:20 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2014, 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 @@ -256,4 +256,47 @@ #define NULL_CHECK(NC_check_pointer) \ NULL_CHECK_RETURN_VALUE(NC_check_pointer, ) +/* + * For JNI calls : + * - check for thrown exceptions + * - check for null return + * + * JNI calls can return null and/or throw an exception. Check for these. + * + * : CHECK_JNI_RETURN_EXCEPTION() + * return the specified RETURNVALUE if exception was generated + * : CHECK_JNI_RETURN_0(JNISTATEMENT) : check if JNISTATEMENT was successful, return 0 if not + * : CHECK_JNI_RETURN_VOID(JNISTATEMENT) : check if JNISTATEMENT was successful, return void if not + * : CHECK_JNI_RETURN_VALUE(JNISTATEMENT,n) : check if JNISTATEMENT was successful, return n if not + * + * These macros need at least one parameter, the JNI statement [ JNISTATEMENT ]. + * + * E.G.: check the JNI statement, and specify a value to return if a failure was detected. + * + * CHECK_JNI_RETURN_VALUE(str = (*env)->CallStaticObjectMethod(env, cls, + * makePlatformStringMID, USE_STDERR, ary), -1); + */ + +#define RETURNVOID return +#define RETURN0 return 0 +#define RETURN(N) return (N) + +#define CHECK_JNI_RETURN_EXCEPTION(RETURNVALUE) \ + if ((((*env)->ExceptionOccurred(env))!=NULL)) { \ + RETURNVALUE; \ + } + +#define CHECK_JNI_RETURN_0(JNISTATEMENT) \ + CHECK_JNI_RETURN_EXCEPTION(RETURN0); \ + NULL_CHECK0(JNISTATEMENT); + +#define CHECK_JNI_RETURN_VOID(JNISTATEMENT) \ + CHECK_JNI_RETURN_EXCEPTION(RETURNVOID); \ + NULL_CHECK(JNISTATEMENT); + +#define CHECK_JNI_RETURN_VALUE(JNISTATEMENT, NCRV_return_value) \ + CHECK_JNI_RETURN_EXCEPTION(RETURN(NCRV_return_value)); \ + NULL_CHECK_RETURN_VALUE(JNISTATEMENT, NCRV_return_value); + + #endif /* _JAVA_H_ */