/* * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. * 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. *
*/
staticbool should_be_archived(char* line) { for (int k = 0; k < NUM_FILTER; k++) { if (strstr(line, filter[k]) != nullptr) { returntrue;
}
} returnfalse;
} #undef NUM_FILTER
void LambdaFormInvokers::append(char* line) {
MutexLocker ml(Thread::current(), LambdaFormInvokers_lock); if (_lambdaform_lines == NULL) {
_lambdaform_lines = new GrowableArrayCHeap<char*, mtClassShared>(150);
}
_lambdaform_lines->append(line);
}
// The regenerated Klass is not added to any class loader, so we need // to keep its java_mirror alive to avoid class unloading. void LambdaFormInvokers::add_regenerated_class(oop regenerated_class) { if (_regenerated_mirrors == nullptr) {
_regenerated_mirrors = new GrowableArrayCHeap<OopHandle, mtClassShared>(150);
}
_regenerated_mirrors->append(OopHandle(Universe::vm_global(), regenerated_class));
}
void LambdaFormInvokers::cleanup_regenerated_classes() { if (_regenerated_mirrors == nullptr) return;
for (int i = 0; i < _regenerated_mirrors->length(); i++) {
_regenerated_mirrors->at(i).release(Universe::vm_global());
} delete _regenerated_mirrors;
_regenerated_mirrors = nullptr;
}
if (HAS_PENDING_EXCEPTION) { if (!PENDING_EXCEPTION->is_a(vmClasses::OutOfMemoryError_klass())) {
log_error(cds)("%s: %s", PENDING_EXCEPTION->klass()->external_name(),
java_lang_String::as_utf8_string(java_lang_Throwable::message(PENDING_EXCEPTION))); if (DumpSharedSpaces) {
log_error(cds)("Failed to generate LambdaForm holder classes. Is your classlist out of date?");
} else {
log_error(cds)("Failed to generate LambdaForm holder classes. Was the base archive generated with an outdated classlist?");
}
CLEAR_PENDING_EXCEPTION;
} return;
}
objArrayHandle h_array(THREAD, (objArrayOop)result.get_oop()); int sz = h_array->length();
assert(sz % 2 == 0 && sz >= 2, "Must be even size of length"); for (int i = 0; i < sz; i+= 2) {
Handle h_name(THREAD, h_array->obj_at(i));
typeArrayHandle h_bytes(THREAD, (typeArrayOop)h_array->obj_at(i+1));
assert(h_name != NULL, "Class name is NULL");
assert(h_bytes != NULL, "Class bytes is NULL");
char *class_name = java_lang_String::as_utf8_string(h_name()); if (strstr(class_name, "java/lang/invoke/BoundMethodHandle$Species_") != nullptr) { // The species classes are already loaded into the system dictionary // during the execution of CDS.generateLambdaFormHolderClasses(). No // need to regenerate.
TempNewSymbol class_name_sym = SymbolTable::new_symbol(class_name);
Klass* klass = SystemDictionary::resolve_or_null(class_name_sym, THREAD);
assert(klass != NULL, "must already be loaded"); if (!klass->is_shared() && klass->shared_classpath_index() < 0) { // Fake it, so that it will be included into the archive.
klass->set_shared_classpath_index(0); // Set the "generated" bit, so it won't interfere with JVMTI. // See SystemDictionaryShared::find_builtin_class().
klass->set_is_generated_shared_class();
}
} else { int len = h_bytes->length(); // make a copy of class bytes so GC will not affect us. char *buf = NEW_RESOURCE_ARRAY(char, len);
memcpy(buf, (char*)h_bytes->byte_at_addr(0), len);
ClassFileStream st((u1*)buf, len, NULL, ClassFileStream::verify);
regenerate_class(class_name, st, CHECK);
}
}
}
{
MutexLocker mu_r(THREAD, Compile_lock); // add_to_hierarchy asserts this.
SystemDictionary::add_to_hierarchy(result);
} // new class not linked yet.
MetaspaceShared::try_link_class(THREAD, result);
assert(!HAS_PENDING_EXCEPTION, "Invariant");
result->set_is_generated_shared_class(); if (!klass->is_shared()) {
SystemDictionaryShared::set_excluded(InstanceKlass::cast(klass)); // exclude the existing class from dump
}
log_info(cds, lambda)("Regenerated class %s, old: " INTPTR_FORMAT " new: " INTPTR_FORMAT,
class_name, p2i(klass), p2i(result));
}
void LambdaFormInvokers::dump_static_archive_invokers() { if (_lambdaform_lines != nullptr && _lambdaform_lines->length() > 0) { int count = 0; int len = _lambdaform_lines->length(); for (int i = 0; i < len; i++) { char* str = _lambdaform_lines->at(i); if (should_be_archived(str)) {
count++;
}
} if (count > 0) {
_static_archive_invokers = ArchiveBuilder::new_ro_array<Array<char>*>(count); int index = 0; for (int i = 0; i < len; i++) { char* str = _lambdaform_lines->at(i); if (should_be_archived(str)) {
size_t str_len = strlen(str) + 1; // including terminating zero
Array<char>* line = ArchiveBuilder::new_ro_array<char>((int)str_len);
strncpy(line->adr_at(0), str, str_len);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.