1 / 46

Run time environments

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

hess
Download Presentation

Run time environments

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Run time environments

  2. 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

  3. Topics we will cover סביבת הרצה • What is a runtime environment (RTE)? • Concurrency management in RTE • Memory management in RTE • Communication and networking in RTE • Persistent data management in RTE

  4. 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

  5. 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

  6. 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

  7. 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

  8. /usr/src/linux/fs 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. ENTRY(system_call) pushl %eax # save orig_eax SAVE_ALL GET_CURRENT(%ebx) testb $0x02,tsk_ptrace(%ebx) # PT_TRACESYS jnetracesys cmpl $(NR_syscalls),%eax jaebadsys call *SYMBOL_NAME(sys_call_table)(,%eax,4) movl %eax,EAX(%esp) # save the return value

  9. 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() asmlinkagessize_tsys_read(unsigned intfd, 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; }

  10. Operating System modules

  11. Processes • Main OS abstraction of an execution unit • Instance of a program, which is currently executing.

  12. Process vs. Program • Program = passive collection of instructions • Process = actual execution of instructions • Possibly many simultaneous incarnations of same program, each incarnation = process

  13. Process / OS interaction • Resource allocation: manage computer resources between processes • Main resources : • CPU time • Disk space • Memory • I/O devices • other services (communication, etc…)

  14. 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

  15. 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

  16. 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)

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

  18. 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

  19. 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.

  20. 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 memory

  21. 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.

  22. 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.

  23. Process Life Cycle – summary • Main elements involved when an OS RTE creates a process

  24. 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

  25. 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

  26. Interpreter vs. Compiler • byte code: java code compilation into JVM instructions. • machine code: C/C++ compilation in binary code

  27. 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

  28. JVM Bytecode compromise • can be compiled to intermediate language (bytecode in Java)

  29. 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

  30. 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

  31. Java Program Lifecycle • java byte code compilation: P.javaP.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

  32. 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

  33. 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

  34. 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>

  35. HTTP Web Server as RTE • Model: web server host programs (servlets), to be run on demand • receive client requestfor URL • run servlet • return output to client

  36. 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

  37. 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. 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. URL - Uniform Resource Location • standard format to uniquely identify a resourcethat 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. 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: • loadservlet class, create an instance • initializeservlet instance • listener Class • invoke service method, passing request and response objects • finalizes servlet by calling destroy method.

  41. distributed RTE ‘s

  42. 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. 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, runningcomponents which are the java classes • server is written in Java, hence running in the JVM RTE.

  44. 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. 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.

More Related