< prev index next >

src/share/vm/prims/unsafe.cpp

Print this page
rev 9088 : 8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.


 766   }
 767   oop      mirror = JNIHandles::resolve_non_null(acls);
 768   Klass* k      = java_lang_Class::as_Klass(mirror);
 769   if (k == NULL || !k->oop_is_array()) {
 770     THROW(vmSymbols::java_lang_InvalidClassException());
 771   } else if (k->oop_is_objArray()) {
 772     base  = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
 773     scale = heapOopSize;
 774   } else if (k->oop_is_typeArray()) {
 775     TypeArrayKlass* tak = TypeArrayKlass::cast(k);
 776     base  = tak->array_header_in_bytes();
 777     assert(base == arrayOopDesc::base_offset_in_bytes(tak->element_type()), "array_header_size semantics ok");
 778     scale = (1 << tak->log2_element_size());
 779   } else {
 780     ShouldNotReachHere();
 781   }
 782 }
 783 
 784 UNSAFE_ENTRY(jint, Unsafe_ArrayBaseOffset(JNIEnv *env, jobject unsafe, jclass acls))
 785   UnsafeWrapper("Unsafe_ArrayBaseOffset");
 786   int base, scale;
 787   getBaseAndScale(base, scale, acls, CHECK_0);
 788   return field_offset_from_byte_offset(base);
 789 UNSAFE_END
 790 
 791 
 792 UNSAFE_ENTRY(jint, Unsafe_ArrayIndexScale(JNIEnv *env, jobject unsafe, jclass acls))
 793   UnsafeWrapper("Unsafe_ArrayIndexScale");
 794   int base, scale;
 795   getBaseAndScale(base, scale, acls, CHECK_0);
 796   // This VM packs both fields and array elements down to the byte.
 797   // But watch out:  If this changes, so that array references for
 798   // a given primitive type (say, T_BOOLEAN) use different memory units
 799   // than fields, this method MUST return zero for such arrays.
 800   // For example, the VM used to store sub-word sized fields in full
 801   // words in the object layout, so that accessors like getByte(Object,int)
 802   // did not really do what one might expect for arrays.  Therefore,
 803   // this function used to report a zero scale factor, so that the user
 804   // would know not to attempt to access sub-word array elements.
 805   // // Code for unpacked fields:
 806   // if (scale < wordSize)  return 0;
 807 
 808   // The following allows for a pretty general fieldOffset cookie scheme,
 809   // but requires it to be linear in byte offset.
 810   return field_offset_from_byte_offset(scale) - field_offset_from_byte_offset(0);
 811 UNSAFE_END
 812 
 813 
 814 static inline void throw_new(JNIEnv *env, const char *ename) {




 766   }
 767   oop      mirror = JNIHandles::resolve_non_null(acls);
 768   Klass* k      = java_lang_Class::as_Klass(mirror);
 769   if (k == NULL || !k->oop_is_array()) {
 770     THROW(vmSymbols::java_lang_InvalidClassException());
 771   } else if (k->oop_is_objArray()) {
 772     base  = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
 773     scale = heapOopSize;
 774   } else if (k->oop_is_typeArray()) {
 775     TypeArrayKlass* tak = TypeArrayKlass::cast(k);
 776     base  = tak->array_header_in_bytes();
 777     assert(base == arrayOopDesc::base_offset_in_bytes(tak->element_type()), "array_header_size semantics ok");
 778     scale = (1 << tak->log2_element_size());
 779   } else {
 780     ShouldNotReachHere();
 781   }
 782 }
 783 
 784 UNSAFE_ENTRY(jint, Unsafe_ArrayBaseOffset(JNIEnv *env, jobject unsafe, jclass acls))
 785   UnsafeWrapper("Unsafe_ArrayBaseOffset");
 786   int base = 0, scale = 0;
 787   getBaseAndScale(base, scale, acls, CHECK_0);
 788   return field_offset_from_byte_offset(base);
 789 UNSAFE_END
 790 
 791 
 792 UNSAFE_ENTRY(jint, Unsafe_ArrayIndexScale(JNIEnv *env, jobject unsafe, jclass acls))
 793   UnsafeWrapper("Unsafe_ArrayIndexScale");
 794   int base = 0, scale = 0;
 795   getBaseAndScale(base, scale, acls, CHECK_0);
 796   // This VM packs both fields and array elements down to the byte.
 797   // But watch out:  If this changes, so that array references for
 798   // a given primitive type (say, T_BOOLEAN) use different memory units
 799   // than fields, this method MUST return zero for such arrays.
 800   // For example, the VM used to store sub-word sized fields in full
 801   // words in the object layout, so that accessors like getByte(Object,int)
 802   // did not really do what one might expect for arrays.  Therefore,
 803   // this function used to report a zero scale factor, so that the user
 804   // would know not to attempt to access sub-word array elements.
 805   // // Code for unpacked fields:
 806   // if (scale < wordSize)  return 0;
 807 
 808   // The following allows for a pretty general fieldOffset cookie scheme,
 809   // but requires it to be linear in byte offset.
 810   return field_offset_from_byte_offset(scale) - field_offset_from_byte_offset(0);
 811 UNSAFE_END
 812 
 813 
 814 static inline void throw_new(JNIEnv *env, const char *ename) {


< prev index next >