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,...

More on Virtual Memory and TLB


Below is a series of videos on virtual memory:

https://www.youtube.com/watch?v=KNUJhZCQZ9c
  • Virtual memory is a layer of indirection. Without virtual memory the program address would be equal to the RAM address. 
  • Discs are 1000x slower than RAM.
  • What happens if a page is not on RAM? 
    • Page table tells that the page is on disc.
    • Hardware (CPU) generates a page fault exception.
    • This exception will be picked up by the operating system. (page fault handler)
    • Operating system kicks out (evicts) another page from RAM and writes it to disc
    • If the page is dirty, it needs to be written back to disc first.
    • Then OS reads the page from disk and puts it in RAM
    • Then OS updates the page table to map the new page
    • Finally OS jumps back to the instruction that caused the page fault
    • A page fault is the slowest possible thing that can happen to a computer. (except for human interaction)
  • Some operating sytems do not use paging:
    • iOS kills the program if it uses too much memory.
  • TLB should be fast, we have to use it for every memory access. Do there are seperate TLBs for instructions and data (iTLB/dTLB) 

  • For iTLB, if the CPU reads the instuctions from the same page, we can put the iTLB to low leakage mode, which decreases the energy usage.
    • But how will we know when the current page will be left? (So that we switch the iTLB to the normal energy mode)
    • First step: run SPEC benchmarks on normal SuperScalar configuration. 
    • Second step: How to implement low energy mode for iTLB.
      • Put it on low energy mode all the time, and see the benchmark results.
    • Third Step: How to guess the time when the current page is left. Implement.

Lecture on simulators:

https://www.youtube.com/watch?v=yfKk4GcBMi8&t=206s

An article on SimpleScalar:

http://www.dre.vanderbilt.edu/~sutambe/documents/pubs/wcre2004.pdf

Modified Version of SimpleScalar:

https://github.com/aivus/SimpleScalar

Visual C++ notes:

http://stackoverflow.com/questions/16883037/remove-secure-warnings-crt-secure-no-warnings-from-projects-by-default-in-vis

Library Directories:
C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10150.0\ucrt\x86

C/C++ Additional Include Libraries:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt


http://stackoverflow.com/questions/31736361/visual-studio-2015-gives-me-errors-upon-creating-a-simple-test-console-program

Building simplescalar on linux is easy as described in readme file.





Comments

Popular posts from this blog

Trie Data Structure and Finding Patterns in a Collection of Words

Virtual Memory

NOTES ON COMPUTER ARCHITECTURE: Some important concepts in computer architecture