Skip to content
Permalink
Browse files
8260341: CDS dump VM init code does not check exceptions
Reviewed-by: coleenp, hseigel
  • Loading branch information
iklam committed Feb 11, 2021
1 parent 447db62 commit adca84cc29caebd5deeb6fea82d287cf30d62a70
@@ -287,7 +287,7 @@ ClassPathZipEntry::~ClassPathZipEntry() {

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

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

#if INCLUDE_CDS
void ClassLoader::setup_app_search_path(const char *class_path) {
void ClassLoader::setup_app_search_path(const char *class_path, TRAPS) {
Arguments::assert_is_dumping_archive();

ResourceMark rm;
ClasspathStream cp_stream(class_path);

while (cp_stream.has_next()) {
const char* path = cp_stream.get_next();
update_class_path_entry_list(path, false, false, false);
update_class_path_entry_list(path, false, false, false, CHECK);
}
}

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

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

void ClassLoader::setup_module_search_path(const char* path, TRAPS) {
update_module_path_entry_list(path, THREAD);
}

#endif // INCLUDE_CDS

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

// Set up the _jrt_entry if present and boot append path
void ClassLoader::setup_boot_search_path(const char *class_path) {
EXCEPTION_MARK;
void ClassLoader::setup_bootstrap_search_path_impl(const char *class_path, TRAPS) {
ResourceMark rm(THREAD);
ClasspathStream cp_stream(class_path);
bool set_base_piece = true;
@@ -675,7 +670,7 @@ void ClassLoader::setup_boot_search_path(const char *class_path) {
} else {
// Every entry on the system boot class path after the initial base piece,
// which is set by os::set_boot_path(), is considered an appended entry.
update_class_path_entry_list(path, false, true, false);
update_class_path_entry_list(path, false, true, false, CHECK);
}
}
}
@@ -722,7 +717,7 @@ ClassPathEntry* ClassLoader::create_class_path_entry(const char *path, const str
bool is_boot_append,
bool from_class_path_attr,
TRAPS) {
JavaThread* thread = JavaThread::current();
JavaThread* thread = THREAD->as_Java_thread();
ClassPathEntry* new_entry = NULL;
if ((st->st_mode & S_IFMT) == S_IFREG) {
ResourceMark rm(thread);
@@ -847,7 +842,8 @@ void ClassLoader::add_to_boot_append_entries(ClassPathEntry *new_entry) {
// jdk/internal/loader/ClassLoaders$AppClassLoader instance.
void ClassLoader::add_to_app_classpath_entries(const char* path,
ClassPathEntry* entry,
bool check_for_duplicates) {
bool check_for_duplicates,
TRAPS) {
#if INCLUDE_CDS
assert(entry != NULL, "ClassPathEntry should not be NULL");
ClassPathEntry* e = _app_classpath_entries;
@@ -871,7 +867,7 @@ void ClassLoader::add_to_app_classpath_entries(const char* path,
}

if (entry->is_jar_file()) {
ClassLoaderExt::process_jar_manifest(entry, check_for_duplicates);
ClassLoaderExt::process_jar_manifest(entry, check_for_duplicates, CHECK);
}
#endif
}
@@ -881,13 +877,12 @@ bool ClassLoader::update_class_path_entry_list(const char *path,
bool check_for_duplicates,
bool is_boot_append,
bool from_class_path_attr,
bool throw_exception) {
TRAPS) {
struct stat st;
if (os::stat(path, &st) == 0) {
// File or directory found
ClassPathEntry* new_entry = NULL;
Thread* THREAD = Thread::current();
new_entry = create_class_path_entry(path, &st, throw_exception, is_boot_append, from_class_path_attr, CHECK_(false));
new_entry = create_class_path_entry(path, &st, /*throw_exception=*/true, is_boot_append, from_class_path_attr, CHECK_false);
if (new_entry == NULL) {
return false;
}
@@ -897,7 +892,7 @@ bool ClassLoader::update_class_path_entry_list(const char *path,
if (is_boot_append) {
add_to_boot_append_entries(new_entry);
} else {
add_to_app_classpath_entries(path, new_entry, check_for_duplicates);
add_to_app_classpath_entries(path, new_entry, check_for_duplicates, CHECK_false);
}
return true;
} else {
@@ -1286,7 +1281,7 @@ InstanceKlass* ClassLoader::load_class(Symbol* name, bool search_append_only, TR
return NULL;
}

result->set_classpath_index(classpath_index, THREAD);
result->set_classpath_index(classpath_index);
return result;
}

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

ClassLoaderExt::record_result(classpath_index, ik, THREAD);
ClassLoaderExt::record_result(classpath_index, ik, CHECK);
}
#endif // INCLUDE_CDS

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

void ClassLoader::initialize() {
EXCEPTION_MARK;

void ClassLoader::initialize(TRAPS) {
if (UsePerfData) {
// jvmstat performance counters
NEWPERFTICKCOUNTER(_perf_accumulated_time, SUN_CLS, "time");
@@ -1464,7 +1457,7 @@ void ClassLoader::initialize() {
// lookup java library entry points
load_java_library();
// jimage library entry points are loaded below, in lookup_vm_options
setup_bootstrap_search_path();
setup_bootstrap_search_path(CHECK);
}

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

#if INCLUDE_CDS
void ClassLoader::initialize_shared_path() {
void ClassLoader::initialize_shared_path(TRAPS) {
if (Arguments::is_dumping_archive()) {
ClassLoaderExt::setup_search_paths();
ClassLoaderExt::setup_search_paths(CHECK);
}
}

void ClassLoader::initialize_module_path(TRAPS) {
if (Arguments::is_dumping_archive()) {
ClassLoaderExt::setup_module_paths(THREAD);
FileMapInfo::allocate_shared_path_table();
ClassLoaderExt::setup_module_paths(CHECK);
FileMapInfo::allocate_shared_path_table(CHECK);
}
}

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


void classLoader_init1() {
ClassLoader::initialize();
EXCEPTION_MARK;
ClassLoader::initialize(THREAD);
if (HAS_PENDING_EXCEPTION) {
vm_exit_during_initialization("ClassLoader::initialize() failed unexpectedly");
}
}

// Complete the ClassPathEntry setup for the boot loader
@@ -222,11 +222,12 @@ class ClassLoader: AllStatic {
CDS_ONLY(static ClassPathEntry* _last_app_classpath_entry;)
CDS_ONLY(static ClassPathEntry* _module_path_entries;)
CDS_ONLY(static ClassPathEntry* _last_module_path_entry;)
CDS_ONLY(static void setup_app_search_path(const char* class_path);)
CDS_ONLY(static void setup_app_search_path(const char* class_path, TRAPS);)
CDS_ONLY(static void setup_module_search_path(const char* path, TRAPS);)
static void add_to_app_classpath_entries(const char* path,
ClassPathEntry* entry,
bool check_for_duplicates);
bool check_for_duplicates,
TRAPS);
CDS_ONLY(static void add_to_module_path_entries(const char* path,
ClassPathEntry* entry);)
public:
@@ -240,8 +241,8 @@ class ClassLoader: AllStatic {
// - setup the boot loader's system class path
// - setup the boot loader's patch mod entries, if present
// - create the ModuleEntry for java.base
static void setup_bootstrap_search_path();
static void setup_boot_search_path(const char *class_path);
static void setup_bootstrap_search_path(TRAPS);
static void setup_bootstrap_search_path_impl(const char *class_path, TRAPS);
static void setup_patch_mod_entries();
static void create_javabase();

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

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

// Initialization
static void initialize();
static void initialize(TRAPS);
static void classLoader_init2(TRAPS);
CDS_ONLY(static void initialize_shared_path();)
CDS_ONLY(static void initialize_shared_path(TRAPS);)
CDS_ONLY(static void initialize_module_path(TRAPS);)

static int compute_Object_vtable();
@@ -65,7 +65,7 @@ void ClassLoaderExt::append_boot_classpath(ClassPathEntry* new_entry) {
ClassLoader::add_to_boot_append_entries(new_entry);
}

void ClassLoaderExt::setup_app_search_path() {
void ClassLoaderExt::setup_app_search_path(TRAPS) {
Arguments::assert_is_dumping_archive();
_app_class_paths_start_index = ClassLoader::num_boot_classpath_entries();
char* app_class_path = os::strdup(Arguments::get_appclasspath());
@@ -77,7 +77,7 @@ void ClassLoaderExt::setup_app_search_path() {
trace_class_path("app loader class path (skipped)=", app_class_path);
} else {
trace_class_path("app loader class path=", app_class_path);
ClassLoader::setup_app_search_path(app_class_path);
ClassLoader::setup_app_search_path(app_class_path, CHECK);
}
}

@@ -88,7 +88,7 @@ void ClassLoaderExt::process_module_table(ModuleEntryTable* met, TRAPS) {
char* path = m->location()->as_C_string();
if (strncmp(path, "file:", 5) == 0) {
path = ClassLoader::skip_uri_protocol(path);
ClassLoader::setup_module_search_path(path, THREAD);
ClassLoader::setup_module_search_path(path, CHECK);
}
m = m->next();
}
@@ -100,7 +100,7 @@ void ClassLoaderExt::setup_module_paths(TRAPS) {
ClassLoader::num_app_classpath_entries();
Handle system_class_loader (THREAD, SystemDictionary::java_system_loader());
ModuleEntryTable* met = Modules::get_module_entry_table(system_class_loader);
process_module_table(met, THREAD);
process_module_table(met, CHECK);
}

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,
}

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

void ClassLoaderExt::setup_search_paths() {
ClassLoaderExt::setup_app_search_path();
void ClassLoaderExt::setup_search_paths(TRAPS) {
ClassLoaderExt::setup_app_search_path(CHECK);
}

void ClassLoaderExt::record_result(const s2 classpath_index,
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -45,7 +45,7 @@ class ClassLoaderExt: public ClassLoader { // AllStatic
};

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

public:
static void process_jar_manifest(ClassPathEntry* entry, bool check_for_duplicates);
static void process_jar_manifest(ClassPathEntry* entry, bool check_for_duplicates, TRAPS);

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

static void setup_search_paths();
static void setup_search_paths(TRAPS);
static void setup_module_paths(TRAPS);

static char* read_manifest(ClassPathEntry* entry, jint *manifest_size, TRAPS) {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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(
}

if (class_loader.is_null()) {
new_ik->set_classpath_index(path_index, THREAD);
new_ik->set_classpath_index(path_index);
}

return new_ik;
@@ -1360,7 +1360,7 @@ void SystemDictionary::load_shared_class_misc(InstanceKlass* ik, ClassLoaderData
// package was loaded.
if (loader_data->is_the_null_class_loader_data()) {
int path_index = ik->shared_classpath_index();
ik->set_classpath_index(path_index, THREAD);
ik->set_classpath_index(path_index);
}

// notify a class loaded from shared object
Loading

0 comments on commit adca84c

Please sign in to comment.