49 |
49 |
50 import static com.sun.tools.javac.code.Flags.*; |
50 import static com.sun.tools.javac.code.Flags.*; |
51 import static com.sun.tools.javac.code.Kinds.*; |
51 import static com.sun.tools.javac.code.Kinds.*; |
52 import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE; |
52 import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE; |
53 import static com.sun.tools.javac.code.TypeTag.*; |
53 import static com.sun.tools.javac.code.TypeTag.*; |
54 import static com.sun.tools.javac.jvm.UninitializedType.*; |
|
55 import static com.sun.tools.javac.main.Option.*; |
54 import static com.sun.tools.javac.main.Option.*; |
56 import static javax.tools.StandardLocation.CLASS_OUTPUT; |
55 import static javax.tools.StandardLocation.CLASS_OUTPUT; |
57 |
56 |
58 /** This class provides operations to map an internal symbol table graph |
57 /** This class provides operations to map an internal symbol table graph |
59 * rooted in a ClassSymbol into a classfile. |
58 * rooted in a ClassSymbol into a classfile. |
541 |
540 |
542 /** Write the EnclosingMethod attribute if needed. |
541 /** Write the EnclosingMethod attribute if needed. |
543 * Returns the number of attributes written (0 or 1). |
542 * Returns the number of attributes written (0 or 1). |
544 */ |
543 */ |
545 int writeEnclosingMethodAttribute(ClassSymbol c) { |
544 int writeEnclosingMethodAttribute(ClassSymbol c) { |
546 if (!target.hasEnclosingMethodAttribute()) |
|
547 return 0; |
|
548 return writeEnclosingMethodAttribute(names.EnclosingMethod, c); |
545 return writeEnclosingMethodAttribute(names.EnclosingMethod, c); |
549 } |
546 } |
550 |
547 |
551 /** Write the EnclosingMethod attribute with a specified name. |
548 /** Write the EnclosingMethod attribute with a specified name. |
552 * Returns the number of attributes written (0 or 1). |
549 * Returns the number of attributes written (0 or 1). |
576 if ((flags & DEPRECATED) != 0) { |
573 if ((flags & DEPRECATED) != 0) { |
577 int alenIdx = writeAttr(names.Deprecated); |
574 int alenIdx = writeAttr(names.Deprecated); |
578 endAttr(alenIdx); |
575 endAttr(alenIdx); |
579 acount++; |
576 acount++; |
580 } |
577 } |
581 if ((flags & ENUM) != 0 && !target.useEnumFlag()) { |
|
582 int alenIdx = writeAttr(names.Enum); |
|
583 endAttr(alenIdx); |
|
584 acount++; |
|
585 } |
|
586 if ((flags & SYNTHETIC) != 0 && !target.useSyntheticFlag()) { |
|
587 int alenIdx = writeAttr(names.Synthetic); |
|
588 endAttr(alenIdx); |
|
589 acount++; |
|
590 } |
|
591 if ((flags & BRIDGE) != 0 && !target.useBridgeFlag()) { |
|
592 int alenIdx = writeAttr(names.Bridge); |
|
593 endAttr(alenIdx); |
|
594 acount++; |
|
595 } |
|
596 if ((flags & VARARGS) != 0 && !target.useVarargsFlag()) { |
|
597 int alenIdx = writeAttr(names.Varargs); |
|
598 endAttr(alenIdx); |
|
599 acount++; |
|
600 } |
|
601 if ((flags & ANNOTATION) != 0 && !target.useAnnotationFlag()) { |
|
602 int alenIdx = writeAttr(names.Annotation); |
|
603 endAttr(alenIdx); |
|
604 acount++; |
|
605 } |
|
606 return acount; |
578 return acount; |
607 } |
579 } |
608 |
580 |
609 /** Write member (field or method) attributes; |
581 /** Write member (field or method) attributes; |
610 * return number of attributes written. |
582 * return number of attributes written. |
611 */ |
583 */ |
612 int writeMemberAttrs(Symbol sym) { |
584 int writeMemberAttrs(Symbol sym) { |
613 int acount = writeFlagAttrs(sym.flags()); |
585 int acount = writeFlagAttrs(sym.flags()); |
614 long flags = sym.flags(); |
586 long flags = sym.flags(); |
615 if (source.allowGenerics() && |
587 if ((flags & (SYNTHETIC | BRIDGE)) != SYNTHETIC && |
616 (flags & (SYNTHETIC|BRIDGE)) != SYNTHETIC && |
|
617 (flags & ANONCONSTR) == 0 && |
588 (flags & ANONCONSTR) == 0 && |
618 (!types.isSameType(sym.type, sym.erasure(types)) || |
589 (!types.isSameType(sym.type, sym.erasure(types)) || |
619 signatureGen.hasTypeVar(sym.type.getThrownTypes()))) { |
590 signatureGen.hasTypeVar(sym.type.getThrownTypes()))) { |
620 // note that a local class with captured variables |
591 // note that a local class with captured variables |
621 // will get a signature attribute |
592 // will get a signature attribute |
622 int alenIdx = writeAttr(names.Signature); |
593 int alenIdx = writeAttr(names.Signature); |
623 databuf.appendChar(pool.put(typeSig(sym.type))); |
594 databuf.appendChar(pool.put(typeSig(sym.type))); |
624 endAttr(alenIdx); |
595 endAttr(alenIdx); |
1250 databuf.appendChar(frame.pc); |
1221 databuf.appendChar(frame.pc); |
1251 |
1222 |
1252 // output locals |
1223 // output locals |
1253 int localCount = 0; |
1224 int localCount = 0; |
1254 for (int j=0; j<frame.locals.length; |
1225 for (int j=0; j<frame.locals.length; |
1255 j += (target.generateEmptyAfterBig() ? 1 : Code.width(frame.locals[j]))) { |
1226 j += Code.width(frame.locals[j])) { |
1256 localCount++; |
1227 localCount++; |
1257 } |
1228 } |
1258 if (debugstackmap) System.out.print(" nlocals=" + |
1229 if (debugstackmap) System.out.print(" nlocals=" + |
1259 localCount); |
1230 localCount); |
1260 databuf.appendChar(localCount); |
1231 databuf.appendChar(localCount); |
1261 for (int j=0; j<frame.locals.length; |
1232 for (int j=0; j<frame.locals.length; |
1262 j += (target.generateEmptyAfterBig() ? 1 : Code.width(frame.locals[j]))) { |
1233 j += Code.width(frame.locals[j])) { |
1263 if (debugstackmap) System.out.print(" local[" + j + "]="); |
1234 if (debugstackmap) System.out.print(" local[" + j + "]="); |
1264 writeStackMapType(frame.locals[j]); |
1235 writeStackMapType(frame.locals[j]); |
1265 } |
1236 } |
1266 |
1237 |
1267 // output stack |
1238 // output stack |
1268 int stackCount = 0; |
1239 int stackCount = 0; |
1269 for (int j=0; j<frame.stack.length; |
1240 for (int j=0; j<frame.stack.length; |
1270 j += (target.generateEmptyAfterBig() ? 1 : Code.width(frame.stack[j]))) { |
1241 j += Code.width(frame.stack[j])) { |
1271 stackCount++; |
1242 stackCount++; |
1272 } |
1243 } |
1273 if (debugstackmap) System.out.print(" nstack=" + |
1244 if (debugstackmap) System.out.print(" nstack=" + |
1274 stackCount); |
1245 stackCount); |
1275 databuf.appendChar(stackCount); |
1246 databuf.appendChar(stackCount); |
1276 for (int j=0; j<frame.stack.length; |
1247 for (int j=0; j<frame.stack.length; |
1277 j += (target.generateEmptyAfterBig() ? 1 : Code.width(frame.stack[j]))) { |
1248 j += Code.width(frame.stack[j])) { |
1278 if (debugstackmap) System.out.print(" stack[" + j + "]="); |
1249 if (debugstackmap) System.out.print(" stack[" + j + "]="); |
1279 writeStackMapType(frame.stack[j]); |
1250 writeStackMapType(frame.stack[j]); |
1280 } |
1251 } |
1281 if (debugstackmap) System.out.println(); |
1252 if (debugstackmap) System.out.println(); |
1282 } |
1253 } |
1682 boolean sigReq = |
1653 boolean sigReq = |
1683 typarams.length() != 0 || supertype.allparams().length() != 0; |
1654 typarams.length() != 0 || supertype.allparams().length() != 0; |
1684 for (List<Type> l = interfaces; !sigReq && l.nonEmpty(); l = l.tail) |
1655 for (List<Type> l = interfaces; !sigReq && l.nonEmpty(); l = l.tail) |
1685 sigReq = l.head.allparams().length() != 0; |
1656 sigReq = l.head.allparams().length() != 0; |
1686 if (sigReq) { |
1657 if (sigReq) { |
1687 Assert.check(source.allowGenerics()); |
|
1688 int alenIdx = writeAttr(names.Signature); |
1658 int alenIdx = writeAttr(names.Signature); |
1689 if (typarams.length() != 0) signatureGen.assembleParamsSig(typarams); |
1659 if (typarams.length() != 0) signatureGen.assembleParamsSig(typarams); |
1690 signatureGen.assembleSig(supertype); |
1660 signatureGen.assembleSig(supertype); |
1691 for (List<Type> l = interfaces; l.nonEmpty(); l = l.tail) |
1661 for (List<Type> l = interfaces; l.nonEmpty(); l = l.tail) |
1692 signatureGen.assembleSig(l.head); |
1662 signatureGen.assembleSig(l.head); |
1759 return 0; |
1729 return 0; |
1760 } |
1730 } |
1761 |
1731 |
1762 int adjustFlags(final long flags) { |
1732 int adjustFlags(final long flags) { |
1763 int result = (int)flags; |
1733 int result = (int)flags; |
1764 if ((flags & SYNTHETIC) != 0 && !target.useSyntheticFlag()) |
1734 |
1765 result &= ~SYNTHETIC; |
1735 if ((flags & BRIDGE) != 0) |
1766 if ((flags & ENUM) != 0 && !target.useEnumFlag()) |
|
1767 result &= ~ENUM; |
|
1768 if ((flags & ANNOTATION) != 0 && !target.useAnnotationFlag()) |
|
1769 result &= ~ANNOTATION; |
|
1770 |
|
1771 if ((flags & BRIDGE) != 0 && target.useBridgeFlag()) |
|
1772 result |= ACC_BRIDGE; |
1736 result |= ACC_BRIDGE; |
1773 if ((flags & VARARGS) != 0 && target.useVarargsFlag()) |
1737 if ((flags & VARARGS) != 0) |
1774 result |= ACC_VARARGS; |
1738 result |= ACC_VARARGS; |
1775 if ((flags & DEFAULT) != 0) |
1739 if ((flags & DEFAULT) != 0) |
1776 result &= ~ABSTRACT; |
1740 result &= ~ABSTRACT; |
1777 return result; |
1741 return result; |
1778 } |
1742 } |