< prev index next >

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

Print this page
@@ -220,11 +220,11 @@
      public static String flagNames(long flags) {
          StringBuilder sbuf = new StringBuilder();
          int i = 0;
          long f = flags & StandardFlags;
          while (f != 0) {
-             if ((f & 1) != 0) {
+             if ((f & 1) != 0 && flagName[i] != "") {
                  sbuf.append(" ");
                  sbuf.append(flagName[i]);
              }
              f = f >> 1;
              i++;

@@ -232,11 +232,12 @@
          return sbuf.toString();
      }
      //where
          private static final String[] flagName = {
              "PUBLIC", "PRIVATE", "PROTECTED", "STATIC", "FINAL",
-             "SUPER", "VOLATILE", "TRANSIENT", "NATIVE", "INTERFACE",
+             // the empty position should be for synchronized but right now we don't have any test checking it
+             "", "VOLATILE", "TRANSIENT", "NATIVE", "INTERFACE",
              "ABSTRACT", "STRICTFP"};
  
  /* ****************************************************************
   * Output routines
   ******************************************************************/

@@ -832,13 +833,12 @@
      void writeInnerClasses() {
          int alenIdx = writeAttr(names.InnerClasses);
          databuf.appendChar(poolWriter.innerClasses.size());
          for (ClassSymbol inner : poolWriter.innerClasses) {
              inner.markAbstractIfNeeded(types);
-             int flags = adjustFlags(inner.flags_field);
+             int flags = adjustFlags(inner, inner.flags_field);
              if ((flags & INTERFACE) != 0) flags |= ABSTRACT; // Interfaces are always ABSTRACT
-             flags &= ~STRICTFP; //inner classes should not have the strictfp flag set.
              if (dumpInnerClassModifiers) {
                  PrintWriter pw = log.getWriter(Log.WriterKind.ERROR);
                  pw.println("INNERCLASS  " + inner.name);
                  pw.println("---" + flagNames(flags));
              }

@@ -850,10 +850,21 @@
              databuf.appendChar(flags);
          }
          endAttr(alenIdx);
      }
  
+      /** Write out "LoadableDescriptors" attribute by enumerating the value classes encountered in field/method descriptors during this compilation.
+       */
+      void writeLoadableDescriptorsAttribute() {
+         int alenIdx = writeAttr(names.LoadableDescriptors);
+         databuf.appendChar(poolWriter.loadableDescriptors.size());
+         for (Symbol c : poolWriter.loadableDescriptors) {
+             databuf.appendChar(poolWriter.putDescriptor(c));
+         }
+         endAttr(alenIdx);
+      }
+ 
      int writeRecordAttribute(ClassSymbol csym) {
          int alenIdx = writeAttr(names.Record);
          Scope s = csym.members();
          databuf.appendChar(csym.getRecordComponents().size());
          for (VarSymbol v: csym.getRecordComponents()) {

@@ -963,19 +974,26 @@
      }
  
      /** Write field symbol, entering all references into constant pool.
       */
      void writeField(VarSymbol v) {
-         int flags = adjustFlags(v.flags());
+         int flags = adjustFlags(v, v.flags());
          databuf.appendChar(flags);
          if (dumpFieldModifiers) {
              PrintWriter pw = log.getWriter(Log.WriterKind.ERROR);
              pw.println("FIELD  " + v.name);
              pw.println("---" + flagNames(v.flags()));
          }
          databuf.appendChar(poolWriter.putName(v.name));
          databuf.appendChar(poolWriter.putDescriptor(v));
+         Type fldType = v.erasure(types);
+         if (fldType.requiresLoadableDescriptors(v.owner)) {
+             poolWriter.enterLoadableDescriptorsClass(fldType.tsym);
+             if (preview.isPreview(Source.Feature.VALUE_CLASSES)) {
+                 preview.markUsesPreview(null);
+             }
+         }
          int acountIdx = beginAttrs();
          int acount = 0;
          if (v.getConstValue() != null) {
              int alenIdx = writeAttr(names.ConstantValue);
              databuf.appendChar(poolWriter.putConstant(v.getConstValue()));

@@ -988,19 +1006,35 @@
      }
  
      /** Write method symbol, entering all references into constant pool.
       */
      void writeMethod(MethodSymbol m) {
-         int flags = adjustFlags(m.flags());
+         int flags = adjustFlags(m, m.flags());
          databuf.appendChar(flags);
          if (dumpMethodModifiers) {
              PrintWriter pw = log.getWriter(Log.WriterKind.ERROR);
              pw.println("METHOD  " + m.name);
              pw.println("---" + flagNames(m.flags()));
          }
          databuf.appendChar(poolWriter.putName(m.name));
          databuf.appendChar(poolWriter.putDescriptor(m));
+         MethodType mtype = (MethodType) m.externalType(types);
+         for (Type t : mtype.getParameterTypes()) {
+             if (t.requiresLoadableDescriptors(m.owner)) {
+                 poolWriter.enterLoadableDescriptorsClass(t.tsym);
+                 if (preview.isPreview(Source.Feature.VALUE_CLASSES)) {
+                     preview.markUsesPreview(null);
+                 }
+             }
+         }
+         Type returnType = mtype.getReturnType();
+         if (returnType.requiresLoadableDescriptors(m.owner)) {
+             poolWriter.enterLoadableDescriptorsClass(returnType.tsym);
+             if (preview.isPreview(Source.Feature.VALUE_CLASSES)) {
+                 preview.markUsesPreview(null);
+             }
+         }
          int acountIdx = beginAttrs();
          int acount = 0;
          if (m.code != null) {
              int alenIdx = writeAttr(names.Code);
              writeCode(m.code);

@@ -1574,14 +1608,15 @@
  
          int flags;
          if (c.owner.kind == MDL) {
              flags = ACC_MODULE;
          } else {
-             flags = adjustFlags(c.flags() & ~DEFAULT);
+             long originalFlags = c.flags();
+             flags = adjustFlags(c, c.flags() & ~(DEFAULT | STRICTFP));
              if ((flags & PROTECTED) != 0) flags |= PUBLIC;
-             flags = flags & ClassFlags & ~STRICTFP;
-             if ((flags & INTERFACE) == 0) flags |= ACC_SUPER;
+             flags = flags & ClassFlags;
+             flags |= (originalFlags & IDENTITY_TYPE) != 0 ? ACC_IDENTITY : flags;
          }
  
          if (dumpClassModifiers) {
              PrintWriter pw = log.getWriter(Log.WriterKind.ERROR);
              pw.println();

@@ -1703,10 +1738,15 @@
          if (!poolWriter.innerClasses.isEmpty()) {
              writeInnerClasses();
              acount++;
          }
  
+         if (!poolWriter.loadableDescriptors.isEmpty()) {
+             writeLoadableDescriptorsAttribute();
+             acount++;
+         }
+ 
          endAttrs(acountIdx, acount);
  
          out.write(poolbuf.elems, 0, poolbuf.length);
  
          poolWriter.writePool(out);

@@ -1733,11 +1773,11 @@
              i += hook.applyAsInt(sym);
          }
          return i;
      }
  
-     int adjustFlags(final long flags) {
+     int adjustFlags(Symbol sym, final long flags) {
          int result = (int)flags;
  
          // Elide strictfp bit in class files
          if (target.obsoleteAccStrict())
              result &= ~STRICTFP;

@@ -1746,10 +1786,18 @@
              result |= ACC_BRIDGE;
          if ((flags & VARARGS) != 0)
              result |= ACC_VARARGS;
          if ((flags & DEFAULT) != 0)
              result &= ~ABSTRACT;
+         if ((flags & IDENTITY_TYPE) != 0) {
+             result |= ACC_IDENTITY;
+         }
+         if (sym.kind == VAR) {
+             if ((flags & STRICT) != 0) {
+                 result |= ACC_STRICT;
+             }
+         }
          return result;
      }
  
      long getLastModified(FileObject filename) {
          long mod = 0;
< prev index next >