-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8362306: HotSpotJVMCIRuntime.getMirror can crash #26346
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
6 commits
Select commit
Hold shift + click to select a range
cca137a
fixed bug in HotSpotJVMCIRuntime.getMirror for <clinit> and injected …
dougxc c2c41aa
moved inject field check into check_field for benefit of get_encoded_…
dougxc c76efe5
fixed bug in use of JVMCI traps
dougxc 7cf4b26
revert from JVMCI_CHECK_NULL back to JVMCIENV in final return stateme…
dougxc fd44d95
test that getMirror on clinit returns null
dougxc d62c74d
replaced use of JVMCIENV with JVMCI_CHECK_NULL in getDeclaredFieldsInfo
dougxc 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2277,7 +2277,7 @@ C2V_VMENTRY_NULL(jobjectArray, getDeclaredFieldsInfo, (JNIEnv* env, jobject, ARG | |
| InstanceKlass* iklass = InstanceKlass::cast(klass); | ||
| int java_fields, injected_fields; | ||
| GrowableArray<FieldInfo>* fields = FieldInfoStream::create_FieldInfoArray(iklass->fieldinfo_stream(), &java_fields, &injected_fields); | ||
| JVMCIObjectArray array = JVMCIENV->new_FieldInfo_array(fields->length(), JVMCIENV); | ||
| JVMCIObjectArray array = JVMCIENV->new_FieldInfo_array(fields->length(), JVMCI_CHECK_NULL); | ||
| for (int i = 0; i < fields->length(); i++) { | ||
| JVMCIObject field_info = JVMCIENV->new_FieldInfo(fields->adr_at(i), JVMCI_CHECK_NULL); | ||
| JVMCIENV->put_object_at(array, i, field_info); | ||
|
|
@@ -2984,13 +2984,21 @@ C2V_VMENTRY_NULL(jobject, asReflectionExecutable, (JNIEnv* env, jobject, ARGUMEN | |
| return JNIHandles::make_local(THREAD, executable); | ||
| C2V_END | ||
|
|
||
| // Checks that `index` denotes a non-injected field in `klass` | ||
| static InstanceKlass* check_field(Klass* klass, jint index, JVMCI_TRAPS) { | ||
| if (!klass->is_instance_klass()) { | ||
| JVMCI_THROW_MSG_NULL(IllegalArgumentException, | ||
| err_msg("Expected non-primitive type, got %s", klass->external_name())); | ||
| } | ||
| InstanceKlass* iklass = InstanceKlass::cast(klass); | ||
| if (index < 0 || index > iklass->total_fields_count()) { | ||
| if (index < 0 || index >= iklass->java_fields_count()) { | ||
| if (index >= 0 && index < iklass->total_fields_count()) { | ||
| fieldDescriptor fd(iklass, index); | ||
| if (fd.is_injected()) { | ||
| JVMCI_THROW_MSG_NULL(IllegalArgumentException, | ||
| err_msg("Cannot get Field for injected %s.%s", klass->external_name(), fd.name()->as_C_string())); | ||
| } | ||
| } | ||
| JVMCI_THROW_MSG_NULL(IllegalArgumentException, | ||
| err_msg("Field index %d out of bounds for %s", index, klass->external_name())); | ||
| } | ||
|
|
@@ -3000,15 +3008,15 @@ static InstanceKlass* check_field(Klass* klass, jint index, JVMCI_TRAPS) { | |
| C2V_VMENTRY_NULL(jobject, asReflectionField, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), jint index)) | ||
| requireInHotSpot("asReflectionField", JVMCI_CHECK_NULL); | ||
| Klass* klass = UNPACK_PAIR(Klass, klass); | ||
| InstanceKlass* iklass = check_field(klass, index, JVMCIENV); | ||
| InstanceKlass* iklass = check_field(klass, index, JVMCI_CHECK_NULL); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's another copy of this idiom in getDeclaredFieldsInfo which might be worth fixing. |
||
| fieldDescriptor fd(iklass, index); | ||
| oop reflected = Reflection::new_field(&fd, CHECK_NULL); | ||
| return JNIHandles::make_local(THREAD, reflected); | ||
| C2V_END | ||
|
|
||
| static jbyteArray get_encoded_annotation_data(InstanceKlass* holder, AnnotationArray* annotations_array, bool for_class, | ||
| jint filter_length, jlong filter_klass_pointers, | ||
| JavaThread* THREAD, JVMCIEnv* JVMCIENV) { | ||
| JavaThread* THREAD, JVMCI_TRAPS) { | ||
| // Get a ConstantPool object for annotation parsing | ||
| Handle jcp = reflect_ConstantPool::create(CHECK_NULL); | ||
| reflect_ConstantPool::set_cp(jcp(), holder->constants()); | ||
|
|
@@ -3086,7 +3094,7 @@ C2V_END | |
| C2V_VMENTRY_NULL(jbyteArray, getEncodedFieldAnnotationData, (JNIEnv* env, jobject, ARGUMENT_PAIR(klass), jint index, | ||
| jobject filter, jint filter_length, jlong filter_klass_pointers)) | ||
| CompilerThreadCanCallJava canCallJava(thread, true); // Requires Java support | ||
| InstanceKlass* holder = check_field(InstanceKlass::cast(UNPACK_PAIR(Klass, klass)), index, JVMCIENV); | ||
| InstanceKlass* holder = check_field(InstanceKlass::cast(UNPACK_PAIR(Klass, klass)), index, JVMCI_CHECK_NULL); | ||
| fieldDescriptor fd(holder, index); | ||
| return get_encoded_annotation_data(holder, fd.annotations(), false, filter_length, filter_klass_pointers, THREAD, JVMCIENV); | ||
| C2V_END | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is the same pattern in
getEncodedFieldAnnotationData, we should probably defend there as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point: c2c41aa