Posts

Showing posts with the label ACC_SYNTHETIC

What is Java Synthetic Class (ACC_SYNTHETIC)? with the example of BoundMethodHandle$1.class in Java package java.lang.invoke

Image
When a .class file marked with the ACC_SYNTHETIC flag, it indicates the .class file was generated by compiler and does not appear in the corresponding .java source code . Binary Code is always the best document, so let's check an example: the BoundMethodHandle$1.class class in java.base.jmod in JDK. The class file BoundMethodHandle$1.class has been marked as synthetic flag, as shown bellow: Basic Information of BoundMethodHandle$1.class  UML diagram of BoundMethodHandle$1.class And this class is used by the container class BoundMethodHandle : Dependency Network diagram of BoundMethodHandle$1.class This class does not exist in the original source code BoundMethodHandle.java , but generated by the java compiler, from the following two (2) methods in the Java class BoundMethodHandle : BoundMethodHandle.bindSingle() , at byte code offset 0 BoundMethodHandle.arg() , at byte code offset 17 Byte code of method BoundMethodHandle.bindSingle() ...

What is Java Synthetic Field (ACC_SYNTHETIC)? with the example of AbstractExecutorService.$assertionsDisabled in java package java.util.concurrent

Image
A Java field in .class file marked with the ACC_SYNTHETIC flag to indicate that it was generated by a compiler and does not appear in source code . Binary Code is always the best document, so let's inspect an example of this case, from the class AbstractExecutorService ( source code ) in the package java.util.concurrent . The UML generated form the AbstractExecutorService.class file indicates it contains a field named $assertionsDisabled , and the detailed inspection shows this field is generated by compiler, since its "Access Flags" contains the value synthetic , which means this field "not present in the source code". UML diagram generated from AbstractExecutorService.class   Details page for the field AbstractExecutorService.$assertionsDisabled So why Java compiler is generating this field? Let's continue to inspect the field AbstractExecutorService.$assertionsDisabled . From the .class binary data analysis, the field Abstract...