183 } |
183 } |
184 |
184 |
185 |
185 |
186 // Get/SetObject must be special-cased, since it works with handles. |
186 // Get/SetObject must be special-cased, since it works with handles. |
187 |
187 |
188 // The xxx140 variants for backward compatibility do not allow a full-width offset. |
188 // These functions allow a null base pointer with an arbitrary address. |
189 UNSAFE_ENTRY(jobject, Unsafe_GetObject140(JNIEnv *env, jobject unsafe, jobject obj, jint offset)) |
|
190 UnsafeWrapper("Unsafe_GetObject"); |
|
191 if (obj == NULL) THROW_0(vmSymbols::java_lang_NullPointerException()); |
|
192 GET_OOP_FIELD(obj, offset, v) |
|
193 jobject ret = JNIHandles::make_local(env, v); |
|
194 #if INCLUDE_ALL_GCS |
|
195 // We could be accessing the referent field in a reference |
|
196 // object. If G1 is enabled then we need to register a non-null |
|
197 // referent with the SATB barrier. |
|
198 if (UseG1GC) { |
|
199 bool needs_barrier = false; |
|
200 |
|
201 if (ret != NULL) { |
|
202 if (offset == java_lang_ref_Reference::referent_offset) { |
|
203 oop o = JNIHandles::resolve_non_null(obj); |
|
204 Klass* k = o->klass(); |
|
205 if (InstanceKlass::cast(k)->reference_type() != REF_NONE) { |
|
206 assert(InstanceKlass::cast(k)->is_subclass_of(SystemDictionary::Reference_klass()), "sanity"); |
|
207 needs_barrier = true; |
|
208 } |
|
209 } |
|
210 } |
|
211 |
|
212 if (needs_barrier) { |
|
213 oop referent = JNIHandles::resolve(ret); |
|
214 G1SATBCardTableModRefBS::enqueue(referent); |
|
215 } |
|
216 } |
|
217 #endif // INCLUDE_ALL_GCS |
|
218 return ret; |
|
219 UNSAFE_END |
|
220 |
|
221 UNSAFE_ENTRY(void, Unsafe_SetObject140(JNIEnv *env, jobject unsafe, jobject obj, jint offset, jobject x_h)) |
|
222 UnsafeWrapper("Unsafe_SetObject"); |
|
223 if (obj == NULL) THROW(vmSymbols::java_lang_NullPointerException()); |
|
224 oop x = JNIHandles::resolve(x_h); |
|
225 //SET_FIELD(obj, offset, oop, x); |
|
226 oop p = JNIHandles::resolve(obj); |
|
227 if (UseCompressedOops) { |
|
228 if (x != NULL) { |
|
229 // If there is a heap base pointer, we are obliged to emit a store barrier. |
|
230 oop_store((narrowOop*)index_oop_from_field_offset_long(p, offset), x); |
|
231 } else { |
|
232 narrowOop n = oopDesc::encode_heap_oop_not_null(x); |
|
233 *(narrowOop*)index_oop_from_field_offset_long(p, offset) = n; |
|
234 } |
|
235 } else { |
|
236 if (x != NULL) { |
|
237 // If there is a heap base pointer, we are obliged to emit a store barrier. |
|
238 oop_store((oop*)index_oop_from_field_offset_long(p, offset), x); |
|
239 } else { |
|
240 *(oop*)index_oop_from_field_offset_long(p, offset) = x; |
|
241 } |
|
242 } |
|
243 UNSAFE_END |
|
244 |
|
245 // The normal variants allow a null base pointer with an arbitrary address. |
|
246 // But if the base pointer is non-null, the offset should make some sense. |
189 // But if the base pointer is non-null, the offset should make some sense. |
247 // That is, it should be in the range [0, MAX_OBJECT_SIZE]. |
190 // That is, it should be in the range [0, MAX_OBJECT_SIZE]. |
248 UNSAFE_ENTRY(jobject, Unsafe_GetObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) |
191 UNSAFE_ENTRY(jobject, Unsafe_GetObject(JNIEnv *env, jobject unsafe, jobject obj, jlong offset)) |
249 UnsafeWrapper("Unsafe_GetObject"); |
192 UnsafeWrapper("Unsafe_GetObject"); |
250 GET_OOP_FIELD(obj, offset, v) |
193 GET_OOP_FIELD(obj, offset, v) |
1348 |
1291 |
1349 |
1292 |
1350 |
1293 |
1351 // These are the methods for 1.4.0 |
1294 // These are the methods for 1.4.0 |
1352 static JNINativeMethod methods_140[] = { |
1295 static JNINativeMethod methods_140[] = { |
1353 {CC"getObject", CC"("OBJ"I)"OBJ"", FN_PTR(Unsafe_GetObject140)}, |
|
1354 {CC"putObject", CC"("OBJ"I"OBJ")V", FN_PTR(Unsafe_SetObject140)}, |
|
1355 |
|
1356 DECLARE_GETSETOOP_140(Boolean, Z), |
1296 DECLARE_GETSETOOP_140(Boolean, Z), |
1357 DECLARE_GETSETOOP_140(Byte, B), |
1297 DECLARE_GETSETOOP_140(Byte, B), |
1358 DECLARE_GETSETOOP_140(Short, S), |
1298 DECLARE_GETSETOOP_140(Short, S), |
1359 DECLARE_GETSETOOP_140(Char, C), |
1299 DECLARE_GETSETOOP_140(Char, C), |
1360 DECLARE_GETSETOOP_140(Int, I), |
1300 DECLARE_GETSETOOP_140(Int, I), |