com.sun.tools.javac.jvm.ClassFile.Version Java Examples

The following examples show how to use com.sun.tools.javac.jvm.ClassFile.Version. 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: NBClassReader.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public NBClassReader(Context context) {
    super(context);

    names = Names.instance(context);
    nbNames = NBNames.instance(context);

    NBAttributeReader[] readers = {
        new NBAttributeReader(nbNames._org_netbeans_EnclosingMethod, Version.V45_3, CLASS_OR_MEMBER_ATTRIBUTE) {
            public void read(Symbol sym, int attrLen) {
                int newbp = bp + attrLen;
                readEnclosingMethodAttr(sym);
                bp = newbp;
            }
        },
    };

    for (NBAttributeReader r: readers)
        attributeReaders.put(r.getName(), r);
}
 
Example #2
Source File: ClassReader.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Read a class definition from the bytes in buf.
 */
private void readClassBuffer(ClassSymbol c) throws IOException {
    int magic = nextInt();
    if (magic != JAVA_MAGIC)
        throw badClassFile("illegal.start.of.class.file");

    minorVersion = nextChar();
    majorVersion = nextChar();
    int maxMajor = 53; // Version.MAX().major;  //******* TEMPORARY *******
    int maxMinor = Version.MAX().minor;
    if (majorVersion > maxMajor ||
        majorVersion * 1000 + minorVersion <
        Version.MIN().major * 1000 + Version.MIN().minor) {
        if (majorVersion == (maxMajor + 1))
            log.warning(Warnings.BigMajorVersion(currentClassFile,
                                                 majorVersion,
                                                 maxMajor));
        else
            throw badClassFile("wrong.version",
                               Integer.toString(majorVersion),
                               Integer.toString(minorVersion),
                               Integer.toString(maxMajor),
                               Integer.toString(maxMinor));
    }

    indexPool();
    if (signatureBuffer.length < bp) {
        int ns = Integer.highestOneBit(bp) << 1;
        signatureBuffer = new byte[ns];
    }
    readClass(c);
}
 
Example #3
Source File: ClassReader.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/** Read a class definition from the bytes in buf.
 */
private void readClassBuffer(ClassSymbol c) throws IOException {
    int magic = nextInt();
    if (magic != JAVA_MAGIC)
        throw badClassFile("illegal.start.of.class.file");

    minorVersion = nextChar();
    majorVersion = nextChar();
    int maxMajor = 53; // Version.MAX().major;  //******* TEMPORARY *******
    int maxMinor = Version.MAX().minor;
    if (majorVersion > maxMajor ||
        majorVersion * 1000 + minorVersion <
        Version.MIN().major * 1000 + Version.MIN().minor) {
        if (majorVersion == (maxMajor + 1))
            log.warning("big.major.version",
                        currentClassFile,
                        majorVersion,
                        maxMajor);
        else
            throw badClassFile("wrong.version",
                               Integer.toString(majorVersion),
                               Integer.toString(minorVersion),
                               Integer.toString(maxMajor),
                               Integer.toString(maxMinor));
    }

    indexPool();
    if (signatureBuffer.length < bp) {
        int ns = Integer.highestOneBit(bp) << 1;
        signatureBuffer = new byte[ns];
    }
    readClass(c);
}
 
Example #4
Source File: ClassReader.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected AttributeReader(Name name, ClassFile.Version version, Set<AttributeKind> kinds) {
    this.name = name;
    this.version = version;
    this.kinds = kinds;
}
 
Example #5
Source File: NBClassReader.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private NBAttributeReader(Name name, Version version, Set<AttributeKind> kinds) {
    super(name, version, kinds);
}
 
Example #6
Source File: ClassReader.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
protected AttributeReader(Name name, ClassFile.Version version, Set<AttributeKind> kinds) {
    this.name = name;
    this.version = version;
    this.kinds = kinds;
}
 
Example #7
Source File: ClassReader.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/** Read a method.
 */
MethodSymbol readMethod() {
    long flags = adjustMethodFlags(nextChar());
    Name name = readName(nextChar());
    Type type = readType(nextChar());
    if (currentOwner.isInterface() &&
            (flags & ABSTRACT) == 0 && !name.equals(names.clinit)) {
        if (majorVersion > Version.V52.major ||
                (majorVersion == Version.V52.major && minorVersion >= Version.V52.minor)) {
            if ((flags & (STATIC | PRIVATE)) == 0) {
                currentOwner.flags_field |= DEFAULT;
                flags |= DEFAULT | ABSTRACT;
            }
        } else {
            //protect against ill-formed classfiles
            throw badClassFile((flags & STATIC) == 0 ? "invalid.default.interface" : "invalid.static.interface",
                               Integer.toString(majorVersion),
                               Integer.toString(minorVersion));
        }
    }
    if (name == names.init && currentOwner.hasOuterInstance()) {
        // Sometimes anonymous classes don't have an outer
        // instance, however, there is no reliable way to tell so
        // we never strip this$n
        // ditto for local classes. Local classes that have an enclosing method set
        // won't pass the "hasOuterInstance" check above, but those that don't have an
        // enclosing method (i.e. from initializers) will pass that check.
        boolean local = !currentOwner.owner.members().includes(currentOwner, LookupKind.NON_RECURSIVE);
        if (!currentOwner.name.isEmpty() && !local)
            type = new MethodType(adjustMethodParams(flags, type.getParameterTypes()),
                                  type.getReturnType(),
                                  type.getThrownTypes(),
                                  syms.methodClass);
    }
    MethodSymbol m = new MethodSymbol(flags, name, type, currentOwner);
    if (types.isSignaturePolymorphic(m)) {
        m.flags_field |= SIGNATURE_POLYMORPHIC;
    }
    if (saveParameterNames)
        initParameterNames(m);
    Symbol prevOwner = currentOwner;
    currentOwner = m;
    try {
        readMemberAttrs(m);
    } finally {
        currentOwner = prevOwner;
    }
    if (saveParameterNames)
        setParameterNames(m, type);

    if ((flags & VARARGS) != 0) {
        final Type last = type.getParameterTypes().last();
        if (last == null || !last.hasTag(ARRAY)) {
            m.flags_field &= ~VARARGS;
            throw badClassFile("malformed.vararg.method", m);
        }
    }

    return m;
}
 
Example #8
Source File: ClassReader.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/** Read contents of a given class symbol `c'. Both external and internal
 *  versions of an inner class are read.
 */
void readClass(ClassSymbol c) {
    ClassType ct = (ClassType)c.type;

    // allocate scope for members
    c.members_field = WriteableScope.create(c);

    // prepare type variable table
    typevars = typevars.dup(currentOwner);
    if (ct.getEnclosingType().hasTag(CLASS))
        enterTypevars(c.owner, ct.getEnclosingType());

    // read flags, or skip if this is an inner class
    long f = nextChar();
    long flags = adjustClassFlags(f);
    if ((flags & MODULE) == 0) {
        if (c.owner.kind == PCK) c.flags_field = flags;
        // read own class name and check that it matches
        currentModule = c.packge().modle;
        ClassSymbol self = readClassSymbol(nextChar());
        if (c != self) {
            throw badClassFile("class.file.wrong.class",
                               self.flatname);
        }
    } else {
        if (majorVersion < Version.V53.major) {
            throw badClassFile("anachronistic.module.info",
                    Integer.toString(majorVersion),
                    Integer.toString(minorVersion));
        }
        c.flags_field = flags;
        currentModule = (ModuleSymbol) c.owner;
        int this_class = nextChar();
        // temp, no check on this_class
    }

    // class attributes must be read before class
    // skip ahead to read class attributes
    int startbp = bp;
    nextChar();
    char interfaceCount = nextChar();
    bp += interfaceCount * 2;
    char fieldCount = nextChar();
    for (int i = 0; i < fieldCount; i++) skipMember();
    char methodCount = nextChar();
    for (int i = 0; i < methodCount; i++) skipMember();
    readClassAttrs(c);

    if (readAllOfClassFile) {
        for (int i = 1; i < poolObj.length; i++) readPool(i);
        c.pool = new Pool(poolObj.length, poolObj, types);
    }

    // reset and read rest of classinfo
    bp = startbp;
    int n = nextChar();
    if ((flags & MODULE) != 0 && n > 0) {
        throw badClassFile("module.info.invalid.super.class");
    }
    if (ct.supertype_field == null)
        ct.supertype_field = (n == 0)
            ? Type.noType
            : readClassSymbol(n).erasure(types);
    n = nextChar();
    List<Type> is = List.nil();
    for (int i = 0; i < n; i++) {
        Type _inter = readClassSymbol(nextChar()).erasure(types);
        is = is.prepend(_inter);
    }
    if (ct.interfaces_field == null)
        ct.interfaces_field = is.reverse();

    Assert.check(fieldCount == nextChar());
    for (int i = 0; i < fieldCount; i++) enterMember(c, readField());
    Assert.check(methodCount == nextChar());
    for (int i = 0; i < methodCount; i++) enterMember(c, readMethod());

    typevars = typevars.leave();
}