- 快召唤伙伴们来围观吧
- 微博 QQ QQ空间 贴吧
- 文档嵌入链接
- 复制
- 微信扫一扫分享
- 已成功复制到剪贴板
运行时的管理
展开查看详情
1 .Chap 7: Runtime Organization Prof. Steven A. Demurjian Computer Science & Engineering Department The University of Connecticut 371 Fairfield Way, Unit 2155 Storrs, CT 06269-3155 steve@engr.uconn.edu http://www.engr.uconn.edu/~steve (860) 486 - 4818 Material for course thanks to: Laurent Michel Aggelos Kiayias Robert LeBarre
2 .Overview Runtime Environment Focuses on the wayt hat a Program is Managed/Controlled During its Execution We’ll Focus on Basic Definitions and Concepts A First Look at Activation Records Memory Allocation Strategies Revisiting Activation Records Impact of Parameter Passing Mechanisms Data Layout and Scoping of Declarations Memory Manager and Compilation Process Concluding Remarks/Looking Ahead
3 .Basic Definitions and Concepts Procedure Definition Declaration that has a Name and has a Body If Returns a value, then Function Procedure Definition Contains a Sequence of Identifiers Called the Formal Parameters Procedure Call Contains a List of Arguments passed to the Procedure or the Actual Parameters Information in Program can be Characterized Environment: Maps Name to Storage Loc (l-value) Store: Maps Location to Value it Contains (l-value to an r-value) Environment State Name Storage Value Compile Time Run Time
4 .Program Organization Purpose Define what constitutes a Program Review overall OS Structure Examine Process Structure Present and Understand Memory Management issues Remember, a Compiler Must: Target a Specific Operating System Interact within that Operating System Provide Access at Machine Level to Operating System Components
5 .The Basic Abstractions Processes Unit of Computation Program/Application Composed of One or More Interacting Processes Processes Interact with and Utilize Resources Files Unit of Information Storage Classic, Default Utilized to Support Programs Read, Write, and Transfer via Files Other Resources CPU, Printer, Memory, etc. Network, Display, etc.
6 .Program, Processes & Resources Processes Resources CPU Memory Device Device Device Device Operating System Hardware Data Program
7 .What are Executables? Executable File Containing Machine Code Examples A bash script, a perl script, a ‘compiled’ java program, a compiled C program, ... Java Bytecode and JVM
8 .Java Virtual Machine (JVM) JVM is a Platform Specific Program which Interprets and Executes Java Code JVM Interprets and Executes Bytecodes JVM Targeted as Small/Efficient - Embeddable within Consumer Electronics JVM Stack Based Machine - Simulates Real Processor CA FE BA BE 00 03 00 2D 00 3E 08 00 3B 08 00 01 08 00 20 08
9 .Java Visualization
10 .What are Executables? Native Executable File Containing Machine Code that the CPU understands without any intervening “layers” of abstractions Examples A compiled C program A Java program compiled natively with Gnu Compiler for Java
11 .From Code to Loaded Program ORIGINAL SOURCE static int gVar; . . . int proc_a (int arg){ . . . gVar = 7; put_record(gVar); . . . } RELOCATABLE OBJECT MODULE 0000 . . . . . . 0008 entry proc_a . . . 0036 [Space for gVar] . . . 0220 load =7, R1 0224 store R1, 0036 0228 push 0036 0232 call ‘put_record’ . . . 0400 External Reference Table 0404 ‘put_record’ 0232 . . . 0500 External Definition Table 0540 ‘proc_a’ 0008 0600 (optional symbol table) 0799 (last location in module)
12 .From Code to Loaded Program THE ABSOLUTE PROGRAM 0000 (Other Modules) . . . 1008 entry proc_a . . . 1036 [Space for gVar] . . . 1220 load =7, R1 1224 store R1, 1036 1228 push 1036 1232 call 2334 1399 (end of proc_a) . . . (Other Modules) 2334 entry put_record . . . 2670 (opt. symbol table) 2999 (last loc. in module) PROGRAM AT LOCATION 4000 0000 (Other Processes) 4000 (Other Modules) . . . 5008 entry proc_a . . . 5036 [Space for gVar] . . . 5220 load =7, R1 5224 store R1, 5036 5228 push 5036 5232 call 6334 5399 (end of proc_a) . . . (Other Modules) 6334 entry put_record . . . 6670 (opt. symbol table) 6999 (last loc. in module) 7000 (Other Processes)
13 .What is a Process? An Executable with its Execution Context and State Consists of: Executable (.exe, a.out, etc.) Loaded into main memory All of the resources currently committed With the value of all the CPU registers Computers can Run Multiple Processes at Same Time
14 .What is a Process? Sequential Program for Execution Object Program (a.out) to Execute Data on Which Program will Execute Resources Required During Execution Status of the Process’ Execution (ps -aux) Program is “Static Source Code/Executable Statements” which Lacks Data Set Process is “Dynamic Entity Executing on Actual Data Set” For Example, Multiple Unix Users Can Execute emacs, Latex, vi, grep, at same Time Shared Program Executable emacs Dedicated Process for Each User of emacs
15 .A Process Abstract Machine Environment (OS) Code Data Process Status Resources Resources Resources
16 .UNIX Process Text Process Status Resources Resources File UNIX kernel Stack Data File
17 .More on UNIX Processes Each Process Has its Own Address Space Subdivided into Text, Data, & Stack Segment a.Out File Describes the Address Space OS Creates Descriptor to Manage Process Process Identifier (PID) is Integer: User Handle for the Process (Descriptor) Try “ ps ” and “ Ps aux ” (Read Man Page) USER PID %CPU %MEM SZ RSS TT S START TIME COMMAND wangz 25150 26.1 15.33048019308 pts/16 O Aug 05 6318:26 /apps/matlab/bin/s manish 7590 25.1 0.821436 964 ? O Jul 22 24628:34 /apps/matlab/bin/s marios 29536 0.6 3.5 5156 4376 pts/6 S 13:22:23 0:24 mailtool steve 29893 0.2 0.8 1080 980 pts/18 S 17:41:11 0:00 -csh root 29905 0.2 0.7 1040 888 pts/18 O 17:41:53 0:00 ps -aux
18 .Multiprogramming Load and Execute Multiple Programs into Space-Multiplexed Mem. while Time-Multiplexing CPU Technique for Sharing the CPU Among Runnable Processes Process May Be Blocked on I/O What is Deadlock and How can it Occur? Process May Be Blocked Waiting for Other Resources to Complete What is Starvation and How is it Prevented? While One Process is Blocked, Another Should Be Able to Run Multiprogramming OS Accomplishes CPU Sharing “Automatically”
19 .How Multiprogramming Works CPU Process 1 Process 2 Process 3 Process 4 Space-Multiplexed Memory Time-Multiplexed
20 .Batch Processing Uses Multiprogramming Job (File of OS Commands) Prepared Offline Batch of Jobs Given to OS at One Time OS Processes Jobs One-After-the-Other No Human-Computer Interaction OS Optimizes Resource Utilization Batch Processing (as an Option) Still Used Today Batch Files in DOS/Unix to Repetitively Execute Same Set of Commands ASIDE: Using Batch Processing 1978/79 First Two Computer Courses at BC Keypunch IBM Cards Run Batch Job: Return 1-2hrs Later for Output
21 .Timesharing Uses Multiprogramming Support Interactive Computing Model (Illusion of Multiple Consoles) Different Scheduling & Memory Allocation Strategies Than Batch Tends to Propagate Processes Considerable Attention to Resource Isolation (Security & Protection) Tend to Optimize Response Time
22 .How Timesharing Works Timesharing OS VM VM VM Terminal Multiplexor Timesharing Still Pervasive in Computing Engineering Network Still Time-Shared in Some Respects Access to User Files Email/Web Server Download Software Terminals Replaced by Unix Workstations and PCs Example of Network File System/OS
23 .Personal Computers CPU Sharing Among One Person’s Processes Ability of Only One Active Process at One Time Early Apple/Mac: Only do 1 Action at Time Same for Win 3.1 and Win 95 Improved with Win 98 and NT Today’s Apple and Windows MS – Multi-Process! Increased Power of Computing for Personal Tasks Graphics - Two-D, Three-D, Real-Time Multimedia - CDs and DVDs
24 .Process Control & Real-Time Computer is Dedicated to a Single Purpose Classic Embedded System Must Respond to External Stimuli in Fixed Time Continuous Media Popularizing Real-time Techniques An Area of Growing Interest Embedded Computing Estimated as one of Key Technologies for 21st Century Pervasiveness: Consumer Products/Electronics Cars, Refrigerators, Phones, Microwaves, etc. Elevators, “Smart” Products and Buildings, etc. Embedded Java Microsoft CE
25 .Evolution of Modern OS Modern OS Batch Timesharing PC & Wkstation Network OS Real-Time Memory Mgmt Protection Scheduling Files Devices Memory Mgmt Protection Scheduling System Software Human- Computer Interface Client-Server Model Protocols Scheduling Java/JINI/JavaOS
26 .Virtual Address Space An Abstraction provided by the Operating System Essentially A sandbox for the process Practically A Contiguous Memory area that Starts at offset 0 Ends at offset 232-1 Entirely devoted to a single process Is transparently managed by the O.S. Has a layout imposed by the O.S.
27 .Virtual Memory Components of Program (Identifiers, Labels, variables, etc.) Define Name Space Language Translation Converts Name Space Elements to Virtual Addresses Binds Symbolic Names to Virtual Addresses Virtual Memory System Dynamically Binds Virtual Addresses to Physical Addresses Defers Binding Decision to During Program Execution Perform Binding “As Needed”
28 .Names, Virtual Addresses, Physical Addresses Source Program Absolute Module Executable Image Name Space Physical Address Space Virtual Address Space Y t : Virtual Address Space Physical Address Space {} Compile and Link Tools Distinguish Between Symbolic Names vs. Virtual Addrs. vs. Physical Addrs.
29 .Virtual Address Space Traditional Organization Code Area at the bottom Static Data above Constants Static strings Static variables Heap Grows upward Stack Grows downward Lot’s of free VM in between 0x0 0xffffffff