< prev index next >

src/hotspot/share/cds/archiveUtils.cpp

Print this page

 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 "cds/aotCompressedPointers.hpp"
 26 #include "cds/aotLogging.hpp"
 27 #include "cds/aotMetaspace.hpp"
 28 #include "cds/archiveBuilder.hpp"
 29 #include "cds/archiveUtils.hpp"
 30 #include "cds/cdsConfig.hpp"
 31 #include "cds/classListParser.hpp"
 32 #include "cds/classListWriter.hpp"
 33 #include "cds/dynamicArchive.hpp"
 34 #include "cds/filemap.hpp"
 35 #include "cds/heapShared.hpp"
 36 #include "cds/lambdaProxyClassDictionary.hpp"

 37 #include "classfile/systemDictionaryShared.hpp"
 38 #include "classfile/vmClasses.hpp"
 39 #include "interpreter/bootstrapInfo.hpp"
 40 #include "memory/metaspaceUtils.hpp"
 41 #include "memory/resourceArea.hpp"
 42 #include "oops/compressedOops.inline.hpp"
 43 #include "oops/klass.inline.hpp"
 44 #include "runtime/arguments.hpp"
 45 #include "utilities/bitMap.inline.hpp"
 46 #include "utilities/debug.hpp"
 47 #include "utilities/formatBuffer.hpp"
 48 #include "utilities/globalDefinitions.hpp"
 49 #include "utilities/spinYield.hpp"
 50 
 51 CHeapBitMap* ArchivePtrMarker::_ptrmap = nullptr;
 52 CHeapBitMap* ArchivePtrMarker::_rw_ptrmap = nullptr;
 53 CHeapBitMap* ArchivePtrMarker::_ro_ptrmap = nullptr;

 54 VirtualSpace* ArchivePtrMarker::_vs;
 55 
 56 bool ArchivePtrMarker::_compacted;
 57 
 58 void ArchivePtrMarker::initialize(CHeapBitMap* ptrmap, VirtualSpace* vs) {
 59   assert(_ptrmap == nullptr, "initialize only once");
 60   assert(_rw_ptrmap == nullptr, "initialize only once");
 61   assert(_ro_ptrmap == nullptr, "initialize only once");

 62   _vs = vs;
 63   _compacted = false;
 64   _ptrmap = ptrmap;
 65 
 66   // Use this as initial guesstimate. We should need less space in the
 67   // archive, but if we're wrong the bitmap will be expanded automatically.
 68   size_t estimated_archive_size = MetaspaceGC::capacity_until_GC();
 69   // But set it smaller in debug builds so we always test the expansion code.
 70   // (Default archive is about 12MB).
 71   DEBUG_ONLY(estimated_archive_size = 6 * M);
 72 
 73   // We need one bit per pointer in the archive.
 74   _ptrmap->initialize(estimated_archive_size / sizeof(intptr_t));
 75 }
 76 
 77 void ArchivePtrMarker::initialize_rw_ro_maps(CHeapBitMap* rw_ptrmap, CHeapBitMap* ro_ptrmap) {
 78   address* buff_bottom = (address*)ArchiveBuilder::current()->buffer_bottom();
 79   address* rw_bottom   = (address*)ArchiveBuilder::current()->rw_region()->base();
 80   address* ro_bottom   = (address*)ArchiveBuilder::current()->ro_region()->base();

 81 
 82   // The bit in _ptrmap that cover the very first word in the rw/ro regions.
 83   size_t rw_start = rw_bottom - buff_bottom;
 84   size_t ro_start = ro_bottom - buff_bottom;

 85 
 86   // The number of bits used by the rw/ro ptrmaps. We might have lots of zero
 87   // bits at the bottom and top of rw/ro ptrmaps, but these zeros will be
 88   // removed by FileMapInfo::write_bitmap_region().
 89   size_t rw_size = ArchiveBuilder::current()->rw_region()->used() / sizeof(address);
 90   size_t ro_size = ArchiveBuilder::current()->ro_region()->used() / sizeof(address);

 91 
 92   // The last (exclusive) bit in _ptrmap that covers the rw/ro regions.
 93   // Note: _ptrmap is dynamically expanded only when an actual pointer is written, so
 94   // it may not be as large as we want.
 95   size_t rw_end = MIN2<size_t>(rw_start + rw_size, _ptrmap->size());
 96   size_t ro_end = MIN2<size_t>(ro_start + ro_size, _ptrmap->size());

 97 
 98   rw_ptrmap->initialize(rw_size);
 99   ro_ptrmap->initialize(ro_size);

100 
101   for (size_t rw_bit = rw_start; rw_bit < rw_end; rw_bit++) {
102     rw_ptrmap->at_put(rw_bit - rw_start, _ptrmap->at(rw_bit));
103   }
104 
105   for(size_t ro_bit = ro_start; ro_bit < ro_end; ro_bit++) {
106     ro_ptrmap->at_put(ro_bit - ro_start, _ptrmap->at(ro_bit));
107   }
108 




109   _rw_ptrmap = rw_ptrmap;
110   _ro_ptrmap = ro_ptrmap;

111 }
112 
113 void ArchivePtrMarker::mark_pointer(address* ptr_loc) {
114   assert(_ptrmap != nullptr, "not initialized");
115   assert(!_compacted, "cannot mark anymore");
116 
117   if (ptr_base() <= ptr_loc && ptr_loc < ptr_end()) {
118     address value = *ptr_loc;
119     // We don't want any pointer that points to very bottom of the archive, otherwise when
120     // AOTMetaspace::default_base_address()==0, we can't distinguish between a pointer
121     // to nothing (null) vs a pointer to an objects that happens to be at the very bottom
122     // of the archive.
123     assert(value != (address)ptr_base(), "don't point to the bottom of the archive");
124 
125     if (value != nullptr) {
126       assert(uintx(ptr_loc) % sizeof(intptr_t) == 0, "pointers must be stored in aligned addresses");
127       size_t idx = ptr_loc - ptr_base();
128       if (_ptrmap->size() <= idx) {
129         _ptrmap->resize((idx + 1) * 2);
130       }

284     aot_log_error(aot)(" required = %d", int(needed_bytes));
285   }
286 }
287 
288 void DumpRegion::init(ReservedSpace* rs, VirtualSpace* vs) {
289   _rs = rs;
290   _vs = vs;
291   // Start with 0 committed bytes. The memory will be committed as needed.
292   if (!_vs->initialize(*_rs, 0)) {
293     fatal("Unable to allocate memory for shared space");
294   }
295   _base = _top = _rs->base();
296   _end = _rs->end();
297 }
298 
299 void DumpRegion::pack(DumpRegion* next) {
300   if (!is_packed()) {
301     _end = (char*)align_up(_top, AOTMetaspace::core_region_alignment());
302     _is_packed = true;
303   }
304   _end = (char*)align_up(_top, AOTMetaspace::core_region_alignment());
305   _is_packed = true;
306   if (next != nullptr) {
307     next->_rs = _rs;
308     next->_vs = _vs;
309     next->_base = next->_top = this->_end;
310     next->_end = _rs->end();
311   }
312 }
313 
314 void WriteClosure::do_ptr(void** p) {
315   address ptr = *(address*)p;
316   AOTCompressedPointers::narrowPtr narrowp = AOTCompressedPointers::encode(ptr);
317   _dump_region->append_intptr_t(checked_cast<intptr_t>(narrowp), false);
318 }
319 
320 void ReadClosure::do_ptr(void** p) {
321   assert(*p == nullptr, "initializing previous initialized pointer.");
322   u4 narrowp = checked_cast<u4>(nextPtr());
323   *p = AOTCompressedPointers::decode<void*>(cast_from_u4(narrowp), _base_address);
324 }
325 

351     if (LambdaProxyClassDictionary::is_supported_invokedynamic(bootstrap_specifier)) {
352       const constantPoolHandle& pool = bootstrap_specifier->pool();
353       if (SystemDictionaryShared::is_builtin_loader(pool->pool_holder()->class_loader_data())) {
354         // Currently lambda proxy classes are supported only for the built-in loaders.
355         ResourceMark rm(THREAD);
356         int pool_index = bootstrap_specifier->bss_index();
357         ClassListWriter w;
358         w.stream()->print("%s %s", ClassListParser::lambda_proxy_tag(), pool->pool_holder()->name()->as_C_string());
359         CDSIndyInfo cii;
360         ClassListParser::populate_cds_indy_info(pool, pool_index, &cii, CHECK);
361         GrowableArray<const char*>* indy_items = cii.items();
362         for (int i = 0; i < indy_items->length(); i++) {
363           w.stream()->print(" %s", indy_items->at(i));
364         }
365         w.stream()->cr();
366       }
367     }
368   }
369 }
370 


















































371 bool ArchiveUtils::has_aot_initialized_mirror(InstanceKlass* src_ik) {
372   if (!ArchiveBuilder::current()->has_been_archived(src_ik)) {
373     return false;
374   }
375   return ArchiveBuilder::current()->get_buffered_addr(src_ik)->has_aot_initialized_mirror();
376 }
377 
378 size_t HeapRootSegments::size_in_bytes(size_t seg_idx) {
379   assert(seg_idx < _count, "In range");
380   return objArrayOopDesc::object_size(size_in_elems(seg_idx)) * HeapWordSize;
381 }
382 
383 int HeapRootSegments::size_in_elems(size_t seg_idx) {
384   assert(seg_idx < _count, "In range");
385   if (seg_idx != _count - 1) {
386     return _max_size_in_elems;
387   } else {
388     // Last slice, leftover
389     return _roots_count % _max_size_in_elems;
390   }

 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 "cds/aotCompressedPointers.hpp"
 26 #include "cds/aotLogging.hpp"
 27 #include "cds/aotMetaspace.hpp"
 28 #include "cds/archiveBuilder.hpp"
 29 #include "cds/archiveUtils.hpp"
 30 #include "cds/cdsConfig.hpp"
 31 #include "cds/classListParser.hpp"
 32 #include "cds/classListWriter.hpp"
 33 #include "cds/dynamicArchive.hpp"
 34 #include "cds/filemap.hpp"
 35 #include "cds/heapShared.hpp"
 36 #include "cds/lambdaProxyClassDictionary.hpp"
 37 #include "classfile/classLoader.hpp"
 38 #include "classfile/systemDictionaryShared.hpp"
 39 #include "classfile/vmClasses.hpp"
 40 #include "interpreter/bootstrapInfo.hpp"
 41 #include "memory/metaspaceUtils.hpp"
 42 #include "memory/resourceArea.hpp"
 43 #include "oops/compressedOops.inline.hpp"
 44 #include "oops/klass.inline.hpp"
 45 #include "runtime/arguments.hpp"
 46 #include "utilities/bitMap.inline.hpp"
 47 #include "utilities/debug.hpp"
 48 #include "utilities/formatBuffer.hpp"
 49 #include "utilities/globalDefinitions.hpp"
 50 #include "utilities/spinYield.hpp"
 51 
 52 CHeapBitMap* ArchivePtrMarker::_ptrmap = nullptr;
 53 CHeapBitMap* ArchivePtrMarker::_rw_ptrmap = nullptr;
 54 CHeapBitMap* ArchivePtrMarker::_ro_ptrmap = nullptr;
 55 CHeapBitMap* ArchivePtrMarker::_ac_ptrmap = nullptr;
 56 VirtualSpace* ArchivePtrMarker::_vs;
 57 
 58 bool ArchivePtrMarker::_compacted;
 59 
 60 void ArchivePtrMarker::initialize(CHeapBitMap* ptrmap, VirtualSpace* vs) {
 61   assert(_ptrmap == nullptr, "initialize only once");
 62   assert(_rw_ptrmap == nullptr, "initialize only once");
 63   assert(_ro_ptrmap == nullptr, "initialize only once");
 64   assert(_ac_ptrmap == nullptr, "initialize only once");
 65   _vs = vs;
 66   _compacted = false;
 67   _ptrmap = ptrmap;
 68 
 69   // Use this as initial guesstimate. We should need less space in the
 70   // archive, but if we're wrong the bitmap will be expanded automatically.
 71   size_t estimated_archive_size = MetaspaceGC::capacity_until_GC();
 72   // But set it smaller in debug builds so we always test the expansion code.
 73   // (Default archive is about 12MB).
 74   DEBUG_ONLY(estimated_archive_size = 6 * M);
 75 
 76   // We need one bit per pointer in the archive.
 77   _ptrmap->initialize(estimated_archive_size / sizeof(intptr_t));
 78 }
 79 
 80 void ArchivePtrMarker::initialize_rw_ro_ac_maps(CHeapBitMap* rw_ptrmap, CHeapBitMap* ro_ptrmap, CHeapBitMap* ac_ptrmap) {
 81   address* buff_bottom = (address*)ArchiveBuilder::current()->buffer_bottom();
 82   address* rw_bottom   = (address*)ArchiveBuilder::current()->rw_region()->base();
 83   address* ro_bottom   = (address*)ArchiveBuilder::current()->ro_region()->base();
 84   address* ac_bottom   = (address*)ArchiveBuilder::current()->ac_region()->base();
 85 
 86   // The bit in _ptrmap that cover the very first word in the rw/ro/ac regions.
 87   size_t rw_start = rw_bottom - buff_bottom;
 88   size_t ro_start = ro_bottom - buff_bottom;
 89   size_t ac_start = ac_bottom - buff_bottom;
 90 
 91   // The number of bits used by the rw/ro ptrmaps. We might have lots of zero
 92   // bits at the bottom and top of rw/ro ptrmaps, but these zeros will be
 93   // removed by FileMapInfo::write_bitmap_region().
 94   size_t rw_size = ArchiveBuilder::current()->rw_region()->used() / sizeof(address);
 95   size_t ro_size = ArchiveBuilder::current()->ro_region()->used() / sizeof(address);
 96   size_t ac_size = ArchiveBuilder::current()->ac_region()->used() / sizeof(address);
 97 
 98   // The last (exclusive) bit in _ptrmap that covers the rw/ro regions.
 99   // Note: _ptrmap is dynamically expanded only when an actual pointer is written, so
100   // it may not be as large as we want.
101   size_t rw_end = MIN2<size_t>(rw_start + rw_size, _ptrmap->size());
102   size_t ro_end = MIN2<size_t>(ro_start + ro_size, _ptrmap->size());
103   size_t ac_end = MIN2<size_t>(ac_start + ac_size, _ptrmap->size());
104 
105   rw_ptrmap->initialize(rw_size);
106   ro_ptrmap->initialize(ro_size);
107   ac_ptrmap->initialize(ac_size);
108 
109   for (size_t rw_bit = rw_start; rw_bit < rw_end; rw_bit++) {
110     rw_ptrmap->at_put(rw_bit - rw_start, _ptrmap->at(rw_bit));
111   }
112 
113   for(size_t ro_bit = ro_start; ro_bit < ro_end; ro_bit++) {
114     ro_ptrmap->at_put(ro_bit - ro_start, _ptrmap->at(ro_bit));
115   }
116 
117   for (size_t ac_bit = ac_start; ac_bit < ac_end; ac_bit++) {
118     ac_ptrmap->at_put(ac_bit - ac_start, _ptrmap->at(ac_bit));
119   }
120 
121   _rw_ptrmap = rw_ptrmap;
122   _ro_ptrmap = ro_ptrmap;
123   _ac_ptrmap = ac_ptrmap;
124 }
125 
126 void ArchivePtrMarker::mark_pointer(address* ptr_loc) {
127   assert(_ptrmap != nullptr, "not initialized");
128   assert(!_compacted, "cannot mark anymore");
129 
130   if (ptr_base() <= ptr_loc && ptr_loc < ptr_end()) {
131     address value = *ptr_loc;
132     // We don't want any pointer that points to very bottom of the archive, otherwise when
133     // AOTMetaspace::default_base_address()==0, we can't distinguish between a pointer
134     // to nothing (null) vs a pointer to an objects that happens to be at the very bottom
135     // of the archive.
136     assert(value != (address)ptr_base(), "don't point to the bottom of the archive");
137 
138     if (value != nullptr) {
139       assert(uintx(ptr_loc) % sizeof(intptr_t) == 0, "pointers must be stored in aligned addresses");
140       size_t idx = ptr_loc - ptr_base();
141       if (_ptrmap->size() <= idx) {
142         _ptrmap->resize((idx + 1) * 2);
143       }

297     aot_log_error(aot)(" required = %d", int(needed_bytes));
298   }
299 }
300 
301 void DumpRegion::init(ReservedSpace* rs, VirtualSpace* vs) {
302   _rs = rs;
303   _vs = vs;
304   // Start with 0 committed bytes. The memory will be committed as needed.
305   if (!_vs->initialize(*_rs, 0)) {
306     fatal("Unable to allocate memory for shared space");
307   }
308   _base = _top = _rs->base();
309   _end = _rs->end();
310 }
311 
312 void DumpRegion::pack(DumpRegion* next) {
313   if (!is_packed()) {
314     _end = (char*)align_up(_top, AOTMetaspace::core_region_alignment());
315     _is_packed = true;
316   }


317   if (next != nullptr) {
318     next->_rs = _rs;
319     next->_vs = _vs;
320     next->_base = next->_top = this->_end;
321     next->_end = _rs->end();
322   }
323 }
324 
325 void WriteClosure::do_ptr(void** p) {
326   address ptr = *(address*)p;
327   AOTCompressedPointers::narrowPtr narrowp = AOTCompressedPointers::encode(ptr);
328   _dump_region->append_intptr_t(checked_cast<intptr_t>(narrowp), false);
329 }
330 
331 void ReadClosure::do_ptr(void** p) {
332   assert(*p == nullptr, "initializing previous initialized pointer.");
333   u4 narrowp = checked_cast<u4>(nextPtr());
334   *p = AOTCompressedPointers::decode<void*>(cast_from_u4(narrowp), _base_address);
335 }
336 

362     if (LambdaProxyClassDictionary::is_supported_invokedynamic(bootstrap_specifier)) {
363       const constantPoolHandle& pool = bootstrap_specifier->pool();
364       if (SystemDictionaryShared::is_builtin_loader(pool->pool_holder()->class_loader_data())) {
365         // Currently lambda proxy classes are supported only for the built-in loaders.
366         ResourceMark rm(THREAD);
367         int pool_index = bootstrap_specifier->bss_index();
368         ClassListWriter w;
369         w.stream()->print("%s %s", ClassListParser::lambda_proxy_tag(), pool->pool_holder()->name()->as_C_string());
370         CDSIndyInfo cii;
371         ClassListParser::populate_cds_indy_info(pool, pool_index, &cii, CHECK);
372         GrowableArray<const char*>* indy_items = cii.items();
373         for (int i = 0; i < indy_items->length(); i++) {
374           w.stream()->print(" %s", indy_items->at(i));
375         }
376         w.stream()->cr();
377       }
378     }
379   }
380 }
381 
382 
383 // "boot", "platform", "app" or nullptr
384 const char* ArchiveUtils::builtin_loader_name_or_null(oop loader) {
385   if (loader == nullptr) {
386     return "boot";
387   } else if (loader == SystemDictionary::java_platform_loader()) {
388     return "platform";
389   } else if (loader == SystemDictionary::java_system_loader()) {
390     return "app";
391   } else {
392     return nullptr;
393   }
394 }
395 
396 // "boot", "platform", "app". Asserts if not a built-in-loader
397 const char* ArchiveUtils::builtin_loader_name(oop loader) {
398   const char* name = builtin_loader_name_or_null(loader);
399   assert(name != nullptr, "must be a built-in loader");
400   return name;
401 }
402 
403 bool ArchiveUtils::builtin_loader_from_type(const char* loader_type, oop* value_ret) {
404   if (strcmp(loader_type, "boot") == 0) {
405     *value_ret = nullptr;
406     return true;
407   } else if (strcmp(loader_type, "platform") == 0) {
408     *value_ret = SystemDictionary::java_platform_loader();
409     return true;
410   } else if (strcmp(loader_type, "app") == 0) {
411     *value_ret = SystemDictionary::java_system_loader();
412     return true;
413   } else {
414     DEBUG_ONLY(*value_ret = cast_to_oop((void*)badOopVal));
415     return false;
416   }
417 }
418 
419 oop ArchiveUtils::builtin_loader_from_type(int loader_type) {
420   if (loader_type == ClassLoader::BOOT_LOADER) {
421     return nullptr;
422   } else if (loader_type == ClassLoader::PLATFORM_LOADER)  {
423     return SystemDictionary::java_platform_loader();
424   } else if (loader_type == ClassLoader::APP_LOADER) {
425     return SystemDictionary::java_system_loader();
426   } else {
427     ShouldNotReachHere();
428     return nullptr;
429   }
430 }
431 
432 bool ArchiveUtils::has_aot_initialized_mirror(InstanceKlass* src_ik) {
433   if (!ArchiveBuilder::current()->has_been_archived(src_ik)) {
434     return false;
435   }
436   return ArchiveBuilder::current()->get_buffered_addr(src_ik)->has_aot_initialized_mirror();
437 }
438 
439 size_t HeapRootSegments::size_in_bytes(size_t seg_idx) {
440   assert(seg_idx < _count, "In range");
441   return objArrayOopDesc::object_size(size_in_elems(seg_idx)) * HeapWordSize;
442 }
443 
444 int HeapRootSegments::size_in_elems(size_t seg_idx) {
445   assert(seg_idx < _count, "In range");
446   if (seg_idx != _count - 1) {
447     return _max_size_in_elems;
448   } else {
449     // Last slice, leftover
450     return _roots_count % _max_size_in_elems;
451   }
< prev index next >