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