1 /*
2 * Copyright (c) 2018, 2023, 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 *
266 bool HeapShared::archive_object(oop obj) {
267 assert(CDSConfig::is_dumping_heap(), "dump-time only");
268
269 assert(!obj->is_stackChunk(), "do not archive stack chunks");
270 if (has_been_archived(obj)) {
271 return true;
272 }
273
274 if (ArchiveHeapWriter::is_too_large_to_archive(obj->size())) {
275 log_debug(cds, heap)("Cannot archive, object (" PTR_FORMAT ") is too large: " SIZE_FORMAT,
276 p2i(obj), obj->size());
277 return false;
278 } else {
279 count_allocation(obj->size());
280 ArchiveHeapWriter::add_source_obj(obj);
281
282 // The archived objects are discovered in a predictable order. Compute
283 // their identity_hash() as soon as we see them. This ensures that the
284 // the identity_hash in the object header will have a predictable value,
285 // making the archive reproducible.
286 obj->identity_hash();
287 CachedOopInfo info = make_cached_oop_info();
288 archived_object_cache()->put(obj, info);
289 mark_native_pointers(obj);
290
291 if (log_is_enabled(Debug, cds, heap)) {
292 ResourceMark rm;
293 log_debug(cds, heap)("Archived heap object " PTR_FORMAT " : %s",
294 p2i(obj), obj->klass()->external_name());
295 }
296
297 if (java_lang_Module::is_instance(obj) && Modules::check_archived_module_oop(obj)) {
298 Modules::update_oops_in_archived_module(obj, append_root(obj));
299 }
300
301 return true;
302 }
303 }
304
305 class MetaspaceObjToOopHandleTable: public ResourceHashtable<MetaspaceObj*, OopHandle,
306 36137, // prime number
1588 }
1589
1590 void HeapShared::archive_object_subgraphs(ArchivableStaticFieldInfo fields[],
1591 bool is_full_module_graph) {
1592 _num_total_subgraph_recordings = 0;
1593 _num_total_walked_objs = 0;
1594 _num_total_archived_objs = 0;
1595 _num_total_recorded_klasses = 0;
1596 _num_total_verifications = 0;
1597
1598 // For each class X that has one or more archived fields:
1599 // [1] Dump the subgraph of each archived field
1600 // [2] Create a list of all the class of the objects that can be reached
1601 // by any of these static fields.
1602 // At runtime, these classes are initialized before X's archived fields
1603 // are restored by HeapShared::initialize_from_archived_subgraph().
1604 int i;
1605 for (int i = 0; fields[i].valid(); ) {
1606 ArchivableStaticFieldInfo* info = &fields[i];
1607 const char* klass_name = info->klass_name;
1608 start_recording_subgraph(info->klass, klass_name, is_full_module_graph);
1609
1610 // If you have specified consecutive fields of the same klass in
1611 // fields[], these will be archived in the same
1612 // {start_recording_subgraph ... done_recording_subgraph} pass to
1613 // save time.
1614 for (; fields[i].valid(); i++) {
1615 ArchivableStaticFieldInfo* f = &fields[i];
1616 if (f->klass_name != klass_name) {
1617 break;
1618 }
1619
1620 archive_reachable_objects_from_static_field(f->klass, f->klass_name,
1621 f->offset, f->field_name);
1622 }
1623 done_recording_subgraph(info->klass, klass_name);
1624 }
1625
1626 log_info(cds, heap)("Archived subgraph records = %d",
1627 _num_total_subgraph_recordings);
|
1 /*
2 * Copyright (c) 2018, 2024, 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 *
266 bool HeapShared::archive_object(oop obj) {
267 assert(CDSConfig::is_dumping_heap(), "dump-time only");
268
269 assert(!obj->is_stackChunk(), "do not archive stack chunks");
270 if (has_been_archived(obj)) {
271 return true;
272 }
273
274 if (ArchiveHeapWriter::is_too_large_to_archive(obj->size())) {
275 log_debug(cds, heap)("Cannot archive, object (" PTR_FORMAT ") is too large: " SIZE_FORMAT,
276 p2i(obj), obj->size());
277 return false;
278 } else {
279 count_allocation(obj->size());
280 ArchiveHeapWriter::add_source_obj(obj);
281
282 // The archived objects are discovered in a predictable order. Compute
283 // their identity_hash() as soon as we see them. This ensures that the
284 // the identity_hash in the object header will have a predictable value,
285 // making the archive reproducible.
286 if (!obj->klass()->is_inline_klass()) {
287 obj->identity_hash();
288 }
289 CachedOopInfo info = make_cached_oop_info();
290 archived_object_cache()->put(obj, info);
291 mark_native_pointers(obj);
292
293 if (log_is_enabled(Debug, cds, heap)) {
294 ResourceMark rm;
295 log_debug(cds, heap)("Archived heap object " PTR_FORMAT " : %s",
296 p2i(obj), obj->klass()->external_name());
297 }
298
299 if (java_lang_Module::is_instance(obj) && Modules::check_archived_module_oop(obj)) {
300 Modules::update_oops_in_archived_module(obj, append_root(obj));
301 }
302
303 return true;
304 }
305 }
306
307 class MetaspaceObjToOopHandleTable: public ResourceHashtable<MetaspaceObj*, OopHandle,
308 36137, // prime number
1590 }
1591
1592 void HeapShared::archive_object_subgraphs(ArchivableStaticFieldInfo fields[],
1593 bool is_full_module_graph) {
1594 _num_total_subgraph_recordings = 0;
1595 _num_total_walked_objs = 0;
1596 _num_total_archived_objs = 0;
1597 _num_total_recorded_klasses = 0;
1598 _num_total_verifications = 0;
1599
1600 // For each class X that has one or more archived fields:
1601 // [1] Dump the subgraph of each archived field
1602 // [2] Create a list of all the class of the objects that can be reached
1603 // by any of these static fields.
1604 // At runtime, these classes are initialized before X's archived fields
1605 // are restored by HeapShared::initialize_from_archived_subgraph().
1606 int i;
1607 for (int i = 0; fields[i].valid(); ) {
1608 ArchivableStaticFieldInfo* info = &fields[i];
1609 const char* klass_name = info->klass_name;
1610
1611 if (CDSConfig::is_valhalla_preview() && strcmp(klass_name, "jdk/internal/module/ArchivedModuleGraph") == 0) {
1612 // FIXME -- ArchivedModuleGraph doesn't work when java.base is patched with valhalla classes.
1613 i++;
1614 continue;
1615 }
1616
1617 start_recording_subgraph(info->klass, klass_name, is_full_module_graph);
1618
1619 // If you have specified consecutive fields of the same klass in
1620 // fields[], these will be archived in the same
1621 // {start_recording_subgraph ... done_recording_subgraph} pass to
1622 // save time.
1623 for (; fields[i].valid(); i++) {
1624 ArchivableStaticFieldInfo* f = &fields[i];
1625 if (f->klass_name != klass_name) {
1626 break;
1627 }
1628
1629 archive_reachable_objects_from_static_field(f->klass, f->klass_name,
1630 f->offset, f->field_name);
1631 }
1632 done_recording_subgraph(info->klass, klass_name);
1633 }
1634
1635 log_info(cds, heap)("Archived subgraph records = %d",
1636 _num_total_subgraph_recordings);
|