< prev index next >

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

Print this page
@@ -38,10 +38,11 @@
  import javax.tools.JavaFileObject;
  
  import com.sun.tools.javac.code.*;
  import com.sun.tools.javac.code.Attribute.RetentionPolicy;
  import com.sun.tools.javac.code.Directive.*;
+ import com.sun.tools.javac.code.Scope.WriteableScope;
  import com.sun.tools.javac.code.Source.Feature;
  import com.sun.tools.javac.code.Symbol.*;
  import com.sun.tools.javac.code.Type.*;
  import com.sun.tools.javac.code.Types.SignatureGenerator.InvalidSignatureException;
  import com.sun.tools.javac.comp.Check;

@@ -140,10 +141,12 @@
      private final Log log;
  
      /** The name table. */
      private final Names names;
  
+     private final Symtab syms;
+ 
      /** Access to files. */
      private final JavaFileManager fileManager;
  
      /** The tags and constants used in compressed stackmap. */
      static final int SAME_FRAME_SIZE = 64;

@@ -173,10 +176,11 @@
          source = Source.instance(context);
          types = Types.instance(context);
          check = Check.instance(context);
          fileManager = context.get(JavaFileManager.class);
          poolWriter = Gen.instance(context).poolWriter;
+         syms = Symtab.instance(context);
  
          verbose        = options.isSet(VERBOSE);
          genCrt         = options.isSet(XJCOV);
          debugstackmap = options.isSet("debug.stackmap");
  

@@ -212,11 +216,10 @@
      private boolean dumpClassModifiers; // -XDdumpmodifiers=c
      private boolean dumpFieldModifiers; // -XDdumpmodifiers=f
      private boolean dumpInnerClassModifiers; // -XDdumpmodifiers=i
      private boolean dumpMethodModifiers; // -XDdumpmodifiers=m
  
- 
      /** Return flags as a string, separated by " ".
       */
      public static String flagNames(long flags) {
          StringBuilder sbuf = new StringBuilder();
          int i = 0;

@@ -232,11 +235,11 @@
          return sbuf.toString();
      }
      //where
          private static final String[] flagName = {
              "PUBLIC", "PRIVATE", "PROTECTED", "STATIC", "FINAL",
-             "SUPER", "VOLATILE", "TRANSIENT", "NATIVE", "INTERFACE",
+             "IDENTITY", "VOLATILE", "TRANSIENT", "NATIVE", "INTERFACE",
              "ABSTRACT", "STRICTFP"};
  
  /******************************************************************
   * Output routines
   ******************************************************************/

@@ -825,11 +828,10 @@
          databuf.appendChar(poolWriter.innerClasses.size());
          for (ClassSymbol inner : poolWriter.innerClasses) {
              inner.markAbstractIfNeeded(types);
              int flags = adjustFlags(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));
              }

@@ -841,10 +843,21 @@
              databuf.appendChar(flags);
          }
          endAttr(alenIdx);
      }
  
+      /** Write out "Preload" attribute by enumerating the value classes encountered in field/method descriptors during this compilation.
+       */
+      void writePreloadAttribute() {
+         int alenIdx = writeAttr(names.Preload);
+         databuf.appendChar(poolWriter.preloadClasses.size());
+         for (ClassSymbol c : poolWriter.preloadClasses) {
+             databuf.appendChar(poolWriter.putClass(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()) {

@@ -954,10 +967,14 @@
              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.requiresPreload(v.owner)) {
+             poolWriter.enterPreloadClass((ClassSymbol) fldType.tsym);
+         }
          int acountIdx = beginAttrs();
          int acount = 0;
          if (v.getConstValue() != null) {
              int alenIdx = writeAttr(names.ConstantValue);
              databuf.appendChar(poolWriter.putConstant(v.getConstValue()));

@@ -979,10 +996,20 @@
              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.requiresPreload(m.owner)) {
+                 poolWriter.enterPreloadClass((ClassSymbol) t.tsym);
+             }
+         }
+         Type returnType = mtype.getReturnType();
+         if (returnType.requiresPreload(m.owner)) {
+             poolWriter.enterPreloadClass((ClassSymbol) returnType.tsym);
+         }
          int acountIdx = beginAttrs();
          int acount = 0;
          if (m.code != null) {
              int alenIdx = writeAttr(names.Code);
              writeCode(m.code);

@@ -1003,11 +1030,13 @@
              int alenIdx = writeAttr(names.AnnotationDefault);
              m.defaultValue.accept(awriter);
              endAttr(alenIdx);
              acount++;
          }
-         if (target.hasMethodParameters() && (options.isSet(PARAMETERS) || m.isConstructor() && (m.flags_field & RECORD) != 0)) {
+         if (target.hasMethodParameters() && (
+                 options.isSet(PARAMETERS)
+                 || ((m.flags_field & RECORD) != 0 && (m.isConstructor() || m.isValueObjectFactory())))) {
              if (!m.isLambdaMethod()) // Per JDK-8138729, do not emit parameters table for lambda bodies.
                  acount += writeMethodParametersAttr(m);
          }
          acount += writeMemberAttrs(m, false);
          if (!m.isLambdaMethod())

@@ -1223,10 +1252,14 @@
                  if (debugstackmap) System.out.print("null");
                  databuf.appendByte(5);
                  break;
              case CLASS:
              case ARRAY:
+                 if (debugstackmap) System.out.print("object(" + types.erasure(t).tsym + ")");
+                 databuf.appendByte(7);
+                 databuf.appendChar(t.isPrimitiveClass() ? poolWriter.putClass(new ConstantPoolQType(types.erasure(t), types)) : poolWriter.putClass(types.erasure(t)));
+                 break;
              case TYPEVAR:
                  if (debugstackmap) System.out.print("object(" + types.erasure(t).tsym + ")");
                  databuf.appendByte(7);
                  databuf.appendChar(poolWriter.putClass(types.erasure(t)));
                  break;

@@ -1534,14 +1567,13 @@
  
          int flags;
          if (c.owner.kind == MDL) {
              flags = ACC_MODULE;
          } else {
-             flags = adjustFlags(c.flags() & ~DEFAULT);
+             flags = adjustFlags(c.flags() & ~(DEFAULT | STRICTFP));
              if ((flags & PROTECTED) != 0) flags |= PUBLIC;
-             flags = flags & ClassFlags & ~STRICTFP;
-             if ((flags & INTERFACE) == 0) flags |= ACC_SUPER;
+             flags = flags & AdjustedClassFlags;
          }
  
          if (dumpClassModifiers) {
              PrintWriter pw = log.getWriter(Log.WriterKind.ERROR);
              pw.println();

@@ -1565,18 +1597,18 @@
          for (Symbol sym : c.members().getSymbols(NON_RECURSIVE)) {
              switch (sym.kind) {
              case VAR: fieldsCount++; break;
              case MTH: if ((sym.flags() & HYPOTHETICAL) == 0) methodsCount++;
                        break;
-             case TYP: poolWriter.enterInner((ClassSymbol)sym); break;
+             case TYP: poolWriter.enterInnerClass((ClassSymbol)sym); break;
              default : Assert.error();
              }
          }
  
          if (c.trans_local != null) {
              for (ClassSymbol local : c.trans_local) {
-                 poolWriter.enterInner(local);
+                 poolWriter.enterInnerClass(local);
              }
          }
  
          databuf.appendChar(fieldsCount);
          writeFields(c.members());

@@ -1663,10 +1695,15 @@
          if (!poolWriter.innerClasses.isEmpty()) {
              writeInnerClasses();
              acount++;
          }
  
+         if (!poolWriter.preloadClasses.isEmpty()) {
+             writePreloadAttribute();
+             acount++;
+         }
+ 
          endAttrs(acountIdx, acount);
  
          out.write(poolbuf.elems, 0, poolbuf.length);
  
          poolWriter.writePool(out);

@@ -1706,10 +1743,16 @@
              result |= ACC_BRIDGE;
          if ((flags & VARARGS) != 0)
              result |= ACC_VARARGS;
          if ((flags & DEFAULT) != 0)
              result &= ~ABSTRACT;
+         if ((flags & PRIMITIVE_CLASS) != 0)
+             result |= ACC_PRIMITIVE;
+         if ((flags & VALUE_CLASS) != 0)
+             result |= ACC_VALUE;
+         if ((flags & IDENTITY_TYPE) != 0)
+             result |= ACC_IDENTITY;
          return result;
      }
  
      long getLastModified(FileObject filename) {
          long mod = 0;
< prev index next >