src/share/classes/com/sun/java/util/jar/pack/PackageWriter.java

Print this page




1392         if (i.getBC() != _invokespecial)  return -1;
1393         MemberEntry ref = (MemberEntry) i.getCPRef(curCPMap);
1394         if ("<init>".equals(ref.descRef.nameRef.stringValue()) == false)
1395             return -1;
1396         ClassEntry refClass = ref.classRef;
1397         if (refClass == curClass.thisClass)
1398             return _invokeinit_op+_invokeinit_self_option;
1399         if (refClass == curClass.superClass)
1400             return _invokeinit_op+_invokeinit_super_option;
1401         if (refClass == newClass)
1402             return _invokeinit_op+_invokeinit_new_option;
1403         return -1;
1404     }
1405 
1406     // Return a _self_linker_op variant, if the instruction matches one,
1407     // else -1.
1408     private int selfOpVariant(Instruction i) {
1409         int bc = i.getBC();
1410         if (!(bc >= _first_linker_op && bc <= _last_linker_op))  return -1;
1411         MemberEntry ref = (MemberEntry) i.getCPRef(curCPMap);




1412         ClassEntry refClass = ref.classRef;
1413         int self_bc = _self_linker_op + (bc - _first_linker_op);
1414         if (refClass == curClass.thisClass)
1415             return self_bc;
1416         if (refClass == curClass.superClass)
1417             return self_bc + _self_linker_super_flag;
1418         return -1;
1419     }
1420 
1421     void writeByteCodes(Code code) throws IOException {
1422         beginCode(code);
1423         IndexGroup cp = pkg.cp;
1424 
1425         // true if the previous instruction is an aload to absorb
1426         boolean prevAload = false;
1427 
1428         // class of most recent new; helps compress <init> calls
1429         Entry newClass = null;
1430 
1431         for (Instruction i = code.instructionAt(0); i != null; i = i.next()) {


1592                     default:
1593                         // CONSTANT_MethodHandle, etc.
1594                         if (getHighestClassVersion().lessThan(JAVA7_MAX_CLASS_VERSION)) {
1595                             throw new IOException("bad class file major version for Java 7 ldc");
1596                         }
1597                         bc_which = bc_loadablevalueref;
1598                         switch (bc) {
1599                         case _ldc:    vbc = _qldc; break;
1600                         case _ldc_w:  vbc = _qldc_w; break;
1601                         default:      assert(false);
1602                         }
1603                     }
1604                     break;
1605                 case CONSTANT_Class:
1606                     // Use a special shorthand for the current class:
1607                     if (ref == curClass.thisClass)  ref = null;
1608                     bc_which = bc_classref; break;
1609                 case CONSTANT_Fieldref:
1610                     bc_which = bc_fieldref; break;
1611                 case CONSTANT_Methodref:
1612                     bc_which = bc_methodref; break;









1613                 case CONSTANT_InterfaceMethodref:
1614                     bc_which = bc_imethodref; break;
1615                 case CONSTANT_InvokeDynamic:
1616                     bc_which = bc_indyref; break;
1617                 default:
1618                     bc_which = null;
1619                     assert(false);
1620                 }
1621                 if (ref != null && bc_which.index != null && !bc_which.index.contains(ref)) {
1622                     // Crash and burn with a complaint if there are funny
1623                     // references for this bytecode instruction.
1624                     // Example:  invokestatic of a CONSTANT_InterfaceMethodref.
1625                     String complaint = code.getMethod() +
1626                         " contains a bytecode " + i +
1627                         " with an unsupported constant reference; please use the pass-file option on this class.";
1628                     Utils.log.warning(complaint);
1629                     throw new IOException(complaint);
1630                 }
1631                 bc_codes.putByte(vbc);
1632                 bc_which.putRef(ref);




1392         if (i.getBC() != _invokespecial)  return -1;
1393         MemberEntry ref = (MemberEntry) i.getCPRef(curCPMap);
1394         if ("<init>".equals(ref.descRef.nameRef.stringValue()) == false)
1395             return -1;
1396         ClassEntry refClass = ref.classRef;
1397         if (refClass == curClass.thisClass)
1398             return _invokeinit_op+_invokeinit_self_option;
1399         if (refClass == curClass.superClass)
1400             return _invokeinit_op+_invokeinit_super_option;
1401         if (refClass == newClass)
1402             return _invokeinit_op+_invokeinit_new_option;
1403         return -1;
1404     }
1405 
1406     // Return a _self_linker_op variant, if the instruction matches one,
1407     // else -1.
1408     private int selfOpVariant(Instruction i) {
1409         int bc = i.getBC();
1410         if (!(bc >= _first_linker_op && bc <= _last_linker_op))  return -1;
1411         MemberEntry ref = (MemberEntry) i.getCPRef(curCPMap);
1412         // do not optimize this case, simply fall back to regular coding
1413         if ((bc == _invokespecial || bc == _invokestatic) &&
1414                 ref.tagEquals(CONSTANT_InterfaceMethodref))
1415             return -1;
1416         ClassEntry refClass = ref.classRef;
1417         int self_bc = _self_linker_op + (bc - _first_linker_op);
1418         if (refClass == curClass.thisClass)
1419             return self_bc;
1420         if (refClass == curClass.superClass)
1421             return self_bc + _self_linker_super_flag;
1422         return -1;
1423     }
1424 
1425     void writeByteCodes(Code code) throws IOException {
1426         beginCode(code);
1427         IndexGroup cp = pkg.cp;
1428 
1429         // true if the previous instruction is an aload to absorb
1430         boolean prevAload = false;
1431 
1432         // class of most recent new; helps compress <init> calls
1433         Entry newClass = null;
1434 
1435         for (Instruction i = code.instructionAt(0); i != null; i = i.next()) {


1596                     default:
1597                         // CONSTANT_MethodHandle, etc.
1598                         if (getHighestClassVersion().lessThan(JAVA7_MAX_CLASS_VERSION)) {
1599                             throw new IOException("bad class file major version for Java 7 ldc");
1600                         }
1601                         bc_which = bc_loadablevalueref;
1602                         switch (bc) {
1603                         case _ldc:    vbc = _qldc; break;
1604                         case _ldc_w:  vbc = _qldc_w; break;
1605                         default:      assert(false);
1606                         }
1607                     }
1608                     break;
1609                 case CONSTANT_Class:
1610                     // Use a special shorthand for the current class:
1611                     if (ref == curClass.thisClass)  ref = null;
1612                     bc_which = bc_classref; break;
1613                 case CONSTANT_Fieldref:
1614                     bc_which = bc_fieldref; break;
1615                 case CONSTANT_Methodref:
1616                     if (ref.tagEquals(CONSTANT_InterfaceMethodref)) {
1617                         if (bc == _invokespecial)
1618                             vbc = _invokespecial_int;
1619                         if (bc == _invokestatic)
1620                             vbc = _invokestatic_int;
1621                         bc_which = bc_imethodref;
1622                     } else {
1623                         bc_which = bc_methodref;
1624                     }
1625                     break;
1626                 case CONSTANT_InterfaceMethodref:
1627                     bc_which = bc_imethodref; break;
1628                 case CONSTANT_InvokeDynamic:
1629                     bc_which = bc_indyref; break;
1630                 default:
1631                     bc_which = null;
1632                     assert(false);
1633                 }
1634                 if (ref != null && bc_which.index != null && !bc_which.index.contains(ref)) {
1635                     // Crash and burn with a complaint if there are funny
1636                     // references for this bytecode instruction.
1637                     // Example:  invokestatic of a CONSTANT_InterfaceMethodref.
1638                     String complaint = code.getMethod() +
1639                         " contains a bytecode " + i +
1640                         " with an unsupported constant reference; please use the pass-file option on this class.";
1641                     Utils.log.warning(complaint);
1642                     throw new IOException(complaint);
1643                 }
1644                 bc_codes.putByte(vbc);
1645                 bc_which.putRef(ref);