changeset 8704:acf72ae6145d

8031737: CHECK_NULL and CHECK_EXCEPTION macros cleanup Reviewed-by: rriggs, mchung, mduigou
author prr
date Wed, 12 Feb 2014 11:36:38 -0800
parents c9d307e51b37
children d127560ad6ff
files src/share/native/common/jni_util.h src/share/native/sun/misc/Version.c
diffstat 2 files changed, 42 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/native/common/jni_util.h	Thu Aug 11 13:22:51 2016 +0300
+++ b/src/share/native/common/jni_util.h	Wed Feb 12 11:36:38 2014 -0800
@@ -285,6 +285,38 @@
 #define IS_NULL(obj) ((obj) == NULL)
 #define JNU_IsNull(env,obj) ((obj) == NULL)
 
+/************************************************************************
+ * Miscellaneous utilities used by the class libraries to return from
+ * a function if a value is NULL or an exception is pending.
+ */
+
+#define CHECK_NULL(x)                           \
+    do {                                        \
+        if ((x) == NULL) {                      \
+            return;                             \
+        }                                       \
+    } while (0)                                 \
+
+#define CHECK_NULL_RETURN(x, y)                 \
+    do {                                        \
+        if ((x) == NULL) {                      \
+            return (y);                         \
+        }                                       \
+    } while (0)                                 \
+
+#define JNU_CHECK_EXCEPTION(env)                \
+    do {                                        \
+        if ((*env)->ExceptionCheck(env)) {      \
+            return;                             \
+        }                                       \
+    } while (0)                                 \
+
+#define JNU_CHECK_EXCEPTION_RETURN(env, y)      \
+    do {                                        \
+        if ((*env)->ExceptionCheck(env)) {      \
+            return (y);                         \
+        }                                       \
+    } while (0)
 
 /************************************************************************
  * Debugging utilities
--- a/src/share/native/sun/misc/Version.c	Thu Aug 11 13:22:51 2016 +0300
+++ b/src/share/native/sun/misc/Version.c	Wed Feb 12 11:36:38 2014 -0800
@@ -90,10 +90,15 @@
 
     (*func_p)(env, &info, sizeof(info));
     setStaticIntField(env, cls, "jvm_major_version", JVM_VERSION_MAJOR(info.jvm_version));
+    JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
     setStaticIntField(env, cls, "jvm_minor_version", JVM_VERSION_MINOR(info.jvm_version));
+    JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
     setStaticIntField(env, cls, "jvm_micro_version", JVM_VERSION_MICRO(info.jvm_version));
+    JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
     setStaticIntField(env, cls, "jvm_build_number", JVM_VERSION_BUILD(info.jvm_version));
+    JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
     setStaticIntField(env, cls, "jvm_update_version", info.update_version);
+    JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
     jvm_special_version = info.special_update_version;
 
     return JNI_TRUE;
@@ -116,10 +121,15 @@
 
     JDK_GetVersionInfo0(&info, sizeof(info));
     setStaticIntField(env, cls, "jdk_major_version", JDK_VERSION_MAJOR(info.jdk_version));
+    JNU_CHECK_EXCEPTION(env);
     setStaticIntField(env, cls, "jdk_minor_version", JDK_VERSION_MINOR(info.jdk_version));
+    JNU_CHECK_EXCEPTION(env);
     setStaticIntField(env, cls, "jdk_micro_version", JDK_VERSION_MICRO(info.jdk_version));
+    JNU_CHECK_EXCEPTION(env);
     setStaticIntField(env, cls, "jdk_build_number", JDK_VERSION_BUILD(info.jdk_version));
+    JNU_CHECK_EXCEPTION(env);
     setStaticIntField(env, cls, "jdk_update_version", info.update_version);
+    JNU_CHECK_EXCEPTION(env);
     jdk_special_version = info.special_update_version;
 }