Not able to add classes in a directory to shared archive when using AppCDS

Jiangli Zhou jiangli.zhou at oracle.com
Thu Apr 5 17:23:28 UTC 2018


Hi Ashutosh,

As Misha pointed out CDS/AppCDS only supports archiving classes from JAR file(s). To be able to archive your TestCDS.class and SamClass.class, you need to create a JAR file to include those classes and set -cp to the JAR file. With classes included in the directory, we're currently lack of methods to efficiently validate the archived data with the class files at runtime. Hence, we restrict the support to JAR file(s) only.

Thanks,
Jiangli


> On Apr 5, 2018, at 3:04 AM, David Holmes <david.holmes at oracle.com> wrote:
> 
> Moving to hotspot-runtime-dev
> 
> David
> 
> On 5/04/2018 7:15 PM, ashutosh mehra wrote:
>> I am trying to use App CDS for a sample application.
>> My class files are in a directory which I specify as the classpath.
>> I want these classes to be included in shared archive.
>> Directory structure is like this:
>> $ tree
>> .
>> ├── classes
>> │   ├── SampleClass.class
>> │   └── SampleClass.java
>> ├── TestCDS.class
>> └── TestCDS.java
>> I performed following steps:
>> 1. Create the class list:
>> $ java -Xshare:off -XX:+UseAppCDS -XX:DumpLoadedClassList=classes.list -cp
>> .:classes TestCDS
>> This generated the list of classes including my application classes TestCDS
>> and SampleClass.
>> 2. Create the shared archive:
>> $ java -Xshare:dump -XX:+UseAppCDS -XX:SharedClassListFile=classes.list
>> -XX:SharedArchiveFile=mycds.jcs -cp .:classes
>> I get following error message:
>> *narrow_klass_base = 0x0000000800000000, narrow_klass_shift = 3*
>> *Allocated temporary class space: 1073741824 bytes at 0x00000008c0000000*
>> *Allocated shared space: 3221225472 bytes at 0x0000000800000000*
>> *Error: non-empty directory '.'*
>> *Hint: enable -Xlog:class+path=info to diagnose the failure*
>> *Error occurred during initialization of VM*
>> *CDS allows only empty directories in archived classpaths*
>> Java version is:
>> openjdk version "10" 2018-03-20
>> OpenJDK Runtime Environment 18.3 (build 10+46)
>> OpenJDK 64-Bit Server VM 18.3 (build 10+46, mixed mode)
>> I have also tried with Java 11 EA build but got same output.
>> Is this expected behavior? I am sure it would be useful for many if the
>> classes loaded from a directory can also be stored in the shared archive.
>> Regards,
>> Ashutosh



More information about the jdk-dev mailing list