6/3/2016IT 3271 WhatHow A system (environment) for programmers to develops their programs in a certain programming language on a certain machine Chapter.

Slides:



Advertisements
Similar presentations
Chapt.2 Machine Architecture Impact of languages –Support – faster, more secure Primitive Operations –e.g. nested subroutine calls »Subroutines implemented.
Advertisements

Agenda Definitions Evolution of Programming Languages and Personal Computers The C Language.
The Assembly Language Level
Lecture 1: Overview of Computers & Programming
SYSTEM PROGRAMMING & SYSTEM ADMINISTRATION
Chapter FourModern Programming Languages1 Language Systems.
1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
Systems Software.
Language Systems Chapter FourModern Programming Languages, 2nd ed.1.
CSCE 145: Algorithmic Design I Chapter 1 Intro to Computers and Java Muhammad Nazmus Sakib.
Lab Information Security Using Java (Review) Lab#0 Omaima Al-Matrafi.
Lab#1 (14/3/1431h) Introduction To java programming cs425
Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.
Software Language Levels Machine Language (Binary) Assembly Language –Assembler converts Assembly into machine High Level Languages (C, Perl, Shell)
1 Lecture 1  Getting ready to program  Hardware Model  Software Model  Programming Languages  The C Language  Software Engineering  Programming.
Memory Management 2010.
JVM-1 Introduction to Java Virtual Machine. JVM-2 Outline Java Language, Java Virtual Machine and Java Platform Organization of Java Virtual Machine Garbage.
Programming Languages Structure
Chapter 2: Impact of Machine Architectures What is the Relationship Between Programs, Programming Languages, and Computers.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 1, Lab.
Chapter 10 Application Development. Chapter Goals Describe the application development process and the role of methodologies, models and tools Compare.
Chapter 3 Software Two major types of software
COP4020 Programming Languages
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
1 Chapter-01 Introduction to Computers and C++ Programming.
Introduction to High-Level Language Programming
Chapter 17 Programming Tools The Architecture of Computer Hardware and Systems Software: An Information Technology Approach 3rd Edition, Irv Englander.
“C” Programming Language What is language ? Language is medium of communication. If two persons want to communicate with each other, they have to use.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Language Systems Chapter FourModern Programming Languages 1.
CS 355 – Programming Languages
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
High level & Low level language High level programming languages are more structured, are closer to spoken language and are more intuitive than low level.
An intro to programming. The purpose of writing a program is to solve a problem or take advantage of an opportunity Consists of multiple steps:  Understanding.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
1 Comp 104: Operating Systems Concepts Java Development and Run-Time Store Organisation.
1.8History of Java Java –Based on C and C++ –Originally developed in early 1991 for intelligent consumer electronic devices Market did not develop, project.
Copyright © 2007 Addison-Wesley. All rights reserved.1-1 Reasons for Studying Concepts of Programming Languages Increased ability to express ideas Improved.
Lecture 8 February 29, Topics Questions about Exercise 4, due Thursday? Object Based Programming (Chapter 8) –Basic Principles –Methods –Fields.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
LANGUAGE SYSTEMS Chapter Four Modern Programming Languages 1.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
1 The Evolution of Major Programming Languages Different Languages Characteristics.
Introduction to OOP CPS235: Introduction.
Lesson 1 1 LESSON 1 l Background information l Introduction to Java Introduction and a Taste of Java.
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Hello world !!! ASCII representation of hello.c.
OCR A Level F453: The function and purpose of translators Translators a. describe the need for, and use of, translators to convert source code.
Programming 2 Intro to Java Machine code Assembly languages Fortran Basic Pascal Scheme CC++ Java LISP Smalltalk Smalltalk-80.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Operating Systems A Biswas, Dept. of Information Technology.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Introduction to Algorithm. What is Algorithm? an algorithm is any well-defined computational procedure that takes some value, or set of values, as input.
Chapter Goals Describe the application development process and the role of methodologies, models, and tools Compare and contrast programming language generations.
Evolution and History of Programming Languages
Lecture 3 Translation.
Visit for more Learning Resources
Programming languages
CSCI-235 Micro-Computer Applications
Compiler Construction (CS-636)
CSCI/CMPE 3334 Systems Programming
Accomplishing Executables
CMP 131 Introduction to Computer Programming
Java Programming Introduction
Programming language translators
Presentation transcript:

6/3/2016IT 3271 WhatHow A system (environment) for programmers to develops their programs in a certain programming language on a certain machine Chapter 4 Programming Language Systems

6/3/2016IT 3272 In this chapter: n The classical sequence n Variations on the classical sequence n Binding times n Debuggers n Runtime support

6/3/2016IT 3273 IDE The Classical Sequence n Integrated Development Environments Here or there n Old-fashioned, un-integrated systems: Step by step

6/3/2016IT 3274 The Classical Sequence editor source code compiler assembly code assembler object code linker machine code loader running in main memory

6/3/2016IT 3275 Creating, Editing a program n The programmer uses an editor to create a text file containing the program in a high-level language: machine independent n A C-like program set: int i; void main() { for (i=1; i<=100; i++) fred(i); } fred:void (a:int){ i:int;... }

6/3/2016IT 3276 Compiling  assembly n Compiler translates to assembly language 1.Machine-specific 2.Each line represents either a piece of data, or a single machine-level instruction 3.Programs used to be written directly in assembly language, before Fortran (1957) 4.Now used directly only when the compiler does not do what you want, which is rare Assembly language

6/3/2016IT 3277 int i; void main() { for (i=1;i<=100;i++) fred(i); } i: data word 0 main: move 1 to i t1: compare i with 100 jump to t2 if greater push i call fred add 1 to i go to t1 t2: return i: data word 0 a: data word 0 fred: t1: return fred:void (a:int){ i:int;... } Compiler A Compiler B

6/3/2016IT cmp %o0, 100 ble.LL5 nop b.LL3.....LL5: sethi %hi(i), %o0 or %o0, %lo(i), %o0 ld [%o0], %o0 call fred, 0 nop sethi %hi(i), %o0 or %o0, %lo(i), %o1 sethi %hi(i), %o0 or %o0, %lo(i), %o0 ld [%o0], %o0 add %o0, 1, %o0 st %o0, [%o1] b.LL2... Sun

6/3/2016IT 3279 Assembling  object code n Assembly language is still not directly executable – Still text format, readable by human – Still has names, not memory addresses n Assembler converts each assembly-language instruction into machine language n Resulting object file not readable by human (machine codes and data in binary presentations)

6/3/2016IT assembly assembler objective code i: data word 0 a: data word 0 fred: t1: return i: data word 0 main: move 1 to i t1: compare i with 100 jump to t2 if greater push i call fred add 1 to i go to t1 t2: return assembler i: a: 0 0 ¥ i  fred: a  $ i  *  a ¥ $ Lib. obj Prg. obj

6/3/2016IT Linking  executable file n Object file still not directly executable – Missing some parts – Still has some names – Mostly machine language, but not entirely fred was compiled separately (maybe in a different high- level language) n Linker collects and combines all parts into an executable file

6/3/2016IT linker i: a: 0 0 ¥ i  fred: a  $ i  *  a ¥ $ j: a: 0 0 XXXX. exe Lib. obj Prg. obj

6/3/2016IT Loading n “Executable” file still not directly executable to the CPU – Still has some names – Mostly machine language, but not entirely n Final step: when the program is run, the loader loads it into memory and replaces names with addresses

6/3/2016IT loader Memory manager

6/3/2016IT Load into the Memory n In the previous slide we assume a very simple kind of memory architecture (without paging, virtual memory…) n Memory organized as an array of bytes (words) n Index of each byte in this array is its address n Before loading, language system does not know where in this array the program will be placed n Loader finds an address for every piece and replaces names with addresses Memory manager (an important part of the OS)

6/3/2016IT Running n After loading, the program is in machine language entirely – All names have been replaced with memory addresses n Processor begins executing its instructions, and the program runs ( under the control of OS)

6/3/2016IT About Optimization n Code generated by a compiler is usually optimized to make it faster, smaller, or both n Other optimizations may be done by the assembler, linker, and/or loader n The resulting code is not guaranteed to be optimal Compiler researchers have been trying to do those for more that 40 years; some good results, some difficulties remains.

6/3/2016IT A Trivial Example int i = 0; while (i < 100) { a[i++] = x*x*x; } int temp = x*x*x; int i = 0; while (i < 100) { a[i++] = temp; } Improved code, with loop invariant moved:

6/3/2016IT Another Trivial Example int i = 0; while (i < 100) { int y = x; y = y*y; y = y*y; a[i++] = y; } int y = x; y = y*y; y = y*y; int i = 0; while (i < 100) { a[i++] = y; } Improved code, with loop invariant moved: LIR (Loop Invariant Removal), add/remove variables, add/remove around code, parallelizing, piping, paging…..etc. hoisting

6/3/2016IT n Loop invariant removal is handled by most compilers n That is, most compilers generate the same efficient code from both of the previous examples n So it is a waste of the programmer’s time to make the transformation manually (Good luck!) This is somehow true that:

6/3/2016IT Optimizations done by compilers n All make the connection between source code and object code more complicated Thus, the question “What assembly language code was generated for this statement?” is somehow difficult to answer.

6/3/2016IT Variation: Hiding The Steps n Many language systems make it possible to do the compile-assemble-link part with one command Example: gcc command on a Unix system: gcc main.c gcc main.c –S as main.s –o main.o ld … Compile, then assemble, then link Compile-assemble-link It generates object code directly

6/3/2016IT Integrated Development Environments n A single interface for editing, running and debugging programs n Integration can add power at every step: – Editor knows language syntax – System may keep a database of source code (not individual text files) and object code – System may maintain versions, coordinate collaboration – Rebuilding after incremental changes can be coordinated, like Unix make but language-specific – Debuggers can benefit (more on this in a minute…)

6/3/2016IT Variation: Interpreters n To interpret a program is to carry out the steps it specifies, without first translating into a lower-level language n Interpreters are usually much slower – Compiling takes more time up front, but program runs at hardware speed – Interpreting starts right away, but each step must be processed in software

6/3/2016IT Virtual Machines n A language system can produce code in a machine language for which there is no real hardware: an intermediate code n Virtual machine must be simulated in software – interpreted, in fact n Language system may do the whole classical sequence, but then interpret the resulting intermediate-code program

6/3/2016IT Why Virtual Machines n Cross-platform – Virtual machine can be implemented in software on many different platforms – Simulating physical machines is harder n Security – The running program is never directly in charge – Interpreter can intervene if the program tries to do something it shouldn’t

6/3/2016IT The Java Virtual Machine n Java languages systems usually compile to code for a virtual machine: the JVM n JVM language is sometimes called bytecode n Bytecode interpreter is a part of almost every Web browser n When you browse a page that contains a Java applet, the browser runs the applet by interpreting its bytecode

6/3/2016IT Delayed Linking n Delay linking, a linked “executable program” does not have every thing and is not ready to go. n Code for library functions is not included in the executable program

6/3/2016IT Delayed Linking: Windows Libraries of functions for delayed linking are stored in.dll files: dynamic-link library n Two flavors – Load-time dynamic linking Loader finds.dll files (which may already be in memory) and links the program to functions it needs, just before running – Run-time dynamic linking Running program makes explicit system calls to find.dll files and load specific functions

6/3/2016IT Delayed Linking: Unix Libraries of functions for delayed linking are stored in.so files: shared object Suffix.so followed by version number n Two flavors (similar to dll) – Shared libraries n Loader links the program to functions it needs before running – Dynamically loaded libraries n Running program makes explicit system calls to find library files and load specific functions

6/3/2016IT Delayed Linking: Java n JVM automatically loads and links classes when a program uses them n Class loader does a lot of work: – May load across Internet – Thoroughly checks loaded code to make sure it complies with JVM requirements

6/3/2016IT Delayed Linking Advantages n Sharing: programs can share a copy of library functions: one copy on disk and in memory n Consistency: library can be updated independently of programs. n Less redundancy: avoid loading code that is never used

6/3/2016IT Profiling (advanced optimization) n Compile, run, compile, run, compile… n Collects statistics while the program is running: most frequently executed parts n If necessary, re-compile the program using this information for better code

6/3/2016IT Dynamic Compilation n This is know as Just-in-time (JIT) compilation. Some examples: – Compile each function only when called – Using interpreter at first, then compile only those pieces that are called frequently – Compile using less expensive technique first (e.g. without optimization; then switch to more complicated compiler on frequently executed pieces.

6/3/2016IT Binding n Binding means associating two things together. In programming language: properties  identifiers n Languages are characterized by its binding times (not its syntax) E.g. int i; void main() { for (i=1;i<=100;i++) fred(i); } Some meaningful questions are: 1.What set of values is associated with int ? 2.What is the type of fred ? 3.What is the address of the object code for fred ? i.e., where? 4.What is the value of i ? And when?

6/3/2016IT Binding Times n Different bindings take place at different times n Some are related to the classical sequence: – Language definition time – Language implementation time (i.e., implement a compiler for it) – Compile time – Link time – Load time – Runtime

6/3/2016IT Language definition time: Meanings of keywords: void, for, …etc. Language implementation time Binding is determined at: – range of values of type int in C (but in Java, these are part of the language definition) – implementation limitations: max identifier length, max number of array dimensions, etc

6/3/2016IT – Types of variables, (C and ML that use static typing) – The activate space for a declared variable (static scoping, most languages) Binding is determined at: Compile time Link time Object code for external function names int i; void main() { for (i=1;i<=100;i++) fred(i); }

6/3/2016IT Binding is determined at: Load time Run time – Memory locations for code for functions – Memory locations for static variables – Values of variables – Types of variables (Lisp uses dynamic typing) – The activate space for a declared variable (dynamic scoping) Also called late or dynamic binding (everything before run time is consider early or static)

6/3/2016IT Debugging Features n Examine a snapshot, such as a core dump n Examine a running program – Single stepping, breakpointing, modifying variables n Modify currently running program – Recompile, relink, reload parts while program runs n Advanced debugging features require an integrated development environment

6/3/2016IT Debugging Information n Where is it executing? n What is the traceback of calls leading there? n What are the values of variables? n machine-level code  source-level information – Variables and functions by name – Code locations by source position – Connection between levels can be hard to maintain, for example, because of optimization

6/3/2016IT Runtime Support -- An important hidden player in language systems n Additional code the linker includes but the program does not refer to it explicitly – Startup processing: initializing the machine state – Exception handling: reacting to exceptions – Memory management: allocating memory, reusing it when the program is finished with it – Operating system interface: communicating between running program and operating system for I/O, etc.

6/3/2016IT Conclusion More implementation issues: – Chapter 12: memory locations for variables – Chapter 14: memory management – Chapter 18: parameters – Chapter 21: cost models

6/3/2016IT SML/NJ Standard ML of New JerseyStandard ML of New Jersey (abbreviated SML/NJ) is a compiler for the Standard ML '97 programming language with associated libraries, tools, and documentation. SML/NJ is free, open source software. Standard ML '97free, open source Install SML/NJ on your computer as soon as possible