Path Finding Algorithm (A* and Dijkstra's)

Image
This Blog is about a project which I did in JANUARY 2021. I created a path finding algorithm simulator using JavaFX. It helps to get a visual representation of two path finding algorithms which are A* and Dijkstra's Path finding Algorithm. I used JavaFX because it is one of the fastest growing technologies in java and it is replacing java swing .JavaFX is much more powerful then java swing and  it has some amazing features like we can apply CSS in JavaFX. The reason why I choose  to A* and Dijkstra's Path Finding Algorithm from a Pool of Algorithm because they help us to  get a basic knowledge of Path finding in Graph. These two are also really great for comparison  with each other and they are also quite famous. Working so let me tell you how this application works. You can download the project by clicking here and then  configure it  in your favorite java IDE .  Now if you have configured the project which I don't think so, then press the run button in your IDE. when the

JVM Architecture

 JVM(JAVA VIRTUAL MACHINE) is a Process Virtual Machine. It runs as a normal application inside a host OS(Operating System) and Supports a Single process. It's purpose is to provide a platform -independent programming environment that abstracts away details of underlying hardware or OS.

JVM acts as a Runtime engine to run Java based applications. It's task is to load ".class"  file and run ".class" file. JVM is a part of JRE which is a part of JDK.

JVM  ARCHITECTURE


The Architectural Diagram of JVM is shown above.

JVM basically consists of five Major Parts:

1. Classloader subsystem.

2. JVM memory.

3. Execution Engine.

4. Native Method Interface.

5. Native Method Libraries.

so lets talk about each part one by one.


Classloader Subsystem: 

Java's loads the classes dynamically and this feature of java is provided by the Classloader Subsystem. It's main task is to load, link and initialize the class file when it refers to a class for the first time during runtime.

Classloader Subsystem Diagram:

                                                                  

Loading:

It means reading the ".Class" file and storing the corresponding binary data in the method area of the JVM memory. The following are some of the information stored in the method area .

* Fully qualified name of the class

*  Fully qualified name of the immediate parent class.

* Method Information.

* Variable Information.

* Constructor Information.

* Modifiers Information.

* Constant Pool Information.

After loading the ".class" file , JVM creates an object for that loaded class on the heap memory of the type java.lang.Class   . This class Class object can be used by the programmer to get class level information.

Following are the three Class Loaders:

1. Bootstrap Classloader.

2. Extension Classloader.

3. Application Classloader.

the above class loaders follow Delegation Hierarchy Algorithm while loading the class.


Bootstrap Classloader:-

Bootstrap class loader is responsible to load core java API(classes in at.jar) from bootstrap classpath(jdk/jre/lib). Bootstrap classloader is by default available in every JVM. It is implemented  in native Languages like C,C++ and not implemented in java.


Extension Classloader:- 

Extension classloader is responsible to load classes from extension classpath(jdk/jre/lib/ext) .extension classloader is implemented in java and the corresponding .class file is 

sun.misc.Launcher$extclassloader.class


Application Classloader:- 

Application Classloader is the child of extension Classloader. This class loader is responsible to load a class from application classpath. It internally uses the environment class a path. It is implemented in java and the corresponding  .class file is 

sun.misc.launcher$Appclassloader.class



Working of Class Loader:-

Whenever the JVM come across a particular class ,first it checks weather a corresponding class is loaded in method area or not. if it is loaded then JVM  continues with the execution , if the class is not loaded in the method are then the JVM request the Classloader subsystem  to load the particular class. Then the classloader subsystem handovers the request to the application classloader. Application classloader delegates the request to the extension classloader. the extension classloader delegates the request to bootstrap classloader. Then the Bootstrap classloader searches for the class in the bootstrap classpath. If the class is found then it is loaded by the bootstrap classloader. if the class is not found then the bootstrap classloader delegates the request to the extension classloader. A similar kind of procedure is followed by extension and application class loader. If the file is not found in the application classpath then a ClassnotFound exception will occur.



Linker:- 

The Taks of Linker are as follows:-

1. Verify

2. Prepare

3. Resolve


Bytecode Verifier:-

It verifies that the bytecode is Valid.

If Verification Fails then we will get Runtime Exception called Java.lang.verifyerror.


Preparation:-

Allocate memory for class level variables and assign default value is assigned.


Resolve:-

It is the process of replacing symbolic names in our program with original memory references from method area.



Initialization:-

Actual values will be assigned to the static variable and static block will be executed from parent to child and from Top to Bottom.

If the linkage is failed the a java.lang.linkagesError will occurred.

JVM Memories:

1. Method Area

2.Heap Area

3. Stack Area

4. PC register.

5. Native Method Stack.


Method Area:- 

for every JVM one method area will be available. Method area will be created at the time of JVM startup. Inside Method Area class level binary data will be stored. Constant pool of class will be stored inside method area . Method Area can be accessed by multiple threads simultaneously.

Heap Area:-

For every JVM one heap area is available. It will be created at the time of JVM startup. Objects and the corresponding instance variables will be stored in heap area. Every array in java is object only , Hence Array's will also be stored in the heap area. Heap area can be accessed by multiple threads and hence data stored in heap area is not thread safe. Heap area need not be continuous.

Stack Area:-

Every Thread in JVM will create a separate Stack at the time of Thread Creation. Each and Every method  call performed by that thread will be stored in the stack including local variable also. After completing the method the corresponding entry in the stack will be removed . After Completing all method calls the stack will be Empty and that empty stack will be destroyed by the JVM just before terminating the thread. Each Entry in the stack is call the Stack frame or Activation Record. The data stored in the stack is available for the corresponding thread only and not available to the other Thread. Hence data Stored in the Stack will be Thread safe.

Stack Frame Structure.



PC Register:

For every thread a separate PC register will be created at the time of Thread Creation. PC register Stores the address of the current executing instruction. Once the instruction is executed the PC register is incremented to hold the address of the next Instruction.

Native Method Stack:-

For every thread JVM will create a separate Native Method Stack. All native method calls invoked by the thread  will be stored in the corresponding Native method Stack.

Java Execution Engine:-



This is the Central Component of JVM.It is responsible to execute Java Class Files.Execution engine mainly comprise of two components listed below1.

1. Interpreter

2. JIT Compiler.

Interpreter:

It is responsible to read bytecode and interpret into machine code and execute that machine code line by line. The problem with interpreter is that it interprets every time even same method invoked multiple times, which reduces performance of the system. To overcome this problem some people introduces JIT compiler in version 1.1 version.

JIT Compiler:

The main purpose of JIT compiler is to improve performance . Internally JIT compiler ,maintains a count for every method . Whenever JVM come across any method call first that method will be interpreted normally and JIT compiler increments the counter.This process will be continued for every method .Once if any method count reaches a threshold value the JIT compiler identifies it as a repeatedly used method(Hot Spot). Immediately the JIT compiler compiles that method and the corresponding native code. Next time when the JVM come across a method call then JVM uses that native code and executes it instead of interpreting once again so that performance of the system will be improved.

Profiler:

Internally profiler, which is the part of JIT compiler is responsible for identifying the Hot Spot.

JNI(Java Native Interface):

It acts as mediator for Java method calls and corresponding native Libraries i.e. JNI is responsible to provide information about native libraries to the JVM

Native Method Library holds libraries information.


In this Blog we have discussed the basics of JVM Architecture.

Other Blogs:- Java Sealed Classes 


Comments

Post a Comment

Popular posts from this blog

Java Sealed Class

Past Olympics data analysis