Posts

Showing posts from January, 2017

Kotlin Language Features Related to Null Handling

Any software engineer with a Java background would find the null handling features in the Kotlin language interesting. Let's summarize this topic with some examples. Nullable types: In Kotlin, types are non-nullable by default. If you want a variable to be able to hold a null value, you need to explicitly declare its type as nullable using the Type? syntax. For example, String? denotes a nullable string, while String represents a non-nullable string. Safe calls (?.): Kotlin introduces the safe call operator (?.) for handling nullable types. It allows you to safely invoke a method or access a property on a nullable object. If the object is null, the expression returns null instead of throwing a NullPointerException. Example: data class Person(val name: String, val age: Int, val address: String?) fun main() {     // Create a person with a nullable address     val person1 = Person("John Doe", 25, "123 Main Street")     val person2 = Person("Jane Doe", 30,

SimpleScalar Simulator

Image
I used to work with Java over the past years and now I have to deal with a simulator that was written in C. It's been a while since I wrote, read and built any C code so it may not be a very easy journey. Let me share how I try to understand the simulator step by step: SimpleScalar is a suite of processor simulators and supporting tools.  Using the SimpleScalar tools, users can build modeling applications that simulate real programs running on a range of modern processors and systems. SimpleScalar architecture is a close derivative of the MIPS architecture. The tool set takes binaries compiled for the SimpleScalar architecture and simulates their execution on one of several provided processor simulators. SimpleScalar provides sets of precompiled binaries (including SPEC95), plus a modified version of GNU GCC (with associated utilities) that allows us to compile our own SimpleScalar test binaries from C code. Different simulators perform differently depending on the detail l

Making Address Translation Fast: the TLB

Since the page tables are stored in main memory, every memory access by a program can take at least twice as long: one memory access to obtain the physical address and a second access to get the data. The key to improving access performance is to rely on locality of reference to the page table. When a translation for a virtual page number is used, it will probably be needed again in the near future, because the references to the words on that page have both temporal and spatial locality. Accordingly, modern processors include a special cache that keeps track of recently used translations. This special address translation cache is traditionally referred to as a translation-lookaside buffer  (TLB), although it would be more accurate to call it a translation cache. The TLB contains a subset of the virtual-to-physical page mappings that are in the page table.  Because the TLB is a cache, it must have a tag field. If there is no matching entry in the TLB for a page, the page table must

Virtual Memory

The main memory can act as a “cache” for the secondary storage, usually implemented with magnetic disks. This technique is called virtual memory. There were two major motivations for virtual memory: to allow efficient and safe sharing of memory among multiple programs, and to remove the programming burdens of a small, limited amount of main memory. Lets consider a collection of programs running all at once on a computer. Of course, to allow multiple programs to share the same memory, we must be able to protect the programs from each other, ensuring that a program can only read and write the portions of main memory that have been assigned to it. Main memory need contain only the active portions of the many programs, just as a cache contains only the active portion of one program. Virtual memory allows us to efficiently share the processor as well as the main memory. We cannot know which programs will share the memory with other programs when we compile them. In fact, the programs s

Memory Hierarchy

Temporal locality (locality in time):  If an item is referenced, it will tend to be referenced again soon. Most programs contain loops, so instructions and data are likely to be accessed repeatedly, showing high amounts of temporal locality. Spatial locality (locality in space): if an item is referenced, items whose addresses are close by will tend to be referenced soon. Since instructions are normally accessed sequentially, programs show high spatial locality. Accesses to data also exhibit a natural spatial locality. For example, sequential accesses to elements of an array or a record will naturally have high degrees of spatial locality. Memory hierarchy: We take advantage of the principle of locality by implementing the memory of a computer as a memory hierarchy. A memory hierarchy consists of multiple levels of memory with different speeds and sizes. The faster memories are more expensive per bit than the slower memories and thus are smaller. Block:  Minimum unit of informat

NOTES ON COMPUTER ARCHITECTURE: Some important concepts in computer architecture

A  virtual address  is a binary number in virtual memory that enables a process to use a location in primary storage (main memory) independently of other processes and to use more space than actually exists in primary storage by temporarily relegating some contents to a hard disk or internal flash drive. In a computer that incorporates memory management, the virtual address differs from the  physical address , which is the data location on an address bus that corresponds to a particular cell of primary storage or to a particular register in a memory-mapped I/O(input/output)  device. In a computer with both physical and virtual memory, a so-called  MMU (memory management unit)  coordinates and controls all of the memory resources, assigning portions called blocks to various running programs to optimize system performance. By translating between virtual addresses and physical addresses, the MMU allows every running process to "think" that it has all the primary storage to i

Popular posts from this blog

Trie Data Structure and Finding Patterns in a Collection of Words

swapLexOrder: Finding lexicographically largest string

A Graph Application in Java: Using WordNet to Find Outcast Words