hotspot/src/share/vm/memory/metaspaceShared.cpp
author iklam
Tue, 18 Aug 2015 11:27:23 -0700
changeset 34257 4be3504cc03b
parent 33638 ef49ed90010b
child 35231 e89989198037
permissions -rw-r--r--
8140802: Clean up and refactor of class loading code for CDS Reviewed-by: jiangli, acorn, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     1
/*
29697
92501504191b 8074459: Flags handling memory sizes should be of type size_t
jwilhelm
parents: 28363
diff changeset
     2
 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     4
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     8
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    13
 * accompanied this code).
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    14
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    18
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    21
 * questions.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    22
 *
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    23
 */
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    24
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    25
#include "precompiled.hpp"
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
    26
#include "classfile/classListParser.hpp"
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
    27
#include "classfile/classLoaderExt.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    28
#include "classfile/dictionary.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    29
#include "classfile/loaderConstraints.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    30
#include "classfile/placeholders.hpp"
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
    31
#include "classfile/sharedClassUtil.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    32
#include "classfile/symbolTable.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    33
#include "classfile/systemDictionary.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    34
#include "code/codeCache.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30120
diff changeset
    35
#include "gc/shared/gcLocker.hpp"
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
    36
#include "interpreter/bytecodeStream.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30120
diff changeset
    37
#include "interpreter/bytecodes.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    38
#include "memory/filemap.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    39
#include "memory/metaspace.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    40
#include "memory/metaspaceShared.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    41
#include "oops/objArrayOop.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    42
#include "oops/oop.inline.hpp"
25468
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 24424
diff changeset
    43
#include "runtime/os.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    44
#include "runtime/signature.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30120
diff changeset
    45
#include "runtime/vmThread.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    46
#include "runtime/vm_operations.hpp"
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
    47
#include "utilities/defaultStream.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    48
#include "utilities/hashtable.inline.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    49
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    50
int MetaspaceShared::_max_alignment = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    51
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    52
ReservedSpace* MetaspaceShared::_shared_rs = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    53
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
    54
MetaspaceSharedStats MetaspaceShared::_stats;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
    55
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
    56
bool MetaspaceShared::_link_classes_made_progress;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
    57
bool MetaspaceShared::_check_classes_made_progress;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
    58
bool MetaspaceShared::_has_error_classes;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
    59
bool MetaspaceShared::_archive_loading_failed = false;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    60
// Read/write a data stream for restoring/preserving metadata pointers and
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    61
// miscellaneous data from/to the shared archive file.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    62
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    63
void MetaspaceShared::serialize(SerializeClosure* soc) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    64
  int tag = 0;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    65
  soc->do_tag(--tag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    66
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    67
  // Verify the sizes of various metadata in the system.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    68
  soc->do_tag(sizeof(Method));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    69
  soc->do_tag(sizeof(ConstMethod));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    70
  soc->do_tag(arrayOopDesc::base_offset_in_bytes(T_BYTE));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    71
  soc->do_tag(sizeof(ConstantPool));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    72
  soc->do_tag(sizeof(ConstantPoolCache));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    73
  soc->do_tag(objArrayOopDesc::base_offset_in_bytes());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    74
  soc->do_tag(typeArrayOopDesc::base_offset_in_bytes(T_BYTE));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    75
  soc->do_tag(sizeof(Symbol));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    76
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    77
  // Dump/restore miscellaneous metadata.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    78
  Universe::serialize(soc, true);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    79
  soc->do_tag(--tag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    80
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    81
  // Dump/restore references to commonly used names and signatures.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    82
  vmSymbols::serialize(soc);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    83
  soc->do_tag(--tag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    84
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    85
  soc->do_tag(666);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    86
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    87
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    88
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    89
// CDS code for dumping shared archive.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    90
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    91
// Global object for holding classes that have been loaded.  Since this
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    92
// is run at a safepoint just before exit, this is the entire set of classes.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    93
static GrowableArray<Klass*>* _global_klass_objects;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    94
static void collect_classes(Klass* k) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    95
  _global_klass_objects->append_if_missing(k);
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
    96
  if (k->is_instance_klass()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    97
    // Add in the array classes too
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    98
    InstanceKlass* ik = InstanceKlass::cast(k);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    99
    ik->array_klasses_do(collect_classes);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   100
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   101
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   102
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   103
static void collect_classes2(Klass* k, ClassLoaderData* class_data) {
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   104
  collect_classes(k);
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   105
}
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   106
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   107
static void remove_unshareable_in_classes() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   108
  for (int i = 0; i < _global_klass_objects->length(); i++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   109
    Klass* k = _global_klass_objects->at(i);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   110
    k->remove_unshareable_info();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   111
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   112
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   113
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   114
static void rewrite_nofast_bytecode(Method* method) {
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   115
  RawBytecodeStream bcs(method);
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   116
  while (!bcs.is_last_bytecode()) {
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   117
    Bytecodes::Code opcode = bcs.raw_next();
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   118
    switch (opcode) {
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   119
    case Bytecodes::_getfield:      *bcs.bcp() = Bytecodes::_nofast_getfield;      break;
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   120
    case Bytecodes::_putfield:      *bcs.bcp() = Bytecodes::_nofast_putfield;      break;
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   121
    case Bytecodes::_aload_0:       *bcs.bcp() = Bytecodes::_nofast_aload_0;       break;
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   122
    case Bytecodes::_iload:         *bcs.bcp() = Bytecodes::_nofast_iload;         break;
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   123
    default: break;
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   124
    }
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   125
  }
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   126
}
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   127
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   128
// Walk all methods in the class list to ensure that they won't be modified at
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   129
// run time. This includes:
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   130
// [1] Rewrite all bytecodes as needed, so that the ConstMethod* will not be modified
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   131
//     at run time by RewriteBytecodes/RewriteFrequentPairs
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   132
// [2] Assign a fingerprint, so one doesn't need to be assigned at run-time.
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   133
static void rewrite_nofast_bytecodes_and_calculate_fingerprints() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   134
  for (int i = 0; i < _global_klass_objects->length(); i++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   135
    Klass* k = _global_klass_objects->at(i);
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
   136
    if (k->is_instance_klass()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   137
      InstanceKlass* ik = InstanceKlass::cast(k);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   138
      for (int i = 0; i < ik->methods()->length(); i++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   139
        Method* m = ik->methods()->at(i);
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   140
        rewrite_nofast_bytecode(m);
20059
c26474fd5ac0 8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents: 19319
diff changeset
   141
        Fingerprinter fp(m);
c26474fd5ac0 8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents: 19319
diff changeset
   142
        // The side effect of this call sets method's fingerprint field.
c26474fd5ac0 8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents: 19319
diff changeset
   143
        fp.fingerprint();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   144
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   145
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   146
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   147
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   148
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   149
// Patch C++ vtable pointer in metadata.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   150
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   151
// Klass and other metadata objects contain references to c++ vtables in the
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   152
// JVM library.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   153
// Fix them to point to our constructed vtables.  However, don't iterate
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   154
// across the space while doing this, as that causes the vtables to be
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   155
// patched, undoing our useful work.  Instead, iterate to make a list,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   156
// then use the list to do the fixing.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   157
//
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   158
// Our constructed vtables:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   159
// Dump time:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   160
//  1. init_self_patching_vtbl_list: table of pointers to current virtual method addrs
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   161
//  2. generate_vtable_methods: create jump table, appended to above vtbl_list
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   162
//  3. patch_klass_vtables: for Klass list, patch the vtable entry in klass and
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   163
//     associated metadata to point to jump table rather than to current vtbl
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   164
// Table layout: NOTE FIXED SIZE
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   165
//   1. vtbl pointers
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   166
//   2. #Klass X #virtual methods per Klass
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   167
//   1 entry for each, in the order:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   168
//   Klass1:method1 entry, Klass1:method2 entry, ... Klass1:method<num_virtuals> entry
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   169
//   Klass2:method1 entry, Klass2:method2 entry, ... Klass2:method<num_virtuals> entry
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   170
//   ...
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   171
//   Klass<vtbl_list_size>:method1 entry, Klass<vtbl_list_size>:method2 entry,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   172
//       ... Klass<vtbl_list_size>:method<num_virtuals> entry
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   173
//  Sample entry: (Sparc):
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   174
//   save(sp, -256, sp)
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   175
//   ba,pt common_code
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   176
//   mov XXX, %L0       %L0 gets: Klass index <<8 + method index (note: max method index 255)
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   177
//
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   178
// Restore time:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   179
//   1. initialize_shared_space: reserve space for table
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   180
//   2. init_self_patching_vtbl_list: update pointers to NEW virtual method addrs in text
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   181
//
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   182
// Execution time:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   183
//   First virtual method call for any object of these metadata types:
13736
5b15a8f57979 7195867: NPG: SAJDI tests fail with sun.jvm.hotspot.types.WrongTypeException: No suitable match for type
coleenp
parents: 13728
diff changeset
   184
//   1. object->klass
5b15a8f57979 7195867: NPG: SAJDI tests fail with sun.jvm.hotspot.types.WrongTypeException: No suitable match for type
coleenp
parents: 13728
diff changeset
   185
//   2. vtable entry for that klass points to the jump table entries
5b15a8f57979 7195867: NPG: SAJDI tests fail with sun.jvm.hotspot.types.WrongTypeException: No suitable match for type
coleenp
parents: 13728
diff changeset
   186
//   3. branches to common_code with %O0/klass, %L0: Klass index <<8 + method index
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   187
//   4. common_code:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   188
//      Get address of new vtbl pointer for this Klass from updated table
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   189
//      Update new vtbl pointer in the Klass: future virtual calls go direct
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   190
//      Jump to method, using new vtbl pointer and method index
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   191
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   192
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   193
static void* find_matching_vtbl_ptr(void** vtbl_list, void* new_vtable_start, void* obj) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   194
  void* old_vtbl_ptr = *(void**)obj;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   195
  for (int i = 0; i < MetaspaceShared::vtbl_list_size; i++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   196
    if (vtbl_list[i] == old_vtbl_ptr) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   197
      return (void**)new_vtable_start + i * MetaspaceShared::num_virtuals;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   198
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   199
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   200
  ShouldNotReachHere();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   201
  return NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   202
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   203
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   204
// Assumes the vtable is in first slot in object.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   205
static void patch_klass_vtables(void** vtbl_list, void* new_vtable_start) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   206
  int n = _global_klass_objects->length();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   207
  for (int i = 0; i < n; i++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   208
    Klass* obj = _global_klass_objects->at(i);
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
   209
    // Note is_instance_klass() is a virtual call in debug.  After patching vtables
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   210
    // all virtual calls on the dummy vtables will restore the original!
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
   211
    if (obj->is_instance_klass()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   212
      InstanceKlass* ik = InstanceKlass::cast(obj);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   213
      *(void**)ik = find_matching_vtbl_ptr(vtbl_list, new_vtable_start, ik);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   214
      ConstantPool* cp = ik->constants();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   215
      *(void**)cp = find_matching_vtbl_ptr(vtbl_list, new_vtable_start, cp);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   216
      for (int j = 0; j < ik->methods()->length(); j++) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   217
        Method* m = ik->methods()->at(j);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   218
        *(void**)m = find_matching_vtbl_ptr(vtbl_list, new_vtable_start, m);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   219
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   220
    } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   221
      // Array klasses
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   222
      Klass* k = obj;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   223
      *(void**)k = find_matching_vtbl_ptr(vtbl_list, new_vtable_start, k);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   224
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   225
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   226
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   227
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   228
// Closure for serializing initialization data out to a data area to be
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   229
// written to the shared file.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   230
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   231
class WriteClosure : public SerializeClosure {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   232
private:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   233
  intptr_t* top;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   234
  char* end;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   235
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   236
  inline void check_space() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   237
    if ((char*)top + sizeof(intptr_t) > end) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   238
      report_out_of_shared_space(SharedMiscData);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   239
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   240
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   241
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   242
public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   243
  WriteClosure(char* md_top, char* md_end) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   244
    top = (intptr_t*)md_top;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   245
    end = md_end;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   246
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   247
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   248
  char* get_top() { return (char*)top; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   249
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   250
  void do_ptr(void** p) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   251
    check_space();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   252
    *top = (intptr_t)*p;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   253
    ++top;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   254
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   255
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   256
  void do_tag(int tag) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   257
    check_space();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   258
    *top = (intptr_t)tag;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   259
    ++top;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   260
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   261
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   262
  void do_region(u_char* start, size_t size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   263
    if ((char*)top + size > end) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   264
      report_out_of_shared_space(SharedMiscData);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   265
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   266
    assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   267
    assert(size % sizeof(intptr_t) == 0, "bad size");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   268
    do_tag((int)size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   269
    while (size > 0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   270
      *top = *(intptr_t*)start;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   271
      ++top;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   272
      start += sizeof(intptr_t);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   273
      size -= sizeof(intptr_t);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   274
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   275
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   276
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   277
  bool reading() const { return false; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   278
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   279
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   280
// This is for dumping detailed statistics for the allocations
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   281
// in the shared spaces.
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   282
class DumpAllocClosure : public Metaspace::AllocRecordClosure {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   283
public:
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   284
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   285
  // Here's poor man's enum inheritance
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   286
#define SHAREDSPACE_OBJ_TYPES_DO(f) \
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   287
  METASPACE_OBJ_TYPES_DO(f) \
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   288
  f(SymbolHashentry) \
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   289
  f(SymbolBucket) \
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   290
  f(Other)
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   291
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   292
#define SHAREDSPACE_OBJ_TYPE_DECLARE(name) name ## Type,
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   293
#define SHAREDSPACE_OBJ_TYPE_NAME_CASE(name) case name ## Type: return #name;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   294
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   295
  enum Type {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   296
    // Types are MetaspaceObj::ClassType, MetaspaceObj::SymbolType, etc
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   297
    SHAREDSPACE_OBJ_TYPES_DO(SHAREDSPACE_OBJ_TYPE_DECLARE)
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   298
    _number_of_types
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   299
  };
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   300
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   301
  static const char * type_name(Type type) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   302
    switch(type) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   303
    SHAREDSPACE_OBJ_TYPES_DO(SHAREDSPACE_OBJ_TYPE_NAME_CASE)
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   304
    default:
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   305
      ShouldNotReachHere();
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   306
      return NULL;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   307
    }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   308
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   309
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   310
public:
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   311
  enum {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   312
    RO = 0,
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   313
    RW = 1
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   314
  };
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   315
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   316
  int _counts[2][_number_of_types];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   317
  int _bytes [2][_number_of_types];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   318
  int _which;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   319
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   320
  DumpAllocClosure() {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   321
    memset(_counts, 0, sizeof(_counts));
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   322
    memset(_bytes,  0, sizeof(_bytes));
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   323
  };
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   324
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   325
  void iterate_metaspace(Metaspace* space, int which) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   326
    assert(which == RO || which == RW, "sanity");
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   327
    _which = which;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   328
    space->iterate(this);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   329
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   330
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   331
  virtual void doit(address ptr, MetaspaceObj::Type type, int byte_size) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   332
    assert(int(type) >= 0 && type < MetaspaceObj::_number_of_types, "sanity");
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   333
    _counts[_which][type] ++;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   334
    _bytes [_which][type] += byte_size;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   335
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   336
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   337
  void dump_stats(int ro_all, int rw_all, int md_all, int mc_all);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   338
};
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   339
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   340
void DumpAllocClosure::dump_stats(int ro_all, int rw_all, int md_all, int mc_all) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   341
  rw_all += (md_all + mc_all); // md and mc are all mapped Read/Write
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   342
  int other_bytes = md_all + mc_all;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   343
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   344
  // Calculate size of data that was not allocated by Metaspace::allocate()
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   345
  MetaspaceSharedStats *stats = MetaspaceShared::stats();
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   346
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   347
  // symbols
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   348
  _counts[RW][SymbolHashentryType] = stats->symbol.hashentry_count;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   349
  _bytes [RW][SymbolHashentryType] = stats->symbol.hashentry_bytes;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   350
  other_bytes -= stats->symbol.hashentry_bytes;
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   351
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   352
  _counts[RW][SymbolBucketType] = stats->symbol.bucket_count;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   353
  _bytes [RW][SymbolBucketType] = stats->symbol.bucket_bytes;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   354
  other_bytes -= stats->symbol.bucket_bytes;
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   355
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   356
  // TODO: count things like dictionary, vtable, etc
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   357
  _bytes[RW][OtherType] =  other_bytes;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   358
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   359
  // prevent divide-by-zero
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   360
  if (ro_all < 1) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   361
    ro_all = 1;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   362
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   363
  if (rw_all < 1) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   364
    rw_all = 1;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   365
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   366
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   367
  int all_ro_count = 0;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   368
  int all_ro_bytes = 0;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   369
  int all_rw_count = 0;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   370
  int all_rw_bytes = 0;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   371
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23540
diff changeset
   372
// To make fmt_stats be a syntactic constant (for format warnings), use #define.
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23540
diff changeset
   373
#define fmt_stats "%-20s: %8d %10d %5.1f | %8d %10d %5.1f | %8d %10d %5.1f"
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   374
  const char *sep = "--------------------+---------------------------+---------------------------+--------------------------";
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   375
  const char *hdr = "                        ro_cnt   ro_bytes     % |   rw_cnt   rw_bytes     % |  all_cnt  all_bytes     %";
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   376
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   377
  tty->print_cr("Detailed metadata info (rw includes md and mc):");
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23540
diff changeset
   378
  tty->print_cr("%s", hdr);
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23540
diff changeset
   379
  tty->print_cr("%s", sep);
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   380
  for (int type = 0; type < int(_number_of_types); type ++) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   381
    const char *name = type_name((Type)type);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   382
    int ro_count = _counts[RO][type];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   383
    int ro_bytes = _bytes [RO][type];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   384
    int rw_count = _counts[RW][type];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   385
    int rw_bytes = _bytes [RW][type];
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   386
    int count = ro_count + rw_count;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   387
    int bytes = ro_bytes + rw_bytes;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   388
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   389
    double ro_perc = 100.0 * double(ro_bytes) / double(ro_all);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   390
    double rw_perc = 100.0 * double(rw_bytes) / double(rw_all);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   391
    double perc    = 100.0 * double(bytes)    / double(ro_all + rw_all);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   392
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23540
diff changeset
   393
    tty->print_cr(fmt_stats, name,
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   394
                  ro_count, ro_bytes, ro_perc,
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   395
                  rw_count, rw_bytes, rw_perc,
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   396
                  count, bytes, perc);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   397
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   398
    all_ro_count += ro_count;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   399
    all_ro_bytes += ro_bytes;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   400
    all_rw_count += rw_count;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   401
    all_rw_bytes += rw_bytes;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   402
  }
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   403
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   404
  int all_count = all_ro_count + all_rw_count;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   405
  int all_bytes = all_ro_bytes + all_rw_bytes;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   406
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   407
  double all_ro_perc = 100.0 * double(all_ro_bytes) / double(ro_all);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   408
  double all_rw_perc = 100.0 * double(all_rw_bytes) / double(rw_all);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   409
  double all_perc    = 100.0 * double(all_bytes)    / double(ro_all + rw_all);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   410
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23540
diff changeset
   411
  tty->print_cr("%s", sep);
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23540
diff changeset
   412
  tty->print_cr(fmt_stats, "Total",
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   413
                all_ro_count, all_ro_bytes, all_ro_perc,
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   414
                all_rw_count, all_rw_bytes, all_rw_perc,
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   415
                all_count, all_bytes, all_perc);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   416
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   417
  assert(all_ro_bytes == ro_all, "everything should have been counted");
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   418
  assert(all_rw_bytes == rw_all, "everything should have been counted");
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23540
diff changeset
   419
#undef fmt_stats
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   420
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   421
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   422
// Populate the shared space.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   423
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   424
class VM_PopulateDumpSharedSpace: public VM_Operation {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   425
private:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   426
  ClassLoaderData* _loader_data;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   427
  GrowableArray<Klass*> *_class_promote_order;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   428
  VirtualSpace _md_vs;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   429
  VirtualSpace _mc_vs;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   430
  CompactHashtableWriter* _string_cht;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   431
  GrowableArray<MemRegion> *_string_regions;
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   432
  char* _md_alloc_low;
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   433
  char* _md_alloc_top;
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   434
  char* _md_alloc_max;
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   435
  static VM_PopulateDumpSharedSpace* _instance;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   436
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   437
public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   438
  VM_PopulateDumpSharedSpace(ClassLoaderData* loader_data,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   439
                             GrowableArray<Klass*> *class_promote_order) :
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   440
    _loader_data(loader_data) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   441
    // Split up and initialize the misc code and data spaces
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   442
    ReservedSpace* shared_rs = MetaspaceShared::shared_rs();
29697
92501504191b 8074459: Flags handling memory sizes should be of type size_t
jwilhelm
parents: 28363
diff changeset
   443
    size_t metadata_size = SharedReadOnlySize + SharedReadWriteSize;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   444
    ReservedSpace shared_ro_rw = shared_rs->first_part(metadata_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   445
    ReservedSpace misc_section = shared_rs->last_part(metadata_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   446
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   447
    // Now split into misc sections.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   448
    ReservedSpace md_rs   = misc_section.first_part(SharedMiscDataSize);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   449
    ReservedSpace mc_rs   = misc_section.last_part(SharedMiscDataSize);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   450
    _md_vs.initialize(md_rs, SharedMiscDataSize);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   451
    _mc_vs.initialize(mc_rs, SharedMiscCodeSize);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   452
    _class_promote_order = class_promote_order;
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   453
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   454
    _md_alloc_low = _md_vs.low();
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   455
    _md_alloc_top = _md_alloc_low + sizeof(char*);
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   456
    _md_alloc_max = _md_vs.low() + SharedMiscDataSize;
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   457
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   458
    assert(_instance == NULL, "must be singleton");
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   459
    _instance = this;
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   460
  }
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   461
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   462
  ~VM_PopulateDumpSharedSpace() {
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   463
    assert(_instance == this, "must be singleton");
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   464
    _instance = NULL;
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   465
  }
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   466
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   467
  static VM_PopulateDumpSharedSpace* instance() {
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   468
    assert(_instance != NULL, "sanity");
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   469
    return _instance;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   470
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   471
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   472
  VMOp_Type type() const { return VMOp_PopulateDumpSharedSpace; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   473
  void doit();   // outline because gdb sucks
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   474
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   475
  char* misc_data_space_alloc(size_t num_bytes) {
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   476
    size_t alignment = sizeof(char*);
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   477
    num_bytes = align_size_up(num_bytes, alignment);
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   478
    _md_alloc_top = (char*)align_ptr_up(_md_alloc_top, alignment);
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   479
    if (_md_alloc_top + num_bytes > _md_alloc_max) {
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   480
      report_out_of_shared_space(SharedMiscData);
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   481
    }
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   482
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   483
    char* p = _md_alloc_top;
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   484
    _md_alloc_top += num_bytes;
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   485
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   486
    memset(p, 0, num_bytes);
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   487
    return p;
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   488
  }
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   489
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   490
private:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   491
  void handle_misc_data_space_failure(bool success) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   492
    if (!success) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   493
      report_out_of_shared_space(SharedMiscData);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   494
    }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   495
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   496
}; // class VM_PopulateDumpSharedSpace
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   497
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   498
VM_PopulateDumpSharedSpace* VM_PopulateDumpSharedSpace::_instance;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   499
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   500
void VM_PopulateDumpSharedSpace::doit() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   501
  Thread* THREAD = VMThread::vm_thread();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   502
  NOT_PRODUCT(SystemDictionary::verify();)
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   503
  // The following guarantee is meant to ensure that no loader constraints
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   504
  // exist yet, since the constraints table is not shared.  This becomes
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   505
  // more important now that we don't re-initialize vtables/itables for
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   506
  // shared classes at runtime, where constraints were previously created.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   507
  guarantee(SystemDictionary::constraints()->number_of_entries() == 0,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   508
            "loader constraints are not saved");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   509
  guarantee(SystemDictionary::placeholders()->number_of_entries() == 0,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   510
          "placeholders are not saved");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   511
  // Revisit and implement this if we prelink method handle call sites:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   512
  guarantee(SystemDictionary::invoke_method_table() == NULL ||
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   513
            SystemDictionary::invoke_method_table()->number_of_entries() == 0,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   514
            "invoke method table is not saved");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   515
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   516
  // At this point, many classes have been loaded.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   517
  // Gather systemDictionary classes in a global array and do everything to
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   518
  // that so we don't have to walk the SystemDictionary again.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   519
  _global_klass_objects = new GrowableArray<Klass*>(1000);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   520
  Universe::basic_type_classes_do(collect_classes);
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   521
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   522
  // Need to call SystemDictionary::classes_do(void f(Klass*, ClassLoaderData*))
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   523
  // as we may have some classes with NULL ClassLoaderData* in the dictionary. Other
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   524
  // variants of SystemDictionary::classes_do will skip those classes.
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   525
  SystemDictionary::classes_do(collect_classes2);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   526
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   527
  tty->print_cr("Number of classes %d", _global_klass_objects->length());
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   528
  {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   529
    int num_type_array = 0, num_obj_array = 0, num_inst = 0;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   530
    for (int i = 0; i < _global_klass_objects->length(); i++) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   531
      Klass* k = _global_klass_objects->at(i);
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
   532
      if (k->is_instance_klass()) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   533
        num_inst ++;
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
   534
      } else if (k->is_objArray_klass()) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   535
        num_obj_array ++;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   536
      } else {
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
   537
        assert(k->is_typeArray_klass(), "sanity");
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   538
        num_type_array ++;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   539
      }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   540
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   541
    tty->print_cr("    instance classes   = %5d", num_inst);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   542
    tty->print_cr("    obj array classes  = %5d", num_obj_array);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   543
    tty->print_cr("    type array classes = %5d", num_type_array);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   544
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   545
30117
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   546
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   547
  // Ensure the ConstMethods won't be modified at run-time
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   548
  tty->print("Updating ConstMethods ... ");
cce2cdac56dc 8074345: Enable RewriteBytecodes when VM runs with CDS
minqi
parents: 28363
diff changeset
   549
  rewrite_nofast_bytecodes_and_calculate_fingerprints();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   550
  tty->print_cr("done. ");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   551
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   552
  // Remove all references outside the metadata
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   553
  tty->print("Removing unshareable information ... ");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   554
  remove_unshareable_in_classes();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   555
  tty->print_cr("done. ");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   556
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   557
  // Set up the share data and shared code segments.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   558
  char* md_low = _md_vs.low();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   559
  char* md_top = md_low;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   560
  char* md_end = _md_vs.high();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   561
  char* mc_low = _mc_vs.low();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   562
  char* mc_top = mc_low;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   563
  char* mc_end = _mc_vs.high();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   564
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   565
  assert(_md_alloc_top != NULL, "sanity");
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   566
  *(char**)_md_alloc_low = _md_alloc_top;
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   567
  md_top = _md_alloc_top;
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   568
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   569
  // Reserve space for the list of Klass*s whose vtables are used
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   570
  // for patching others as needed.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   571
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   572
  void** vtbl_list = (void**)md_top;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   573
  int vtbl_list_size = MetaspaceShared::vtbl_list_size;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   574
  Universe::init_self_patching_vtbl_list(vtbl_list, vtbl_list_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   575
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   576
  md_top += vtbl_list_size * sizeof(void*);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   577
  void* vtable = md_top;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   578
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   579
  // Reserve space for a new dummy vtable for klass objects in the
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   580
  // heap.  Generate self-patching vtable entries.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   581
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   582
  MetaspaceShared::generate_vtable_methods(vtbl_list, &vtable,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   583
                                     &md_top, md_end,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   584
                                     &mc_top, mc_end);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   585
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   586
  // Reorder the system dictionary.  (Moving the symbols affects
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   587
  // how the hash table indices are calculated.)
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   588
  // Not doing this either.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   589
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   590
  SystemDictionary::reorder_dictionary();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   591
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   592
  NOT_PRODUCT(SystemDictionary::verify();)
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   593
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   594
  // Copy the symbol table, string table, and the system dictionary to the shared
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 20059
diff changeset
   595
  // space in usable form.  Copy the hashtable
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   596
  // buckets first [read-write], then copy the linked lists of entries
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   597
  // [read-only].
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   598
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   599
  NOT_PRODUCT(SymbolTable::verify());
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
   600
  handle_misc_data_space_failure(SymbolTable::copy_compact_table(&md_top, md_end));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   601
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   602
  size_t ss_bytes = 0;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   603
  char* ss_low;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   604
  // The string space has maximum two regions. See FileMapInfo::write_string_regions() for details.
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   605
  _string_regions = new GrowableArray<MemRegion>(2);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   606
  NOT_PRODUCT(StringTable::verify());
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   607
  handle_misc_data_space_failure(StringTable::copy_compact_table(&md_top, md_end, _string_regions,
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   608
                                                                 &ss_bytes));
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   609
  ss_low = _string_regions->is_empty() ? NULL : (char*)_string_regions->first().start();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   610
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   611
  SystemDictionary::reverse();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   612
  SystemDictionary::copy_buckets(&md_top, md_end);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   613
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   614
  ClassLoader::verify();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   615
  ClassLoader::copy_package_info_buckets(&md_top, md_end);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   616
  ClassLoader::verify();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   617
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   618
  SystemDictionary::copy_table(&md_top, md_end);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   619
  ClassLoader::verify();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   620
  ClassLoader::copy_package_info_table(&md_top, md_end);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   621
  ClassLoader::verify();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   622
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   623
  // Write the other data to the output array.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   624
  WriteClosure wc(md_top, md_end);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   625
  MetaspaceShared::serialize(&wc);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   626
  md_top = wc.get_top();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   627
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   628
  // Print shared spaces all the time
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23540
diff changeset
   629
// To make fmt_space be a syntactic constant (for format warnings), use #define.
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31362
diff changeset
   630
#define fmt_space "%s space: " SIZE_FORMAT_W(9) " [ %4.1f%% of total] out of " SIZE_FORMAT_W(9) " bytes [%4.1f%% used] at " INTPTR_FORMAT
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   631
  Metaspace* ro_space = _loader_data->ro_metaspace();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   632
  Metaspace* rw_space = _loader_data->rw_metaspace();
15197
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   633
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   634
  // Allocated size of each space (may not be all occupied)
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 15197
diff changeset
   635
  const size_t ro_alloced = ro_space->capacity_bytes_slow(Metaspace::NonClassType);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 15197
diff changeset
   636
  const size_t rw_alloced = rw_space->capacity_bytes_slow(Metaspace::NonClassType);
15197
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   637
  const size_t md_alloced = md_end-md_low;
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   638
  const size_t mc_alloced = mc_end-mc_low;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   639
  const size_t total_alloced = ro_alloced + rw_alloced + md_alloced + mc_alloced
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   640
                             + ss_bytes;
15197
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   641
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   642
  // Occupied size of each space.
17109
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 15197
diff changeset
   643
  const size_t ro_bytes = ro_space->used_bytes_slow(Metaspace::NonClassType);
90e6c31bbbe4 8008966: NPG: Inefficient Metaspace counter functions cause large young GC regressions
jmasa
parents: 15197
diff changeset
   644
  const size_t rw_bytes = rw_space->used_bytes_slow(Metaspace::NonClassType);
15197
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   645
  const size_t md_bytes = size_t(md_top - md_low);
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   646
  const size_t mc_bytes = size_t(mc_top - mc_low);
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   647
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   648
  // Percent of total size
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   649
  const size_t total_bytes = ro_bytes + rw_bytes + md_bytes + mc_bytes + ss_bytes;
15197
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   650
  const double ro_t_perc = ro_bytes / double(total_bytes) * 100.0;
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   651
  const double rw_t_perc = rw_bytes / double(total_bytes) * 100.0;
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   652
  const double md_t_perc = md_bytes / double(total_bytes) * 100.0;
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   653
  const double mc_t_perc = mc_bytes / double(total_bytes) * 100.0;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   654
  const double ss_t_perc = ss_bytes / double(total_bytes) * 100.0;
15197
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   655
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   656
  // Percent of fullness of each space
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   657
  const double ro_u_perc = ro_bytes / double(ro_alloced) * 100.0;
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   658
  const double rw_u_perc = rw_bytes / double(rw_alloced) * 100.0;
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   659
  const double md_u_perc = md_bytes / double(md_alloced) * 100.0;
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   660
  const double mc_u_perc = mc_bytes / double(mc_alloced) * 100.0;
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   661
  const double total_u_perc = total_bytes / double(total_alloced) * 100.0;
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   662
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31362
diff changeset
   663
  tty->print_cr(fmt_space, "ro", ro_bytes, ro_t_perc, ro_alloced, ro_u_perc, p2i(ro_space->bottom()));
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31362
diff changeset
   664
  tty->print_cr(fmt_space, "rw", rw_bytes, rw_t_perc, rw_alloced, rw_u_perc, p2i(rw_space->bottom()));
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31362
diff changeset
   665
  tty->print_cr(fmt_space, "md", md_bytes, md_t_perc, md_alloced, md_u_perc, p2i(md_low));
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31362
diff changeset
   666
  tty->print_cr(fmt_space, "mc", mc_bytes, mc_t_perc, mc_alloced, mc_u_perc, p2i(mc_low));
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31362
diff changeset
   667
  tty->print_cr(fmt_space, "st", ss_bytes, ss_t_perc, ss_bytes,   100.0,     p2i(ss_low));
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31362
diff changeset
   668
  tty->print_cr("total   : " SIZE_FORMAT_W(9) " [100.0%% of total] out of " SIZE_FORMAT_W(9) " bytes [%4.1f%% used]",
15197
cef3fb881307 8005467: CDS size information is incorrect and unfriendly
coleenp
parents: 15100
diff changeset
   669
                 total_bytes, total_alloced, total_u_perc);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   670
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   671
  // Update the vtable pointers in all of the Klass objects in the
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   672
  // heap. They should point to newly generated vtable.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   673
  patch_klass_vtables(vtbl_list, vtable);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   674
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   675
  // dunno what this is for.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   676
  char* saved_vtbl = (char*)os::malloc(vtbl_list_size * sizeof(void*), mtClass);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   677
  memmove(saved_vtbl, vtbl_list, vtbl_list_size * sizeof(void*));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   678
  memset(vtbl_list, 0, vtbl_list_size * sizeof(void*));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   679
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   680
  // Create and write the archive file that maps the shared spaces.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   681
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   682
  FileMapInfo* mapinfo = new FileMapInfo();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   683
  mapinfo->populate_header(MetaspaceShared::max_alignment());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   684
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   685
  // Pass 1 - update file offsets in header.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   686
  mapinfo->write_header();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   687
  mapinfo->write_space(MetaspaceShared::ro, _loader_data->ro_metaspace(), true);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   688
  mapinfo->write_space(MetaspaceShared::rw, _loader_data->rw_metaspace(), false);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   689
  mapinfo->write_region(MetaspaceShared::md, _md_vs.low(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   690
                        pointer_delta(md_top, _md_vs.low(), sizeof(char)),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   691
                        SharedMiscDataSize,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   692
                        false, false);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   693
  mapinfo->write_region(MetaspaceShared::mc, _mc_vs.low(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   694
                        pointer_delta(mc_top, _mc_vs.low(), sizeof(char)),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   695
                        SharedMiscCodeSize,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   696
                        true, true);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   697
  mapinfo->write_string_regions(_string_regions);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   698
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   699
  // Pass 2 - write data.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   700
  mapinfo->open_for_write();
27025
f4805f778f16 8044269: Analysis of archive files.
jiangli
parents: 26304
diff changeset
   701
  mapinfo->set_header_crc(mapinfo->compute_header_crc());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   702
  mapinfo->write_header();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   703
  mapinfo->write_space(MetaspaceShared::ro, _loader_data->ro_metaspace(), true);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   704
  mapinfo->write_space(MetaspaceShared::rw, _loader_data->rw_metaspace(), false);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   705
  mapinfo->write_region(MetaspaceShared::md, _md_vs.low(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   706
                        pointer_delta(md_top, _md_vs.low(), sizeof(char)),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   707
                        SharedMiscDataSize,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   708
                        false, false);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   709
  mapinfo->write_region(MetaspaceShared::mc, _mc_vs.low(),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   710
                        pointer_delta(mc_top, _mc_vs.low(), sizeof(char)),
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   711
                        SharedMiscCodeSize,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   712
                        true, true);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   713
  mapinfo->write_string_regions(_string_regions);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   714
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   715
  mapinfo->close();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   716
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   717
  memmove(vtbl_list, saved_vtbl, vtbl_list_size * sizeof(void*));
30753
75e795c4d14f 8075288: malloc without free in VM_PopulateDumpSharedSpace::doit()
dholmes
parents: 30120
diff changeset
   718
  os::free(saved_vtbl);
17858
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   719
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   720
  if (PrintSharedSpaces) {
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   721
    DumpAllocClosure dac;
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   722
    dac.iterate_metaspace(_loader_data->ro_metaspace(), DumpAllocClosure::RO);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   723
    dac.iterate_metaspace(_loader_data->rw_metaspace(), DumpAllocClosure::RW);
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   724
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   725
    dac.dump_stats(int(ro_bytes), int(rw_bytes), int(md_bytes), int(mc_bytes));
c292f8791cca 8014912: Restore PrintSharedSpaces functionality after NPG
iklam
parents: 17109
diff changeset
   726
  }
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23540
diff changeset
   727
#undef fmt_space
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   728
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   729
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   730
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   731
void MetaspaceShared::link_one_shared_class(Klass* obj, TRAPS) {
14488
ab48109f7d1b 8001471: Klass::cast() does nothing
hseigel
parents: 14120
diff changeset
   732
  Klass* k = obj;
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
   733
  if (k->is_instance_klass()) {
33602
16053580a684 8139163: InstanceKlass::cast passes through NULL
coleenp
parents: 33148
diff changeset
   734
    InstanceKlass* ik = InstanceKlass::cast(k);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   735
    // Link the class to cause the bytecodes to be rewritten and the
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   736
    // cpcache to be created. Class verification is done according
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   737
    // to -Xverify setting.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   738
    _link_classes_made_progress |= try_link_class(ik, THREAD);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   739
    guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   740
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   741
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   742
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   743
void MetaspaceShared::check_one_shared_class(Klass* k) {
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 33602
diff changeset
   744
  if (k->is_instance_klass() && InstanceKlass::cast(k)->check_sharing_error_state()) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   745
    _check_classes_made_progress = true;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   746
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   747
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   748
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   749
void MetaspaceShared::link_and_cleanup_shared_classes(TRAPS) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   750
  // We need to iterate because verification may cause additional classes
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   751
  // to be loaded.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   752
  do {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   753
    _link_classes_made_progress = false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   754
    SystemDictionary::classes_do(link_one_shared_class, THREAD);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   755
    guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   756
  } while (_link_classes_made_progress);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   757
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   758
  if (_has_error_classes) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   759
    // Mark all classes whose super class or interfaces failed verification.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   760
    do {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   761
      // Not completely sure if we need to do this iteratively. Anyway,
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   762
      // we should come here only if there are unverifiable classes, which
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   763
      // shouldn't happen in normal cases. So better safe than sorry.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   764
      _check_classes_made_progress = false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   765
      SystemDictionary::classes_do(check_one_shared_class);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   766
    } while (_check_classes_made_progress);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   767
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   768
    if (IgnoreUnverifiableClassesDuringDump) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   769
      // This is useful when running JCK or SQE tests. You should not
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   770
      // enable this when running real apps.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   771
      SystemDictionary::remove_classes_in_error_state();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   772
    } else {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   773
      tty->print_cr("Please remove the unverifiable classes from your class list and try again");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   774
      exit(1);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   775
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   776
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   777
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   778
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   779
void MetaspaceShared::prepare_for_dumping() {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   780
  ClassLoader::initialize_shared_path();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   781
  FileMapInfo::allocate_classpath_entry_table();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   782
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   783
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   784
// Preload classes from a list, populate the shared spaces and dump to a
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   785
// file.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   786
void MetaspaceShared::preload_and_dump(TRAPS) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   787
  TraceTime timer("Dump Shared Spaces", TraceStartupTime);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   788
  ResourceMark rm;
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   789
  char class_list_path_str[JVM_MAXPATHLEN];
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   790
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31362
diff changeset
   791
  tty->print_cr("Allocated shared space: " SIZE_FORMAT " bytes at " PTR_FORMAT,
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   792
                MetaspaceShared::shared_rs()->size(),
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 31362
diff changeset
   793
                p2i(MetaspaceShared::shared_rs()->base()));
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   794
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   795
  // Preload classes to be shared.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   796
  // Should use some os:: method rather than fopen() here. aB.
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   797
  const char* class_list_path;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   798
  if (SharedClassListFile == NULL) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   799
    // Construct the path to the class list (in jre/lib)
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   800
    // Walk up two directories from the location of the VM and
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   801
    // optionally tack on "lib" (depending on platform)
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   802
    os::jvm_path(class_list_path_str, sizeof(class_list_path_str));
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   803
    for (int i = 0; i < 3; i++) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   804
      char *end = strrchr(class_list_path_str, *os::file_separator());
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   805
      if (end != NULL) *end = '\0';
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   806
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   807
    int class_list_path_len = (int)strlen(class_list_path_str);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   808
    if (class_list_path_len >= 3) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   809
      if (strcmp(class_list_path_str + class_list_path_len - 3, "lib") != 0) {
27471
6e56277909f1 8062370: Various minor code improvements
goetz
parents: 27025
diff changeset
   810
        if (class_list_path_len < JVM_MAXPATHLEN - 4) {
27611
e8e7b0902deb 8060721: Test runtime/SharedArchiveFile/LimitSharedSizes.java fails in jdk 9 fcs new platforms/compiler
ccheung
parents: 27471
diff changeset
   811
          jio_snprintf(class_list_path_str + class_list_path_len,
e8e7b0902deb 8060721: Test runtime/SharedArchiveFile/LimitSharedSizes.java fails in jdk 9 fcs new platforms/compiler
ccheung
parents: 27471
diff changeset
   812
                       sizeof(class_list_path_str) - class_list_path_len,
e8e7b0902deb 8060721: Test runtime/SharedArchiveFile/LimitSharedSizes.java fails in jdk 9 fcs new platforms/compiler
ccheung
parents: 27471
diff changeset
   813
                       "%slib", os::file_separator());
e8e7b0902deb 8060721: Test runtime/SharedArchiveFile/LimitSharedSizes.java fails in jdk 9 fcs new platforms/compiler
ccheung
parents: 27471
diff changeset
   814
          class_list_path_len += 4;
27471
6e56277909f1 8062370: Various minor code improvements
goetz
parents: 27025
diff changeset
   815
        }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   816
      }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   817
    }
27471
6e56277909f1 8062370: Various minor code improvements
goetz
parents: 27025
diff changeset
   818
    if (class_list_path_len < JVM_MAXPATHLEN - 10) {
27611
e8e7b0902deb 8060721: Test runtime/SharedArchiveFile/LimitSharedSizes.java fails in jdk 9 fcs new platforms/compiler
ccheung
parents: 27471
diff changeset
   819
      jio_snprintf(class_list_path_str + class_list_path_len,
e8e7b0902deb 8060721: Test runtime/SharedArchiveFile/LimitSharedSizes.java fails in jdk 9 fcs new platforms/compiler
ccheung
parents: 27471
diff changeset
   820
                   sizeof(class_list_path_str) - class_list_path_len,
e8e7b0902deb 8060721: Test runtime/SharedArchiveFile/LimitSharedSizes.java fails in jdk 9 fcs new platforms/compiler
ccheung
parents: 27471
diff changeset
   821
                   "%sclasslist", os::file_separator());
27471
6e56277909f1 8062370: Various minor code improvements
goetz
parents: 27025
diff changeset
   822
    }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   823
    class_list_path = class_list_path_str;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   824
  } else {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   825
    class_list_path = SharedClassListFile;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   826
  }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   827
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   828
  int class_count = 0;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   829
  GrowableArray<Klass*>* class_promote_order = new GrowableArray<Klass*>();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   830
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   831
  // sun.io.Converters
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   832
  static const char obj_array_sig[] = "[[Ljava/lang/Object;";
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   833
  SymbolTable::new_permanent_symbol(obj_array_sig, THREAD);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   834
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   835
  // java.util.HashMap
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   836
  static const char map_entry_array_sig[] = "[Ljava/util/Map$Entry;";
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   837
  SymbolTable::new_permanent_symbol(map_entry_array_sig, THREAD);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   838
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   839
  // Need to allocate the op here:
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   840
  // op.misc_data_space_alloc() will be called during preload_and_dump().
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   841
  ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   842
  VM_PopulateDumpSharedSpace op(loader_data, class_promote_order);
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   843
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   844
  tty->print_cr("Loading classes to share ...");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   845
  _has_error_classes = false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   846
  class_count += preload_and_dump(class_list_path, class_promote_order,
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   847
                                  THREAD);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   848
  if (ExtraSharedClassListFile) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   849
    class_count += preload_and_dump(ExtraSharedClassListFile, class_promote_order,
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   850
                                    THREAD);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   851
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   852
  tty->print_cr("Loading classes to share: done.");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   853
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   854
  if (PrintSharedSpaces) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   855
    tty->print_cr("Shared spaces: preloaded %d classes", class_count);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   856
  }
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   857
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   858
  // Rewrite and link classes
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   859
  tty->print_cr("Rewriting and linking classes ...");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   860
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   861
  // Link any classes which got missed. This would happen if we have loaded classes that
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   862
  // were not explicitly specified in the classlist. E.g., if an interface implemented by class K
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   863
  // fails verification, all other interfaces that were not specified in the classlist but
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   864
  // are implemented by K are not verified.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   865
  link_and_cleanup_shared_classes(CATCH);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   866
  tty->print_cr("Rewriting and linking classes: done");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   867
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   868
  VMThread::execute(&op);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   869
  // Since various initialization steps have been undone by this process,
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   870
  // it is not reasonable to continue running a java process.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   871
  exit(0);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   872
}
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   873
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   874
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   875
int MetaspaceShared::preload_and_dump(const char* class_list_path,
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   876
                                      GrowableArray<Klass*>* class_promote_order,
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   877
                                      TRAPS) {
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   878
  ClassListParser parser(class_list_path);
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   879
  int class_count = 0;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   880
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   881
    while (parser.parse_one_line()) {
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   882
      Klass* klass = ClassLoaderExt::load_one_class(&parser, THREAD);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   883
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   884
      CLEAR_PENDING_EXCEPTION;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   885
      if (klass != NULL) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   886
        if (PrintSharedSpaces && Verbose && WizardMode) {
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   887
          ResourceMark rm;
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   888
          tty->print_cr("Shared spaces preloaded: %s", klass->external_name());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   889
        }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   890
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   891
        InstanceKlass* ik = InstanceKlass::cast(klass);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   892
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   893
        // Should be class load order as per -XX:+TraceClassLoadingPreorder
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   894
        class_promote_order->append(ik);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   895
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   896
        // Link the class to cause the bytecodes to be rewritten and the
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   897
        // cpcache to be created. The linking is done as soon as classes
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   898
        // are loaded in order that the related data structures (klass and
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   899
        // cpCache) are located together.
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   900
        try_link_class(ik, THREAD);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   901
        guarantee(!HAS_PENDING_EXCEPTION, "exception in link_class");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   902
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   903
        class_count++;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   904
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   905
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   906
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   907
  return class_count;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   908
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   909
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   910
// Returns true if the class's status has changed
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   911
bool MetaspaceShared::try_link_class(InstanceKlass* ik, TRAPS) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   912
  assert(DumpSharedSpaces, "should only be called during dumping");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   913
  if (ik->init_state() < InstanceKlass::linked) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   914
    bool saved = BytecodeVerificationLocal;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   915
    if (!SharedClassUtil::is_shared_boot_class(ik)) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   916
      // The verification decision is based on BytecodeVerificationRemote
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   917
      // for non-system classes. Since we are using the NULL classloader
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   918
      // to load non-system classes during dumping, we need to temporarily
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   919
      // change BytecodeVerificationLocal to be the same as
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   920
      // BytecodeVerificationRemote. Note this can cause the parent system
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   921
      // classes also being verified. The extra overhead is acceptable during
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   922
      // dumping.
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   923
      BytecodeVerificationLocal = BytecodeVerificationRemote;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   924
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   925
    ik->link_class(THREAD);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   926
    if (HAS_PENDING_EXCEPTION) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   927
      ResourceMark rm;
27618
790a8bf5488b 8064375: Change certain errors to warnings in CDS output.
jiangli
parents: 27025
diff changeset
   928
      tty->print_cr("Preload Warning: Verification failed for %s",
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   929
                    ik->external_name());
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   930
      CLEAR_PENDING_EXCEPTION;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   931
      ik->set_in_error_state();
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   932
      _has_error_classes = true;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   933
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   934
    BytecodeVerificationLocal = saved;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   935
    return true;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   936
  } else {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   937
    return false;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   938
  }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
   939
}
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   940
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   941
// Allocate misc data blocks during dumping.
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   942
char* MetaspaceShared::misc_data_space_alloc(size_t num_bytes) {
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   943
  return VM_PopulateDumpSharedSpace::instance()->misc_data_space_alloc(num_bytes);
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   944
}
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
   945
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   946
// Closure for serializing initialization data in from a data area
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   947
// (ptr_array) read from the shared file.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   948
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   949
class ReadClosure : public SerializeClosure {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   950
private:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   951
  intptr_t** _ptr_array;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   952
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   953
  inline intptr_t nextPtr() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   954
    return *(*_ptr_array)++;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   955
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   956
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   957
public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   958
  ReadClosure(intptr_t** ptr_array) { _ptr_array = ptr_array; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   959
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   960
  void do_ptr(void** p) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   961
    assert(*p == NULL, "initializing previous initialized pointer.");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   962
    intptr_t obj = nextPtr();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   963
    assert((intptr_t)obj >= 0 || (intptr_t)obj < -100,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   964
           "hit tag while initializing ptrs.");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   965
    *p = (void*)obj;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   966
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   967
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   968
  void do_tag(int tag) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   969
    int old_tag;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   970
    old_tag = (int)(intptr_t)nextPtr();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   971
    // do_int(&old_tag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   972
    assert(tag == old_tag, "old tag doesn't match");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   973
    FileMapInfo::assert_mark(tag == old_tag);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   974
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   975
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   976
  void do_region(u_char* start, size_t size) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   977
    assert((intptr_t)start % sizeof(intptr_t) == 0, "bad alignment");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   978
    assert(size % sizeof(intptr_t) == 0, "bad size");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   979
    do_tag((int)size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   980
    while (size > 0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   981
      *(intptr_t*)start = nextPtr();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   982
      start += sizeof(intptr_t);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   983
      size -= sizeof(intptr_t);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   984
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   985
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   986
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   987
  bool reading() const { return true; }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   988
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   989
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   990
// Return true if given address is in the mapped shared space.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   991
bool MetaspaceShared::is_in_shared_space(const void* p) {
18483
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17858
diff changeset
   992
  return UseSharedSpaces && FileMapInfo::current_info()->is_in_shared_space(p);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   993
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   994
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   995
bool MetaspaceShared::is_string_region(int idx) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   996
  return (idx >= MetaspaceShared::first_string &&
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   997
          idx < MetaspaceShared::first_string + MetaspaceShared::max_strings);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   998
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
   999
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1000
void MetaspaceShared::print_shared_spaces() {
18483
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17858
diff changeset
  1001
  if (UseSharedSpaces) {
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17858
diff changeset
  1002
    FileMapInfo::current_info()->print_shared_spaces();
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17858
diff changeset
  1003
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1004
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1005
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1006
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1007
// Map shared spaces at requested addresses and return if succeeded.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1008
// Need to keep the bounds of the ro and rw space for the Metaspace::contains
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1009
// call, or is_in_shared_space.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1010
bool MetaspaceShared::map_shared_spaces(FileMapInfo* mapinfo) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1011
  size_t image_alignment = mapinfo->alignment();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1012
15100
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  1013
#ifndef _WINDOWS
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  1014
  // Map in the shared memory and then map the regions on top of it.
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  1015
  // On Windows, don't map the memory here because it will cause the
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  1016
  // mappings of the regions to fail.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1017
  ReservedSpace shared_rs = mapinfo->reserve_shared_memory();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1018
  if (!shared_rs.is_reserved()) return false;
15100
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  1019
#endif
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  1020
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  1021
  assert(!DumpSharedSpaces, "Should not be called with DumpSharedSpaces");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1022
18483
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17858
diff changeset
  1023
  char* _ro_base = NULL;
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17858
diff changeset
  1024
  char* _rw_base = NULL;
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17858
diff changeset
  1025
  char* _md_base = NULL;
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17858
diff changeset
  1026
  char* _mc_base = NULL;
c021907fa0a7 8016075: Win32 crash with CDS enabled and small heap size
iklam
parents: 17858
diff changeset
  1027
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1028
  // Map each shared region
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1029
  if ((_ro_base = mapinfo->map_region(ro)) != NULL &&
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1030
      mapinfo->verify_region_checksum(ro) &&
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1031
      (_rw_base = mapinfo->map_region(rw)) != NULL &&
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1032
      mapinfo->verify_region_checksum(rw) &&
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1033
      (_md_base = mapinfo->map_region(md)) != NULL &&
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1034
      mapinfo->verify_region_checksum(md) &&
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1035
      (_mc_base = mapinfo->map_region(mc)) != NULL &&
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1036
      mapinfo->verify_region_checksum(mc) &&
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1037
      (image_alignment == (size_t)max_alignment()) &&
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1038
      mapinfo->validate_classpath_entry_table()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1039
    // Success (no need to do anything)
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1040
    return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1041
  } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1042
    // If there was a failure in mapping any of the spaces, unmap the ones
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1043
    // that succeeded
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1044
    if (_ro_base != NULL) mapinfo->unmap_region(ro);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1045
    if (_rw_base != NULL) mapinfo->unmap_region(rw);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1046
    if (_md_base != NULL) mapinfo->unmap_region(md);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1047
    if (_mc_base != NULL) mapinfo->unmap_region(mc);
15100
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  1048
#ifndef _WINDOWS
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1049
    // Release the entire mapped region
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1050
    shared_rs.release();
15100
0ae85ac7c8b0 8003705: CDS failed on Windows: can not map in the CDS.
hseigel
parents: 14488
diff changeset
  1051
#endif
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1052
    // If -Xshare:on is specified, print out the error message and exit VM,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1053
    // otherwise, set UseSharedSpaces to false and continue.
28017
84009002b566 8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
iklam
parents: 27619
diff changeset
  1054
    if (RequireSharedSpaces || PrintSharedArchiveAndExit) {
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1055
      vm_exit_during_initialization("Unable to use shared archive.", "Failed map_region for using -Xshare:on.");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1056
    } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1057
      FLAG_SET_DEFAULT(UseSharedSpaces, false);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1058
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1059
    return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1060
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1061
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1062
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1063
// Read the miscellaneous data from the shared file, and
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1064
// serialize it out to its various destinations.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1065
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1066
void MetaspaceShared::initialize_shared_spaces() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1067
  FileMapInfo *mapinfo = FileMapInfo::current_info();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1068
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1069
  char* buffer = mapinfo->header()->region_addr(md);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1070
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
  1071
  buffer = *((char**)buffer); // skip over the md_alloc'ed blocks
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents: 33638
diff changeset
  1072
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1073
  // Skip over (reserve space for) a list of addresses of C++ vtables
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1074
  // for Klass objects.  They get filled in later.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1075
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1076
  void** vtbl_list = (void**)buffer;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1077
  buffer += MetaspaceShared::vtbl_list_size * sizeof(void*);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1078
  Universe::init_self_patching_vtbl_list(vtbl_list, vtbl_list_size);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1079
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1080
  // Skip over (reserve space for) dummy C++ vtables Klass objects.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1081
  // They are used as is.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1082
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1083
  intptr_t vtable_size = *(intptr_t*)buffer;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1084
  buffer += sizeof(intptr_t);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1085
  buffer += vtable_size;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1086
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1087
  // Create the shared symbol table using the compact table at this spot in the
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
  1088
  // misc data space. (Todo: move this to read-only space. Currently
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
  1089
  // this is mapped copy-on-write but will never be written into).
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1090
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
  1091
  buffer = (char*)SymbolTable::init_shared_table(buffer);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
  1092
  SymbolTable::create_table();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1093
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1094
  // Create the shared string table using the compact table
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1095
  buffer = (char*)StringTable::init_shared_table(mapinfo, buffer);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1096
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1097
  // Create the shared dictionary using the bucket array at this spot in
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1098
  // the misc data space.  Since the shared dictionary table is never
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1099
  // modified, this region (of mapped pages) will be (effectively, if
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1100
  // not explicitly) read-only.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1101
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1102
  int sharedDictionaryLen = *(intptr_t*)buffer;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1103
  buffer += sizeof(intptr_t);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
  1104
  int number_of_entries = *(intptr_t*)buffer;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1105
  buffer += sizeof(intptr_t);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1106
  SystemDictionary::set_shared_dictionary((HashtableBucket<mtClass>*)buffer,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1107
                                          sharedDictionaryLen,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1108
                                          number_of_entries);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1109
  buffer += sharedDictionaryLen;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1110
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1111
  // Create the package info table using the bucket array at this spot in
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1112
  // the misc data space.  Since the package info table is never
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1113
  // modified, this region (of mapped pages) will be (effectively, if
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1114
  // not explicitly) read-only.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1115
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1116
  int pkgInfoLen = *(intptr_t*)buffer;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1117
  buffer += sizeof(intptr_t);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1118
  number_of_entries = *(intptr_t*)buffer;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1119
  buffer += sizeof(intptr_t);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1120
  ClassLoader::create_package_info_table((HashtableBucket<mtClass>*)buffer, pkgInfoLen,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1121
                                         number_of_entries);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1122
  buffer += pkgInfoLen;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1123
  ClassLoader::verify();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1124
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1125
  // The following data in the shared misc data region are the linked
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
  1126
  // list elements (HashtableEntry objects) for the shared dictionary
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
  1127
  // and package info table.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1128
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 28017
diff changeset
  1129
  int len = *(intptr_t*)buffer;     // skip over shared dictionary entries
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1130
  buffer += sizeof(intptr_t);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1131
  buffer += len;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1132
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1133
  len = *(intptr_t*)buffer;     // skip over package info table entries
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1134
  buffer += sizeof(intptr_t);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1135
  buffer += len;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1136
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1137
  len = *(intptr_t*)buffer;     // skip over package info table char[] arrays.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1138
  buffer += sizeof(intptr_t);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1139
  buffer += len;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1140
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1141
  intptr_t* array = (intptr_t*)buffer;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1142
  ReadClosure rc(&array);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1143
  serialize(&rc);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1144
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1145
  // Close the mapinfo file
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1146
  mapinfo->close();
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1147
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1148
  if (PrintSharedArchiveAndExit) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1149
    if (PrintSharedDictionary) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1150
      tty->print_cr("\nShared classes:\n");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1151
      SystemDictionary::print_shared(false);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1152
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1153
    if (_archive_loading_failed) {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1154
      tty->print_cr("archive is invalid");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1155
      vm_exit(1);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1156
    } else {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1157
      tty->print_cr("archive is valid");
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1158
      vm_exit(0);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1159
    }
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 25468
diff changeset
  1160
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1161
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1162
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1163
void MetaspaceShared::fixup_shared_string_regions() {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1164
  FileMapInfo *mapinfo = FileMapInfo::current_info();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1165
  mapinfo->fixup_string_regions();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1166
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30773
diff changeset
  1167
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1168
// JVM/TI RedefineClasses() support:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1169
bool MetaspaceShared::remap_shared_readonly_as_readwrite() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1170
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1171
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1172
  if (UseSharedSpaces) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1173
    // remap the shared readonly space to shared readwrite, private
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1174
    FileMapInfo* mapinfo = FileMapInfo::current_info();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1175
    if (!mapinfo->remap_shared_readonly_as_readwrite()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1176
      return false;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1177
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1178
  }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1179
  return true;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
  1180
}
26304
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1181
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1182
int MetaspaceShared::count_class(const char* classlist_file) {
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1183
  if (classlist_file == NULL) {
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1184
    return 0;
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1185
  }
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1186
  char class_name[256];
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1187
  int class_count = 0;
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1188
  FILE* file = fopen(classlist_file, "r");
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1189
  if (file != NULL) {
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1190
    while ((fgets(class_name, sizeof class_name, file)) != NULL) {
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1191
      if (*class_name == '#') { // comment
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1192
        continue;
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1193
      }
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1194
      class_count++;
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1195
    }
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1196
    fclose(file);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1197
  } else {
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1198
    char errmsg[JVM_MAXPATHLEN];
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1199
    os::lasterror(errmsg, JVM_MAXPATHLEN);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1200
    tty->print_cr("Loading classlist failed: %s", errmsg);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1201
    exit(1);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1202
  }
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1203
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1204
  return class_count;
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1205
}
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1206
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1207
// the sizes are good for typical large applications that have a lot of shared
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1208
// classes
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1209
void MetaspaceShared::estimate_regions_size() {
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1210
  int class_count = count_class(SharedClassListFile);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1211
  class_count += count_class(ExtraSharedClassListFile);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1212
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1213
  if (class_count > LargeThresholdClassCount) {
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1214
    if (class_count < HugeThresholdClassCount) {
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1215
      SET_ESTIMATED_SIZE(Large, ReadOnly);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1216
      SET_ESTIMATED_SIZE(Large, ReadWrite);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1217
      SET_ESTIMATED_SIZE(Large, MiscData);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1218
      SET_ESTIMATED_SIZE(Large, MiscCode);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1219
    } else {
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1220
      SET_ESTIMATED_SIZE(Huge,  ReadOnly);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1221
      SET_ESTIMATED_SIZE(Huge,  ReadWrite);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1222
      SET_ESTIMATED_SIZE(Huge,  MiscData);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1223
      SET_ESTIMATED_SIZE(Huge,  MiscCode);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1224
    }
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1225
  }
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
  1226
}