< prev index next >

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

Print this page
rev 58565 : 8238358: Implementation of JEP 371: Hidden Classes
Reviewed-by: duke
Contributed-by: mandy.chung@oracle.com, lois.foltan@oracle.com, david.holmes@oracle.com, harold.seigel@oracle.com, serguei.spitsyn@oracle.com, alex.buckley@oracle.com, jamsheed.c.m@oracle.com

@@ -205,10 +205,70 @@
         free(utfName);
 
     return result;
 }
 
+JNIEXPORT jclass JNICALL
+Java_java_lang_ClassLoader_defineClass0(JNIEnv *env,
+                                        jclass cls,
+                                        jobject loader,
+                                        jclass lookup,
+                                        jstring name,
+                                        jbyteArray data,
+                                        jint offset,
+                                        jint length,
+                                        jobject pd,
+                                        jboolean initialize,
+                                        jint flags,
+                                        jobject classData)
+{
+    jbyte *body;
+    char *utfName;
+    jclass result = 0;
+    char buf[128];
+
+    if (data == NULL) {
+        JNU_ThrowNullPointerException(env, 0);
+        return 0;
+    }
+
+    /* Work around 4153825. malloc crashes on Solaris when passed a
+     * negative size.
+     */
+    if (length < 0) {
+        JNU_ThrowArrayIndexOutOfBoundsException(env, 0);
+        return 0;
+    }
+
+    body = (jbyte *)malloc(length);
+    if (body == 0) {
+        JNU_ThrowOutOfMemoryError(env, 0);
+        return 0;
+    }
+
+    (*env)->GetByteArrayRegion(env, data, offset, length, body);
+
+    if ((*env)->ExceptionOccurred(env))
+        goto free_body;
+
+    if (name != NULL) {
+        utfName = getUTF(env, name, buf, sizeof(buf));
+        if (utfName == NULL) {
+            goto free_body;
+        }
+        fixClassname(utfName);
+    } else {
+        utfName = NULL;
+    }
+
+    return JVM_LookupDefineClass(env, lookup, utfName, body, length, pd, initialize, flags, classData);
+
+ free_body:
+    free(body);
+    return result;
+}
+
 /*
  * Returns NULL if class not found.
  */
 JNIEXPORT jclass JNICALL
 Java_java_lang_ClassLoader_findBootstrapClass(JNIEnv *env, jobject loader,
< prev index next >