< prev index next >

src/hotspot/share/cds/archiveUtils.cpp

Print this page

 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 "cds/archiveBuilder.hpp"
 27 #include "cds/archiveHeapLoader.inline.hpp"
 28 #include "cds/archiveUtils.hpp"
 29 #include "cds/cdsConfig.hpp"
 30 #include "cds/classListParser.hpp"
 31 #include "cds/classListWriter.hpp"
 32 #include "cds/dynamicArchive.hpp"
 33 #include "cds/filemap.hpp"
 34 #include "cds/heapShared.hpp"
 35 #include "cds/metaspaceShared.hpp"

 36 #include "classfile/systemDictionaryShared.hpp"
 37 #include "classfile/vmClasses.hpp"
 38 #include "interpreter/bootstrapInfo.hpp"
 39 #include "memory/metaspaceUtils.hpp"
 40 #include "memory/resourceArea.hpp"
 41 #include "oops/compressedOops.inline.hpp"

 42 #include "runtime/arguments.hpp"
 43 #include "utilities/bitMap.inline.hpp"
 44 #include "utilities/debug.hpp"
 45 #include "utilities/formatBuffer.hpp"
 46 #include "utilities/globalDefinitions.hpp"
 47 
 48 CHeapBitMap* ArchivePtrMarker::_ptrmap = nullptr;
 49 VirtualSpace* ArchivePtrMarker::_vs;
 50 
 51 bool ArchivePtrMarker::_compacted;
 52 
 53 void ArchivePtrMarker::initialize(CHeapBitMap* ptrmap, VirtualSpace* vs) {
 54   assert(_ptrmap == nullptr, "initialize only once");
 55   _vs = vs;
 56   _compacted = false;
 57   _ptrmap = ptrmap;
 58 
 59   // Use this as initial guesstimate. We should need less space in the
 60   // archive, but if we're wrong the bitmap will be expanded automatically.
 61   size_t estimated_archive_size = MetaspaceGC::capacity_until_GC();

210 char* DumpRegion::allocate(size_t num_bytes) {
211   char* p = (char*)align_up(_top, (size_t)SharedSpaceObjectAlignment);
212   char* newtop = p + align_up(num_bytes, (size_t)SharedSpaceObjectAlignment);
213   expand_top_to(newtop);
214   memset(p, 0, newtop - p);
215   return p;
216 }
217 
218 void DumpRegion::append_intptr_t(intptr_t n, bool need_to_mark) {
219   assert(is_aligned(_top, sizeof(intptr_t)), "bad alignment");
220   intptr_t *p = (intptr_t*)_top;
221   char* newtop = _top + sizeof(intptr_t);
222   expand_top_to(newtop);
223   *p = n;
224   if (need_to_mark) {
225     ArchivePtrMarker::mark_pointer(p);
226   }
227 }
228 
229 void DumpRegion::print(size_t total_bytes) const {

230   log_debug(cds)("%s space: " SIZE_FORMAT_W(9) " [ %4.1f%% of total] out of " SIZE_FORMAT_W(9) " bytes [%5.1f%% used] at " INTPTR_FORMAT,
231                  _name, used(), percent_of(used(), total_bytes), reserved(), percent_of(used(), reserved()),
232                  p2i(ArchiveBuilder::current()->to_requested(_base)));
233 }
234 
235 void DumpRegion::print_out_of_space_msg(const char* failing_region, size_t needed_bytes) {
236   log_error(cds)("[%-8s] " PTR_FORMAT " - " PTR_FORMAT " capacity =%9d, allocated =%9d",
237                  _name, p2i(_base), p2i(_top), int(_end - _base), int(_top - _base));
238   if (strcmp(_name, failing_region) == 0) {
239     log_error(cds)(" required = %d", int(needed_bytes));
240   }
241 }
242 
243 void DumpRegion::init(ReservedSpace* rs, VirtualSpace* vs) {
244   _rs = rs;
245   _vs = vs;
246   // Start with 0 committed bytes. The memory will be committed as needed.
247   if (!_vs->initialize(*_rs, 0)) {
248     fatal("Unable to allocate memory for shared space");
249   }
250   _base = _top = _rs->base();
251   _end = _rs->end();
252 }
253 
254 void DumpRegion::pack(DumpRegion* next) {
255   assert(!is_packed(), "sanity");
256   _end = (char*)align_up(_top, MetaspaceShared::core_region_alignment());
257   _is_packed = true;

258   if (next != nullptr) {
259     next->_rs = _rs;
260     next->_vs = _vs;
261     next->_base = next->_top = this->_end;
262     next->_end = _rs->end();
263   }
264 }
265 
266 void WriteClosure::do_ptr(void** p) {
267   // Write ptr into the archive; ptr can be:
268   //   (a) null                 -> written as 0
269   //   (b) a "buffered" address -> written as is
270   //   (c) a "source"   address -> convert to "buffered" and write
271   // The common case is (c). E.g., when writing the vmClasses into the archive.
272   // We have (b) only when we don't have a corresponding source object. E.g.,
273   // the archived c++ vtable entries.
274   address ptr = *(address*)p;
275   if (ptr != nullptr && !ArchiveBuilder::current()->is_in_buffer_space(ptr)) {
276     ptr = ArchiveBuilder::current()->get_buffered_addr(ptr);
277   }

323 void ReadClosure::do_region(u_char* start, size_t size) {
324   assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment");
325   assert(size % sizeof(intptr_t) == 0, "bad size");
326   do_tag((int)size);
327   while (size > 0) {
328     *(intptr_t*)start = nextPtr();
329     start += sizeof(intptr_t);
330     size -= sizeof(intptr_t);
331   }
332 }
333 
334 void ArchiveUtils::log_to_classlist(BootstrapInfo* bootstrap_specifier, TRAPS) {
335   if (ClassListWriter::is_enabled()) {
336     if (SystemDictionaryShared::is_supported_invokedynamic(bootstrap_specifier)) {
337       const constantPoolHandle& pool = bootstrap_specifier->pool();
338       if (SystemDictionaryShared::is_builtin_loader(pool->pool_holder()->class_loader_data())) {
339         // Currently lambda proxy classes are supported only for the built-in loaders.
340         ResourceMark rm(THREAD);
341         int pool_index = bootstrap_specifier->bss_index();
342         ClassListWriter w;
343         w.stream()->print("%s %s", LAMBDA_PROXY_TAG, pool->pool_holder()->name()->as_C_string());
344         CDSIndyInfo cii;
345         ClassListParser::populate_cds_indy_info(pool, pool_index, &cii, CHECK);
346         GrowableArray<const char*>* indy_items = cii.items();
347         for (int i = 0; i < indy_items->length(); i++) {
348           w.stream()->print(" %s", indy_items->at(i));
349         }
350         w.stream()->cr();
351       }
352     }
353   }
354 }












































































 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 "cds/archiveBuilder.hpp"
 27 #include "cds/archiveHeapLoader.inline.hpp"
 28 #include "cds/archiveUtils.hpp"
 29 #include "cds/cdsConfig.hpp"
 30 #include "cds/classListParser.hpp"
 31 #include "cds/classListWriter.hpp"
 32 #include "cds/dynamicArchive.hpp"
 33 #include "cds/filemap.hpp"
 34 #include "cds/heapShared.hpp"
 35 #include "cds/metaspaceShared.hpp"
 36 #include "classfile/classLoader.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 
 50 CHeapBitMap* ArchivePtrMarker::_ptrmap = nullptr;
 51 VirtualSpace* ArchivePtrMarker::_vs;
 52 
 53 bool ArchivePtrMarker::_compacted;
 54 
 55 void ArchivePtrMarker::initialize(CHeapBitMap* ptrmap, VirtualSpace* vs) {
 56   assert(_ptrmap == nullptr, "initialize only once");
 57   _vs = vs;
 58   _compacted = false;
 59   _ptrmap = ptrmap;
 60 
 61   // Use this as initial guesstimate. We should need less space in the
 62   // archive, but if we're wrong the bitmap will be expanded automatically.
 63   size_t estimated_archive_size = MetaspaceGC::capacity_until_GC();

212 char* DumpRegion::allocate(size_t num_bytes) {
213   char* p = (char*)align_up(_top, (size_t)SharedSpaceObjectAlignment);
214   char* newtop = p + align_up(num_bytes, (size_t)SharedSpaceObjectAlignment);
215   expand_top_to(newtop);
216   memset(p, 0, newtop - p);
217   return p;
218 }
219 
220 void DumpRegion::append_intptr_t(intptr_t n, bool need_to_mark) {
221   assert(is_aligned(_top, sizeof(intptr_t)), "bad alignment");
222   intptr_t *p = (intptr_t*)_top;
223   char* newtop = _top + sizeof(intptr_t);
224   expand_top_to(newtop);
225   *p = n;
226   if (need_to_mark) {
227     ArchivePtrMarker::mark_pointer(p);
228   }
229 }
230 
231 void DumpRegion::print(size_t total_bytes) const {
232   char* base = used() > 0 ? ArchiveBuilder::current()->to_requested(_base) : nullptr;
233   log_debug(cds)("%s space: " SIZE_FORMAT_W(9) " [ %4.1f%% of total] out of " SIZE_FORMAT_W(9) " bytes [%5.1f%% used] at " INTPTR_FORMAT,
234                  _name, used(), percent_of(used(), total_bytes), reserved(), percent_of(used(), reserved()),
235                  p2i(base));
236 }
237 
238 void DumpRegion::print_out_of_space_msg(const char* failing_region, size_t needed_bytes) {
239   log_error(cds)("[%-8s] " PTR_FORMAT " - " PTR_FORMAT " capacity =%9d, allocated =%9d",
240                  _name, p2i(_base), p2i(_top), int(_end - _base), int(_top - _base));
241   if (strcmp(_name, failing_region) == 0) {
242     log_error(cds)(" required = %d", int(needed_bytes));
243   }
244 }
245 
246 void DumpRegion::init(ReservedSpace* rs, VirtualSpace* vs) {
247   _rs = rs;
248   _vs = vs;
249   // Start with 0 committed bytes. The memory will be committed as needed.
250   if (!_vs->initialize(*_rs, 0)) {
251     fatal("Unable to allocate memory for shared space");
252   }
253   _base = _top = _rs->base();
254   _end = _rs->end();
255 }
256 
257 void DumpRegion::pack(DumpRegion* next) {
258   if (!is_packed()) {
259     _end = (char*)align_up(_top, MetaspaceShared::core_region_alignment());
260     _is_packed = true;
261   }
262   if (next != nullptr) {
263     next->_rs = _rs;
264     next->_vs = _vs;
265     next->_base = next->_top = this->_end;
266     next->_end = _rs->end();
267   }
268 }
269 
270 void WriteClosure::do_ptr(void** p) {
271   // Write ptr into the archive; ptr can be:
272   //   (a) null                 -> written as 0
273   //   (b) a "buffered" address -> written as is
274   //   (c) a "source"   address -> convert to "buffered" and write
275   // The common case is (c). E.g., when writing the vmClasses into the archive.
276   // We have (b) only when we don't have a corresponding source object. E.g.,
277   // the archived c++ vtable entries.
278   address ptr = *(address*)p;
279   if (ptr != nullptr && !ArchiveBuilder::current()->is_in_buffer_space(ptr)) {
280     ptr = ArchiveBuilder::current()->get_buffered_addr(ptr);
281   }

327 void ReadClosure::do_region(u_char* start, size_t size) {
328   assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment");
329   assert(size % sizeof(intptr_t) == 0, "bad size");
330   do_tag((int)size);
331   while (size > 0) {
332     *(intptr_t*)start = nextPtr();
333     start += sizeof(intptr_t);
334     size -= sizeof(intptr_t);
335   }
336 }
337 
338 void ArchiveUtils::log_to_classlist(BootstrapInfo* bootstrap_specifier, TRAPS) {
339   if (ClassListWriter::is_enabled()) {
340     if (SystemDictionaryShared::is_supported_invokedynamic(bootstrap_specifier)) {
341       const constantPoolHandle& pool = bootstrap_specifier->pool();
342       if (SystemDictionaryShared::is_builtin_loader(pool->pool_holder()->class_loader_data())) {
343         // Currently lambda proxy classes are supported only for the built-in loaders.
344         ResourceMark rm(THREAD);
345         int pool_index = bootstrap_specifier->bss_index();
346         ClassListWriter w;
347         w.stream()->print("%s %s", ClassListParser::lambda_proxy_tag(), pool->pool_holder()->name()->as_C_string());
348         CDSIndyInfo cii;
349         ClassListParser::populate_cds_indy_info(pool, pool_index, &cii, CHECK);
350         GrowableArray<const char*>* indy_items = cii.items();
351         for (int i = 0; i < indy_items->length(); i++) {
352           w.stream()->print(" %s", indy_items->at(i));
353         }
354         w.stream()->cr();
355       }
356     }
357   }
358 }
359 
360 // Used in logging: "boot", "boot2", "plat", "app" and "unreg";
361 const char* ArchiveUtils::class_category(Klass* k) {
362   if (k->is_array_klass()) {
363     return "array";
364   } else {
365     oop loader = k->class_loader();
366     if (loader == nullptr) {
367       if (k->module() != nullptr &&
368           k->module()->name() != nullptr &&
369           k->module()->name()->equals("java.base")) {
370         return "boot"; // all boot classes in java.base -- they are loaded first with PreloadSharedClasses
371       } else {
372         return "boot2"; // other boot classes -- they are loaded in a second phase with PreloadSharedClasses
373       }
374     } else {
375       if (loader == SystemDictionary::java_platform_loader()) {
376         return "plat";
377       } else if (loader == SystemDictionary::java_system_loader()) {
378         return "app";
379       } else {
380         return "unreg";
381       }
382     }
383   }
384 }
385 
386 // "boot", "platform", "app" or nullptr
387 const char* ArchiveUtils::builtin_loader_name_or_null(oop loader) {
388   if (loader == nullptr) {
389     return "boot";
390   } else if (loader == SystemDictionary::java_platform_loader()) {
391     return "platform";
392   } else if (loader == SystemDictionary::java_system_loader()) {
393     return "app";
394   } else {
395     return nullptr;
396   }
397 }
398 
399 // "boot", "platform", "app". Asserts if not a built-in-loader
400 const char* ArchiveUtils::builtin_loader_name(oop loader) {
401   const char* name = builtin_loader_name_or_null(loader);
402   assert(name != nullptr, "must be a built-in loader");
403   return name;
404 }
405 
406 bool ArchiveUtils::builtin_loader_from_type(const char* loader_type, oop* value_ret) {
407   if (strcmp(loader_type, "boot") == 0) {
408     *value_ret = nullptr;
409     return true;
410   } else if (strcmp(loader_type, "platform") == 0) {
411     *value_ret = SystemDictionary::java_platform_loader();
412     return true;
413   } else if (strcmp(loader_type, "app") == 0) {
414     *value_ret = SystemDictionary::java_system_loader();
415     return true;
416   } else {
417     DEBUG_ONLY(*value_ret = cast_to_oop((void*)badOopVal));
418     return false;
419   }
420 }
421 
422 oop ArchiveUtils::builtin_loader_from_type(int loader_type) {
423   if (loader_type == ClassLoader::BOOT_LOADER) {
424     return nullptr;
425   } else if (loader_type == ClassLoader::PLATFORM_LOADER)  {
426     return SystemDictionary::java_platform_loader();
427   } else if (loader_type == ClassLoader::APP_LOADER) {
428     return SystemDictionary::java_system_loader();
429   } else {
430     ShouldNotReachHere();
431     return nullptr;
432   }
433 }
< prev index next >