Posts

Showing posts with the label Java

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...

What is Java Bridge Method (ACC_BRIDGE)?

Image
Java method could be tagged with bridge ( ACC_BRIDGE ) in the .class file, denotes this method is generated by Java Compiler for type erasure purpose of Java Generics . Code is the best document, so let's check the code of java.util.ArrayDeque as an example for the details. In the source code of ArrayDeque , there is only one (1) clone() method defined, as bellow: public ArrayDeque<E> clone() { try { @SuppressWarnings("unchecked") ArrayDeque<E> result = (ArrayDeque<E>) super.clone(); result.elements = Arrays.copyOf(elements, elements.length); return result; } catch (CloneNotSupportedException e) { throw new AssertionError(); } } Well in the generated the .class file for ArrayDeque , there are two (2) clone() methods, as the generated UML diagram from the ArrayDeque.class file shown: UML Diagram of ArrayDeque.class Here are the details of...

How many CPU architectures (platforms) can Java run?

Image
Java is famous for its cross-platform feature, and declared as Write once, run anywhere (WORE). Well the question is, how many platforms Java can run? Code always contains the best answer, let's investigate the code of Java Virtual Machine (JVM) for this. The Architecture ( source code ) class in the jdk.internal.vm.ci.jmod module indicates the CPU architectures Java Virtual Machine can run on:   UML Hierarchy Diagram for Java class Architecture We can found Java can execute on the following three (3) CPU architectures / platforms: AArch64 ( source code ): ARM CPU, 64 bit, which is mostly used in Mobile devices, like Android phone, Android PAD, Apple iPhone, etc AMD64 ( source code ): x86 CPU, 64 bit, which is used by most laptop and desktop computers, including Acer, Apple, Asus, Dell, Hewlett-Packard (HP), IBM, Lenovo, Samsung, Toshiba, etc SPARC ( source code ): SPARC CPU, originally designed by Sun Microsystems , which is used by powerful servers ...