< prev index next >

src/java.base/share/native/libjava/Class.c

Print this page
rev 56072 : 8230043: Lazily load libverify
Reviewed-by: hseigel, erikj, alanb


  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /*-
  27  *      Implementation of class Class
  28  *
  29  *      former threadruntime.c, Sun Sep 22 12:09:39 1991
  30  */
  31 
  32 #include <string.h>
  33 #include <stdlib.h>
  34 
  35 #include "jni.h"
  36 #include "jni_util.h"
  37 #include "jvm.h"

  38 #include "java_lang_Class.h"
  39 
  40 /* defined in libverify.so/verify.dll (src file common/check_format.c) */
  41 extern jboolean VerifyClassname(char *utf_name, jboolean arrayAllowed);
  42 extern jboolean VerifyFixClassname(char *utf_name);
  43 
  44 #define OBJ "Ljava/lang/Object;"
  45 #define CLS "Ljava/lang/Class;"
  46 #define CPL "Ljdk/internal/reflect/ConstantPool;"
  47 #define STR "Ljava/lang/String;"
  48 #define FLD "Ljava/lang/reflect/Field;"
  49 #define MHD "Ljava/lang/reflect/Method;"
  50 #define CTR "Ljava/lang/reflect/Constructor;"
  51 #define PD  "Ljava/security/ProtectionDomain;"
  52 #define BA  "[B"
  53 
  54 static JNINativeMethod methods[] = {
  55     {"initClassName",    "()" STR,          (void *)&JVM_InitClassName},
  56     {"getSuperclass",    "()" CLS,          NULL},
  57     {"getInterfaces0",   "()[" CLS,         (void *)&JVM_GetClassInterfaces},
  58     {"isInterface",      "()Z",             (void *)&JVM_IsInterface},
  59     {"getSigners",       "()[" OBJ,         (void *)&JVM_GetClassSigners},
  60     {"setSigners",       "([" OBJ ")V",     (void *)&JVM_SetClassSigners},
  61     {"isArray",          "()Z",             (void *)&JVM_IsArrayClass},
  62     {"isPrimitive",      "()Z",             (void *)&JVM_IsPrimitiveClass},
  63     {"getModifiers",     "()I",             (void *)&JVM_GetClassModifiers},


 105     jsize unicode_len;
 106 
 107     if (classname == NULL) {
 108         JNU_ThrowNullPointerException(env, 0);
 109         return 0;
 110     }
 111 
 112     len = (*env)->GetStringUTFLength(env, classname);
 113     unicode_len = (*env)->GetStringLength(env, classname);
 114     if (len >= (jsize)sizeof(buf)) {
 115         clname = malloc(len + 1);
 116         if (clname == NULL) {
 117             JNU_ThrowOutOfMemoryError(env, NULL);
 118             return NULL;
 119         }
 120     } else {
 121         clname = buf;
 122     }
 123     (*env)->GetStringUTFRegion(env, classname, 0, unicode_len, clname);
 124 
 125     if (VerifyFixClassname(clname) == JNI_TRUE) {
 126         /* slashes present in clname, use name b4 translation for exception */
 127         (*env)->GetStringUTFRegion(env, classname, 0, unicode_len, clname);
 128         JNU_ThrowClassNotFoundException(env, clname);
 129         goto done;
 130     }
 131 
 132     if (!VerifyClassname(clname, JNI_TRUE)) {  /* expects slashed name */
 133         JNU_ThrowClassNotFoundException(env, clname);
 134         goto done;
 135     }
 136 
 137     cls = JVM_FindClassFromCaller(env, clname, initialize, loader, caller);
 138 
 139  done:
 140     if (clname != buf) {
 141         free(clname);
 142     }
 143     return cls;
 144 }
 145 
 146 JNIEXPORT jboolean JNICALL
 147 Java_java_lang_Class_isInstance(JNIEnv *env, jobject cls, jobject obj)
 148 {
 149     if (obj == NULL) {
 150         return JNI_FALSE;
 151     }
 152     return (*env)->IsInstanceOf(env, obj, (jclass)cls);




  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /*-
  27  *      Implementation of class Class
  28  *
  29  *      former threadruntime.c, Sun Sep 22 12:09:39 1991
  30  */
  31 
  32 #include <string.h>
  33 #include <stdlib.h>
  34 
  35 #include "jni.h"
  36 #include "jni_util.h"
  37 #include "jvm.h"
  38 #include "check_classname.h"
  39 #include "java_lang_Class.h"
  40 




  41 #define OBJ "Ljava/lang/Object;"
  42 #define CLS "Ljava/lang/Class;"
  43 #define CPL "Ljdk/internal/reflect/ConstantPool;"
  44 #define STR "Ljava/lang/String;"
  45 #define FLD "Ljava/lang/reflect/Field;"
  46 #define MHD "Ljava/lang/reflect/Method;"
  47 #define CTR "Ljava/lang/reflect/Constructor;"
  48 #define PD  "Ljava/security/ProtectionDomain;"
  49 #define BA  "[B"
  50 
  51 static JNINativeMethod methods[] = {
  52     {"initClassName",    "()" STR,          (void *)&JVM_InitClassName},
  53     {"getSuperclass",    "()" CLS,          NULL},
  54     {"getInterfaces0",   "()[" CLS,         (void *)&JVM_GetClassInterfaces},
  55     {"isInterface",      "()Z",             (void *)&JVM_IsInterface},
  56     {"getSigners",       "()[" OBJ,         (void *)&JVM_GetClassSigners},
  57     {"setSigners",       "([" OBJ ")V",     (void *)&JVM_SetClassSigners},
  58     {"isArray",          "()Z",             (void *)&JVM_IsArrayClass},
  59     {"isPrimitive",      "()Z",             (void *)&JVM_IsPrimitiveClass},
  60     {"getModifiers",     "()I",             (void *)&JVM_GetClassModifiers},


 102     jsize unicode_len;
 103 
 104     if (classname == NULL) {
 105         JNU_ThrowNullPointerException(env, 0);
 106         return 0;
 107     }
 108 
 109     len = (*env)->GetStringUTFLength(env, classname);
 110     unicode_len = (*env)->GetStringLength(env, classname);
 111     if (len >= (jsize)sizeof(buf)) {
 112         clname = malloc(len + 1);
 113         if (clname == NULL) {
 114             JNU_ThrowOutOfMemoryError(env, NULL);
 115             return NULL;
 116         }
 117     } else {
 118         clname = buf;
 119     }
 120     (*env)->GetStringUTFRegion(env, classname, 0, unicode_len, clname);
 121 
 122     if (verifyFixClassname(clname) == JNI_TRUE) {
 123         /* slashes present in clname, use name b4 translation for exception */
 124         (*env)->GetStringUTFRegion(env, classname, 0, unicode_len, clname);
 125         JNU_ThrowClassNotFoundException(env, clname);
 126         goto done;
 127     }
 128 
 129     if (!verifyClassname(clname, JNI_TRUE)) {  /* expects slashed name */
 130         JNU_ThrowClassNotFoundException(env, clname);
 131         goto done;
 132     }
 133 
 134     cls = JVM_FindClassFromCaller(env, clname, initialize, loader, caller);
 135 
 136  done:
 137     if (clname != buf) {
 138         free(clname);
 139     }
 140     return cls;
 141 }
 142 
 143 JNIEXPORT jboolean JNICALL
 144 Java_java_lang_Class_isInstance(JNIEnv *env, jobject cls, jobject obj)
 145 {
 146     if (obj == NULL) {
 147         return JNI_FALSE;
 148     }
 149     return (*env)->IsInstanceOf(env, obj, (jclass)cls);


< prev index next >