< prev index next >

src/share/vm/oops/oop.inline.hpp

Print this page




 215   // a virtual call.
 216   //
 217   // We go to all this trouble because the size computation is at the
 218   // heart of phase 2 of mark-compaction, and called for every object,
 219   // alive or dead.  So the speed here is equal in importance to the
 220   // speed of allocation.
 221 
 222   if (lh > Klass::_lh_neutral_value) {
 223     if (!Klass::layout_helper_needs_slow_path(lh)) {
 224       s = lh >> LogHeapWordSize;  // deliver size scaled by wordSize
 225     } else {
 226       s = klass->oop_size(this);
 227     }
 228   } else if (lh <= Klass::_lh_neutral_value) {
 229     // The most common case is instances; fall through if so.
 230     if (lh < Klass::_lh_neutral_value) {
 231       // Second most common case is arrays.  We have to fetch the
 232       // length of the array, shift (multiply) it appropriately,
 233       // up to wordSize, add the header, and align to object size.
 234       size_t size_in_bytes;
 235 #ifdef _M_IA64
 236       // The Windows Itanium Aug 2002 SDK hoists this load above
 237       // the check for s < 0.  An oop at the end of the heap will
 238       // cause an access violation if this load is performed on a non
 239       // array oop.  Making the reference volatile prohibits this.
 240       // (%%% please explain by what magic the length is actually fetched!)
 241       volatile int *array_length;
 242       array_length = (volatile int *)( (intptr_t)this +
 243                           arrayOopDesc::length_offset_in_bytes() );
 244       assert(array_length > 0, "Integer arithmetic problem somewhere");
 245       // Put into size_t to avoid overflow.
 246       size_in_bytes = (size_t) array_length;
 247       size_in_bytes = size_in_bytes << Klass::layout_helper_log2_element_size(lh);
 248 #else
 249       size_t array_length = (size_t) ((arrayOop)this)->length();
 250       size_in_bytes = array_length << Klass::layout_helper_log2_element_size(lh);
 251 #endif
 252       size_in_bytes += Klass::layout_helper_header_size(lh);
 253 
 254       // This code could be simplified, but by keeping array_header_in_bytes
 255       // in units of bytes and doing it this way we can round up just once,
 256       // skipping the intermediate round to HeapWordSize.  Cast the result
 257       // of round_to to size_t to guarantee unsigned division == right shift.
 258       s = (int)((size_t)round_to(size_in_bytes, MinObjAlignmentInBytes) /
 259         HeapWordSize);
 260 
 261       // ParNew (used by CMS), UseParallelGC and UseG1GC can change the length field
 262       // of an "old copy" of an object array in the young gen so it indicates
 263       // the grey portion of an already copied array. This will cause the first
 264       // disjunct below to fail if the two comparands are computed across such
 265       // a concurrent change.
 266       // ParNew also runs with promotion labs (which look like int
 267       // filler arrays) which are subject to changing their declared size
 268       // when finally retiring a PLAB; this also can cause the first disjunct
 269       // to fail for another worker thread that is concurrently walking the block
 270       // offset table. Both these invariant failures are benign for their
 271       // current uses; we relax the assertion checking to cover these two cases below:




 215   // a virtual call.
 216   //
 217   // We go to all this trouble because the size computation is at the
 218   // heart of phase 2 of mark-compaction, and called for every object,
 219   // alive or dead.  So the speed here is equal in importance to the
 220   // speed of allocation.
 221 
 222   if (lh > Klass::_lh_neutral_value) {
 223     if (!Klass::layout_helper_needs_slow_path(lh)) {
 224       s = lh >> LogHeapWordSize;  // deliver size scaled by wordSize
 225     } else {
 226       s = klass->oop_size(this);
 227     }
 228   } else if (lh <= Klass::_lh_neutral_value) {
 229     // The most common case is instances; fall through if so.
 230     if (lh < Klass::_lh_neutral_value) {
 231       // Second most common case is arrays.  We have to fetch the
 232       // length of the array, shift (multiply) it appropriately,
 233       // up to wordSize, add the header, and align to object size.
 234       size_t size_in_bytes;














 235       size_t array_length = (size_t) ((arrayOop)this)->length();
 236       size_in_bytes = array_length << Klass::layout_helper_log2_element_size(lh);

 237       size_in_bytes += Klass::layout_helper_header_size(lh);
 238 
 239       // This code could be simplified, but by keeping array_header_in_bytes
 240       // in units of bytes and doing it this way we can round up just once,
 241       // skipping the intermediate round to HeapWordSize.  Cast the result
 242       // of round_to to size_t to guarantee unsigned division == right shift.
 243       s = (int)((size_t)round_to(size_in_bytes, MinObjAlignmentInBytes) /
 244         HeapWordSize);
 245 
 246       // ParNew (used by CMS), UseParallelGC and UseG1GC can change the length field
 247       // of an "old copy" of an object array in the young gen so it indicates
 248       // the grey portion of an already copied array. This will cause the first
 249       // disjunct below to fail if the two comparands are computed across such
 250       // a concurrent change.
 251       // ParNew also runs with promotion labs (which look like int
 252       // filler arrays) which are subject to changing their declared size
 253       // when finally retiring a PLAB; this also can cause the first disjunct
 254       // to fail for another worker thread that is concurrently walking the block
 255       // offset table. Both these invariant failures are benign for their
 256       // current uses; we relax the assertion checking to cover these two cases below:


< prev index next >