< prev index next >

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

Print this page




 194         utfSource = getUTF(env, source, sourceBuf, sizeof(sourceBuf));
 195         if (utfSource == NULL) {
 196             JNU_ThrowOutOfMemoryError(env, NULL);
 197             goto free_utfName;
 198         }
 199     } else {
 200         utfSource = NULL;
 201     }
 202     result = JVM_DefineClassWithSource(env, utfName, loader, body, length, pd, utfSource);
 203 
 204     if (utfSource && utfSource != sourceBuf)
 205         free(utfSource);
 206 
 207  free_utfName:
 208     if (utfName && utfName != buf)
 209         free(utfName);
 210 
 211     return result;
 212 }
 213 



























































 214 /*
 215  * Returns NULL if class not found.
 216  */
 217 JNIEXPORT jclass JNICALL
 218 Java_java_lang_ClassLoader_findBootstrapClass(JNIEnv *env, jobject loader,
 219                                               jstring classname)
 220 {
 221     char *clname;
 222     jclass cls = 0;
 223     char buf[128];
 224 
 225     if (classname == NULL) {
 226         return 0;
 227     }
 228 
 229     clname = getUTF(env, classname, buf, sizeof(buf));
 230     if (clname == NULL) {
 231         JNU_ThrowOutOfMemoryError(env, NULL);
 232         return NULL;
 233     }




 194         utfSource = getUTF(env, source, sourceBuf, sizeof(sourceBuf));
 195         if (utfSource == NULL) {
 196             JNU_ThrowOutOfMemoryError(env, NULL);
 197             goto free_utfName;
 198         }
 199     } else {
 200         utfSource = NULL;
 201     }
 202     result = JVM_DefineClassWithSource(env, utfName, loader, body, length, pd, utfSource);
 203 
 204     if (utfSource && utfSource != sourceBuf)
 205         free(utfSource);
 206 
 207  free_utfName:
 208     if (utfName && utfName != buf)
 209         free(utfName);
 210 
 211     return result;
 212 }
 213 
 214 JNIEXPORT jclass JNICALL
 215 Java_java_lang_ClassLoader_defineClass0(JNIEnv *env,
 216                                         jclass cls,
 217                                         jobject loader,
 218                                         jclass lookup,
 219                                         jstring name,
 220                                         jbyteArray data,
 221                                         jint offset,
 222                                         jint length,
 223                                         jobject pd,
 224                                         jint flags,
 225                                         jobject classData)
 226 {
 227     jbyte *body;
 228     char *utfName;
 229     jclass result = 0;
 230     char buf[128];
 231 
 232     if (data == NULL) {
 233         JNU_ThrowNullPointerException(env, 0);
 234         return 0;
 235     }
 236 
 237     /* Work around 4153825. malloc crashes on Solaris when passed a
 238      * negative size.
 239      */
 240     if (length < 0) {
 241         JNU_ThrowArrayIndexOutOfBoundsException(env, 0);
 242         return 0;
 243     }
 244 
 245     body = (jbyte *)malloc(length);
 246     if (body == 0) {
 247         JNU_ThrowOutOfMemoryError(env, 0);
 248         return 0;
 249     }
 250 
 251     (*env)->GetByteArrayRegion(env, data, offset, length, body);
 252 
 253     if ((*env)->ExceptionOccurred(env))
 254         goto free_body;
 255 
 256     if (name != NULL) {
 257         utfName = getUTF(env, name, buf, sizeof(buf));
 258         if (utfName == NULL) {
 259             goto free_body;
 260         }
 261         VerifyFixClassname(utfName);
 262     } else {
 263         utfName = NULL;
 264     }
 265 
 266     return JVM_LookupDefineClass(env, lookup, utfName, loader, body, length, pd, flags, classData);
 267 
 268  free_body:
 269     free(body);
 270     return result;
 271 }
 272 
 273 /*
 274  * Returns NULL if class not found.
 275  */
 276 JNIEXPORT jclass JNICALL
 277 Java_java_lang_ClassLoader_findBootstrapClass(JNIEnv *env, jobject loader,
 278                                               jstring classname)
 279 {
 280     char *clname;
 281     jclass cls = 0;
 282     char buf[128];
 283 
 284     if (classname == NULL) {
 285         return 0;
 286     }
 287 
 288     clname = getUTF(env, classname, buf, sizeof(buf));
 289     if (clname == NULL) {
 290         JNU_ThrowOutOfMemoryError(env, NULL);
 291         return NULL;
 292     }


< prev index next >