RFR(L): 8186842: Use Java class loaders for creating the CDS archive
Jiangli Zhou
jiangli.zhou at oracle.com
Tue Aug 29 22:48:43 UTC 2017
> On Aug 29, 2017, at 1:44 PM, Ioi Lam <ioi.lam at oracle.com> wrote:
>
>
>
> On 8/29/17 12:55 PM, Jiangli Zhou wrote:
>> I was looking for code that handles anonymous classes. There are following code in classLoader.cpp and metaspaceShared.cpp. However, I can’t find any code that specifically removes anonymous classes from the system dictionary at CDS dump time. I’m probably missing something, how do we guarantee (besides the assert) anonymous classes are not being archived?
>>
>> 1582 void ClassLoader::record_shared_class_loader_type(InstanceKlass* ik, const ClassFileStream* stream) {
>> 1583 assert(DumpSharedSpaces, "sanity");
>> 1584 assert(stream != NULL, "sanity");
>> 1585
>> 1586 if (ik->is_anonymous()) {
>> 1587 // We do not archive anonymous classes.
>> 1588 return;
>> 1589 }
>> 487 NOT_PRODUCT(
>> 488 static void assert_not_anonymous_class(InstanceKlass* k) {
>> 489 if (k->is_instance_klass()) {
>> 490 assert(!(k->is_anonymous()), "cannot archive anonymous classes");
>> 491 }
>> 492 }
>> 494 static void assert_no_anonymoys_classes_in_dictionaries() {
>> 495 ClassLoaderDataGraph::dictionary_classes_do(assert_not_anonymous_class);
>> 496 })
> Hi Jiangli,
>
> Anonymous classes are not stored inside any Dictionaries. They are created by SystemDictionary::parse_stream() with a non-null host_klass:
>
> // Note: this method is much like resolve_from_stream, but
> // does not publish the classes via the SystemDictionary.
> // Handles unsafe_DefineAnonymousClass and redefineclasses
> // RedefinedClasses do not add to the class hierarchy
> InstanceKlass* SystemDictionary::parse_stream(Symbol* class_name,
> Handle class_loader,
> Handle protection_domain,
> ClassFileStream* st,
> const InstanceKlass* host_klass,
> GrowableArray<Handle>* cp_patches,
> TRAPS)
>
> Anonymous classes are referenced in other data structures, such as in this loader_data:
>
> loader_data = ClassLoaderData::anonymous_class_loader_data(class_loader(), CHECK_NULL);
>
> However, all these places are ignored by CDS during dump time (We only archive classes that are directly stored in the Dictionary objects of the boot/platform/app loaders. See SystemDictionary::combine_shared_dictionaries() in the new code).
>
> Therefore, we can guarantee that no anonymous classes are archived. The assert_no_anonymous_classes_in_dictionaries() just ensure this is true (i.e., in future VM development, if people start putting anonymous classes in the Dictionary objects of the boot/platform/app loaders, this assert would catch it).
That’s exactly what I was looking for! I suspected that must be the case but didn’t find the related code. Thanks for the details.
Calvin, could you please add comments above assert_no_anonymoys_classes_in_dictionaries() explaining that anonymous classes are not stored in system dictionary?
Thanks,
Jiangli
>
> Thanks
> - Ioi
>
>
More information about the hotspot-runtime-dev
mailing list