001: /*
002: * Copyright 2001-2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.java.util.jar.pack;
027:
028: import java.util.*;
029:
030: /**
031: * Shared constants
032: * @author John Rose
033: * @version 1.30, 05/05/07
034: */
035: interface Constants {
036: public final static int JAVA_MAGIC = 0xCAFEBABE;
037:
038: /*
039: Java Class Version numbers history
040: 1.0 to 1.3.X 45,3
041: 1.4 to 1.4.X 46,0
042: 1.5 to 1.5.X 49,0
043: 1.6 to 1.5.x 50,0 NOTE Assumed for now
044: */
045:
046: public final static short JAVA_MIN_CLASS_MAJOR_VERSION = 45;
047: public final static short JAVA_MIN_CLASS_MINOR_VERSION = 03;
048:
049: public final static short JAVA5_MAX_CLASS_MAJOR_VERSION = 49;
050: public final static short JAVA5_MAX_CLASS_MINOR_VERSION = 0;
051: // NOTE: ASSUMED for now
052: public final static short JAVA6_MAX_CLASS_MAJOR_VERSION = 50;
053: public final static short JAVA6_MAX_CLASS_MINOR_VERSION = 0;
054:
055: public final static int JAVA_PACKAGE_MAGIC = 0xCAFED00D;
056: public final static int JAVA5_PACKAGE_MAJOR_VERSION = 150;
057: public final static int JAVA5_PACKAGE_MINOR_VERSION = 7;
058:
059: public final static int JAVA6_PACKAGE_MAJOR_VERSION = 160;
060: public final static int JAVA6_PACKAGE_MINOR_VERSION = 1;
061:
062: public final static int CONSTANT_POOL_INDEX_LIMIT = 0x10000;
063: public final static int CONSTANT_POOL_NARROW_LIMIT = 0x00100;
064:
065: public final static String JAVA_SIGNATURE_CHARS = "BSCIJFDZLV([";
066:
067: public final static byte CONSTANT_Utf8 = 1;
068: public final static byte CONSTANT_unused2 = 2; // unused, was Unicode
069: public final static byte CONSTANT_Integer = 3;
070: public final static byte CONSTANT_Float = 4;
071: public final static byte CONSTANT_Long = 5;
072: public final static byte CONSTANT_Double = 6;
073: public final static byte CONSTANT_Class = 7;
074: public final static byte CONSTANT_String = 8;
075: public final static byte CONSTANT_Fieldref = 9;
076: public final static byte CONSTANT_Methodref = 10;
077: public final static byte CONSTANT_InterfaceMethodref = 11;
078: public final static byte CONSTANT_NameandType = 12;
079:
080: // pseudo-constants:
081: public final static byte CONSTANT_None = 0;
082: public final static byte CONSTANT_Signature = 13;
083: public final static byte CONSTANT_Limit = 14;
084:
085: public final static byte CONSTANT_All = 19; // combined global map
086: public final static byte CONSTANT_Literal = 20; // used only for ldc fields
087:
088: // pseudo-access bits
089: public final static int ACC_IC_LONG_FORM = (1 << 16); //for ic_flags
090:
091: // attribute "context types"
092: public static final int ATTR_CONTEXT_CLASS = 0;
093: public static final int ATTR_CONTEXT_FIELD = 1;
094: public static final int ATTR_CONTEXT_METHOD = 2;
095: public static final int ATTR_CONTEXT_CODE = 3;
096: public static final int ATTR_CONTEXT_LIMIT = 4;
097: public static final String[] ATTR_CONTEXT_NAME = { "class",
098: "field", "method", "code" };
099:
100: // predefined attr bits
101: public static final int X_ATTR_OVERFLOW = 16,
102: CLASS_ATTR_SourceFile = 17,
103: METHOD_ATTR_Code = 17,
104: FIELD_ATTR_ConstantValue = 17,
105: CLASS_ATTR_EnclosingMethod = 18,
106: METHOD_ATTR_Exceptions = 18,
107: X_ATTR_Signature = 19,
108: X_ATTR_Deprecated = 20,
109: X_ATTR_RuntimeVisibleAnnotations = 21,
110: X_ATTR_RuntimeInvisibleAnnotations = 22,
111: METHOD_ATTR_RuntimeVisibleParameterAnnotations = 23,
112: CLASS_ATTR_InnerClasses = 23,
113: METHOD_ATTR_RuntimeInvisibleParameterAnnotations = 24,
114: CLASS_ATTR_ClassFile_version = 24,
115: METHOD_ATTR_AnnotationDefault = 25,
116: CODE_ATTR_StackMapTable = 0, // new in Java 6
117: CODE_ATTR_LineNumberTable = 1,
118: CODE_ATTR_LocalVariableTable = 2,
119: CODE_ATTR_LocalVariableTypeTable = 3;
120:
121: // File option bits, from LSB in ascending bit position.
122: public static final int FO_DEFLATE_HINT = 1 << 0;
123: public static final int FO_IS_CLASS_STUB = 1 << 1;
124:
125: // Archive option bits, from LSB in ascending bit position:
126: public static final int AO_HAVE_SPECIAL_FORMATS = 1 << 0;
127: public static final int AO_HAVE_CP_NUMBERS = 1 << 1;
128: public static final int AO_HAVE_ALL_CODE_FLAGS = 1 << 2;
129: public static final int AO_3_UNUSED_MBZ = 1 << 3;
130: public static final int AO_HAVE_FILE_HEADERS = 1 << 4;
131: public static final int AO_DEFLATE_HINT = 1 << 5;
132: public static final int AO_HAVE_FILE_MODTIME = 1 << 6;
133: public static final int AO_HAVE_FILE_OPTIONS = 1 << 7;
134: public static final int AO_HAVE_FILE_SIZE_HI = 1 << 8;
135: public static final int AO_HAVE_CLASS_FLAGS_HI = 1 << 9;
136: public static final int AO_HAVE_FIELD_FLAGS_HI = 1 << 10;
137: public static final int AO_HAVE_METHOD_FLAGS_HI = 1 << 11;
138: public static final int AO_HAVE_CODE_FLAGS_HI = 1 << 12;
139:
140: public static final int LG_AO_HAVE_XXX_FLAGS_HI = 9;
141:
142: // visitRefs modes:
143: static final int VRM_CLASSIC = 0;
144: static final int VRM_PACKAGE = 1;
145:
146: public static final int NO_MODTIME = 0; // null modtime value
147:
148: // some comstantly empty containers
149: public final static int[] noInts = {};
150: public final static byte[] noBytes = {};
151: public final static Object[] noValues = {};
152: public final static String[] noStrings = {};
153: public final static List emptyList = Arrays.asList(noValues);
154:
155: // meta-coding
156: public final static int _meta_default = 0, _meta_canon_min = 1,
157: _meta_canon_max = 115, _meta_arb = 116, _meta_run = 117,
158: _meta_pop = 141, _meta_limit = 189;
159:
160: // bytecodes
161: public final static int _nop = 0, // 0x00
162: _aconst_null = 1, // 0x01
163: _iconst_m1 = 2, // 0x02
164: _iconst_0 = 3, // 0x03
165: _iconst_1 = 4, // 0x04
166: _iconst_2 = 5, // 0x05
167: _iconst_3 = 6, // 0x06
168: _iconst_4 = 7, // 0x07
169: _iconst_5 = 8, // 0x08
170: _lconst_0 = 9, // 0x09
171: _lconst_1 = 10, // 0x0a
172: _fconst_0 = 11, // 0x0b
173: _fconst_1 = 12, // 0x0c
174: _fconst_2 = 13, // 0x0d
175: _dconst_0 = 14, // 0x0e
176: _dconst_1 = 15, // 0x0f
177: _bipush = 16, // 0x10
178: _sipush = 17, // 0x11
179: _ldc = 18, // 0x12
180: _ldc_w = 19, // 0x13
181: _ldc2_w = 20, // 0x14
182: _iload = 21, // 0x15
183: _lload = 22, // 0x16
184: _fload = 23, // 0x17
185: _dload = 24, // 0x18
186: _aload = 25, // 0x19
187: _iload_0 = 26, // 0x1a
188: _iload_1 = 27, // 0x1b
189: _iload_2 = 28, // 0x1c
190: _iload_3 = 29, // 0x1d
191: _lload_0 = 30, // 0x1e
192: _lload_1 = 31, // 0x1f
193: _lload_2 = 32, // 0x20
194: _lload_3 = 33, // 0x21
195: _fload_0 = 34, // 0x22
196: _fload_1 = 35, // 0x23
197: _fload_2 = 36, // 0x24
198: _fload_3 = 37, // 0x25
199: _dload_0 = 38, // 0x26
200: _dload_1 = 39, // 0x27
201: _dload_2 = 40, // 0x28
202: _dload_3 = 41, // 0x29
203: _aload_0 = 42, // 0x2a
204: _aload_1 = 43, // 0x2b
205: _aload_2 = 44, // 0x2c
206: _aload_3 = 45, // 0x2d
207: _iaload = 46, // 0x2e
208: _laload = 47, // 0x2f
209: _faload = 48, // 0x30
210: _daload = 49, // 0x31
211: _aaload = 50, // 0x32
212: _baload = 51, // 0x33
213: _caload = 52, // 0x34
214: _saload = 53, // 0x35
215: _istore = 54, // 0x36
216: _lstore = 55, // 0x37
217: _fstore = 56, // 0x38
218: _dstore = 57, // 0x39
219: _astore = 58, // 0x3a
220: _istore_0 = 59, // 0x3b
221: _istore_1 = 60, // 0x3c
222: _istore_2 = 61, // 0x3d
223: _istore_3 = 62, // 0x3e
224: _lstore_0 = 63, // 0x3f
225: _lstore_1 = 64, // 0x40
226: _lstore_2 = 65, // 0x41
227: _lstore_3 = 66, // 0x42
228: _fstore_0 = 67, // 0x43
229: _fstore_1 = 68, // 0x44
230: _fstore_2 = 69, // 0x45
231: _fstore_3 = 70, // 0x46
232: _dstore_0 = 71, // 0x47
233: _dstore_1 = 72, // 0x48
234: _dstore_2 = 73, // 0x49
235: _dstore_3 = 74, // 0x4a
236: _astore_0 = 75, // 0x4b
237: _astore_1 = 76, // 0x4c
238: _astore_2 = 77, // 0x4d
239: _astore_3 = 78, // 0x4e
240: _iastore = 79, // 0x4f
241: _lastore = 80, // 0x50
242: _fastore = 81, // 0x51
243: _dastore = 82, // 0x52
244: _aastore = 83, // 0x53
245: _bastore = 84, // 0x54
246: _castore = 85, // 0x55
247: _sastore = 86, // 0x56
248: _pop = 87, // 0x57
249: _pop2 = 88, // 0x58
250: _dup = 89, // 0x59
251: _dup_x1 = 90, // 0x5a
252: _dup_x2 = 91, // 0x5b
253: _dup2 = 92, // 0x5c
254: _dup2_x1 = 93, // 0x5d
255: _dup2_x2 = 94, // 0x5e
256: _swap = 95, // 0x5f
257: _iadd = 96, // 0x60
258: _ladd = 97, // 0x61
259: _fadd = 98, // 0x62
260: _dadd = 99, // 0x63
261: _isub = 100, // 0x64
262: _lsub = 101, // 0x65
263: _fsub = 102, // 0x66
264: _dsub = 103, // 0x67
265: _imul = 104, // 0x68
266: _lmul = 105, // 0x69
267: _fmul = 106, // 0x6a
268: _dmul = 107, // 0x6b
269: _idiv = 108, // 0x6c
270: _ldiv = 109, // 0x6d
271: _fdiv = 110, // 0x6e
272: _ddiv = 111, // 0x6f
273: _irem = 112, // 0x70
274: _lrem = 113, // 0x71
275: _frem = 114, // 0x72
276: _drem = 115, // 0x73
277: _ineg = 116, // 0x74
278: _lneg = 117, // 0x75
279: _fneg = 118, // 0x76
280: _dneg = 119, // 0x77
281: _ishl = 120, // 0x78
282: _lshl = 121, // 0x79
283: _ishr = 122, // 0x7a
284: _lshr = 123, // 0x7b
285: _iushr = 124, // 0x7c
286: _lushr = 125, // 0x7d
287: _iand = 126, // 0x7e
288: _land = 127, // 0x7f
289: _ior = 128, // 0x80
290: _lor = 129, // 0x81
291: _ixor = 130, // 0x82
292: _lxor = 131, // 0x83
293: _iinc = 132, // 0x84
294: _i2l = 133, // 0x85
295: _i2f = 134, // 0x86
296: _i2d = 135, // 0x87
297: _l2i = 136, // 0x88
298: _l2f = 137, // 0x89
299: _l2d = 138, // 0x8a
300: _f2i = 139, // 0x8b
301: _f2l = 140, // 0x8c
302: _f2d = 141, // 0x8d
303: _d2i = 142, // 0x8e
304: _d2l = 143, // 0x8f
305: _d2f = 144, // 0x90
306: _i2b = 145, // 0x91
307: _i2c = 146, // 0x92
308: _i2s = 147, // 0x93
309: _lcmp = 148, // 0x94
310: _fcmpl = 149, // 0x95
311: _fcmpg = 150, // 0x96
312: _dcmpl = 151, // 0x97
313: _dcmpg = 152, // 0x98
314: _ifeq = 153, // 0x99
315: _ifne = 154, // 0x9a
316: _iflt = 155, // 0x9b
317: _ifge = 156, // 0x9c
318: _ifgt = 157, // 0x9d
319: _ifle = 158, // 0x9e
320: _if_icmpeq = 159, // 0x9f
321: _if_icmpne = 160, // 0xa0
322: _if_icmplt = 161, // 0xa1
323: _if_icmpge = 162, // 0xa2
324: _if_icmpgt = 163, // 0xa3
325: _if_icmple = 164, // 0xa4
326: _if_acmpeq = 165, // 0xa5
327: _if_acmpne = 166, // 0xa6
328: _goto = 167, // 0xa7
329: _jsr = 168, // 0xa8
330: _ret = 169, // 0xa9
331: _tableswitch = 170, // 0xaa
332: _lookupswitch = 171, // 0xab
333: _ireturn = 172, // 0xac
334: _lreturn = 173, // 0xad
335: _freturn = 174, // 0xae
336: _dreturn = 175, // 0xaf
337: _areturn = 176, // 0xb0
338: _return = 177, // 0xb1
339: _getstatic = 178, // 0xb2
340: _putstatic = 179, // 0xb3
341: _getfield = 180, // 0xb4
342: _putfield = 181, // 0xb5
343: _invokevirtual = 182, // 0xb6
344: _invokespecial = 183, // 0xb7
345: _invokestatic = 184, // 0xb8
346: _invokeinterface = 185, // 0xb9
347: _xxxunusedxxx = 186, // 0xba
348: _new = 187, // 0xbb
349: _newarray = 188, // 0xbc
350: _anewarray = 189, // 0xbd
351: _arraylength = 190, // 0xbe
352: _athrow = 191, // 0xbf
353: _checkcast = 192, // 0xc0
354: _instanceof = 193, // 0xc1
355: _monitorenter = 194, // 0xc2
356: _monitorexit = 195, // 0xc3
357: _wide = 196, // 0xc4
358: _multianewarray = 197, // 0xc5
359: _ifnull = 198, // 0xc6
360: _ifnonnull = 199, // 0xc7
361: _goto_w = 200, // 0xc8
362: _jsr_w = 201, // 0xc9
363: _bytecode_limit = 202; // 0xca
364:
365: // End marker, used to terminate bytecode sequences:
366: public final static int _end_marker = 255;
367: // Escapes:
368: public final static int _byte_escape = 254;
369: public final static int _ref_escape = 253;
370:
371: // Self-relative pseudo-opcodes for better compression.
372: // A "linker op" is a bytecode which links to a class member.
373: // (But in what follows, "invokeinterface" ops are excluded.)
374: //
375: // A "self linker op" is a variant bytecode which works only
376: // with the current class or its super. Because the number of
377: // possible targets is small, it admits a more compact encoding.
378: // Self linker ops are allowed to absorb a previous "aload_0" op.
379: // There are (7 * 4) self linker ops (super or not, aload_0 or not).
380: //
381: // For simplicity, we define the full symmetric set of variants.
382: // However, some of them are relatively useless.
383: // Self linker ops are enabled by Pack.selfCallVariants (true).
384: public final static int _first_linker_op = _getstatic;
385: public final static int _last_linker_op = _invokestatic;
386: public final static int _num_linker_ops = (_last_linker_op - _first_linker_op) + 1;
387: public final static int _self_linker_op = _bytecode_limit;
388: public final static int _self_linker_aload_flag = 1 * _num_linker_ops;
389: public final static int _self_linker_super _flag = 2 * _num_linker_ops;
390: public final static int _self_linker_limit = _self_linker_op + 4
391: * _num_linker_ops;
392: // An "invoke init" op is a variant of invokespecial which works
393: // only with the method name "<init>". There are variants which
394: // link to the current class, the super class, or the class of the
395: // immediately previous "newinstance" op. There are 3 of these ops.
396: // They all take method signature references as operands.
397: // Invoke init ops are enabled by Pack.initCallVariants (true).
398: public final static int _invokeinit_op = _self_linker_limit;
399: public final static int _invokeinit_self_option = 0;
400: public final static int _invokeinit_super _option = 1;
401: public final static int _invokeinit_new_option = 2;
402: public final static int _invokeinit_limit = _invokeinit_op + 3;
403:
404: public final static int _pseudo_instruction_limit = _invokeinit_limit;
405: // linker variant limit == 202+(7*4)+3 == 233
406:
407: // Ldc variants support strongly typed references to constants.
408: // This lets us index constant pool entries completely according to tag,
409: // which is a great simplification.
410: // Ldc variants gain us only 0.007% improvement in compression ratio,
411: // but they simplify the file format greatly.
412: public final static int _xldc_op = _invokeinit_limit;
413: public final static int _aldc = _ldc;
414: public final static int _cldc = _xldc_op + 0;
415: public final static int _ildc = _xldc_op + 1;
416: public final static int _fldc = _xldc_op + 2;
417: public final static int _aldc_w = _ldc_w;
418: public final static int _cldc_w = _xldc_op + 3;
419: public final static int _ildc_w = _xldc_op + 4;
420: public final static int _fldc_w = _xldc_op + 5;
421: public final static int _lldc2_w = _ldc2_w;
422: public final static int _dldc2_w = _xldc_op + 6;
423: public final static int _xldc_limit = _xldc_op + 7;
424: }
|