1 /* 2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 */ 4 /* 5 * Licensed to the Apache Software Foundation (ASF) under one or more 6 * contributor license agreements. See the NOTICE file distributed with 7 * this work for additional information regarding copyright ownership. 8 * The ASF licenses this file to You under the Apache License, Version 2.0 9 * (the "License"); you may not use this file except in compliance with 10 * the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 package com.sun.org.apache.bcel.internal; 21 22 import java.util.Arrays; 23 import java.util.Collections; 24 25 /** 26 * Constants for the project, mostly defined in the JVM specification. 27 * 28 * @version $Id$ 29 * @since 6.0 (intended to replace the Constants interface) 30 */ 31 public final class Const { 32 33 /** 34 * Java class file format Magic number (0xCAFEBABE) 35 * 36 * @see <a href="http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.1-200-A"> 37 * The ClassFile Structure in The Java Virtual Machine Specification</a> 38 */ 39 public static final int JVM_CLASSFILE_MAGIC = 0xCAFEBABE; 40 41 /** Major version number of class files for Java 1.1. 42 * @see #MINOR_1_1 43 * */ 44 public static final short MAJOR_1_1 = 45; 45 46 /** Minor version number of class files for Java 1.1. 47 * @see #MAJOR_1_1 48 * */ 49 public static final short MINOR_1_1 = 3; 163 /** Major version number of class files for Java 12. 164 * @see #MINOR_12 165 * */ 166 public static final short MAJOR_12 = 56; 167 168 /** Minor version number of class files for Java 12. 169 * @see #MAJOR_12 170 * */ 171 public static final short MINOR_12 = 0; 172 173 /** Major version number of class files for Java 13. 174 * @see #MINOR_13 175 * */ 176 public static final short MAJOR_13 = 57; 177 178 /** Minor version number of class files for Java 13. 179 * @see #MAJOR_13 180 * */ 181 public static final short MINOR_13 = 0; 182 183 /** Default major version number. Class file is for Java 1.1. 184 * @see #MAJOR_1_1 185 * */ 186 public static final short MAJOR = MAJOR_1_1; 187 188 /** Default major version number. Class file is for Java 1.1. 189 * @see #MAJOR_1_1 190 * */ 191 public static final short MINOR = MINOR_1_1; 192 193 /** Maximum value for an unsigned short. 194 */ 195 public static final int MAX_SHORT = 65535; // 2^16 - 1 196 197 /** Maximum value for an unsigned byte. 198 */ 199 public static final int MAX_BYTE = 255; // 2^8 - 1 200 201 /** One of the access flags for fields, methods, or classes. 202 * @see <a href='http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.5'> 203 * Flag definitions for Fields in the Java Virtual Machine Specification (Java SE 8 Edition).</a> 204 * @see <a href='http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.6'> 205 * Flag definitions for Methods in the Java Virtual Machine Specification (Java SE 8 Edition).</a> 206 * @see <a href='http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.6-300-D.1-D.1'> 207 * Flag definitions for Classes in the Java Virtual Machine Specification (Java SE 8 Edition).</a> 208 */ 209 public static final short ACC_PUBLIC = 0x0001; 210 211 /** One of the access flags for fields, methods, or classes. 212 * @see #ACC_PUBLIC 213 */ 214 public static final short ACC_PRIVATE = 0x0002; 215 216 /** One of the access flags for fields, methods, or classes. 217 * @see #ACC_PUBLIC 218 */ 219 public static final short ACC_PROTECTED = 0x0004; 220 221 /** One of the access flags for fields, methods, or classes. 222 * @see #ACC_PUBLIC 223 */ 224 public static final short ACC_STATIC = 0x0008; 225 226 /** One of the access flags for fields, methods, or classes. 227 * @see #ACC_PUBLIC 228 */ 229 public static final short ACC_FINAL = 0x0010; 230 231 /** One of the access flags for fields, methods, or classes. 232 * @see #ACC_PUBLIC 233 */ 234 public static final short ACC_SYNCHRONIZED = 0x0020; 235 236 /** One of the access flags for fields, methods, or classes. 237 * @see #ACC_PUBLIC 238 */ 239 public static final short ACC_VOLATILE = 0x0040; 240 241 /** One of the access flags for fields, methods, or classes. 242 * @see #ACC_PUBLIC 243 */ 244 public static final short ACC_BRIDGE = 0x0040; 245 246 /** One of the access flags for fields, methods, or classes. 247 * @see #ACC_PUBLIC 248 */ 249 public static final short ACC_TRANSIENT = 0x0080; 250 251 /** One of the access flags for fields, methods, or classes. 252 * @see #ACC_PUBLIC 253 */ 254 public static final short ACC_VARARGS = 0x0080; 255 256 /** One of the access flags for fields, methods, or classes. 257 * @see #ACC_PUBLIC 258 */ 259 public static final short ACC_NATIVE = 0x0100; 260 261 /** One of the access flags for fields, methods, or classes. 262 * @see #ACC_PUBLIC 263 */ 264 public static final short ACC_INTERFACE = 0x0200; 265 266 /** One of the access flags for fields, methods, or classes. 267 * @see #ACC_PUBLIC 268 */ 269 public static final short ACC_ABSTRACT = 0x0400; 270 271 /** One of the access flags for fields, methods, or classes. 272 * @see #ACC_PUBLIC 273 */ 274 public static final short ACC_STRICT = 0x0800; 275 276 /** One of the access flags for fields, methods, or classes. 277 * @see #ACC_PUBLIC 278 */ 279 public static final short ACC_SYNTHETIC = 0x1000; 280 281 /** One of the access flags for fields, methods, or classes. 282 * @see #ACC_PUBLIC 283 */ 284 public static final short ACC_ANNOTATION = 0x2000; 285 286 /** One of the access flags for fields, methods, or classes. 287 * @see #ACC_PUBLIC 288 */ 289 public static final short ACC_ENUM = 0x4000; 290 291 /** One of the access flags for fields, methods, or classes. 292 * @see #ACC_PUBLIC 293 */ 294 public static final short ACC_MANDATED = (short) 0x8000; 295 296 // Applies to classes compiled by new compilers only 297 /** One of the access flags for fields, methods, or classes. 298 * @see #ACC_PUBLIC 299 */ 300 public static final short ACC_SUPER = 0x0020; 301 302 /** One of the access flags for fields, methods, or classes. 303 * @see #ACC_PUBLIC 304 */ 305 public static final short MAX_ACC_FLAG = ACC_ENUM; 306 307 /** 308 * The names of the access flags. 309 */ 310 private static final String[] ACCESS_NAMES = { 311 "public", "private", "protected", "static", "final", "synchronized", 312 "volatile", "transient", "native", "interface", "abstract", "strictfp", 313 "synthetic", "annotation", "enum" 314 }; 315 316 /** @since 6.0 */ 317 public static final int ACCESS_NAMES_LENGTH = ACCESS_NAMES.length; 318 319 /** 320 * @param index 321 * @return the ACCESS_NAMES entry at the given index 322 * @since 6.0 323 */ 324 public static String getAccessName(final int index) { 325 return ACCESS_NAMES[index]; 326 } 327 328 /* 329 * The description of the constant pool is at: 330 * http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4 331 * References below are to the individual sections 332 */ 333 2262 public static final byte ATTR_CODE = 2; 2263 public static final byte ATTR_EXCEPTIONS = 3; 2264 public static final byte ATTR_LINE_NUMBER_TABLE = 4; 2265 public static final byte ATTR_LOCAL_VARIABLE_TABLE = 5; 2266 public static final byte ATTR_INNER_CLASSES = 6; 2267 public static final byte ATTR_SYNTHETIC = 7; 2268 public static final byte ATTR_DEPRECATED = 8; 2269 public static final byte ATTR_PMG = 9; 2270 public static final byte ATTR_SIGNATURE = 10; 2271 public static final byte ATTR_STACK_MAP = 11; 2272 public static final byte ATTR_RUNTIME_VISIBLE_ANNOTATIONS = 12; 2273 public static final byte ATTR_RUNTIME_INVISIBLE_ANNOTATIONS = 13; 2274 public static final byte ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS = 14; 2275 public static final byte ATTR_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS = 15; 2276 public static final byte ATTR_ANNOTATION_DEFAULT = 16; 2277 public static final byte ATTR_LOCAL_VARIABLE_TYPE_TABLE = 17; 2278 public static final byte ATTR_ENCLOSING_METHOD = 18; 2279 public static final byte ATTR_STACK_MAP_TABLE = 19; 2280 public static final byte ATTR_BOOTSTRAP_METHODS = 20; 2281 public static final byte ATTR_METHOD_PARAMETERS = 21; 2282 2283 public static final short KNOWN_ATTRIBUTES = 22; // count of attributes 2284 2285 private static final String[] ATTRIBUTE_NAMES = { 2286 "SourceFile", "ConstantValue", "Code", "Exceptions", 2287 "LineNumberTable", "LocalVariableTable", 2288 "InnerClasses", "Synthetic", "Deprecated", 2289 "PMGClass", "Signature", "StackMap", 2290 "RuntimeVisibleAnnotations", "RuntimeInvisibleAnnotations", 2291 "RuntimeVisibleParameterAnnotations", "RuntimeInvisibleParameterAnnotations", 2292 "AnnotationDefault", "LocalVariableTypeTable", "EnclosingMethod", "StackMapTable", 2293 "BootstrapMethods", "MethodParameters" 2294 }; 2295 2296 /** 2297 * 2298 * @param index 2299 * @return the attribute name 2300 * @since 6.0 2301 */ 2302 public static String getAttributeName(final int index) { 2303 return ATTRIBUTE_NAMES[index]; 2304 } 2305 2306 /** Constants used in the StackMap attribute. 2307 */ 2308 public static final byte ITEM_Bogus = 0; 2309 public static final byte ITEM_Integer = 1; 2310 public static final byte ITEM_Float = 2; 2311 public static final byte ITEM_Double = 3; 2312 public static final byte ITEM_Long = 4; 2313 public static final byte ITEM_Null = 5; | 1 /* 2 * Copyright (c) 2017, 2020 Oracle and/or its affiliates. All rights reserved. 3 */ 4 /* 5 * Licensed to the Apache Software Foundation (ASF) under one or more 6 * contributor license agreements. See the NOTICE file distributed with 7 * this work for additional information regarding copyright ownership. 8 * The ASF licenses this file to You under the Apache License, Version 2.0 9 * (the "License"); you may not use this file except in compliance with 10 * the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 package com.sun.org.apache.bcel.internal; 21 22 import java.util.Arrays; 23 import java.util.Collections; 24 25 /** 26 * Constants for the project, mostly defined in the JVM specification. 27 * 28 * @since 6.0 (intended to replace the Constants interface) 29 * @LastModified: Jan 2020 30 */ 31 public final class Const { 32 33 /** 34 * Java class file format Magic number (0xCAFEBABE) 35 * 36 * @see <a href="http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.1-200-A"> 37 * The ClassFile Structure in The Java Virtual Machine Specification</a> 38 */ 39 public static final int JVM_CLASSFILE_MAGIC = 0xCAFEBABE; 40 41 /** Major version number of class files for Java 1.1. 42 * @see #MINOR_1_1 43 * */ 44 public static final short MAJOR_1_1 = 45; 45 46 /** Minor version number of class files for Java 1.1. 47 * @see #MAJOR_1_1 48 * */ 49 public static final short MINOR_1_1 = 3; 163 /** Major version number of class files for Java 12. 164 * @see #MINOR_12 165 * */ 166 public static final short MAJOR_12 = 56; 167 168 /** Minor version number of class files for Java 12. 169 * @see #MAJOR_12 170 * */ 171 public static final short MINOR_12 = 0; 172 173 /** Major version number of class files for Java 13. 174 * @see #MINOR_13 175 * */ 176 public static final short MAJOR_13 = 57; 177 178 /** Minor version number of class files for Java 13. 179 * @see #MAJOR_13 180 * */ 181 public static final short MINOR_13 = 0; 182 183 /** Major version number of class files for Java 14. 184 * @see #MINOR_14 185 * @since 6.4.0 186 * */ 187 public static final short MAJOR_14 = 58; 188 189 /** Minor version number of class files for Java 14. 190 * @see #MAJOR_14 191 * @since 6.4.0 192 * */ 193 public static final short MINOR_14 = 0; 194 195 /** Default major version number. Class file is for Java 1.1. 196 * @see #MAJOR_1_1 197 * */ 198 public static final short MAJOR = MAJOR_1_1; 199 200 /** Default major version number. Class file is for Java 1.1. 201 * @see #MAJOR_1_1 202 * */ 203 public static final short MINOR = MINOR_1_1; 204 205 /** Maximum value for an unsigned short. 206 */ 207 public static final int MAX_SHORT = 65535; // 2^16 - 1 208 209 /** Maximum value for an unsigned byte. 210 */ 211 public static final int MAX_BYTE = 255; // 2^8 - 1 212 213 /** One of the access flags for fields, methods, or classes. 214 * @see <a href='http://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.1-200-E.1'> 215 * Flag definitions for Classes in the Java Virtual Machine Specification (Java SE 9 Edition).</a> 216 * @see <a href='http://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.5'> 217 * Flag definitions for Fields in the Java Virtual Machine Specification (Java SE 9 Edition).</a> 218 * @see <a href='http://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.6'> 219 * Flag definitions for Methods in the Java Virtual Machine Specification (Java SE 9 Edition).</a> 220 * @see <a href='http://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.6-300-D.1-D.1'> 221 * Flag definitions for Inner Classes in the Java Virtual Machine Specification (Java SE 9 Edition).</a> 222 */ 223 public static final short ACC_PUBLIC = 0x0001; 224 225 /** One of the access flags for fields, methods, or classes. 226 * @see #ACC_PUBLIC 227 */ 228 public static final short ACC_PRIVATE = 0x0002; 229 230 /** One of the access flags for fields, methods, or classes. 231 * @see #ACC_PUBLIC 232 */ 233 public static final short ACC_PROTECTED = 0x0004; 234 235 /** One of the access flags for fields, methods, or classes. 236 * @see #ACC_PUBLIC 237 */ 238 public static final short ACC_STATIC = 0x0008; 239 240 /** One of the access flags for fields, methods, or classes. 241 * @see #ACC_PUBLIC 242 */ 243 public static final short ACC_FINAL = 0x0010; 244 245 /** One of the access flags for the Module attribute. 246 * @see #ACC_PUBLIC 247 */ 248 public static final short ACC_OPEN = 0x0020; 249 250 /** One of the access flags for classes. 251 * @see #ACC_PUBLIC 252 */ 253 public static final short ACC_SUPER = 0x0020; 254 255 /** One of the access flags for methods. 256 * @see #ACC_PUBLIC 257 */ 258 public static final short ACC_SYNCHRONIZED = 0x0020; 259 260 /** One of the access flags for the Module attribute. 261 * @see #ACC_PUBLIC 262 */ 263 public static final short ACC_TRANSITIVE = 0x0020; 264 265 /** One of the access flags for methods. 266 * @see #ACC_PUBLIC 267 */ 268 public static final short ACC_BRIDGE = 0x0040; 269 270 /** One of the access flags for the Module attribute. 271 * @see #ACC_PUBLIC 272 */ 273 public static final short ACC_STATIC_PHASE = 0x0040; 274 275 /** One of the access flags for fields. 276 * @see #ACC_PUBLIC 277 */ 278 public static final short ACC_VOLATILE = 0x0040; 279 280 /** One of the access flags for fields. 281 * @see #ACC_PUBLIC 282 */ 283 public static final short ACC_TRANSIENT = 0x0080; 284 285 /** One of the access flags for methods. 286 * @see #ACC_PUBLIC 287 */ 288 public static final short ACC_VARARGS = 0x0080; 289 290 /** One of the access flags for methods. 291 * @see #ACC_PUBLIC 292 */ 293 public static final short ACC_NATIVE = 0x0100; 294 295 /** One of the access flags for classes. 296 * @see #ACC_PUBLIC 297 */ 298 public static final short ACC_INTERFACE = 0x0200; 299 300 /** One of the access flags for methods or classes. 301 * @see #ACC_PUBLIC 302 */ 303 public static final short ACC_ABSTRACT = 0x0400; 304 305 /** One of the access flags for methods. 306 * @see #ACC_PUBLIC 307 */ 308 public static final short ACC_STRICT = 0x0800; 309 310 /** One of the access flags for fields, methods, classes, MethodParameter attribute, or Module attribute. 311 * @see #ACC_PUBLIC 312 */ 313 public static final short ACC_SYNTHETIC = 0x1000; 314 315 /** One of the access flags for classes. 316 * @see #ACC_PUBLIC 317 */ 318 public static final short ACC_ANNOTATION = 0x2000; 319 320 /** One of the access flags for fields or classes. 321 * @see #ACC_PUBLIC 322 */ 323 public static final short ACC_ENUM = 0x4000; 324 325 // Applies to classes compiled by new compilers only 326 /** One of the access flags for MethodParameter or Module attributes. 327 * @see #ACC_PUBLIC 328 */ 329 public static final short ACC_MANDATED = (short) 0x8000; 330 331 /** One of the access flags for classes. 332 * @see #ACC_PUBLIC 333 */ 334 public static final short ACC_MODULE = (short) 0x8000; 335 336 /** One of the access flags for fields, methods, or classes. 337 * @see #ACC_PUBLIC 338 * @deprecated Use {@link #MAX_ACC_FLAG_I} 339 */ 340 @Deprecated 341 public static final short MAX_ACC_FLAG = ACC_ENUM; 342 343 /** One of the access flags for fields, methods, or classes. 344 * ACC_MODULE is negative as a short. 345 * @see #ACC_PUBLIC 346 * @since 6.4.0 347 */ 348 public static final int MAX_ACC_FLAG_I = 0x8000; // ACC_MODULE is negative as a short 349 350 // Note that do to overloading: 351 // 'synchronized' is for methods, might be 'open' (if Module), 'super' (if class), or 'transitive' (if Module). 352 // 'volatile' is for fields, might be 'bridge' (if method) or 'static_phase' (if Module) 353 // 'transient' is for fields, might be 'varargs' (if method) 354 // 'module' is for classes, might be 'mandated' (if Module or MethodParameters) 355 /** 356 * The names of the access flags. 357 */ 358 private static final String[] ACCESS_NAMES = { 359 "public", "private", "protected", "static", "final", "synchronized", 360 "volatile", "transient", "native", "interface", "abstract", "strictfp", 361 "synthetic", "annotation", "enum", "module" 362 }; 363 364 /** @since 6.0 */ 365 public static final int ACCESS_NAMES_LENGTH = ACCESS_NAMES.length; 366 367 /** 368 * @param index 369 * @return the ACCESS_NAMES entry at the given index 370 * @since 6.0 371 */ 372 public static String getAccessName(final int index) { 373 return ACCESS_NAMES[index]; 374 } 375 376 /* 377 * The description of the constant pool is at: 378 * http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4 379 * References below are to the individual sections 380 */ 381 2310 public static final byte ATTR_CODE = 2; 2311 public static final byte ATTR_EXCEPTIONS = 3; 2312 public static final byte ATTR_LINE_NUMBER_TABLE = 4; 2313 public static final byte ATTR_LOCAL_VARIABLE_TABLE = 5; 2314 public static final byte ATTR_INNER_CLASSES = 6; 2315 public static final byte ATTR_SYNTHETIC = 7; 2316 public static final byte ATTR_DEPRECATED = 8; 2317 public static final byte ATTR_PMG = 9; 2318 public static final byte ATTR_SIGNATURE = 10; 2319 public static final byte ATTR_STACK_MAP = 11; 2320 public static final byte ATTR_RUNTIME_VISIBLE_ANNOTATIONS = 12; 2321 public static final byte ATTR_RUNTIME_INVISIBLE_ANNOTATIONS = 13; 2322 public static final byte ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS = 14; 2323 public static final byte ATTR_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS = 15; 2324 public static final byte ATTR_ANNOTATION_DEFAULT = 16; 2325 public static final byte ATTR_LOCAL_VARIABLE_TYPE_TABLE = 17; 2326 public static final byte ATTR_ENCLOSING_METHOD = 18; 2327 public static final byte ATTR_STACK_MAP_TABLE = 19; 2328 public static final byte ATTR_BOOTSTRAP_METHODS = 20; 2329 public static final byte ATTR_METHOD_PARAMETERS = 21; 2330 public static final byte ATTR_MODULE = 22; 2331 public static final byte ATTR_MODULE_PACKAGES = 23; 2332 public static final byte ATTR_MODULE_MAIN_CLASS = 24; 2333 public static final byte ATTR_NEST_HOST = 25; 2334 public static final byte ATTR_NEST_MEMBERS = 26; 2335 2336 public static final short KNOWN_ATTRIBUTES = 27; // count of attributes 2337 2338 private static final String[] ATTRIBUTE_NAMES = { 2339 "SourceFile", "ConstantValue", "Code", "Exceptions", 2340 "LineNumberTable", "LocalVariableTable", 2341 "InnerClasses", "Synthetic", "Deprecated", 2342 "PMGClass", "Signature", "StackMap", 2343 "RuntimeVisibleAnnotations", "RuntimeInvisibleAnnotations", 2344 "RuntimeVisibleParameterAnnotations", "RuntimeInvisibleParameterAnnotations", 2345 "AnnotationDefault", "LocalVariableTypeTable", "EnclosingMethod", "StackMapTable", 2346 "BootstrapMethods", "MethodParameters", "Module", "ModulePackages", 2347 "ModuleMainClass", "NestHost", "NestMembers" 2348 }; 2349 2350 /** 2351 * 2352 * @param index 2353 * @return the attribute name 2354 * @since 6.0 2355 */ 2356 public static String getAttributeName(final int index) { 2357 return ATTRIBUTE_NAMES[index]; 2358 } 2359 2360 /** Constants used in the StackMap attribute. 2361 */ 2362 public static final byte ITEM_Bogus = 0; 2363 public static final byte ITEM_Integer = 1; 2364 public static final byte ITEM_Float = 2; 2365 public static final byte ITEM_Double = 3; 2366 public static final byte ITEM_Long = 4; 2367 public static final byte ITEM_Null = 5; |