Java Internals. Frank Yellin Tim Lindholm JavaSoft

Similar documents
Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1

Special Topics: Programming Languages

Run-time Environments

Run-time Environments

Operating Systems CMPSCI 377, Lec 2 Intro to C/C++ Prashant Shenoy University of Massachusetts Amherst

Lecture 1: Overview of Java

High-Level Language VMs

Programming. Syntax and Semantics

Short Notes of CS201

Today. Instance Method Dispatch. Instance Method Dispatch. Instance Method Dispatch 11/29/11. today. last time

CS201 - Introduction to Programming Glossary By

Identity-based Access Control

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson


Java Security HotJava to Netscape and Beyond

Chapter 3:: Names, Scopes, and Bindings

Compiling Techniques

The Java Programming Language

Chapter 1 GETTING STARTED. SYS-ED/ Computer Education Techniques, Inc.

Outline. Introduction to Java. What Is Java? History. Java 2 Platform. Java 2 Platform Standard Edition. Introduction Java 2 Platform

Run-time Environments. Lecture 13. Prof. Alex Aiken Original Slides (Modified by Prof. Vijay Ganesh) Lecture 13

Control Abstraction. Hwansoo Han

Processes. Johan Montelius KTH

Java On Steroids: Sun s High-Performance Java Implementation. History

A process. the stack

The Java Language Implementation

Chapter 1 INTRODUCTION SYS-ED/ COMPUTER EDUCATION TECHNIQUES, INC.

Oak Intermediate Bytecodes

CMSC 330: Organization of Programming Languages

History Introduction to Java Characteristics of Java Data types

JAVA An overview for C++ programmers

Project. there are a couple of 3 person teams. a new drop with new type checking is coming. regroup or see me or forever hold your peace

Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8

Class Information ANNOUCEMENTS

CS2110 Fall 2011 Lecture 25. Under the Hood: The Java Virtual Machine, Part II

Windows 7 Overview. Windows 7. Objectives. The History of Windows. CS140M Fall Lake 1

Field Analysis. Last time Exploit encapsulation to improve memory system performance

C++ for System Developers with Design Pattern

Lecture 4: Threads; weaving control flow

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

CS321 Languages and Compiler Design I. Winter 2012 Lecture 2

CMSC 330: Organization of Programming Languages

ELEC 377 Operating Systems. Week 1 Class 2

Software Development & Education Center. Java Platform, Standard Edition 7 (JSE 7)

StackVsHeap SPL/2010 SPL/20

Azul Systems, Inc.

Chapter 3: Operating-System Structures

G Programming Languages - Fall 2012

Administration CS 412/413. Why build a compiler? Compilers. Architectural independence. Source-to-source translator

CSE 504: Compiler Design. Runtime Environments

Chapter 4: Threads. Operating System Concepts 9 th Edit9on

Names, Scope, and Bindings

CSCE 314 Programming Languages

Operating System Services

Operational Semantics. One-Slide Summary. Lecture Outline

AC59/AT59/AC110/AT110 OPERATING SYSTEMS & SYSTEMS SOFTWARE DEC 2015

Java: framework overview and in-the-small features

Compaq Interview Questions And Answers

C. E. McDowell August 25, Baskin Center for. University of California, Santa Cruz. Santa Cruz, CA USA. abstract

Lecture 8 Dynamic Memory Allocation

Chapter 8 :: Composite Types

Core Java - SCJP. Q2Technologies, Rajajinagar. Course content

02 B The Java Virtual Machine

CMSC 430 Introduction to Compilers. Spring Intermediate Representations and Bytecode Formats

Global Scheduler. Global Issue. Global Retire

Procedure and Object- Oriented Abstraction

OS lpr. www. nfsd gcc emacs ls 1/27/09. Process Management. CS 537 Lecture 3: Processes. Example OS in operation. Why Processes? Simplicity + Speed

The Slide does not contain all the information and cannot be treated as a study material for Operating System. Please refer the text book for exams.

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309

The NetRexx Interpreter

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS

Introduction to Programming (Java) 2/12

Remote Procedure Call (RPC) and Transparency

Chapter 3: Operating-System Structures

Sample Copy. Not for Distribution.

Portable Resource Control in Java The J-SEAL2 Approach

Java Security. Compiler. Compiler. Hardware. Interpreter. The virtual machine principle: Abstract Machine Code. Source Code

Advanced Object-Oriented Programming Introduction to OOP and Java

SOFTWARE ARCHITECTURE 7. JAVA VIRTUAL MACHINE

Heap Management. Heap Allocation

Advanced Programming & C++ Language

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

Interpreting Languages for the Java Platform

What goes inside when you declare a variable?

Project 3 Due October 21, 2015, 11:59:59pm

Praktische Softwaretechnologie

Motivation. Threads. Multithreaded Server Architecture. Thread of execution. Chapter 4

Threads. Raju Pandey Department of Computer Sciences University of California, Davis Spring 2011

Java TM Introduction. Renaud Florquin Isabelle Leclercq. FloConsult SPRL.

Names, Scope, and Bindings

CMSC 330: Organization of Programming Languages. Memory Management and Garbage Collection

Homework I - Solution

by Joseph D. Darcy and William Kahan Computer Science Division, University of California, Berkeley

Chapter 6 Introduction to Defining Classes

Binding and Storage. COMP 524: Programming Language Concepts Björn B. Brandenburg. The University of North Carolina at Chapel Hill

2 Sadeghi, Davi TU Darmstadt 2012 Secure, Trusted, and Trustworthy Computing Chapter 6: Runtime Attacks

Chapter 9 :: Subroutines and Control Abstraction

CHAPTER 3 - PROCESS CONCEPT

Run-time Environment

Transcription:

Java Internals Frank Yellin Tim Lindholm JavaSoft

About This Talk The JavaSoft implementation of the Java Virtual Machine (JDK 1.0.2) Some companies have tweaked our implementation Alternative implementations also exist Microsoft Natural Intelligence Companies we don t even know about

Overview Class file format Object format Memory layout Instruction Set Security Security Manager Garbage collection Native methods Class loading Threads and monitors

Class File (External) Machine independent Stream of bytes No byte sex dependency No pointer size dependency Constant Pool Attributes http://java.sun.com/newdocs.html

Class Format (Internal) name superclass constant pool fields methods method table field1 field2 fieldn method1 method2 methodn

Field Information name signature class access offset

Method Block (field info) code exception table invoker argument count max stack max locals max stack

Memory Areas Malloc ed space Methods, classes Random data structures Java heap Handle space Object space Moving more stuff to the Java heap

Java Heap Layout handles objects

Object Format handle object data method table data header data word 1 data word 2 data word 3 data word n Java objects refer to other objects via handles

Object Data Header Next fit allocation = allocated = free Both allocated and free space kept in linked list (Handle allocation, however, is trivial)

Instruction Set Instructions are typed Operate on the stack and local variables Non-orthogonal All arithmetic operations use the stack

Instruction Set (cont.) The Java Virtual Machine is not: The world s greatest virtual machine We wanted the Java Virtual Machine instruction set to be: Easy to verify Easy to compile Easy to interpret Portable Contain extensive type information

Instruction Categories Load/store local variable Arithmetic and type conversion Conditional/unconditional branch Object creation and manipulation Array creation and manipulation Method invocation Stack manipulation

Execution Stack machine model One Java stack per thread Java stack contains frames All instructions use the operand stack Local variables are per method invocation Method invocation arguments are pushed on the operand stack Separate (per thread) C stack

Java Stack Frames local variables frame info current method local variables constant pool return PC operand stack top operand stack

Java Stack Frames (cont.) local variables frame info operand stack old frame new frame local variables frame info operand stack

Linking, Loading, and Initialization Class files are loaded as needed Class files are loaded from the same source as the code requesting the class Several stage process

Constant Pool Resolution All references to String s, methods, fields, and (most) constants are done through the constant pool References are initially symbolic References are snapped the first time an instruction is executed

Constant Pool (cont.) Causes new classes to be loaded, as necessary

Security Low-level security The definition of the language The verifier High-level security The Security Manager

When Is the Verifier Run? Any class files that comes from an untrusted source (such as the network) Not on class files that come from your local disk Choice really depends on your interpreter or browser and on your security requirements

Why a Verifier? Hostile compilers (or just broken ones) Improve the speed of the interpreter Protect against changing APIs Protect against stack overflow, underflow, etc.

Verifier Passes 1. Check the class files syntactically 2. Check the class files semantically 3. Check the bytes codes 4. Runtime checks [optimization]

But... Halting Problem

Java High-Level Security Code that is downloaded over the Net is untrusted The Java language runs untrusted code in a trusted environment The Security Manager keeps a watchful eye on untrusted code

The Security Manager The Security Manager is the cop: Implements security policies Throughout the system, security checks are done at sensitive points The system s Security Manager performs those checks

What Does it Protect? The Security Manager restricts access to: The file system The network Other dangerous runtime calls: Setting the Security Manager Exiting Executing programs

How Does it Work? The Security Manager can: Scan the stack Check the caller s: Thread group Namespace Digital signature Or anything else: it s extensible! You can provide your own

Forthcoming: Signed Classes 1. User declares trusted entity 2. Entity signs Java-powered applet or application 3. Applet or application is now trusted, and thus granted more privileges Java-based technology enables true internet applications!

Garbage Collection Three causes of garbage collection Synchronous Asynchronous (Not always as useful as you might think) Explicit

GC Buzzwords Conservative or Exact? Compacting or Non-compacting? Generational? Stop and Copy? Real-time?

Sun s Garbage Collector Sun s garbage collector is: partially conservative, optionally compacting, non-generational, stop and copy, and generally pretty fast

Finalization A generalization of garbage collection Normally asynchronous, may be synchronous Guarantees?

Possible New Stuff Better low-memory behavior Heap contraction (staying small) Class garbage collection Tunable garbage collection Garbage collector plug ins Better algorithms (faster, generational, etc.)

Native Methods Declaring native methods in the Java language Defining native methods in C The javah glue Dynamic linking at runtime

Declaring Native Methods in Java: public native int read(); public static native double sin(double x);

Defining Native Methods in C #include java_io_fileinputstream.h long java_io_fileinputstream_read( Hjava_io_FileInputStream *this) {... }

Defining Native Methods in C #include java_lang_math.h double java_lang_math_sin( Hjava_lang_Math *this, double f) { return sin(f) }

javah To generate.h include files $ javah -stubs java.lang.fileinputstream To generate glue files $ javah java.lang.fileinputstream

Runtime Dynamic Linking The glue file generated by javah must be included in the shareable library or dll What happens internally

Class Loading System classes The ClassLoader class Used by HotJava to download classes over the network Can be used by sophisticated applets to create classes on the fly

Threads Priority preemptive Not guaranteed time-sliced Use platform facilities when possible Don t specify what we can t deliver Program defensively

Threads Implementations Solaris Windows 95/Windows NT MacOS

Monitors Java s synchronization primitive Use platform facilities Monitor cache Implementations Solaris Windows 95/Windows NT MacOS

The Host Programming Interface Java HPI Platform-independent C code Platform-specific code (C or assembly) Operating system

Conclusions The Java Virtual Machine Synthesis of successful ideas from other languages and other projects Designed to meet a goal, not to be aesthetically pure

For More Information.... The Java Virtual Machine Specification, by Tim Lindholm and Frank Yellin The Java Language Specification, by James Gosling, Bill Joy, and Guy Steele http://java.sun.com/newdocs.html