< prev index next >

src/jdk.rmic/share/classes/sun/tools/java/BinaryClass.java

Print this page


   1 /*
   2  * Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 105      * Load a binary class
 106      */
 107     public static BinaryClass load(Environment env, DataInputStream in) throws IOException {
 108         return load(env, in, ~(ATT_CODE|ATT_ALLCLASSES));
 109     }
 110 
 111     public static BinaryClass load(Environment env,
 112                                    DataInputStream in, int mask) throws IOException {
 113         // Read the header
 114         int magic = in.readInt();                    // JVM 4.1 ClassFile.magic
 115         if (magic != JAVA_MAGIC) {
 116             throw new ClassFormatError("wrong magic: " + magic + ", expected " + JAVA_MAGIC);
 117         }
 118         int minor_version = in.readUnsignedShort();  // JVM 4.1 ClassFile.minor_version
 119         int version = in.readUnsignedShort();        // JVM 4.1 ClassFile.major_version
 120         if (version < JAVA_MIN_SUPPORTED_VERSION) {
 121             throw new ClassFormatError(
 122                            sun.tools.javac.Main.getText(
 123                                "javac.err.version.too.old",
 124                                String.valueOf(version)));
 125         } else if ((version >= JAVA_MIN_PREVIEW_MAJOR_VERSION)
 126                      && (minor_version == JAVA_PREVIEW_MINOR_VERSION)) {
 127             // reject all class files that have preview features enabled
 128             throw new ClassFormatError(
 129                            sun.tools.javac.Main.getText(
 130                                "javac.err.version.preview",
 131                                version+"."+minor_version));
 132         } else if ((version > JAVA_MAX_SUPPORTED_VERSION)
 133                      || (version == JAVA_MAX_SUPPORTED_VERSION
 134                   && minor_version > JAVA_MAX_SUPPORTED_MINOR_VERSION)) {
 135             throw new ClassFormatError(
 136                            sun.tools.javac.Main.getText(
 137                                "javac.err.version.too.recent",
 138                                version+"."+minor_version));
 139         }
 140 
 141         // Read the constant pool
 142         BinaryConstantPool cpool = new BinaryConstantPool(in);
 143 
 144         // The dependencies of this class
 145         Vector<ClassDeclaration> dependencies = cpool.getDependencies(env);
 146 
 147         // Read modifiers
 148         int classMod = in.readUnsignedShort() & ACCM_CLASS;  // JVM 4.1 ClassFile.access_flags
 149 
 150         // Read the class name - from JVM 4.1 ClassFile.this_class
 151         ClassDeclaration classDecl = cpool.getDeclaration(env, in.readUnsignedShort());


   1 /*
   2  * Copyright (c) 1994, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 105      * Load a binary class
 106      */
 107     public static BinaryClass load(Environment env, DataInputStream in) throws IOException {
 108         return load(env, in, ~(ATT_CODE|ATT_ALLCLASSES));
 109     }
 110 
 111     public static BinaryClass load(Environment env,
 112                                    DataInputStream in, int mask) throws IOException {
 113         // Read the header
 114         int magic = in.readInt();                    // JVM 4.1 ClassFile.magic
 115         if (magic != JAVA_MAGIC) {
 116             throw new ClassFormatError("wrong magic: " + magic + ", expected " + JAVA_MAGIC);
 117         }
 118         int minor_version = in.readUnsignedShort();  // JVM 4.1 ClassFile.minor_version
 119         int version = in.readUnsignedShort();        // JVM 4.1 ClassFile.major_version
 120         if (version < JAVA_MIN_SUPPORTED_VERSION) {
 121             throw new ClassFormatError(
 122                            sun.tools.javac.Main.getText(
 123                                "javac.err.version.too.old",
 124                                String.valueOf(version)));







 125         } else if ((version > JAVA_MAX_SUPPORTED_VERSION)
 126                      || (version == JAVA_MAX_SUPPORTED_VERSION
 127                   && minor_version > JAVA_MAX_SUPPORTED_MINOR_VERSION)) {
 128             throw new ClassFormatError(
 129                            sun.tools.javac.Main.getText(
 130                                "javac.err.version.too.recent",
 131                                version+"."+minor_version));
 132         }
 133 
 134         // Read the constant pool
 135         BinaryConstantPool cpool = new BinaryConstantPool(in);
 136 
 137         // The dependencies of this class
 138         Vector<ClassDeclaration> dependencies = cpool.getDependencies(env);
 139 
 140         // Read modifiers
 141         int classMod = in.readUnsignedShort() & ACCM_CLASS;  // JVM 4.1 ClassFile.access_flags
 142 
 143         // Read the class name - from JVM 4.1 ClassFile.this_class
 144         ClassDeclaration classDecl = cpool.getDeclaration(env, in.readUnsignedShort());


< prev index next >