2016-12-11 19:07:04 -08:00
|
|
|
/*
|
2017-02-09 15:43:54 -05:00
|
|
|
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
2016-12-11 19:07:04 -08:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precompiled.hpp"
|
2017-10-31 11:55:09 -04:00
|
|
|
#include "jvm.h"
|
2016-12-11 19:07:04 -08:00
|
|
|
|
|
|
|
#include "aot/aotCodeHeap.hpp"
|
|
|
|
#include "aot/aotLoader.inline.hpp"
|
|
|
|
#include "jvmci/jvmciRuntime.hpp"
|
|
|
|
#include "oops/method.hpp"
|
2017-02-09 15:43:54 -05:00
|
|
|
#include "runtime/os.hpp"
|
2017-07-05 11:03:19 -07:00
|
|
|
#include "runtime/timerTrace.hpp"
|
2016-12-11 19:07:04 -08:00
|
|
|
|
|
|
|
GrowableArray<AOTCodeHeap*>* AOTLoader::_heaps = new(ResourceObj::C_HEAP, mtCode) GrowableArray<AOTCodeHeap*> (2, true);
|
|
|
|
GrowableArray<AOTLib*>* AOTLoader::_libraries = new(ResourceObj::C_HEAP, mtCode) GrowableArray<AOTLib*> (2, true);
|
|
|
|
|
|
|
|
// Iterate over all AOT CodeHeaps
|
|
|
|
#define FOR_ALL_AOT_HEAPS(heap) for (GrowableArrayIterator<AOTCodeHeap*> heap = heaps()->begin(); heap != heaps()->end(); ++heap)
|
|
|
|
// Iterate over all AOT Libraries
|
|
|
|
#define FOR_ALL_AOT_LIBRARIES(lib) for (GrowableArrayIterator<AOTLib*> lib = libraries()->begin(); lib != libraries()->end(); ++lib)
|
|
|
|
|
2017-03-15 10:25:37 -04:00
|
|
|
void AOTLoader::load_for_klass(InstanceKlass* ik, Thread* thread) {
|
2017-10-19 19:23:48 -07:00
|
|
|
if (ik->is_anonymous()) {
|
|
|
|
// don't even bother
|
|
|
|
return;
|
|
|
|
}
|
2016-12-11 19:07:04 -08:00
|
|
|
if (UseAOT) {
|
|
|
|
FOR_ALL_AOT_HEAPS(heap) {
|
2017-03-15 10:25:37 -04:00
|
|
|
(*heap)->load_klass_data(ik, thread);
|
2016-12-11 19:07:04 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t AOTLoader::get_saved_fingerprint(InstanceKlass* ik) {
|
2017-10-19 19:23:48 -07:00
|
|
|
if (ik->is_anonymous()) {
|
|
|
|
// don't even bother
|
|
|
|
return 0;
|
|
|
|
}
|
2016-12-11 19:07:04 -08:00
|
|
|
FOR_ALL_AOT_HEAPS(heap) {
|
|
|
|
AOTKlassData* klass_data = (*heap)->find_klass(ik);
|
|
|
|
if (klass_data != NULL) {
|
|
|
|
return klass_data->_fingerprint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AOTLoader::find_klass(InstanceKlass* ik) {
|
|
|
|
FOR_ALL_AOT_HEAPS(heap) {
|
|
|
|
if ((*heap)->find_klass(ik) != NULL) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AOTLoader::contains(address p) {
|
|
|
|
FOR_ALL_AOT_HEAPS(heap) {
|
|
|
|
if ((*heap)->contains(p)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AOTLoader::oops_do(OopClosure* f) {
|
|
|
|
if (UseAOT) {
|
|
|
|
FOR_ALL_AOT_HEAPS(heap) {
|
|
|
|
(*heap)->oops_do(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AOTLoader::metadata_do(void f(Metadata*)) {
|
|
|
|
if (UseAOT) {
|
|
|
|
FOR_ALL_AOT_HEAPS(heap) {
|
|
|
|
(*heap)->metadata_do(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Flushing and deoptimization in case of evolution
|
2017-03-15 10:25:37 -04:00
|
|
|
void AOTLoader::flush_evol_dependents_on(InstanceKlass* dependee) {
|
2016-12-11 19:07:04 -08:00
|
|
|
// make non entrant and mark for deoptimization
|
|
|
|
FOR_ALL_AOT_HEAPS(heap) {
|
|
|
|
(*heap)->flush_evol_dependents_on(dependee);
|
|
|
|
}
|
|
|
|
Deoptimization::deoptimize_dependents();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of core modules for which we search for shared libraries.
|
|
|
|
*/
|
|
|
|
static const char* modules[] = {
|
|
|
|
"java.base",
|
|
|
|
"java.logging",
|
|
|
|
"jdk.compiler",
|
|
|
|
"jdk.scripting.nashorn",
|
2017-02-16 15:46:09 -08:00
|
|
|
"jdk.internal.vm.ci",
|
|
|
|
"jdk.internal.vm.compiler"
|
2016-12-11 19:07:04 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
void AOTLoader::initialize() {
|
2017-07-05 11:03:19 -07:00
|
|
|
TraceTime timer("AOT initialization", TRACETIME_LOG(Info, aot, startuptime));
|
|
|
|
|
2016-12-11 19:07:04 -08:00
|
|
|
if (FLAG_IS_DEFAULT(UseAOT) && AOTLibrary != NULL) {
|
|
|
|
// Don't need to set UseAOT on command line when AOTLibrary is specified
|
|
|
|
FLAG_SET_DEFAULT(UseAOT, true);
|
|
|
|
}
|
|
|
|
if (UseAOT) {
|
|
|
|
// EagerInitialization is not compatible with AOT
|
|
|
|
if (EagerInitialization) {
|
2016-12-12 21:56:45 -08:00
|
|
|
if (PrintAOT) {
|
|
|
|
warning("EagerInitialization is not compatible with AOT (switching AOT off)");
|
|
|
|
}
|
2016-12-11 19:07:04 -08:00
|
|
|
FLAG_SET_DEFAULT(UseAOT, false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -Xint is not compatible with AOT
|
|
|
|
if (Arguments::is_interpreter_only()) {
|
2016-12-12 21:56:45 -08:00
|
|
|
if (PrintAOT) {
|
|
|
|
warning("-Xint is not compatible with AOT (switching AOT off)");
|
|
|
|
}
|
2016-12-11 19:07:04 -08:00
|
|
|
FLAG_SET_DEFAULT(UseAOT, false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scan the AOTLibrary option.
|
|
|
|
if (AOTLibrary != NULL) {
|
2017-02-09 15:43:54 -05:00
|
|
|
const int len = (int)strlen(AOTLibrary);
|
2016-12-11 19:07:04 -08:00
|
|
|
char* cp = NEW_C_HEAP_ARRAY(char, len+1, mtCode);
|
|
|
|
if (cp != NULL) { // No memory?
|
|
|
|
memcpy(cp, AOTLibrary, len);
|
|
|
|
cp[len] = '\0';
|
|
|
|
char* end = cp + len;
|
|
|
|
while (cp < end) {
|
|
|
|
const char* name = cp;
|
|
|
|
while ((*cp) != '\0' && (*cp) != '\n' && (*cp) != ',' && (*cp) != ':' && (*cp) != ';') cp++;
|
|
|
|
cp[0] = '\0'; // Terminate name
|
|
|
|
cp++;
|
|
|
|
load_library(name, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-29 10:30:51 -08:00
|
|
|
|
|
|
|
// Load well-know AOT libraries from Java installation directory.
|
|
|
|
const char* home = Arguments::get_java_home();
|
|
|
|
const char* file_separator = os::file_separator();
|
|
|
|
|
|
|
|
for (int i = 0; i < (int) (sizeof(modules) / sizeof(const char*)); i++) {
|
|
|
|
char library[JVM_MAXPATHLEN];
|
|
|
|
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());
|
|
|
|
load_library(library, false);
|
|
|
|
}
|
2016-12-11 19:07:04 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AOTLoader::universe_init() {
|
|
|
|
if (UseAOT && libraries_count() > 0) {
|
|
|
|
// Shifts are static values which initialized by 0 until java heap initialization.
|
|
|
|
// AOT libs are loaded before heap initialized so shift values are not set.
|
|
|
|
// It is okay since ObjectAlignmentInBytes flag which defines shifts value is set before AOT libs are loaded.
|
|
|
|
// Set shifts value based on first AOT library config.
|
|
|
|
if (UseCompressedOops && AOTLib::narrow_oop_shift_initialized()) {
|
|
|
|
int oop_shift = Universe::narrow_oop_shift();
|
|
|
|
if (oop_shift == 0) {
|
|
|
|
Universe::set_narrow_oop_shift(AOTLib::narrow_oop_shift());
|
|
|
|
} else {
|
|
|
|
FOR_ALL_AOT_LIBRARIES(lib) {
|
|
|
|
(*lib)->verify_flag(AOTLib::narrow_oop_shift(), oop_shift, "Universe::narrow_oop_shift");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (UseCompressedClassPointers) { // It is set only if UseCompressedOops is set
|
|
|
|
int klass_shift = Universe::narrow_klass_shift();
|
|
|
|
if (klass_shift == 0) {
|
|
|
|
Universe::set_narrow_klass_shift(AOTLib::narrow_klass_shift());
|
|
|
|
} else {
|
|
|
|
FOR_ALL_AOT_LIBRARIES(lib) {
|
|
|
|
(*lib)->verify_flag(AOTLib::narrow_klass_shift(), klass_shift, "Universe::narrow_klass_shift");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Create heaps for all the libraries
|
|
|
|
FOR_ALL_AOT_LIBRARIES(lib) {
|
|
|
|
if ((*lib)->is_valid()) {
|
|
|
|
AOTCodeHeap* heap = new AOTCodeHeap(*lib);
|
|
|
|
{
|
|
|
|
MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
|
|
|
|
add_heap(heap);
|
|
|
|
CodeCache::add_heap(heap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (heaps_count() == 0) {
|
|
|
|
if (FLAG_IS_DEFAULT(UseAOT)) {
|
|
|
|
FLAG_SET_DEFAULT(UseAOT, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AOTLoader::set_narrow_klass_shift() {
|
|
|
|
// This method could be called from Metaspace::set_narrow_klass_base_and_shift().
|
|
|
|
// In case it is not called (during dump CDS, for example) the corresponding code in
|
|
|
|
// AOTLoader::universe_init(), which is called later, will set the shift value.
|
|
|
|
if (UseAOT && libraries_count() > 0 &&
|
|
|
|
UseCompressedOops && AOTLib::narrow_oop_shift_initialized() &&
|
|
|
|
UseCompressedClassPointers) {
|
|
|
|
int klass_shift = Universe::narrow_klass_shift();
|
|
|
|
if (klass_shift == 0) {
|
|
|
|
Universe::set_narrow_klass_shift(AOTLib::narrow_klass_shift());
|
|
|
|
} else {
|
|
|
|
FOR_ALL_AOT_LIBRARIES(lib) {
|
|
|
|
(*lib)->verify_flag(AOTLib::narrow_klass_shift(), klass_shift, "Universe::narrow_klass_shift");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AOTLoader::load_library(const char* name, bool exit_on_error) {
|
2017-11-29 10:30:51 -08:00
|
|
|
// Skip library if a library with the same name is already loaded.
|
|
|
|
const int file_separator = *os::file_separator();
|
|
|
|
const char* start = strrchr(name, file_separator);
|
|
|
|
const char* new_name = (start == NULL) ? name : (start + 1);
|
|
|
|
FOR_ALL_AOT_LIBRARIES(lib) {
|
|
|
|
const char* lib_name = (*lib)->name();
|
|
|
|
start = strrchr(lib_name, file_separator);
|
|
|
|
const char* old_name = (start == NULL) ? lib_name : (start + 1);
|
|
|
|
if (strcmp(old_name, new_name) == 0) {
|
|
|
|
if (PrintAOT) {
|
|
|
|
warning("AOT library %s is already loaded as %s.", name, lib_name);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-02-09 15:43:54 -05:00
|
|
|
char ebuf[1024];
|
|
|
|
void* handle = os::dll_load(name, ebuf, sizeof ebuf);
|
2016-12-11 19:07:04 -08:00
|
|
|
if (handle == NULL) {
|
|
|
|
if (exit_on_error) {
|
2017-02-09 15:43:54 -05:00
|
|
|
tty->print_cr("error opening file: %s", ebuf);
|
2016-12-11 19:07:04 -08:00
|
|
|
vm_exit(1);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const int dso_id = libraries_count() + 1;
|
|
|
|
AOTLib* lib = new AOTLib(handle, name, dso_id);
|
|
|
|
if (!lib->is_valid()) {
|
|
|
|
delete lib;
|
2017-02-09 15:43:54 -05:00
|
|
|
os::dll_unload(handle);
|
2016-12-11 19:07:04 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
add_library(lib);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef PRODUCT
|
|
|
|
void AOTLoader::print_statistics() {
|
|
|
|
{ ttyLocker ttyl;
|
|
|
|
tty->print_cr("--- AOT Statistics ---");
|
|
|
|
tty->print_cr("AOT libraries loaded: %d", heaps_count());
|
|
|
|
AOTCodeHeap::print_statistics();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2017-10-19 19:23:48 -07:00
|
|
|
|
|
|
|
|
|
|
|
bool AOTLoader::reconcile_dynamic_invoke(InstanceKlass* holder, int index, Method* adapter_method, Klass* appendix_klass) {
|
|
|
|
if (!UseAOT) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
JavaThread* thread = JavaThread::current();
|
|
|
|
ResourceMark rm(thread);
|
|
|
|
RegisterMap map(thread, false);
|
|
|
|
frame caller_frame = thread->last_frame().sender(&map); // Skip stub
|
|
|
|
CodeBlob* caller_cb = caller_frame.cb();
|
|
|
|
guarantee(caller_cb != NULL && caller_cb->is_compiled(), "must be called from compiled method");
|
|
|
|
CompiledMethod* cm = caller_cb->as_compiled_method();
|
|
|
|
|
|
|
|
if (!cm->is_aot()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
AOTCompiledMethod* aot = (AOTCompiledMethod*)cm;
|
|
|
|
|
|
|
|
AOTCodeHeap* caller_heap = NULL;
|
|
|
|
FOR_ALL_AOT_HEAPS(heap) {
|
|
|
|
if ((*heap)->contains_blob(aot)) {
|
|
|
|
caller_heap = *heap;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
guarantee(caller_heap != NULL, "CodeHeap not found");
|
|
|
|
bool success = caller_heap->reconcile_dynamic_invoke(aot, holder, index, adapter_method, appendix_klass);
|
|
|
|
vmassert(success || thread->last_frame().sender(&map).is_deoptimized_frame(), "caller not deoptimized on failure");
|
|
|
|
return success;
|
|
|
|
}
|