1 /*
2 * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_MEMORY_METASPACESHARED_HPP
26 #define SHARE_VM_MEMORY_METASPACESHARED_HPP
27
28 #include "classfile/compactHashtable.hpp"
29 #include "memory/allocation.hpp"
30 #include "memory/memRegion.hpp"
31 #include "memory/virtualspace.hpp"
32 #include "utilities/exceptions.hpp"
33 #include "utilities/macros.hpp"
34
35 #define DEFAULT_VTBL_LIST_SIZE (17) // number of entries in the shared space vtable list.
36 #define DEFAULT_VTBL_VIRTUALS_COUNT (200) // maximum number of virtual functions
37 // If virtual functions are added to Metadata,
38 // this number needs to be increased. Also,
39 // SharedMiscCodeSize will need to be increased.
40 // The following 2 sizes were based on
41 // MetaspaceShared::generate_vtable_methods()
42 #define DEFAULT_VTBL_METHOD_SIZE (16) // conservative size of the mov1 and jmp instructions
43 // for the x64 platform
44 #define DEFAULT_VTBL_COMMON_CODE_SIZE (1*K) // conservative size of the "common_code" for the x64 platform
45
46 #define DEFAULT_SHARED_READ_WRITE_SIZE (NOT_LP64(6*M) LP64_ONLY(10*M))
47 #define MIN_SHARED_READ_WRITE_SIZE (NOT_LP64(6*M) LP64_ONLY(10*M))
48
49 #define DEFAULT_SHARED_READ_ONLY_SIZE (NOT_LP64(6*M) LP64_ONLY(10*M))
50 #define MIN_SHARED_READ_ONLY_SIZE (NOT_LP64(6*M) LP64_ONLY(10*M))
51
52 // the MIN_SHARED_MISC_DATA_SIZE and MIN_SHARED_MISC_CODE_SIZE estimates are based on
53 // the sizes required for dumping the archive using the default classlist. The sizes
54 // are multiplied by 1.5 for a safety margin.
55
56 #define DEFAULT_SHARED_MISC_DATA_SIZE (NOT_LP64(2*M) LP64_ONLY(4*M))
57 #define MIN_SHARED_MISC_DATA_SIZE (NOT_LP64(1*M) LP64_ONLY(1200*K))
58
59 #define DEFAULT_SHARED_MISC_CODE_SIZE (120*K)
60 #define MIN_SHARED_MISC_CODE_SIZE (NOT_LP64(63*K) LP64_ONLY(69*K))
61 #define DEFAULT_COMBINED_SIZE (DEFAULT_SHARED_READ_WRITE_SIZE+DEFAULT_SHARED_READ_ONLY_SIZE+DEFAULT_SHARED_MISC_DATA_SIZE+DEFAULT_SHARED_MISC_CODE_SIZE)
62
63 // the max size is the MAX size (ie. 0x7FFFFFFF) - the total size of
64 // the other 3 sections - page size (to avoid overflow in case the final
65 // size will get aligned up on page size)
118 class MetaspaceShared : AllStatic {
119
120 // CDS support
121 static ReservedSpace* _shared_rs;
122 static int _max_alignment;
123 static MetaspaceSharedStats _stats;
124 static bool _link_classes_made_progress;
125 static bool _check_classes_made_progress;
126 static bool _has_error_classes;
127 static bool _archive_loading_failed;
128 static bool _remapped_readwrite;
129 static address _cds_i2i_entry_code_buffers;
130 static size_t _cds_i2i_entry_code_buffers_size;
131
132 // Used only during dumping.
133 static SharedMiscRegion _md;
134 static SharedMiscRegion _mc;
135 static SharedMiscRegion _od;
136 public:
137 enum {
138 vtbl_list_size = DEFAULT_VTBL_LIST_SIZE,
139 num_virtuals = DEFAULT_VTBL_VIRTUALS_COUNT,
140 vtbl_method_size = DEFAULT_VTBL_METHOD_SIZE,
141 vtbl_common_code_size = DEFAULT_VTBL_COMMON_CODE_SIZE
142 };
143
144 enum {
145 ro = 0, // read-only shared space in the heap
146 rw = 1, // read-write shared space in the heap
147 md = 2, // miscellaneous data for initializing tables, etc.
148 mc = 3, // miscellaneous code - vtable replacement.
149 max_strings = 2, // max number of string regions in string space
150 num_non_strings = 4, // number of non-string regions
151 first_string = num_non_strings, // index of first string region
152 // The optional data region is the last region.
153 // Currently it only contains class file data.
154 od = max_strings + num_non_strings,
155 n_regions = od + 1 // total number of regions
156 };
157
158 // Accessor functions to save shared space created for metadata, which has
159 // extra space allocated at the end for miscellaneous data and code.
160 static void set_max_alignment(int alignment) {
161 CDS_ONLY(_max_alignment = alignment);
162 }
163
164 static int max_alignment() {
177 NOT_CDS(return NULL);
178 }
179
180 static void initialize_shared_rs(ReservedSpace* rs) NOT_CDS_RETURN;
181
182 static void set_archive_loading_failed() {
183 _archive_loading_failed = true;
184 }
185 static bool map_shared_spaces(FileMapInfo* mapinfo) NOT_CDS_RETURN_(false);
186 static void initialize_shared_spaces() NOT_CDS_RETURN;
187 static void fixup_shared_string_regions() NOT_CDS_RETURN;
188
189 // Return true if given address is in the mapped shared space.
190 static bool is_in_shared_space(const void* p) NOT_CDS_RETURN_(false);
191
192 // Return true if given address is in the shared region corresponding to the idx
193 static bool is_in_shared_region(const void* p, int idx) NOT_CDS_RETURN_(false);
194
195 static bool is_string_region(int idx) NOT_CDS_RETURN_(false);
196
197 static void generate_vtable_methods(void** vtbl_list,
198 void** vtable,
199 char** md_top, char* md_end,
200 char** mc_top, char* mc_end);
201 static void serialize(SerializeClosure* sc, GrowableArray<MemRegion> *string_space,
202 size_t* space_size);
203
204 static MetaspaceSharedStats* stats() {
205 return &_stats;
206 }
207
208 // JVM/TI RedefineClasses() support:
209 // Remap the shared readonly space to shared readwrite, private if
210 // sharing is enabled. Simply returns true if sharing is not enabled
211 // or if the remapping has already been done by a prior call.
212 static bool remap_shared_readonly_as_readwrite() NOT_CDS_RETURN_(true);
213 static bool remapped_readwrite() {
214 CDS_ONLY(return _remapped_readwrite);
215 NOT_CDS(return false);
216 }
217
218 static void print_shared_spaces();
219
220 static bool try_link_class(InstanceKlass* ik, TRAPS);
|
1 /*
2 * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_MEMORY_METASPACESHARED_HPP
26 #define SHARE_VM_MEMORY_METASPACESHARED_HPP
27
28 #include "classfile/compactHashtable.hpp"
29 #include "memory/allocation.hpp"
30 #include "memory/memRegion.hpp"
31 #include "memory/virtualspace.hpp"
32 #include "utilities/exceptions.hpp"
33 #include "utilities/macros.hpp"
34
35 #define DEFAULT_SHARED_READ_WRITE_SIZE (NOT_LP64(6*M) LP64_ONLY(10*M))
36 #define MIN_SHARED_READ_WRITE_SIZE (NOT_LP64(6*M) LP64_ONLY(10*M))
37
38 #define DEFAULT_SHARED_READ_ONLY_SIZE (NOT_LP64(6*M) LP64_ONLY(10*M))
39 #define MIN_SHARED_READ_ONLY_SIZE (NOT_LP64(6*M) LP64_ONLY(10*M))
40
41 // the MIN_SHARED_MISC_DATA_SIZE and MIN_SHARED_MISC_CODE_SIZE estimates are based on
42 // the sizes required for dumping the archive using the default classlist. The sizes
43 // are multiplied by 1.5 for a safety margin.
44
45 #define DEFAULT_SHARED_MISC_DATA_SIZE (NOT_LP64(2*M) LP64_ONLY(4*M))
46 #define MIN_SHARED_MISC_DATA_SIZE (NOT_LP64(1*M) LP64_ONLY(1200*K))
47
48 #define DEFAULT_SHARED_MISC_CODE_SIZE (120*K)
49 #define MIN_SHARED_MISC_CODE_SIZE (NOT_LP64(63*K) LP64_ONLY(69*K))
50 #define DEFAULT_COMBINED_SIZE (DEFAULT_SHARED_READ_WRITE_SIZE+DEFAULT_SHARED_READ_ONLY_SIZE+DEFAULT_SHARED_MISC_DATA_SIZE+DEFAULT_SHARED_MISC_CODE_SIZE)
51
52 // the max size is the MAX size (ie. 0x7FFFFFFF) - the total size of
53 // the other 3 sections - page size (to avoid overflow in case the final
54 // size will get aligned up on page size)
107 class MetaspaceShared : AllStatic {
108
109 // CDS support
110 static ReservedSpace* _shared_rs;
111 static int _max_alignment;
112 static MetaspaceSharedStats _stats;
113 static bool _link_classes_made_progress;
114 static bool _check_classes_made_progress;
115 static bool _has_error_classes;
116 static bool _archive_loading_failed;
117 static bool _remapped_readwrite;
118 static address _cds_i2i_entry_code_buffers;
119 static size_t _cds_i2i_entry_code_buffers_size;
120
121 // Used only during dumping.
122 static SharedMiscRegion _md;
123 static SharedMiscRegion _mc;
124 static SharedMiscRegion _od;
125 public:
126 enum {
127 ro = 0, // read-only shared space in the heap
128 rw = 1, // read-write shared space in the heap
129 md = 2, // miscellaneous data for initializing tables, etc.
130 mc = 3, // miscellaneous code - vtable replacement.
131 max_strings = 2, // max number of string regions in string space
132 num_non_strings = 4, // number of non-string regions
133 first_string = num_non_strings, // index of first string region
134 // The optional data region is the last region.
135 // Currently it only contains class file data.
136 od = max_strings + num_non_strings,
137 n_regions = od + 1 // total number of regions
138 };
139
140 // Accessor functions to save shared space created for metadata, which has
141 // extra space allocated at the end for miscellaneous data and code.
142 static void set_max_alignment(int alignment) {
143 CDS_ONLY(_max_alignment = alignment);
144 }
145
146 static int max_alignment() {
159 NOT_CDS(return NULL);
160 }
161
162 static void initialize_shared_rs(ReservedSpace* rs) NOT_CDS_RETURN;
163
164 static void set_archive_loading_failed() {
165 _archive_loading_failed = true;
166 }
167 static bool map_shared_spaces(FileMapInfo* mapinfo) NOT_CDS_RETURN_(false);
168 static void initialize_shared_spaces() NOT_CDS_RETURN;
169 static void fixup_shared_string_regions() NOT_CDS_RETURN;
170
171 // Return true if given address is in the mapped shared space.
172 static bool is_in_shared_space(const void* p) NOT_CDS_RETURN_(false);
173
174 // Return true if given address is in the shared region corresponding to the idx
175 static bool is_in_shared_region(const void* p, int idx) NOT_CDS_RETURN_(false);
176
177 static bool is_string_region(int idx) NOT_CDS_RETURN_(false);
178
179 private:
180 static intptr_t* allocate_cpp_vtable_clones(intptr_t* md_top, intptr_t* md_end);
181 public:
182 static intptr_t* clone_cpp_vtables(intptr_t* p);
183 static intptr_t* init_cpp_vtable_clones(intptr_t* md_top, intptr_t* md_end);
184 static void zero_cpp_vtable_clones_for_writing();
185 static void patch_cpp_vtable_pointers();
186
187 static void serialize(SerializeClosure* sc, GrowableArray<MemRegion> *string_space,
188 size_t* space_size);
189
190 static MetaspaceSharedStats* stats() {
191 return &_stats;
192 }
193
194 // JVM/TI RedefineClasses() support:
195 // Remap the shared readonly space to shared readwrite, private if
196 // sharing is enabled. Simply returns true if sharing is not enabled
197 // or if the remapping has already been done by a prior call.
198 static bool remap_shared_readonly_as_readwrite() NOT_CDS_RETURN_(true);
199 static bool remapped_readwrite() {
200 CDS_ONLY(return _remapped_readwrite);
201 NOT_CDS(return false);
202 }
203
204 static void print_shared_spaces();
205
206 static bool try_link_class(InstanceKlass* ik, TRAPS);
|