Skip to content
10 changes: 5 additions & 5 deletions src/hotspot/share/jvmci/jvmciCompilerToVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,24 +697,24 @@ C2V_VMENTRY_NULL(jobject, getUncachedStringInPool, (JNIEnv* env, jobject, ARGUME
return JVMCIENV->get_jobject(JVMCIENV->get_object_constant(obj));
C2V_END

C2V_VMENTRY_NULL(jobject, lookupConstantInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint index, bool resolve))
C2V_VMENTRY_NULL(jobject, lookupConstantInPool, (JNIEnv* env, jobject, ARGUMENT_PAIR(cp), jint cp_index, bool resolve))
constantPoolHandle cp(THREAD, UNPACK_PAIR(ConstantPool, cp));
oop obj;
if (!resolve) {
bool found_it;
obj = cp->find_cached_constant_at(index, found_it, CHECK_NULL);
obj = cp->find_cached_constant_at(cp_index, found_it, CHECK_NULL);
if (!found_it) {
return nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be some sort of exception or error checking here or in the caller? If the constant can't be found it either isn't resolved or the index is invalid, correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error checking is already done by the call to getTagAt in HotSpotConstantPool.lookupConstant(int cpi, boolean resolve).
I'll add more javadoc to clarify when a null is returned.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the javadoc of lookupConstantInPool already states:

     * The behavior of this method is undefined if {@code cpi} does not denote one of the following
     * entry types: {@code JVM_CONSTANT_Dynamic}, {@code JVM_CONSTANT_String},
     * {@code JVM_CONSTANT_MethodHandle}, {@code JVM_CONSTANT_MethodHandleInError},
     * {@code JVM_CONSTANT_MethodType} and {@code JVM_CONSTANT_MethodTypeInError}.

}
} else {
obj = cp->resolve_possibly_cached_constant_at(index, CHECK_NULL);
obj = cp->resolve_possibly_cached_constant_at(cp_index, CHECK_NULL);
}
constantTag tag = cp->tag_at(index);
constantTag tag = cp->tag_at(cp_index);
if (tag.is_dynamic_constant()) {
if (obj == nullptr) {
return JVMCIENV->get_jobject(JVMCIENV->get_JavaConstant_NULL_POINTER());
}
BasicType bt = Signature::basic_type(cp->uncached_signature_ref_at(index));
BasicType bt = Signature::basic_type(cp->uncached_signature_ref_at(cp_index));
if (!is_reference_type(bt)) {
if (!is_java_primitive(bt)) {
return JVMCIENV->get_jobject(JVMCIENV->get_JavaConstant_ILLEGAL());
Expand Down