3946 float_to_int_bits_fn == NULL && 3947 double_to_long_bits_fn == NULL , 3948 "initialization done twice" 3949 ); 3950 // initialize 3951 int_bits_to_float_fn = CAST_TO_FN_PTR(IntBitsToFloatFn , NativeLookup::base_library_lookup("java/lang/Float" , "intBitsToFloat" , "(I)F")); 3952 long_bits_to_double_fn = CAST_TO_FN_PTR(LongBitsToDoubleFn, NativeLookup::base_library_lookup("java/lang/Double", "longBitsToDouble", "(J)D")); 3953 float_to_int_bits_fn = CAST_TO_FN_PTR(FloatToIntBitsFn , NativeLookup::base_library_lookup("java/lang/Float" , "floatToIntBits" , "(F)I")); 3954 double_to_long_bits_fn = CAST_TO_FN_PTR(DoubleToLongBitsFn, NativeLookup::base_library_lookup("java/lang/Double", "doubleToLongBits", "(D)J")); 3955 // verify 3956 assert( 3957 int_bits_to_float_fn != NULL && 3958 long_bits_to_double_fn != NULL && 3959 float_to_int_bits_fn != NULL && 3960 double_to_long_bits_fn != NULL , 3961 "initialization failed" 3962 ); 3963 } 3964 3965 3966 // Serialization 3967 JVM_ENTRY(void, JVM_SetPrimitiveFieldValues(JNIEnv *env, jclass cb, jobject obj, 3968 jlongArray fieldIDs, jcharArray typecodes, jbyteArray data)) 3969 assert(!JDK_Version::is_gte_jdk14x_version(), "should only be used in 1.3.1 and earlier"); 3970 3971 typeArrayOop tcodes = typeArrayOop(JNIHandles::resolve(typecodes)); 3972 typeArrayOop dbuf = typeArrayOop(JNIHandles::resolve(data)); 3973 typeArrayOop fids = typeArrayOop(JNIHandles::resolve(fieldIDs)); 3974 oop o = JNIHandles::resolve(obj); 3975 3976 if (o == NULL || fids == NULL || dbuf == NULL || tcodes == NULL) { 3977 THROW(vmSymbols::java_lang_NullPointerException()); 3978 } 3979 3980 jsize nfids = fids->length(); 3981 if (nfids == 0) return; 3982 3983 if (tcodes->length() < nfids) { 3984 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); 3985 } 3986 3987 jsize off = 0; 3988 /* loop through fields, setting values */ 3989 for (jsize i = 0; i < nfids; i++) { 3990 jfieldID fid = (jfieldID)(intptr_t) fids->long_at(i); 3991 int field_offset; 3992 if (fid != NULL) { 3993 // NULL is a legal value for fid, but retrieving the field offset 3994 // trigger assertion in that case 3995 field_offset = jfieldIDWorkaround::from_instance_jfieldID(o->klass(), fid); 3996 } 3997 3998 switch (tcodes->char_at(i)) { 3999 case 'Z': 4000 if (fid != NULL) { 4001 jboolean val = (dbuf->byte_at(off) != 0) ? JNI_TRUE : JNI_FALSE; 4002 o->bool_field_put(field_offset, val); 4003 } 4004 off++; 4005 break; 4006 4007 case 'B': 4008 if (fid != NULL) { 4009 o->byte_field_put(field_offset, dbuf->byte_at(off)); 4010 } 4011 off++; 4012 break; 4013 4014 case 'C': 4015 if (fid != NULL) { 4016 jchar val = ((dbuf->byte_at(off + 0) & 0xFF) << 8) 4017 + ((dbuf->byte_at(off + 1) & 0xFF) << 0); 4018 o->char_field_put(field_offset, val); 4019 } 4020 off += 2; 4021 break; 4022 4023 case 'S': 4024 if (fid != NULL) { 4025 jshort val = ((dbuf->byte_at(off + 0) & 0xFF) << 8) 4026 + ((dbuf->byte_at(off + 1) & 0xFF) << 0); 4027 o->short_field_put(field_offset, val); 4028 } 4029 off += 2; 4030 break; 4031 4032 case 'I': 4033 if (fid != NULL) { 4034 jint ival = ((dbuf->byte_at(off + 0) & 0xFF) << 24) 4035 + ((dbuf->byte_at(off + 1) & 0xFF) << 16) 4036 + ((dbuf->byte_at(off + 2) & 0xFF) << 8) 4037 + ((dbuf->byte_at(off + 3) & 0xFF) << 0); 4038 o->int_field_put(field_offset, ival); 4039 } 4040 off += 4; 4041 break; 4042 4043 case 'F': 4044 if (fid != NULL) { 4045 jint ival = ((dbuf->byte_at(off + 0) & 0xFF) << 24) 4046 + ((dbuf->byte_at(off + 1) & 0xFF) << 16) 4047 + ((dbuf->byte_at(off + 2) & 0xFF) << 8) 4048 + ((dbuf->byte_at(off + 3) & 0xFF) << 0); 4049 jfloat fval = (*int_bits_to_float_fn)(env, NULL, ival); 4050 o->float_field_put(field_offset, fval); 4051 } 4052 off += 4; 4053 break; 4054 4055 case 'J': 4056 if (fid != NULL) { 4057 jlong lval = (((jlong) dbuf->byte_at(off + 0) & 0xFF) << 56) 4058 + (((jlong) dbuf->byte_at(off + 1) & 0xFF) << 48) 4059 + (((jlong) dbuf->byte_at(off + 2) & 0xFF) << 40) 4060 + (((jlong) dbuf->byte_at(off + 3) & 0xFF) << 32) 4061 + (((jlong) dbuf->byte_at(off + 4) & 0xFF) << 24) 4062 + (((jlong) dbuf->byte_at(off + 5) & 0xFF) << 16) 4063 + (((jlong) dbuf->byte_at(off + 6) & 0xFF) << 8) 4064 + (((jlong) dbuf->byte_at(off + 7) & 0xFF) << 0); 4065 o->long_field_put(field_offset, lval); 4066 } 4067 off += 8; 4068 break; 4069 4070 case 'D': 4071 if (fid != NULL) { 4072 jlong lval = (((jlong) dbuf->byte_at(off + 0) & 0xFF) << 56) 4073 + (((jlong) dbuf->byte_at(off + 1) & 0xFF) << 48) 4074 + (((jlong) dbuf->byte_at(off + 2) & 0xFF) << 40) 4075 + (((jlong) dbuf->byte_at(off + 3) & 0xFF) << 32) 4076 + (((jlong) dbuf->byte_at(off + 4) & 0xFF) << 24) 4077 + (((jlong) dbuf->byte_at(off + 5) & 0xFF) << 16) 4078 + (((jlong) dbuf->byte_at(off + 6) & 0xFF) << 8) 4079 + (((jlong) dbuf->byte_at(off + 7) & 0xFF) << 0); 4080 jdouble dval = (*long_bits_to_double_fn)(env, NULL, lval); 4081 o->double_field_put(field_offset, dval); 4082 } 4083 off += 8; 4084 break; 4085 4086 default: 4087 // Illegal typecode 4088 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "illegal typecode"); 4089 } 4090 } 4091 JVM_END 4092 4093 4094 JVM_ENTRY(void, JVM_GetPrimitiveFieldValues(JNIEnv *env, jclass cb, jobject obj, 4095 jlongArray fieldIDs, jcharArray typecodes, jbyteArray data)) 4096 assert(!JDK_Version::is_gte_jdk14x_version(), "should only be used in 1.3.1 and earlier"); 4097 4098 typeArrayOop tcodes = typeArrayOop(JNIHandles::resolve(typecodes)); 4099 typeArrayOop dbuf = typeArrayOop(JNIHandles::resolve(data)); 4100 typeArrayOop fids = typeArrayOop(JNIHandles::resolve(fieldIDs)); 4101 oop o = JNIHandles::resolve(obj); 4102 4103 if (o == NULL || fids == NULL || dbuf == NULL || tcodes == NULL) { 4104 THROW(vmSymbols::java_lang_NullPointerException()); 4105 } 4106 4107 jsize nfids = fids->length(); 4108 if (nfids == 0) return; 4109 4110 if (tcodes->length() < nfids) { 4111 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); 4112 } 4113 4114 /* loop through fields, fetching values */ 4115 jsize off = 0; 4116 for (jsize i = 0; i < nfids; i++) { 4117 jfieldID fid = (jfieldID)(intptr_t) fids->long_at(i); 4118 if (fid == NULL) { 4119 THROW(vmSymbols::java_lang_NullPointerException()); 4120 } 4121 int field_offset = jfieldIDWorkaround::from_instance_jfieldID(o->klass(), fid); 4122 4123 switch (tcodes->char_at(i)) { 4124 case 'Z': 4125 { 4126 jboolean val = o->bool_field(field_offset); 4127 dbuf->byte_at_put(off++, (val != 0) ? 1 : 0); 4128 } 4129 break; 4130 4131 case 'B': 4132 dbuf->byte_at_put(off++, o->byte_field(field_offset)); 4133 break; 4134 4135 case 'C': 4136 { 4137 jchar val = o->char_field(field_offset); 4138 dbuf->byte_at_put(off++, (val >> 8) & 0xFF); 4139 dbuf->byte_at_put(off++, (val >> 0) & 0xFF); 4140 } 4141 break; 4142 4143 case 'S': 4144 { 4145 jshort val = o->short_field(field_offset); 4146 dbuf->byte_at_put(off++, (val >> 8) & 0xFF); 4147 dbuf->byte_at_put(off++, (val >> 0) & 0xFF); 4148 } 4149 break; 4150 4151 case 'I': 4152 { 4153 jint val = o->int_field(field_offset); 4154 dbuf->byte_at_put(off++, (val >> 24) & 0xFF); 4155 dbuf->byte_at_put(off++, (val >> 16) & 0xFF); 4156 dbuf->byte_at_put(off++, (val >> 8) & 0xFF); 4157 dbuf->byte_at_put(off++, (val >> 0) & 0xFF); 4158 } 4159 break; 4160 4161 case 'F': 4162 { 4163 jfloat fval = o->float_field(field_offset); 4164 jint ival = (*float_to_int_bits_fn)(env, NULL, fval); 4165 dbuf->byte_at_put(off++, (ival >> 24) & 0xFF); 4166 dbuf->byte_at_put(off++, (ival >> 16) & 0xFF); 4167 dbuf->byte_at_put(off++, (ival >> 8) & 0xFF); 4168 dbuf->byte_at_put(off++, (ival >> 0) & 0xFF); 4169 } 4170 break; 4171 4172 case 'J': 4173 { 4174 jlong val = o->long_field(field_offset); 4175 dbuf->byte_at_put(off++, (val >> 56) & 0xFF); 4176 dbuf->byte_at_put(off++, (val >> 48) & 0xFF); 4177 dbuf->byte_at_put(off++, (val >> 40) & 0xFF); 4178 dbuf->byte_at_put(off++, (val >> 32) & 0xFF); 4179 dbuf->byte_at_put(off++, (val >> 24) & 0xFF); 4180 dbuf->byte_at_put(off++, (val >> 16) & 0xFF); 4181 dbuf->byte_at_put(off++, (val >> 8) & 0xFF); 4182 dbuf->byte_at_put(off++, (val >> 0) & 0xFF); 4183 } 4184 break; 4185 4186 case 'D': 4187 { 4188 jdouble dval = o->double_field(field_offset); 4189 jlong lval = (*double_to_long_bits_fn)(env, NULL, dval); 4190 dbuf->byte_at_put(off++, (lval >> 56) & 0xFF); 4191 dbuf->byte_at_put(off++, (lval >> 48) & 0xFF); 4192 dbuf->byte_at_put(off++, (lval >> 40) & 0xFF); 4193 dbuf->byte_at_put(off++, (lval >> 32) & 0xFF); 4194 dbuf->byte_at_put(off++, (lval >> 24) & 0xFF); 4195 dbuf->byte_at_put(off++, (lval >> 16) & 0xFF); 4196 dbuf->byte_at_put(off++, (lval >> 8) & 0xFF); 4197 dbuf->byte_at_put(off++, (lval >> 0) & 0xFF); 4198 } 4199 break; 4200 4201 default: 4202 // Illegal typecode 4203 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "illegal typecode"); 4204 } 4205 } 4206 JVM_END 4207 4208 4209 // Shared JNI/JVM entry points ////////////////////////////////////////////////////////////// 4210 4211 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init, Handle loader, Handle protection_domain, jboolean throwError, TRAPS) { 4212 // Security Note: 4213 // The Java level wrapper will perform the necessary security check allowing 4214 // us to pass the NULL as the initiating class loader. 4215 Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL); 4216 4217 KlassHandle klass_handle(THREAD, klass); 4218 // Check if we should initialize the class 4219 if (init && klass_handle->oop_is_instance()) { 4220 klass_handle->initialize(CHECK_NULL); 4221 } 4222 return (jclass) JNIHandles::make_local(env, klass_handle->java_mirror()); 4223 } 4224 4225 4226 // Internal SQE debugging support /////////////////////////////////////////////////////////// 4227 | 3946 float_to_int_bits_fn == NULL && 3947 double_to_long_bits_fn == NULL , 3948 "initialization done twice" 3949 ); 3950 // initialize 3951 int_bits_to_float_fn = CAST_TO_FN_PTR(IntBitsToFloatFn , NativeLookup::base_library_lookup("java/lang/Float" , "intBitsToFloat" , "(I)F")); 3952 long_bits_to_double_fn = CAST_TO_FN_PTR(LongBitsToDoubleFn, NativeLookup::base_library_lookup("java/lang/Double", "longBitsToDouble", "(J)D")); 3953 float_to_int_bits_fn = CAST_TO_FN_PTR(FloatToIntBitsFn , NativeLookup::base_library_lookup("java/lang/Float" , "floatToIntBits" , "(F)I")); 3954 double_to_long_bits_fn = CAST_TO_FN_PTR(DoubleToLongBitsFn, NativeLookup::base_library_lookup("java/lang/Double", "doubleToLongBits", "(D)J")); 3955 // verify 3956 assert( 3957 int_bits_to_float_fn != NULL && 3958 long_bits_to_double_fn != NULL && 3959 float_to_int_bits_fn != NULL && 3960 double_to_long_bits_fn != NULL , 3961 "initialization failed" 3962 ); 3963 } 3964 3965 3966 3967 // Shared JNI/JVM entry points ////////////////////////////////////////////////////////////// 3968 3969 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init, Handle loader, Handle protection_domain, jboolean throwError, TRAPS) { 3970 // Security Note: 3971 // The Java level wrapper will perform the necessary security check allowing 3972 // us to pass the NULL as the initiating class loader. 3973 Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL); 3974 3975 KlassHandle klass_handle(THREAD, klass); 3976 // Check if we should initialize the class 3977 if (init && klass_handle->oop_is_instance()) { 3978 klass_handle->initialize(CHECK_NULL); 3979 } 3980 return (jclass) JNIHandles::make_local(env, klass_handle->java_mirror()); 3981 } 3982 3983 3984 // Internal SQE debugging support /////////////////////////////////////////////////////////// 3985 |