RFR: 8263632: Improve exception handling of APIs in classLoader.cpp [v2]

Calvin Cheung ccheung at openjdk.java.net
Fri Mar 26 16:16:26 UTC 2021


On Fri, 26 Mar 2021 06:04:38 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> src/hotspot/share/classfile/classLoader.cpp line 554:
>> 
>>> 552:   // File or directory found
>>> 553:   ClassPathEntry* new_entry = NULL;
>>> 554:   new_entry = create_class_path_entry_or_fail(path, &st,
>> 
>> Ideally, there's should be no need to check for new_entry == NULL when calling  calling create_class_path_entry_or_fail(). This will make the code easier to read.
>> 
>> But currently the create_class_path_entry_or_fail() is still "tri-state":
>> 
>> - success: non-null
>> - throw vmSymbols::java_io_IOException()
>> - return NULL
>> 
>> The third case is this:
>> 
>>         // Don't complain about bad jar files added via -Xbootclasspath/a:.
>>         if (throw_exception && is_init_completed()) {
>>           THROW_MSG_(vmSymbols::java_lang_ClassNotFoundException(), msg, NULL);
>>         } else {
>>           return NULL; <<<<< here
>>         }
>> 
>> I am wondering if we can get rid of this logic. That way, we can add asserts like:
>> 
>> ClassPathEntry* ClassLoader::create_class_path_entry_or_fail(...) {
>>   ClassPathEntry* entry = create_class_path_entry(, THREAD);
>>   assert(entry != NULL || HAS_PENDING_EXCEPTION, "must throw or return valid entry");
>>   return entry;
>> }
>> 
>> ClassPathEntry* ClassLoader::create_class_path_entry_or_null(...) {
>>   ClassPathEntry* entry = create_class_path_entry(, current);
>>   assert(!HAS_PENDING_EXCEPTION, "must not throw");
>>   return entry;
>> }
>
> You can't use HAS_PENDING_EXCEPTION in create_class_path_entry_or_null without reintroducing THREAD.

After offline discussion with Ioi, we've decided to get rid of the `throw_exception` in `create_class_path_entry()`. This makes the code cleaner. We could also drop the `TRAPS` parameter of a few other related functions.

-------------

PR: https://git.openjdk.java.net/jdk/pull/3203


More information about the hotspot-runtime-dev mailing list