Runs as a normal application inside an os and supports a single process. Runs as a normal application inside an os and supports a single process



Yüklə 1,18 Mb.
tarix07.11.2018
ölçüsü1,18 Mb.
#78946



Runs as a normal application inside an OS and supports a single process.

  • Runs as a normal application inside an OS and supports a single process.

  • Created when the process is started and destroyed when it exits.

  • A software implementation of a machine (i.e. a computer) that executes programs like a physical machine.



Application Virtual Machines

  • Application Virtual Machines

    • Allows application byte code to be run on different architectures and operating systems.
    • Eg. JVM, CLR, Dalvik, Squeak (Smalltalk), etc…
  • System (Platform) Virtual Machines

    • Emulation of entire physical machine
    • Eg. VMWare, VirtualBox, etc…
  • We will be focusing on process virtual machines!!





Compatibility: Virtual machines are compatible with various hardware platforms.

  • Compatibility: Virtual machines are compatible with various hardware platforms.

  • Isolation: Virtual machines are isolated from each other as if physically separated.

  • Encapsulation: Virtual machines encapsulate a complete computing environment.

  • Hardware Independence: Virtual machines run independently of underlying hardware.



Stacks vs Registers

  • Stacks vs Registers

    • Stack-based machine: Operands are pushed and popped off the stack.
    • Register-based machine: Operands stored in register.
    • The most popular VMs use stack architectures.
  • Costs of executing VM instructions

    • Dispatching the instruction
    • Accessing the operands
    • Performing the computation


Costs of executing a VM instruction

  • Costs of executing a VM instruction

    • Dispatching the instruction
      • A given task can often be expressed using fewer register machine instructions than stack ones.
    • Accessing the operands
      • Stack code is smaller than register code, and requires fewer memory fetches to execute.
      • This is the main reason why stack architectures are popular for VMs.


Costs of executing a VM instruction (cont)

  • Costs of executing a VM instruction (cont)

    • Performing the computation
      • Usually the smallest part of cost.
      • Has to be performed regardless of intermediate representation.
      • However, eliminating invariant and common expressions is much easier on a register machine.


Managed (eg. JVM)

  • Managed (eg. JVM)

    • Safe automatic memory management.
    • Disallow manually constructed pointers to memory.
  • Unmanaged (eg. LLVM)

    • Allow direct use and manipulation of pointers.
    • But no automated garbage collection.


Hybrid (eg. Dot.NET)

  • Hybrid (eg. Dot.NET)

    • Offering both controlled use of memory, while also offering an “unsafe” mode that allows direct manipulation of pointers in ways that can violate type boundaries and permission.


AKA Dynamic Translation

  • AKA Dynamic Translation

  • A method to improve the runtime performance of computer programs

  • Hybrid of two previous approaches

    • Interpretation: Translated from a high-level language to machine code continuously during every execution
    • Static (ahead-of-time) compilation: Translated into machine code before execution, and only requires this translation once.


JIT compilers in JRE (JVM) and .NET runtimes

  • JIT compilers in JRE (JVM) and .NET runtimes



At the time of code execution, the JIT compiler will compile some or all of it to native machine code for better performance.

  • At the time of code execution, the JIT compiler will compile some or all of it to native machine code for better performance.

  • Can be done per-file, per-function or even on any arbitrary code fragment.

  • The compiled code is cached and reused later without needing to be recompiled (unlike interpretation).



Offers other advantages over statically compiled code at development time, such as handling of late-bound data types and the ability to enforce security guarantees.

  • Offers other advantages over statically compiled code at development time, such as handling of late-bound data types and the ability to enforce security guarantees.

  • Most VMs rely on JIT compilation for high speed code execution

  • JIT for Android: Dalvik JIT

    • http://www.youtube.com/watch?v=Ls0tM-c4Vfo




Brief History

  • Brief History

    • Developed by Alan Kay et al. in Xerox PARC (Palo Alto Research Center Incorporated)
    • Generally recognized as the second Object Programming Language (OPL) (After Simula)
    • The first Pure OPL
    • Variants: Smalltalk-71, Smalltalk-72, Smalltalk-76, Smalltalk-80(First made available outside PARC), Squeak (Most popular version today)


Two major components

  • Two major components

    • The virtual image
      • Stores the heap and all the objects in it on disk
      • In Java, the heap conceptually starts out empty and is discarded after program termination
    • The virtual machine
      • Reads the image from disk into memory and executes the code it contains.


The image can be saved at the user’s discretion (“taking a snapshot”).

  • The image can be saved at the user’s discretion (“taking a snapshot”).

  • If the system crashes, the user may restart the system, going back to the exact state of the heap from the snapshot.

  • This feature is more commonly seen nowadays in system VMs instead of process VMs.

  • The image makes Smalltalk more portable than Java



1991 - James Gosling begins work on Java project (Originally named “Oak” for the oak tree outside his office.)

  • 1991 - James Gosling begins work on Java project (Originally named “Oak” for the oak tree outside his office.)

  • 1995 - Sun releases first public implementation as Java 1.0

  • 1998 - JDK 1.1 release downloads tops 2 million

  • 1999 - Java 2 is released by Sun

  • 2005 - Approximately 4.5 million developers use Java technology

  • 2007 - Sun makes all of Java’s core code available under open-source distribution terms.



Java is a general-purpose, concurrent, class-based, object oriented language that is specifically designed to have as few implementation dependencies as possible.

  • Java is a general-purpose, concurrent, class-based, object oriented language that is specifically designed to have as few implementation dependencies as possible.

  • It is intended to let application developers “write once, run anywhere”.

  • Currently one of the most popular programming languages in use.



Why this design?

  • Why this design?

    • Familiarity
      • Bytecode interpreter/compilers were used before
      • Eg. Pascal “pcode”; Smalltalk bytecode
    • Minimize machine-dependency
    • Portability
      • Transmit bytecode across network
      • “Compile once, run anywhere”






Bootstrap class loader

  • Bootstrap class loader

  • User-defined class loader





Type Information

  • Type Information

  • Constant pool

  • Field information

  • Method table

  • Method information

  • Class variable

  • Reference to class loader and class



Fully qualified type’s name.

  • Fully qualified type’s name.

  • Fully qualified direct super class name.

  • Whether class or an interface

  • Type’s modifiers

  • List of fully qualified names of any direct super interfaces



Ordered set of constants

  • Ordered set of constants

    • string
    • integer
    • floating point
    • final variables
  • Symbolic references to

    • Types
    • Fields
    • Methods
















Objects and arrays are allocated in a single, shared heap.

  • Objects and arrays are allocated in a single, shared heap.

  • Each application has its own heap (isolation).

  • However, two different threads of the same application could trample on each other’s heap data.

  • Used when memory allocated with new operator.

  • Runtime environment automatically frees up memory on heap occupied by objects that are no longer referenced (garbage collection).









Java stack stores a thread’s state in discrete frames.

  • Java stack stores a thread’s state in discrete frames.

  • Each frame contains

    • Local variables area.
    • Operant stack
    • Frame data


Organized as a zero-based array of cells.

  • Organized as a zero-based array of cells.

  • Variables area accessed through their indices.

  • Values of type int, float, reference, and return address occupy one cell.

  • Values of type byte, short, and char also occupy one cell.

  • Values of type long and double occupy two consecutive cells in the array.





iload_0 // push the int in local variable 0

  • iload_0 // push the int in local variable 0

  • iload_1 // push the int in local variable 1

  • iadd // pop two ints, add them, push result

  • istore_2 // pop int, store into local variable 2



10 basic sections to the Java Class File structure:

  • 10 basic sections to the Java Class File structure:

    • Magic Number
    • Version of Class File Format
    • Constant Pool
    • Access Flags
    • This Class
    • Super Class
    • Interfaces
    • Fields
    • Methods
    • Attributes


Magic Number (4 bytes)

  • Magic Number (4 bytes)

    • Class files are identified by the following 4 byte header : CAFEBABE
    • Version of Class File Format (4 bytes)
    • minor version number of the class file format being used(2 bytes)
    • major version number of the class file format being used(2 bytes)
      • J2SE 6.0 = 50 (0x32 hex) J2SE 5.0 = 49 (0x31 hex) JDK 1.4 = 48 (0x30 hex) JDK 1.3 = 47 (0x2F hex) JDK 1.2 = 46 (0x2E hex) JDK 1.1 = 45 (0x2D hex)


Constant Pool(2 bytes)

  • Constant Pool(2 bytes)

    • number of entries in the following constant pool table, say N
    • At least one greater than the actual number of entries (N-1)
  • Constant Pool[1]….[N-1]

  • Access Flag(2 bytes)

    • flags that represent modifiers of the class or interface defined by this file.
      • ACC_PUBLIC is 0x0001
      • ACC_FINAL is 0x0010
      • both public and final is (ACC_PUBLIC | ACC_FINAL)


This Class(2 bytes)

  • This Class(2 bytes)

    • index into the constant pool to a "Class"-type entry
  • Super Class(2 bytes)

    • index into the constant pool to a "Class"-type entry
  • Interfaces(2 bytes)

    • the number of interfaces implemented by this class. (N)


Fields(2 bytes)

  • Fields(2 bytes)

    • the number of fields (class or instance variables) declared by this class.
  • Methods(2 bytes)

    • the number of methods defined by this class. The count does not include any methods inherited from superclasses, only those methods explicitly defined in this class.
    • the instance initialization method, (), is generated by the compiler.
  • Attributes(2 bytes)

    • The number of attributes (N)


Each time a method is invoked a new stack frame is created. The frame consists of an operand stack, an array of local variables, and a reference to the runtime constant pool of the class of the current method.

  • Each time a method is invoked a new stack frame is created. The frame consists of an operand stack, an array of local variables, and a reference to the runtime constant pool of the class of the current method.



Basic Opcode

  • Basic Opcode

    • const (push constant onto the stack)
      • iconst_1: push integer constant value 1 onto the stack
    • Store(pop to local variables)
      • istore_1: store the integer in local position one
    • Load(push variable onto the stack)
      • iload_1: push integer from local variable position one
  • Java opcodes generally indicate the type of their operands.

    • Opcodes iload, lload, fload, and dload push local variables of type int, long, float, and double, respectively, onto the stack


 javap -c

  •  javap -c

    • print out the bytecode
  • javap -c -s –verbose

    • Print out the constant pool
  • http://arhipov.blogspot.com/2011/01/java-bytecode-fundamentals.html



Example-Example.java

  • Example-Example.java

    • public class Example
    • {
    • public int plus(int a)
    • {
    • int b = 1;
    • return a + b;
    • }
    • }


Javap –c Example

  • Javap –c Example



Local variable Table for Example.java

  • Local variable Table for Example.java



http://www.artima.com/insidejvm/ed2/

  • http://www.artima.com/insidejvm/ed2/

  • http://rockfish-cs.cs.unc.edu/COMP144/lect32a.ppt

  • http://web.cecs.pdx.edu/~harry/musings/SmalltalkOverview.html

  • http://www.cse.iitk.ac.in/users/vkirankr/Memory%20Architecture.ppt



Yüklə 1,18 Mb.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə