8048150: Allow easy configurations for large CDS archives

Mon, 25 Aug 2014 00:13:36 -0700

author
ccheung
date
Mon, 25 Aug 2014 00:13:36 -0700
changeset 7103
622c6e0ad4d6
parent 7100
edb5f3b38aab
child 7104
b23a19cd0536

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

src/share/vm/memory/metaspace.cpp file | annotate | diff | comparison | revisions
src/share/vm/memory/metaspaceShared.cpp file | annotate | diff | comparison | revisions
src/share/vm/memory/metaspaceShared.hpp file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/memory/metaspace.cpp	Thu Aug 28 17:05:41 2014 +0200
     1.2 +++ b/src/share/vm/memory/metaspace.cpp	Mon Aug 25 00:13:36 2014 -0700
     1.3 @@ -3124,6 +3124,8 @@
     1.4  
     1.5    if (DumpSharedSpaces) {
     1.6  #if INCLUDE_CDS
     1.7 +    MetaspaceShared::estimate_regions_size();
     1.8 +
     1.9      SharedReadOnlySize  = align_size_up(SharedReadOnlySize,  max_alignment);
    1.10      SharedReadWriteSize = align_size_up(SharedReadWriteSize, max_alignment);
    1.11      SharedMiscDataSize  = align_size_up(SharedMiscDataSize,  max_alignment);
     2.1 --- a/src/share/vm/memory/metaspaceShared.cpp	Thu Aug 28 17:05:41 2014 +0200
     2.2 +++ b/src/share/vm/memory/metaspaceShared.cpp	Mon Aug 25 00:13:36 2014 -0700
     2.3 @@ -815,6 +815,7 @@
     2.4          //tty->print_cr("Preload failed: %s", class_name);
     2.5        }
     2.6      }
     2.7 +    fclose(file);
     2.8    } else {
     2.9      char errmsg[JVM_MAXPATHLEN];
    2.10      os::lasterror(errmsg, JVM_MAXPATHLEN);
    2.11 @@ -1085,3 +1086,49 @@
    2.12    }
    2.13    return true;
    2.14  }
    2.15 +
    2.16 +int MetaspaceShared::count_class(const char* classlist_file) {
    2.17 +  if (classlist_file == NULL) {
    2.18 +    return 0;
    2.19 +  }
    2.20 +  char class_name[256];
    2.21 +  int class_count = 0;
    2.22 +  FILE* file = fopen(classlist_file, "r");
    2.23 +  if (file != NULL) {
    2.24 +    while ((fgets(class_name, sizeof class_name, file)) != NULL) {
    2.25 +      if (*class_name == '#') { // comment
    2.26 +        continue;
    2.27 +      }
    2.28 +      class_count++;
    2.29 +    }
    2.30 +    fclose(file);
    2.31 +  } else {
    2.32 +    char errmsg[JVM_MAXPATHLEN];
    2.33 +    os::lasterror(errmsg, JVM_MAXPATHLEN);
    2.34 +    tty->print_cr("Loading classlist failed: %s", errmsg);
    2.35 +    exit(1);
    2.36 +  }
    2.37 +
    2.38 +  return class_count;
    2.39 +}
    2.40 +
    2.41 +// the sizes are good for typical large applications that have a lot of shared
    2.42 +// classes
    2.43 +void MetaspaceShared::estimate_regions_size() {
    2.44 +  int class_count = count_class(SharedClassListFile);
    2.45 +  class_count += count_class(ExtraSharedClassListFile);
    2.46 +
    2.47 +  if (class_count > LargeThresholdClassCount) {
    2.48 +    if (class_count < HugeThresholdClassCount) {
    2.49 +      SET_ESTIMATED_SIZE(Large, ReadOnly);
    2.50 +      SET_ESTIMATED_SIZE(Large, ReadWrite);
    2.51 +      SET_ESTIMATED_SIZE(Large, MiscData);
    2.52 +      SET_ESTIMATED_SIZE(Large, MiscCode);
    2.53 +    } else {
    2.54 +      SET_ESTIMATED_SIZE(Huge,  ReadOnly);
    2.55 +      SET_ESTIMATED_SIZE(Huge,  ReadWrite);
    2.56 +      SET_ESTIMATED_SIZE(Huge,  MiscData);
    2.57 +      SET_ESTIMATED_SIZE(Huge,  MiscCode);
    2.58 +    }
    2.59 +  }
    2.60 +}
     3.1 --- a/src/share/vm/memory/metaspaceShared.hpp	Thu Aug 28 17:05:41 2014 +0200
     3.2 +++ b/src/share/vm/memory/metaspaceShared.hpp	Mon Aug 25 00:13:36 2014 -0700
     3.3 @@ -30,6 +30,19 @@
     3.4  #include "utilities/exceptions.hpp"
     3.5  #include "utilities/macros.hpp"
     3.6  
     3.7 +#define LargeSharedArchiveSize    (300*M)
     3.8 +#define HugeSharedArchiveSize     (800*M)
     3.9 +#define ReadOnlyRegionPercentage  0.4
    3.10 +#define ReadWriteRegionPercentage 0.55
    3.11 +#define MiscDataRegionPercentage  0.03
    3.12 +#define MiscCodeRegionPercentage  0.02
    3.13 +#define LargeThresholdClassCount  5000
    3.14 +#define HugeThresholdClassCount   40000
    3.15 +
    3.16 +#define SET_ESTIMATED_SIZE(type, region)                              \
    3.17 +  Shared ##region## Size  = FLAG_IS_DEFAULT(Shared ##region## Size) ? \
    3.18 +    (type ## SharedArchiveSize *  region ## RegionPercentage) : Shared ## region ## Size
    3.19 +
    3.20  class FileMapInfo;
    3.21  
    3.22  // Class Data Sharing Support
    3.23 @@ -112,5 +125,8 @@
    3.24    static void link_one_shared_class(Klass* obj, TRAPS);
    3.25    static void check_one_shared_class(Klass* obj);
    3.26    static void link_and_cleanup_shared_classes(TRAPS);
    3.27 +
    3.28 +  static int count_class(const char* classlist_file);
    3.29 +  static void estimate_regions_size() NOT_CDS_RETURN;
    3.30  };
    3.31  #endif // SHARE_VM_MEMORY_METASPACE_SHARED_HPP

mercurial