How to set up smartphones and PCs. Informational portal

Installing a java machine. JVM (Java Virtual Machine)

Can be compiled to Java bytecode which can then be executed by the JVM.

The JVM is a key component of the Java platform. Since Java virtual machines are available for many hardware and software platforms, Java can be viewed as both middleware and a standalone platform, hence the write once, run anywhere principle. Using a single bytecode for many platforms allows Java to be described as "compiled once, run anywhere" (compile once, run anywhere).

JVM specification

Sun vs. IBM standoff

In 2001, with the aim of developing a standard for cross-platform Desktop-applications, Eclipse.

IBM VisualAge. IBM has managed to balance the interests of the free community and the interests of the business (its own interests) in the Eclipse Public License, recognized by the FSF.

The project is successfully developing, recognized by the industry, to a large extent separated from IBM into an independent Eclipse Foundation.


Wikimedia Foundation. 2010.

See what "Java Virtual Machine" is in other dictionaries:

    Java virtual machine- The main part of the Java Runtime Environment (JRE). The Java Virtual Machine interprets and executes Java byte code previously generated from the Java source code of the Java program by the Java compiler. JVM can be used for ... - developed by JavaSoft. Web applications built using it can run naturally within the operating system, or the Web browser, or within an emulation environment known as the Java virtual machine ... Electronic Business Dictionary

    - (JPF) Free tool for testing multithreaded Java programs. In essence, it is a Java Virtual Machine on the basis of which model checking methods are implemented. This means that ... ... Wikipedia

    Java virtual machine- Interpreter byte code of Java programs. A virtual machine designed to run Java applets. The JVM is built into most web browsers. This allows the client-side execution of Java applets, calls of which are provided in ... ... Technical translator's guide

    Another name for this concept is "Java"; see also other meanings. Not to be confused with JavaScript. Java Language class ... Wikipedia

    It is necessary to check the quality of the translation and bring the article in accordance with the stylistic rules of Wikipedia. You can help improve this article by correcting errors. Original n ... Wikipedia

The JVM is a key component of the Java platform. The Java Virtual Machine interprets and executes Java Bytecode that is previously generated from the Java source code by the Java compiler (javac).

Since Java virtual machines are available for many hardware and software platforms, Java can be viewed both as middleware and as a standalone platform, hence the write once, run anywhere principle. Using a single bytecode across multiple platforms allows Java to be described as “compile once, run anywhere”.

Programs intended to run on the JVM must be compiled in a standardized portable binary format, usually represented as .class files. A program can consist of many classes located in different files. To facilitate the placement of large programs, some of the .class files can be packaged together in a so-called .jar file (short for Java Archive).

JVM virtual machine executing files .class or .jar by emulating instructions written for the JVM by interpreting or using a just-in-time (JIT) compiler such as Sun microsystems' HotSpot. JIT compilation is used by most JVMs these days for the sake of speed. There are also ahead-of-time compilers that allow application developers to precompile class files into platform-specific code.

The JVM, which is an instance of the JRE (Java Runtime Environment), comes into play when Java programs are executed. Upon completion of execution, this instance is discarded by the garbage collector. JIT is part of the Java Virtual Machine that is used to speed up the execution time of applications. JIT simultaneously compiles portions of bytecode that have similar functionality and therefore reduces the amount of compilation time.

The JVM is a stacking machine. This means that there are no general registers in it, and operations are performed on the data on the stack. The operand stack allocated for each frame serves this purpose. When executing Java bytecode instructions that modify data, the operands of such instructions are popped from the operand stack, and the results of the instruction execution are placed on the same stack.

The method runtime contains the information needed to dynamically bind, return from the method, and handle exceptions. Class code (located in class scope) refers to external methods and variables using symbolic links. Dynamic linking translates symbolic links into actual links. The runtime contains links to the method symbol table through which calls to external methods and variables are made.

The runtime also contains the information needed to return from the method: a pointer to the caller's frame, the pc register value to return, the contents of the caller's registers, and a pointer to an area to write the return value.

The exception handling information contains links to the exception handling sections in the class method.

The runtime also accesses the data contained in the class scope, including constants and class variables.

JVM commands consist of a one-bit opcode and can also contain operands. The number and size of operands are determined by the opcode, some instructions have no operands

What is JVM?

JVM is a engine that provides runtime environment to drive the Java Code or applications. It converts Java bytecode into machines language. JVM is a part of JRE (Java Run Environment). It stands for Java Virtual Machine

  • In other programming languages, the compiler produces machine code for a particular system. However, Java compiler produces code for a Virtual Machine known as Java Virtual Machine.
  • First, Java code is complied into bytecode. This bytecode gets interpreted on different machines
  • Between host system and Java source, Bytecode is an intermediary language.
  • JVM is responsible for allocating memory space.

In this tutorial, you will learn-

JVM Architecture

Let "s understand the Architecture of JVM. It contains classloader, memory area, execution engine etc.

1) ClassLoader

The class loader is a subsystem used for loading class files. It performs three major functions viz. Loading, Linking, and Initialization.

2) Method Area

JVM Method Area stores class structures like metadata, the constant runtime pool, and the code for methods.

All the Objects, their related instance variables, and arrays are stored in the heap. This memory is common and shared across multiple threads.

4) JVM language Stacks

Java language Stacks store local variables, and it's partial results. Each thread has its own JVM stack, created simultaneously as the thread is created. A new frame is created whenever a method is invoked, and it is deleted when method invocation process is complete.

5) PC Registers

PC register store the address of the Java virtual machine instruction which is currently executing. In Java, each thread has its separate PC register.

6) Native Method Stacks

Native method stacks hold the instruction of native code depends on the native library. It is written in another language instead of Java.

7) Execution Engine

It is a type of software used to test hardware, software, or complete systems. The test execution engine never carries any information about the tested product.

8) Native Method interface

The Native Method Interface is a programming framework. It allows Java code which is running in a JVM to call by libraries and native applications.

9) Native Method Libraries

Native Libraries is a collection of the Native Libraries (C, C ++) which are needed by the Execution Engine.

Software Code Compilation & Execution process

In order to write and execute a software program, you need the following

1) Editor- To type your program into, a notepad could be used for this

2) Compiler- To convert your high language program into native machine code

3) Linker- To combine different program files reference in your main program together.

4) Loader- To load the files from your secondary storage device like Hard Disk, Flash Drive, CD into RAM for execution. The loading is automatically done when you execute your code.

5) Execution- Actual execution of the code which is handled by your OS & processor.

With this background, refer the following video & learn the working and architecture of the Java Virtual Machine.

C code Compilation and Execution process

To understand the Java compiling process in Java. Let "s first take a quick look to compiling and linking process in C.

Suppose in the main, you have called two function f1 and f2. The main function is stored in file a1.c.

Function f1 is stored in a file a2.c

Function f2 is stored in a file a3.c

All these files, i.e., a1.c, a2.c, and a3.c, is fed to the compiler. Whose output is the corresponding object files which are the machine code.

The next step is integrating all these object files into a single .exe file with the help of linker. The linker will club all these files together and produces the .exe file.

During program run, a loader program will load a.exe into the RAM for the execution.

Java code Compilation and Execution in Java VM

Let "s look at the process for JAVA. In your main, you have two methods f1 and f2.

  • The main method is stored in file a1.java
  • f1 is stored in a file as a2.java
  • f2 is stored in a file as a3.java

The compiler will compile the three files and produces 3 corresponding .class file which consists of BYTE code. Unlike C, no linking is done.

The Java VM or Java Virtual Machine resides on the RAM. During execution, using the class loader the class files are brought on the RAM. The BYTE code is verified for any security breaches.

Next, the execution engine will convert the Bytecode into Native machine code. This is just in time compiling. It is one of the main reason why Java is comparatively slow.

NOTE: JIT or Just-in-time compiler is the part of the Java Virtual Machine (JVM). It interprets part of the Byte Code that has similar functionality at the same time.

Why is Java both Interpreted and Compiled Language?

Programming languages ​​are classified as
  • Higher Level Language Ex. C ++, Java
  • Middle-Level Languages ​​Ex. C
  • Low-Level Language Ex Assembly
  • finally the lowest level as the Machine Language.

A compiler is a program which converts a program from one level of language to another. Example conversion of C ++ program into machine code.

The java compiler converts high-level java code into bytecode (which is also a type of machine code).

An interpreter is a program which converts a program at one level to another programming language at the same level. Example conversion of Java program into C ++

In Java, the Just In Time Code generator converts the bytecode into the native machine code which are at the same programming levels.

Hence, Java is both compiled as well as interpreted language.

Why is Java slow?

The two main reasons behind the slowness of Java are

  1. Dynamic Linking: Unlike C, linking is done at run-time, every time the program is run in Java.
  2. Run-time Interpreter: The conversion of byte code into native machine code is done at run-time in Java which furthers slows down the speed

However, the latest version of Java has addressed the performance bottlenecks to a great extent.

Summary:

  • JVM or Java Virtual Machine is the engine that drives the Java Code. It converts Java bytecode into machines language.
  • In JVM, Java code is compiled to bytecode. This bytecode gets interpreted on different machines
  • JIT or Just-in-time compiler is the part of the Java Virtual Machine (JVM). It is used to speed up the execution time
  • In comparison to other compiler machines, Java may be slow in execution.
The JVM (Java Virtual Machine) is the heart of the Java programming language. The Java environment consists of five elements:
■ Java language
■ Bytecode definition
■ Java / Sun Class Libraries
■ Java Virtual Machine
■ The structure of the .class file

Of all these five elements, the elements that led to Java's success
■ Definition of bytecode,
■ the structure of the .class file,
■ and the Java Virtual Machine.

Thus, "write once and run anywhere" was actually made possible by the portability of the .class file, which helps run on any computer or chipset using the Java Virtual Machine.

1.3.1 What is Java Virtual Machine?

A virtual machine is software based on the concepts and idea of ​​an imaginary computer that has a logical set of instructions and commands that determine the operations of that computer. It can be said to be a small operating system. It forms the necessary level of abstraction, where independence from the platform and the equipment used is achieved.

The compiler converts the source code into code that is based on an imaginary computer instruction system and does not depend on the specificity of the processor. An interpreter is an application that understands these streams of commands and translates these commands for the hardware used, to which the interpreter belongs. The JVM creates an execution support system internally, which helps code execution when
■ uploading .class files,
■ memory management
■ performing exception handling.

Due to the inconsistency of hardware platforms, the virtual machine uses the concept of a stack, which contains the following information:
■ Method State Descriptors
■ Operands to byte codes
■ Method parameters
■ Local variables

When the code is executed by the JVM, there is one special register that is used as a counter to indicate which commands are currently being executed. If necessary, the commands change the program, change the flow of execution, otherwise the flow is sequential and moves from one command to another.

Another concept that is becoming popular is the use of a Just In Time (JIT) compiler. Browsers like Netscape Navigator 4.0 and Internet Explorer 4.0 include JIT compilers that speed up the execution of Java code. The main goal of JIT is to convert the bytecode instruction set to machine code instructions targeted to a specific microprocessor. These commands are saved and used whenever a request is made to this particular method.

1.3.2 Java Runtime

JRE (Java Runtime Environment) A JVM that interacts with hardware on one side and a program on the other. The JRE executes code compiled for the JVM:
Loading .class files
Performed by the "Class Loader"
The class loader does a security check if the files are in use on the network.
Bytecode check
Performed by the "bytecode verifier"
The bytecode verifier checks code format, object type conversions, and checks for access violations.
Code execution
Performed by "interpreter at runtime"
The interpreter executes bytecodes and makes inquiries about the equipment used.


Figure 1.3: Java Runtime

1.3.3 Exception Handling and Memory Management

In C, C ++ or Pascal, programmers used primitive methods of allocating and freeing blocks of memory - heap memory. Dynamic memory is a large chunk of memory that is denoted in the amount of all memory.

Dynamic memory is used:
Free block list
Distributed block list

The free list checks a block of memory whenever a request is made. The allocation mechanism is the "first-fit-block method", whereby the first smallest block of memory is allocated depending on the request. This procedure allocates and frees small amounts of memory of varying sizes from heap, while minimizing heap fragmentation.

There is a stage through which a memory request is made - to obtain a larger block of memory than is available. In such cases, the heap manager must create more memory. This technique is called compaction. It is the process by which all free available blocks of memory are merged together, moving free memory to one end of the heap, thus creating one large block of memory.

The Java Virtual Machine uses two separate heaps for static and dynamic memory allocation.

Dynamic memory - Does not do dynamic memory exception handling, which preserves all class properties, persistent pool, and method tables.

The second heap is again split into two sections, which can be expanded in opposite directions as needed. One section is used to store sample objects, and the other section is used to store descriptors to these samples. A descriptor is a structure that consists of two pointers. Point to the method table of an object and other items to a sample of that object. This placement basically eliminates the need to preserve object paths when modifying pointers after compaction. All we have to do is update the value of the handle pointer.

The exception handling algorithm is applied to heap-allocated objects. Since a request for a block of memory is received, the heap first checks the free list, and if the heap cannot find free blocks of memory, exception handling is called as soon as the system has been idle for a sufficient period of time. In cases where applications are highly interactive and system downtime is minimized, exception handling should be called explicitly by the application.

The exception collector calls the terminating method before a sample object is collected using exception handling. The terminating method is used to clean up external resources like files and streams that are open and not taken care of in standard exception handling. Even if we explicitly call exception handling with the (System.gc ()) method, it won't work quickly. It's just slated to work. It also means that exception handling cannot be invoked. This is because the exception handling threads run at a very low priority and can be interrupted frequently. This can happen when our object has never been located before in memory.

Top related articles