1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc/shared/barrierSet.hpp"
  27 #include "gc/shared/collectedHeap.inline.hpp"
  28 #include "gc/shared/gcLocker.inline.hpp"
  29 #include "interpreter/interpreter.hpp"
  30 #include "logging/log.hpp"
  31 #include "memory/metadataFactory.hpp"
  32 #include "oops/access.hpp"
  33 #include "oops/compressedOops.inline.hpp"
  34 #include "oops/fieldStreams.hpp"
  35 #include "oops/instanceKlass.inline.hpp"
  36 #include "oops/method.hpp"
  37 #include "oops/oop.inline.hpp"
  38 #include "oops/objArrayKlass.hpp"
  39 #include "oops/valueKlass.hpp"
  40 #include "oops/valueArrayKlass.hpp"
  41 #include "runtime/fieldDescriptor.inline.hpp"
  42 #include "runtime/handles.inline.hpp"
  43 #include "runtime/safepointVerifiers.hpp"
  44 #include "runtime/sharedRuntime.hpp"
  45 #include "runtime/signature.hpp"
  46 #include "runtime/thread.inline.hpp"
  47 #include "utilities/copy.hpp"
  48 
  49 int ValueKlass::first_field_offset() const {
  50 #ifdef ASSERT
  51   int first_offset = INT_MAX;
  52   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
  53     if (fs.offset() < first_offset) first_offset= fs.offset();
  54   }
  55 #endif
  56   int base_offset = instanceOopDesc::base_offset_in_bytes();
  57   // The first field of value types is aligned on a long boundary
  58   base_offset = align_up(base_offset, BytesPerLong);
  59   assert(base_offset == first_offset, "inconsistent offsets");
  60   return base_offset;
  61 }
  62 
  63 int ValueKlass::raw_value_byte_size() const {
  64   int heapOopAlignedSize = nonstatic_field_size() << LogBytesPerHeapOop;
  65   // If bigger than 64 bits or needs oop alignment, then use jlong aligned
  66   // which for values should be jlong aligned, asserts in raw_field_copy otherwise
  67   if (heapOopAlignedSize >= longSize || contains_oops()) {
  68     return heapOopAlignedSize;
  69   }
  70   // Small primitives...
  71   // If a few small basic type fields, return the actual size, i.e.
  72   // 1 byte = 1
  73   // 2 byte = 2
  74   // 3 byte = 4, because pow2 needed for element stores
  75   int first_offset = first_field_offset();
  76   int last_offset  = 0; // find the last offset, add basic type size
  77   int last_tsz     = 0;
  78   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
  79     if (fs.access_flags().is_static()) {
  80       continue;
  81     } else if (fs.offset() > last_offset) {
  82       BasicType type = fs.field_descriptor().field_type();
  83       if (is_java_primitive(type)) {
  84         last_tsz = type2aelembytes(type);
  85       } else if (type == T_VALUETYPE) {
  86         // Not just primitives. Layout aligns embedded value, so use jlong aligned it is
  87         return heapOopAlignedSize;
  88       } else {
  89         guarantee(0, "Unknown type %d", type);
  90       }
  91       assert(last_tsz != 0, "Invariant");
  92       last_offset = fs.offset();
  93     }
  94   }
  95   // Assumes VT with no fields are meaningless and illegal
  96   last_offset += last_tsz;
  97   assert(last_offset > first_offset && last_tsz, "Invariant");
  98   return 1 << upper_log2(last_offset - first_offset);
  99 }
 100 
 101 instanceOop ValueKlass::allocate_instance(TRAPS) {
 102   int size = size_helper();  // Query before forming handle.
 103 
 104   instanceOop oop = (instanceOop)Universe::heap()->obj_allocate(this, size, CHECK_NULL);
 105   assert(oop->mark()->is_always_locked(), "Unlocked value type");
 106   return oop;
 107 }
 108 
 109 bool ValueKlass::is_atomic() {
 110   return (nonstatic_field_size() * heapOopSize) <= longSize;
 111 }
 112 
 113 int ValueKlass::nonstatic_oop_count() {
 114   int oops = 0;
 115   int map_count = nonstatic_oop_map_count();
 116   OopMapBlock* block = start_of_nonstatic_oop_maps();
 117   OopMapBlock* end = block + map_count;
 118   while (block != end) {
 119     oops += block->count();
 120     block++;
 121   }
 122   return oops;
 123 }
 124 
 125 // Arrays of...
 126 
 127 bool ValueKlass::flatten_array() {
 128   if (!ValueArrayFlatten) {
 129     return false;
 130   }
 131 
 132   int elem_bytes = raw_value_byte_size();
 133   // Too big
 134   if ((ValueArrayElemMaxFlatSize >= 0) && (elem_bytes > ValueArrayElemMaxFlatSize)) {
 135     return false;
 136   }
 137   // Too many embedded oops
 138   if ((ValueArrayElemMaxFlatOops >= 0) && (nonstatic_oop_count() > ValueArrayElemMaxFlatOops)) {
 139     return false;
 140   }
 141 
 142   return true;
 143 }
 144 
 145 
 146 Klass* ValueKlass::array_klass_impl(ArrayStorageProperties storage_props, bool or_null, int n, TRAPS) {
 147   if (storage_props.is_flattened()) {
 148     return value_array_klass(storage_props, or_null, n, THREAD);
 149   } else {
 150     return InstanceKlass::array_klass_impl(storage_props, or_null, n, THREAD);
 151   }
 152 }
 153 
 154 Klass* ValueKlass::array_klass_impl(ArrayStorageProperties storage_props, bool or_null, TRAPS) {
 155   return array_klass_impl(storage_props, or_null, 1, THREAD);
 156 }
 157 
 158 Klass* ValueKlass::value_array_klass(ArrayStorageProperties storage_props, bool or_null, int rank, TRAPS) {
 159   Klass* vak = acquire_value_array_klass();
 160   if (vak == NULL) {
 161     if (or_null) return NULL;
 162     ResourceMark rm;
 163     JavaThread *jt = (JavaThread *)THREAD;
 164     {
 165       // Atomic creation of array_klasses
 166       MutexLocker ma(MultiArray_lock, THREAD);
 167       if (get_value_array_klass() == NULL) {
 168         vak = allocate_value_array_klass(CHECK_NULL);
 169         OrderAccess::release_store((Klass**)adr_value_array_klass(), vak);
 170       }
 171     }
 172   }
 173 
 174   if (!vak->is_valueArray_klass()) {
 175     storage_props.clear_flattened();
 176   }
 177   if (or_null) {
 178     return vak->array_klass_or_null(storage_props, rank);
 179   }
 180   return vak->array_klass(storage_props, rank, THREAD);
 181 }
 182 
 183 Klass* ValueKlass::allocate_value_array_klass(TRAPS) {
 184   if (flatten_array() && (is_atomic() || (!ValueArrayAtomicAccess))) {
 185     return ValueArrayKlass::allocate_klass(ArrayStorageProperties::flattened_and_null_free, this, THREAD);
 186   }
 187   return ObjArrayKlass::allocate_objArray_klass(ArrayStorageProperties::null_free, 1, this, THREAD);
 188 }
 189 
 190 void ValueKlass::array_klasses_do(void f(Klass* k)) {
 191   InstanceKlass::array_klasses_do(f);
 192   if (get_value_array_klass() != NULL)
 193     ArrayKlass::cast(get_value_array_klass())->array_klasses_do(f);
 194 }
 195 
 196 void ValueKlass::raw_field_copy(void* src, void* dst, size_t raw_byte_size) {
 197   /*
 198    * Try not to shear fields even if not an atomic store...
 199    *
 200    * First 3 cases handle value array store, otherwise works on the same basis
 201    * as JVM_Clone, at this size data is aligned. The order of primitive types
 202    * is largest to smallest, and it not possible for fields to stradle long
 203    * copy boundaries.
 204    *
 205    * If MT without exclusive access, possible to observe partial value store,
 206    * but not partial primitive and reference field values
 207    */
 208   switch (raw_byte_size) {
 209     case 1:
 210       *((jbyte*) dst) = *(jbyte*)src;
 211       break;
 212     case 2:
 213       *((jshort*) dst) = *(jshort*)src;
 214       break;
 215     case 4:
 216       *((jint*) dst) = *(jint*) src;
 217       break;
 218     default:
 219       assert(raw_byte_size % sizeof(jlong) == 0, "Unaligned raw_byte_size");
 220       Copy::conjoint_jlongs_atomic((jlong*)src, (jlong*)dst, raw_byte_size >> LogBytesPerLong);
 221   }
 222 }
 223 
 224 /*
 225  * Store the value of this klass contained with src into dst.
 226  *
 227  * This operation is appropriate for use from vastore, vaload and putfield (for values)
 228  *
 229  * GC barriers currently can lock with no safepoint check and allocate c-heap,
 230  * so raw point is "safe" for now.
 231  *
 232  * Going forward, look to use machine generated (stub gen or bc) version for most used klass layouts
 233  *
 234  */
 235 void ValueKlass::value_store(void* src, void* dst, size_t raw_byte_size, bool dst_heap, bool dst_uninitialized) {
 236   if (contains_oops()) {
 237     if (dst_heap) {
 238       // src/dst aren't oops, need offset to adjust oop map offset
 239       const address dst_oop_addr = ((address) dst) - first_field_offset();
 240 
 241       ModRefBarrierSet* bs = barrier_set_cast<ModRefBarrierSet>(BarrierSet::barrier_set());
 242 
 243       // Pre-barriers...
 244       OopMapBlock* map = start_of_nonstatic_oop_maps();
 245       OopMapBlock* const end = map + nonstatic_oop_map_count();
 246       while (map != end) {
 247         // Shame we can't just use the existing oop iterator...src/dst aren't oop
 248         address doop_address = dst_oop_addr + map->offset();
 249         // TEMP HACK: barrier code need to migrate to => access API (need own versions of value type ops)
 250         if (UseCompressedOops) {
 251           bs->write_ref_array_pre((narrowOop*) doop_address, map->count(), dst_uninitialized);
 252         } else {
 253           bs->write_ref_array_pre((oop*) doop_address, map->count(), dst_uninitialized);
 254         }
 255         map++;
 256       }
 257 
 258       raw_field_copy(src, dst, raw_byte_size);
 259 
 260       // Post-barriers...
 261       map = start_of_nonstatic_oop_maps();
 262       while (map != end) {
 263         address doop_address = dst_oop_addr + map->offset();
 264         bs->write_ref_array((HeapWord*) doop_address, map->count());
 265         map++;
 266       }
 267     } else { // Buffered value case
 268       raw_field_copy(src, dst, raw_byte_size);
 269     }
 270   } else {   // Primitive-only case...
 271     raw_field_copy(src, dst, raw_byte_size);
 272   }
 273 }
 274 
 275 // Value type arguments are not passed by reference, instead each
 276 // field of the value type is passed as an argument. This helper
 277 // function collects the fields of the value types (including embedded
 278 // value type's fields) in a list. Included with the field's type is
 279 // the offset of each field in the value type: i2c and c2i adapters
 280 // need that to load or store fields. Finally, the list of fields is
 281 // sorted in order of increasing offsets: the adapters and the
 282 // compiled code need to agree upon the order of fields.
 283 //
 284 // The list of basic types that is returned starts with a T_VALUETYPE
 285 // and ends with an extra T_VOID. T_VALUETYPE/T_VOID pairs are used as
 286 // delimiters. Every entry between the two is a field of the value
 287 // type. If there's an embedded value type in the list, it also starts
 288 // with a T_VALUETYPE and ends with a T_VOID. This is so we can
 289 // generate a unique fingerprint for the method's adapters and we can
 290 // generate the list of basic types from the interpreter point of view
 291 // (value types passed as reference: iterate on the list until a
 292 // T_VALUETYPE, drop everything until and including the closing
 293 // T_VOID) or the compiler point of view (each field of the value
 294 // types is an argument: drop all T_VALUETYPE/T_VOID from the list).
 295 int ValueKlass::collect_fields(GrowableArray<SigEntry>* sig, int base_off) const {
 296   int count = 0;
 297   SigEntry::add_entry(sig, T_VALUETYPE, base_off);
 298   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
 299     if (fs.access_flags().is_static()) continue;
 300     int offset = base_off + fs.offset() - (base_off > 0 ? first_field_offset() : 0);
 301     if (fs.is_flattened()) {
 302       // Resolve klass of flattened value type field and recursively collect fields
 303       Klass* vk = get_value_field_klass(fs.index());
 304       count += ValueKlass::cast(vk)->collect_fields(sig, offset);
 305     } else {
 306       BasicType bt = FieldType::basic_type(fs.signature());
 307       if (bt == T_VALUETYPE) {
 308         bt = T_OBJECT;
 309       }
 310       SigEntry::add_entry(sig, bt, offset);
 311       count += type2size[bt];
 312     }
 313   }
 314   int offset = base_off + size_helper()*HeapWordSize - (base_off > 0 ? first_field_offset() : 0);
 315   SigEntry::add_entry(sig, T_VOID, offset);
 316   if (base_off == 0) {
 317     sig->sort(SigEntry::compare);
 318   }
 319   assert(sig->at(0)._bt == T_VALUETYPE && sig->at(sig->length()-1)._bt == T_VOID, "broken structure");
 320   return count;
 321 }
 322 
 323 void ValueKlass::initialize_calling_convention(TRAPS) {
 324   // Because the pack and unpack handler addresses need to be loadable from generated code,
 325   // they are stored at a fixed offset in the klass metadata. Since value type klasses do
 326   // not have a vtable, the vtable offset is used to store these addresses.
 327   if (ValueTypeReturnedAsFields || ValueTypePassFieldsAsArgs) {
 328     ResourceMark rm;
 329     GrowableArray<SigEntry> sig_vk;
 330     int nb_fields = collect_fields(&sig_vk);
 331     Array<SigEntry>* extended_sig = MetadataFactory::new_array<SigEntry>(class_loader_data(), sig_vk.length(), CHECK);
 332     *((Array<SigEntry>**)adr_extended_sig()) = extended_sig;
 333     for (int i = 0; i < sig_vk.length(); i++) {
 334       extended_sig->at_put(i, sig_vk.at(i));
 335     }
 336 
 337     if (ValueTypeReturnedAsFields) {
 338       nb_fields++;
 339       BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, nb_fields);
 340       sig_bt[0] = T_METADATA;
 341       SigEntry::fill_sig_bt(&sig_vk, sig_bt+1);
 342       VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, nb_fields);
 343       int total = SharedRuntime::java_return_convention(sig_bt, regs, nb_fields);
 344 
 345       if (total > 0) {
 346         Array<VMRegPair>* return_regs = MetadataFactory::new_array<VMRegPair>(class_loader_data(), nb_fields, CHECK);
 347         *((Array<VMRegPair>**)adr_return_regs()) = return_regs;
 348         for (int i = 0; i < nb_fields; i++) {
 349           return_regs->at_put(i, regs[i]);
 350         }
 351 
 352         BufferedValueTypeBlob* buffered_blob = SharedRuntime::generate_buffered_value_type_adapter(this);
 353         *((address*)adr_pack_handler()) = buffered_blob->pack_fields();
 354         *((address*)adr_unpack_handler()) = buffered_blob->unpack_fields();
 355         assert(CodeCache::find_blob(pack_handler()) == buffered_blob, "lost track of blob");
 356       }
 357     }
 358   }
 359 }
 360 
 361 void ValueKlass::deallocate_contents(ClassLoaderData* loader_data) {
 362   if (extended_sig() != NULL) {
 363     MetadataFactory::free_array<SigEntry>(loader_data, extended_sig());
 364   }
 365   if (return_regs() != NULL) {
 366     MetadataFactory::free_array<VMRegPair>(loader_data, return_regs());
 367   }
 368   cleanup_blobs();
 369   InstanceKlass::deallocate_contents(loader_data);
 370 }
 371 
 372 void ValueKlass::cleanup(ValueKlass* ik) {
 373   ik->cleanup_blobs();
 374 }
 375 
 376 void ValueKlass::cleanup_blobs() {
 377   if (pack_handler() != NULL) {
 378     CodeBlob* buffered_blob = CodeCache::find_blob(pack_handler());
 379     assert(buffered_blob->is_buffered_value_type_blob(), "bad blob type");
 380     BufferBlob::free((BufferBlob*)buffered_blob);
 381     *((address*)adr_pack_handler()) = NULL;
 382     *((address*)adr_unpack_handler()) = NULL;
 383   }
 384 }
 385 
 386 // Can this value type be returned as multiple values?
 387 bool ValueKlass::can_be_returned_as_fields() const {
 388   return return_regs() != NULL;
 389 }
 390 
 391 // Create handles for all oop fields returned in registers that are going to be live across a safepoint
 392 void ValueKlass::save_oop_fields(const RegisterMap& reg_map, GrowableArray<Handle>& handles) const {
 393   Thread* thread = Thread::current();
 394   const Array<SigEntry>* sig_vk = extended_sig();
 395   const Array<VMRegPair>* regs = return_regs();
 396   int j = 1;
 397 
 398   for (int i = 0; i < sig_vk->length(); i++) {
 399     BasicType bt = sig_vk->at(i)._bt;
 400     if (bt == T_OBJECT || bt == T_ARRAY) {
 401       VMRegPair pair = regs->at(j);
 402       address loc = reg_map.location(pair.first());
 403       oop v = *(oop*)loc;
 404       assert(v == NULL || oopDesc::is_oop(v), "not an oop?");
 405       assert(Universe::heap()->is_in_or_null(v), "must be heap pointer");
 406       handles.push(Handle(thread, v));
 407     }
 408     if (bt == T_VALUETYPE) {
 409       continue;
 410     }
 411     if (bt == T_VOID &&
 412         sig_vk->at(i-1)._bt != T_LONG &&
 413         sig_vk->at(i-1)._bt != T_DOUBLE) {
 414       continue;
 415     }
 416     j++;
 417   }
 418   assert(j == regs->length(), "missed a field?");
 419 }
 420 
 421 // Update oop fields in registers from handles after a safepoint
 422 void ValueKlass::restore_oop_results(RegisterMap& reg_map, GrowableArray<Handle>& handles) const {
 423   assert(ValueTypeReturnedAsFields, "inconsistent");
 424   const Array<SigEntry>* sig_vk = extended_sig();
 425   const Array<VMRegPair>* regs = return_regs();
 426   assert(regs != NULL, "inconsistent");
 427 
 428   int j = 1;
 429   for (int i = 0, k = 0; i < sig_vk->length(); i++) {
 430     BasicType bt = sig_vk->at(i)._bt;
 431     if (bt == T_OBJECT || bt == T_ARRAY) {
 432       VMRegPair pair = regs->at(j);
 433       address loc = reg_map.location(pair.first());
 434       *(oop*)loc = handles.at(k++)();
 435     }
 436     if (bt == T_VALUETYPE) {
 437       continue;
 438     }
 439     if (bt == T_VOID &&
 440         sig_vk->at(i-1)._bt != T_LONG &&
 441         sig_vk->at(i-1)._bt != T_DOUBLE) {
 442       continue;
 443     }
 444     j++;
 445   }
 446   assert(j == regs->length(), "missed a field?");
 447 }
 448 
 449 // Fields are in registers. Create an instance of the value type and
 450 // initialize it with the values of the fields.
 451 oop ValueKlass::realloc_result(const RegisterMap& reg_map, const GrowableArray<Handle>& handles, TRAPS) {
 452   oop new_vt = allocate_instance(CHECK_NULL);
 453   const Array<SigEntry>* sig_vk = extended_sig();
 454   const Array<VMRegPair>* regs = return_regs();
 455 
 456   int j = 1;
 457   int k = 0;
 458   for (int i = 0; i < sig_vk->length(); i++) {
 459     BasicType bt = sig_vk->at(i)._bt;
 460     if (bt == T_VALUETYPE) {
 461       continue;
 462     }
 463     if (bt == T_VOID) {
 464       if (sig_vk->at(i-1)._bt == T_LONG ||
 465           sig_vk->at(i-1)._bt == T_DOUBLE) {
 466         j++;
 467       }
 468       continue;
 469     }
 470     int off = sig_vk->at(i)._offset;
 471     assert(off > 0, "offset in object should be positive");
 472     VMRegPair pair = regs->at(j);
 473     address loc = reg_map.location(pair.first());
 474     switch(bt) {
 475     case T_BOOLEAN: {
 476       new_vt->bool_field_put(off, *(jboolean*)loc);
 477       break;
 478     }
 479     case T_CHAR: {
 480       new_vt->char_field_put(off, *(jchar*)loc);
 481       break;
 482     }
 483     case T_BYTE: {
 484       new_vt->byte_field_put(off, *(jbyte*)loc);
 485       break;
 486     }
 487     case T_SHORT: {
 488       new_vt->short_field_put(off, *(jshort*)loc);
 489       break;
 490     }
 491     case T_INT: {
 492       new_vt->int_field_put(off, *(jint*)loc);
 493       break;
 494     }
 495     case T_LONG: {
 496 #ifdef _LP64
 497       new_vt->double_field_put(off,  *(jdouble*)loc);
 498 #else
 499       Unimplemented();
 500 #endif
 501       break;
 502     }
 503     case T_OBJECT:
 504     case T_ARRAY: {
 505       Handle handle = handles.at(k++);
 506       new_vt->obj_field_put(off, handle());
 507       break;
 508     }
 509     case T_FLOAT: {
 510       new_vt->float_field_put(off,  *(jfloat*)loc);
 511       break;
 512     }
 513     case T_DOUBLE: {
 514       new_vt->double_field_put(off, *(jdouble*)loc);
 515       break;
 516     }
 517     default:
 518       ShouldNotReachHere();
 519     }
 520     *(intptr_t*)loc = 0xDEAD;
 521     j++;
 522   }
 523   assert(j == regs->length(), "missed a field?");
 524   assert(k == handles.length(), "missed an oop?");
 525   return new_vt;
 526 }
 527 
 528 // Check the return register for a ValueKlass oop
 529 ValueKlass* ValueKlass::returned_value_klass(const RegisterMap& map) {
 530   BasicType bt = T_METADATA;
 531   VMRegPair pair;
 532   int nb = SharedRuntime::java_return_convention(&bt, &pair, 1);
 533   assert(nb == 1, "broken");
 534 
 535   address loc = map.location(pair.first());
 536   intptr_t ptr = *(intptr_t*)loc;
 537   if (is_set_nth_bit(ptr, 0)) {
 538     // Oop is tagged, must be a ValueKlass oop
 539     clear_nth_bit(ptr, 0);
 540     assert(Metaspace::contains((void*)ptr), "should be klass");
 541     ValueKlass* vk = (ValueKlass*)ptr;
 542     assert(vk->can_be_returned_as_fields(), "must be able to return as fields");
 543     return vk;
 544   }
 545 #ifdef ASSERT
 546   // Oop is not tagged, must be a valid oop
 547   if (VerifyOops) {
 548     oopDesc::verify(oop((HeapWord*)ptr));
 549   }
 550 #endif
 551   return NULL;
 552 }
 553 
 554 void ValueKlass::iterate_over_inside_oops(OopClosure* f, oop value) {
 555   assert(!Universe::heap()->is_in_reserved(value), "This method is used on buffered values");
 556 
 557   oop* addr_mirror = (oop*)(value)->mark_addr_raw();
 558   f->do_oop_no_buffering(addr_mirror);
 559 
 560   if (!contains_oops()) return;
 561 
 562   OopMapBlock* map = start_of_nonstatic_oop_maps();
 563   OopMapBlock* const end_map = map + nonstatic_oop_map_count();
 564 
 565   if (!UseCompressedOops) {
 566     for (; map < end_map; map++) {
 567       oop* p = (oop*) (((char*)(oopDesc*)value) + map->offset());
 568       oop* const end = p + map->count();
 569       for (; p < end; ++p) {
 570         assert(oopDesc::is_oop_or_null(*p), "Sanity check");
 571         f->do_oop(p);
 572       }
 573     }
 574   } else {
 575     for (; map < end_map; map++) {
 576       narrowOop* p = (narrowOop*) (((char*)(oopDesc*)value) + map->offset());
 577       narrowOop* const end = p + map->count();
 578       for (; p < end; ++p) {
 579         oop o = CompressedOops::decode(*p);
 580         assert(Universe::heap()->is_in_reserved_or_null(o), "Sanity check");
 581         assert(oopDesc::is_oop_or_null(o), "Sanity check");
 582         f->do_oop(p);
 583       }
 584     }
 585   }
 586 }
 587 
 588 void ValueKlass::verify_on(outputStream* st) {
 589   InstanceKlass::verify_on(st);
 590   guarantee(prototype_header()->is_always_locked(), "Prototype header is not always locked");
 591 }
 592 
 593 void ValueKlass::oop_verify_on(oop obj, outputStream* st) {
 594   InstanceKlass::oop_verify_on(obj, st);
 595   guarantee(obj->mark()->is_always_locked(), "Header is not always locked");
 596 }