Skip to content

Commit adca84c

Browse files
committedFeb 11, 2021
8260341: CDS dump VM init code does not check exceptions
Reviewed-by: coleenp, hseigel
1 parent 447db62 commit adca84c

12 files changed

+93
-85
lines changed
 

‎src/hotspot/share/classfile/classLoader.cpp

+28-31
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ ClassPathZipEntry::~ClassPathZipEntry() {
287287

288288
u1* ClassPathZipEntry::open_entry(const char* name, jint* filesize, bool nul_terminate, TRAPS) {
289289
// enable call to C land
290-
JavaThread* thread = JavaThread::current();
290+
JavaThread* thread = THREAD->as_Java_thread();
291291
ThreadToNativeFromVM ttn(thread);
292292
// check whether zip archive contains name
293293
jint name_len;
@@ -501,7 +501,7 @@ void ClassLoader::trace_class_path(const char* msg, const char* name) {
501501
}
502502
}
503503

504-
void ClassLoader::setup_bootstrap_search_path() {
504+
void ClassLoader::setup_bootstrap_search_path(TRAPS) {
505505
const char* sys_class_path = Arguments::get_sysclasspath();
506506
assert(sys_class_path != NULL, "System boot class path must not be NULL");
507507
if (PrintSharedArchiveAndExit) {
@@ -510,19 +510,19 @@ void ClassLoader::setup_bootstrap_search_path() {
510510
} else {
511511
trace_class_path("bootstrap loader class path=", sys_class_path);
512512
}
513-
setup_boot_search_path(sys_class_path);
513+
setup_bootstrap_search_path_impl(sys_class_path, CHECK);
514514
}
515515

516516
#if INCLUDE_CDS
517-
void ClassLoader::setup_app_search_path(const char *class_path) {
517+
void ClassLoader::setup_app_search_path(const char *class_path, TRAPS) {
518518
Arguments::assert_is_dumping_archive();
519519

520520
ResourceMark rm;
521521
ClasspathStream cp_stream(class_path);
522522

523523
while (cp_stream.has_next()) {
524524
const char* path = cp_stream.get_next();
525-
update_class_path_entry_list(path, false, false, false);
525+
update_class_path_entry_list(path, false, false, false, CHECK);
526526
}
527527
}
528528

@@ -542,7 +542,7 @@ void ClassLoader::add_to_module_path_entries(const char* path,
542542
}
543543

544544
// Add a module path to the _module_path_entries list.
545-
void ClassLoader::update_module_path_entry_list(const char *path, TRAPS) {
545+
void ClassLoader::setup_module_search_path(const char* path, TRAPS) {
546546
Arguments::assert_is_dumping_archive();
547547
struct stat st;
548548
if (os::stat(path, &st) != 0) {
@@ -562,10 +562,6 @@ void ClassLoader::update_module_path_entry_list(const char *path, TRAPS) {
562562
return;
563563
}
564564

565-
void ClassLoader::setup_module_search_path(const char* path, TRAPS) {
566-
update_module_path_entry_list(path, THREAD);
567-
}
568-
569565
#endif // INCLUDE_CDS
570566

571567
void ClassLoader::close_jrt_image() {
@@ -632,8 +628,7 @@ bool ClassLoader::is_in_patch_mod_entries(Symbol* module_name) {
632628
}
633629

634630
// Set up the _jrt_entry if present and boot append path
635-
void ClassLoader::setup_boot_search_path(const char *class_path) {
636-
EXCEPTION_MARK;
631+
void ClassLoader::setup_bootstrap_search_path_impl(const char *class_path, TRAPS) {
637632
ResourceMark rm(THREAD);
638633
ClasspathStream cp_stream(class_path);
639634
bool set_base_piece = true;
@@ -675,7 +670,7 @@ void ClassLoader::setup_boot_search_path(const char *class_path) {
675670
} else {
676671
// Every entry on the system boot class path after the initial base piece,
677672
// which is set by os::set_boot_path(), is considered an appended entry.
678-
update_class_path_entry_list(path, false, true, false);
673+
update_class_path_entry_list(path, false, true, false, CHECK);
679674
}
680675
}
681676
}
@@ -722,7 +717,7 @@ ClassPathEntry* ClassLoader::create_class_path_entry(const char *path, const str
722717
bool is_boot_append,
723718
bool from_class_path_attr,
724719
TRAPS) {
725-
JavaThread* thread = JavaThread::current();
720+
JavaThread* thread = THREAD->as_Java_thread();
726721
ClassPathEntry* new_entry = NULL;
727722
if ((st->st_mode & S_IFMT) == S_IFREG) {
728723
ResourceMark rm(thread);
@@ -847,7 +842,8 @@ void ClassLoader::add_to_boot_append_entries(ClassPathEntry *new_entry) {
847842
// jdk/internal/loader/ClassLoaders$AppClassLoader instance.
848843
void ClassLoader::add_to_app_classpath_entries(const char* path,
849844
ClassPathEntry* entry,
850-
bool check_for_duplicates) {
845+
bool check_for_duplicates,
846+
TRAPS) {
851847
#if INCLUDE_CDS
852848
assert(entry != NULL, "ClassPathEntry should not be NULL");
853849
ClassPathEntry* e = _app_classpath_entries;
@@ -871,7 +867,7 @@ void ClassLoader::add_to_app_classpath_entries(const char* path,
871867
}
872868

873869
if (entry->is_jar_file()) {
874-
ClassLoaderExt::process_jar_manifest(entry, check_for_duplicates);
870+
ClassLoaderExt::process_jar_manifest(entry, check_for_duplicates, CHECK);
875871
}
876872
#endif
877873
}
@@ -881,13 +877,12 @@ bool ClassLoader::update_class_path_entry_list(const char *path,
881877
bool check_for_duplicates,
882878
bool is_boot_append,
883879
bool from_class_path_attr,
884-
bool throw_exception) {
880+
TRAPS) {
885881
struct stat st;
886882
if (os::stat(path, &st) == 0) {
887883
// File or directory found
888884
ClassPathEntry* new_entry = NULL;
889-
Thread* THREAD = Thread::current();
890-
new_entry = create_class_path_entry(path, &st, throw_exception, is_boot_append, from_class_path_attr, CHECK_(false));
885+
new_entry = create_class_path_entry(path, &st, /*throw_exception=*/true, is_boot_append, from_class_path_attr, CHECK_false);
891886
if (new_entry == NULL) {
892887
return false;
893888
}
@@ -897,7 +892,7 @@ bool ClassLoader::update_class_path_entry_list(const char *path,
897892
if (is_boot_append) {
898893
add_to_boot_append_entries(new_entry);
899894
} else {
900-
add_to_app_classpath_entries(path, new_entry, check_for_duplicates);
895+
add_to_app_classpath_entries(path, new_entry, check_for_duplicates, CHECK_false);
901896
}
902897
return true;
903898
} else {
@@ -1286,7 +1281,7 @@ InstanceKlass* ClassLoader::load_class(Symbol* name, bool search_append_only, TR
12861281
return NULL;
12871282
}
12881283

1289-
result->set_classpath_index(classpath_index, THREAD);
1284+
result->set_classpath_index(classpath_index);
12901285
return result;
12911286
}
12921287

@@ -1421,7 +1416,7 @@ void ClassLoader::record_result(InstanceKlass* ik, const ClassFileStream* stream
14211416
ik->name()->utf8_length());
14221417
assert(file_name != NULL, "invariant");
14231418

1424-
ClassLoaderExt::record_result(classpath_index, ik, THREAD);
1419+
ClassLoaderExt::record_result(classpath_index, ik, CHECK);
14251420
}
14261421
#endif // INCLUDE_CDS
14271422

@@ -1430,9 +1425,7 @@ void ClassLoader::record_result(InstanceKlass* ik, const ClassFileStream* stream
14301425
// this list has been created, it must not change order (see class PackageInfo)
14311426
// it can be appended to and is by jvmti.
14321427

1433-
void ClassLoader::initialize() {
1434-
EXCEPTION_MARK;
1435-
1428+
void ClassLoader::initialize(TRAPS) {
14361429
if (UsePerfData) {
14371430
// jvmstat performance counters
14381431
NEWPERFTICKCOUNTER(_perf_accumulated_time, SUN_CLS, "time");
@@ -1464,7 +1457,7 @@ void ClassLoader::initialize() {
14641457
// lookup java library entry points
14651458
load_java_library();
14661459
// jimage library entry points are loaded below, in lookup_vm_options
1467-
setup_bootstrap_search_path();
1460+
setup_bootstrap_search_path(CHECK);
14681461
}
14691462

14701463
char* lookup_vm_resource(JImageFile *jimage, const char *jimage_version, const char *path) {
@@ -1501,16 +1494,16 @@ char* ClassLoader::lookup_vm_options() {
15011494
}
15021495

15031496
#if INCLUDE_CDS
1504-
void ClassLoader::initialize_shared_path() {
1497+
void ClassLoader::initialize_shared_path(TRAPS) {
15051498
if (Arguments::is_dumping_archive()) {
1506-
ClassLoaderExt::setup_search_paths();
1499+
ClassLoaderExt::setup_search_paths(CHECK);
15071500
}
15081501
}
15091502

15101503
void ClassLoader::initialize_module_path(TRAPS) {
15111504
if (Arguments::is_dumping_archive()) {
1512-
ClassLoaderExt::setup_module_paths(THREAD);
1513-
FileMapInfo::allocate_shared_path_table();
1505+
ClassLoaderExt::setup_module_paths(CHECK);
1506+
FileMapInfo::allocate_shared_path_table(CHECK);
15141507
}
15151508
}
15161509

@@ -1566,7 +1559,11 @@ int ClassLoader::compute_Object_vtable() {
15661559

15671560

15681561
void classLoader_init1() {
1569-
ClassLoader::initialize();
1562+
EXCEPTION_MARK;
1563+
ClassLoader::initialize(THREAD);
1564+
if (HAS_PENDING_EXCEPTION) {
1565+
vm_exit_during_initialization("ClassLoader::initialize() failed unexpectedly");
1566+
}
15701567
}
15711568

15721569
// Complete the ClassPathEntry setup for the boot loader

‎src/hotspot/share/classfile/classLoader.hpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,12 @@ class ClassLoader: AllStatic {
222222
CDS_ONLY(static ClassPathEntry* _last_app_classpath_entry;)
223223
CDS_ONLY(static ClassPathEntry* _module_path_entries;)
224224
CDS_ONLY(static ClassPathEntry* _last_module_path_entry;)
225-
CDS_ONLY(static void setup_app_search_path(const char* class_path);)
225+
CDS_ONLY(static void setup_app_search_path(const char* class_path, TRAPS);)
226226
CDS_ONLY(static void setup_module_search_path(const char* path, TRAPS);)
227227
static void add_to_app_classpath_entries(const char* path,
228228
ClassPathEntry* entry,
229-
bool check_for_duplicates);
229+
bool check_for_duplicates,
230+
TRAPS);
230231
CDS_ONLY(static void add_to_module_path_entries(const char* path,
231232
ClassPathEntry* entry);)
232233
public:
@@ -240,8 +241,8 @@ class ClassLoader: AllStatic {
240241
// - setup the boot loader's system class path
241242
// - setup the boot loader's patch mod entries, if present
242243
// - create the ModuleEntry for java.base
243-
static void setup_bootstrap_search_path();
244-
static void setup_boot_search_path(const char *class_path);
244+
static void setup_bootstrap_search_path(TRAPS);
245+
static void setup_bootstrap_search_path_impl(const char *class_path, TRAPS);
245246
static void setup_patch_mod_entries();
246247
static void create_javabase();
247248

@@ -272,8 +273,7 @@ class ClassLoader: AllStatic {
272273
bool check_for_duplicates,
273274
bool is_boot_append,
274275
bool from_class_path_attr,
275-
bool throw_exception=true);
276-
CDS_ONLY(static void update_module_path_entry_list(const char *path, TRAPS);)
276+
TRAPS);
277277
static void print_bootclasspath();
278278

279279
// Timing
@@ -335,9 +335,9 @@ class ClassLoader: AllStatic {
335335
static objArrayOop get_system_packages(TRAPS);
336336

337337
// Initialization
338-
static void initialize();
338+
static void initialize(TRAPS);
339339
static void classLoader_init2(TRAPS);
340-
CDS_ONLY(static void initialize_shared_path();)
340+
CDS_ONLY(static void initialize_shared_path(TRAPS);)
341341
CDS_ONLY(static void initialize_module_path(TRAPS);)
342342

343343
static int compute_Object_vtable();

‎src/hotspot/share/classfile/classLoaderExt.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void ClassLoaderExt::append_boot_classpath(ClassPathEntry* new_entry) {
6565
ClassLoader::add_to_boot_append_entries(new_entry);
6666
}
6767

68-
void ClassLoaderExt::setup_app_search_path() {
68+
void ClassLoaderExt::setup_app_search_path(TRAPS) {
6969
Arguments::assert_is_dumping_archive();
7070
_app_class_paths_start_index = ClassLoader::num_boot_classpath_entries();
7171
char* app_class_path = os::strdup(Arguments::get_appclasspath());
@@ -77,7 +77,7 @@ void ClassLoaderExt::setup_app_search_path() {
7777
trace_class_path("app loader class path (skipped)=", app_class_path);
7878
} else {
7979
trace_class_path("app loader class path=", app_class_path);
80-
ClassLoader::setup_app_search_path(app_class_path);
80+
ClassLoader::setup_app_search_path(app_class_path, CHECK);
8181
}
8282
}
8383

@@ -88,7 +88,7 @@ void ClassLoaderExt::process_module_table(ModuleEntryTable* met, TRAPS) {
8888
char* path = m->location()->as_C_string();
8989
if (strncmp(path, "file:", 5) == 0) {
9090
path = ClassLoader::skip_uri_protocol(path);
91-
ClassLoader::setup_module_search_path(path, THREAD);
91+
ClassLoader::setup_module_search_path(path, CHECK);
9292
}
9393
m = m->next();
9494
}
@@ -100,7 +100,7 @@ void ClassLoaderExt::setup_module_paths(TRAPS) {
100100
ClassLoader::num_app_classpath_entries();
101101
Handle system_class_loader (THREAD, SystemDictionary::java_system_loader());
102102
ModuleEntryTable* met = Modules::get_module_entry_table(system_class_loader);
103-
process_module_table(met, THREAD);
103+
process_module_table(met, CHECK);
104104
}
105105

106106
char* ClassLoaderExt::read_manifest(ClassPathEntry* entry, jint *manifest_size, bool clean_text, TRAPS) {
@@ -164,8 +164,7 @@ char* ClassLoaderExt::get_class_path_attr(const char* jar_path, char* manifest,
164164
}
165165

166166
void ClassLoaderExt::process_jar_manifest(ClassPathEntry* entry,
167-
bool check_for_duplicates) {
168-
Thread* THREAD = Thread::current();
167+
bool check_for_duplicates, TRAPS) {
169168
ResourceMark rm(THREAD);
170169
jint manifest_size;
171170
char* manifest = read_manifest(entry, &manifest_size, CHECK);
@@ -213,7 +212,8 @@ void ClassLoaderExt::process_jar_manifest(ClassPathEntry* entry,
213212
char* libname = NEW_RESOURCE_ARRAY(char, libname_len + 1);
214213
int n = os::snprintf(libname, libname_len + 1, "%.*s%s", dir_len, dir_name, file_start);
215214
assert((size_t)n == libname_len, "Unexpected number of characters in string");
216-
if (ClassLoader::update_class_path_entry_list(libname, true, false, true /* from_class_path_attr */)) {
215+
bool status = ClassLoader::update_class_path_entry_list(libname, true, false, true /* from_class_path_attr */, CHECK);
216+
if (status) {
217217
trace_class_path("library = ", libname);
218218
} else {
219219
trace_class_path("library (non-existent) = ", libname);
@@ -226,8 +226,8 @@ void ClassLoaderExt::process_jar_manifest(ClassPathEntry* entry,
226226
}
227227
}
228228

229-
void ClassLoaderExt::setup_search_paths() {
230-
ClassLoaderExt::setup_app_search_path();
229+
void ClassLoaderExt::setup_search_paths(TRAPS) {
230+
ClassLoaderExt::setup_app_search_path(CHECK);
231231
}
232232

233233
void ClassLoaderExt::record_result(const s2 classpath_index,

‎src/hotspot/share/classfile/classLoaderExt.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -45,7 +45,7 @@ class ClassLoaderExt: public ClassLoader { // AllStatic
4545
};
4646

4747
static char* get_class_path_attr(const char* jar_path, char* manifest, jint manifest_size);
48-
static void setup_app_search_path(); // Only when -Xshare:dump
48+
static void setup_app_search_path(TRAPS); // Only when -Xshare:dump
4949
static void process_module_table(ModuleEntryTable* met, TRAPS);
5050
// index of first app JAR in shared classpath entry table
5151
static jshort _app_class_paths_start_index;
@@ -61,12 +61,12 @@ class ClassLoaderExt: public ClassLoader { // AllStatic
6161
static ClassPathEntry* find_classpath_entry_from_cache(const char* path, TRAPS);
6262

6363
public:
64-
static void process_jar_manifest(ClassPathEntry* entry, bool check_for_duplicates);
64+
static void process_jar_manifest(ClassPathEntry* entry, bool check_for_duplicates, TRAPS);
6565

6666
// Called by JVMTI code to add boot classpath
6767
static void append_boot_classpath(ClassPathEntry* new_entry);
6868

69-
static void setup_search_paths();
69+
static void setup_search_paths(TRAPS);
7070
static void setup_module_paths(TRAPS);
7171

7272
static char* read_manifest(ClassPathEntry* entry, jint *manifest_size, TRAPS) {

‎src/hotspot/share/classfile/klassFactory.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -98,7 +98,7 @@ InstanceKlass* KlassFactory::check_shared_class_file_load_hook(
9898
}
9999

100100
if (class_loader.is_null()) {
101-
new_ik->set_classpath_index(path_index, THREAD);
101+
new_ik->set_classpath_index(path_index);
102102
}
103103

104104
return new_ik;

‎src/hotspot/share/classfile/systemDictionary.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ void SystemDictionary::load_shared_class_misc(InstanceKlass* ik, ClassLoaderData
13601360
// package was loaded.
13611361
if (loader_data->is_the_null_class_loader_data()) {
13621362
int path_index = ik->shared_classpath_index();
1363-
ik->set_classpath_index(path_index, THREAD);
1363+
ik->set_classpath_index(path_index);
13641364
}
13651365

13661366
// notify a class loaded from shared object

0 commit comments

Comments
 (0)
Please sign in to comment.