-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8247536: Support for pre-generated java.lang.invoke classes in CDS static archive #193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
7c1df12
8252689: Classes are loaded from jrt:/java.base even when CDS is used
ee27088
8252689: Classes are loaded from jrt:/java.base even when CDS is used
395b490
8252689: Classes are loaded from jrt:/java.base even when CDS is used
09a6d9e
Merge remote-tracking branch 'origin/jdk-8252689'
d934b88
Merge remote-tracking branch 'upstream/master' into jdk-8247536
89c9a2e
Merge remote-tracking branch 'upstream/master' into jdk-8247536
0aa0498
8247536: Support for pre-generated java.lang.invoke classes in CDS st…
90b4927
Merge branch 'master' of https://github.com/openjdk/jdk
ebe54c9
Merge branch 'master' of https://github.com/openjdk/jdk
896f111
Merge branch 'master' into jdk-8247536
f45f364
8247536: Support for pre-generated java.lang.invoke classes in CDS st…
b195527
8247536: Support for pre-generated java.lang.invoke classes in CDS st…
4148e7d
8247536: Support for pre-generated java.lang.invoke classes in CDS st…
01b229c
Merge branch 'master' of https://git.openjdk.java.net/jdk into jdk-82…
9768c24
Merge branch 'master' of https://github.com/openjdk/jdk into jdk-8247536
9ab5211
In case of exception happens during reloading class, CHECK will retur…
9b0f523
Remove trailing word of line which is not used in holder class regene…
125112b
Move the check work to java, restore code in VM. Modified test code a…
52764a6
Moved and renamed cdsGenerateHolderClasses from GenerateJLIClassesHel…
686e211
Fixed comments with correct class and method name in CDS, removed unu…
5d32a54
Removed unused imports.
5f6b68c
Merge branch 'master' of https://github.com/openjdk/jdk into jdk-8247536
f5584dc
Added new separate function to CDS for logging species and modified t…
107192f
Move assert on klass is InstanceKlass after its NULL check. Added san…
f163fe4
Made isDumpingClassList a private final and add a public function to …
16362e1
Changed isValidInputLines to validateInputLines and throw IAE upon wr…
3120f4c
Make change to original indent
624092e
Removed try/catch from java side and moved output to vm.
2184725
Correct typo for check message
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
/* | ||
* Copyright (c) 2020, 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. | ||
* | ||
*/ | ||
|
||
#include "precompiled.hpp" | ||
#include "classfile/classLoadInfo.hpp" | ||
#include "classfile/classFileStream.hpp" | ||
#include "classfile/dictionary.hpp" | ||
#include "classfile/javaClasses.inline.hpp" | ||
#include "classfile/klassFactory.hpp" | ||
#include "classfile/lambdaFormInvokers.hpp" | ||
#include "classfile/symbolTable.hpp" | ||
#include "classfile/systemDictionary.hpp" | ||
#include "classfile/systemDictionaryShared.hpp" | ||
#include "classfile/vmSymbols.hpp" | ||
#include "logging/log.hpp" | ||
#include "memory/oopFactory.hpp" | ||
#include "memory/metaspaceShared.hpp" | ||
#include "memory/resourceArea.hpp" | ||
#include "oops/instanceKlass.hpp" | ||
#include "oops/klass.hpp" | ||
#include "oops/objArrayKlass.hpp" | ||
#include "oops/objArrayOop.hpp" | ||
#include "oops/oop.inline.hpp" | ||
#include "oops/typeArrayOop.inline.hpp" | ||
#include "runtime/handles.inline.hpp" | ||
#include "runtime/javaCalls.hpp" | ||
|
||
GrowableArray<char*>* LambdaFormInvokers::_lambdaform_lines = NULL; | ||
|
||
void LambdaFormInvokers::append(char* line) { | ||
if (_lambdaform_lines == NULL) { | ||
_lambdaform_lines = new GrowableArray<char*>(100); | ||
} | ||
_lambdaform_lines->append(line); | ||
} | ||
|
||
void LambdaFormInvokers::regenerate_holder_classes(TRAPS) { | ||
assert(_lambdaform_lines != NULL, "Bad List"); | ||
ResourceMark rm(THREAD); | ||
|
||
Symbol* cds_name = vmSymbols::jdk_internal_misc_CDS(); | ||
Klass* cds_klass = SystemDictionary::resolve_or_null(cds_name, THREAD); | ||
guarantee(cds_klass != NULL, "jdk/internal/misc/CDS must exist!"); | ||
|
||
int len = _lambdaform_lines->length(); | ||
objArrayHandle list_lines = oopFactory::new_objArray_handle(SystemDictionary::String_klass(), len, CHECK); | ||
for (int i = 0; i < len; i++) { | ||
char* record = _lambdaform_lines->at(i); | ||
record += strlen(lambda_form_invoker_tag()) + 1; // skip the @lambda_form_invoker prefix | ||
Handle h_line = java_lang_String::create_from_str(record, CHECK); | ||
list_lines->obj_at_put(i, h_line()); | ||
} | ||
|
||
// | ||
// Object[] CDS.generateLambdaFormHolderClasses(String[] lines) | ||
// the returned Object[] layout: | ||
// name, byte[], name, byte[] .... | ||
Symbol* method = vmSymbols::generateLambdaFormHolderClasses(); | ||
Symbol* signrs = vmSymbols::generateLambdaFormHolderClasses_signature(); | ||
|
||
JavaValue result(T_OBJECT); | ||
JavaCalls::call_static(&result, cds_klass, method, signrs, list_lines, THREAD); | ||
|
||
if (HAS_PENDING_EXCEPTION) { | ||
log_info(cds)("%s: %s", THREAD->pending_exception()->klass()->external_name(), | ||
java_lang_String::as_utf8_string(java_lang_Throwable::message(THREAD->pending_exception()))); | ||
CLEAR_PENDING_EXCEPTION; | ||
return; | ||
} | ||
|
||
objArrayHandle h_array(THREAD, (objArrayOop)result.get_jobject()); | ||
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()); | ||
int len = h_bytes->length(); | ||
// make a copy of class bytes so GC will not affect us. | ||
char *buf = resource_allocate_bytes(THREAD, len); | ||
memcpy(buf, (char*)h_bytes->byte_at_addr(0), len); | ||
ClassFileStream st((u1*)buf, len, NULL, ClassFileStream::verify); | ||
|
||
reload_class(class_name, st, THREAD); | ||
// free buf | ||
resource_free_bytes(buf, len); | ||
|
||
if (HAS_PENDING_EXCEPTION) { | ||
log_info(cds)("Exception happened: %s", PENDING_EXCEPTION->klass()->name()->as_C_string()); | ||
log_info(cds)("Could not create InstanceKlass for class %s", class_name); | ||
CLEAR_PENDING_EXCEPTION; | ||
return; | ||
} | ||
} | ||
} | ||
|
||
// class_handle - the class name, bytes_handle - the class bytes | ||
void LambdaFormInvokers::reload_class(char* name, ClassFileStream& st, TRAPS) { | ||
Symbol* class_name = SymbolTable::new_symbol((const char*)name); | ||
// the class must exist | ||
Klass* klass = SystemDictionary::resolve_or_null(class_name, THREAD); | ||
if (klass == NULL) { | ||
log_info(cds)("Class %s not present, skip", name); | ||
return; | ||
} | ||
yminqi marked this conversation as resolved.
Show resolved
Hide resolved
yminqi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert(klass->is_instance_klass(), "Should be"); | ||
|
||
ClassLoaderData* cld = ClassLoaderData::the_null_class_loader_data(); | ||
Handle protection_domain; | ||
ClassLoadInfo cl_info(protection_domain); | ||
|
||
InstanceKlass* result = KlassFactory::create_from_stream(&st, | ||
class_name, | ||
cld, | ||
cl_info, | ||
CHECK); | ||
|
||
{ | ||
MutexLocker mu_r(THREAD, Compile_lock); // add_to_hierarchy asserts this. | ||
SystemDictionary::add_to_hierarchy(result, THREAD); | ||
} | ||
// new class not linked yet. | ||
MetaspaceShared::try_link_class(result, THREAD); | ||
assert(!HAS_PENDING_EXCEPTION, "Invariant"); | ||
|
||
// exclude the existing class from dump | ||
SystemDictionaryShared::set_excluded(InstanceKlass::cast(klass)); | ||
log_info(cds)("Replaced class %s, old: %p new: %p", name, klass, result); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2020, 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. | ||
* | ||
*/ | ||
|
||
#ifndef SHARE_MEMORY_LAMBDAFORMINVOKERS_HPP | ||
#define SHARE_MEMORY_LAMBDAFORMINVOKERS_HPP | ||
#include "memory/allStatic.hpp" | ||
#include "runtime/handles.hpp" | ||
|
||
template <class T> | ||
class GrowableArray; | ||
class ClassFileStream; | ||
|
||
class LambdaFormInvokers : public AllStatic { | ||
private: | ||
static GrowableArray<char*>* _lambdaform_lines; | ||
static void reload_class(char* name, ClassFileStream& st, TRAPS); | ||
public: | ||
|
||
static void append(char* line); | ||
static void regenerate_holder_classes(TRAPS); | ||
static GrowableArray<char*>* lambdaform_lines() { | ||
return _lambdaform_lines; | ||
} | ||
|
||
static const char* lambda_form_invoker_tag() { | ||
return "@lambda-form-invoker"; | ||
} | ||
}; | ||
#endif // SHARE_MEMORY_LAMBDAFORMINVOKERS_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.