src/hotspot/share/memory/heapShared.cpp
author iklam
Mon, 08 Oct 2018 16:29:10 -0700
changeset 52047 7bc8b456e5ac
parent 51796 9d3a00c8c047
child 52062 8dbf1a13af49
permissions -rw-r--r--
8210388: Use hash table to store archived subgraph_info records Reviewed-by: jiangli
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
     1
/*
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
     4
 *
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
     8
 *
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    13
 * accompanied this code).
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    14
 *
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    18
 *
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    21
 * questions.
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    22
 *
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    23
 */
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    24
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    25
#include "precompiled.hpp"
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    26
#include "classfile/javaClasses.inline.hpp"
51429
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
    27
#include "classfile/symbolTable.hpp"
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    28
#include "classfile/vmSymbols.hpp"
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    29
#include "logging/log.hpp"
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    30
#include "logging/logMessage.hpp"
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    31
#include "logging/logStream.hpp"
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
    32
#include "memory/heapShared.inline.hpp"
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    33
#include "memory/iterator.inline.hpp"
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    34
#include "memory/metadataFactory.hpp"
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    35
#include "memory/metaspaceClosure.hpp"
51796
9d3a00c8c047 8210864: Reduce the use of metaspaceShared.hpp
iklam
parents: 51720
diff changeset
    36
#include "memory/metaspaceShared.inline.hpp"
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    37
#include "memory/resourceArea.hpp"
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    38
#include "oops/compressedOops.inline.hpp"
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    39
#include "oops/oop.inline.hpp"
51467
12997ebbc0d8 8209647: constantPoolHandle::constantPoolHandle(ConstantPool*) when precompiled header is disabled
iklam
parents: 51429
diff changeset
    40
#include "runtime/fieldDescriptor.inline.hpp"
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
    41
#include "utilities/bitMap.inline.hpp"
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    42
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    43
#if INCLUDE_CDS_JAVA_HEAP
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
    44
address   HeapShared::_narrow_oop_base;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
    45
int       HeapShared::_narrow_oop_shift;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
    46
HeapShared::DumpTimeKlassSubGraphInfoTable* HeapShared::_dump_time_subgraph_info_table = NULL;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
    47
HeapShared::RunTimeKlassSubGraphInfoTable   HeapShared::_run_time_subgraph_info_table;
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    48
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    49
// Get the subgraph_info for Klass k. A new subgraph_info is created if
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    50
// there is no existing one for k. The subgraph_info records the relocated
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    51
// Klass* of the original k.
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    52
KlassSubGraphInfo* HeapShared::get_subgraph_info(Klass* k) {
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
    53
  assert(DumpSharedSpaces, "dump time only");
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    54
  Klass* relocated_k = MetaspaceShared::get_relocated_klass(k);
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
    55
  KlassSubGraphInfo* info = _dump_time_subgraph_info_table->get(relocated_k);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
    56
  if (info == NULL) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
    57
    _dump_time_subgraph_info_table->put(relocated_k, KlassSubGraphInfo(relocated_k));
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
    58
    info = _dump_time_subgraph_info_table->get(relocated_k);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
    59
    ++ _dump_time_subgraph_info_table->_count;
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    60
  }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    61
  return info;
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    62
}
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    63
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    64
// Add an entry field to the current KlassSubGraphInfo.
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    65
void KlassSubGraphInfo::add_subgraph_entry_field(int static_field_offset, oop v) {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    66
  assert(DumpSharedSpaces, "dump time only");
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    67
  if (_subgraph_entry_fields == NULL) {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    68
    _subgraph_entry_fields =
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    69
      new(ResourceObj::C_HEAP, mtClass) GrowableArray<juint>(10, true);
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    70
  }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    71
  _subgraph_entry_fields->append((juint)static_field_offset);
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    72
  _subgraph_entry_fields->append(CompressedOops::encode(v));
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    73
}
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    74
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    75
// Add the Klass* for an object in the current KlassSubGraphInfo's subgraphs.
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    76
// Only objects of boot classes can be included in sub-graph.
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    77
void KlassSubGraphInfo::add_subgraph_object_klass(Klass* orig_k, Klass *relocated_k) {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    78
  assert(DumpSharedSpaces, "dump time only");
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    79
  assert(relocated_k == MetaspaceShared::get_relocated_klass(orig_k),
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    80
         "must be the relocated Klass in the shared space");
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    81
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    82
  if (_subgraph_object_klasses == NULL) {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    83
    _subgraph_object_klasses =
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    84
      new(ResourceObj::C_HEAP, mtClass) GrowableArray<Klass*>(50, true);
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    85
  }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    86
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    87
  assert(relocated_k->is_shared(), "must be a shared class");
51371
3ab8b84e93cd 8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents: 50951
diff changeset
    88
3ab8b84e93cd 8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents: 50951
diff changeset
    89
  if (_k == relocated_k) {
3ab8b84e93cd 8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents: 50951
diff changeset
    90
    // Don't add the Klass containing the sub-graph to it's own klass
3ab8b84e93cd 8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents: 50951
diff changeset
    91
    // initialization list.
3ab8b84e93cd 8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents: 50951
diff changeset
    92
    return;
3ab8b84e93cd 8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents: 50951
diff changeset
    93
  }
3ab8b84e93cd 8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents: 50951
diff changeset
    94
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    95
  if (relocated_k->is_instance_klass()) {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    96
    assert(InstanceKlass::cast(relocated_k)->is_shared_boot_class(),
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    97
          "must be boot class");
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    98
    // SystemDictionary::xxx_klass() are not updated, need to check
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    99
    // the original Klass*
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   100
    if (orig_k == SystemDictionary::String_klass() ||
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   101
        orig_k == SystemDictionary::Object_klass()) {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   102
      // Initialized early during VM initialization. No need to be added
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   103
      // to the sub-graph object class list.
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   104
      return;
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   105
    }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   106
  } else if (relocated_k->is_objArray_klass()) {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   107
    Klass* abk = ObjArrayKlass::cast(relocated_k)->bottom_klass();
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   108
    if (abk->is_instance_klass()) {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   109
      assert(InstanceKlass::cast(abk)->is_shared_boot_class(),
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   110
            "must be boot class");
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   111
    }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   112
    if (relocated_k == Universe::objectArrayKlassObj()) {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   113
      // Initialized early during Universe::genesis. No need to be added
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   114
      // to the list.
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   115
      return;
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   116
    }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   117
  } else {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   118
    assert(relocated_k->is_typeArray_klass(), "must be");
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   119
    // Primitive type arrays are created early during Universe::genesis.
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   120
    return;
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   121
  }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   122
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   123
  if (log_is_enabled(Debug, cds, heap)) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   124
    if (!_subgraph_object_klasses->contains(relocated_k)) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   125
      ResourceMark rm;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   126
      log_debug(cds, heap)("Adding klass %s", orig_k->external_name());
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   127
    }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   128
  }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   129
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   130
  _subgraph_object_klasses->append_if_missing(relocated_k);
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   131
}
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   132
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   133
// Initialize an archived subgraph_info_record from the given KlassSubGraphInfo.
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   134
void ArchivedKlassSubGraphInfoRecord::init(KlassSubGraphInfo* info) {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   135
  _k = info->klass();
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   136
  _entry_field_records = NULL;
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   137
  _subgraph_object_klasses = NULL;
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   138
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   139
  // populate the entry fields
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   140
  GrowableArray<juint>* entry_fields = info->subgraph_entry_fields();
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   141
  if (entry_fields != NULL) {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   142
    int num_entry_fields = entry_fields->length();
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   143
    assert(num_entry_fields % 2 == 0, "sanity");
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   144
    _entry_field_records =
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   145
      MetaspaceShared::new_ro_array<juint>(num_entry_fields);
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   146
    for (int i = 0 ; i < num_entry_fields; i++) {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   147
      _entry_field_records->at_put(i, entry_fields->at(i));
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   148
    }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   149
  }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   150
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   151
  // the Klasses of the objects in the sub-graphs
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   152
  GrowableArray<Klass*>* subgraph_object_klasses = info->subgraph_object_klasses();
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   153
  if (subgraph_object_klasses != NULL) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   154
    int num_subgraphs_klasses = subgraph_object_klasses->length();
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   155
    _subgraph_object_klasses =
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   156
      MetaspaceShared::new_ro_array<Klass*>(num_subgraphs_klasses);
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   157
    for (int i = 0; i < num_subgraphs_klasses; i++) {
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   158
      Klass* subgraph_k = subgraph_object_klasses->at(i);
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   159
      if (log_is_enabled(Info, cds, heap)) {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   160
        ResourceMark rm;
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   161
        log_info(cds, heap)(
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   162
          "Archived object klass %s (%2d) => %s",
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   163
          _k->external_name(), i, subgraph_k->external_name());
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   164
      }
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   165
      _subgraph_object_klasses->at_put(i, subgraph_k);
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   166
    }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   167
  }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   168
}
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   169
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   170
struct CopyKlassSubGraphInfoToArchive : StackObj {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   171
  CompactHashtableWriter* _writer;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   172
  CopyKlassSubGraphInfoToArchive(CompactHashtableWriter* writer) : _writer(writer) {}
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   173
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   174
  bool do_entry(Klass* klass, KlassSubGraphInfo& info) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   175
    if (info.subgraph_object_klasses() != NULL || info.subgraph_entry_fields() != NULL) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   176
      ArchivedKlassSubGraphInfoRecord* record =
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   177
        (ArchivedKlassSubGraphInfoRecord*)MetaspaceShared::read_only_space_alloc(sizeof(ArchivedKlassSubGraphInfoRecord));
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   178
      record->init(&info);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   179
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   180
      unsigned int hash = primitive_hash<Klass*>(klass);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   181
      uintx deltax = MetaspaceShared::object_delta(record);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   182
      guarantee(deltax <= MAX_SHARED_DELTA, "must not be");
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   183
      u4 delta = u4(deltax);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   184
      _writer->add(hash, delta);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   185
    }
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   186
    return true; // keep on iterating
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   187
  }
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   188
};
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   189
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   190
// Build the records of archived subgraph infos, which include:
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   191
// - Entry points to all subgraphs from the containing class mirror. The entry
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   192
//   points are static fields in the mirror. For each entry point, the field
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   193
//   offset and value are recorded in the sub-graph info. The value are stored
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   194
//   back to the corresponding field at runtime.
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   195
// - A list of klasses that need to be loaded/initialized before archived
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   196
//   java object sub-graph can be accessed at runtime.
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   197
void HeapShared::write_subgraph_info_table() {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   198
  // Allocate the contents of the hashtable(s) inside the RO region of the CDS archive.
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   199
  DumpTimeKlassSubGraphInfoTable* d_table = _dump_time_subgraph_info_table;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   200
  CompactHashtableStats stats;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   201
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   202
  _run_time_subgraph_info_table.reset();
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   203
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   204
  int num_buckets = CompactHashtableWriter::default_num_buckets(d_table->_count);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   205
  CompactHashtableWriter writer(num_buckets, &stats);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   206
  CopyKlassSubGraphInfoToArchive copy(&writer);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   207
  _dump_time_subgraph_info_table->iterate(&copy);
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   208
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   209
  writer.dump(&_run_time_subgraph_info_table, "subgraphs");
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   210
}
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   211
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   212
void HeapShared::serialize_subgraph_info_table_header(SerializeClosure* soc) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   213
  _run_time_subgraph_info_table.serialize_header(soc);
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   214
}
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   215
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   216
void HeapShared::initialize_from_archived_subgraph(Klass* k) {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   217
  if (!MetaspaceShared::open_archive_heap_region_mapped()) {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   218
    return; // nothing to do
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   219
  }
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   220
  assert(!DumpSharedSpaces, "Should not be called with DumpSharedSpaces");
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   221
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   222
  unsigned int hash = primitive_hash<Klass*>(k);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   223
  ArchivedKlassSubGraphInfoRecord* record = _run_time_subgraph_info_table.lookup(k, hash, 0);
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   224
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   225
  // Initialize from archived data. Currently this is done only
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   226
  // during VM initialization time. No lock is needed.
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   227
  if (record != NULL) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   228
    Thread* THREAD = Thread::current();
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   229
    if (log_is_enabled(Info, cds, heap)) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   230
      ResourceMark rm;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   231
      log_info(cds, heap)("initialize_from_archived_subgraph " PTR_FORMAT " %s", p2i(k),
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   232
                          k->external_name());
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   233
    }
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   234
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   235
    int i;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   236
    // Load/link/initialize the klasses of the objects in the subgraph.
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   237
    // NULL class loader is used.
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   238
    Array<Klass*>* klasses = record->subgraph_object_klasses();
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   239
    if (klasses != NULL) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   240
      for (i = 0; i < klasses->length(); i++) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   241
        Klass* obj_k = klasses->at(i);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   242
        Klass* resolved_k = SystemDictionary::resolve_or_null(
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   243
                                              (obj_k)->name(), THREAD);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   244
        if (resolved_k != obj_k) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   245
          return;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   246
        }
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   247
        if ((obj_k)->is_instance_klass()) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   248
          InstanceKlass* ik = InstanceKlass::cast(obj_k);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   249
          ik->initialize(THREAD);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   250
        } else if ((obj_k)->is_objArray_klass()) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   251
          ObjArrayKlass* oak = ObjArrayKlass::cast(obj_k);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   252
          oak->initialize(THREAD);
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   253
        }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   254
      }
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   255
    }
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   256
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   257
    if (HAS_PENDING_EXCEPTION) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   258
      CLEAR_PENDING_EXCEPTION;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   259
      // None of the field value will be set if there was an exception.
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   260
      // The java code will not see any of the archived objects in the
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   261
      // subgraphs referenced from k in this case.
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   262
      return;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   263
    }
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   264
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   265
    // Load the subgraph entry fields from the record and store them back to
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   266
    // the corresponding fields within the mirror.
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   267
    oop m = k->java_mirror();
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   268
    Array<juint>* entry_field_records = record->entry_field_records();
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   269
    if (entry_field_records != NULL) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   270
      int efr_len = entry_field_records->length();
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   271
      assert(efr_len % 2 == 0, "sanity");
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   272
      for (i = 0; i < efr_len;) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   273
        int field_offset = entry_field_records->at(i);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   274
        // The object refereced by the field becomes 'known' by GC from this
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   275
        // point. All objects in the subgraph reachable from the object are
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   276
        // also 'known' by GC.
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   277
        oop v = MetaspaceShared::materialize_archived_object(
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   278
            entry_field_records->at(i+1));
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   279
        m->obj_field_put(field_offset, v);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   280
        i += 2;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   281
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   282
        log_debug(cds, heap)("  " PTR_FORMAT " init field @ %2d = " PTR_FORMAT, p2i(k), field_offset, p2i(v));
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   283
      }
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   284
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   285
    // Done. Java code can see the archived sub-graphs referenced from k's
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   286
    // mirror after this point.
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   287
    }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   288
  }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   289
}
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   290
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   291
class WalkOopAndArchiveClosure: public BasicOopIterateClosure {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   292
  int _level;
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   293
  bool _record_klasses_only;
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   294
  KlassSubGraphInfo* _subgraph_info;
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   295
  oop _orig_referencing_obj;
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   296
  oop _archived_referencing_obj;
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   297
  Thread* _thread;
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   298
 public:
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   299
  WalkOopAndArchiveClosure(int level, bool record_klasses_only,
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   300
                           KlassSubGraphInfo* subgraph_info,
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   301
                           oop orig, oop archived, TRAPS) :
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   302
    _level(level), _record_klasses_only(record_klasses_only),
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   303
    _subgraph_info(subgraph_info),
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   304
    _orig_referencing_obj(orig), _archived_referencing_obj(archived),
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   305
    _thread(THREAD) {}
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   306
  void do_oop(narrowOop *p) { WalkOopAndArchiveClosure::do_oop_work(p); }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   307
  void do_oop(      oop *p) { WalkOopAndArchiveClosure::do_oop_work(p); }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   308
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   309
 protected:
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   310
  template <class T> void do_oop_work(T *p) {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   311
    oop obj = RawAccess<>::oop_load(p);
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   312
    if (!CompressedOops::is_null(obj)) {
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   313
      assert(!MetaspaceShared::is_archive_object(obj),
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   314
             "original objects must not point to archived objects");
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   315
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   316
      size_t field_delta = pointer_delta(p, _orig_referencing_obj, sizeof(char));
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   317
      T* new_p = (T*)(address(_archived_referencing_obj) + field_delta);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   318
      Thread* THREAD = _thread;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   319
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   320
      if (!_record_klasses_only && log_is_enabled(Debug, cds, heap)) {
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   321
        ResourceMark rm;
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   322
        log_debug(cds, heap)("(%d) %s[" SIZE_FORMAT "] ==> " PTR_FORMAT " size %d %s", _level,
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   323
                             _orig_referencing_obj->klass()->external_name(), field_delta,
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   324
                             p2i(obj), obj->size() * HeapWordSize, obj->klass()->external_name());
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   325
        LogTarget(Trace, cds, heap) log;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   326
        LogStream out(log);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   327
        obj->print_on(&out);
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   328
      }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   329
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   330
      oop archived = HeapShared::archive_reachable_objects_from(_level + 1, _subgraph_info, obj, THREAD);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   331
      assert(archived != NULL, "VM should have exited with unarchivable objects for _level > 1");
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   332
      assert(MetaspaceShared::is_archive_object(archived), "must be");
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   333
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   334
      if (!_record_klasses_only) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   335
        // Update the reference in the archived copy of the referencing object.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   336
        log_debug(cds, heap)("(%d) updating oop @[" PTR_FORMAT "] " PTR_FORMAT " ==> " PTR_FORMAT,
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   337
                             _level, p2i(new_p), p2i(obj), p2i(archived));
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   338
        RawAccess<IS_NOT_NULL>::oop_store(new_p, archived);
51425
4e9667589c43 8209389: SIGSEGV in WalkOopAndArchiveClosure::do_oop_work.
jiangli
parents: 51388
diff changeset
   339
      }
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   340
    }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   341
  }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   342
};
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   343
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   344
// (1) If orig_obj has not been archived yet, archive it.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   345
// (2) If orig_obj has not been seen yet (since start_recording_subgraph() was called),
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   346
//     trace all  objects that are reachable from it, and make sure these objects are archived.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   347
// (3) Record the klasses of all orig_obj and all reachable objects.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   348
oop HeapShared::archive_reachable_objects_from(int level, KlassSubGraphInfo* subgraph_info, oop orig_obj, TRAPS) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   349
  assert(orig_obj != NULL, "must be");
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   350
  assert(!MetaspaceShared::is_archive_object(orig_obj), "sanity");
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   351
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   352
  // java.lang.Class instances cannot be included in an archived
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   353
  // object sub-graph.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   354
  if (java_lang_Class::is_instance(orig_obj)) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   355
    log_error(cds, heap)("(%d) Unknown java.lang.Class object is in the archived sub-graph", level);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   356
    vm_exit(1);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   357
  }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   358
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   359
  oop archived_obj = MetaspaceShared::find_archived_heap_object(orig_obj);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   360
  if (java_lang_String::is_instance(orig_obj) && archived_obj != NULL) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   361
    // To save time, don't walk strings that are already archived. They just contain
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   362
    // pointers to a type array, whose klass doesn't need to be recorded.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   363
    return archived_obj;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   364
  }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   365
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   366
  if (has_been_seen_during_subgraph_recording(orig_obj)) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   367
    // orig_obj has already been archived and traced. Nothing more to do.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   368
    return archived_obj;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   369
  } else {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   370
    set_has_been_seen_during_subgraph_recording(orig_obj);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   371
  }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   372
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   373
  bool record_klasses_only = (archived_obj != NULL);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   374
  if (archived_obj == NULL) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   375
    ++_num_new_archived_objs;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   376
    archived_obj = MetaspaceShared::archive_heap_object(orig_obj, THREAD);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   377
    if (archived_obj == NULL) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   378
      // Skip archiving the sub-graph referenced from the current entry field.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   379
      ResourceMark rm;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   380
      log_error(cds, heap)(
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   381
        "Cannot archive the sub-graph referenced from %s object ("
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   382
        PTR_FORMAT ") size %d, skipped.",
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   383
        orig_obj->klass()->external_name(), p2i(orig_obj), orig_obj->size() * HeapWordSize);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   384
      if (level == 1) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   385
        // Don't archive a subgraph root that's too big. For archives static fields, that's OK
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   386
        // as the Java code will take care of initializing this field dynamically.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   387
        return NULL;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   388
      } else {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   389
        // We don't know how to handle an object that has been archived, but some of its reachable
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   390
        // objects cannot be archived. Bail out for now. We might need to fix this in the future if
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   391
        // we have a real use case.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   392
        vm_exit(1);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   393
      }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   394
    }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   395
  }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   396
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   397
  assert(archived_obj != NULL, "must be");
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   398
  Klass *orig_k = orig_obj->klass();
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   399
  Klass *relocated_k = archived_obj->klass();
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   400
  subgraph_info->add_subgraph_object_klass(orig_k, relocated_k);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   401
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   402
  WalkOopAndArchiveClosure walker(level, record_klasses_only, subgraph_info, orig_obj, archived_obj, THREAD);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   403
  orig_obj->oop_iterate(&walker);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   404
  return archived_obj;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   405
}
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   406
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   407
//
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   408
// Start from the given static field in a java mirror and archive the
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   409
// complete sub-graph of java heap objects that are reached directly
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   410
// or indirectly from the starting object by following references.
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   411
// Sub-graph archiving restrictions (current):
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   412
//
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   413
// - All classes of objects in the archived sub-graph (including the
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   414
//   entry class) must be boot class only.
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   415
// - No java.lang.Class instance (java mirror) can be included inside
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   416
//   an archived sub-graph. Mirror can only be the sub-graph entry object.
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   417
//
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   418
// The Java heap object sub-graph archiving process (see
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   419
// WalkOopAndArchiveClosure):
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   420
//
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   421
// 1) Java object sub-graph archiving starts from a given static field
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   422
// within a Class instance (java mirror). If the static field is a
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   423
// refererence field and points to a non-null java object, proceed to
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   424
// the next step.
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   425
//
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   426
// 2) Archives the referenced java object. If an archived copy of the
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   427
// current object already exists, updates the pointer in the archived
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   428
// copy of the referencing object to point to the current archived object.
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   429
// Otherwise, proceed to the next step.
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   430
//
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   431
// 3) Follows all references within the current java object and recursively
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   432
// archive the sub-graph of objects starting from each reference.
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   433
//
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   434
// 4) Updates the pointer in the archived copy of referencing object to
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   435
// point to the current archived object.
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   436
//
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   437
// 5) The Klass of the current java object is added to the list of Klasses
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   438
// for loading and initialzing before any object in the archived graph can
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   439
// be accessed at runtime.
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   440
//
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   441
void HeapShared::archive_reachable_objects_from_static_field(InstanceKlass *k,
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   442
                                                             const char* klass_name,
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   443
                                                             int field_offset,
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   444
                                                             const char* field_name,
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   445
                                                             TRAPS) {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   446
  assert(DumpSharedSpaces, "dump time only");
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   447
  assert(k->is_shared_boot_class(), "must be boot class");
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   448
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   449
  oop m = k->java_mirror();
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   450
  oop archived_m = MetaspaceShared::find_archived_heap_object(m);
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   451
  if (CompressedOops::is_null(archived_m)) {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   452
    return;
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   453
  }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   454
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   455
  KlassSubGraphInfo* subgraph_info = get_subgraph_info(k);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   456
  oop f = m->obj_field(field_offset);
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   457
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   458
  log_debug(cds, heap)("Start archiving from: %s::%s (" PTR_FORMAT ")", klass_name, field_name, p2i(f));
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   459
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   460
  if (!CompressedOops::is_null(f)) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   461
    if (log_is_enabled(Trace, cds, heap)) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   462
      LogTarget(Trace, cds, heap) log;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   463
      LogStream out(log);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   464
      f->print_on(&out);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   465
    }
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   466
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   467
    oop af = archive_reachable_objects_from(1, subgraph_info, f, CHECK);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   468
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   469
    if (af == NULL) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   470
      log_error(cds, heap)("Archiving failed %s::%s (some reachable objects cannot be archived)",
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   471
                           klass_name, field_name);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   472
    } else {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   473
      // Note: the field value is not preserved in the archived mirror.
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   474
      // Record the field as a new subGraph entry point. The recorded
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   475
      // information is restored from the archive at runtime.
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   476
      subgraph_info->add_subgraph_entry_field(field_offset, af);
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   477
      log_info(cds, heap)("Archived field %s::%s => " PTR_FORMAT, klass_name, field_name, p2i(af));
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   478
    }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   479
  } else {
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   480
    // The field contains null, we still need to record the entry point,
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   481
    // so it can be restored at runtime.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   482
    subgraph_info->add_subgraph_entry_field(field_offset, NULL);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   483
  }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   484
}
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   485
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   486
#ifndef PRODUCT
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   487
class VerifySharedOopClosure: public BasicOopIterateClosure {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   488
 private:
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   489
  bool _is_archived;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   490
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   491
 public:
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   492
  VerifySharedOopClosure(bool is_archived) : _is_archived(is_archived) {}
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   493
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   494
  void do_oop(narrowOop *p) { VerifySharedOopClosure::do_oop_work(p); }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   495
  void do_oop(      oop *p) { VerifySharedOopClosure::do_oop_work(p); }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   496
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   497
 protected:
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   498
  template <class T> void do_oop_work(T *p) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   499
    oop obj = RawAccess<>::oop_load(p);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   500
    if (!CompressedOops::is_null(obj)) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   501
      HeapShared::verify_reachable_objects_from(obj, _is_archived);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   502
    }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   503
  }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   504
};
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   505
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   506
void HeapShared::verify_subgraph_from_static_field(InstanceKlass* k, int field_offset) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   507
  assert(DumpSharedSpaces, "dump time only");
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   508
  assert(k->is_shared_boot_class(), "must be boot class");
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   509
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   510
  oop m = k->java_mirror();
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   511
  oop archived_m = MetaspaceShared::find_archived_heap_object(m);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   512
  if (CompressedOops::is_null(archived_m)) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   513
    return;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   514
  }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   515
  oop f = m->obj_field(field_offset);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   516
  if (!CompressedOops::is_null(f)) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   517
    verify_subgraph_from(f);
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   518
  }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   519
}
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   520
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   521
void HeapShared::verify_subgraph_from(oop orig_obj) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   522
  oop archived_obj = MetaspaceShared::find_archived_heap_object(orig_obj);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   523
  if (archived_obj == NULL) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   524
    // It's OK for the root of a subgraph to be not archived. See comments in
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   525
    // archive_reachable_objects_from().
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   526
    return;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   527
  }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   528
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   529
  // Verify that all objects reachable from orig_obj are archived.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   530
  init_seen_objects_table();
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   531
  verify_reachable_objects_from(orig_obj, false);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   532
  delete_seen_objects_table();
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   533
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   534
  // Note: we could also verify that all objects reachable from the archived
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   535
  // copy of orig_obj can only point to archived objects, with:
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   536
  //      init_seen_objects_table();
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   537
  //      verify_reachable_objects_from(archived_obj, true);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   538
  //      init_seen_objects_table();
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   539
  // but that's already done in G1HeapVerifier::verify_archive_regions so we
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   540
  // won't do it here.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   541
}
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   542
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   543
void HeapShared::verify_reachable_objects_from(oop obj, bool is_archived) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   544
  _num_total_verifications ++;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   545
  if (!has_been_seen_during_subgraph_recording(obj)) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   546
    set_has_been_seen_during_subgraph_recording(obj);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   547
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   548
    if (is_archived) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   549
      assert(MetaspaceShared::is_archive_object(obj), "must be");
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   550
      assert(MetaspaceShared::find_archived_heap_object(obj) == NULL, "must be");
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   551
    } else {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   552
      assert(!MetaspaceShared::is_archive_object(obj), "must be");
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   553
      assert(MetaspaceShared::find_archived_heap_object(obj) != NULL, "must be");
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   554
    }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   555
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   556
    VerifySharedOopClosure walker(is_archived);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   557
    obj->oop_iterate(&walker);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   558
  }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   559
}
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   560
#endif
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   561
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   562
HeapShared::SeenObjectsTable* HeapShared::_seen_objects_table = NULL;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   563
int HeapShared::_num_new_walked_objs;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   564
int HeapShared::_num_new_archived_objs;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   565
int HeapShared::_num_old_recorded_klasses;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   566
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   567
int HeapShared::_num_total_subgraph_recordings = 0;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   568
int HeapShared::_num_total_walked_objs = 0;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   569
int HeapShared::_num_total_archived_objs = 0;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   570
int HeapShared::_num_total_recorded_klasses = 0;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   571
int HeapShared::_num_total_verifications = 0;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   572
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   573
bool HeapShared::has_been_seen_during_subgraph_recording(oop obj) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   574
  return _seen_objects_table->get(obj) != NULL;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   575
}
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   576
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   577
void HeapShared::set_has_been_seen_during_subgraph_recording(oop obj) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   578
  assert(!has_been_seen_during_subgraph_recording(obj), "sanity");
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   579
  _seen_objects_table->put(obj, true);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   580
  ++ _num_new_walked_objs;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   581
}
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   582
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   583
void HeapShared::start_recording_subgraph(InstanceKlass *k, const char* class_name) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   584
  log_info(cds, heap)("Start recording subgraph(s) for archived fields in %s", class_name);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   585
  init_seen_objects_table();
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   586
  _num_new_walked_objs = 0;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   587
  _num_new_archived_objs = 0;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   588
  _num_old_recorded_klasses = get_subgraph_info(k)->num_subgraph_object_klasses();
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   589
}
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   590
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   591
void HeapShared::done_recording_subgraph(InstanceKlass *k, const char* class_name) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   592
  int num_new_recorded_klasses = get_subgraph_info(k)->num_subgraph_object_klasses() -
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   593
    _num_old_recorded_klasses;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   594
  log_info(cds, heap)("Done recording subgraph(s) for archived fields in %s: "
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   595
                      "walked %d objs, archived %d new objs, recorded %d classes",
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   596
                      class_name, _num_new_walked_objs, _num_new_archived_objs,
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   597
                      num_new_recorded_klasses);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   598
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   599
  delete_seen_objects_table();
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   600
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   601
  _num_total_subgraph_recordings ++;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   602
  _num_total_walked_objs      += _num_new_walked_objs;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   603
  _num_total_archived_objs    += _num_new_archived_objs;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   604
  _num_total_recorded_klasses +=  num_new_recorded_klasses;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   605
}
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   606
51429
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   607
struct ArchivableStaticFieldInfo {
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   608
  const char* klass_name;
51429
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   609
  const char* field_name;
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   610
  InstanceKlass* klass;
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   611
  int offset;
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   612
  BasicType type;
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   613
};
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   614
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   615
// If you add new entries to this table, you should know what you're doing!
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   616
static ArchivableStaticFieldInfo archivable_static_fields[] = {
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   617
  {"jdk/internal/module/ArchivedModuleGraph",  "archivedSystemModules"},
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   618
  {"jdk/internal/module/ArchivedModuleGraph",  "archivedModuleFinder"},
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   619
  {"jdk/internal/module/ArchivedModuleGraph",  "archivedMainModule"},
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   620
  {"jdk/internal/module/ArchivedModuleGraph",  "archivedConfiguration"},
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   621
  {"java/util/ImmutableCollections$ListN",     "EMPTY_LIST"},
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   622
  {"java/util/ImmutableCollections$MapN",      "EMPTY_MAP"},
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   623
  {"java/util/ImmutableCollections$SetN",      "EMPTY_SET"},
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   624
  {"java/lang/Integer$IntegerCache",           "archivedCache"},
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   625
  {"java/lang/module/Configuration",           "EMPTY_CONFIGURATION"},
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   626
};
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   627
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   628
const static int num_archivable_static_fields =
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   629
  sizeof(archivable_static_fields) / sizeof(ArchivableStaticFieldInfo);
51429
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   630
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   631
class ArchivableStaticFieldFinder: public FieldClosure {
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   632
  InstanceKlass* _ik;
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   633
  Symbol* _field_name;
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   634
  bool _found;
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   635
  int _offset;
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   636
public:
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   637
  ArchivableStaticFieldFinder(InstanceKlass* ik, Symbol* field_name) :
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   638
    _ik(ik), _field_name(field_name), _found(false), _offset(-1) {}
51429
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   639
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   640
  virtual void do_field(fieldDescriptor* fd) {
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   641
    if (fd->name() == _field_name) {
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   642
      assert(!_found, "fields cannot be overloaded");
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   643
      assert(fd->field_type() == T_OBJECT || fd->field_type() == T_ARRAY, "can archive only obj or array fields");
51429
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   644
      _found = true;
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   645
      _offset = fd->offset();
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   646
    }
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   647
  }
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   648
  bool found()     { return _found;  }
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   649
  int offset()     { return _offset; }
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   650
};
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   651
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   652
void HeapShared::init_archivable_static_fields(Thread* THREAD) {
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   653
  _dump_time_subgraph_info_table = new (ResourceObj::C_HEAP, mtClass)DumpTimeKlassSubGraphInfoTable();
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   654
51429
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   655
  for (int i = 0; i < num_archivable_static_fields; i++) {
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   656
    ArchivableStaticFieldInfo* info = &archivable_static_fields[i];
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   657
    TempNewSymbol klass_name =  SymbolTable::new_symbol(info->klass_name, THREAD);
51429
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   658
    TempNewSymbol field_name =  SymbolTable::new_symbol(info->field_name, THREAD);
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   659
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   660
    Klass* k = SystemDictionary::resolve_or_null(klass_name, THREAD);
51429
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   661
    assert(k != NULL && !HAS_PENDING_EXCEPTION, "class must exist");
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   662
    InstanceKlass* ik = InstanceKlass::cast(k);
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   663
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   664
    ArchivableStaticFieldFinder finder(ik, field_name);
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   665
    ik->do_local_static_fields(&finder);
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   666
    assert(finder.found(), "field must exist");
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   667
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   668
    info->klass = ik;
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   669
    info->offset = finder.offset();
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   670
  }
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   671
}
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   672
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   673
void HeapShared::archive_static_fields(Thread* THREAD) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   674
  // For each class X that has one or more archived fields:
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   675
  // [1] Dump the subgraph of each archived field
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   676
  // [2] Create a list of all the class of the objects that can be reached
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   677
  //     by any of these static fields.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   678
  //     At runtime, these classes are initialized before X's archived fields
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   679
  //     are restored by HeapShared::initialize_from_archived_subgraph().
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   680
  int i;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   681
  for (i = 0; i < num_archivable_static_fields; ) {
51429
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   682
    ArchivableStaticFieldInfo* info = &archivable_static_fields[i];
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   683
    const char* klass_name = info->klass_name;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   684
    start_recording_subgraph(info->klass, klass_name);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   685
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   686
    // If you have specified consecutive fields of the same klass in
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   687
    // archivable_static_fields[], these will be archived in the same
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   688
    // {start_recording_subgraph ... done_recording_subgraph} pass to
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   689
    // save time.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   690
    for (; i < num_archivable_static_fields; i++) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   691
      ArchivableStaticFieldInfo* f = &archivable_static_fields[i];
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   692
      if (f->klass_name != klass_name) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   693
        break;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   694
      }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   695
      archive_reachable_objects_from_static_field(f->klass, f->klass_name,
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   696
                                                  f->offset, f->field_name, CHECK);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   697
    }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   698
    done_recording_subgraph(info->klass, klass_name);
51429
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   699
  }
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   700
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   701
  log_info(cds, heap)("Performed subgraph records = %d times", _num_total_subgraph_recordings);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   702
  log_info(cds, heap)("Walked %d objects", _num_total_walked_objs);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   703
  log_info(cds, heap)("Archived %d objects", _num_total_archived_objs);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   704
  log_info(cds, heap)("Recorded %d klasses", _num_total_recorded_klasses);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   705
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   706
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   707
#ifndef PRODUCT
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   708
  for (int i = 0; i < num_archivable_static_fields; i++) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   709
    ArchivableStaticFieldInfo* f = &archivable_static_fields[i];
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   710
    verify_subgraph_from_static_field(f->klass, f->offset);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   711
  }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   712
  log_info(cds, heap)("Verified %d references", _num_total_verifications);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   713
#endif
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   714
}
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   715
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   716
// At dump-time, find the location of all the non-null oop pointers in an archived heap
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   717
// region. This way we can quickly relocate all the pointers without using
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   718
// BasicOopIterateClosure at runtime.
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   719
class FindEmbeddedNonNullPointers: public BasicOopIterateClosure {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   720
  narrowOop* _start;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   721
  BitMap *_oopmap;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   722
  int _num_total_oops;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   723
  int _num_null_oops;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   724
 public:
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   725
  FindEmbeddedNonNullPointers(narrowOop* start, BitMap* oopmap)
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   726
    : _start(start), _oopmap(oopmap), _num_total_oops(0),  _num_null_oops(0) {}
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   727
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   728
  virtual bool should_verify_oops(void) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   729
    return false;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   730
  }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   731
  virtual void do_oop(narrowOop* p) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   732
    _num_total_oops ++;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   733
    narrowOop v = *p;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   734
    if (!CompressedOops::is_null(v)) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   735
      size_t idx = p - _start;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   736
      _oopmap->set_bit(idx);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   737
    } else {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   738
      _num_null_oops ++;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   739
    }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   740
  }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   741
  virtual void do_oop(oop *p) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   742
    ShouldNotReachHere();
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   743
  }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   744
  int num_total_oops() const { return _num_total_oops; }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   745
  int num_null_oops()  const { return _num_null_oops; }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   746
};
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   747
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   748
ResourceBitMap HeapShared::calculate_oopmap(MemRegion region) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   749
  assert(UseCompressedOops, "must be");
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   750
  size_t num_bits = region.byte_size() / sizeof(narrowOop);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   751
  ResourceBitMap oopmap(num_bits);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   752
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   753
  HeapWord* p   = region.start();
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   754
  HeapWord* end = region.end();
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   755
  FindEmbeddedNonNullPointers finder((narrowOop*)p, &oopmap);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   756
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   757
  int num_objs = 0;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   758
  while (p < end) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   759
    oop o = (oop)p;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   760
    o->oop_iterate(&finder);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   761
    p += o->size();
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   762
    ++ num_objs;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   763
  }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   764
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   765
  log_info(cds, heap)("calculate_oopmap: objects = %6d, embedded oops = %7d, nulls = %7d",
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   766
                      num_objs, finder.num_total_oops(), finder.num_null_oops());
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   767
  return oopmap;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   768
}
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   769
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   770
void HeapShared::init_narrow_oop_decoding(address base, int shift) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   771
  _narrow_oop_base = base;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   772
  _narrow_oop_shift = shift;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   773
}
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   774
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   775
// Patch all the embedded oop pointers inside an archived heap region,
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   776
// to be consistent with the runtime oop encoding.
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   777
class PatchEmbeddedPointers: public BitMapClosure {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   778
  narrowOop* _start;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   779
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   780
 public:
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   781
  PatchEmbeddedPointers(narrowOop* start) : _start(start) {}
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   782
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   783
  bool do_bit(size_t offset) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   784
    narrowOop* p = _start + offset;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   785
    narrowOop v = *p;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   786
    assert(!CompressedOops::is_null(v), "null oops should have been filtered out at dump time");
51720
b7bfd64e43a6 8210523: runtime/appcds/cacheObject/DifferentHeapSizes.java crash
iklam
parents: 51701
diff changeset
   787
    oop o = HeapShared::decode_from_archive(v);
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   788
    RawAccess<IS_NOT_NULL>::oop_store(p, o);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   789
    return true;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   790
  }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   791
};
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   792
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   793
void HeapShared::patch_archived_heap_embedded_pointers(MemRegion region, address oopmap,
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   794
                                                       size_t oopmap_size_in_bits) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   795
  BitMapView bm((BitMap::bm_word_t*)oopmap, oopmap_size_in_bits);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   796
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   797
#ifndef PRODUCT
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   798
  ResourceMark rm;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   799
  ResourceBitMap checkBm = calculate_oopmap(region);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   800
  assert(bm.is_same(checkBm), "sanity");
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   801
#endif
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   802
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   803
  PatchEmbeddedPointers patcher((narrowOop*)region.start());
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   804
  bm.iterate(&patcher);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   805
}
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   806
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   807
#endif // INCLUDE_CDS_JAVA_HEAP