1 /*
2 * Copyright (c) 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 #include "precompiled.hpp"
25
26 #include "aot/aotCodeHeap.hpp"
27 #include "aot/aotLoader.inline.hpp"
28 #include "jvmci/jvmciRuntime.hpp"
29 #include "oops/method.hpp"
30
31 GrowableArray<AOTCodeHeap*>* AOTLoader::_heaps = new(ResourceObj::C_HEAP, mtCode) GrowableArray<AOTCodeHeap*> (2, true);
32 GrowableArray<AOTLib*>* AOTLoader::_libraries = new(ResourceObj::C_HEAP, mtCode) GrowableArray<AOTLib*> (2, true);
33
34 // Iterate over all AOT CodeHeaps
35 #define FOR_ALL_AOT_HEAPS(heap) for (GrowableArrayIterator<AOTCodeHeap*> heap = heaps()->begin(); heap != heaps()->end(); ++heap)
36 // Iterate over all AOT Libraries
37 #define FOR_ALL_AOT_LIBRARIES(lib) for (GrowableArrayIterator<AOTLib*> lib = libraries()->begin(); lib != libraries()->end(); ++lib)
38
39 void AOTLoader::load_for_klass(instanceKlassHandle kh, Thread* thread) {
40 if (UseAOT) {
41 FOR_ALL_AOT_HEAPS(heap) {
42 (*heap)->load_klass_data(kh, thread);
43 }
44 }
45 }
46
47 uint64_t AOTLoader::get_saved_fingerprint(InstanceKlass* ik) {
48 FOR_ALL_AOT_HEAPS(heap) {
49 AOTKlassData* klass_data = (*heap)->find_klass(ik);
129 warning("EagerInitialization is not compatible with AOT (switching AOT off)");
130 }
131 FLAG_SET_DEFAULT(UseAOT, false);
132 return;
133 }
134
135 // -Xint is not compatible with AOT
136 if (Arguments::is_interpreter_only()) {
137 if (PrintAOT) {
138 warning("-Xint is not compatible with AOT (switching AOT off)");
139 }
140 FLAG_SET_DEFAULT(UseAOT, false);
141 return;
142 }
143
144 const char* home = Arguments::get_java_home();
145 const char* file_separator = os::file_separator();
146
147 for (int i = 0; i < (int) (sizeof(modules) / sizeof(const char*)); i++) {
148 char library[JVM_MAXPATHLEN];
149 jio_snprintf(library, sizeof(library), "%s%slib%slib%s%s%s.so", home, file_separator, file_separator, modules[i], UseCompressedOops ? "-coop" : "", UseG1GC ? "" : "-nong1");
150 load_library(library, false);
151 }
152
153 // Scan the AOTLibrary option.
154 if (AOTLibrary != NULL) {
155 const int len = strlen(AOTLibrary);
156 char* cp = NEW_C_HEAP_ARRAY(char, len+1, mtCode);
157 if (cp != NULL) { // No memory?
158 memcpy(cp, AOTLibrary, len);
159 cp[len] = '\0';
160 char* end = cp + len;
161 while (cp < end) {
162 const char* name = cp;
163 while ((*cp) != '\0' && (*cp) != '\n' && (*cp) != ',' && (*cp) != ':' && (*cp) != ';') cp++;
164 cp[0] = '\0'; // Terminate name
165 cp++;
166 load_library(name, true);
167 }
168 }
169 }
170 }
171 }
172
173 void AOTLoader::universe_init() {
174 if (UseAOT && libraries_count() > 0) {
175 // Shifts are static values which initialized by 0 until java heap initialization.
217
218 void AOTLoader::set_narrow_klass_shift() {
219 // This method could be called from Metaspace::set_narrow_klass_base_and_shift().
220 // In case it is not called (during dump CDS, for example) the corresponding code in
221 // AOTLoader::universe_init(), which is called later, will set the shift value.
222 if (UseAOT && libraries_count() > 0 &&
223 UseCompressedOops && AOTLib::narrow_oop_shift_initialized() &&
224 UseCompressedClassPointers) {
225 int klass_shift = Universe::narrow_klass_shift();
226 if (klass_shift == 0) {
227 Universe::set_narrow_klass_shift(AOTLib::narrow_klass_shift());
228 } else {
229 FOR_ALL_AOT_LIBRARIES(lib) {
230 (*lib)->verify_flag(AOTLib::narrow_klass_shift(), klass_shift, "Universe::narrow_klass_shift");
231 }
232 }
233 }
234 }
235
236 void AOTLoader::load_library(const char* name, bool exit_on_error) {
237 void* handle = dlopen(name, RTLD_LAZY);
238 if (handle == NULL) {
239 if (exit_on_error) {
240 tty->print_cr("error opening file: %s", dlerror());
241 vm_exit(1);
242 }
243 return;
244 }
245 const int dso_id = libraries_count() + 1;
246 AOTLib* lib = new AOTLib(handle, name, dso_id);
247 if (!lib->is_valid()) {
248 delete lib;
249 dlclose(handle);
250 return;
251 }
252 add_library(lib);
253 }
254
255 #ifndef PRODUCT
256 void AOTLoader::print_statistics() {
257 { ttyLocker ttyl;
258 tty->print_cr("--- AOT Statistics ---");
259 tty->print_cr("AOT libraries loaded: %d", heaps_count());
260 AOTCodeHeap::print_statistics();
261 }
262 }
263 #endif
|
1 /*
2 * Copyright (c) 2016, 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 #include "precompiled.hpp"
25
26 #include "aot/aotCodeHeap.hpp"
27 #include "aot/aotLoader.inline.hpp"
28 #include "jvmci/jvmciRuntime.hpp"
29 #include "oops/method.hpp"
30 #include "runtime/os.hpp"
31
32 GrowableArray<AOTCodeHeap*>* AOTLoader::_heaps = new(ResourceObj::C_HEAP, mtCode) GrowableArray<AOTCodeHeap*> (2, true);
33 GrowableArray<AOTLib*>* AOTLoader::_libraries = new(ResourceObj::C_HEAP, mtCode) GrowableArray<AOTLib*> (2, true);
34
35 // Iterate over all AOT CodeHeaps
36 #define FOR_ALL_AOT_HEAPS(heap) for (GrowableArrayIterator<AOTCodeHeap*> heap = heaps()->begin(); heap != heaps()->end(); ++heap)
37 // Iterate over all AOT Libraries
38 #define FOR_ALL_AOT_LIBRARIES(lib) for (GrowableArrayIterator<AOTLib*> lib = libraries()->begin(); lib != libraries()->end(); ++lib)
39
40 void AOTLoader::load_for_klass(instanceKlassHandle kh, Thread* thread) {
41 if (UseAOT) {
42 FOR_ALL_AOT_HEAPS(heap) {
43 (*heap)->load_klass_data(kh, thread);
44 }
45 }
46 }
47
48 uint64_t AOTLoader::get_saved_fingerprint(InstanceKlass* ik) {
49 FOR_ALL_AOT_HEAPS(heap) {
50 AOTKlassData* klass_data = (*heap)->find_klass(ik);
130 warning("EagerInitialization is not compatible with AOT (switching AOT off)");
131 }
132 FLAG_SET_DEFAULT(UseAOT, false);
133 return;
134 }
135
136 // -Xint is not compatible with AOT
137 if (Arguments::is_interpreter_only()) {
138 if (PrintAOT) {
139 warning("-Xint is not compatible with AOT (switching AOT off)");
140 }
141 FLAG_SET_DEFAULT(UseAOT, false);
142 return;
143 }
144
145 const char* home = Arguments::get_java_home();
146 const char* file_separator = os::file_separator();
147
148 for (int i = 0; i < (int) (sizeof(modules) / sizeof(const char*)); i++) {
149 char library[JVM_MAXPATHLEN];
150 jio_snprintf(library, sizeof(library), "%s%slib%slib%s%s%s%s", home, file_separator, file_separator, modules[i], UseCompressedOops ? "-coop" : "", UseG1GC ? "" : "-nong1", os::dll_file_extension());
151 load_library(library, false);
152 }
153
154 // Scan the AOTLibrary option.
155 if (AOTLibrary != NULL) {
156 const int len = (int)strlen(AOTLibrary);
157 char* cp = NEW_C_HEAP_ARRAY(char, len+1, mtCode);
158 if (cp != NULL) { // No memory?
159 memcpy(cp, AOTLibrary, len);
160 cp[len] = '\0';
161 char* end = cp + len;
162 while (cp < end) {
163 const char* name = cp;
164 while ((*cp) != '\0' && (*cp) != '\n' && (*cp) != ',' && (*cp) != ':' && (*cp) != ';') cp++;
165 cp[0] = '\0'; // Terminate name
166 cp++;
167 load_library(name, true);
168 }
169 }
170 }
171 }
172 }
173
174 void AOTLoader::universe_init() {
175 if (UseAOT && libraries_count() > 0) {
176 // Shifts are static values which initialized by 0 until java heap initialization.
218
219 void AOTLoader::set_narrow_klass_shift() {
220 // This method could be called from Metaspace::set_narrow_klass_base_and_shift().
221 // In case it is not called (during dump CDS, for example) the corresponding code in
222 // AOTLoader::universe_init(), which is called later, will set the shift value.
223 if (UseAOT && libraries_count() > 0 &&
224 UseCompressedOops && AOTLib::narrow_oop_shift_initialized() &&
225 UseCompressedClassPointers) {
226 int klass_shift = Universe::narrow_klass_shift();
227 if (klass_shift == 0) {
228 Universe::set_narrow_klass_shift(AOTLib::narrow_klass_shift());
229 } else {
230 FOR_ALL_AOT_LIBRARIES(lib) {
231 (*lib)->verify_flag(AOTLib::narrow_klass_shift(), klass_shift, "Universe::narrow_klass_shift");
232 }
233 }
234 }
235 }
236
237 void AOTLoader::load_library(const char* name, bool exit_on_error) {
238 char ebuf[1024];
239 void* handle = os::dll_load(name, ebuf, sizeof ebuf);
240 if (handle == NULL) {
241 if (exit_on_error) {
242 tty->print_cr("error opening file: %s", ebuf);
243 vm_exit(1);
244 }
245 return;
246 }
247 const int dso_id = libraries_count() + 1;
248 AOTLib* lib = new AOTLib(handle, name, dso_id);
249 if (!lib->is_valid()) {
250 delete lib;
251 os::dll_unload(handle);
252 return;
253 }
254 add_library(lib);
255 }
256
257 #ifndef PRODUCT
258 void AOTLoader::print_statistics() {
259 { ttyLocker ttyl;
260 tty->print_cr("--- AOT Statistics ---");
261 tty->print_cr("AOT libraries loaded: %d", heaps_count());
262 AOTCodeHeap::print_statistics();
263 }
264 }
265 #endif
|