刘旭东 cameran@hit.edu.cn Tuesday, March 21, 2017 软件体系结构 6 虚拟机-解释器风格 刘旭东 cameran@hit.edu.cn Tuesday, March 21, 2017.

Slides:



Advertisements
Similar presentations
1 Java 语言程序设计 计算机系 鲍金玲. 2 引子 甲骨文 甲骨文是全球最大的信息管理软件及服务供应商,成立于 1977 年,公司总部 设在美国加利福尼亚州的红木城( Redwood Shores ),全球员工达 名, 包括 名开发人员、 7500 多名技术支持人员和.
Advertisements

1 Java 程序设计 Java 程序设计 Java Programming Fall, 2013.
第一章 Java 程序设计技术 概述  什么是 Java 语言  一个简单的 Java 程序  程序的编译和运行  常见错误  使用 Java 核心 API 文档.
第一组 Java 与云计算. Contents 云计算简介 一 二 云计算实例 三 云计算在教育中的应用 四.
Java 程序设计(第二版) 普通高等教育 “ 十一五 ” 国家级规划教材 辛运帷等 编著 徐小平 主讲.
云计算辅助教学风云录 黎加厚 上海师范大学教育技术系 2010年8月9日.
基础模块 模块一 程序设计基础 (一)开发环境部分.
Chapter 3: Operating-System Structures操作系统结构
第1章 Java语言概述.
创新实验 课程说明 计算机学院 孙彤 计算机学院 张明.
Java Programming Hygiene - for DIDC
加快数据中心运转速度 — 加速业务发展 约翰•福勒 甲骨文公司系统事业部执行副总裁. 加快数据中心运转速度 — 加速业务发展 约翰•福勒 甲骨文公司系统事业部执行副总裁.
Performance Evaluation
操作系统结构.
Oracle数据库 Oracle 子程序.
程設一.
天文望远镜集成建模研究 杨德华 南京天文光学技术研究所 30 NOV, 年中国虚拟天文台年会 广西师范大学 桂林
Leftmost Longest Regular Expression Matching in Reconfigurable Logic
作業系統的結構 日期 : 2018/9/17.
第1章 程式語言與Visual Basic的基礎
C# 程式設計 第一部分 第1-4章 C# 程式設計 - 南華大學資管系.
雲端運算虛擬主機技術的發展.
臺北市立大學 資訊科學系(含碩士班) 賴阿福 CS TEAM
簡易 Visual Studio 2010 C++ 使用手冊
2018/11/20 第一章 Java概述 武汉大学计算机学院计算机应用系 2018/11/20 14:33.
Operating System Concepts 作業系統原理 CHAPTER 2 系統結構 (System Structures)
Draft Amendment to STANDARD FOR Information Technology -Telecommunications and Information Exchange Between Systems - LAN/: R: Fast BSS.
第一章 電腦、程式與JAVA.
Decision Support System (靜宜資管楊子青)
Android 课程讲义 智能手机开发
HLA - Time Management 陳昱豪.
创建型设计模式.
鄭士康 國立台灣大學 電機工程學系/電信工程研究所/ 資訊網路與多媒體研究所
2018/12/7 Java语言程序设计 教师:段鹏飞.
Lecture on High Performance Processor Architecture (CS05162)
臺北市立大學 資訊科學系(含碩士班) 賴阿福 CS TEAM
第一单元 初识C程序与C程序开发平台搭建 ---观其大略
第九單元 Classes and data abstraction I
重點 資料結構之選定會影響演算法 選擇對的資料結構讓您上天堂 程式.
第4章(1) 空间数据库 —数据库理论基础 北京建筑工程学院 王文宇.
簡易 Visual Studio 2005 C++ 使用手冊
認識 Java.
Decision Support System (靜宜資管楊子青)
第 1 章 Java 簡介.
DevDays ’99 The aim of this mission is knowledge..
Instructions: Language of the Machine
Microsoft SQL Server 2008 報表服務_設計
Unit 11.Operating System 11.1 What’s OS 11.2 Related Courses
資料結構 Data Structures Fall 2006, 95學年第一學期 Instructor : 陳宗正.


第1章 Java语言概述 学习目标 本章要点 上机练习 习 题.
计算机问题求解 – 论题1-7 - 不同的程序设计方法
雲端虛擬化 Cloud Virtualization
C语言程序设计 主讲教师:陆幼利.
Real-Time System Software Group Lab 408 Wireless Networking and Embedded Systems Laboratory Virtualization, Parallelization, Service 實驗室主要是以系統軟體設計為主,
開發Java程式語言的工具 JDK.
中国科学技术大学计算机系 陈香兰 2013Fall 第七讲 存储器管理 中国科学技术大学计算机系 陈香兰 2013Fall.
虚 拟 仪 器 virtual instrument
中国科学技术大学计算机系 陈香兰 Fall 2013 第三讲 线程 中国科学技术大学计算机系 陈香兰 Fall 2013.
Common Qs Regarding Earnings
Aspect Oriented Programming
Inheritance -II.
临界区问题的硬件指令解决方案 (Synchronization Hardware)
11 Overview Cloud Computing 2012 NTHU. CS Che-Rung Lee
C++语言程序设计 C++语言程序设计 第一章 C++语言概述 第十一组 C++语言程序设计.
程式語言簡介 2019/7/17 明乘中學編製.
MGT 213 System Management Server的昨天,今天和明天
MATLAB 結構化財務程式之撰寫 MATLAB財務程式實作應用研習 主題五 資管所 陳竑廷
Windows Workflow Foundation CON 230
Presentation transcript:

刘旭东 cameran@hit.edu.cn Tuesday, March 21, 2017 软件体系结构 6 虚拟机-解释器风格 刘旭东 cameran@hit.edu.cn Tuesday, March 21, 2017

主要内容

主要内容 解释器风格(Interpreter) 基于规则的系统(Rule-based System) 虚拟机(Virtual Machine)

6.1 从Java入手…

Write Once, Run Anywhere 问题 你认为JAVA最吸引人的特性是什么? Object Oriented Automatic Memory Management Security Built-in Networking Robust Write Once, Run Anywhere Compiler/Interpreter Combo Platform Independence Dynamic Binding Good Performance Several dangerous features of C&C++ eliminated

Write Once, Run Anywhere 一次书写,多处运行

JAVA如何支持Platform Independence

6.2 解释器架构风格 Interpreter

MS-DOS的命令解释器 用户的命令行请求 (e.g., dir *.jsp /a /p) 操作系统内核的 执行指令?

解释器 An interpreter is a program that executes another program (解释器是一个用来执行其他程序的程序). An interpreter implements a virtual machine, which may be different from the underlying hardware platform. (解释器针对不同的硬件平台实现了一个虚拟机) To close the gap between the computing engine expected by the semantics of the program and the computing engine available in hardware. (将高抽象层次的程序翻译为低抽象层次所能理解的指令,以消除在程序语言与硬件之间存在的语义差异) 解释执行 解释器 宿主系统 (OS、硬件) 源代码

解释器 解释器通常用来在程序语言定义的计算和有效硬件操作确定的计算之间建立对应和联系。 简单和小规模的解释器只完成基本的信息识别和转换 复杂的解释器需要从词法到句法、到语法的复杂识别和处理 作为一种体系结构风格,解释器已经被广泛应用在从系统软件到应用软件的各个层面, 包括各类语言环境、Internet浏览器、数据分析与转换等; LISP、Prolog、JavaScript、VBScript、HTML、Matlab、数据库系统(SQL解释器)、各种通信协议等。

解释器的组成 被解释执行的程序 程序执行的当前状态 解释器引擎 的内部状态 解释器引擎

解释器风格 基本构件: 连接器: An interpretation engine (解释器引擎) A Memory that contains(存储区): The pseudo-code to be interpreted (被解释的源代码) A representation of the control state of the interpretation engine (解释器引擎当前的控制状态的表示) A representation of the current state of the program being simulated. (程序当前执行状态的表示) 连接器: Data access (对存储区的数据访问)

6.3 Interpreter versus compiler (解释器和编译器)

Interpreter versus compiler (解释器和编译器) 解释器在软件中的应用由来已久,早期的程序语言环境就分为编译(Compilation)和解释(Interpretation)两大类。

Compiler (编译器) This is in contrast to a compiler which does not execute its input program (the source code) but translates it into another language, usually executable machine code (also called object code) which is output to a file for later execution. (编译器不会执行输入的源程序代码,而是将其翻译为另一种语言,通常是可执行的机器码或目标码,并输出到文件中以便随后链接为可执行文件并加以执行) 编译 链接 执行 源代码 (.c++) 编译器 目标码 (.obj) 可执行文件 (.exe) 宿主系统 (OS、硬件)

Interpreter (解释器) 解释执行 It may be possible to execute the same source code either directly by an interpreter or by compiling it and then executing the machine code produced. (在解释器中,程序源代码被解释器直接加以执行。) 解释执行 解释器 宿主系统 (OS、硬件) 源代码

Interpreter versus compiler (解释器和编译器) 链接 执行 编译器 分析程序结构 源代码目标码 确定内存分配与访问方案 分配内存 执行目标码(机器码) 解释执行 解释器 分析程序结构 确定内存分配与访问方案 分配内存 解释并执行程序

Interpreter versus compiler (解释器和编译器) It takes longer to run a program under an interpreter than to run the compiled code but it can take less time to interpret it than the total time required to compile and run it. (解释器的执行速度要慢于编译器产生的目标代码的执行速度,但是却低于编译器“编译+链接+执行”的总时间) Interpreters are generally slower to run, but more flexible than compilers. Interpreters usually skip a linking and compilation step, enabling faster turn-around and decreasing cost of programmer time. (解释器通常省略了链接与编译的步骤,从而降低编程时间) edit-interpret-debug (编辑源代码-解释-调试) edit-compile-link-run-debug (编辑源代码-编译-链接-运行-调试)

Interpreter versus compiler (解释器和编译器) Interpreting code is slower than running the compiled code because the interpreter must analyze each statement in the program each time it is executed and then perform the desired action whereas the compiled code just performs the action. (解析器执行速度之所以慢,是因为每次解释执行的时候,都需要分析程序的结构,而编译代码则直接执行而无需重复编译) Access to variables is also slower in an interpreter because the mapping of identifiers to storage locations must be done repeatedly at run-time rather than at compile time.(解释器对内存的分配是在解释时才进行的;而编译器则是在编译时进行,因此运行时直接将程序代码装入内存并执行即可)

解释器的三种策略 传统解释器(traditionally interpreted) 纯粹的解释执行 基于字节码的解释器 (compiled to bytecode which is then interpreted) 编译解释执行 Just-in-Time (JIT)编译器 编译||解释执行 The GNU Compiler for the Java Programming Language GCJ is a portable, optimizing, ahead-of-time compiler for the Java Programming Language. It can compile Java source code to Java bytecode (class files) or directly to native machine code, and Java bytecode to native machine code.

传统解释器 解释执行 解释器直接读取源代码并加以执行; ASP Excel JavaScript MATLAB etc 宿主系统 解释器 (OS、硬件) 源代码

JVM中的解释器 Java的源程序不是直接交给解释器解释,而是先经过一个编译过程,把Java源程序翻译成一种特定的二进制字节码文件(Bytecode),再把这个字节码文件交给Java解释器来解释执行; The javac compiles Java source code to Java bytecode. (javac程序将Java源代码编译为字节码) Java编译器所生成的可执行代码可以不基于任何具体的硬件平台,而是基于JVM。 C/C++要的源程序要在不同的平台上运行,必须重新进行编译。

Bytecode interpreter (字节码解释器) 在该类解释器下,源代码首先被“编译”为高度压缩和优化的字节码,但并不是真正的机器目标代码,因而与硬件平台无关; 编译后得到的字节码然后被解释器加以解释; 例如: Java Perl PHP Python etc 注意: 字节码解释器中所产生的中间 字节码与编译器中产生的目标码 有何区别? 编译 解释执行 源代码 (.java) 编译器 字节码 (.class) 解释器 宿主系统 (OS、硬件)

Just-in-time compilation (实时编译) Just-in-time compilation (JIT), refers to a technique where bytecode is compiled to native machine code at runtime (实时编译JIT中,字节码在运行时被编译为本机的目标代码) In a JIT environment, bytecode compilation is the first step, reducing source code to a portable and optimizable intermediate representation. (第一步是编译得到字节码) The bytecode is deployed onto the target system. (字节码被配置到目标系统中) When the code is executed, the runtime environment‘s compiler translates it into native machine code. (当字节码被执行时,运行环境下的编译器将其翻译为本地机器码)

Just-in-time compilation (实时编译) It has gained attention in recent years, which further blurs the distinction between interpreters, byte-code interpreters and compilation. (JIT模糊了解释器、字节码解释器和编译器之间的边界与区分) JIT is available for both the .NET and Java platforms. 编译 解释执行 源代码 (.java) 编译器 字节码 (.class) 解释器 宿主系统 (OS、硬件) 执行 编译 JIT编译器 目标码 (.obj)

JIT: Deciding what to Compile(需编译哪些部分?) This can be done on a per-file or per-function basis: functions can be compiled only when they are about to be executed (hence the name “just-in-time”). (只有当某个函数要被执行时,才被编译,因此称为JIT) JIT compiles only those methods that contain frequently executed (“hot”) code: (而且,JIT并不是编译全部的代码,而是只编译那些被频繁执行的代码段) methods that are called a large number of times (被执行多次的方法); methods containing loops with large iteration counts (包含多次循环的方法).

总结 解释器的三种策略: 传统解释器(traditionally interpreted) 基于字节码的解释器 (compiled to bytecode which is then interpreted) Just-in-Time (JIT)编译器

6.4 基于规则的系统 Rule-based System

业务逻辑的频繁变化 现实里的业务需求经常频繁的发生变化(例如价格、业务流程、配方计算、用户界面等),软件系统也要随之适应。如果每一次的需求变化都需要程序员来修改代码,那么,效率将会非常低,成本也非常高。 软件工程要求从“需求设计编码”,然而很多业务逻辑常常在需求阶段可能还没有明确,在设计和编码后还在变化。

程序中的业务规则 业务规则在程序中通常是以if-then-else-endif分支结构的形式书写的。 业务越复杂,判断逻辑越多,程序越难理解,越难维护 业务变化导致程序修改,通常是对程序进行局部性修改

如何解决上述问题? OO设计的一个重要原则:固定部分与可变部分分离; 将二者分离开来,当可变部分发生变化时,不会影响固定部分。 OCP: the Open-Closed Principle (开放封闭原则) 将二者分离开来,当可变部分发生变化时,不会影响固定部分。 Bertrand Meyer introduced the Open/Closed Principle (OCP) to state the goal that a class should be open for extension but closed for modification (Meyer, 1997).

基于规则的系统 最好的办法是把频繁变化的业务逻辑抽取出来,形成独立的规则库。这些规则可独立于软件系统而存在,可被随时的更新; 业务逻辑=固定业务逻辑+可变业务逻辑(规则)+规则引擎 系统运行的时候,读取规则库,并根据模式匹配的原理,依据系统当前运行的状态,从规则库中选择与之匹配的规则,对规则进行解释,根据结果控制系统运行的流程。 ——“频繁变化的规则”与“较少发生变化的规则执行代码”分离 基于规则的系统:一个使用模式匹配搜索来寻找规则并在正确的时候应用正确的逻辑知识的虚拟机。

基于规则的系统 Rule-based systems provide a means of codifying the problem-solving know-how of human experts. (基于规则的系统提供了一种将专家解决问题的知识与技巧进行编码的手段) These experts tend to capture problem-solving techniques as sets of situation-action rules whose execution or activation is sequenced in response to the conditions of the computation rather than by a predetermined scheme. (将知识表示为“条件-行为”的规则,当满足条件时,触发相应的行为,而不是将这些规则直接写在程序源代码中) Since these rules are not directly executable by available computers, systems for interpreting such rules must be provided. (规则一般用类似于自然语言的形式书写,无法被系统直接执行,故而需要提供解释规则执行的“解释器”)

基于规则的系统 规则库 程序运行存储区 规则选择 规则解释执行引擎

基于规则的系统 基本构件: 基于规则的系统 解释器风格 The knowledge base 知识库(规则库) the pseudo-code to be executed 待执行的伪代码 The rule interpreter 规则解释器 the interpretation engine 解释器引擎 The rule and data element selector 规则与数据元素选择器 The control state of the interpretation engine 解释器引擎的内部控制状态 the working memory 工作存储区 The current state of the program running on the virtual machine 程序当前的运行状态

基于规则的系统的优点 Lowers the cost incurred in the modification of business logic (降低了修改业务逻辑的成本) Shortens development time (缩短了开发时间) Rules are externalized and easily shared among multiple applications (将规则外部化,可在多个应用之间共享) Changes can be made faster and with less risk (对规则的改变将非常迅速并且具有较低的风险)

用户界面解释器示例

基于规则的系统 核心思想: 基本过程: 将业务逻辑中可能频繁发生变化的代码从源代码中分离出来; 使用规则定义语言(IF…THEN…的形式,通常基于XML或自然语言,但决不是程序设计语言),将这些变化部分定义为“规则”; 在程序运行的时候,规则引擎根据程序执行的当前状态,判断需要调用并执行哪些规则,进而通过“解释器”的方式来解释执行这些规则。 其他直接写在源代码里的程序,仍然通过传统的“编译”或“解释”的办法加以执行。

基于规则的系统 源代码 编译 链接 执行 高级语言 解释执行 规则定义语言 (自然语言/XML) 解释执行 编译器 目标码 (.obj) 可执行文件 (.exe) 高级语言 固定部分 解释执行 解释器 宿主系统 (OS、硬件) 可变部分 解释器 (规则引擎) 规则定义语言 (自然语言/XML) 解释执行

规则的表达形式 Any rule consists of two parts (任何规则都包含两部分) : IF part, called the antecedent (premise or condition) (IF:规则的前提或条件) THEN part, called the consequent (conclusion or action) (THEN:规则的结论或触发的行为) IF <antecedent> THEN <consequent> A rule can have multiple antecedents joined by AND (conjunction), OR (disjunction) or a combination of both. (一个规则可以有多个条件,使用AND或OR连接) IF <antecedent 1> AND (<antecedent 2> OR <antecedent 3>) THEN <consequent>

几个例子 如果客户年龄小于18岁, 而且取款金额大于1000元, 那么,需要家长的签名; 如果客户订单的总金额大于100元, IF Customer.age<18 AND Withdraw.amount>1000 THEN signature of the parent is required IF CustomerOrder.TotalMoney >100 THEN CustomerOrder.Discount = 10% IF Order.Sum >¥10,000 AND Order.Sum <=¥50,000 THEN Order.AuditedBy(“DepartmentManager”) 如果客户年龄小于18岁, 而且取款金额大于1000元, 那么,需要家长的签名; 如果客户订单的总金额大于100元, 那么,该订单的折扣为10%; 如果订单总金额大于1万人民币, 而且订单总金额小于5万人民币, 那么,该订单需要由部门经理审核。

几个例子 如果,购物车里货物的总金额大于200美元, 那么,该顾客为金卡客户; 如果,顾客为金卡客户, IF ShoppingCart.purchaseAmount > $200 THEN Customer.category = “Gold” IF Customer.category == “Gold” THEN ShoppingCart.discount += 5% IF ShoppingCart.discount > 15% THEN ShoppingCart.discount = 15% 如果,购物车里货物的总金额大于200美元, 那么,该顾客为金卡客户; 如果,顾客为金卡客户, 那么,该客户每次购物的折扣在原有基础上提高5%; 如果,某次购物的折扣超过15%, 那么,调整折扣到15%。

规则的分类 UI输入域的合法性检查 数据库中的触发器和存储过程 安全性规则(权限控制规则) 组织中的权利/义务/责任的相关规则 业务过程中各活动的执行次序 业务策略(如折扣策略、风险/信用控制策略等) …

规则引擎实例:ILOG JRules 规则编辑器 规则库 规则配置与部署工具 规则执行引擎 软件系统

开源规则引擎JBoss Drools及其开发 场景:银行借贷,当借贷款额小于1000时,直接借出,否则,需交由总经理处理。 实现: Drools5.1 Eclipse3.4

package demo.loan; public class pojo { int moneycount; String customer="Cameran"; private String custType="Norm"; private String custStatus="NoPass"; public int getMoneycount() { return moneycount; } public void setMoneycount(int moneycount) { this.moneycount = moneycount; void setCustomer(String customer) { this.customer = customer; ...

package demo.loan; import demo.loan.pojo; rule "A" when $m:pojo(moneycount<1000,custStatus=="NoPass"); then $m.setCustStatus("Pass"); update($m); end rule "B" $m:pojo(moneycount>=1000,custStatus=="NoPass"); System.out.println("交由总经理审批!"); $m.setCustType("VIP"); rule "C" $m:pojo(custStatus=="Pass"); System.out.println("办理完毕!");

package demo.loan; public class deploy { public void loanrool(int moneycount) throws Exception { // TODO Auto-generated method stub pojo p=new pojo(); try { KnowledgeBase kbase = readKnowledgeBase(); StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory .newFileLogger(ksession, "test"); p.setMoneycount(moneycount); ksession.insert(p); ksession.fireAllRules(); System.out.println(p.toString()); logger.close(); } catch (Throwable t) { t.printStackTrace(); } private KnowledgeBase readKnowledgeBase() throws Exception {…} ... 读取规则定义文件

运行结果 package demo.loan; public class test { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub deploy dp=new deploy(); dp.loanrool( 1200); } 900

思考 京东、亚马逊等电商网站频繁的价格调整如何利用规则引擎实现? ?

6.5 虚拟机 Virtual Machine

What is Virtual Machine? 要在开发Android程序,必须买一部Android手机并在手机上编程? No!在PC上安装一个包含Android虚拟机(硬件虚拟机)的SDK即可 A virtual machine is software implementation of a machine (i.e. a computer) that executes programs like a physical. 虚拟机是一种软件; 它创建了一种虚拟机器; 可像真实机器一样执行程序。

虚拟机的分类 系统虚拟机(System virtual machine):A system virtual machine provides a complete system platform which supports the execution of a complete operating system (OS) 在OS与硬件之间建立隔离。 Also called Hardware virtual machine (硬件虚拟机) 进程虚拟机(Process virtual machine):a process virtual machine is designed to run a single program.在应用程序与OS之间建立隔离。 Also called Application virtual machine (应用程序虚拟机) OS1 OS2 OSn Hypervisor Host OS Hardware http://en.wikipedia.org/wiki/Virtual_machine App1 App2 Appn Interpreter Host OS Hardware

1 Hardware virtual machine (硬件虚拟机) Hardware virtual machine (also called Hypervisor) is the virtualization of computers or operating systems. It hides the physical characteristics of a computing platform from users, instead showing another abstract computing platform. 原生虚拟化 installed on server hardware.直接运行在硬件之上. 寄宿虚拟化 run within a host operating system environment.运行在宿主操作系统上.

硬件虚拟机的特点 多实例 单个 Hypervisor 上可以运行多个虚拟机,而物理系统的资源是以可控方式分配给虚拟机的。 隔离 虚拟机之间需要隔离。即便一个或者多个虚拟机操作系统崩溃,其他虚拟机也不会受到影响。虚拟机之间不会泄漏数据。多个虚拟机之间的应用程序如果需要相互访问,只能通过配置的网络进行通信。这些就如同独立的物理服务器一样。 封装 或者叫做硬件无关性。虚拟机对外的表现为单一的实体,例如一个虚拟机配置文件、一个虚拟硬盘文件。 硬件独立 或者叫平台无关性,虚拟器件(Virtual Appliance)可以便于在不同的硬件的虚拟机间备份、移动或者复制。

硬件虚拟机的优缺点 Advantages优点 Disadvantages缺点 Improve the system resource utilization rate提高系统资源利用率 multiple OS environments can co-exist on the same computer, in strong isolation from each other多系统共存且隔离 the virtual machine can provide an instruction set architecture (ISA) that is somewhat different from that of the real machine可提供额外指令 application provisioning, maintenance, high availability and disaster recovery易维护、高可用、灾难恢复 Disadvantages缺点 a virtual machine is less efficient than a real machine when it accesses the hardware indirectly性能有限 when multiple VMs are concurrently running on the same physical host, each VM may exhibit a varying and unstable performance可能不稳定

硬件虚拟机产品实例 原生虚拟化(企业级) 寄宿虚级化(面向个人) VMware ESX Server Microsoft Hyper-V IBM powerVM及z/VM Xen(开源) KVM(开源) … 寄宿虚级化(面向个人) VMware Workstation Oracle Virtual Box(免费) Microsoft Virtual PC

2 Application virtual machine (应用程序虚拟机) A piece of computer software that isolates the application being used by the user from the computer. (应用程序虚拟机:将用户使用的应用程序与计算机系统隔离开来的软件) Any application written for the virtual machine can be operated on any of the platforms, instead of creating separate versions of the same software for different OS and computers. (应用程序无需针对不同的OS和硬件环境而开发不同的版本,只需针对虚拟机开发即可) The application is run on the computer using an interpreter or Just-in-Time compilation. (应用系统使用解释器或JIT技术运行)

Java Virtual Machine (JVM) A Java Virtual Machine (JVM), originally developed by Sun Microsystems, is a virtual machine that executes Java byteCode. (JVM:执行Java字节码的虚拟机) The availability of JVMs on many types of hardware and software platforms enables Java to function both as middleware and a platform in its own right. Hence the expression “Write once, run anywhere.“ (JVM可适应所有的硬件与OS平台,从而使得Java具有“一次书写,到处运行”的能力)

JVM的标准输入:Java Class prog.java Programs intended to run on a JVM must be compiled into a standardized portable binary format, which typically comes in the form of .class files. (在JVM上运行的程序必须首先被编译为标准的二进制格式的文件:.class) prog.java

Java Class在JVM上的执行 注意:Java class文件并不是机器代码或目标代码,而是一种具有标准中间格式的二进制文件,无法直接在任何OS平台上执行; Java Class必须在JVM的支持下才能真正执行; This binary is then executed by the JVM runtime which carries out emulation of the JVM instruction set by interpreting it or by applying a just-in-time compiler (JIT). ( java class文件在JVM下运行,运行策略可能为:解释器或JIT编译器)

JVM的执行机制 JVM (Java虚拟机)

JVM的功能与作用 Each particular host operating system needs its own implementation of the JVM and runtime. (每个特定的OS需要实现自己的JVM) The JVM has instructions for the following groups of tasks: (在执行具体的class代码之前,JVM需要针对特定的OS环境,进行以下转换) Load and store Type conversion Object creation and manipulation Operand stack management (push / pop) Control transfer (branching) Method invocation and return Throwing exceptions 将JAVA CLASS代码转化为 特定OS所能支持的程序运行模式

总结:基于JVM的Java程序开发与执行过程

典型的应用程序虚拟机列表

结束 2017年3月21日