< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java

Print this page

        

@@ -159,13 +159,10 @@
 
     /** The module containing the class currently being read.
      */
     protected ModuleSymbol currentModule = null;
 
-    // FIXME: temporary compatibility code
-    private boolean readNewModuleAttribute;
-
     /** The buffer containing the currently read class file.
      */
     byte[] buf = new byte[INITIAL_BUFFER_SIZE];
 
     /** The current input pointer.

@@ -390,10 +387,12 @@
                 break;
             }
             case CONSTANT_Class:
             case CONSTANT_String:
             case CONSTANT_MethodType:
+            case CONSTANT_Module:
+            case CONSTANT_Package:
                 bp = bp + 2;
                 break;
             case CONSTANT_MethodHandle:
                 bp = bp + 3;
                 break;

@@ -479,10 +478,15 @@
             skipBytes(3);
             break;
         case CONSTANT_InvokeDynamic:
             skipBytes(5);
             break;
+        case CONSTANT_Module:
+        case CONSTANT_Package:
+            // this is temporary for now: treat as a simple reference to the underlying Utf8.
+            poolObj[i] = readName(getChar(index + 1));
+            break;
         default:
             throw badClassFile("bad.const.pool.tag", Byte.toString(tag));
         }
         return poolObj[i];
     }

@@ -565,44 +569,16 @@
                                currentClassFile.toString(),
                                "CONSTANT_NameAndType_info", i);
         return (NameAndType)obj;
     }
 
-    /** Read the class name of a module-info.class file.
-     * The name is stored in a CONSTANT_Class entry, where the
-     * class name is of the form module-name.module-info.
-     */
-    Name readModuleInfoName(int i) {
-        if (majorVersion < Version.V53.major) {
-            throw badClassFile("anachronistic.module.info",
-                    Integer.toString(majorVersion),
-                    Integer.toString(minorVersion));
-        }
-        int classIndex = poolIdx[i];
-        if (buf[classIndex] == CONSTANT_Class) {
-            int utf8Index = poolIdx[getChar(classIndex + 1)];
-            if (buf[utf8Index] == CONSTANT_Utf8) {
-                int len = getChar(utf8Index + 1);
-                int start = utf8Index + 3;
-                return names.fromUtf(internalize(buf, start, len));
-            }
-        }
-        throw badClassFile("bad.module-info.name");
-    }
-
     /** Read the name of a module.
-     * The name is stored in a CONSTANT_Utf8 entry, in
-     * JVMS 4.2 internal form (with '/' instead of '.')
+     * The name is stored in a CONSTANT_Module entry, in
+     * JVMS 4.2 binary form (using ".", not "/")
      */
     Name readModuleName(int i) {
-        Name name = readName(i);
-        // FIXME: temporary compatibility code
-        if (readNewModuleAttribute) {
-            return names.fromUtf(internalize(name));
-        } else {
-            return name;
-        }
+        return readName(i);
     }
 
     /** Read module_flags.
      */
     Set<ModuleFlags> readModuleFlags(int flags) {

@@ -612,10 +588,21 @@
                 set.add(f);
         }
         return set;
     }
 
+    /** Read resolution_flags.
+     */
+    Set<ModuleResolutionFlags> readModuleResolutionFlags(int flags) {
+        Set<ModuleResolutionFlags> set = EnumSet.noneOf(ModuleResolutionFlags.class);
+        for (ModuleResolutionFlags f : ModuleResolutionFlags.values()) {
+            if ((flags & f.value) != 0)
+                set.add(f);
+        }
+        return set;
+    }
+
     /** Read exports_flags.
      */
     Set<ExportsFlag> readExportsFlags(int flags) {
         Set<ExportsFlag> set = EnumSet.noneOf(ExportsFlag.class);
         for (ExportsFlag f: ExportsFlag.values()) {

@@ -1280,25 +1267,24 @@
                 protected void read(Symbol sym, int attrLen) {
                     if (sym.kind == TYP && sym.owner.kind == MDL) {
                         ModuleSymbol msym = (ModuleSymbol) sym.owner;
                         ListBuffer<Directive> directives = new ListBuffer<>();
 
-                        // FIXME: temporary compatibility code
-                        if (readNewModuleAttribute) {
                             Name moduleName = readModuleName(nextChar());
                             if (currentModule.name != moduleName) {
                                 throw badClassFile("module.name.mismatch", moduleName, currentModule.name);
                             }
-                        }
 
                         msym.flags.addAll(readModuleFlags(nextChar()));
+                        msym.version = readName(nextChar());
 
                         ListBuffer<RequiresDirective> requires = new ListBuffer<>();
                         int nrequires = nextChar();
                         for (int i = 0; i < nrequires; i++) {
                             ModuleSymbol rsym = syms.enterModule(readModuleName(nextChar()));
                             Set<RequiresFlag> flags = readRequiresFlags(nextChar());
+                            nextChar(); // skip compiled version
                             requires.add(new RequiresDirective(rsym, flags));
                         }
                         msym.requires = requires.toList();
                         directives.addAll(msym.requires);
 

@@ -1370,19 +1356,19 @@
                         interimProvides = provides.toList();
                     }
                 }
             },
 
-            new AttributeReader(names.ModuleVersion, V53, CLASS_ATTRIBUTE) {
+            new AttributeReader(names.ModuleResolution, V53, CLASS_ATTRIBUTE) {
                 @Override
                 protected boolean accepts(AttributeKind kind) {
                     return super.accepts(kind) && allowModules;
                 }
                 protected void read(Symbol sym, int attrLen) {
                     if (sym.kind == TYP && sym.owner.kind == MDL) {
                         ModuleSymbol msym = (ModuleSymbol) sym.owner;
-                        msym.version = readName(nextChar());
+                        msym.resolutionFlags.addAll(readModuleResolutionFlags(nextChar()));
                     }
                 }
             },
         };
 

@@ -2562,28 +2548,19 @@
             if (c != self) {
                 throw badClassFile("class.file.wrong.class",
                                    self.flatname);
             }
         } else {
+            if (majorVersion < Version.V53.major) {
+                throw badClassFile("anachronistic.module.info",
+                        Integer.toString(majorVersion),
+                        Integer.toString(minorVersion));
+            }
             c.flags_field = flags;
             currentModule = (ModuleSymbol) c.owner;
             int this_class = nextChar();
-            // FIXME: temporary compatibility code
-            if (this_class == 0) {
-                readNewModuleAttribute = true;
-            } else {
-                Name modInfoName = readModuleInfoName(this_class);
-                if (currentModule.name.append('.', names.module_info) != modInfoName) {
-                    //strip trailing .module-info, if exists:
-                    int modInfoStart = modInfoName.length() - names.module_info.length();
-                    modInfoName = modInfoName.subName(modInfoStart, modInfoName.length()) == names.module_info &&
-                                  modInfoName.charAt(modInfoStart - 1) == '.' ?
-                                      modInfoName.subName(0, modInfoStart - 1) : modInfoName;
-                    throw badClassFile("module.name.mismatch", modInfoName, currentModule.name);
-                }
-                readNewModuleAttribute = false;
-            }
+            // temp, no check on this_class
         }
 
         // class attributes must be read before class
         // skip ahead to read class attributes
         int startbp = bp;
< prev index next >