Top Banner
SPL/2010 SPL/2010 Run time environments 1
46

Run time environments

Feb 25, 2016

Download

Documents

janet

Run time environments. What is runtime?. Runtime: time during which a program is running (executing). It contrasts to other phases of program as compile time, link time, load time, etc. Topics we will cover . סביבת הרצה. What is a runtime environment (RTE)? Concurrency management in RTE - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Run time environments

SPL/2010SPL/2010

Run time environments

1

Page 2: Run time environments

SPL/2010SPL/2010

What is runtime?● Runtime: time during which a program is

running (executing). ● It contrasts to other phases of program

as compile time, link time, load time, etc

2

Page 3: Run time environments

SPL/2010SPL/2010

Topics we will cover

1. What is a runtime environment (RTE)?2. Concurrency management in RTE3. Memory management in RTE4. Communication and networking in RTE5. Persistent data management in RTE

3

הרצה סביבת

Page 4: Run time environments

SPL/2010SPL/2010

Topics we will cover ● RTE’s standard tools and abstractions● RTE limitations and costs: how knowing

your RTE helps task design● Multiple levels of abstractions formed by

intra-RTE relationships● Compare RTEs: Unix and Win32 OS, Java

Virtual Machine (JVM) Servlets, distributed RTEs

4

Page 5: Run time environments

SPL/2010SPL/2010

RTE 1st example: OS● Who is the RTE and who are entities running

inside? ● OS vs. Process (entity running/executing

inside OS):● Definition● Interaction● Process lifecycle

5

Page 6: Run time environments

SPL/2010SPL/2010

What is OS?● OS manages sharing of computer

resources● OS performs basic tasks:

● allocate and control memory● control I/O devices● control CPU time ● networking ● managing file systems

6

Page 7: Run time environments

SPL/2010SPL/2010

OS system calls● Most services offered by OS are abstract

objects (e.g., files and directories)● echo abc > /dev/ttyS0

● Interface for service request from OS is through system calls● system call: low level function which enable

interaction between process and OS

7

Page 8: Run time environments

SPL/2010SPL/2010

/usr/src/linux/fsENTRY(system_call)

pushl %eax # save orig_eax

SAVE_ALL

GET_CURRENT(%ebx)

testb $0x02,tsk_ptrace(%ebx) # PT_TRACESYS

jne tracesys

cmpl $(NR_syscalls),%eax

jae badsys

call *SYMBOL_NAME(sys_call_table)(,%eax,4)

movl %eax,EAX(%esp) # save the return value

8

entry.S : system-call and fault low-level handling routines * NOTE: This code handles signal-recognition, which happens every time after a timer-interrupt and after each system call.

Page 9: Run time environments

SPL/2010SPL/2010

Unix system calls● Sys calls for file I/O

● open() close() read() write()

● Sys calls for process control

● fork() wait() execv(), exit() sigal() kill()

● Sys calls for IPC● pipe() dup()

9

asmlinkage ssize_t sys_read(unsigned int fd, char * buf, size_t count){

ssize_t ret;struct file * file;

ret = -EBADF;file = fget(fd);

if (file) {if (file->f_mode & FMODE_READ) { ret = locks_verify_area(FLOCK_VERIFY_READ, file->f_dentry-

>d_inode, file, file->f_pos, count);if (!ret) { ssize_t (*read)(struct file *, char *, size_t, loff_t *); ret = -EINVAL; if (file->f_op && (read = file->f_op->read) != NULL)

ret = read(file, buf, count, &file->f_pos); }

}if (ret > 0)

dnotify_parent(file->f_dentry, DN_ACCESS);fput(file);

}return ret;}

Page 10: Run time environments

SPL/2010SPL/2010

Operating System modules

10

Page 11: Run time environments

SPL/2010SPL/2010

Processes● Main OS abstraction of an execution

unit ● Instance of a program, which is currently

executing.

11

Page 12: Run time environments

SPL/2010SPL/2010

Process vs. Program● Program = passive collection of

instructions● Process = actual execution of

instructions ● Possibly many simultaneous incarnations

of same program, each incarnation = process

12

Page 13: Run time environments

SPL/2010SPL/2010

Process / OS interaction

● Resource allocation: manage computer resources between processes

● Main resources :● CPU time● Disk space● Memory● I/O devices● other services (communication, etc…)

13

Page 14: Run time environments

SPL/2010SPL/2010

CPU time● CPU: execute machine code sequentially, one instruction

at a time. ● Multitasking: processes executing concurrently - CPU

sharing. How?● Context switch: CPU stops executing one process and

switch to another.● In modern OSs, CPUs, one context switch = ~10 microseconds

(compare with single computation execution ~1 nanosecond) ● 1 context switch = 10000 instructions ● Scheduler: entity inside OS in charge of selecting which process

will be executed next

14

Page 15: Run time environments

SPL/2010SPL/2010

Process / OS interaction● Services initiated by the OS

● CPU (through context switch)● initial memory allocation (to load the code

itself).● Services requested by the process

● memory allocation● disk space● access external devices: mouse, KBD, screen

15

Page 16: Run time environments

SPL/2010SPL/2010

Process Life Cycle● Processes states: 

● Running (executed in CPU) ● Waiting

– CPU time,– I/O (much slower than a CPU operation),– event (synchronization: process waiting for

another process to reach a certain state before it can continue)

16

Page 17: Run time environments

SPL/2010SPL/2010

Process Life Cycle● OS manages the life cycle of a process● 3 main steps: create, manage, terminate

17

Page 18: Run time environments

SPL/2010SPL/2010

Process Life Cycle● Compiler: translate a program in a

language such as C or C++ to executable files

● Executable: binary file that contains machine instructions to be executed on the CPU

● Shell: piece of software that provides an interface to the services of an OS kernel

18

Page 19: Run time environments

SPL/2010SPL/2010

Process Life Cycle - invoke● OS is asked by user to create a process

through a shell● OS identifies which program (=

executable file) is to be executed.

19

Page 20: Run time environments

SPL/2010SPL/2010

Process Life Cycle – new process

● OS creates a new process to run executable: ● process ID unique identifier● process table: maintains information about

running processes● OS allocates memory for new process in

computer's main memory (RAM)● OS loads instructions from program

executable file into main memory20

Page 21: Run time environments

SPL/2010SPL/2010

Process Life Cycle - main● OS identifies starting function in program

(e.g "main" in C and C++) and invokes it (calls the function). ● command line arguments: main function

receives arguments from OS. ● instructions are executed, specified in

program.

21

Page 22: Run time environments

SPL/2010SPL/2010

Process Life Cycle – sys call● Process invokes system call:

printf("Hello"); ● process is interrupted until the OS executes

the service requested. ● process undergoes a context switch.● system call exit() - process is terminated:

– resources (memory, process ID) are freed– entry is removed from process table.

22

Page 23: Run time environments

SPL/2010SPL/2010

Process Life Cycle – summary● Main elements involved when an OS RTE

creates a process

23

Page 24: Run time environments

SPL/2010SPL/2010

OS RTE● OS is an example of basic but complex

RTE:● interface between the user code and the

hardware of the machine hosting● multitasking via “process” abstraction

(collection of variables):– state– current execution point– resources

24

Page 25: Run time environments

SPL/2010SPL/2010

The Java virtual machine (JVM)● JVM is an RTE!● Executes Java classes● Simulates a complete machine for Java

programs execution ● interprets Java byte code and translates

into actions or Operating System calls

25

Page 26: Run time environments

SPL/2010SPL/2010

Interpreter vs. Compiler● byte code: java code compilation into

JVM instructions. ● machine code: C/C++ compilation in

binary code

26

Page 27: Run time environments

SPL/2010SPL/2010

Interpreter vs. Compiler● Compiled languages:

● directly processed on CPU● a compiler+linker translate text program to machine

code● runs faster than interpreted code

● Interpreted languages:● on the fly interpretation into machine code● interpreter is an RTE

– supplies services to program– portability, code is not "standalone“– test on the fly code modifications

27

Page 28: Run time environments

SPL/2010SPL/2010

JVM Bytecode compromise● can be compiled to intermediate language

(bytecode in Java)

28

Page 29: Run time environments

SPL/2010SPL/2010

JVM RTE● JVM simulates a complete machine, on

which Java programs are executed:● byte code: specific JVM instructions● portability: interpreted on any OS with a JVM

29

Page 30: Run time environments

SPL/2010SPL/2010

JVM RTE● JVM is a process inside OS RTE

● intermediate between program and OS RTE● program interacts with JVM using object

oriented paradigm = language interface● system.out - JVM support

for printing

30

Page 31: Run time environments

SPL/2010SPL/2010

Java Program Lifecycle● java byte code compilation: P.java P.class● JVM is invoked: java P.class● load class file and referred classes (through

import) into JVM process main memory● invoke Main with parameters: static

Main(String args[])● program requires a service from the JVM through

System package● System.exit : JVM cleans resources allocated to

program, JVM process is terminated

31

Page 32: Run time environments

SPL/2010SPL/2010

Java program execution (inside JVM RTE inside OS RTE)

● Program service requests from JVM ● JVM translates requests into sys. calls to

OS● JVM can run multiple Java class● OS can run multiple JVM

32

Page 33: Run time environments

SPL/2010SPL/2010

Internet Browser as RTE● browser provides RTE for applets:

● mini-applications that run within a browser● written in Java● interact with Applet Container inside browser

● applet interface - environment and applet interaction :

● load - container● initialize - only once● start/stop – when page becomes visible/invisible● destroyed - container shut down/ no resources

33

Page 34: Run time environments

SPL/2010SPL/2010

Applet lifecycle● applet - visual object for information

display in a window● import java.applet.Applet, import java.awt.Graphics

● Invoking applets from HTML:● <applet code=SPL10Applet.class width=400

height=200>

34

Page 35: Run time environments

SPL/2010SPL/2010

HTTP Web Server as RTE● Model: web server host programs

(servlets), to be run on demand● receive client request

for URL● run servlet● return output to client

35

Page 36: Run time environments

SPL/2010SPL/2010

Java Servlet Container● web server: program that serves content, using

Hypertext Transfer Protocol  (HTTP)● servlets: object used to extend servers to host

applications accessed via a request-response programming model

● javax.servlet / javax.servlet.http packages● processing/storing data submitted by an HTML form● providing dynamic content, e.g. results of database

query● managing state information ,e.g. online shopping cart

36

Page 37: Run time environments

SPL/2010SPL/2010 37

Page 38: Run time environments

SPL/2010SPL/2010

Tomcat Java Servlet Container● Tomcat HTTP server running as process● compiled servlet (Java class)● associate URL to servlet in server● Web client submit requests to server

38

Page 39: Run time environments

SPL/2010SPL/2010

Invoke servlet ● web client connects the HTTP:

http://localhost:8080/servlet1?action=edit● client connects the server at: localhost:8080● HTTP server gets the request: /servlet1?action=edit● HTTP maps request to the servlet1● HTTP server activates servlet, invokes method doGet

with parameter "action=edit" string.● servlet executes code and returns a string● HTTP server passes string to client● client displays the answer on the screen

39

Page 40: Run time environments

SPL/2010SPL/2010

URL - Uniform Resource Location

● standard format to uniquely identify a resource that can be accessed through a protocol.

● format: protocol://[host]:[port][request-path]?[query-string]

● protocol can be http or ftp. ● host and port identify network location where the

server providing access to the resource can be found

● request path uniquely identifies a specific resource among the several resources managed by the server

40

Page 41: Run time environments

SPL/2010SPL/2010

Servlet lifecycle● controlled by the container in which the servlet has

been deployed● a request is mapped to a servlet (URL maps to

servlet in server configuration)● container performs:

● load servlet class, create an instance● initialize servlet instance● listener Class● invoke service method, passing request and response

objects● finalizes servlet by calling destroy method.

41

Page 42: Run time environments

SPL/2010SPL/2010

distributed RTE ‘s

42

Page 43: Run time environments

SPL/2010SPL/2010

Java Enterprise Edition (JEE)● development platform for distributed

component-based applications /servers● application = collection of components that

run on several computers across a network and collaborate (=server)

● components = store data in a database, implement usage policies enforce access rights…

43

Page 44: Run time environments

SPL/2010SPL/2010

Enterprise Java Beans (EJB)● distributed RTE

● server application ● running on several machines on a network● communication through dedicated protocol

● 3 level of abstractions: ● EJB Server is an RTE that runs containers● containers are RTEs, running

components which are the java classes ● server is written in Java, hence

running in the JVM RTE.

44

Page 45: Run time environments

SPL/2010SPL/2010

The EJB server/container services

● Naming server: components are named so that they are found based on their name and not on location, can move from machine to machine without interference, naming server maps abstract names to network addresses

● Messaging server: components send messages to each other. controls messages reach their destination and dispatches messages based on flexible policies.

● Activation: the Application Server determines when each component should run. It can also de-activate a component, permanently (destroy) or temporarily (unload). Application Server manages the state of components.

● Security: the Application Server enforces access rights according to application roles. Each component can specify which users can perform which actions.

● Transactions: a sequence of actions (even across components) behaves as a "unit" transaction - a primitive operation that can either succeed as a whole (commit), or fail as a whole without leaving partial results in any component (full rollback).

● Resource Pooling: the Application Server can "pool" (reuse/share) resources . In this case, whenever a component accesses a resource (e.g., a file, a thread, a database connection), the Application Server must make sure the resource is acquired by the component.

45

Page 46: Run time environments

SPL/2010SPL/2010

Summary● programs we write interact with the environment that executes them

and their behavior is defined by it. ● interface between program and RTE is bi-directional: program

invokes services provided by container. Container can send events or change the state of the process as it is running.

● main responsibilities of an RTE include:● Process management● Storage management (memory, file, dbms)● Communication management● Hardware/Devices management● Security

● different RTEs (OS: Linux/Win32, JVM, applet, servlet -container, distributed RTEs). The structure of the interface remains quite stable.

46