< prev index next >

src/share/vm/prims/unsafe.cpp

Print this page




  93 static inline jlong field_offset_to_byte_offset(jlong field_offset) {
  94   return field_offset;
  95 }
  96 
  97 static inline jlong field_offset_from_byte_offset(jlong byte_offset) {
  98   return byte_offset;
  99 }
 100 
 101 static inline void* index_oop_from_field_offset_long(oop p, jlong field_offset) {
 102   jlong byte_offset = field_offset_to_byte_offset(field_offset);
 103 
 104 #ifdef ASSERT
 105   if (p != NULL) {
 106     assert(byte_offset >= 0 && byte_offset <= (jlong)MAX_OBJECT_SIZE, "sane offset");
 107     if (byte_offset == (jint)byte_offset) {
 108       void* ptr_plus_disp = (address)p + byte_offset;
 109       assert((void*)p->obj_field_addr<oop>((jint)byte_offset) == ptr_plus_disp,
 110              "raw [ptr+disp] must be consistent with oop::field_base");
 111     }
 112     jlong p_size = HeapWordSize * (jlong)(p->size());
 113     assert(byte_offset < p_size, "Unsafe access: offset " INT64_FORMAT " > object's size " INT64_FORMAT, byte_offset, p_size);
 114   }
 115 #endif
 116 
 117   if (sizeof(char*) == sizeof(jint)) {   // (this constant folds!)
 118     return (address)p + (jint) byte_offset;
 119   } else {
 120     return (address)p +        byte_offset;
 121   }
 122 }
 123 
 124 // Externally callable versions:
 125 // (Use these in compiler intrinsics which emulate unsafe primitives.)
 126 jlong Unsafe_field_offset_to_byte_offset(jlong field_offset) {
 127   return field_offset;
 128 }
 129 jlong Unsafe_field_offset_from_byte_offset(jlong byte_offset) {
 130   return byte_offset;
 131 }
 132 
 133 




  93 static inline jlong field_offset_to_byte_offset(jlong field_offset) {
  94   return field_offset;
  95 }
  96 
  97 static inline jlong field_offset_from_byte_offset(jlong byte_offset) {
  98   return byte_offset;
  99 }
 100 
 101 static inline void* index_oop_from_field_offset_long(oop p, jlong field_offset) {
 102   jlong byte_offset = field_offset_to_byte_offset(field_offset);
 103 
 104 #ifdef ASSERT
 105   if (p != NULL) {
 106     assert(byte_offset >= 0 && byte_offset <= (jlong)MAX_OBJECT_SIZE, "sane offset");
 107     if (byte_offset == (jint)byte_offset) {
 108       void* ptr_plus_disp = (address)p + byte_offset;
 109       assert((void*)p->obj_field_addr<oop>((jint)byte_offset) == ptr_plus_disp,
 110              "raw [ptr+disp] must be consistent with oop::field_base");
 111     }
 112     jlong p_size = HeapWordSize * (jlong)(p->size());
 113     assert(byte_offset < p_size, "Unsafe access: offset " INT64_FORMAT " > object's size " INT64_FORMAT, (int64_t)byte_offset, (int64_t)p_size);
 114   }
 115 #endif
 116 
 117   if (sizeof(char*) == sizeof(jint)) {   // (this constant folds!)
 118     return (address)p + (jint) byte_offset;
 119   } else {
 120     return (address)p +        byte_offset;
 121   }
 122 }
 123 
 124 // Externally callable versions:
 125 // (Use these in compiler intrinsics which emulate unsafe primitives.)
 126 jlong Unsafe_field_offset_to_byte_offset(jlong field_offset) {
 127   return field_offset;
 128 }
 129 jlong Unsafe_field_offset_from_byte_offset(jlong byte_offset) {
 130   return byte_offset;
 131 }
 132 
 133 


< prev index next >