< prev index next >

src/hotspot/share/cds/heapShared.cpp

Print this page

 291     // already archived
 292     return ao;
 293   }
 294 
 295   int len = obj->size();
 296   if (G1CollectedHeap::heap()->is_archive_alloc_too_large(len)) {
 297     log_debug(cds, heap)("Cannot archive, object (" PTR_FORMAT ") is too large: " SIZE_FORMAT,
 298                          p2i(obj), (size_t)obj->size());
 299     return NULL;
 300   }
 301 
 302   oop archived_oop = cast_to_oop(G1CollectedHeap::heap()->archive_mem_allocate(len));
 303   if (archived_oop != NULL) {
 304     Copy::aligned_disjoint_words(cast_from_oop<HeapWord*>(obj), cast_from_oop<HeapWord*>(archived_oop), len);
 305     // Reinitialize markword to remove age/marking/locking/etc.
 306     //
 307     // We need to retain the identity_hash, because it may have been used by some hashtables
 308     // in the shared heap. This also has the side effect of pre-initializing the
 309     // identity_hash for all shared objects, so they are less likely to be written
 310     // into during run time, increasing the potential of memory sharing.
 311     int hash_original = obj->identity_hash();
 312     archived_oop->set_mark(markWord::prototype().copy_set_hash(hash_original));
 313     assert(archived_oop->mark().is_unlocked(), "sanity");

 314 
 315     DEBUG_ONLY(int hash_archived = archived_oop->identity_hash());
 316     assert(hash_original == hash_archived, "Different hash codes: original %x, archived %x", hash_original, hash_archived);

 317 
 318     ArchivedObjectCache* cache = archived_object_cache();
 319     CachedOopInfo info = make_cached_oop_info(archived_oop);
 320     cache->put(obj, info);
 321     if (_original_object_table != NULL) {
 322       _original_object_table->put(archived_oop, obj);
 323     }
 324     mark_native_pointers(obj, archived_oop);
 325     if (log_is_enabled(Debug, cds, heap)) {
 326       ResourceMark rm;
 327       log_debug(cds, heap)("Archived heap object " PTR_FORMAT " ==> " PTR_FORMAT " : %s",
 328                            p2i(obj), p2i(archived_oop), obj->klass()->external_name());
 329     }
 330   } else {
 331     log_error(cds, heap)(
 332       "Cannot allocate space for object " PTR_FORMAT " in archived heap region",
 333       p2i(obj));
 334     log_error(cds)("Out of memory. Please run with a larger Java heap, current MaxHeapSize = "
 335         SIZE_FORMAT "M", MaxHeapSize/M);
 336     os::_exit(-1);

 556   G1CollectedHeap::heap()->end_archive_alloc_range(open_regions,
 557                                                    os::vm_allocation_granularity());
 558 }
 559 
 560 // Copy _pending_archive_roots into an objArray
 561 void HeapShared::copy_roots() {
 562   // HeapShared::roots() points into an ObjArray in the open archive region. A portion of the
 563   // objects in this array are discovered during HeapShared::archive_objects(). For example,
 564   // in HeapShared::archive_reachable_objects_from() ->  HeapShared::check_enum_obj().
 565   // However, HeapShared::archive_objects() happens inside a safepoint, so we can't
 566   // allocate a "regular" ObjArray and pass the result to HeapShared::archive_object().
 567   // Instead, we have to roll our own alloc/copy routine here.
 568   int length = _pending_roots != NULL ? _pending_roots->length() : 0;
 569   size_t size = objArrayOopDesc::object_size(length);
 570   Klass* k = Universe::objectArrayKlassObj(); // already relocated to point to archived klass
 571   HeapWord* mem = G1CollectedHeap::heap()->archive_mem_allocate(size);
 572 
 573   memset(mem, 0, size * BytesPerWord);
 574   {
 575     // This is copied from MemAllocator::finish
 576     oopDesc::set_mark(mem, markWord::prototype());
 577     oopDesc::release_set_klass(mem, k);
 578   }
 579   {
 580     // This is copied from ObjArrayAllocator::initialize
 581     arrayOopDesc::set_length(mem, length);
 582   }
 583 
 584   _roots = OopHandle(Universe::vm_global(), cast_to_oop(mem));
 585   for (int i = 0; i < length; i++) {
 586     roots()->obj_at_put(i, _pending_roots->at(i));
 587   }
 588   log_info(cds)("archived obj roots[%d] = " SIZE_FORMAT " words, klass = %p, obj = %p", length, size, k, mem);
 589 }
 590 
 591 //
 592 // Subgraph archiving support
 593 //
 594 HeapShared::DumpTimeKlassSubGraphInfoTable* HeapShared::_dump_time_subgraph_info_table = NULL;
 595 HeapShared::RunTimeKlassSubGraphInfoTable   HeapShared::_run_time_subgraph_info_table;
 596 

 291     // already archived
 292     return ao;
 293   }
 294 
 295   int len = obj->size();
 296   if (G1CollectedHeap::heap()->is_archive_alloc_too_large(len)) {
 297     log_debug(cds, heap)("Cannot archive, object (" PTR_FORMAT ") is too large: " SIZE_FORMAT,
 298                          p2i(obj), (size_t)obj->size());
 299     return NULL;
 300   }
 301 
 302   oop archived_oop = cast_to_oop(G1CollectedHeap::heap()->archive_mem_allocate(len));
 303   if (archived_oop != NULL) {
 304     Copy::aligned_disjoint_words(cast_from_oop<HeapWord*>(obj), cast_from_oop<HeapWord*>(archived_oop), len);
 305     // Reinitialize markword to remove age/marking/locking/etc.
 306     //
 307     // We need to retain the identity_hash, because it may have been used by some hashtables
 308     // in the shared heap. This also has the side effect of pre-initializing the
 309     // identity_hash for all shared objects, so they are less likely to be written
 310     // into during run time, increasing the potential of memory sharing.
 311     if (!(EnableValhalla && obj->mark().is_inline_type())) {
 312       int hash_original = obj->identity_hash();
 313       archived_oop->set_mark(archived_oop->klass()->prototype_header().copy_set_hash(hash_original));
 314       assert(archived_oop->mark().is_unlocked(), "sanity");
 315 
 316       DEBUG_ONLY(int hash_archived = archived_oop->identity_hash());
 317       assert(hash_original == hash_archived, "Different hash codes: original %x, archived %x", hash_original, hash_archived);
 318     }
 319 
 320     ArchivedObjectCache* cache = archived_object_cache();
 321     CachedOopInfo info = make_cached_oop_info(archived_oop);
 322     cache->put(obj, info);
 323     if (_original_object_table != NULL) {
 324       _original_object_table->put(archived_oop, obj);
 325     }
 326     mark_native_pointers(obj, archived_oop);
 327     if (log_is_enabled(Debug, cds, heap)) {
 328       ResourceMark rm;
 329       log_debug(cds, heap)("Archived heap object " PTR_FORMAT " ==> " PTR_FORMAT " : %s",
 330                            p2i(obj), p2i(archived_oop), obj->klass()->external_name());
 331     }
 332   } else {
 333     log_error(cds, heap)(
 334       "Cannot allocate space for object " PTR_FORMAT " in archived heap region",
 335       p2i(obj));
 336     log_error(cds)("Out of memory. Please run with a larger Java heap, current MaxHeapSize = "
 337         SIZE_FORMAT "M", MaxHeapSize/M);
 338     os::_exit(-1);

 558   G1CollectedHeap::heap()->end_archive_alloc_range(open_regions,
 559                                                    os::vm_allocation_granularity());
 560 }
 561 
 562 // Copy _pending_archive_roots into an objArray
 563 void HeapShared::copy_roots() {
 564   // HeapShared::roots() points into an ObjArray in the open archive region. A portion of the
 565   // objects in this array are discovered during HeapShared::archive_objects(). For example,
 566   // in HeapShared::archive_reachable_objects_from() ->  HeapShared::check_enum_obj().
 567   // However, HeapShared::archive_objects() happens inside a safepoint, so we can't
 568   // allocate a "regular" ObjArray and pass the result to HeapShared::archive_object().
 569   // Instead, we have to roll our own alloc/copy routine here.
 570   int length = _pending_roots != NULL ? _pending_roots->length() : 0;
 571   size_t size = objArrayOopDesc::object_size(length);
 572   Klass* k = Universe::objectArrayKlassObj(); // already relocated to point to archived klass
 573   HeapWord* mem = G1CollectedHeap::heap()->archive_mem_allocate(size);
 574 
 575   memset(mem, 0, size * BytesPerWord);
 576   {
 577     // This is copied from MemAllocator::finish
 578     oopDesc::set_mark(mem, k->prototype_header());
 579     oopDesc::release_set_klass(mem, k);
 580   }
 581   {
 582     // This is copied from ObjArrayAllocator::initialize
 583     arrayOopDesc::set_length(mem, length);
 584   }
 585 
 586   _roots = OopHandle(Universe::vm_global(), cast_to_oop(mem));
 587   for (int i = 0; i < length; i++) {
 588     roots()->obj_at_put(i, _pending_roots->at(i));
 589   }
 590   log_info(cds)("archived obj roots[%d] = " SIZE_FORMAT " words, klass = %p, obj = %p", length, size, k, mem);
 591 }
 592 
 593 //
 594 // Subgraph archiving support
 595 //
 596 HeapShared::DumpTimeKlassSubGraphInfoTable* HeapShared::_dump_time_subgraph_info_table = NULL;
 597 HeapShared::RunTimeKlassSubGraphInfoTable   HeapShared::_run_time_subgraph_info_table;
 598 
< prev index next >