mips virtual what is the java what is the jvm lecture 25
play

MIPS Virtual what is the Java - what is the JVM ? lecture 25 - PowerPoint PPT Presentation

MIPS Virtual what is the Java - what is the JVM ? lecture 25 Machine analogy ? - what is Java "byte code" Java Virtual Machine invoked methods and local stack (is it related to MIPS assembly/machine code ?) variables ?


  1. MIPS Virtual what is the Java - what is the JVM ? lecture 25 Machine analogy ? - what is Java "byte code" Java Virtual Machine invoked methods and local stack (is it related to MIPS assembly/machine code ?) variables ? (different from MIPS virtual machine) - what are .class files ? objects and garbage ? Wed. April 13, 2016 heap - what is garbage collection? class definitions ? user instructions Example: what you've seen in COMP 273 "Virtual Machine" (MIPS, Java) can refer to: 1) an abstract specification yourMIPScode.asm Let's turn our attention specifically to - a well defined instruction set MARS is written in the Java Virtual Machine (JVM). high level (both assembly and machine code) language (Java) and compiled to - specified "on paper" MARS Java byte code. It is a MIPS virtual 2) an implementation machine running on a Java virtual MIPS your computer machine. - software that runs on your computer (e.g. MARS for MIPS) computer (OS, processor) What does that 3) a runtime instance of that software mean? Compile time (your programs) "Java API" can refer both to: Compile time ("Java API") written by Sun 1) an abstract specification Microsystems (now Oracle) - set of classes and interfaces (with methods & fields) - on paper The Java compiler itself is a program written in (or 2) an implementation (libraries ) translated into) assembly language for your particular i.e. class files (see previous slide) machine. "byte code" Java API (implementation)

  2. Run time Portability your compiled code your compiled classes Java API classes your Java your Java your Java programs programs programs "Java platform" Java platform Java platform Java platform The above classes are "loaded" into the JVM at runtime, as they are needed. Windows Mac OS Linux Java API implementation JVM Java Virtual Machine Processor Z Processor Y (assembly language Processor X or machine code for your processor i.e. "native" code) implementation The Java platform and the OS both can be written in a higher level language (C, C++) ("native" code) but ultimately they must be compiled down to assembly language or machine code for particular processor. Let's compare MIPS with Java (and then JVM) Why was Java so important for www ? Java History (early 1990s) - portability - Java language created (by James Gosling at Sun) MIPS (assembly) Java (high level) (downloaded .class files can run on any JVM) - first web browsers written (html created) (*Java applets run in browser*) classes - security data - Mosaic (1993), Internet Explorer (1995) - fields (data) - registers - methods (instructions) (your compiled Java code doesn't know which computer it - Memory - superclass is running on. The platform provides a layer of protection - stack (0xffff ffff) (unlike C code which uses memory addresses explicitly) - globals & heap (0x1000 0000) objects (instances of classes) instructions JVM - what is the JVM ? MIPS - what is Java "byte code" ? Everytime a method is invoked, a stack frame is data added. "methods" point (is it related to MIPS assembly/machine code ?) Stack frames correspond to to information - registers invoked methods, like in about the class MIPS. Stack frames to which it contain: belongs (not - Memory shown) - stack (0xffff ffff) -a pointer to a method - what are .class files - globals & heap - a program counter within (0x1000 0000) that method. (This is quite different from what you are used to in MIPS.) - what is garbage collection? instructions - local variables of the method, e.g. references to objects. - Memory - an operand stack (a stack - text within a stack!) which I will Details are very implementation dependent. Think of the explain later. above as data structures in a JVM, namely in assembler code of the real computer.

  3. Example 1 JVM MIPS JVM instructions MIPS instructions ("byte code") No registers registers and Memory Java stack (except PC) frame Indeed, no CPU. Uses "operand stack" (stack within a stack) How is this done? MIPS analogy: load words from Memory into opcode (one byte) registers, then perform operation, then write back to Memory. http://en.wikipedia.org/wiki/Java_bytecode_instruction_listings Java stack frame (over time) Example 2 local variable index in the method's stack frame class SumToN { 0: iconst_0 1: istore_1 public static int sumton(int n){ 2: iconst_0 3: istore_2 int sum = 0; 4: iload_2 for (int k=0; k < n; k++){ 5: iload_0 sum = sum + k; fload_0 6: if_icmpge 19 } 9: iload_1 return sum; 10: iload_2 } fload_1 11: iadd } 12: istore_1 13: iinc 2, 1 fadd 0 16: goto 4 n 19: iload_1 sum 20: ireturn fstore_2 k What is in a class file? (on disk) What defines a class ? Try it yourself (linux) - 4 bytes 0xCAFEBABE - name - constants e.g. numbers, strings, identifier (names) - fields (identifier, type) javac SumToN.java - fields (including types) - methods (local variables, instructions, return type) produces SumToN.class - methods (byte code) - modifiers javap -c SumToN What is in a class file? "disassembles" the class file

  4. Define a graph 4 number of methods Garbage Collection 67 number of bytes in method 0 byte code for method 0 As more and more objects 52 number of bytes in method 1 are created, the heap eventually "fills up". What byte code for method 1 to do? 94 number of bytes in method 2 (Depends on implementation. The stack and heap should not be thought of as part of a byte code for method 2 single virtual address space, as we have seen in MIPS.) 45 number of bytes in method 3 byte code for method 3 JVM maintains a linked list of objects. Garbage Collection: "Mark and Sweep" Algorithm Only live (non-garbage) need to be kept. BEFORE GC AFTER GC - mark each object vertex as not visited - for each reference variable (vertex) in the stack If two objects point to each other, but nothing - traverse the graph starting from that vertex, and points to either of them, mark each object that you visit as visited then both will be removed by garbage - remove each not visited object vertex (garbage) collection. Final Exam Final Exam 48 multiple choice questions (5 choices per question): 48 multiple choice questions. - 18 have number / bitstring / hex / boolean formula answers Answer them all. If you are unsure, then eliminate as many as you can and guess from the rest. - 6 are of the form 'which of these is not correct ?' - the rest require you to choose the best (positive) answer This approach is consistent with principle of "no negative marking" : e.g. which of the following is correct ? http://www.ugent.be/en/education/degree/practical/studentadmin/OEREnglish/multiplechoice.htm The issue is subtle. Some multiple choice exams penalize you for getting wrong answer, but they don't penalize you for leaving a question blank. This encourages you to do probabilistic calculations on the exam, based on your certainty of whether you are correct or not. This is a distraction (not good). Instead of penalizing you for guessing, I will scale the grades downward, so you need to answer corretly more than half the questions correctly in order to get a grade of 50%. To my knowledge, such scaling is not controversial.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend