< prev index next >

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

Print this page




1162                 databuf.appendByte(1);
1163                 break;
1164             case FLOAT:
1165                 if (debugstackmap) System.out.print("float");
1166                 databuf.appendByte(2);
1167                 break;
1168             case DOUBLE:
1169                 if (debugstackmap) System.out.print("double");
1170                 databuf.appendByte(3);
1171                 break;
1172             case LONG:
1173                 if (debugstackmap) System.out.print("long");
1174                 databuf.appendByte(4);
1175                 break;
1176             case BOT: // null
1177                 if (debugstackmap) System.out.print("null");
1178                 databuf.appendByte(5);
1179                 break;
1180             case CLASS:
1181             case ARRAY:




1182             case TYPEVAR:
1183                 if (debugstackmap) System.out.print("object(" + types.erasure(t).tsym + ")");
1184                 databuf.appendByte(7);
1185                 databuf.appendChar(poolWriter.putClass(types.erasure(t)));
1186                 break;
1187             case UNINITIALIZED_THIS:
1188                 if (debugstackmap) System.out.print("uninit_this");
1189                 databuf.appendByte(6);
1190                 break;
1191             case UNINITIALIZED_OBJECT:
1192                 { UninitializedType uninitType = (UninitializedType)t;
1193                 databuf.appendByte(8);
1194                 if (debugstackmap) System.out.print("uninit_object@" + uninitType.offset);
1195                 databuf.appendChar(uninitType.offset);
1196                 }
1197                 break;
1198             default:
1199                 throw new AssertionError();
1200             }
1201         }


1475     }
1476 
1477     /** Write class `c' to outstream `out'.
1478      */
1479     public void writeClassFile(OutputStream out, ClassSymbol c)
1480         throws IOException, PoolOverflow, StringOverflow {
1481         Assert.check((c.flags() & COMPOUND) == 0);
1482         databuf.reset();
1483         poolbuf.reset();
1484 
1485         Type supertype = types.supertype(c.type);
1486         List<Type> interfaces = types.interfaces(c.type);
1487         List<Type> typarams = c.type.getTypeArguments();
1488 
1489         int flags;
1490         if (c.owner.kind == MDL) {
1491             flags = ACC_MODULE;
1492         } else {
1493             flags = adjustFlags(c.flags() & ~DEFAULT);
1494             if ((flags & PROTECTED) != 0) flags |= PUBLIC;
1495             flags = flags & ClassFlags & ~STRICTFP;
1496             if ((flags & INTERFACE) == 0) flags |= ACC_SUPER;
1497         }
1498 
1499         if (dumpClassModifiers) {
1500             PrintWriter pw = log.getWriter(Log.WriterKind.ERROR);
1501             pw.println();
1502             pw.println("CLASSFILE  " + c.getQualifiedName());
1503             pw.println("---" + flagNames(flags));
1504         }
1505         databuf.appendChar(flags);
1506 
1507         if (c.owner.kind == MDL) {
1508             PackageSymbol unnamed = ((ModuleSymbol) c.owner).unnamedPackage;
1509             databuf.appendChar(poolWriter.putClass(new ClassSymbol(0, names.module_info, unnamed)));
1510         } else {
1511             databuf.appendChar(poolWriter.putClass(c));
1512         }
1513         databuf.appendChar(supertype.hasTag(CLASS) ? poolWriter.putClass((ClassSymbol)supertype.tsym) : 0);
1514         databuf.appendChar(interfaces.length());
1515         for (List<Type> l = interfaces; l.nonEmpty(); l = l.tail)


1620         out.write(databuf.elems, 0, databuf.length);
1621      }
1622 
1623     /**Allows subclasses to write additional class attributes
1624      *
1625      * @return the number of attributes written
1626      */
1627     protected int writeExtraClassAttributes(ClassSymbol c) {
1628         return 0;
1629     }
1630 
1631     int adjustFlags(final long flags) {
1632         int result = (int)flags;
1633 
1634         if ((flags & BRIDGE) != 0)
1635             result |= ACC_BRIDGE;
1636         if ((flags & VARARGS) != 0)
1637             result |= ACC_VARARGS;
1638         if ((flags & DEFAULT) != 0)
1639             result &= ~ABSTRACT;


1640         return result;
1641     }
1642 
1643     long getLastModified(FileObject filename) {
1644         long mod = 0;
1645         try {
1646             mod = filename.getLastModified();
1647         } catch (SecurityException e) {
1648             throw new AssertionError("CRT: couldn't get source file modification date: " + e.getMessage());
1649         }
1650         return mod;
1651     }
1652 }


1162                 databuf.appendByte(1);
1163                 break;
1164             case FLOAT:
1165                 if (debugstackmap) System.out.print("float");
1166                 databuf.appendByte(2);
1167                 break;
1168             case DOUBLE:
1169                 if (debugstackmap) System.out.print("double");
1170                 databuf.appendByte(3);
1171                 break;
1172             case LONG:
1173                 if (debugstackmap) System.out.print("long");
1174                 databuf.appendByte(4);
1175                 break;
1176             case BOT: // null
1177                 if (debugstackmap) System.out.print("null");
1178                 databuf.appendByte(5);
1179                 break;
1180             case CLASS:
1181             case ARRAY:
1182                 if (debugstackmap) System.out.print("object(" + types.erasure(t).tsym + ")");
1183                 databuf.appendByte(7);
1184                 databuf.appendChar(types.isValue(t) ? poolWriter.putClass(new ConstantPoolQType(types.erasure(t), types)) : poolWriter.putClass(types.erasure(t)));
1185                 break;
1186             case TYPEVAR:
1187                 if (debugstackmap) System.out.print("object(" + types.erasure(t).tsym + ")");
1188                 databuf.appendByte(7);
1189                 databuf.appendChar(poolWriter.putClass(types.erasure(t)));
1190                 break;
1191             case UNINITIALIZED_THIS:
1192                 if (debugstackmap) System.out.print("uninit_this");
1193                 databuf.appendByte(6);
1194                 break;
1195             case UNINITIALIZED_OBJECT:
1196                 { UninitializedType uninitType = (UninitializedType)t;
1197                 databuf.appendByte(8);
1198                 if (debugstackmap) System.out.print("uninit_object@" + uninitType.offset);
1199                 databuf.appendChar(uninitType.offset);
1200                 }
1201                 break;
1202             default:
1203                 throw new AssertionError();
1204             }
1205         }


1479     }
1480 
1481     /** Write class `c' to outstream `out'.
1482      */
1483     public void writeClassFile(OutputStream out, ClassSymbol c)
1484         throws IOException, PoolOverflow, StringOverflow {
1485         Assert.check((c.flags() & COMPOUND) == 0);
1486         databuf.reset();
1487         poolbuf.reset();
1488 
1489         Type supertype = types.supertype(c.type);
1490         List<Type> interfaces = types.interfaces(c.type);
1491         List<Type> typarams = c.type.getTypeArguments();
1492 
1493         int flags;
1494         if (c.owner.kind == MDL) {
1495             flags = ACC_MODULE;
1496         } else {
1497             flags = adjustFlags(c.flags() & ~DEFAULT);
1498             if ((flags & PROTECTED) != 0) flags |= PUBLIC;
1499             flags = flags & (ClassFlags | ACC_VALUE) & ~STRICTFP;
1500             if ((flags & INTERFACE) == 0) flags |= ACC_SUPER;
1501         }
1502 
1503         if (dumpClassModifiers) {
1504             PrintWriter pw = log.getWriter(Log.WriterKind.ERROR);
1505             pw.println();
1506             pw.println("CLASSFILE  " + c.getQualifiedName());
1507             pw.println("---" + flagNames(flags));
1508         }
1509         databuf.appendChar(flags);
1510 
1511         if (c.owner.kind == MDL) {
1512             PackageSymbol unnamed = ((ModuleSymbol) c.owner).unnamedPackage;
1513             databuf.appendChar(poolWriter.putClass(new ClassSymbol(0, names.module_info, unnamed)));
1514         } else {
1515             databuf.appendChar(poolWriter.putClass(c));
1516         }
1517         databuf.appendChar(supertype.hasTag(CLASS) ? poolWriter.putClass((ClassSymbol)supertype.tsym) : 0);
1518         databuf.appendChar(interfaces.length());
1519         for (List<Type> l = interfaces; l.nonEmpty(); l = l.tail)


1624         out.write(databuf.elems, 0, databuf.length);
1625      }
1626 
1627     /**Allows subclasses to write additional class attributes
1628      *
1629      * @return the number of attributes written
1630      */
1631     protected int writeExtraClassAttributes(ClassSymbol c) {
1632         return 0;
1633     }
1634 
1635     int adjustFlags(final long flags) {
1636         int result = (int)flags;
1637 
1638         if ((flags & BRIDGE) != 0)
1639             result |= ACC_BRIDGE;
1640         if ((flags & VARARGS) != 0)
1641             result |= ACC_VARARGS;
1642         if ((flags & DEFAULT) != 0)
1643             result &= ~ABSTRACT;
1644         if ((flags & VALUE) != 0)
1645             result |= ACC_VALUE;
1646         return result;
1647     }
1648 
1649     long getLastModified(FileObject filename) {
1650         long mod = 0;
1651         try {
1652             mod = filename.getLastModified();
1653         } catch (SecurityException e) {
1654             throw new AssertionError("CRT: couldn't get source file modification date: " + e.getMessage());
1655         }
1656         return mod;
1657     }
1658 }
< prev index next >