841 // than fields, this method MUST return zero for such arrays. 842 // For example, the VM used to store sub-word sized fields in full 843 // words in the object layout, so that accessors like getByte(Object,int) 844 // did not really do what one might expect for arrays. Therefore, 845 // this function used to report a zero scale factor, so that the user 846 // would know not to attempt to access sub-word array elements. 847 // // Code for unpacked fields: 848 // if (scale < wordSize) return 0; 849 850 // The following allows for a pretty general fieldOffset cookie scheme, 851 // but requires it to be linear in byte offset. 852 return field_offset_from_byte_offset(scale) - field_offset_from_byte_offset(0); 853 UNSAFE_END 854 855 856 static inline void throw_new(JNIEnv *env, const char *ename) { 857 char buf[100]; 858 strcpy(buf, "java/lang/"); 859 strcat(buf, ename); 860 jclass cls = env->FindClass(buf); 861 char* msg = NULL; 862 env->ThrowNew(cls, msg); 863 } 864 865 static jclass Unsafe_DefineClass_impl(JNIEnv *env, jstring name, jbyteArray data, int offset, int length, jobject loader, jobject pd) { 866 { 867 // Code lifted from JDK 1.3 ClassLoader.c 868 869 jbyte *body; 870 char *utfName; 871 jclass result = 0; 872 char buf[128]; 873 874 if (UsePerfData) { 875 ClassLoader::unsafe_defineClassCallCounter()->inc(); 876 } 877 878 if (data == NULL) { 879 throw_new(env, "NullPointerException"); 880 return 0; | 841 // than fields, this method MUST return zero for such arrays. 842 // For example, the VM used to store sub-word sized fields in full 843 // words in the object layout, so that accessors like getByte(Object,int) 844 // did not really do what one might expect for arrays. Therefore, 845 // this function used to report a zero scale factor, so that the user 846 // would know not to attempt to access sub-word array elements. 847 // // Code for unpacked fields: 848 // if (scale < wordSize) return 0; 849 850 // The following allows for a pretty general fieldOffset cookie scheme, 851 // but requires it to be linear in byte offset. 852 return field_offset_from_byte_offset(scale) - field_offset_from_byte_offset(0); 853 UNSAFE_END 854 855 856 static inline void throw_new(JNIEnv *env, const char *ename) { 857 char buf[100]; 858 strcpy(buf, "java/lang/"); 859 strcat(buf, ename); 860 jclass cls = env->FindClass(buf); 861 if (env->ExceptionCheck()) { 862 env->ExceptionClear(); 863 tty->print_cr("Unsafe: cannot throw %s because FindClass has failed", buf); 864 return; 865 } 866 char* msg = NULL; 867 env->ThrowNew(cls, msg); 868 } 869 870 static jclass Unsafe_DefineClass_impl(JNIEnv *env, jstring name, jbyteArray data, int offset, int length, jobject loader, jobject pd) { 871 { 872 // Code lifted from JDK 1.3 ClassLoader.c 873 874 jbyte *body; 875 char *utfName; 876 jclass result = 0; 877 char buf[128]; 878 879 if (UsePerfData) { 880 ClassLoader::unsafe_defineClassCallCounter()->inc(); 881 } 882 883 if (data == NULL) { 884 throw_new(env, "NullPointerException"); 885 return 0; |