Constants.java revision 12745:f068a4ffddd2
1/* 2 * Copyright (c) 2001, 2013, 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 23 * questions. 24 */ 25 26package com.sun.java.util.jar.pack; 27 28import java.util.Arrays; 29import java.util.List; 30 31/** 32 * Shared constants 33 * @author John Rose 34 */ 35class Constants { 36 37 private Constants(){} 38 39 public static final int JAVA_MAGIC = 0xCAFEBABE; 40 41 /* 42 Java Class Version numbers history 43 1.0 to 1.3.X 45,3 44 1.4 to 1.4.X 46,0 45 1.5 to 1.5.X 49,0 46 1.6 to 1.5.x 50,0 47 1.7 to 1.6.x 51,0 48 1.8 to 1.7.x 52,0 49 */ 50 51 public static final Package.Version JAVA_MIN_CLASS_VERSION = 52 Package.Version.of(45, 03); 53 54 public static final Package.Version JAVA5_MAX_CLASS_VERSION = 55 Package.Version.of(49, 00); 56 57 public static final Package.Version JAVA6_MAX_CLASS_VERSION = 58 Package.Version.of(50, 00); 59 60 public static final Package.Version JAVA7_MAX_CLASS_VERSION = 61 Package.Version.of(51, 00); 62 63 public static final Package.Version JAVA8_MAX_CLASS_VERSION = 64 Package.Version.of(52, 00); 65 66 public static final int JAVA_PACKAGE_MAGIC = 0xCAFED00D; 67 68 public static final Package.Version JAVA5_PACKAGE_VERSION = 69 Package.Version.of(150, 7); 70 71 public static final Package.Version JAVA6_PACKAGE_VERSION = 72 Package.Version.of(160, 1); 73 74 public static final Package.Version JAVA7_PACKAGE_VERSION = 75 Package.Version.of(170, 1); 76 77 public static final Package.Version JAVA8_PACKAGE_VERSION = 78 Package.Version.of(171, 0); 79 80 // upper limit, should point to the latest class version 81 public static final Package.Version JAVA_MAX_CLASS_VERSION = 82 JAVA8_MAX_CLASS_VERSION; 83 84 // upper limit should point to the latest package version, for version info!. 85 public static final Package.Version MAX_PACKAGE_VERSION = 86 JAVA7_PACKAGE_VERSION; 87 88 public static final int CONSTANT_POOL_INDEX_LIMIT = 0x10000; 89 public static final int CONSTANT_POOL_NARROW_LIMIT = 0x00100; 90 91 public static final String JAVA_SIGNATURE_CHARS = "BSCIJFDZLV(["; 92 93 public static final byte CONSTANT_Utf8 = 1; 94 public static final byte CONSTANT_unused2 = 2; // unused, was Unicode 95 public static final byte CONSTANT_Integer = 3; 96 public static final byte CONSTANT_Float = 4; 97 public static final byte CONSTANT_Long = 5; 98 public static final byte CONSTANT_Double = 6; 99 public static final byte CONSTANT_Class = 7; 100 public static final byte CONSTANT_String = 8; 101 public static final byte CONSTANT_Fieldref = 9; 102 public static final byte CONSTANT_Methodref = 10; 103 public static final byte CONSTANT_InterfaceMethodref = 11; 104 public static final byte CONSTANT_NameandType = 12; 105 public static final byte CONSTANT_unused13 = 13; 106 public static final byte CONSTANT_unused14 = 14; 107 public static final byte CONSTANT_MethodHandle = 15; 108 public static final byte CONSTANT_MethodType = 16; 109 public static final byte CONSTANT_unused17 = 17; // unused 110 public static final byte CONSTANT_InvokeDynamic = 18; 111 112 // pseudo-constants: 113 public static final byte CONSTANT_None = 0; 114 public static final byte CONSTANT_Signature = CONSTANT_unused13; 115 public static final byte CONSTANT_BootstrapMethod = CONSTANT_unused17; // used only in InvokeDynamic constants 116 public static final byte CONSTANT_Limit = 19; 117 118 public static final byte CONSTANT_All = 50; // combined global map 119 public static final byte CONSTANT_LoadableValue = 51; // used for 'KL' and qldc operands 120 public static final byte CONSTANT_AnyMember = 52; // union of refs to field or (interface) method 121 public static final byte CONSTANT_FieldSpecific = 53; // used only for 'KQ' ConstantValue attrs 122 public static final byte CONSTANT_GroupFirst = CONSTANT_All; 123 public static final byte CONSTANT_GroupLimit = CONSTANT_FieldSpecific+1; 124 125 // CONSTANT_MethodHandle reference kinds 126 public static final byte REF_getField = 1; 127 public static final byte REF_getStatic = 2; 128 public static final byte REF_putField = 3; 129 public static final byte REF_putStatic = 4; 130 public static final byte REF_invokeVirtual = 5; 131 public static final byte REF_invokeStatic = 6; 132 public static final byte REF_invokeSpecial = 7; 133 public static final byte REF_newInvokeSpecial = 8; 134 public static final byte REF_invokeInterface = 9; 135 136 // pseudo-access bits 137 public static final int ACC_IC_LONG_FORM = (1<<16); //for ic_flags 138 139 // attribute "context types" 140 public static final int ATTR_CONTEXT_CLASS = 0; 141 public static final int ATTR_CONTEXT_FIELD = 1; 142 public static final int ATTR_CONTEXT_METHOD = 2; 143 public static final int ATTR_CONTEXT_CODE = 3; 144 public static final int ATTR_CONTEXT_LIMIT = 4; 145 public static final String[] ATTR_CONTEXT_NAME 146 = { "class", "field", "method", "code" }; 147 148 // predefined attr bits 149 public static final int 150 X_ATTR_OVERFLOW = 16, 151 CLASS_ATTR_SourceFile = 17, 152 METHOD_ATTR_Code = 17, 153 FIELD_ATTR_ConstantValue = 17, 154 CLASS_ATTR_EnclosingMethod = 18, 155 METHOD_ATTR_Exceptions = 18, 156 X_ATTR_Signature = 19, 157 X_ATTR_Deprecated = 20, 158 X_ATTR_RuntimeVisibleAnnotations = 21, 159 X_ATTR_RuntimeInvisibleAnnotations = 22, 160 METHOD_ATTR_RuntimeVisibleParameterAnnotations = 23, 161 CLASS_ATTR_InnerClasses = 23, 162 METHOD_ATTR_RuntimeInvisibleParameterAnnotations = 24, 163 CLASS_ATTR_ClassFile_version = 24, 164 METHOD_ATTR_AnnotationDefault = 25, 165 METHOD_ATTR_MethodParameters = 26, // JDK8 166 X_ATTR_RuntimeVisibleTypeAnnotations = 27, // JDK8 167 X_ATTR_RuntimeInvisibleTypeAnnotations = 28, // JDK8 168 CODE_ATTR_StackMapTable = 0, // new in Java 6 169 CODE_ATTR_LineNumberTable = 1, 170 CODE_ATTR_LocalVariableTable = 2, 171 CODE_ATTR_LocalVariableTypeTable = 3; 172 173 // File option bits, from LSB in ascending bit position. 174 public static final int FO_DEFLATE_HINT = 1<<0; 175 public static final int FO_IS_CLASS_STUB = 1<<1; 176 177 // Archive option bits, from LSB in ascending bit position: 178 public static final int AO_HAVE_SPECIAL_FORMATS = 1<<0; 179 public static final int AO_HAVE_CP_NUMBERS = 1<<1; 180 public static final int AO_HAVE_ALL_CODE_FLAGS = 1<<2; 181 public static final int AO_HAVE_CP_EXTRAS = 1<<3; 182 public static final int AO_HAVE_FILE_HEADERS = 1<<4; 183 public static final int AO_DEFLATE_HINT = 1<<5; 184 public static final int AO_HAVE_FILE_MODTIME = 1<<6; 185 public static final int AO_HAVE_FILE_OPTIONS = 1<<7; 186 public static final int AO_HAVE_FILE_SIZE_HI = 1<<8; 187 public static final int AO_HAVE_CLASS_FLAGS_HI = 1<<9; 188 public static final int AO_HAVE_FIELD_FLAGS_HI = 1<<10; 189 public static final int AO_HAVE_METHOD_FLAGS_HI = 1<<11; 190 public static final int AO_HAVE_CODE_FLAGS_HI = 1<<12; 191 public static final int AO_UNUSED_MBZ = (-1)<<13; // option bits reserved for future use 192 193 public static final int LG_AO_HAVE_XXX_FLAGS_HI = 9; 194 195 // visitRefs modes: 196 static final int VRM_CLASSIC = 0; 197 static final int VRM_PACKAGE = 1; 198 199 public static final int NO_MODTIME = 0; // null modtime value 200 201 // some comstantly empty containers 202 public static final int[] noInts = {}; 203 public static final byte[] noBytes = {}; 204 public static final Object[] noValues = {}; 205 public static final String[] noStrings = {}; 206 public static final List<Object> emptyList = Arrays.asList(noValues); 207 208 // meta-coding 209 public static final int 210 _meta_default = 0, 211 _meta_canon_min = 1, 212 _meta_canon_max = 115, 213 _meta_arb = 116, 214 _meta_run = 117, 215 _meta_pop = 141, 216 _meta_limit = 189; 217 218 // bytecodes 219 public static final int 220 _nop = 0, // 0x00 221 _aconst_null = 1, // 0x01 222 _iconst_m1 = 2, // 0x02 223 _iconst_0 = 3, // 0x03 224 _iconst_1 = 4, // 0x04 225 _iconst_2 = 5, // 0x05 226 _iconst_3 = 6, // 0x06 227 _iconst_4 = 7, // 0x07 228 _iconst_5 = 8, // 0x08 229 _lconst_0 = 9, // 0x09 230 _lconst_1 = 10, // 0x0a 231 _fconst_0 = 11, // 0x0b 232 _fconst_1 = 12, // 0x0c 233 _fconst_2 = 13, // 0x0d 234 _dconst_0 = 14, // 0x0e 235 _dconst_1 = 15, // 0x0f 236 _bipush = 16, // 0x10 237 _sipush = 17, // 0x11 238 _ldc = 18, // 0x12 239 _ldc_w = 19, // 0x13 240 _ldc2_w = 20, // 0x14 241 _iload = 21, // 0x15 242 _lload = 22, // 0x16 243 _fload = 23, // 0x17 244 _dload = 24, // 0x18 245 _aload = 25, // 0x19 246 _iload_0 = 26, // 0x1a 247 _iload_1 = 27, // 0x1b 248 _iload_2 = 28, // 0x1c 249 _iload_3 = 29, // 0x1d 250 _lload_0 = 30, // 0x1e 251 _lload_1 = 31, // 0x1f 252 _lload_2 = 32, // 0x20 253 _lload_3 = 33, // 0x21 254 _fload_0 = 34, // 0x22 255 _fload_1 = 35, // 0x23 256 _fload_2 = 36, // 0x24 257 _fload_3 = 37, // 0x25 258 _dload_0 = 38, // 0x26 259 _dload_1 = 39, // 0x27 260 _dload_2 = 40, // 0x28 261 _dload_3 = 41, // 0x29 262 _aload_0 = 42, // 0x2a 263 _aload_1 = 43, // 0x2b 264 _aload_2 = 44, // 0x2c 265 _aload_3 = 45, // 0x2d 266 _iaload = 46, // 0x2e 267 _laload = 47, // 0x2f 268 _faload = 48, // 0x30 269 _daload = 49, // 0x31 270 _aaload = 50, // 0x32 271 _baload = 51, // 0x33 272 _caload = 52, // 0x34 273 _saload = 53, // 0x35 274 _istore = 54, // 0x36 275 _lstore = 55, // 0x37 276 _fstore = 56, // 0x38 277 _dstore = 57, // 0x39 278 _astore = 58, // 0x3a 279 _istore_0 = 59, // 0x3b 280 _istore_1 = 60, // 0x3c 281 _istore_2 = 61, // 0x3d 282 _istore_3 = 62, // 0x3e 283 _lstore_0 = 63, // 0x3f 284 _lstore_1 = 64, // 0x40 285 _lstore_2 = 65, // 0x41 286 _lstore_3 = 66, // 0x42 287 _fstore_0 = 67, // 0x43 288 _fstore_1 = 68, // 0x44 289 _fstore_2 = 69, // 0x45 290 _fstore_3 = 70, // 0x46 291 _dstore_0 = 71, // 0x47 292 _dstore_1 = 72, // 0x48 293 _dstore_2 = 73, // 0x49 294 _dstore_3 = 74, // 0x4a 295 _astore_0 = 75, // 0x4b 296 _astore_1 = 76, // 0x4c 297 _astore_2 = 77, // 0x4d 298 _astore_3 = 78, // 0x4e 299 _iastore = 79, // 0x4f 300 _lastore = 80, // 0x50 301 _fastore = 81, // 0x51 302 _dastore = 82, // 0x52 303 _aastore = 83, // 0x53 304 _bastore = 84, // 0x54 305 _castore = 85, // 0x55 306 _sastore = 86, // 0x56 307 _pop = 87, // 0x57 308 _pop2 = 88, // 0x58 309 _dup = 89, // 0x59 310 _dup_x1 = 90, // 0x5a 311 _dup_x2 = 91, // 0x5b 312 _dup2 = 92, // 0x5c 313 _dup2_x1 = 93, // 0x5d 314 _dup2_x2 = 94, // 0x5e 315 _swap = 95, // 0x5f 316 _iadd = 96, // 0x60 317 _ladd = 97, // 0x61 318 _fadd = 98, // 0x62 319 _dadd = 99, // 0x63 320 _isub = 100, // 0x64 321 _lsub = 101, // 0x65 322 _fsub = 102, // 0x66 323 _dsub = 103, // 0x67 324 _imul = 104, // 0x68 325 _lmul = 105, // 0x69 326 _fmul = 106, // 0x6a 327 _dmul = 107, // 0x6b 328 _idiv = 108, // 0x6c 329 _ldiv = 109, // 0x6d 330 _fdiv = 110, // 0x6e 331 _ddiv = 111, // 0x6f 332 _irem = 112, // 0x70 333 _lrem = 113, // 0x71 334 _frem = 114, // 0x72 335 _drem = 115, // 0x73 336 _ineg = 116, // 0x74 337 _lneg = 117, // 0x75 338 _fneg = 118, // 0x76 339 _dneg = 119, // 0x77 340 _ishl = 120, // 0x78 341 _lshl = 121, // 0x79 342 _ishr = 122, // 0x7a 343 _lshr = 123, // 0x7b 344 _iushr = 124, // 0x7c 345 _lushr = 125, // 0x7d 346 _iand = 126, // 0x7e 347 _land = 127, // 0x7f 348 _ior = 128, // 0x80 349 _lor = 129, // 0x81 350 _ixor = 130, // 0x82 351 _lxor = 131, // 0x83 352 _iinc = 132, // 0x84 353 _i2l = 133, // 0x85 354 _i2f = 134, // 0x86 355 _i2d = 135, // 0x87 356 _l2i = 136, // 0x88 357 _l2f = 137, // 0x89 358 _l2d = 138, // 0x8a 359 _f2i = 139, // 0x8b 360 _f2l = 140, // 0x8c 361 _f2d = 141, // 0x8d 362 _d2i = 142, // 0x8e 363 _d2l = 143, // 0x8f 364 _d2f = 144, // 0x90 365 _i2b = 145, // 0x91 366 _i2c = 146, // 0x92 367 _i2s = 147, // 0x93 368 _lcmp = 148, // 0x94 369 _fcmpl = 149, // 0x95 370 _fcmpg = 150, // 0x96 371 _dcmpl = 151, // 0x97 372 _dcmpg = 152, // 0x98 373 _ifeq = 153, // 0x99 374 _ifne = 154, // 0x9a 375 _iflt = 155, // 0x9b 376 _ifge = 156, // 0x9c 377 _ifgt = 157, // 0x9d 378 _ifle = 158, // 0x9e 379 _if_icmpeq = 159, // 0x9f 380 _if_icmpne = 160, // 0xa0 381 _if_icmplt = 161, // 0xa1 382 _if_icmpge = 162, // 0xa2 383 _if_icmpgt = 163, // 0xa3 384 _if_icmple = 164, // 0xa4 385 _if_acmpeq = 165, // 0xa5 386 _if_acmpne = 166, // 0xa6 387 _goto = 167, // 0xa7 388 _jsr = 168, // 0xa8 389 _ret = 169, // 0xa9 390 _tableswitch = 170, // 0xaa 391 _lookupswitch = 171, // 0xab 392 _ireturn = 172, // 0xac 393 _lreturn = 173, // 0xad 394 _freturn = 174, // 0xae 395 _dreturn = 175, // 0xaf 396 _areturn = 176, // 0xb0 397 _return = 177, // 0xb1 398 _getstatic = 178, // 0xb2 399 _putstatic = 179, // 0xb3 400 _getfield = 180, // 0xb4 401 _putfield = 181, // 0xb5 402 _invokevirtual = 182, // 0xb6 403 _invokespecial = 183, // 0xb7 404 _invokestatic = 184, // 0xb8 405 _invokeinterface = 185, // 0xb9 406 _invokedynamic = 186, // 0xba 407 _new = 187, // 0xbb 408 _newarray = 188, // 0xbc 409 _anewarray = 189, // 0xbd 410 _arraylength = 190, // 0xbe 411 _athrow = 191, // 0xbf 412 _checkcast = 192, // 0xc0 413 _instanceof = 193, // 0xc1 414 _monitorenter = 194, // 0xc2 415 _monitorexit = 195, // 0xc3 416 _wide = 196, // 0xc4 417 _multianewarray = 197, // 0xc5 418 _ifnull = 198, // 0xc6 419 _ifnonnull = 199, // 0xc7 420 _goto_w = 200, // 0xc8 421 _jsr_w = 201, // 0xc9 422 _bytecode_limit = 202; // 0xca 423 424 // End marker, used to terminate bytecode sequences: 425 public static final int _end_marker = 255; 426 // Escapes: 427 public static final int _byte_escape = 254; 428 public static final int _ref_escape = 253; 429 430 // Self-relative pseudo-opcodes for better compression. 431 // A "linker op" is a bytecode which links to a class member. 432 // (But in what follows, "invokeinterface" ops are excluded.) 433 // 434 // A "self linker op" is a variant bytecode which works only 435 // with the current class or its super. Because the number of 436 // possible targets is small, it admits a more compact encoding. 437 // Self linker ops are allowed to absorb a previous "aload_0" op. 438 // There are (7 * 4) self linker ops (super or not, aload_0 or not). 439 // 440 // For simplicity, we define the full symmetric set of variants. 441 // However, some of them are relatively useless. 442 // Self linker ops are enabled by Pack.selfCallVariants (true). 443 public static final int _first_linker_op = _getstatic; 444 public static final int _last_linker_op = _invokestatic; 445 public static final int _num_linker_ops = (_last_linker_op - _first_linker_op) + 1; 446 public static final int _self_linker_op = _bytecode_limit; 447 public static final int _self_linker_aload_flag = 1*_num_linker_ops; 448 public static final int _self_linker_super_flag = 2*_num_linker_ops; 449 public static final int _self_linker_limit = _self_linker_op + 4*_num_linker_ops; 450 // An "invoke init" op is a variant of invokespecial which works 451 // only with the method name "<init>". There are variants which 452 // link to the current class, the super class, or the class of the 453 // immediately previous "newinstance" op. There are 3 of these ops. 454 // They all take method signature references as operands. 455 // Invoke init ops are enabled by Pack.initCallVariants (true). 456 public static final int _invokeinit_op = _self_linker_limit; 457 public static final int _invokeinit_self_option = 0; 458 public static final int _invokeinit_super_option = 1; 459 public static final int _invokeinit_new_option = 2; 460 public static final int _invokeinit_limit = _invokeinit_op+3; 461 462 public static final int _pseudo_instruction_limit = _invokeinit_limit; 463 // linker variant limit == 202+(7*4)+3 == 233 464 465 // Ldc variants support strongly typed references to constants. 466 // This lets us index constant pool entries completely according to tag, 467 // which is a great simplification. 468 // Ldc variants gain us only 0.007% improvement in compression ratio, 469 // but they simplify the file format greatly. 470 public static final int _xldc_op = _invokeinit_limit; 471 public static final int _sldc = _ldc; // previously named _aldc 472 public static final int _cldc = _xldc_op+0; 473 public static final int _ildc = _xldc_op+1; 474 public static final int _fldc = _xldc_op+2; 475 public static final int _sldc_w = _ldc_w; // previously named _aldc_w 476 public static final int _cldc_w = _xldc_op+3; 477 public static final int _ildc_w = _xldc_op+4; 478 public static final int _fldc_w = _xldc_op+5; 479 public static final int _lldc2_w = _ldc2_w; 480 public static final int _dldc2_w = _xldc_op+6; 481 // anything other than primitive, string, or class must be handled with qldc: 482 public static final int _qldc = _xldc_op+7; 483 public static final int _qldc_w = _xldc_op+8; 484 public static final int _xldc_limit = _xldc_op+9; 485 486 // handling of InterfaceMethodRef 487 public static final int _invoke_int_op = _xldc_limit; 488 public static final int _invokespecial_int = _invoke_int_op+0; 489 public static final int _invokestatic_int = _invoke_int_op+1; 490 public static final int _invoke_int_limit = _invoke_int_op+2; 491} 492