936 result = JVM_DefineClass(env, utfName, loader, body, length, pd);
937
938 if (utfName && utfName != buf)
939 FREE_C_HEAP_ARRAY(char, utfName, mtInternal);
940
941 free_body:
942 FREE_C_HEAP_ARRAY(jbyte, body, mtInternal);
943 return result;
944 }
945 }
946
947
948 UNSAFE_ENTRY(jclass, Unsafe_DefineClass(JNIEnv *env, jobject unsafe, jstring name, jbyteArray data, int offset, int length, jobject loader, jobject pd))
949 UnsafeWrapper("Unsafe_DefineClass");
950 {
951 ThreadToNativeFromVM ttnfv(thread);
952 return Unsafe_DefineClass_impl(env, name, data, offset, length, loader, pd);
953 }
954 UNSAFE_END
955
956
957 UNSAFE_ENTRY(jclass, Unsafe_DefineClass0(JNIEnv *env, jobject unsafe, jstring name, jbyteArray data, int offset, int length))
958 UnsafeWrapper("Unsafe_DefineClass");
959 {
960 ThreadToNativeFromVM ttnfv(thread);
961
962 int depthFromDefineClass0 = 1;
963 jclass caller = JVM_GetCallerClass(env, depthFromDefineClass0);
964 jobject loader = (caller == NULL) ? NULL : JVM_GetClassLoader(env, caller);
965 jobject pd = (caller == NULL) ? NULL : JVM_GetProtectionDomain(env, caller);
966
967 return Unsafe_DefineClass_impl(env, name, data, offset, length, loader, pd);
968 }
969 UNSAFE_END
970
971
972 #define DAC_Args CLS"[B["OBJ
973 // define a class but do not make it known to the class loader or system dictionary
974 // - host_class: supplies context for linkage, access control, protection domain, and class loader
975 // - data: bytes of a class file, a raw memory address (length gives the number of bytes)
976 // - cp_patches: where non-null entries exist, they replace corresponding CP entries in data
977
978 // When you load an anonymous class U, it works as if you changed its name just before loading,
979 // to a name that you will never use again. Since the name is lost, no other class can directly
980 // link to any member of U. Just after U is loaded, the only way to use it is reflectively,
981 // through java.lang.Class methods like Class.newInstance.
982
983 // Access checks for linkage sites within U continue to follow the same rules as for named classes.
984 // The package of an anonymous class is given by the package qualifier on the name under which it was loaded.
|
936 result = JVM_DefineClass(env, utfName, loader, body, length, pd);
937
938 if (utfName && utfName != buf)
939 FREE_C_HEAP_ARRAY(char, utfName, mtInternal);
940
941 free_body:
942 FREE_C_HEAP_ARRAY(jbyte, body, mtInternal);
943 return result;
944 }
945 }
946
947
948 UNSAFE_ENTRY(jclass, Unsafe_DefineClass(JNIEnv *env, jobject unsafe, jstring name, jbyteArray data, int offset, int length, jobject loader, jobject pd))
949 UnsafeWrapper("Unsafe_DefineClass");
950 {
951 ThreadToNativeFromVM ttnfv(thread);
952 return Unsafe_DefineClass_impl(env, name, data, offset, length, loader, pd);
953 }
954 UNSAFE_END
955
956 static jobject get_class_loader(JNIEnv* env, jclass cls) {
957 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
958 return NULL;
959 }
960 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
961 oop loader = k->class_loader();
962 return JNIHandles::make_local(env, loader);
963 }
964
965 UNSAFE_ENTRY(jclass, Unsafe_DefineClass0(JNIEnv *env, jobject unsafe, jstring name, jbyteArray data, int offset, int length))
966 UnsafeWrapper("Unsafe_DefineClass");
967 {
968 ThreadToNativeFromVM ttnfv(thread);
969
970 int depthFromDefineClass0 = 1;
971 jclass caller = JVM_GetCallerClass(env, depthFromDefineClass0);
972 jobject loader = (caller == NULL) ? NULL : get_class_loader(env, caller);
973 jobject pd = (caller == NULL) ? NULL : JVM_GetProtectionDomain(env, caller);
974
975 return Unsafe_DefineClass_impl(env, name, data, offset, length, loader, pd);
976 }
977 UNSAFE_END
978
979
980 #define DAC_Args CLS"[B["OBJ
981 // define a class but do not make it known to the class loader or system dictionary
982 // - host_class: supplies context for linkage, access control, protection domain, and class loader
983 // - data: bytes of a class file, a raw memory address (length gives the number of bytes)
984 // - cp_patches: where non-null entries exist, they replace corresponding CP entries in data
985
986 // When you load an anonymous class U, it works as if you changed its name just before loading,
987 // to a name that you will never use again. Since the name is lost, no other class can directly
988 // link to any member of U. Just after U is loaded, the only way to use it is reflectively,
989 // through java.lang.Class methods like Class.newInstance.
990
991 // Access checks for linkage sites within U continue to follow the same rules as for named classes.
992 // The package of an anonymous class is given by the package qualifier on the name under which it was loaded.
|