CSI402 Systems Programming           Spring 1999
             COURSE LOG

  • Lecture 1 (1/27) Some Course Policies: Prerequisites: CSI310 and CSI333 are critical for success. Incompletes: None will be given except under extenuating circumstances that begin after drop day, and only to people who have Passing: At least one project must earn at least 20% before the midterm, and at least one project must earn at least 20% after the midterm. (Passing means at least a D) Don't plan to get by with just the minimum. Grading: 50% weight for projects, 50% weight for exams. Midterm: will be given in two lecture centers, outside of class time, to be announced. Textbooks, email addresses, office hrs, etc: See course web page. Subject is about (1) Details of how programs, especially multiple source module ones, get compiled, loaded into the computer and execute there. (2) Introduction to programming with system facilities: files, system calls, libraries, etc. (3) Big projects whose specifications combine many features and use details from real industry documents. First view of first project: text based command processor. Runtime information can be passed to already compiled programs via (1) command line arguments and (2) the environment. (1) uses first 2 arguments of main(), (2) uses 3rd argument of main(), or (global variable) char **environ; (or system library functions) Slide showing ragged array data structure, argc, argv, env, and legal environment strings. USER=sdc example What a dictionary is, key, value. How to achieve consistancy of implementing and calling functions of a module, use of header files, preprocessor #include operation, dictionary.c example Separate files for module implementation, interface specification and use. dictionary.c, .h and main.c example introduced.
  • Lecture 2 (1/29) Full Notes. Compilation Steps Diagram. Project1 Part1 assignment handed out. Details of steps performed by compiling a compilation unit. dictionary.h, .c and main.c details. Obtaining type safe function use, avoid calling a function with argument types different from what the function implementation expects. Module implementation, module user and module interface specification How done in C/C++ with files Declarations and definition, signature of a function. What extern means Multiple declarations declaration plus definition in the same compilation unit are OK, see example Definition helps produce memory allocation and address assignment.
  • Lecture 3 (2/1) Design Sketch of the demo program(.ps) 3 Modules: Command interface insert, retrieve. You add delete, dump StringDict module StringDict uses Listof2CharPtrs Design described with modified UML-like diagram showing data structures. StringDict takes care of managing the keys and values as strings. Listof2Ptrs is used by StringDict to manage a list of char pointer pairs. Walk through files main.cc showing StringDict instance and command interface
  • Lecture 4 (2/3) How data members of structs are referenced variable.name name (with the member function invocation associated with this object. this->name (*this).name New ideas about member functions and structures: (1) function to operate on the structure is declared within and thus tightly connected with that structure type. Those functions are called member functions. (2) Every member functions invocation is associated with an instance of the structure that contains the member function. (3) Structure elements (members) may be accessed from within the member function invocation by their (field) name or via the "this" pointer C++ structs ARE classes whose member protections specifiers start with public: (instead of private:) Walk through code with pager demo is C++ code demoC translation into C that uses variables named "this" to illustrate the "this" pointer. Walk through with debugger under EMACS M-x gdm Print value of argv[1] and argv[0] with debugger- see pointer (Hex) value expression plus the string for convenience. Observe calls to initializers.
  • Lecture 5 (2/5) Project 1-Part 2 assigned, due 2/17 .PS .PDF Interactive command loop, scan an indefinite number of tokens, suggest array of char *, pointer variable to it is char **, use strtok initially. Three storage extents of C/C++ Each extent is implemented by a different region in virtual memory. How to specify each extent in C/C++ C/C++ function parameters (except reference) are automatic extent. Pitfalls of automatic variables Local scope (2 different variables with the same name) Uninitialized by default Risk of pointer with illegal address Static extent Dynamically allocated by new, malloc, calloc Importance of only using properly allocated space, cause of "illegal addess" or "bus error" crashes, consequence of using a bad pointer to accessible space (hard to find bugs)
  • Lecture 6 (2/8) Review of 3 storage extents and what extent means. optional extant qualifier "auto" calloc clears allocated space, malloc doesn't Example situations that require static extent: Function call counter. (initialization done once for each allocation operation) Stopwatch facility required in project. Slide Combinations of (name) scopes with variable extents Scopes: What a name is Same identifier name different variables. Local (to function) scope Compilation unit (local symbol) scope Global (global symbol) scope Unfortunate two different meanings for "static" qualifier Optimizing compilers allocate automatic variables to registers Slide Responsibility of program designer to design storage allocation policy. Slide Storage management policies: A "client" is a module that initiates a service request "selfish" (most common) occurs when the module uses an automatic variable examples cin >> buff; times system call required for project. how to read the man page from man -s 2 times "lender" readdir facility use required for project. Slide ------------------------------------------ Reading reference on C extents and scopes: Harbison and Steele: Section 4.3 Storage Class Specifiers
  • Lecture 7 (2/10) Storage management policies for items in current project Policies: Extent (3 kinds) Ownership Owner is the module that reclaims, ie. deletes, destroys, deallocates the storage unit Failure to reclaim dynamic memory causes "memory leakage" (automatic memory causes stack overflow, that is caused by recursions that do not return) See Maguire's Solid Code book for lots of philosophy on storage management Items in project: () StringDict StringDict is revised now in demo-part2: Documentation added to StringDict.h demo.cc now runs delete[] on value string pointer returned by dict.retrieve( ... ) StringDict manages storage for key and value strings all by itself. It never passes ownership away nor takes ownership. key and value strings are copied when they are stored. () command input and tokenization by strtok OK to decompose and insert '\0' in the static extent variable named buffer in the command reader module for project items 1-15 since that processing does not increase the length of each token token strings are not needed after use by each command item 16 DOES require getting new space for quoted tokens because variable substitution can increase the length Example: >>>> import >>>> tokens "$PWD" token[0]: tokens token[1]: /home2/classes/csi402/public_html/pub/LectureMaterial () ls IF you use system("ls") you will lose credit because it is too easy!! See man directory. readdir is a "lender" service. New calls to readdir make the pointers returned by the older calls into garbage () stopwatch Clients of the times() system call are selfish. You must allocate space a for the struct tms and pass a pointer P to this space by calling times(P) This policy is just like cin >> somevar; cin.operator<<( ... ) writes data into your variable somevar State diagram describing the operation of the stopwatch Explanation of stopwatches used in clocked sports (basketball, hocky, football, etc) 2 states ON, OFF How -zero, -on, and -off commands make the states change. Need for persistant (static extent) storage to store stopwatch state and the times counts when the stopwatch was started from 0. () environment See various Unix resources about the environment, and log in to eve, type printenv and see what comes out. Demo slide of using gdb to view types and values of env, *env, **env, env[0], env[1] etc Slide(unspaced) Slide(spaced)
  • Lecture 8 (2/12) Environment applications, environment (ragged array) structure, copying an environment string requires (1) obtaining its length (strlen can be used) (2) allocating space for your copy (requires length+1 bytes) (3) actual copy (strcpy can be used) Lexical Scanning and Table driven programming Ref: Beck 5.1.2 Write program logic by filling in a table rather than by writing statements. Outline for invoking table driven scanner for part2 project: Code simple scan to find beginning of each token. If the token begins with ", use table driven scanner. If not, use say strtok to find the end. "PAC-man" slide. Use of end-of-input or "Tack". Scan step action: 1. Determine the class of the current character 2. Based on scanner's *current state *class of current character ->perform an action ->change state 3. "Gobble" the current character exit when state is an exit state Glimpse at scanner code: classify() enumerated type for states. struct transition represents ONE ARROW coming out of ONE state has 3 components: ch_class, new state, action arrays of transitions state table drawn on blackboard (array of *tranition) (See also notes.txt in the Lecture08 directory)
  • Lecture 9 (2/17) Meanings compared: char A[100]; char *pch="xxx"; char B[]="yyy"; Function pointer explanation and demo program. (1) Declaring function pointer variables. (2) Loading a function pointer value into a function pointer variable (3) Calling the function pointed to by a function pointer variable Quick glimpse at the scanner operation.
  • Lecture 10 (2/19) Details of Scanner Demo design and code. Design Slide (.ps, .pdf ) Public interface: Analysis structure, storage management, specifying scan extent fsa structure: Cursor, state, symbol, buf, extent Basic scanner theory (again) Table representation Scanner loop walkthrough (Scanner.C) compared to theory slide Use of action functions, what they return Use of variable "Mark" to preserve beginning position of a token.
  • Lecture 11 (2/22) Formats must be "exact" for full credit. Internet service protocols specify exact spellings of keywords used in conversations over network connections. email client (pine, elm, mail, browser email) converses with server "RFC"s contains the standards Build steps reviewed, understanding them is important for understanding the problem solved by make and how make works Executing a file, "x" indicator of in ls -l listing Shell script Magic number #! at the beginning of a Unix executable file means run the program named on the first line with standard input this file. Shell script saves typing effort, is like DOS/Win .bat file RCS database required for build.sh as with all other project files. Question on what ci -l means Type safe linkage and mangled names using say strcpy(45,22,96) in a C program is not detected, but in C++, the class of a member function, the name, and the types of arguments are coded in a "mangled" name or symbol
  • Lecture 12 (2/24) Reading for next project: As assigned for part1, assembling, skip relocation for now, Beck chapter 3 on absolute loading (no relocation for now) Patterson and Hennessy, review MIPS processor and assembly language. Overview of project2.
  • Lecture 13 (2/26) Introduction to the cpu component of project2. cpu will use the tester (person) as memory by default, should also accept 512 bytes of MIPS instructions in a file. Basic bus oriented computer architecture, bus errors. Introduction to MIPS instruction interpretation. Hexadecimal and binary. ADDIU instruction interpretationin detail. You can get MIPS instructions from software in ~csi402/usr/bin or from spim (installed in CSC unix cluster) 16 to 32 bit sign extension and 2-s complement arithmetic used in ADDIU instruction, example of why 0xFFFFFFE0 is -32 What overflow means: wrong arithmetic result. 2-s complement overflow is detected by carries out of sign bit and bit next to sign bit being unequal. Year 2000 overflow example. unsigned binary represents only positive or 0 integers.
  • Lecture 14 (3/8) Project 4 Assigned All work (except README files for messages to the TAs) must be submitted as RCS databases in an RCS directory RCS database must include RCS/Makefile,v (produced by ci -l Makefile) For full credit, gmake cpu must generate an executable file named cpu. Review of args of main to provide command line arguments for spec. 1 See Topics in C on ragged arrays if necessary Use of global variables to record options (Question on why main(int argc, char *argv[argc] ) cannot be done in C/C+) State report format for spec. 2,3 see ~csi402/pub/Project2/Messages in particular, demo-MP.C, MP.h slide of demo-MP run Initialization of state for spec. 3 report should print state before the next instruction execute Basic fetch m[PC], execute, set new PC value loop The 5 steps that suffice to execute every MIPS instruction
  • Lecture 15 (3/10) Examples of MIPS instruction interpretation ~csi402/pub/Project2/RISCSimulation/InstrExamples.txt The 5 basic RISC pipeline stages When done in sequence, they suffice for all instruction types ~csi402/pub/Project2/RISCSimulation/soutline.txt Use of mask and shift to extract bit fields Signed and unsigned integers pairs with the same bit patterns can compare oppositely (see sign-types.C)
  • Lecture 16 (3/12) Exam: 1hr, 1sheet of notes. Topics for exam: Concepts and programming techniques from projects Executable program build steps: Preprocess (header files), compile, assemble, link Separate compilations Command line args and environment Dictionaries Member functions of C++ struct, how to access structure instance "for which a member function is called" Declarations versus definitions, undefined symbol linking errors, extern Modules (software design concept) Tools: RCS, gdb Storage extents: what they mean how to specify each pitfalls, dangling pointers Memory management policies steps needed for using dynamic ("new operator") memory pointers ownership Lexical scanning simple scanner design express design in table using C/C++ initializers table loop driver function pointers Accessing and using directories, system time, stopwatch What is overflow MIPS instructions Registers Field extraction (using mask and shifts) Interpreting a few instruction types from examples that will appear in ~csi402/pub/Project2/Tests How to specify signed or unsigned integer comparison in C/C++ How to prepare for the exam: "object for which a member function is called" C++ struct member function review defining an object (instance) allocates memory invoking a member function referring to instance data members in the member function body the "this" pointer; (*this).pnext, this->pnext How to start the project: Explore all of ~csi402/pub/Project2 Messages subdirectory: formats for input and output RISCSimulation subdirectory: Supplemental information Care in use of C types is needed for accurate simulation Integer comparison (<) depends on type (signed or unsigned) of its operands. C++ examples (see Lecture16 directory) C Types: (see C_types_quotes) A type is a set of values and operations. C integers must use binary representation
  • Lecture 17 (3/15) The types of the operands determine what operation the operator symbol does Examples: float, unsigned int, signed int Unsigned ints use straight binary representation Signed int (generally) use 2-s complement binary representation Type of operands determines the kind of comparison done When types are mixed, promotion rules are used to convert to a common type to which the operator can apply. signed int SI; unsigned int UI; if( SI == UI ) { ... } C/C++ rule here: Promote to unsigned! The type of a pointer P determines the operations in expressions with *P long unsigned int *P; if( (*P) < 0 ) { // Never reached, since unsigned values // are never negative } if( static_cast(*P) < 0 ) {// sign bit == 1} P++ increments an ADDRESS by 4, since 4 == sizeof(long unsigned int) Demonstration of byte orderings beginning with the first 4 bytes of an ELF file. Endianness: RULE 1: Memory is Byte Addressable. Model of memory: Array of bytes each byte is 8 bits. Here is BIG ENDIAN, also known as Most Significant Byte byte ordering, also known as Left to Right ordering 0 1 2 3 4 5 . . . . 28 29 2a 2b . . . <- address -------------------------------------------- 1 9 9 5 <- contents Address is 28 1 is the HIGH digit RULE 2: A MULTI-BYTE unit is ALWAYS addressed by the LOWEST NUMBERED BYTE ADDRESS of its bytes. Here is LITTLE ENDIAN, also known as Least Significant Byte byte ordering also known as Right to Left ordering . . . 2b 2a 29 28 . . . . 5 4 3 2 1 0 <- address -------------------------------------------- 1 9 9 5 <- contents Address is 28 5 is the LOW digit RULE 3: Hardware processes data in multibyte units correctly. (X & 0xFF) == low byte (ALWAYS) ((X >> 24) & 0xFF) == high byte (ALWAYS)
  • Lecture 18 (3/17) Midterm Exam
  • Lecture 19 (3/19) More on byte order Delayed branches: what they mean Reason for delayed branches explained in terms of pipelined operation of the processor. Demonstration of opertion of the 5 stage pipeline with slides. Overflow intro
  • Lecture 20 (3/22) Make Reason for the make utility Review of inputs and build operation for the dictionary demo. Rules are basic components of the Makefile Target, Dependencies, Commands are the 3 parts of a rule The (recursive) make algorithm Integer addition/subtraction overflow meaning and detection.
  • Lecture 21 (3/24) Make: Builtin rules Basic memory concepts: Data storage facility Addresses DATA and ADDRESS are conceptually DIFFERENT Unformatted file reading
  • Lecture 23 (3/29) Virtual Memory Pr2 is not a hardware simulator, it is a process simulator Process: one "running" of a program A program is static software, an executable file Processes have resources, which are parts of a virtual (sometimes called abstract) machine (Virtual DOS machines used in Windows95/NT) Each process runs in its own virtual machine instance Different processes do not interfere Multitasking or multiprocessing operating system Hardware CPU is time shared among the processes Scheduler: Part of the operating system that chooses which process is running by the hardware CPU now ps command ps aux displays all processes ps displays just your processes Virtual memory resource contains: data (free-store (new, dynamic), constants. C++ variables) stack (automatic (local) variables, return addresses) use gdb where command to see stack trace code (copied from the executable file when the process is started) CPU resource: registers, PC, ability to fetch and execute instructions, ability to load and store data between registers and virtual memory System Calls: an interface to operating system services
  • Lecture 24 (3/31) Virtual memory support hardware in MIPS (the translation lookaside buffer), explained using diagrams from the MIPS R4000 User Manual.
  • Lecture 25 (4/7) How to simulate virtual memory. Page alignment.
  • Lecture 26 (4/9) Reading and processing an ELF file Symbols defined in some object files and referenced from other object files illustrated with symbol table listings obtained from ELF object and executable files from the StringDict demo project. Symbol table listings Symbols are defined relative to a section. How symbols are listed as undefined. See linking slide Review of mangled symbols used for member functions.
  • Lecture 27 (4/12) Reference to Beck's book sections 3.1 and 3.2 402 object file == Beck's control section 402 section == Beck's "different parts" page 169, problem 16 402 segment == not discussed, should have been in Chapter 6 page: Unit of allocation of physical/virtual memory Relocation and linking.
  • Lecture 28 (4/14) Relocation and linking illustrated with Beck's material in detail. Modification Records. Use of symbol table: defined and undefined symbols.
  • Lecture 29 (4/16) Illustration of ELF object files and their sections linked to form an executable file, then the executable file is used to initialize the processes virtual memory. Linking and Loading slide
  • Lecture 30 (4/19) Description of Project 3 (cooperative dictionary editing) Grading Policies: only RCS databases accepted, Log must record what work you did, we might or might not compile and test submitted programs What a process means Resources: CPU, virtual memory Sometimes "process" refers to the virtual memory only, and it can contain multiple abstract CPUs called threads Interprocess communication using sockets Server is the passive listening process Client performs connect operation Data is passed through the connection by being written by write() by sender and read by read() by the recipient.
  • Lecture 31 (4/21) C++ iostream and C stdio file access functions: ifstream constructor, fopen C++: Myfile << var; Myfile.read(pch,count) C: fread(FILE *, pch, count) Pathnames, current directory in unix cd, pwd commands Absolute and relative pathnames Low level Unix functions open, read File descriptor (int) numbers, handles File descriptor 0 is standard input Blocking reads, discussion for terminal input (read call blocks until ENTER key is pressed) Return value of read: -1 for error, use of errno and perror() 0 for end of file, positive value equals actual number of chars read. Computer Demonstration of ClientServer demo program What happens when a second client is started when the first client is still connected, and when the first client exits.
  • Lecture 32 (4/23) Walkthru of client.C code. socket function return value, errno and perror use. return code of a process returned by exit() A process is usually created by another process called the parent. Parent can receive the return code via the wait() system call The shell is the parent for programs you run The shell can print the return code with echo $? (<-CORRECTED!!) Address family Need for a rendezvous address. AF_UNIX uses file name tree names AF_INET uses IP address/port number pairs 32 bit Internet Protocol Addresses, to become 128 bit IPv6 addresses in the future. connect function socket number (file descriptor) address structure address structure length Address structure details how program fills them write function return value, test of it read function (brief) implicit synchronization with server process.
  • Lecture 33 (4/26) See Lecture33/misc.txt Kochan and Wood good for files, read, write and shells Use netstat -a (and read the man page) to observe sockets Use of netstat -a | grep mysocket grep = "(g)eneral (r)egular (e)xpression (p)arser" Client/Server program operation and interaction timeline. Building the address structure: sockaddr_un and sockaddr types, why and how casting is used.
  • Lecture 34 (4/28) How are the characters written by Process A's write transmitted to Process B's read? The operating system or operating system and networking infrastructure does the job. This question is analogous to asking how the characters you type on the keyboard get to the char array BUFFER in the code char BUFFER[BUFSIZE] cin.getline(BUFFER, BUFSIZE); Flow Control problem in stream connections, Stream connection means the channel does not provide message boundaries Explained It is an example of DEADLOCK, studied in operating systems courses Solutions based on application level protocol Fixed message size Termination sequence, escape sequences, use of scanner Message composed of header and body with the body length coded in the header (used in http) Computer Demo of the Threader program Please read Threader.C code, how to run threader Demonstration of the multiple threads' outputs interfering with each other. Unix Virtual memory layout: Class Slide Images Linking and Loading slide: See Virtual memory at the bottom Code, data, free-store at lower addresses, environment, argv, and stack at higher addresses. Threads: Multiple CPUs running on the SAME virtual memory. Each thread has its own stack region within that one virtual memory space.
  • Lecture 35 (4/30) Threader demo program useage instructions Threader program outline Draw the threads in... Process is ONE virtual memory plus one or more CPU, each CPU runs one thread Each CPU has its own PC and register set Threading is an easy to program and efficient way to make applications work on several tasks concurrently (to be defined) Dictionary server that server many simultaneous client is an example Client and Server terminology Server is started ahead of time, waits for "passive opening" of connections Client initiates an connection, it performs an "active open" Diagram of non-threaded server and client Diagram of threaded server Diagram of single process memory used by multiple threads Separate threads have separate stacks.
  • Lecture 36 (5/3) Using threads #include g++ -g -c -D_REENTRANT threaded.C g++ -o executablename threaded.o -lpthread DO NOT USE STRTOK or other thread unsafe functions!! USE ONLY automatic (i.e.,stack) or free-store ("new or malloc") memory for variables you want private to one thread pthread_t pthread_create( , , pf, (void *) argument) pthread_self pthread_detach( myid ) exit() kills the whole precess, pthread_exit or return from (*pf)(..) terminates the thread executing it How Virtual memory is used for threads Reentrant procedures. Do not use static variables, so independently called activations of the procedure do not interfere. Using mutexs Allocation and initialization: pthread_mutex_t mp; or pmp = new( pthread_mutex_t ); pthread_mutex_init(&mp, NULL); or pthread_mutex_init(pmp, NULL); Allocation and initialization are done only once! pthread_mutex_lock( &mp ); or pthread_mutex_lock( pmp ); BLOCKS current thread if mutex mp is locked Returns when some other thread unlocks mp. //put the code to use protected data structures here pthread_mutex_unlock(&mp);
  • Lecture 37 (5/5) Demonstration of stepping through server and client programs with gdb debugger in separate windows, Where each process blocks View process and socket tables with ps -la and netstat -a Concurrency: Multiple computations for which the time order among the instructions of the different computations is unpredictable. (True) parallelism: Multiple computations that are really done at the same time. Scheduler: Part of the operating system that chooses which thread or process to run now.
  • Lecture 38 (5/7) Concurrency and parallelism definitions. Time sharing. System runs scheduler to decide what process or thread to run next every time the CPU is interrupted by a clock tick Clock ticks are generated by a timer clock, typical tick period is 1/100 second Processor modes: user and system (priviliged) System instructions cause exceptions when processor is in system mode. Examples of system instructions: Instructions to change virtual memory mappings syscall instructions Instructions to change processor mode Exception action: 1. Make mode become priviliged 2. Save PC in a fixed place 3. PC = fixed value (should be address of kernel's interrupt processing routine) 4. Set register bit so software can determine exception's cause Causes: Timer (Operating system runs the scheduler) Scheduler decides chooses which process/thread to run now syscall instruction used to call for operating system services Examples: open, read, write, socket, fork, exec, exit Counting Semaphores Used to control concurrent access to resources used in producer-consumer situations Model: Shared "toybox" wait(S) [aka P(s), down(S), TAKE(S)] {block until S > 0, then S=S-1} (sleep until at least one toy appears, then take it) signal(S) [aka V(S), up(S) GIVE(S)] {S=S+1; alert other processes to check S} (put a toy in the box)
  • Lecture 39 (5/10) Java Compile once, execute everywhere sam.java (source file), sam.class (object file), javac Java Virtual Machine Language Specification From www.javasoft.com Running java programs java (application runner) Web browser, applet viewer (applet) Fully qualified class names Java design goals Small (static) program size .class file contains "bytecodes" Stack oriented machine language Demo of disassembled sample program Sample Dynamic Linking Classes can be loaded via the Internet Security try to run untrusted applets "safely" Units of Modularization Package (hierarchical package name, eg EDU.albany.csi402.java. Class (like C++ classes) Fully qualified class name is package name.class-name Virtual functions (as in C++) An instance of a class with no virtual functions only has data members. An instance of a class with virtual functions (has in addition to any data members) a pointer to a virtual function table class wide contains function pointers to bodies of functions Different function bodies can be called for different instances. All Java functions are virtual
  • Lecture 40 (5/12) Exam Topics: Java Intro, Java versus C++ Concurrency, scheduler, mutexs, threads, processes System calls, what operating systems do, timesharing/multitasking Client-Server applications using socket interface, read/write functions Application message protocols Assembling, relocation, linking, symbol tables Beck sections 2.1 and 2.2 Beck section 3.2, Beck problem 16 of section 3.2 (on sections) Applications of dictionaries Virtual Memory: Address Translation, page alignment Reading and interpreting an "unformatted" or "binary" such as ELF Decoding and executing MIPS instructions, MIPS memory references, delayed branches, intro to pipelining C++ storage extents, use of the stack, free-store, data segment, pointers and strings Unix technicalities PATH environment variable, absolute and relative pathnames process list (ps command), socket list (netstat command) job control (background, foreground, C-Z, C-C) Make algorithm Arithmetic: Overflow, sign extension, big and little endian Java continued Java class one structure type, could be empty some INSTANCE functions some CLASS functions some CLASS variables or constants Every function must belong to a class Class sources compiled into .class files loaded and executed by Java Virtual Machine (JVM) JVM Language "byte coded" stack oriented, small code size JVM storage areas Threads Each thread has a PC and stack of frames Each frame has local vars and an operand stack Heap Stores instances, like C/C++ free store Method Area Stores classes, like the code segment Java types of variables Primative: byte, short, char, int, long, float, double Standardized Reference: null or point to a class instance C/C++, not Java have object (structure) variables C/C++ = does copying of structures, copy operator can be customized by the programmer, is complicated Java, not C++, StringDict MyDict = new StringDict(..); Reference assignment copies pointers, not objects. Every non-primative is a pointer; the word pointer is eliminated No "delete/free" operation; the heap is garbage collected How an object reference is implemented in Sun's implementation Handle, virtual function table, pointer to object data in heap The invokevirtual instruction and how it calls a function Caller has complete symbolic information about the function called A reference to the instance FOR WHICH the function is called should be in the stack and is passed to the called function. Called Classes can be resolved in different ways by ClassLoaders, including retrieval on the Internet.