Posts

Evolution of Java Dependency Diagrams, from Java 7 to Java 13

Image
The OpenJDK community is trying to modularize the OpenJDK itself in the past years, and the following Dependency Network diagrams of OpenJDK jar/jmod files can show it visually.


Dependency Network diagrams of OpenJDK 7
Dependency Network diagrams of OpenJDK 8
Dependency Network diagrams of OpenJDK 9
Dependency Network diagrams of OpenJDK 10
Dependency Network diagrams of OpenJDK 11
Dependency Network diagrams of OpenJDK 12
Dependency Network diagrams of OpenJDK 13

From the diagrams above, we can have the following points:

OpenJDK 7 and 8 is very similar, well there is a big change Since OpenJDK 9 Since Java 9, the keyword module has been introduced for the Java Platform Module System. From the dependency network diagram point of view, with the module system, there is (almost) no circular dependency between JDK library .jmod files.

There is slow evolution from OpenJDK 9 until OpenJDK 13, via minor changes The reason is the community is keeping improve the moralization between JDK libraries.


What is Java Synthetic Method (ACC_SYNTHETIC)? with the example of AbstractPlainSocketImpl.lambda$getInputStream$0() in Java package java.net

Image
A Java method in .class file marked with the ACC_SYNTHETIC flag to indicate that it was generated by Java compiler and does not appear in source code.

Binary Code is always the best document. So let's inspect an example of such case: the Java method AbstractPlainSocketImpl.lambda$getInputStream$0() in Java package java.net is tagged as synthetic in AbstractPlainSocketImpl.class.

The UML generated form the AbstractExecutorService.class file indicates it contains a method named lambda$getInputStream$0(), and the detailed inspection shows this method is generated by compiler, since its "Access Flags" contains the value synthetic, which means this field "not present in the source code".

So why Java compiler is generating this method? Let's continue to inspect the method AbstractPlainSocketImpl.lambda$getInputStream$0().
This method is generated for lambda expressionThe lambda express exits in the getInputStream() methodThis method is generated for the 0th lambd…

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


And this class is used by the container class BoundMethodHandle:


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 0BoundMethodHandle.arg(), at byte code offset 17

Highlight: Source code of BoundMethodHandle.bindSingle():
62 static BoundMethodHandle bindSingle(MethodType type, LambdaForm form, BasicType xtype, Object x) { 63 // for some type signatures, there exist pre-defined concrete BMH classes 64 …

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 AbstractExecutorService.$assertionsDisabled…

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 these two clone() methods:
publ…

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, etcAMD64 (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, etcSPARC (source code): SPARC CPU, originally designed by Sun Microsystems, which is used by powerful servers servicing numerous client requests So Java c…