< prev index next >

src/share/vm/prims/unsafe.cpp

Print this page




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




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


< prev index next >