Java Virtual Machine (JVM) is a specification that provides runtime environment in which java  bytecode can be executed. As the name implies, the JVM acts as a “virtual” machine or processor. Java's platform independence consists mostly of its Java Virtual Machine (JVM) . JVM makes this possible because it is aware of the specific instruction lengths and other particularities of the platform. The JVM performs following operation:

  1. Loads code
  2. Verifies code
  3. Executes code

In most cases, other programming languages, the compiler produce code for a particular Operating System but the Java compiler produce Bytecode only for a  Java Virtual Machine . When you run a Java program, it runs as a thread within the JVM process. It is the JVM's responsibility to load your class files, verify code, interpret them and execute them. When you issue a command like java , the JVM loads the class definition for that particular class and calls the main method of that class.

It is the JVMs responsibility that makes it possible for the same class file to run on any other  Operating Systems . The JVM takes your compiled platform-neutral byte code and interprets it to run platform-specific machine code. It can also compile it into native code with a  JIT (a  just-in-time compiler that compiles and caches your code, usually one method at a time). Thus, it is in the JVM where your code results, if needed, in native Operating System calls. Therefore, in the  JVM , your platform-neutral threading code gets turned into platform-specific threading code.

Java allocates  threads as needed for your application. The JVM manages the memory of your Java program. So, when you create an Object, or an Audio Clip, or a plain old float, Java allocates memory for both objects and primitives. Java determines when these items are no longer referenced, and, therefore, can have their memories reclaimed. The JVM, without any prompting from the user, runs the  Garbage Collector thread (when possible or required) to reclaim used, unreferenced memory. In addition to interpreting bytecodes, the JVM must supply interfaces to the various subsystems managed by the  Operating System for display, mouse, keyboard, file system and I/O ports etc.

JVM Architecture

Each Java application runs inside a runtime instance of some concrete implementation of the abstract specification of the  Java virtual machine . There are three notions of JVM: specification, implementation, and instance.

  1. Specification : A document that describes what is required of JVM Implementation.
  2. Implementation: Known as JRE(Java Run Time Environment.)
  3. Instance: Whenever you will run a java class file an instance of JVM is created.

As shown in picture, JVM is divided into three main subsystems:

  1. Class Loader Subsystem
  2. Runtime Data Area
  3. Execution Engine

Class Loader Subsystem

The  Java virtual machine has a flexible  Class Loader architecture that allows a Java application to load classes in custom ways. In a JVM, each and every class is loaded by some instance of a  java.lang.ClassLoader . A classloader is a special Java class file that is responsible for loading other classes onto a Java Virtual Machine. If a Java class is invoked and needs to be executed on a Java Virtual Machine, a special Java component, called a  classloader , is used to find the Java class of interest, pull that Java class off of the file system, and execute the  bytecode of that class file on the Java Virtual Machine.

Java  Class Loader Subsystem loads, links and initializes the class file when it refers to a class for the first time at runtime. It is responsible for loading class files from file system, network or any other source. There are three default class loader used in Java, Bootstrap ,  Extension and  System or Application class loader.

Boot Strap class Loader

When a JVM starts up, a special chunk of machine code runs that loads the system classloader. This machine code is known as the  Bootstrap / Primordial classloader. It is platform specific machine instructions that kick off the whole classloading process. The bootstrap classloader also takes care of loading all of the code needed to support the basic  Java Runtime Environment (JRE), including classes in the java.util and the java.lang packages .

Extension ClassLoader

The Extension class loader loads the classes from the JRE’s extension directories, such  lib/ext directories. Extension ClassLoader delegates class loading request to its parent, Bootstrap and if unsuccessful, loads class form  jre/lib/ext directory or any other directory pointed by  java.ext.dirs system property. Extension ClassLoader in JVM is implemented by  sun.misc.Launcher$ExtClassLoader .

System/Application Class Loader

System/Application  Class Loader is responsible for loading Application Level Classpath, path mentioned  Environment Variable etc.

Classloader - Linking

Linking is the process of incorporating the loaded bytecodes into the Java  Runtime System so that the loaded Type can be used by the JVM. It involves verifying and preparing that class or interface, its direct superclass, its direct  superinterfaces , and its element type (if it is an array type), if necessary.

  1. Verify: Bytecode verifier will verify whether the generated bytecode is proper or not if verification fails we will get verification error
  2. Prepare: For all static variables memory will be allocated and assigned with default values.
  3. Resolve: All symbolic memory references are replaced with the original references from Method Area.

Initialization

This is the final phase of Class Loading, here all static variable will be assigned with the original values and  static block will be executed.

Runtime Data Areas

The  Java Virtual Machine (JVM) defines various run-time data areas that are used during execution of a program. Some of these data areas are created on Java Virtual Machine start-up and are destroyed only when the Java Virtual Machine exits. Other data areas are per  thread . Per-thread data areas are created when a thread is created and destroyed when the thread exits.

Method Area

It is memory which is shared among all Threads like  Heap . It is created on Java Virtual Machine startup. It contains the code actually a compiled code, methods and its data and fields. Runtime constant pool is also a part of  Method Area .

Heap Area

Heap is a  memory place where the objects and its instance variable are stored. Each time an object is created in Java it goes into the area of  memory known as heap.

Stack Area

Stack is a memory place where the methods and the  local variables are stored. Variable references (either primitive or object references) are stored in the  Stack

PC Register

PC Register basically is a  address of current instruction is being executed. Since each thread some sets of method which is going to be executed depends upon  PC Register. It has some value for each instruction and undefined for  native methods . It is usually for keep tracking of instructions.

Native Method Stack

Native methods are those which are written in languages other than java.  JVM implementations cannot load native methods and can't rely on conventional stacks . It is also associated with each thread. In short it same as stack but it is used for  native methods .

Execution Engine

This is the core of the JVM.  Execution engine can communicate with various memory areas of JVM. Each thread of a running Java application is a distinct instance of the virtual machine's execution engine. The byte code that is assigned to the runtime data areas in the JVM via  class loader is executed by the execution engine.

  1. Interpreter
  2. JIT Compiler
  3. Garbage Collector

Interpreter

Reads, interprets and executes the  bytecode instructions one by one. As it interprets and executes instructions one by one, it can quickly interpret one bytecode, but slowly executes the interpreted result. This is the disadvantage of the interpret language. The 'language' called Bytecode basically runs like an  interpreter .

JIT Compiler

The  JIT compiler converts the bytecode to an intermediate-level expression, IR (Intermediate Representation), to execute  optimization , and then converts the expression to native code. The JIT compiler has been introduced to compensate for the disadvantages of the interpreter. The main purpose of JIT compiler is to improve the performance. Internally  JIT compiler maintains a separate count for every method. Whenever JVM across any method call, first that method will be  interpretednormally by the interpreter and JIT compiler increments the corresponding count variable.

Garbage Collector

Garbage collection (GC) is the process that aims to free up  occupied memory that is no longer referenced by any reachable Java object, and is an essential part of the Java virtual machine's (JVM's)  dynamic memory management system. All Java objects automatically grab the memory that they need when they are created, and when the object is no longer need, the Java  Garbage Collection process reclaim the memory. That means, the Garbage Collector tracked live objects and everything else designated garbage. More about.... Java Garbage Collection Basics

Native Method Interface

Native methods allow you to use code from other languages such as  C or C++ in your java code. You use them when java doesn't provide the functionality that you need.

Native Method Libraries

Native Method Libraries are Collection of the  Native Libraries which is required for the  Execution Engine .

http://net-informations.com/java/intro/jvm.htm

What is Java virtual machine?的更多相关文章

  1. fail to create java virtual machine..

    今天打开zend stdio 的时候 出现的错误  fail to create java virtual machine... 然后找度娘了,,都说改xxxxx, 我打开360  ,把内存清理了一遍 ...

  2. Failed to create the Java Virtual Machine.问题的解决

    运行Eclipse,出现了"Failed to create the Java Virtual Machine."错误: 解决的办法是在Eclipse的解压目录下找到eclipse ...

  3. eclipse failed to create the java virtual machine 问题图文解析

    eclipse failed to create the java virtual machine 问题图文解析 分类: java常用软件异常2010-10-02 23:45 73200人阅读 评论( ...

  4. [转载]Eclipse提示No java virtual machine

    第一次运行Eclipse,经常会提示下面的问题:... No java virtual machine  was found after searching the follwing location ...

  5. SQL Developer 4.0 启动报错“unable to create an instance of the java virtual machine located at path”

    安装了Oracle之后,第一件事情就是想想怎么去连接,进而操作.SQL Developer是官方提供的强大工具,个人看来也是第一选择. 目前官网提供的最新版是4.0.1.14.48,下载下来之后,就跃 ...

  6. Java Hour 58 Java Virtual Machine

    每每谈到Java Virtual Machine, 你必须意识到这个有三种意思: 1 一个抽象的指南 2 一个具体的实现 3 一个运行时的实例 JVM 的生命周期 每个运行时JVM 实例都是为一个特定 ...

  7. 解决Eclipse启动报错Failed to create the Java Virtual Machine

    电脑:2G内存,WIN7 32位. 启动adt-bundle-windows-x86-20140702\eclipse\eclipse.exe时,报错[Failed to create the Jav ...

  8. myeclipse启动报错 no java virtual machine。。。

    如果环境变量里已经配置了JAVA_HOME,但是在启动的时候还会提示下面的信息:   A Java Runtime Environment (JRE) or Java Development Kit ...

  9. Failed to create the java virtual machine完全解决办法

    一直用EcliPSe开发java,突然有这么一天,无法启动了,splash窗口显示“Failed to create the Java Virtual Machine”,结果发现eclipse和mye ...

  10. Eclipse 4.6 Neon, could not create the java virtual machine

    下了eclipse 4.6,打开报错:could not create the java virtual machine. a fatal exception has occurred. 命令行用 e ...

随机推荐

  1. 改变JAVA窗体属性的操作方法

    在本篇内容里小编给大家详细分析了关于改变JAVA窗体属性的操作方法和步骤,需要的朋友们学习下. 若将JDK版本升级到最新版本,Java窗体就可以简单实现窗体的透明效果,用户可以通过拉动滑块(Slide ...

  2. Springboot异常处理和自定义错误页面

    1.异常来源 要处理程序发生的异常,首先需要知道异常来自哪里? 1.前端错误的的请求路径,会使得程序发生4xx错误,最常见的就是404,Springboot默认当发生这种错误的请求路径,pc端响应的页 ...

  3. SpringCloud微服务(06):Config组件,实现配置统一管理

    本文源码:GitHub·点这里 || GitEE·点这里 一.Config简介 在微服务系统中,服务较多,相同的配置:如数据库信息.缓存.参数等,会出现在不同的服务上,如果一个配置发生变化,需要修改很 ...

  4. C#中 EF 性能优化

    https://www.cnblogs.com/chenwolong/p/7531955.html EF使用AsNoTracking(),无跟踪查询技术(查询出来的数据不可以修改,如果你做了修改,你会 ...

  5. 个性化windows10主题/换成winxp主题

    win10系统主题手动更换为仿winXp系统主题 突然想念家里那台被遗忘了好久的旧电脑,思绪被拉回小时候偷玩电脑的场景. 如果你也是一个念旧的人的话,我相信你一定喜爱Windows XP的经典界面. ...

  6. JS If...Else

    JS If...Else 条件语句用于基于不同的条件来执行不同的动作. 条件语句 通常在写代码时,您总是需要为不同的决定来执行不同的动作.您可以在代码中使用条件语句来完成该任务. 在 JavaScri ...

  7. 高级语言——java

    高级语言——java 起源与发展 1991 年,James Gosling 博士发布产品 Oak,这是 Java 语言的前身. 1995 年,Oak 语言改名为 Java. 1996 年,JDK(Ja ...

  8. Kafka学习(一)

    官网 kafka.apache.org 集群部署 消息中间键 --> 分布式流式平台 Kafka Streaming Flume: 1个进程包含三个角色 source channle sink ...

  9. 激活windows操作系统的命令行指令

    1.开始菜单中搜索命令提示符,右键管理员运行 2.为了避免激活的失败,首先卸载已经过期的密钥 输入以下命令:slmgr.vbs /upk 回车确认之后会弹出提示“已成功卸载了产品密钥” 3.下一步是将 ...

  10. Django模版中加载静态文件配置详解

    .settings.INSTALLED_APPS下添加:django.contrib.staticfiles .settings.py下添加:STATIC_URL = '/static/' . ()在 ...