Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with this 3 questions 1.Explain how a Java program is taken from sou

ID: 3790459 • Letter: I

Question

I need help with this 3 questions

1.Explain how a Java program is taken from source code and run on a machine. How translation, virtual machines and interpretation come into play?
Do the same for an assembly language, C and Python Program.

2.For each of the following choose mainframe or COTS

Ease of maintenance

Backward compatibility

Cost

3.For each of the following choose RISC or CISC

Cost per MIP

Backward compability

Supports many instructions

Supplies more registers

Common in embedded systems

Please help this assignment is due soon

Explanation / Answer

Java:

A source code is a program in a human-readable format, and a program called a compiler translates it to a binary format called executable code that the computer can understand and execute. The executable code is machine dependent. In Java, one important difference is , it allows us to write Java programs that are machine independent.
Using an interpreter, all Java programs are compiled to an intermediate level called byte code. We can run the compiled byte code on any computer with the Java runtime environment installed on it.
The runtime environment consists of a virtual machine and its supporting code.

Java Virtual MAchine(JVM):

Java Virtual Machine exists only in the memory of our computer. It acts as the intermediary between the Virtual Machine and our real machine.

The Java Virtual Machine is responsible for interpreting Java byte code and translating this into actions or Operating System calls.

Basic parts of JVM:

   •   A set of registers
   •   A stack
   •   An execution environment
   •   A garbage-collected heap
   •   A constant pool
   •   A method storage area
   •   An instruction set


The registers of the Java Virtual Machine are similar to the registers in our computer. However, because the Virtual Machine is stack based, its registers are not used for passing or receiving arguments. In Java, registers hold the machine's state, and are updated after each line of byte code is executed, to maintain that state.
All these registers are 32 bits wide, and are allocated immediately. This is possible because the compiler knows the size of the local variables and the operand stack, and because the interpreter knows the size of the execution environment.

The Java Virtual Machine uses an operand stack to supply parameters to methods and operations, and to receive results back from them. All byte code instructions take operands from the stack, operate on them, and return results to the stack. Like registers in the Virtual Machine, the operand stack is 32 bits wide.
The operand stack follows the last-in first-out (LIFO) methodology.
Each method in our Java program has a stack frame associated with it. The stack frame holds the state of the method with three sets of data: the method's local variables, the method's execution environment, and the method's operand stack.
Because the Java stack is 32 bits wide, 64-bit numbers are not guaranteed to be 64-bit aligned.

Execution Environment:

The execution environment is maintained within the stack as a data set, and is used to handle dynamic linking, normal method returns, and exception generation. To handle dynamic linking, the execution environment contains symbolic references to methods and variables for the current method and current class. These symbolic calls are translated into actual method calls through dynamic linking to a symbol table.
Whenever a method completes normally, a value is returned to the calling method. The execution environment handles normal method returns by restoring the registers of the caller and incrementing the program counter of the caller to skip the method call instruction. Execution of the program then continues in the calling method's execution environment.
If execution of the current method completes normally, a value is returned to the calling method. This occurs when the calling method executes a return instruction appropriate to the return type.
If the calling method executes a return instruction that is not appropriate to the return type, the method throws an exception or an error. Errors that can occur include dynamic linkage failure, such as a failure to find a class file, or runtime errors, such as a reference outside the bounds of an array. When errors occur, the execution environment generates an exception.


Garbage Collection:

Each program running in the Java runtime environment has a garbage-collected heap assigned to it.
To ensure that the heap does not get too large, objects that are no longer in use are automatically deallocated or garbage-collected by the Java Virtual Machine.
Java performs automatic garbage collection as a background thread. Each thread running in the Java runtime environment has two stacks associated with it: the first stack is used for Java code; the second is used for C code. Memory used by these stacks is drawn from the total system memory pool. Whenever a new thread starts execution, it is assigned a maximum stack size for the Java code and for the C code.
If our system has memory limitations, we can force Java to perform more aggressive cleanup and thus reduce the total amount of memory used. To do this, reduce the maximum size of the Java and C code stacks. If our system has lots of memory, we can force Java to perform less aggressive cleanup, thus reducing the amount of background processing. To do this, increase the maximum size of the Java and C code stacks.

C Program:

There are four main stages through which a source code passes in order to finally become an executable.

The four stages for a C program to become an executable are the following:
   1   Pre-processing
   2   Compilation
   3   Assembly
   4   Linking

1. Pre-processing
This is the very first stage through which a source code passes. In this stage the following tasks are done:
   1   Macro substitution
   2   Comments are stripped off
   3   Expansion of the included files

2. Compilation
After the compiler is done with the pre-processor stage. The next step is to produce an intermediate compiled output. The output file for this stage is assembly level instructions.

3. Assembly
At this stage intermediate file is produced. This file is also known as the object file.
This file is produced by the assembler that understands and converts a ‘.s’ file with assembly instructions into a ‘.o’ object file which contains machine level instructions. At this stage only the existing code is converted into machine language, the function calls like printf() are not resolved.
Since the output of this stage is a machine level file (print.o). So we cannot view the content of it.

4. Linking
This is the final stage at which all the linking of function calls with their definitions are done. As discussed earlier, till this stage gcc doesn’t know about the definition of functions like printf(). Until the compiler knows exactly where all of these functions are implemented, it simply uses a place-holder for the function call.
It is at this stage, the definition of printf() is resolved and the actual address of the function printf() is plugged in.
The linker comes into action at this stage and does this task.
The linker also does some extra work; it combines some extra code to our program that is required when the program starts and when the program ends. For example, there is code which is standard for setting up the running environment like passing command line arguments, passing environment variables to every program. Similarly some standard code that is required to return the return value of the program to the system.


Python:

Two kinds of programs process high-level languages into low-level languages: interpreters and compilers. An interpreter reads a high-level program and executes it, meaning that it does what the program says. It processes the program a little at a time, alternately reading lines and performing computations.
A compiler reads the program and translates it completely before the program starts running. In this case, the high-level program is called the source code, and the translated program is called the object code or the executable. Once a program is compiled, you can execute it repeatedly without further translation.
Many modern languages use both processes. They are first compiled into a lower level language, called byte code, and then interpreted by a program called a virtual machine. Python uses both processes, but because of the way programmers interact with it, it is usually considered an interpreted language.
There are two ways to use the Python interpreter: shell mode and program mode. In shell mode, you type Python expressions into the Python shell, and the interpreter immediately shows the result.
Alternatively, you can write an entire program by placing lines of Python instructions in a file and then use the interpreter to execute the contents of the file as a whole. Such a file is often referred to as source code.

Assembly Language:

A program written in assembly language consists of a series of (mnemonic) processor instructions and meta-statements (known variously as directives, pseudo-instructions and pseudo-ops), comments and data. Assembly language instructions usually consist of an opcode mnemonic followed by a list of data, arguments or parameters. These are translated by an interpreter into machine language instructions that can be loaded into memory and executed.
An assembler program creates object code by translating combinations of mnemonics and syntax for operations and addressing modes into their numerical equivalents. The assembler also calculates constant expressions and resolves symbolic names for memory locations and other entities.
The use of symbolic references is a key feature of assemblers, saving tedious calculations and manual address updates after program modifications. Most assemblers also include macro facilities for performing textual substitution –
Number of passes:
There are two types of assemblers based on how many passes through the source are needed (how many times the assembler reads the source) to produce the executable program.
   •   One-pass assemblers go through the source code once. Any symbol used before it is defined will require errata at the end of the object code (or, at least, no earlier than the point where the symbol is defined) telling the linker or the loader to "go back" and overwrite a placeholder which had been left where the as yet undefined symbol was used.
   •   Multi-pass assemblers create a table with all symbols and their values in the first passes, then use the table in later passes to generate code.
In both cases, the assembler must be able to determine the size of each instruction on the initial passes in order to calculate the addresses of subsequent symbols.


2. Ease of Maintenance:
Mainframe:
A computer system is available when its applications are available. An available system is one that is reliable; that is, it rarely requires downtime for upgrades or repairs. And, if the system is brought down by an error condition, it must be serviceable; that is, easy to fix within a relatively short period of time.
Mean time between failure (MTBF) refers to the availability of a computer system. The New Mainframe and its associated software have evolved to the point that customers often experience months or even years of system availability between system downtimes. Moreover, when the system is unavailable because of an unplanned failure or a scheduled upgrade, this period is typically very short. The remarkable availability of the system in processing the organisation's mission-critical applications is vital in today's 24-hour global economy. Along with the hardware, mainframe operating systems exhibit RAS through storage protection and a controlled maintenance process.
a state-of-the-art mainframe system might be said to provide "high availability" and fault tolerance. Redundant hardware components in critical paths, enhanced storage protection, a controlled maintenance process, and system software designed for unlimited availability all help to ensure a consistent, highly available environment for business applications in the event that a system component fails. Such an approach allows the system designer to minimise the risk of having a single point of failure undermine the overall RAS of a computer system.

COTS

One of the most difficult problems in maintenance of COTS-based systems is the decision to upgrade or replace a COTS product. The program management generally cannot control the frequency or the content of new COTS releases. The timing of a new COTS product release tends to be asynchronous with and independent of the new releases of other COTS products and components in the system. Changes in the operational requirements for the system are not always easy to synchronise with product upgrades either.
New releases of COTS software products can occur as often as every six months. Failing to upgrade to the latest version can result in:
• Loss of vendor support for prior versions that are installed and in use.
The inability to buy new copies or obtain licenses for additional copies of the version that is already in the system. This is necessary when the system is being installed in sites incrementally over a period of time.


Backward Compatibility:
Mainframe:
IBM's current mainframe operating systems, z/OS, z/VM, z/VSE, and z/TPF, are backwards compatible successors to operating systems introduced in the 1960s, although of course they have been improved in many ways.

* Choose mainframe for ease of maintenance and backward compatibility and choose COTS for the cost

3.

Cost per MIP- RISC

Large number of registers-RISC

Common in embedded system- RISC

Supports many instructions-CISC

Backward compatibility - CISC