RFR: 8263632: Improve exception handling of APIs in classLoader.cpp [v4]
Ioi Lam
ioi.lam at oracle.com
Mon Mar 29 23:01:10 UTC 2021
On 3/28/21 9:40 PM, David Holmes wrote:
> On Fri, 26 Mar 2021 16:12:54 GMT, Calvin Cheung <ccheung at openjdk.org> wrote:
>
>>> 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.
> It is not at all clear to me how you now deal with the error cases without exceptions. How is it detected that ClassLoader::setup_module_search_path failed for example?
>
During VM bootstrap, classLoader.cpp tries to open files on related to
-Xbootclasspath/a: and --patch-module.
For --patch-module handling, throw_exception=false was specified.
For bootclasspath handling, throw_exception=true was specified before
JDK-8263632:
https://github.com/openjdk/jdk/blame/59ed1fa28c80395ddc5e8d8611e2225349aaff1a/src/hotspot/share/classfile/classLoader.cpp#L672
ClassLoader::initialize
-> ClassLoader::setup_bootstrap_search_path
-> ClassLoader::setup_bootstrap_search_path_impl
-> update_class_path_entry_list
-> create_class_path_entry(path, &st, /*throw_exception=*/true, ...)
But this will not throw any exception for invalid JAR files:
[1] the file doesn't exist.
$ rm -f foo.jar
$ java -Xbootclasspath/a:foo.jar -version
openjdk version "15" 2020-09-15
OpenJDK Runtime Environment (build 15+36-1562)
OpenJDK 64-Bit Server VM (build 15+36-1562, mixed mode, sharing)
[2] the file exists but is not a ZIP file
$ touch foo.jar
$ java -Xbootclasspath/a:foo.jar -version
openjdk version "15" 2020-09-15
OpenJDK Runtime Environment (build 15+36-1562)
OpenJDK 64-Bit Server VM (build 15+36-1562, mixed mode, sharing)
The behavior of [2] is due to this: is_init_completed() is false during
VM bootstrap.
// 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;
}
create_class_path_entry() is called when is_init_completed() is true
only during CDS dumping code. We decided that we don't need the
exception in this case and will just ignore any non-existing or invalid
ZIP files. Getting rid of the throw_exception parameter makes things a
lot simpler.
Thanks
- Ioi
> -------------
>
> PR: https://git.openjdk.java.net/jdk/pull/3203
More information about the hotspot-runtime-dev
mailing list