Posts

Showing posts with the label BinaryDoc

Java module-info Essentials, from Binary code point of view

Image
Java module system has been introduced since Java 9, via the project Jigsaw . Each java module contains a module-info.class file, for the specification of current module. Here we are trying to make an introduction of the module-info file. Binary Code is always the best document . So let's inspect an example module-info: module info in java.base.jmod file, which is the biggest java module in current OpenJDK . Source code: master/src/java.base/share/classes/module-info.java   The binary file is located at: JAVA_HOME/jmods/java.base.jmod - classes/module-info.class We can open the module-info.class file using Java Class Viewer , as the screen shots bellow. The module-info.class file is a special type of .class file, and it has the following key differences from other normal .class file: 1. module-info.class do not have super class, interfaces, fields, methods. From the screen shot bellow, we can find that the super_class node's value is " 0 ", whic...

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