src/hotspot/share/memory/heapShared.cpp
author iklam
Wed, 17 Oct 2018 15:57:10 -0700
changeset 52319 625f6c742392
parent 52062 8dbf1a13af49
child 52402 72d4e10305b9
permissions -rw-r--r--
8212200: assert when shared java.lang.Object is redefined by JVMTI agent Reviewed-by: dholmes, jiangli, hseigel, lfoltan, sspitsyn
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"
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    27
#include "classfile/stringTable.hpp"
51429
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
    28
#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
    29
#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
    30
#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
    31
#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
    32
#include "logging/logStream.hpp"
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    33
#include "memory/filemap.hpp"
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
    34
#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
    35
#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
    36
#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
    37
#include "memory/metaspaceClosure.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 "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
    39
#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
    40
#include "oops/oop.inline.hpp"
51467
12997ebbc0d8 8209647: constantPoolHandle::constantPoolHandle(ConstantPool*) when precompiled header is disabled
iklam
parents: 51429
diff changeset
    41
#include "runtime/fieldDescriptor.inline.hpp"
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    42
#include "runtime/safepointVerifiers.hpp"
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
    43
#include "utilities/bitMap.inline.hpp"
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    44
#if INCLUDE_G1GC
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    45
#include "gc/g1/g1CollectedHeap.hpp"
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    46
#endif
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    47
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
    48
#if INCLUDE_CDS_JAVA_HEAP
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    49
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    50
bool HeapShared::_open_archive_heap_region_mapped = false;
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    51
bool HeapShared::_archive_heap_region_fixed = false;
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    52
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
    53
address   HeapShared::_narrow_oop_base;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
    54
int       HeapShared::_narrow_oop_shift;
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    55
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    56
////////////////////////////////////////////////////////////////
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    57
//
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    58
// Java heap object archiving support
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    59
//
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    60
////////////////////////////////////////////////////////////////
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    61
void HeapShared::fixup_mapped_heap_regions() {
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    62
  FileMapInfo *mapinfo = FileMapInfo::current_info();
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    63
  mapinfo->fixup_mapped_heap_regions();
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    64
  set_archive_heap_region_fixed();
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    65
}
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    66
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    67
unsigned HeapShared::oop_hash(oop const& p) {
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    68
  assert(!p->mark()->has_bias_pattern(),
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    69
         "this object should never have been locked");  // so identity_hash won't safepoin
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    70
  unsigned hash = (unsigned)p->identity_hash();
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    71
  return hash;
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    72
}
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    73
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    74
HeapShared::ArchivedObjectCache* HeapShared::_archived_object_cache = NULL;
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    75
oop HeapShared::find_archived_heap_object(oop obj) {
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    76
  assert(DumpSharedSpaces, "dump-time only");
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    77
  ArchivedObjectCache* cache = archived_object_cache();
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    78
  oop* p = cache->get(obj);
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    79
  if (p != NULL) {
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    80
    return *p;
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    81
  } else {
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    82
    return NULL;
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    83
  }
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    84
}
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    85
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    86
oop HeapShared::archive_heap_object(oop obj, Thread* THREAD) {
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    87
  assert(DumpSharedSpaces, "dump-time only");
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    88
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    89
  oop ao = find_archived_heap_object(obj);
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    90
  if (ao != NULL) {
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    91
    // already archived
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    92
    return ao;
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    93
  }
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    94
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    95
  int len = obj->size();
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    96
  if (G1CollectedHeap::heap()->is_archive_alloc_too_large(len)) {
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    97
    log_debug(cds, heap)("Cannot archive, object (" PTR_FORMAT ") is too large: " SIZE_FORMAT,
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    98
                         p2i(obj), (size_t)obj->size());
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
    99
    return NULL;
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   100
  }
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   101
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   102
  // Pre-compute object identity hash at CDS dump time.
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   103
  obj->identity_hash();
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   104
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   105
  oop archived_oop = (oop)G1CollectedHeap::heap()->archive_mem_allocate(len);
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   106
  if (archived_oop != NULL) {
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   107
    Copy::aligned_disjoint_words((HeapWord*)obj, (HeapWord*)archived_oop, len);
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   108
    MetaspaceShared::relocate_klass_ptr(archived_oop);
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   109
    ArchivedObjectCache* cache = archived_object_cache();
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   110
    cache->put(obj, archived_oop);
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   111
    log_debug(cds, heap)("Archived heap object " PTR_FORMAT " ==> " PTR_FORMAT,
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   112
                         p2i(obj), p2i(archived_oop));
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   113
  } else {
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   114
    log_error(cds, heap)(
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   115
      "Cannot allocate space for object " PTR_FORMAT " in archived heap region",
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   116
      p2i(obj));
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   117
    vm_exit(1);
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   118
  }
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   119
  return archived_oop;
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   120
}
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   121
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   122
oop HeapShared::materialize_archived_object(narrowOop v) {
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   123
  assert(archive_heap_region_fixed(),
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   124
         "must be called after archive heap regions are fixed");
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   125
  if (!CompressedOops::is_null(v)) {
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   126
    oop obj = HeapShared::decode_from_archive(v);
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   127
    return G1CollectedHeap::heap()->materialize_archived_object(obj);
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   128
  }
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   129
  return NULL;
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   130
}
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   131
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   132
void HeapShared::archive_klass_objects(Thread* THREAD) {
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   133
  GrowableArray<Klass*>* klasses = MetaspaceShared::collected_klasses();
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   134
  assert(klasses != NULL, "sanity");
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   135
  for (int i = 0; i < klasses->length(); i++) {
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   136
    Klass* k = klasses->at(i);
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   137
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   138
    // archive mirror object
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   139
    java_lang_Class::archive_mirror(k, CHECK);
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   140
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   141
    // archive the resolved_referenes array
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   142
    if (k->is_instance_klass()) {
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   143
      InstanceKlass* ik = InstanceKlass::cast(k);
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   144
      ik->constants()->archive_resolved_references(THREAD);
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   145
    }
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   146
  }
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   147
}
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   148
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   149
void HeapShared::archive_java_heap_objects(GrowableArray<MemRegion> *closed,
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   150
                                           GrowableArray<MemRegion> *open) {
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   151
  if (!is_heap_object_archiving_allowed()) {
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   152
    if (log_is_enabled(Info, cds)) {
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   153
      log_info(cds)(
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   154
        "Archived java heap is not supported as UseG1GC, "
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   155
        "UseCompressedOops and UseCompressedClassPointers are required."
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   156
        "Current settings: UseG1GC=%s, UseCompressedOops=%s, UseCompressedClassPointers=%s.",
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   157
        BOOL_TO_STR(UseG1GC), BOOL_TO_STR(UseCompressedOops),
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   158
        BOOL_TO_STR(UseCompressedClassPointers));
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   159
    }
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   160
    return;
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   161
  }
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   162
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   163
  {
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   164
    NoSafepointVerifier nsv;
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   165
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   166
    // Cache for recording where the archived objects are copied to
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   167
    create_archived_object_cache();
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   168
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   169
    tty->print_cr("Dumping objects to closed archive heap region ...");
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   170
    NOT_PRODUCT(StringTable::verify());
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   171
    copy_closed_archive_heap_objects(closed);
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   172
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   173
    tty->print_cr("Dumping objects to open archive heap region ...");
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   174
    copy_open_archive_heap_objects(open);
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   175
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   176
    destroy_archived_object_cache();
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   177
  }
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   178
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   179
  G1HeapVerifier::verify_archive_regions();
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   180
}
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   181
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   182
void HeapShared::copy_closed_archive_heap_objects(
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   183
                                    GrowableArray<MemRegion> * closed_archive) {
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   184
  assert(is_heap_object_archiving_allowed(), "Cannot archive java heap objects");
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   185
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   186
  Thread* THREAD = Thread::current();
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   187
  G1CollectedHeap::heap()->begin_archive_alloc_range();
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   188
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   189
  // Archive interned string objects
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   190
  StringTable::write_to_archive();
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   191
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   192
  G1CollectedHeap::heap()->end_archive_alloc_range(closed_archive,
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   193
                                                   os::vm_allocation_granularity());
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   194
}
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   195
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   196
void HeapShared::copy_open_archive_heap_objects(
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   197
                                    GrowableArray<MemRegion> * open_archive) {
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   198
  assert(is_heap_object_archiving_allowed(), "Cannot archive java heap objects");
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   199
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   200
  Thread* THREAD = Thread::current();
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   201
  G1CollectedHeap::heap()->begin_archive_alloc_range(true /* open */);
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   202
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   203
  java_lang_Class::archive_basic_type_mirrors(THREAD);
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   204
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   205
  archive_klass_objects(THREAD);
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   206
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   207
  archive_object_subgraphs(THREAD);
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   208
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   209
  G1CollectedHeap::heap()->end_archive_alloc_range(open_archive,
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   210
                                                   os::vm_allocation_granularity());
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   211
}
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   212
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   213
void HeapShared::init_narrow_oop_decoding(address base, int shift) {
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   214
  _narrow_oop_base = base;
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   215
  _narrow_oop_shift = shift;
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   216
}
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   217
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   218
//
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   219
// Subgraph archiving support
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   220
//
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   221
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
   222
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
   223
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   224
// 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
   225
// 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
   226
// 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
   227
KlassSubGraphInfo* HeapShared::get_subgraph_info(Klass* k) {
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   228
  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
   229
  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
   230
  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
   231
  if (info == NULL) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   232
    _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
   233
    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
   234
    ++ _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
   235
  }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   236
  return info;
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   237
}
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   238
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   239
// 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
   240
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
   241
  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
   242
  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
   243
    _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
   244
      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
   245
  }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   246
  _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
   247
  _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
   248
}
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   249
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   250
// 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
   251
// 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
   252
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
   253
  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
   254
  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
   255
         "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
   256
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   257
  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
   258
    _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
   259
      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
   260
  }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   261
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   262
  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
   263
3ab8b84e93cd 8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents: 50951
diff changeset
   264
  if (_k == relocated_k) {
3ab8b84e93cd 8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents: 50951
diff changeset
   265
    // 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
   266
    // initialization list.
3ab8b84e93cd 8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents: 50951
diff changeset
   267
    return;
3ab8b84e93cd 8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents: 50951
diff changeset
   268
  }
3ab8b84e93cd 8207263: Store the Configuration for system modules into CDS archive.
jiangli
parents: 50951
diff changeset
   269
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   270
  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
   271
    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
   272
          "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
   273
    // 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
   274
    // 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
   275
    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
   276
        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
   277
      // 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
   278
      // 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
   279
      return;
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   280
    }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   281
  } 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
   282
    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
   283
    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
   284
      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
   285
            "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
   286
    }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   287
    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
   288
      // 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
   289
      // 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
   290
      return;
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   291
    }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   292
  } else {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   293
    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
   294
    // 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
   295
    return;
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   296
  }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   297
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   298
  if (log_is_enabled(Debug, cds, heap)) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   299
    if (!_subgraph_object_klasses->contains(relocated_k)) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   300
      ResourceMark rm;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   301
      log_debug(cds, heap)("Adding klass %s", orig_k->external_name());
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   302
    }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   303
  }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   304
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   305
  _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
   306
}
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   307
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   308
// 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
   309
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
   310
  _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
   311
  _entry_field_records = NULL;
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   312
  _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
   313
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   314
  // 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
   315
  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
   316
  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
   317
    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
   318
    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
   319
    _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
   320
      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
   321
    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
   322
      _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
   323
    }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   324
  }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   325
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   326
  // the Klasses of the objects in the sub-graphs
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   327
  GrowableArray<Klass*>* subgraph_object_klasses = info->subgraph_object_klasses();
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   328
  if (subgraph_object_klasses != NULL) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   329
    int num_subgraphs_klasses = subgraph_object_klasses->length();
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   330
    _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
   331
      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
   332
    for (int i = 0; i < num_subgraphs_klasses; i++) {
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   333
      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
   334
      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
   335
        ResourceMark rm;
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   336
        log_info(cds, heap)(
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   337
          "Archived object klass %s (%2d) => %s",
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   338
          _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
   339
      }
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   340
      _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
   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
}
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   344
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   345
struct CopyKlassSubGraphInfoToArchive : StackObj {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   346
  CompactHashtableWriter* _writer;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   347
  CopyKlassSubGraphInfoToArchive(CompactHashtableWriter* writer) : _writer(writer) {}
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   348
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   349
  bool do_entry(Klass* klass, KlassSubGraphInfo& info) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   350
    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
   351
      ArchivedKlassSubGraphInfoRecord* record =
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   352
        (ArchivedKlassSubGraphInfoRecord*)MetaspaceShared::read_only_space_alloc(sizeof(ArchivedKlassSubGraphInfoRecord));
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   353
      record->init(&info);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   354
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   355
      unsigned int hash = primitive_hash<Klass*>(klass);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   356
      uintx deltax = MetaspaceShared::object_delta(record);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   357
      guarantee(deltax <= MAX_SHARED_DELTA, "must not be");
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   358
      u4 delta = u4(deltax);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   359
      _writer->add(hash, delta);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   360
    }
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   361
    return true; // keep on iterating
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   362
  }
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   363
};
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   364
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   365
// 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
   366
// - 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
   367
//   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
   368
//   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
   369
//   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
   370
// - 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
   371
//   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
   372
void HeapShared::write_subgraph_info_table() {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   373
  // 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
   374
  DumpTimeKlassSubGraphInfoTable* d_table = _dump_time_subgraph_info_table;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   375
  CompactHashtableStats stats;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   376
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   377
  _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
   378
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   379
  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
   380
  CompactHashtableWriter writer(num_buckets, &stats);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   381
  CopyKlassSubGraphInfoToArchive copy(&writer);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   382
  _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
   383
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   384
  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
   385
}
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   386
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   387
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
   388
  _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
   389
}
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   390
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   391
void HeapShared::initialize_from_archived_subgraph(Klass* k) {
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   392
  if (!open_archive_heap_region_mapped()) {
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   393
    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
   394
  }
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   395
  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
   396
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   397
  unsigned int hash = primitive_hash<Klass*>(k);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   398
  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
   399
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   400
  // Initialize from archived data. Currently this is done only
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   401
  // 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
   402
  if (record != NULL) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   403
    Thread* THREAD = Thread::current();
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   404
    if (log_is_enabled(Info, cds, heap)) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   405
      ResourceMark rm;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   406
      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
   407
                          k->external_name());
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   408
    }
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   409
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   410
    int i;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   411
    // 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
   412
    // NULL class loader is used.
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   413
    Array<Klass*>* klasses = record->subgraph_object_klasses();
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   414
    if (klasses != NULL) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   415
      for (i = 0; i < klasses->length(); i++) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   416
        Klass* obj_k = klasses->at(i);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   417
        Klass* resolved_k = SystemDictionary::resolve_or_null(
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   418
                                              (obj_k)->name(), THREAD);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   419
        if (resolved_k != obj_k) {
52319
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52062
diff changeset
   420
          assert(!SystemDictionary::is_well_known_klass(resolved_k),
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52062
diff changeset
   421
                 "shared well-known classes must not be replaced by JVMTI ClassFileLoadHook");
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52062
diff changeset
   422
          ResourceMark rm(THREAD);
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52062
diff changeset
   423
          log_info(cds, heap)("Failed to load subgraph because %s was not loaded from archive",
625f6c742392 8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents: 52062
diff changeset
   424
                              resolved_k->external_name());
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   425
          return;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   426
        }
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   427
        if ((obj_k)->is_instance_klass()) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   428
          InstanceKlass* ik = InstanceKlass::cast(obj_k);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   429
          ik->initialize(THREAD);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   430
        } else if ((obj_k)->is_objArray_klass()) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   431
          ObjArrayKlass* oak = ObjArrayKlass::cast(obj_k);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   432
          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
   433
        }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   434
      }
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   435
    }
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   436
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   437
    if (HAS_PENDING_EXCEPTION) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   438
      CLEAR_PENDING_EXCEPTION;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   439
      // 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
   440
      // 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
   441
      // subgraphs referenced from k in this case.
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   442
      return;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   443
    }
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   444
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   445
    // 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
   446
    // the corresponding fields within the mirror.
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   447
    oop m = k->java_mirror();
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   448
    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
   449
    if (entry_field_records != NULL) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   450
      int efr_len = entry_field_records->length();
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   451
      assert(efr_len % 2 == 0, "sanity");
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   452
      for (i = 0; i < efr_len;) {
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   453
        int field_offset = entry_field_records->at(i);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   454
        // 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
   455
        // 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
   456
        // also 'known' by GC.
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   457
        oop v = materialize_archived_object(entry_field_records->at(i+1));
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   458
        m->obj_field_put(field_offset, v);
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   459
        i += 2;
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   460
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   461
        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
   462
      }
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   463
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51796
diff changeset
   464
    // 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
   465
    // 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
   466
    }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   467
  }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   468
}
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   469
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   470
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
   471
  int _level;
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   472
  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
   473
  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
   474
  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
   475
  oop _archived_referencing_obj;
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   476
  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
   477
 public:
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   478
  WalkOopAndArchiveClosure(int level, bool record_klasses_only,
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   479
                           KlassSubGraphInfo* subgraph_info,
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   480
                           oop orig, oop archived, TRAPS) :
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   481
    _level(level), _record_klasses_only(record_klasses_only),
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   482
    _subgraph_info(subgraph_info),
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   483
    _orig_referencing_obj(orig), _archived_referencing_obj(archived),
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   484
    _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
   485
  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
   486
  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
   487
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   488
 protected:
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   489
  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
   490
    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
   491
    if (!CompressedOops::is_null(obj)) {
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   492
      assert(!HeapShared::is_archived_object(obj),
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   493
             "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
   494
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   495
      size_t field_delta = pointer_delta(p, _orig_referencing_obj, sizeof(char));
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   496
      T* new_p = (T*)(address(_archived_referencing_obj) + field_delta);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   497
      Thread* THREAD = _thread;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   498
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   499
      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
   500
        ResourceMark rm;
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   501
        log_debug(cds, heap)("(%d) %s[" SIZE_FORMAT "] ==> " PTR_FORMAT " size %d %s", _level,
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   502
                             _orig_referencing_obj->klass()->external_name(), field_delta,
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   503
                             p2i(obj), obj->size() * HeapWordSize, obj->klass()->external_name());
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   504
        LogTarget(Trace, cds, heap) log;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   505
        LogStream out(log);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   506
        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
   507
      }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   508
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   509
      oop archived = HeapShared::archive_reachable_objects_from(_level + 1, _subgraph_info, obj, THREAD);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   510
      assert(archived != NULL, "VM should have exited with unarchivable objects for _level > 1");
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   511
      assert(HeapShared::is_archived_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
   512
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   513
      if (!_record_klasses_only) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   514
        // Update the reference in the archived copy of the referencing object.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   515
        log_debug(cds, heap)("(%d) updating oop @[" PTR_FORMAT "] " PTR_FORMAT " ==> " PTR_FORMAT,
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   516
                             _level, p2i(new_p), p2i(obj), p2i(archived));
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   517
        RawAccess<IS_NOT_NULL>::oop_store(new_p, archived);
51425
4e9667589c43 8209389: SIGSEGV in WalkOopAndArchiveClosure::do_oop_work.
jiangli
parents: 51388
diff changeset
   518
      }
50951
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
  }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   521
};
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   522
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   523
// (1) If orig_obj has not been archived yet, archive it.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   524
// (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
   525
//     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
   526
// (3) Record the klasses of all orig_obj and all reachable objects.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   527
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
   528
  assert(orig_obj != NULL, "must be");
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   529
  assert(!is_archived_object(orig_obj), "sanity");
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   530
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   531
  // java.lang.Class instances cannot be included in an archived
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   532
  // object sub-graph.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   533
  if (java_lang_Class::is_instance(orig_obj)) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   534
    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
   535
    vm_exit(1);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   536
  }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   537
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   538
  oop archived_obj = find_archived_heap_object(orig_obj);
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   539
  if (java_lang_String::is_instance(orig_obj) && archived_obj != NULL) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   540
    // To save time, don't walk strings that are already archived. They just contain
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   541
    // pointers to a type array, whose klass doesn't need to be recorded.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   542
    return archived_obj;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   543
  }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   544
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   545
  if (has_been_seen_during_subgraph_recording(orig_obj)) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   546
    // orig_obj has already been archived and traced. Nothing more to do.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   547
    return archived_obj;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   548
  } else {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   549
    set_has_been_seen_during_subgraph_recording(orig_obj);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   550
  }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   551
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   552
  bool record_klasses_only = (archived_obj != NULL);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   553
  if (archived_obj == NULL) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   554
    ++_num_new_archived_objs;
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   555
    archived_obj = archive_heap_object(orig_obj, THREAD);
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   556
    if (archived_obj == NULL) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   557
      // Skip archiving the sub-graph referenced from the current entry field.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   558
      ResourceMark rm;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   559
      log_error(cds, heap)(
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   560
        "Cannot archive the sub-graph referenced from %s object ("
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   561
        PTR_FORMAT ") size %d, skipped.",
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   562
        orig_obj->klass()->external_name(), p2i(orig_obj), orig_obj->size() * HeapWordSize);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   563
      if (level == 1) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   564
        // 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
   565
        // as the Java code will take care of initializing this field dynamically.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   566
        return NULL;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   567
      } else {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   568
        // 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
   569
        // 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
   570
        // we have a real use case.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   571
        vm_exit(1);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   572
      }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   573
    }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   574
  }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   575
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   576
  assert(archived_obj != NULL, "must be");
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   577
  Klass *orig_k = orig_obj->klass();
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   578
  Klass *relocated_k = archived_obj->klass();
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   579
  subgraph_info->add_subgraph_object_klass(orig_k, relocated_k);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   580
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   581
  WalkOopAndArchiveClosure walker(level, record_klasses_only, subgraph_info, orig_obj, archived_obj, THREAD);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   582
  orig_obj->oop_iterate(&walker);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   583
  return archived_obj;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   584
}
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   585
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   586
//
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   587
// 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
   588
// 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
   589
// or indirectly from the starting object by following references.
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   590
// 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
   591
//
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   592
// - 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
   593
//   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
   594
// - 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
   595
//   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
   596
//
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   597
// 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
   598
// WalkOopAndArchiveClosure):
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   599
//
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   600
// 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
   601
// 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
   602
// 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
   603
// 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
   604
//
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   605
// 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
   606
// 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
   607
// 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
   608
// 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
   609
//
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   610
// 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
   611
// 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
   612
//
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   613
// 4) Updates the pointer in the archived copy of referencing object to
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   614
// 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
   615
//
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   616
// 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
   617
// 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
   618
// 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
   619
//
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   620
void HeapShared::archive_reachable_objects_from_static_field(InstanceKlass *k,
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   621
                                                             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
   622
                                                             int field_offset,
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   623
                                                             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
   624
                                                             TRAPS) {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   625
  assert(DumpSharedSpaces, "dump time only");
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   626
  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
   627
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   628
  oop m = k->java_mirror();
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   629
  oop archived_m = find_archived_heap_object(m);
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   630
  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
   631
    return;
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   632
  }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   633
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   634
  KlassSubGraphInfo* subgraph_info = get_subgraph_info(k);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   635
  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
   636
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   637
  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
   638
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   639
  if (!CompressedOops::is_null(f)) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   640
    if (log_is_enabled(Trace, cds, heap)) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   641
      LogTarget(Trace, cds, heap) log;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   642
      LogStream out(log);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   643
      f->print_on(&out);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   644
    }
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   645
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   646
    oop af = archive_reachable_objects_from(1, subgraph_info, f, CHECK);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   647
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   648
    if (af == NULL) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   649
      log_error(cds, heap)("Archiving failed %s::%s (some reachable objects cannot be archived)",
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   650
                           klass_name, field_name);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   651
    } else {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   652
      // 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
   653
      // 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
   654
      // 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
   655
      subgraph_info->add_subgraph_entry_field(field_offset, af);
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   656
      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
   657
    }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   658
  } else {
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   659
    // The field contains null, we still need to record the entry point,
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   660
    // so it can be restored at runtime.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   661
    subgraph_info->add_subgraph_entry_field(field_offset, NULL);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   662
  }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   663
}
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   664
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   665
#ifndef PRODUCT
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   666
class VerifySharedOopClosure: public BasicOopIterateClosure {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   667
 private:
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   668
  bool _is_archived;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   669
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   670
 public:
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   671
  VerifySharedOopClosure(bool is_archived) : _is_archived(is_archived) {}
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   672
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   673
  void do_oop(narrowOop *p) { VerifySharedOopClosure::do_oop_work(p); }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   674
  void do_oop(      oop *p) { VerifySharedOopClosure::do_oop_work(p); }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   675
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   676
 protected:
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   677
  template <class T> void do_oop_work(T *p) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   678
    oop obj = RawAccess<>::oop_load(p);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   679
    if (!CompressedOops::is_null(obj)) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   680
      HeapShared::verify_reachable_objects_from(obj, _is_archived);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   681
    }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   682
  }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   683
};
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   684
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   685
void HeapShared::verify_subgraph_from_static_field(InstanceKlass* k, int field_offset) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   686
  assert(DumpSharedSpaces, "dump time only");
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   687
  assert(k->is_shared_boot_class(), "must be boot class");
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   688
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   689
  oop m = k->java_mirror();
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   690
  oop archived_m = find_archived_heap_object(m);
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   691
  if (CompressedOops::is_null(archived_m)) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   692
    return;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   693
  }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   694
  oop f = m->obj_field(field_offset);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   695
  if (!CompressedOops::is_null(f)) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   696
    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
   697
  }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   698
}
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   699
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   700
void HeapShared::verify_subgraph_from(oop orig_obj) {
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   701
  oop archived_obj = find_archived_heap_object(orig_obj);
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   702
  if (archived_obj == NULL) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   703
    // 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
   704
    // archive_reachable_objects_from().
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   705
    return;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   706
  }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   707
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   708
  // Verify that all objects reachable from orig_obj are archived.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   709
  init_seen_objects_table();
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   710
  verify_reachable_objects_from(orig_obj, false);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   711
  delete_seen_objects_table();
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   712
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   713
  // Note: we could also verify that all objects reachable from the archived
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   714
  // copy of orig_obj can only point to archived objects, with:
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   715
  //      init_seen_objects_table();
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   716
  //      verify_reachable_objects_from(archived_obj, true);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   717
  //      init_seen_objects_table();
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   718
  // but that's already done in G1HeapVerifier::verify_archive_regions so we
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   719
  // won't do it here.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   720
}
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   721
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   722
void HeapShared::verify_reachable_objects_from(oop obj, bool is_archived) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   723
  _num_total_verifications ++;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   724
  if (!has_been_seen_during_subgraph_recording(obj)) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   725
    set_has_been_seen_during_subgraph_recording(obj);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   726
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   727
    if (is_archived) {
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   728
      assert(is_archived_object(obj), "must be");
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   729
      assert(find_archived_heap_object(obj) == NULL, "must be");
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   730
    } else {
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   731
      assert(!is_archived_object(obj), "must be");
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   732
      assert(find_archived_heap_object(obj) != NULL, "must be");
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   733
    }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   734
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   735
    VerifySharedOopClosure walker(is_archived);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   736
    obj->oop_iterate(&walker);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   737
  }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   738
}
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   739
#endif
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   740
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   741
HeapShared::SeenObjectsTable* HeapShared::_seen_objects_table = NULL;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   742
int HeapShared::_num_new_walked_objs;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   743
int HeapShared::_num_new_archived_objs;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   744
int HeapShared::_num_old_recorded_klasses;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   745
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   746
int HeapShared::_num_total_subgraph_recordings = 0;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   747
int HeapShared::_num_total_walked_objs = 0;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   748
int HeapShared::_num_total_archived_objs = 0;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   749
int HeapShared::_num_total_recorded_klasses = 0;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   750
int HeapShared::_num_total_verifications = 0;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   751
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   752
bool HeapShared::has_been_seen_during_subgraph_recording(oop obj) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   753
  return _seen_objects_table->get(obj) != NULL;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   754
}
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   755
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   756
void HeapShared::set_has_been_seen_during_subgraph_recording(oop obj) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   757
  assert(!has_been_seen_during_subgraph_recording(obj), "sanity");
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   758
  _seen_objects_table->put(obj, true);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   759
  ++ _num_new_walked_objs;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   760
}
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   761
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   762
void HeapShared::start_recording_subgraph(InstanceKlass *k, const char* class_name) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   763
  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
   764
  init_seen_objects_table();
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   765
  _num_new_walked_objs = 0;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   766
  _num_new_archived_objs = 0;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   767
  _num_old_recorded_klasses = get_subgraph_info(k)->num_subgraph_object_klasses();
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   768
}
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   769
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   770
void HeapShared::done_recording_subgraph(InstanceKlass *k, const char* class_name) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   771
  int num_new_recorded_klasses = get_subgraph_info(k)->num_subgraph_object_klasses() -
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   772
    _num_old_recorded_klasses;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   773
  log_info(cds, heap)("Done recording subgraph(s) for archived fields in %s: "
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   774
                      "walked %d objs, archived %d new objs, recorded %d classes",
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   775
                      class_name, _num_new_walked_objs, _num_new_archived_objs,
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   776
                      num_new_recorded_klasses);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   777
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   778
  delete_seen_objects_table();
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   779
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   780
  _num_total_subgraph_recordings ++;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   781
  _num_total_walked_objs      += _num_new_walked_objs;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   782
  _num_total_archived_objs    += _num_new_archived_objs;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   783
  _num_total_recorded_klasses +=  num_new_recorded_klasses;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   784
}
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   785
51429
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   786
struct ArchivableStaticFieldInfo {
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   787
  const char* klass_name;
51429
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   788
  const char* field_name;
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   789
  InstanceKlass* klass;
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   790
  int offset;
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   791
  BasicType type;
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   792
};
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   793
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   794
// 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
   795
static ArchivableStaticFieldInfo archivable_static_fields[] = {
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   796
  {"jdk/internal/module/ArchivedModuleGraph",  "archivedSystemModules"},
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   797
  {"jdk/internal/module/ArchivedModuleGraph",  "archivedModuleFinder"},
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   798
  {"jdk/internal/module/ArchivedModuleGraph",  "archivedMainModule"},
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   799
  {"jdk/internal/module/ArchivedModuleGraph",  "archivedConfiguration"},
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   800
  {"java/util/ImmutableCollections$ListN",     "EMPTY_LIST"},
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   801
  {"java/util/ImmutableCollections$MapN",      "EMPTY_MAP"},
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   802
  {"java/util/ImmutableCollections$SetN",      "EMPTY_SET"},
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   803
  {"java/lang/Integer$IntegerCache",           "archivedCache"},
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   804
  {"java/lang/module/Configuration",           "EMPTY_CONFIGURATION"},
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   805
};
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   806
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   807
const static int num_archivable_static_fields =
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   808
  sizeof(archivable_static_fields) / sizeof(ArchivableStaticFieldInfo);
51429
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   809
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   810
class ArchivableStaticFieldFinder: public FieldClosure {
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   811
  InstanceKlass* _ik;
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   812
  Symbol* _field_name;
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   813
  bool _found;
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   814
  int _offset;
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   815
public:
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   816
  ArchivableStaticFieldFinder(InstanceKlass* ik, Symbol* field_name) :
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   817
    _ik(ik), _field_name(field_name), _found(false), _offset(-1) {}
51429
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   818
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   819
  virtual void do_field(fieldDescriptor* fd) {
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   820
    if (fd->name() == _field_name) {
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   821
      assert(!_found, "fields cannot be overloaded");
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   822
      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
   823
      _found = true;
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   824
      _offset = fd->offset();
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   825
    }
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   826
  }
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   827
  bool found()     { return _found;  }
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   828
  int offset()     { return _offset; }
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   829
};
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   830
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   831
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
   832
  _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
   833
51429
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   834
  for (int i = 0; i < num_archivable_static_fields; i++) {
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   835
    ArchivableStaticFieldInfo* info = &archivable_static_fields[i];
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   836
    TempNewSymbol klass_name =  SymbolTable::new_symbol(info->klass_name, THREAD);
51429
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   837
    TempNewSymbol field_name =  SymbolTable::new_symbol(info->field_name, THREAD);
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   838
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   839
    Klass* k = SystemDictionary::resolve_or_null(klass_name, THREAD);
51429
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   840
    assert(k != NULL && !HAS_PENDING_EXCEPTION, "class must exist");
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   841
    InstanceKlass* ik = InstanceKlass::cast(k);
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   842
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   843
    ArchivableStaticFieldFinder finder(ik, field_name);
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   844
    ik->do_local_static_fields(&finder);
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   845
    assert(finder.found(), "field must exist");
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   846
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   847
    info->klass = ik;
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   848
    info->offset = finder.offset();
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   849
  }
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   850
}
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   851
52062
8dbf1a13af49 8206009: Move CDS java heap object archiving code to heapShared.hpp and heapShared.cpp
jiangli
parents: 52047
diff changeset
   852
void HeapShared::archive_object_subgraphs(Thread* THREAD) {
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   853
  // For each class X that has one or more archived fields:
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   854
  // [1] Dump the subgraph of each archived field
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   855
  // [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
   856
  //     by any of these static fields.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   857
  //     At runtime, these classes are initialized before X's archived fields
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   858
  //     are restored by HeapShared::initialize_from_archived_subgraph().
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   859
  int i;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   860
  for (i = 0; i < num_archivable_static_fields; ) {
51429
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   861
    ArchivableStaticFieldInfo* info = &archivable_static_fields[i];
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   862
    const char* klass_name = info->klass_name;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   863
    start_recording_subgraph(info->klass, klass_name);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   864
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   865
    // If you have specified consecutive fields of the same klass in
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   866
    // archivable_static_fields[], these will be archived in the same
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   867
    // {start_recording_subgraph ... done_recording_subgraph} pass to
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   868
    // save time.
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   869
    for (; i < num_archivable_static_fields; i++) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   870
      ArchivableStaticFieldInfo* f = &archivable_static_fields[i];
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   871
      if (f->klass_name != klass_name) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   872
        break;
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   873
      }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   874
      archive_reachable_objects_from_static_field(f->klass, f->klass_name,
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   875
                                                  f->offset, f->field_name, CHECK);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   876
    }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   877
    done_recording_subgraph(info->klass, klass_name);
51429
d9f6e3ee7fcb 8209545: Simplify HeapShared::archive_module_graph_objects
iklam
parents: 51425
diff changeset
   878
  }
51701
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   879
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   880
  log_info(cds, heap)("Performed subgraph records = %d times", _num_total_subgraph_recordings);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   881
  log_info(cds, heap)("Walked %d objects", _num_total_walked_objs);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   882
  log_info(cds, heap)("Archived %d objects", _num_total_archived_objs);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   883
  log_info(cds, heap)("Recorded %d klasses", _num_total_recorded_klasses);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   884
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   885
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   886
#ifndef PRODUCT
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   887
  for (int i = 0; i < num_archivable_static_fields; i++) {
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   888
    ArchivableStaticFieldInfo* f = &archivable_static_fields[i];
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   889
    verify_subgraph_from_static_field(f->klass, f->offset);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   890
  }
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   891
  log_info(cds, heap)("Verified %d references", _num_total_verifications);
9012aeaf993b 8210289: ArchivedKlassSubGraphInfoRecord is incomplete
iklam
parents: 51491
diff changeset
   892
#endif
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   893
}
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   894
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   895
// 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
   896
// 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
   897
// BasicOopIterateClosure at runtime.
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   898
class FindEmbeddedNonNullPointers: public BasicOopIterateClosure {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   899
  narrowOop* _start;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   900
  BitMap *_oopmap;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   901
  int _num_total_oops;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   902
  int _num_null_oops;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   903
 public:
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   904
  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
   905
    : _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
   906
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   907
  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
   908
    return false;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   909
  }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   910
  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
   911
    _num_total_oops ++;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   912
    narrowOop v = *p;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   913
    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
   914
      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
   915
      _oopmap->set_bit(idx);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   916
    } else {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   917
      _num_null_oops ++;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   918
    }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   919
  }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   920
  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
   921
    ShouldNotReachHere();
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   922
  }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   923
  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
   924
  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
   925
};
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   926
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   927
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
   928
  assert(UseCompressedOops, "must be");
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   929
  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
   930
  ResourceBitMap oopmap(num_bits);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   931
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   932
  HeapWord* p   = region.start();
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   933
  HeapWord* end = region.end();
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   934
  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
   935
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   936
  int num_objs = 0;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   937
  while (p < end) {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   938
    oop o = (oop)p;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   939
    o->oop_iterate(&finder);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   940
    p += o->size();
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   941
    ++ num_objs;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   942
  }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   943
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   944
  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
   945
                      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
   946
  return oopmap;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   947
}
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   948
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   949
// 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
   950
// 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
   951
class PatchEmbeddedPointers: public BitMapClosure {
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   952
  narrowOop* _start;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   953
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   954
 public:
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   955
  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
   956
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   957
  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
   958
    narrowOop* p = _start + offset;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   959
    narrowOop v = *p;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   960
    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
   961
    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
   962
    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
   963
    return true;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   964
  }
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   965
};
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   966
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   967
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
   968
                                                       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
   969
  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
   970
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   971
#ifndef PRODUCT
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   972
  ResourceMark rm;
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   973
  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
   974
  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
   975
#endif
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   976
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   977
  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
   978
  bm.iterate(&patcher);
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   979
}
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 51467
diff changeset
   980
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
diff changeset
   981
#endif // INCLUDE_CDS_JAVA_HEAP