hotspot/src/share/vm/memory/metaspaceShared.hpp
author ccheung
Mon, 25 Aug 2014 00:13:36 -0700
changeset 26304 a28e6335ce60
parent 26135 82b516c550f7
child 26408 d6defe172e25
permissions -rw-r--r--
8048150: Allow easy configurations for large CDS archives Summary: Estimate the size of shared archive based on the number of classes in the classlist file Reviewed-by: iklam, jiangli, minqi, dholmes
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
/*
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
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
#ifndef SHARE_VM_MEMORY_METASPACE_SHARED_HPP
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    25
#define SHARE_VM_MEMORY_METASPACE_SHARED_HPP
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    26
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    27
#include "memory/allocation.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    28
#include "memory/memRegion.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    29
#include "runtime/virtualspace.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    30
#include "utilities/exceptions.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    31
#include "utilities/macros.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    32
26304
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
    33
#define LargeSharedArchiveSize    (300*M)
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
    34
#define HugeSharedArchiveSize     (800*M)
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
    35
#define ReadOnlyRegionPercentage  0.4
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
    36
#define ReadWriteRegionPercentage 0.55
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
    37
#define MiscDataRegionPercentage  0.03
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
    38
#define MiscCodeRegionPercentage  0.02
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
    39
#define LargeThresholdClassCount  5000
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
    40
#define HugeThresholdClassCount   40000
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
    41
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
    42
#define SET_ESTIMATED_SIZE(type, region)                              \
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
    43
  Shared ##region## Size  = FLAG_IS_DEFAULT(Shared ##region## Size) ? \
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
    44
    (type ## SharedArchiveSize *  region ## RegionPercentage) : Shared ## region ## Size
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
    45
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    46
class FileMapInfo;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    47
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    48
// Class Data Sharing Support
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    49
class MetaspaceShared : AllStatic {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    50
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    51
  // CDS support
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    52
  static ReservedSpace* _shared_rs;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    53
  static int _max_alignment;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 13975
diff changeset
    54
  static bool _link_classes_made_progress;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 13975
diff changeset
    55
  static bool _check_classes_made_progress;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 13975
diff changeset
    56
  static bool _has_error_classes;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 13975
diff changeset
    57
  static bool _archive_loading_failed;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    58
 public:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    59
  enum {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    60
    vtbl_list_size = 17, // number of entries in the shared space vtable list.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    61
    num_virtuals = 200   // maximum number of virtual functions
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    62
                         // If virtual functions are added to Metadata,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    63
                         // this number needs to be increased.  Also,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    64
                         // SharedMiscCodeSize will need to be increased.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    65
  };
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
  enum {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    68
    ro = 0,  // read-only shared space in the heap
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    69
    rw = 1,  // read-write shared space in the heap
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    70
    md = 2,  // miscellaneous data for initializing tables, etc.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    71
    mc = 3,  // miscellaneous code - vtable replacement.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    72
    n_regions = 4
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    73
  };
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    74
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
    75
  // Accessor functions to save shared space created for metadata, which has
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
    76
  // extra space allocated at the end for miscellaneous data and code.
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
    77
  static void set_max_alignment(int alignment) {
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
    78
    CDS_ONLY(_max_alignment = alignment);
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
    79
  }
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
    80
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
    81
  static int max_alignment() {
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
    82
    CDS_ONLY(return _max_alignment);
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
    83
    NOT_CDS(return 0);
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
    84
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    85
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 13975
diff changeset
    86
  static void prepare_for_dumping() NOT_CDS_RETURN;
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
    87
  static void preload_and_dump(TRAPS) NOT_CDS_RETURN;
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 13975
diff changeset
    88
  static int preload_and_dump(const char * class_list_path,
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 13975
diff changeset
    89
                              GrowableArray<Klass*>* class_promote_order,
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 13975
diff changeset
    90
                              TRAPS) NOT_CDS_RETURN;
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
    91
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
    92
  static ReservedSpace* shared_rs() {
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
    93
    CDS_ONLY(return _shared_rs);
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
    94
    NOT_CDS(return NULL);
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
    95
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
    96
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
    97
  static void set_shared_rs(ReservedSpace* rs) {
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
    98
    CDS_ONLY(_shared_rs = rs;)
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
    99
  }
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
   100
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 13975
diff changeset
   101
  static void set_archive_loading_failed() {
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 13975
diff changeset
   102
    _archive_loading_failed = true;
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 13975
diff changeset
   103
  }
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
   104
  static bool map_shared_spaces(FileMapInfo* mapinfo) NOT_CDS_RETURN_(false);
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
   105
  static void initialize_shared_spaces() NOT_CDS_RETURN;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   106
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   107
  // Return true if given address is in the mapped shared space.
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
   108
  static bool is_in_shared_space(const void* p) NOT_CDS_RETURN_(false);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   109
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   110
  static void generate_vtable_methods(void** vtbl_list,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   111
                                      void** vtable,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   112
                                      char** md_top, char* md_end,
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   113
                                      char** mc_top, char* mc_end);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   114
  static void serialize(SerializeClosure* sc);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   115
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   116
  // JVM/TI RedefineClasses() support:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   117
  // Remap the shared readonly space to shared readwrite, private if
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   118
  // sharing is enabled. Simply returns true if sharing is not enabled
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   119
  // or if the remapping has already been done by a prior call.
13975
2f7431485cfa 7189254: Change makefiles for more flexibility to override defaults
jprovino
parents: 13728
diff changeset
   120
  static bool remap_shared_readonly_as_readwrite() NOT_CDS_RETURN_(true);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   121
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   122
  static void print_shared_spaces();
26135
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 13975
diff changeset
   123
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 13975
diff changeset
   124
  static bool try_link_class(InstanceKlass* ik, TRAPS);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 13975
diff changeset
   125
  static void link_one_shared_class(Klass* obj, TRAPS);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 13975
diff changeset
   126
  static void check_one_shared_class(Klass* obj);
82b516c550f7 8046070: Class Data Sharing clean up and refactoring
iklam
parents: 13975
diff changeset
   127
  static void link_and_cleanup_shared_classes(TRAPS);
26304
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
   128
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
   129
  static int count_class(const char* classlist_file);
a28e6335ce60 8048150: Allow easy configurations for large CDS archives
ccheung
parents: 26135
diff changeset
   130
  static void estimate_regions_size() NOT_CDS_RETURN;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   131
};
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
diff changeset
   132
#endif // SHARE_VM_MEMORY_METASPACE_SHARED_HPP