com.sun.java.util.jar.pack.ConstantPool.Entry Java Examples

The following examples show how to use com.sun.java.util.jar.pack.ConstantPool.Entry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClassReader.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
void readCode(Code code) throws IOException {
    code.max_stack = readUnsignedShort();
    code.max_locals = readUnsignedShort();
    code.bytes = new byte[readInt()];
    in.readFully(code.bytes);
    Entry[] cpMap = cls.getCPMap();
    Instruction.opcodeChecker(code.bytes, cpMap, this.cls.version);
    int nh = readUnsignedShort();
    code.setHandlerCount(nh);
    for (int i = 0; i < nh; i++) {
        code.handler_start[i] = readUnsignedShort();
        code.handler_end[i]   = readUnsignedShort();
        code.handler_catch[i] = readUnsignedShort();
        code.handler_class[i] = readClassRefOrNull();
    }
    readAttributes(ATTR_CONTEXT_CODE, code);
}
 
Example #2
Source File: Fixups.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean addAll(Collection<? extends Fixup> c) {
    if (c instanceof Fixups) {
        // Use knowledge of Itr structure to avoid building little structs.
        Fixups that = (Fixups) c;
        if (that.size == 0)  return false;
        if (this.size == 0 && entries.length < that.size)
            growEntries(that.size);  // presize exactly
        Entry[] thatEntries = that.entries;
        for (Itr i = that.new Itr(); i.hasNext(); ) {
            int ni = i.index;
            addDesc(i.nextDesc(), thatEntries[ni]);
        }
        return true;
    } else {
        return super.addAll(c);
    }
}
 
Example #3
Source File: Fixups.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean addAll(Collection<? extends Fixup> c) {
    if (c instanceof Fixups) {
        // Use knowledge of Itr structure to avoid building little structs.
        Fixups that = (Fixups) c;
        if (that.size == 0)  return false;
        if (this.size == 0 && entries.length < that.size)
            growEntries(that.size);  // presize exactly
        Entry[] thatEntries = that.entries;
        for (Itr i = that.new Itr(); i.hasNext(); ) {
            int ni = i.index;
            addDesc(i.nextDesc(), thatEntries[ni]);
        }
        return true;
    } else {
        return super.addAll(c);
    }
}
 
Example #4
Source File: ClassReader.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
void readCode(Code code) throws IOException {
    code.max_stack = readUnsignedShort();
    code.max_locals = readUnsignedShort();
    code.bytes = new byte[readInt()];
    in.readFully(code.bytes);
    Entry[] cpMap = cls.getCPMap();
    Instruction.opcodeChecker(code.bytes, cpMap, this.cls.version);
    int nh = readUnsignedShort();
    code.setHandlerCount(nh);
    for (int i = 0; i < nh; i++) {
        code.handler_start[i] = readUnsignedShort();
        code.handler_end[i]   = readUnsignedShort();
        code.handler_catch[i] = readUnsignedShort();
        code.handler_class[i] = readClassRefOrNull();
    }
    readAttributes(ATTR_CONTEXT_CODE, code);
}
 
Example #5
Source File: Package.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
protected void visitRefs(int mode, Collection<Entry> refs) {
    if (verbose > 2)  Utils.log.fine("visitRefs "+this);
    refs.add(thisClass);
    refs.add(superClass);
    refs.addAll(Arrays.asList(interfaces));
    for (int isM = 0; isM <= 1; isM++) {
        ArrayList<? extends Member> members = (isM == 0) ? fields : methods;
        if (members == null)  continue;
        for (Member m : members) {
            boolean ok = false;
            try {
                m.visitRefs(mode, refs);
                ok = true;
            } finally {
                if (!ok)
                    Utils.log.warning("Error scanning "+m);
            }
        }
    }
    visitInnerClassRefs(mode, refs);
    // Handle attribute list:
    super.visitRefs(mode, refs);
}
 
Example #6
Source File: BandStructure.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private int encodeRefOrNull(Entry e, Index index) {
    int nonNullCode;  // NNC is the coding which assumes nulls are rare
    if (e == null) {
        nonNullCode = -1;  // negative values are rare
    } else {
        nonNullCode = encodeRef(e, index);
    }
    // If nulls are expected, increment, to make -1 code turn to 0.
    return (nullOK ? 1 : 0) + nonNullCode;
}
 
Example #7
Source File: ClassReader.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void fixUnresolvedEntries() {
    if (!haveUnresolvedEntry)  return;
    Entry[] cpMap = cls.getCPMap();
    for (int i = 0; i < cpMap.length; i++) {
        Entry e = cpMap[i];
        if (e instanceof UnresolvedEntry) {
            cpMap[i] = e = ((UnresolvedEntry)e).resolve();
            assert(!(e instanceof UnresolvedEntry));
        }
    }
    haveUnresolvedEntry = false;
}
 
Example #8
Source File: Fixups.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void trimToSize() {
    if (size != entries.length) {
        Entry[] oldEntries = entries;
        entries = new Entry[size];
        System.arraycopy(oldEntries, 0, entries, 0, size);
    }
    int bigSize = bigDescs[BIGSIZE];
    if (bigSize == MINBIGSIZE) {
        bigDescs = noBigDescs;
    } else if (bigSize != bigDescs.length) {
        int[] oldBigDescs = bigDescs;
        bigDescs = new int[bigSize];
        System.arraycopy(oldBigDescs, 0, bigDescs, 0, bigSize);
    }
}
 
Example #9
Source File: BandStructure.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private Entry decodeRefOrNull(int code, Index index) {
    // Inverse to encodeRefOrNull...
    int nonNullCode = code - (nullOK ? 1 : 0);
    if (nonNullCode == -1) {
        return null;
    } else {
        return decodeRef(nonNullCode, index);
    }
}
 
Example #10
Source File: ClassReader.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
void readBootstrapMethods(Class cls) throws IOException {
    BootstrapMethodEntry[] bsms = new BootstrapMethodEntry[readUnsignedShort()];
    for (int i = 0; i < bsms.length; i++) {
        MethodHandleEntry bsmRef = (MethodHandleEntry) readRef(CONSTANT_MethodHandle);
        Entry[] argRefs = new Entry[readUnsignedShort()];
        for (int j = 0; j < argRefs.length; j++) {
            argRefs[j] = readRef(CONSTANT_LoadableValue);
        }
        bsms[i] = ConstantPool.getBootstrapMethodEntry(bsmRef, argRefs);
    }
    cls.setBootstrapMethods(Arrays.asList(bsms));
}
 
Example #11
Source File: ClassWriter.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
void writeBootstrapMethods(Class cls) throws IOException {
    List<BootstrapMethodEntry> bsms = cls.getBootstrapMethods();
    writeShort(bsms.size());
    for (BootstrapMethodEntry e : bsms) {
        writeRef(e.bsmRef);
        writeShort(e.argRefs.length);
        for (Entry argRef : e.argRefs) {
            writeRef(argRef);
        }
    }
}
 
Example #12
Source File: Fixups.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static
void finishRefs(Object fixups, byte[] bytes, ConstantPool.Index ix) {
    if (fixups == null)
        return;
    if (!(fixups instanceof Fixups)) {
        // Special convention; see above.
        int index = ix.indexOf((Entry) fixups);
        storeIndex(bytes, SPECIAL_LOC, SPECIAL_FMT, index);
        return;
    }
    Fixups f = (Fixups) fixups;
    assert(f.bytes == bytes);
    f.finishRefs(ix);
}
 
Example #13
Source File: ClassReader.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
Entry resolve() {
    Class cls = ClassReader.this.cls;
    Entry res;
    switch (tag) {
    case CONSTANT_InvokeDynamic:
        BootstrapMethodEntry iboots = cls.bootstrapMethods.get((Integer) refsOrIndexes[0]);
        DescriptorEntry         idescr = (DescriptorEntry) refsOrIndexes[1];
        res = ConstantPool.getInvokeDynamicEntry(iboots, idescr);
        break;
    default:
        throw new AssertionError();
    }
    return res;
}
 
Example #14
Source File: Fixups.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void addDesc(int thisDesc, Entry entry) {
    if (entries.length == size)
        growEntries(size * 2);
    entries[size] = entry;
    if (size == 0) {
        head = tail = thisDesc;
    } else {
        int prevDesc = tail;
        // Store new desc in previous tail.
        int prevLoc = descLoc(prevDesc);
        int prevFmt = descFmt(prevDesc);
        int prevLen = fmtLen(prevFmt);
        int thisLoc = descLoc(thisDesc);
        // The collection must go in ascending order, and not overlap.
        if (thisLoc < prevLoc + prevLen)
            badOverlap(thisLoc);
        tail = thisDesc;
        if (!storeDesc(prevLoc, prevFmt, thisDesc)) {
            // overflow
            int bigSize = bigDescs[BIGSIZE];
            if (bigDescs.length == bigSize)
                growBigDescs();
            //System.out.println("bigDescs["+bigSize+"] = "+thisDesc);
            bigDescs[bigSize++] = thisDesc;
            bigDescs[BIGSIZE] = bigSize;
        }
    }
    size += 1;
}
 
Example #15
Source File: Package.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected void visitRefs(int mode, Collection<Entry> refs) {
    super.visitRefs(mode, refs);
    if (code != null) {
        if (mode == VRM_CLASSIC) {
            refs.add(getRefString("Code"));
        }
        code.visitRefs(mode, refs);
    }
}
 
Example #16
Source File: ClassReader.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void fixUnresolvedEntries() {
    if (!haveUnresolvedEntry)  return;
    Entry[] cpMap = cls.getCPMap();
    for (int i = 0; i < cpMap.length; i++) {
        Entry e = cpMap[i];
        if (e instanceof UnresolvedEntry) {
            cpMap[i] = e = ((UnresolvedEntry)e).resolve();
            assert(!(e instanceof UnresolvedEntry));
        }
    }
    haveUnresolvedEntry = false;
}
 
Example #17
Source File: Fixups.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void trimToSize() {
    if (size != entries.length) {
        Entry[] oldEntries = entries;
        entries = new Entry[size];
        System.arraycopy(oldEntries, 0, entries, 0, size);
    }
    int bigSize = bigDescs[BIGSIZE];
    if (bigSize == MINBIGSIZE) {
        bigDescs = noBigDescs;
    } else if (bigSize != bigDescs.length) {
        int[] oldBigDescs = bigDescs;
        bigDescs = new int[bigSize];
        System.arraycopy(oldBigDescs, 0, bigDescs, 0, bigSize);
    }
}
 
Example #18
Source File: Package.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
protected void visitRefs(int mode, Collection<Entry> refs) {
    refs.add(thisClass);
    if (mode == VRM_CLASSIC || !predictable) {
        // If the name can be demangled, the package omits
        // the products of demangling.  Otherwise, include them.
        refs.add(outerClass);
        refs.add(name);
    }
}
 
Example #19
Source File: Package.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void transformSourceFile(boolean minimize) {
    // Replace "obvious" SourceFile by null.
    Attribute olda = getAttribute(attrSourceFileSpecial);
    if (olda == null)
        return;  // no SourceFile attr.
    String obvious = getObviousSourceFile();
    List<Entry> ref = new ArrayList<>(1);
    olda.visitRefs(this, VRM_PACKAGE, ref);
    Utf8Entry sfName = (Utf8Entry) ref.get(0);
    Attribute a = olda;
    if (sfName == null) {
        if (minimize) {
            // A pair of zero bytes.  Cannot use predef. layout.
            a = Attribute.find(ATTR_CONTEXT_CLASS, "SourceFile", "H");
            a = a.addContent(new byte[2]);
        } else {
            // Expand null attribute to the obvious string.
            byte[] bytes = new byte[2];
            sfName = getRefString(obvious);
            Object f = null;
            f = Fixups.addRefWithBytes(f, bytes, sfName);
            a = attrSourceFileSpecial.addContent(bytes, f);
        }
    } else if (obvious.equals(sfName.stringValue())) {
        if (minimize) {
            // Replace by an all-zero attribute.
            a = attrSourceFileSpecial.addContent(new byte[2]);
        } else {
            assert(false);
        }
    }
    if (a != olda) {
        if (verbose > 2)
            Utils.log.fine("recoding obvious SourceFile="+obvious);
        List<Attribute> newAttrs = new ArrayList<>(getAttributes());
        int where = newAttrs.indexOf(olda);
        newAttrs.set(where, a);
        setAttributes(newAttrs);
    }
}
 
Example #20
Source File: Package.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
protected void visitRefs(int mode, Collection<Entry> refs) {
    if (verbose > 2)  Utils.log.fine("visitRefs "+this);
    // Careful:  The descriptor is used by the package,
    // but the classfile breaks it into component refs.
    if (mode == VRM_CLASSIC) {
        refs.add(descriptor.nameRef);
        refs.add(descriptor.typeRef);
    } else {
        refs.add(descriptor);
    }
    // Handle attribute list:
    super.visitRefs(mode, refs);
}
 
Example #21
Source File: Fixups.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static
void finishRefs(Object fixups, byte[] bytes, ConstantPool.Index ix) {
    if (fixups == null)
        return;
    if (!(fixups instanceof Fixups)) {
        // Special convention; see above.
        int index = ix.indexOf((Entry) fixups);
        storeIndex(bytes, SPECIAL_LOC, SPECIAL_FMT, index);
        return;
    }
    Fixups f = (Fixups) fixups;
    assert(f.bytes == bytes);
    f.finishRefs(ix);
}
 
Example #22
Source File: Fixups.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static
void visitRefs(Object fixups, Collection<Entry> refs) {
    if (fixups == null) {
    } else if (!(fixups instanceof Fixups)) {
        // Special convention; see above.
        refs.add((Entry) fixups);
    } else {
        Fixups f = (Fixups) fixups;
        f.visitRefs(refs);
    }
}
 
Example #23
Source File: Package.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void transformSourceFile(boolean minimize) {
    // Replace "obvious" SourceFile by null.
    Attribute olda = getAttribute(attrSourceFileSpecial);
    if (olda == null)
        return;  // no SourceFile attr.
    String obvious = getObviousSourceFile();
    List<Entry> ref = new ArrayList<>(1);
    olda.visitRefs(this, VRM_PACKAGE, ref);
    Utf8Entry sfName = (Utf8Entry) ref.get(0);
    Attribute a = olda;
    if (sfName == null) {
        if (minimize) {
            // A pair of zero bytes.  Cannot use predef. layout.
            a = Attribute.find(ATTR_CONTEXT_CLASS, "SourceFile", "H");
            a = a.addContent(new byte[2]);
        } else {
            // Expand null attribute to the obvious string.
            byte[] bytes = new byte[2];
            sfName = getRefString(obvious);
            Object f = null;
            f = Fixups.addRefWithBytes(f, bytes, sfName);
            a = attrSourceFileSpecial.addContent(bytes, f);
        }
    } else if (obvious.equals(sfName.stringValue())) {
        if (minimize) {
            // Replace by an all-zero attribute.
            a = attrSourceFileSpecial.addContent(new byte[2]);
        } else {
            assert(false);
        }
    }
    if (a != olda) {
        if (verbose > 2)
            Utils.log.fine("recoding obvious SourceFile="+obvious);
        List<Attribute> newAttrs = new ArrayList<>(getAttributes());
        int where = newAttrs.indexOf(olda);
        newAttrs.set(where, a);
        setAttributes(newAttrs);
    }
}
 
Example #24
Source File: Package.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected void visitRefs(int mode, Collection<Entry> refs) {
    super.visitRefs(mode, refs);
    if (code != null) {
        if (mode == VRM_CLASSIC) {
            refs.add(getRefString("Code"));
        }
        code.visitRefs(mode, refs);
    }
}
 
Example #25
Source File: Package.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected void visitRefs(int mode, Collection<Entry> refs) {
    for ( Class c : classes) {
        c.visitRefs(mode, refs);
    }
    if (mode != VRM_CLASSIC) {
        for (File f : files) {
            f.visitRefs(mode, refs);
        }
        visitInnerClassRefs(allInnerClasses, mode, refs);
    }
}
 
Example #26
Source File: Fixups.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static
void finishRefs(Object fixups, byte[] bytes, ConstantPool.Index ix) {
    if (fixups == null)
        return;
    if (!(fixups instanceof Fixups)) {
        // Special convention; see above.
        int index = ix.indexOf((Entry) fixups);
        storeIndex(bytes, SPECIAL_LOC, SPECIAL_FMT, index);
        return;
    }
    Fixups f = (Fixups) fixups;
    assert(f.bytes == bytes);
    f.finishRefs(ix);
}
 
Example #27
Source File: Package.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void transformSourceFile(boolean minimize) {
    // Replace "obvious" SourceFile by null.
    Attribute olda = getAttribute(attrSourceFileSpecial);
    if (olda == null)
        return;  // no SourceFile attr.
    String obvious = getObviousSourceFile();
    List<Entry> ref = new ArrayList<>(1);
    olda.visitRefs(this, VRM_PACKAGE, ref);
    Utf8Entry sfName = (Utf8Entry) ref.get(0);
    Attribute a = olda;
    if (sfName == null) {
        if (minimize) {
            // A pair of zero bytes.  Cannot use predef. layout.
            a = Attribute.find(ATTR_CONTEXT_CLASS, "SourceFile", "H");
            a = a.addContent(new byte[2]);
        } else {
            // Expand null attribute to the obvious string.
            byte[] bytes = new byte[2];
            sfName = getRefString(obvious);
            Object f = null;
            f = Fixups.addRefWithBytes(f, bytes, sfName);
            a = attrSourceFileSpecial.addContent(bytes, f);
        }
    } else if (obvious.equals(sfName.stringValue())) {
        if (minimize) {
            // Replace by an all-zero attribute.
            a = attrSourceFileSpecial.addContent(new byte[2]);
        } else {
            assert(false);
        }
    }
    if (a != olda) {
        if (verbose > 2)
            Utils.log.fine("recoding obvious SourceFile="+obvious);
        List<Attribute> newAttrs = new ArrayList<>(getAttributes());
        int where = newAttrs.indexOf(olda);
        newAttrs.set(where, a);
        setAttributes(newAttrs);
    }
}
 
Example #28
Source File: BandStructure.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
int encodeRef(Entry e, Index ix) {
    if (ix == null)
        throw new RuntimeException("null index for " + e.stringValue());
    int coding = ix.indexOf(e);
    if (verbose > 2)
        Utils.log.fine("putRef "+coding+" => "+e);
    return coding;
}
 
Example #29
Source File: Package.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected void visitRefs(int mode, Collection<Entry> refs) {
    for ( Class c : classes) {
        c.visitRefs(mode, refs);
    }
    if (mode != VRM_CLASSIC) {
        for (File f : files) {
            f.visitRefs(mode, refs);
        }
        visitInnerClassRefs(allInnerClasses, mode, refs);
    }
}
 
Example #30
Source File: BandStructure.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void printArrayTo(PrintStream ps, Entry[] cpMap, int start, int end, boolean showTags) {
    StringBuffer buf = new StringBuffer();
    int len = end-start;
    for (int i = 0; i < len; i++) {
        Entry e = cpMap[start+i];
        ps.print(start+i); ps.print("=");
        if (showTags) { ps.print(e.tag); ps.print(":"); }
        String s = e.stringValue();
        buf.setLength(0);
        for (int j = 0; j < s.length(); j++) {
            char ch = s.charAt(j);
            if (!(ch < ' ' || ch > '~' || ch == '\\')) {
                buf.append(ch);
            } else if (ch == '\\') {
                buf.append("\\\\");
            } else if (ch == '\n') {
                buf.append("\\n");
            } else if (ch == '\t') {
                buf.append("\\t");
            } else if (ch == '\r') {
                buf.append("\\r");
            } else {
                String str = "000"+Integer.toHexString(ch);
                buf.append("\\u").append(str.substring(str.length()-4));
            }
        }
        ps.println(buf);
    }
}