Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8321033

Avoid casting Array to GrowableArray

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 24
    • None
    • hotspot
    • b04

      ModuleEntry::_reads is declared as an GrowableArray<ModuleEntry*>*, but when stored in a CDS archive, we assign an Array<ModuleEntry*>* to this field with a type cast:

      https://github.com/openjdk/jdk/commit/03a4df0acd103702e52dcd01c3f03fda4d7b04f5#diff-3ddec12a402a8e4f3993dc642c7f8cb7ca277553deff15ae00b10392f6322ffcR450

      _reads = (GrowableArray<ModuleEntry*>*)archived_reads;

      There's a corresponding cast that converts the Array<ModuleEntry*>* back to a GrowableArray<ModuleEntry*>*:

      void ModuleEntry::load_from_archive(ClassLoaderData* loader_data) {
        assert(CDSConfig::is_loading_full_module_graph(), "runtime only");
        set_loader_data(loader_data);
        _reads = restore_growable_array((Array<ModuleEntry*>*)_reads);
        JFR_ONLY(INIT_ID(this);)
      }

      This code is confusing and should be fixed (use a union type??)

            matsaave Matias Saavedra Silva
            iklam Ioi Lam
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: