Java10 に Class Data Sharing なる機能が追加されたので試したけど、テストケースが良くない場合の話。
Spring Boot の maven プロジェクト
$ export MAVEN_OPTS="-XX:+UnlockCommercialFeatures -Xshare:off -XX:DumpLoadedClassList=hello.classlist -XX:+UseAppCDS"
$ ./mvnw validate
/Users/smochida/tmp/app-cds-sample/j10
skip writing class com/sun/proxy/$Proxy0 from source __JVM_DefineClass__ to classlist file
skip writing class com/sun/proxy/$Proxy1 from source __JVM_DefineClass__ to classlist file
skip writing class com/sun/proxy/$Proxy2 from source __JVM_DefineClass__ to classlist file
skip writing class com/sun/proxy/$Proxy11 from source __JVM_DefineClass__ to classlist file
skip writing class com/sun/proxy/$Proxy13 from source __JVM_DefineClass__ to classlist file
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< com.example:app-cds-sample >---------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.951 s
[INFO] Finished at: 2018-03-27T14:36:02+09:00
[INFO] ------------------------------------------------------------------------
$ ll
total 144
drwxr-xr-x 9 smochida staff 288 3 27 14:35 .
drwxr-xr-x 4 smochida staff 128 3 27 14:13 ..
-rw-r--r-- 1 smochida staff 261 3 27 14:30 .gitignore
drwxr-xr-x 3 smochida staff 96 3 27 14:30 .mvn
-rw-r--r-- 1 smochida staff 49005 3 27 14:36 hello.classlist
-rwxr-xr-x 1 smochida staff 6468 3 27 14:30 mvnw
-rw-r--r-- 1 smochida staff 4994 3 27 14:30 mvnw.cmd
-rw-r--r-- 1 smochida staff 2744 3 27 14:30 pom.xml
drwxr-xr-x 4 smochida staff 128 3 27 14:30 src
$ cat hello.classlist | grep maven
org/apache/maven/wrapper/MavenWrapperMain
org/apache/maven/wrapper/Downloader
org/apache/maven/wrapper/cli/SystemPropertiesCommandLineConverter
org/apache/maven/wrapper/cli/AbstractPropertiesCommandLineConverter
org/apache/maven/wrapper/cli/AbstractCommandLineConverter
org/apache/maven/wrapper/cli/CommandLineConverter
org/apache/maven/wrapper/cli/CommandLineParser
org/apache/maven/wrapper/cli/CommandLineParser$ParserState
org/apache/maven/wrapper/cli/CommandLineParser$BeforeFirstSubCommand
org/apache/maven/wrapper/cli/CommandLineParser$OptionAwareParserState
org/apache/maven/wrapper/cli/CommandLineParser$AfterOptions
org/apache/maven/wrapper/cli/CommandLineOption
org/apache/maven/wrapper/cli/ParsedCommandLine
org/apache/maven/wrapper/cli/ParsedCommandLineOption
org/apache/maven/wrapper/cli/CommandLineParser$AfterFirstSubCommand
org/apache/maven/wrapper/cli/CommandLineParser$OptionParserState
org/apache/maven/wrapper/cli/CommandLineParser$UnknownOptionParserState
org/apache/maven/wrapper/cli/CommandLineArgumentException
org/apache/maven/wrapper/cli/CommandLineParser$KnownOptionParserState
org/apache/maven/wrapper/SystemPropertiesHandler
org/apache/maven/wrapper/WrapperExecutor
org/apache/maven/wrapper/WrapperConfiguration
org/apache/maven/wrapper/Installer
org/apache/maven/wrapper/DefaultDownloader
org/apache/maven/wrapper/DefaultDownloader$SystemPropertiesProxyAuthenticator
org/apache/maven/wrapper/PathAssembler
org/apache/maven/wrapper/BootstrapMainStarter
org/apache/maven/wrapper/PathAssembler$LocalDistribution
$ export MAVEN_OPTS="-XX:+UnlockCommercialFeatures -Xshare:dump -XX:+UseAppCDS -XX:SharedArchiveFile=hello.jsa -XX:SharedClassListFile=hello.classlist"
$ ./mvnw validate
/Users/smochida/tmp/app-cds-sample/j10
narrow_klass_base = 0x0000000800000000, narrow_klass_shift = 3
Allocated temporary class space: 1073741824 bytes at 0x00000008c0000000
Allocated shared space: 3221225472 bytes at 0x0000000800000000
Loading classes to share ...
Loading classes to share: done.
Rewriting and linking classes ...
Rewriting and linking classes: done
Number of classes 1478
instance classes = 1400
obj array classes = 70
type array classes = 8
Updating ConstMethods ... done.
Removing unshareable information ... done.
Scanning all metaspace objects ...
Allocating RW objects ...
Allocating RO objects ...
Relocating embedded pointers ...
Relocating external roots ...
Dumping symbol table ...
Dumping String objects to closed archive heap region ...
Dumping objects to open archive heap region ...
Relocating SystemDictionary::_well_known_klasses[] ...
Removing java_mirror ... done.
mc space: 7456 [ 0.0% of total] out of 8192 bytes [ 91.0% used] at 0x0000000800000000
rw space: 4217752 [ 22.2% of total] out of 4218880 bytes [100.0% used] at 0x0000000800002000
ro space: 7545072 [ 39.8% of total] out of 7548928 bytes [ 99.9% used] at 0x0000000800408000
md space: 6160 [ 0.0% of total] out of 8192 bytes [ 75.2% used] at 0x0000000800b3b000
od space: 6649456 [ 35.1% of total] out of 6651904 bytes [100.0% used] at 0x0000000800b3d000
st0 space: 462848 [ 2.4% of total] out of 462848 bytes [100.0% used] at 0x00000007bff00000
oa0 space: 61440 [ 0.3% of total] out of 61440 bytes [100.0% used] at 0x00000007bfe00000
total : 18950184 [100.0% of total] out of 18960384 bytes [ 99.9% used]
$ ll
total 37184
drwxr-xr-x 10 smochida staff 320 3 27 14:37 .
drwxr-xr-x 4 smochida staff 128 3 27 14:13 ..
-rw-r--r-- 1 smochida staff 261 3 27 14:30 .gitignore
drwxr-xr-x 3 smochida staff 96 3 27 14:30 .mvn
-rw-r--r-- 1 smochida staff 49005 3 27 14:36 hello.classlist
-r--r--r-- 1 smochida staff 18964480 3 27 14:37 hello.jsa
-rwxr-xr-x 1 smochida staff 6468 3 27 14:30 mvnw
-rw-r--r-- 1 smochida staff 4994 3 27 14:30 mvnw.cmd
-rw-r--r-- 1 smochida staff 2744 3 27 14:30 pom.xml
drwxr-xr-x 4 smochida staff 128 3 27 14:30 src
$ export MAVEN_OPTS="-XX:+UnlockCommercialFeatures -Xshare:on -XX:+UseAppCDS -XX:SharedArchiveFile=hello.jsa"
$ time ./mvnw validate
/Users/smochida/tmp/app-cds-sample/j10
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< com.example:app-cds-sample >---------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.149 s
[INFO] Finished at: 2018-03-27T14:38:28+09:00
[INFO] ------------------------------------------------------------------------
real 0m3.639s
user 0m6.669s
sys 0m0.565s
Java8 で mvn コマンドを実行する
$ time ./mvnw validate
/Users/smochida/tmp/app-cds-sample/j08
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< com.example:app-cds-sample >---------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.774 s
[INFO] Finished at: 2018-03-27T14:28:53+09:00
[INFO] ------------------------------------------------------------------------
real 0m2.745s
user 0m5.133s
sys 0m0.387s
- mvn はプラグインをJVM起動後にロードする仕組みを持っているようで、プラグインの有無にかかわらずロードされるクラスが少なくて、無駄に時間がかかる結果になってしまった…
- 遅延ロードする仕組みのないようなアプリケーションでないとあまり効果が出ない模様
- 後で Spring Batch または Guice でつくったバッチアプリケーションなどを試してみたい