< prev index next >

src/java.base/share/classes/java/lang/reflect/Module.java

Print this page
rev 16412 : 8171855: Move package name transformations during module bootstrap into native code
Reviewed-by: alanb, acorn, lfoltan, mchung

@@ -126,18 +126,12 @@
 
         boolean isOpen = descriptor.isOpen();
         Version version = descriptor.version().orElse(null);
         String vs = Objects.toString(version, null);
         String loc = Objects.toString(uri, null);
-        Set<String> packages = descriptor.packages();
-        int n = packages.size();
-        String[] array = new String[n];
-        int i = 0;
-        for (String pn : packages) {
-            array[i++] = pn.replace('.', '/');
-        }
-        defineModule0(this, isOpen, vs, loc, array);
+        String[] packages = descriptor.packages().toArray(new String[0]);
+        defineModule0(this, isOpen, vs, loc, packages);
     }
 
 
     /**
      * Create the unnamed Module for the given ClassLoader.

@@ -787,17 +781,16 @@
                                                + " not in contents");
         }
 
         // update VM first, just in case it fails
         if (syncVM) {
-            String pkgInternalForm = pn.replace('.', '/');
             if (other == EVERYONE_MODULE) {
-                addExportsToAll0(this, pkgInternalForm);
+                addExportsToAll0(this, pn);
             } else if (other == ALL_UNNAMED_MODULE) {
-                addExportsToAllUnnamed0(this, pkgInternalForm);
+                addExportsToAllUnnamed0(this, pn);
             } else {
-                addExports0(this, pkgInternalForm, other);
+                addExports0(this, pn, other);
             }
         }
 
         // add package name to reflectivelyExports if absent
         Map<String, Boolean> map = reflectivelyExports

@@ -1019,11 +1012,11 @@
                 extraPackages = Collections.singleton(pn);
             }
 
             // update VM first, just in case it fails
             if (syncVM)
-                addPackage0(this, pn.replace('.', '/'));
+                addPackage0(this, pn);
 
             // replace with new set
             this.extraPackages = extraPackages; // volatile write
         }
     }

@@ -1178,49 +1171,46 @@
     {
         // The VM doesn't know about open modules so need to export all packages
         if (descriptor.isOpen()) {
             assert descriptor.opens().isEmpty();
             for (String source : descriptor.packages()) {
-                String sourceInternalForm = source.replace('.', '/');
-                addExportsToAll0(m, sourceInternalForm);
+                addExportsToAll0(m, source);
             }
             return;
         }
 
         Map<String, Set<Module>> openPackages = new HashMap<>();
         Map<String, Set<Module>> exportedPackages = new HashMap<>();
 
         // process the open packages first
         for (Opens opens : descriptor.opens()) {
             String source = opens.source();
-            String sourceInternalForm = source.replace('.', '/');
 
             if (opens.isQualified()) {
                 // qualified opens
                 Set<Module> targets = new HashSet<>();
                 for (String target : opens.targets()) {
                     // only open to modules that are in this configuration
                     Module m2 = nameToModule.get(target);
                     if (m2 != null) {
-                        addExports0(m, sourceInternalForm, m2);
+                        addExports0(m, source, m2);
                         targets.add(m2);
                     }
                 }
                 if (!targets.isEmpty()) {
                     openPackages.put(source, targets);
                 }
             } else {
                 // unqualified opens
-                addExportsToAll0(m, sourceInternalForm);
+                addExportsToAll0(m, source);
                 openPackages.put(source, EVERYONE_SET);
             }
         }
 
         // next the exports, skipping exports when the package is open
         for (Exports exports : descriptor.exports()) {
             String source = exports.source();
-            String sourceInternalForm = source.replace('.', '/');
 
             // skip export if package is already open to everyone
             Set<Module> openToTargets = openPackages.get(source);
             if (openToTargets != null && openToTargets.contains(EVERYONE_MODULE))
                 continue;

@@ -1232,22 +1222,22 @@
                     // only export to modules that are in this configuration
                     Module m2 = nameToModule.get(target);
                     if (m2 != null) {
                         // skip qualified export if already open to m2
                         if (openToTargets == null || !openToTargets.contains(m2)) {
-                            addExports0(m, sourceInternalForm, m2);
+                            addExports0(m, source, m2);
                             targets.add(m2);
                         }
                     }
                 }
                 if (!targets.isEmpty()) {
                     exportedPackages.put(source, targets);
                 }
 
             } else {
                 // unqualified exports
-                addExportsToAll0(m, sourceInternalForm);
+                addExportsToAll0(m, source);
                 exportedPackages.put(source, EVERYONE_SET);
             }
         }
 
         if (!openPackages.isEmpty())
< prev index next >