0N/A/*
2498N/A * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.java.util.jar.pack;
0N/A
3063N/Aimport java.util.Arrays;
3063N/Aimport java.util.List;
0N/A
0N/A/**
0N/A * Shared constants
0N/A * @author John Rose
0N/A */
3315N/Aclass Constants {
3315N/A
3315N/A private Constants(){}
3315N/A
0N/A public final static int JAVA_MAGIC = 0xCAFEBABE;
0N/A
0N/A /*
0N/A Java Class Version numbers history
0N/A 1.0 to 1.3.X 45,3
0N/A 1.4 to 1.4.X 46,0
0N/A 1.5 to 1.5.X 49,0
0N/A 1.6 to 1.5.x 50,0 NOTE Assumed for now
0N/A */
0N/A
0N/A public final static short JAVA_MIN_CLASS_MAJOR_VERSION = 45;
0N/A public final static short JAVA_MIN_CLASS_MINOR_VERSION = 03;
0N/A
0N/A public final static short JAVA5_MAX_CLASS_MAJOR_VERSION = 49;
0N/A public final static short JAVA5_MAX_CLASS_MINOR_VERSION = 0;
2498N/A
0N/A public final static short JAVA6_MAX_CLASS_MAJOR_VERSION = 50;
0N/A public final static short JAVA6_MAX_CLASS_MINOR_VERSION = 0;
0N/A
2498N/A public final static short JAVA7_MAX_CLASS_MAJOR_VERSION = 51;
2498N/A public final static short JAVA7_MAX_CLASS_MINOR_VERSION = 0;
2498N/A
0N/A public final static int JAVA_PACKAGE_MAGIC = 0xCAFED00D;
0N/A public final static int JAVA5_PACKAGE_MAJOR_VERSION = 150;
0N/A public final static int JAVA5_PACKAGE_MINOR_VERSION = 7;
0N/A
0N/A public final static int JAVA6_PACKAGE_MAJOR_VERSION = 160;
0N/A public final static int JAVA6_PACKAGE_MINOR_VERSION = 1;
0N/A
0N/A public final static int CONSTANT_POOL_INDEX_LIMIT = 0x10000;
0N/A public final static int CONSTANT_POOL_NARROW_LIMIT = 0x00100;
0N/A
0N/A public final static String JAVA_SIGNATURE_CHARS = "BSCIJFDZLV([";
0N/A
0N/A public final static byte CONSTANT_Utf8 = 1;
0N/A public final static byte CONSTANT_unused2 = 2; // unused, was Unicode
0N/A public final static byte CONSTANT_Integer = 3;
0N/A public final static byte CONSTANT_Float = 4;
0N/A public final static byte CONSTANT_Long = 5;
0N/A public final static byte CONSTANT_Double = 6;
0N/A public final static byte CONSTANT_Class = 7;
0N/A public final static byte CONSTANT_String = 8;
0N/A public final static byte CONSTANT_Fieldref = 9;
0N/A public final static byte CONSTANT_Methodref = 10;
0N/A public final static byte CONSTANT_InterfaceMethodref = 11;
0N/A public final static byte CONSTANT_NameandType = 12;
0N/A
0N/A // pseudo-constants:
0N/A public final static byte CONSTANT_None = 0;
0N/A public final static byte CONSTANT_Signature = 13;
0N/A public final static byte CONSTANT_Limit = 14;
0N/A
0N/A public final static byte CONSTANT_All = 19; // combined global map
0N/A public final static byte CONSTANT_Literal = 20; // used only for ldc fields
0N/A
0N/A // pseudo-access bits
0N/A public final static int ACC_IC_LONG_FORM = (1<<16); //for ic_flags
0N/A
0N/A // attribute "context types"
0N/A public static final int ATTR_CONTEXT_CLASS = 0;
0N/A public static final int ATTR_CONTEXT_FIELD = 1;
0N/A public static final int ATTR_CONTEXT_METHOD = 2;
0N/A public static final int ATTR_CONTEXT_CODE = 3;
0N/A public static final int ATTR_CONTEXT_LIMIT = 4;
0N/A public static final String[] ATTR_CONTEXT_NAME
0N/A = { "class", "field", "method", "code" };
0N/A
0N/A // predefined attr bits
0N/A public static final int
0N/A X_ATTR_OVERFLOW = 16,
0N/A CLASS_ATTR_SourceFile = 17,
0N/A METHOD_ATTR_Code = 17,
0N/A FIELD_ATTR_ConstantValue = 17,
0N/A CLASS_ATTR_EnclosingMethod = 18,
0N/A METHOD_ATTR_Exceptions = 18,
0N/A X_ATTR_Signature = 19,
0N/A X_ATTR_Deprecated = 20,
0N/A X_ATTR_RuntimeVisibleAnnotations = 21,
0N/A X_ATTR_RuntimeInvisibleAnnotations = 22,
0N/A METHOD_ATTR_RuntimeVisibleParameterAnnotations = 23,
0N/A CLASS_ATTR_InnerClasses = 23,
0N/A METHOD_ATTR_RuntimeInvisibleParameterAnnotations = 24,
0N/A CLASS_ATTR_ClassFile_version = 24,
0N/A METHOD_ATTR_AnnotationDefault = 25,
0N/A CODE_ATTR_StackMapTable = 0, // new in Java 6
0N/A CODE_ATTR_LineNumberTable = 1,
0N/A CODE_ATTR_LocalVariableTable = 2,
0N/A CODE_ATTR_LocalVariableTypeTable = 3;
0N/A
0N/A // File option bits, from LSB in ascending bit position.
0N/A public static final int FO_DEFLATE_HINT = 1<<0;
0N/A public static final int FO_IS_CLASS_STUB = 1<<1;
0N/A
0N/A // Archive option bits, from LSB in ascending bit position:
0N/A public static final int AO_HAVE_SPECIAL_FORMATS = 1<<0;
0N/A public static final int AO_HAVE_CP_NUMBERS = 1<<1;
0N/A public static final int AO_HAVE_ALL_CODE_FLAGS = 1<<2;
0N/A public static final int AO_3_UNUSED_MBZ = 1<<3;
0N/A public static final int AO_HAVE_FILE_HEADERS = 1<<4;
0N/A public static final int AO_DEFLATE_HINT = 1<<5;
0N/A public static final int AO_HAVE_FILE_MODTIME = 1<<6;
0N/A public static final int AO_HAVE_FILE_OPTIONS = 1<<7;
0N/A public static final int AO_HAVE_FILE_SIZE_HI = 1<<8;
0N/A public static final int AO_HAVE_CLASS_FLAGS_HI = 1<<9;
0N/A public static final int AO_HAVE_FIELD_FLAGS_HI = 1<<10;
0N/A public static final int AO_HAVE_METHOD_FLAGS_HI = 1<<11;
0N/A public static final int AO_HAVE_CODE_FLAGS_HI = 1<<12;
0N/A
0N/A public static final int LG_AO_HAVE_XXX_FLAGS_HI = 9;
0N/A
0N/A // visitRefs modes:
0N/A static final int VRM_CLASSIC = 0;
0N/A static final int VRM_PACKAGE = 1;
0N/A
0N/A public static final int NO_MODTIME = 0; // null modtime value
0N/A
0N/A // some comstantly empty containers
0N/A public final static int[] noInts = {};
0N/A public final static byte[] noBytes = {};
0N/A public final static Object[] noValues = {};
0N/A public final static String[] noStrings = {};
0N/A public final static List emptyList = Arrays.asList(noValues);
0N/A
0N/A // meta-coding
0N/A public final static int
0N/A _meta_default = 0,
0N/A _meta_canon_min = 1,
0N/A _meta_canon_max = 115,
0N/A _meta_arb = 116,
0N/A _meta_run = 117,
0N/A _meta_pop = 141,
0N/A _meta_limit = 189;
0N/A
0N/A // bytecodes
0N/A public final static int
0N/A _nop = 0, // 0x00
0N/A _aconst_null = 1, // 0x01
0N/A _iconst_m1 = 2, // 0x02
0N/A _iconst_0 = 3, // 0x03
0N/A _iconst_1 = 4, // 0x04
0N/A _iconst_2 = 5, // 0x05
0N/A _iconst_3 = 6, // 0x06
0N/A _iconst_4 = 7, // 0x07
0N/A _iconst_5 = 8, // 0x08
0N/A _lconst_0 = 9, // 0x09
0N/A _lconst_1 = 10, // 0x0a
0N/A _fconst_0 = 11, // 0x0b
0N/A _fconst_1 = 12, // 0x0c
0N/A _fconst_2 = 13, // 0x0d
0N/A _dconst_0 = 14, // 0x0e
0N/A _dconst_1 = 15, // 0x0f
0N/A _bipush = 16, // 0x10
0N/A _sipush = 17, // 0x11
0N/A _ldc = 18, // 0x12
0N/A _ldc_w = 19, // 0x13
0N/A _ldc2_w = 20, // 0x14
0N/A _iload = 21, // 0x15
0N/A _lload = 22, // 0x16
0N/A _fload = 23, // 0x17
0N/A _dload = 24, // 0x18
0N/A _aload = 25, // 0x19
0N/A _iload_0 = 26, // 0x1a
0N/A _iload_1 = 27, // 0x1b
0N/A _iload_2 = 28, // 0x1c
0N/A _iload_3 = 29, // 0x1d
0N/A _lload_0 = 30, // 0x1e
0N/A _lload_1 = 31, // 0x1f
0N/A _lload_2 = 32, // 0x20
0N/A _lload_3 = 33, // 0x21
0N/A _fload_0 = 34, // 0x22
0N/A _fload_1 = 35, // 0x23
0N/A _fload_2 = 36, // 0x24
0N/A _fload_3 = 37, // 0x25
0N/A _dload_0 = 38, // 0x26
0N/A _dload_1 = 39, // 0x27
0N/A _dload_2 = 40, // 0x28
0N/A _dload_3 = 41, // 0x29
0N/A _aload_0 = 42, // 0x2a
0N/A _aload_1 = 43, // 0x2b
0N/A _aload_2 = 44, // 0x2c
0N/A _aload_3 = 45, // 0x2d
0N/A _iaload = 46, // 0x2e
0N/A _laload = 47, // 0x2f
0N/A _faload = 48, // 0x30
0N/A _daload = 49, // 0x31
0N/A _aaload = 50, // 0x32
0N/A _baload = 51, // 0x33
0N/A _caload = 52, // 0x34
0N/A _saload = 53, // 0x35
0N/A _istore = 54, // 0x36
0N/A _lstore = 55, // 0x37
0N/A _fstore = 56, // 0x38
0N/A _dstore = 57, // 0x39
0N/A _astore = 58, // 0x3a
0N/A _istore_0 = 59, // 0x3b
0N/A _istore_1 = 60, // 0x3c
0N/A _istore_2 = 61, // 0x3d
0N/A _istore_3 = 62, // 0x3e
0N/A _lstore_0 = 63, // 0x3f
0N/A _lstore_1 = 64, // 0x40
0N/A _lstore_2 = 65, // 0x41
0N/A _lstore_3 = 66, // 0x42
0N/A _fstore_0 = 67, // 0x43
0N/A _fstore_1 = 68, // 0x44
0N/A _fstore_2 = 69, // 0x45
0N/A _fstore_3 = 70, // 0x46
0N/A _dstore_0 = 71, // 0x47
0N/A _dstore_1 = 72, // 0x48
0N/A _dstore_2 = 73, // 0x49
0N/A _dstore_3 = 74, // 0x4a
0N/A _astore_0 = 75, // 0x4b
0N/A _astore_1 = 76, // 0x4c
0N/A _astore_2 = 77, // 0x4d
0N/A _astore_3 = 78, // 0x4e
0N/A _iastore = 79, // 0x4f
0N/A _lastore = 80, // 0x50
0N/A _fastore = 81, // 0x51
0N/A _dastore = 82, // 0x52
0N/A _aastore = 83, // 0x53
0N/A _bastore = 84, // 0x54
0N/A _castore = 85, // 0x55
0N/A _sastore = 86, // 0x56
0N/A _pop = 87, // 0x57
0N/A _pop2 = 88, // 0x58
0N/A _dup = 89, // 0x59
0N/A _dup_x1 = 90, // 0x5a
0N/A _dup_x2 = 91, // 0x5b
0N/A _dup2 = 92, // 0x5c
0N/A _dup2_x1 = 93, // 0x5d
0N/A _dup2_x2 = 94, // 0x5e
0N/A _swap = 95, // 0x5f
0N/A _iadd = 96, // 0x60
0N/A _ladd = 97, // 0x61
0N/A _fadd = 98, // 0x62
0N/A _dadd = 99, // 0x63
0N/A _isub = 100, // 0x64
0N/A _lsub = 101, // 0x65
0N/A _fsub = 102, // 0x66
0N/A _dsub = 103, // 0x67
0N/A _imul = 104, // 0x68
0N/A _lmul = 105, // 0x69
0N/A _fmul = 106, // 0x6a
0N/A _dmul = 107, // 0x6b
0N/A _idiv = 108, // 0x6c
0N/A _ldiv = 109, // 0x6d
0N/A _fdiv = 110, // 0x6e
0N/A _ddiv = 111, // 0x6f
0N/A _irem = 112, // 0x70
0N/A _lrem = 113, // 0x71
0N/A _frem = 114, // 0x72
0N/A _drem = 115, // 0x73
0N/A _ineg = 116, // 0x74
0N/A _lneg = 117, // 0x75
0N/A _fneg = 118, // 0x76
0N/A _dneg = 119, // 0x77
0N/A _ishl = 120, // 0x78
0N/A _lshl = 121, // 0x79
0N/A _ishr = 122, // 0x7a
0N/A _lshr = 123, // 0x7b
0N/A _iushr = 124, // 0x7c
0N/A _lushr = 125, // 0x7d
0N/A _iand = 126, // 0x7e
0N/A _land = 127, // 0x7f
0N/A _ior = 128, // 0x80
0N/A _lor = 129, // 0x81
0N/A _ixor = 130, // 0x82
0N/A _lxor = 131, // 0x83
0N/A _iinc = 132, // 0x84
0N/A _i2l = 133, // 0x85
0N/A _i2f = 134, // 0x86
0N/A _i2d = 135, // 0x87
0N/A _l2i = 136, // 0x88
0N/A _l2f = 137, // 0x89
0N/A _l2d = 138, // 0x8a
0N/A _f2i = 139, // 0x8b
0N/A _f2l = 140, // 0x8c
0N/A _f2d = 141, // 0x8d
0N/A _d2i = 142, // 0x8e
0N/A _d2l = 143, // 0x8f
0N/A _d2f = 144, // 0x90
0N/A _i2b = 145, // 0x91
0N/A _i2c = 146, // 0x92
0N/A _i2s = 147, // 0x93
0N/A _lcmp = 148, // 0x94
0N/A _fcmpl = 149, // 0x95
0N/A _fcmpg = 150, // 0x96
0N/A _dcmpl = 151, // 0x97
0N/A _dcmpg = 152, // 0x98
0N/A _ifeq = 153, // 0x99
0N/A _ifne = 154, // 0x9a
0N/A _iflt = 155, // 0x9b
0N/A _ifge = 156, // 0x9c
0N/A _ifgt = 157, // 0x9d
0N/A _ifle = 158, // 0x9e
0N/A _if_icmpeq = 159, // 0x9f
0N/A _if_icmpne = 160, // 0xa0
0N/A _if_icmplt = 161, // 0xa1
0N/A _if_icmpge = 162, // 0xa2
0N/A _if_icmpgt = 163, // 0xa3
0N/A _if_icmple = 164, // 0xa4
0N/A _if_acmpeq = 165, // 0xa5
0N/A _if_acmpne = 166, // 0xa6
0N/A _goto = 167, // 0xa7
0N/A _jsr = 168, // 0xa8
0N/A _ret = 169, // 0xa9
0N/A _tableswitch = 170, // 0xaa
0N/A _lookupswitch = 171, // 0xab
0N/A _ireturn = 172, // 0xac
0N/A _lreturn = 173, // 0xad
0N/A _freturn = 174, // 0xae
0N/A _dreturn = 175, // 0xaf
0N/A _areturn = 176, // 0xb0
0N/A _return = 177, // 0xb1
0N/A _getstatic = 178, // 0xb2
0N/A _putstatic = 179, // 0xb3
0N/A _getfield = 180, // 0xb4
0N/A _putfield = 181, // 0xb5
0N/A _invokevirtual = 182, // 0xb6
0N/A _invokespecial = 183, // 0xb7
0N/A _invokestatic = 184, // 0xb8
0N/A _invokeinterface = 185, // 0xb9
0N/A _xxxunusedxxx = 186, // 0xba
0N/A _new = 187, // 0xbb
0N/A _newarray = 188, // 0xbc
0N/A _anewarray = 189, // 0xbd
0N/A _arraylength = 190, // 0xbe
0N/A _athrow = 191, // 0xbf
0N/A _checkcast = 192, // 0xc0
0N/A _instanceof = 193, // 0xc1
0N/A _monitorenter = 194, // 0xc2
0N/A _monitorexit = 195, // 0xc3
0N/A _wide = 196, // 0xc4
0N/A _multianewarray = 197, // 0xc5
0N/A _ifnull = 198, // 0xc6
0N/A _ifnonnull = 199, // 0xc7
0N/A _goto_w = 200, // 0xc8
0N/A _jsr_w = 201, // 0xc9
0N/A _bytecode_limit = 202; // 0xca
0N/A
0N/A // End marker, used to terminate bytecode sequences:
0N/A public final static int _end_marker = 255;
0N/A // Escapes:
0N/A public final static int _byte_escape = 254;
0N/A public final static int _ref_escape = 253;
0N/A
0N/A // Self-relative pseudo-opcodes for better compression.
0N/A // A "linker op" is a bytecode which links to a class member.
0N/A // (But in what follows, "invokeinterface" ops are excluded.)
0N/A //
0N/A // A "self linker op" is a variant bytecode which works only
0N/A // with the current class or its super. Because the number of
0N/A // possible targets is small, it admits a more compact encoding.
0N/A // Self linker ops are allowed to absorb a previous "aload_0" op.
0N/A // There are (7 * 4) self linker ops (super or not, aload_0 or not).
0N/A //
0N/A // For simplicity, we define the full symmetric set of variants.
0N/A // However, some of them are relatively useless.
0N/A // Self linker ops are enabled by Pack.selfCallVariants (true).
0N/A public final static int _first_linker_op = _getstatic;
0N/A public final static int _last_linker_op = _invokestatic;
0N/A public final static int _num_linker_ops = (_last_linker_op - _first_linker_op) + 1;
0N/A public final static int _self_linker_op = _bytecode_limit;
0N/A public final static int _self_linker_aload_flag = 1*_num_linker_ops;
0N/A public final static int _self_linker_super_flag = 2*_num_linker_ops;
0N/A public final static int _self_linker_limit = _self_linker_op + 4*_num_linker_ops;
0N/A // An "invoke init" op is a variant of invokespecial which works
0N/A // only with the method name "<init>". There are variants which
0N/A // link to the current class, the super class, or the class of the
0N/A // immediately previous "newinstance" op. There are 3 of these ops.
0N/A // They all take method signature references as operands.
0N/A // Invoke init ops are enabled by Pack.initCallVariants (true).
0N/A public final static int _invokeinit_op = _self_linker_limit;
0N/A public final static int _invokeinit_self_option = 0;
0N/A public final static int _invokeinit_super_option = 1;
0N/A public final static int _invokeinit_new_option = 2;
0N/A public final static int _invokeinit_limit = _invokeinit_op+3;
0N/A
0N/A public final static int _pseudo_instruction_limit = _invokeinit_limit;
0N/A // linker variant limit == 202+(7*4)+3 == 233
0N/A
0N/A // Ldc variants support strongly typed references to constants.
0N/A // This lets us index constant pool entries completely according to tag,
0N/A // which is a great simplification.
0N/A // Ldc variants gain us only 0.007% improvement in compression ratio,
0N/A // but they simplify the file format greatly.
0N/A public final static int _xldc_op = _invokeinit_limit;
0N/A public final static int _aldc = _ldc;
0N/A public final static int _cldc = _xldc_op+0;
0N/A public final static int _ildc = _xldc_op+1;
0N/A public final static int _fldc = _xldc_op+2;
0N/A public final static int _aldc_w = _ldc_w;
0N/A public final static int _cldc_w = _xldc_op+3;
0N/A public final static int _ildc_w = _xldc_op+4;
0N/A public final static int _fldc_w = _xldc_op+5;
0N/A public final static int _lldc2_w = _ldc2_w;
0N/A public final static int _dldc2_w = _xldc_op+6;
0N/A public final static int _xldc_limit = _xldc_op+7;
0N/A}