提交 b73be4a8 编写于 作者: C ccheung

8048150: Allow easy configurations for large CDS archives

Summary: Estimate the size of shared archive based on the number of classes in the classlist file
Reviewed-by: iklam, jiangli, minqi, dholmes
上级 35d4d219
......@@ -3124,6 +3124,8 @@ void Metaspace::global_initialize() {
if (DumpSharedSpaces) {
#if INCLUDE_CDS
MetaspaceShared::estimate_regions_size();
SharedReadOnlySize = align_size_up(SharedReadOnlySize, max_alignment);
SharedReadWriteSize = align_size_up(SharedReadWriteSize, max_alignment);
SharedMiscDataSize = align_size_up(SharedMiscDataSize, max_alignment);
......
......@@ -815,6 +815,7 @@ int MetaspaceShared::preload_and_dump(const char * class_list_path,
//tty->print_cr("Preload failed: %s", class_name);
}
}
fclose(file);
} else {
char errmsg[JVM_MAXPATHLEN];
os::lasterror(errmsg, JVM_MAXPATHLEN);
......@@ -1085,3 +1086,49 @@ bool MetaspaceShared::remap_shared_readonly_as_readwrite() {
}
return true;
}
int MetaspaceShared::count_class(const char* classlist_file) {
if (classlist_file == NULL) {
return 0;
}
char class_name[256];
int class_count = 0;
FILE* file = fopen(classlist_file, "r");
if (file != NULL) {
while ((fgets(class_name, sizeof class_name, file)) != NULL) {
if (*class_name == '#') { // comment
continue;
}
class_count++;
}
fclose(file);
} else {
char errmsg[JVM_MAXPATHLEN];
os::lasterror(errmsg, JVM_MAXPATHLEN);
tty->print_cr("Loading classlist failed: %s", errmsg);
exit(1);
}
return class_count;
}
// the sizes are good for typical large applications that have a lot of shared
// classes
void MetaspaceShared::estimate_regions_size() {
int class_count = count_class(SharedClassListFile);
class_count += count_class(ExtraSharedClassListFile);
if (class_count > LargeThresholdClassCount) {
if (class_count < HugeThresholdClassCount) {
SET_ESTIMATED_SIZE(Large, ReadOnly);
SET_ESTIMATED_SIZE(Large, ReadWrite);
SET_ESTIMATED_SIZE(Large, MiscData);
SET_ESTIMATED_SIZE(Large, MiscCode);
} else {
SET_ESTIMATED_SIZE(Huge, ReadOnly);
SET_ESTIMATED_SIZE(Huge, ReadWrite);
SET_ESTIMATED_SIZE(Huge, MiscData);
SET_ESTIMATED_SIZE(Huge, MiscCode);
}
}
}
......@@ -30,6 +30,19 @@
#include "utilities/exceptions.hpp"
#include "utilities/macros.hpp"
#define LargeSharedArchiveSize (300*M)
#define HugeSharedArchiveSize (800*M)
#define ReadOnlyRegionPercentage 0.4
#define ReadWriteRegionPercentage 0.55
#define MiscDataRegionPercentage 0.03
#define MiscCodeRegionPercentage 0.02
#define LargeThresholdClassCount 5000
#define HugeThresholdClassCount 40000
#define SET_ESTIMATED_SIZE(type, region) \
Shared ##region## Size = FLAG_IS_DEFAULT(Shared ##region## Size) ? \
(type ## SharedArchiveSize * region ## RegionPercentage) : Shared ## region ## Size
class FileMapInfo;
// Class Data Sharing Support
......@@ -112,5 +125,8 @@ class MetaspaceShared : AllStatic {
static void link_one_shared_class(Klass* obj, TRAPS);
static void check_one_shared_class(Klass* obj);
static void link_and_cleanup_shared_classes(TRAPS);
static int count_class(const char* classlist_file);
static void estimate_regions_size() NOT_CDS_RETURN;
};
#endif // SHARE_VM_MEMORY_METASPACE_SHARED_HPP
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册