Posts

Showing posts from 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,

Returning to SimpleScalar and TLB

The topic of my master's degree thesis is Virtual Memory. More specifically, it is about a low-power Translation Lookaside Buffer design. You can look at my previous posts for an introduction.   We have proven that more than 97% of virtual adress reading is done from the same page. So it is clear that the motivation of putting the TLB in low-power mode is a good idea if the cost of changing power mode is not too high. The motivation part is ok. Now what I need is calculating the latency that is caused by putting the TLB in low-power mode. After that, I need to put there a mini-TLB, and simulate the situation. If the result is not better, then I'll say that mini-TLB is not required. Note: Virtualbox->Settings->Display->Enable 3d acceleration We check if the power mode is changed for every instruction:  if (itlb)  {     if (CACHE_TAGSET(itlb, IACOMPRESS(fetch_regs_PC)) == itlb->last_tagset) {     if (low_power == 0) {                 power_mode_change

Running SPEC2000 binaries on SimpleScalar

Fast-forwarding and limiting the instructions: Example: fast-forward 1 million instructions and then execute 100 million instructions: (under simple-sim3.0 directory) ./sim-outorder -max:inst 1000000000 tests/spec2000/164.gzip/gzip00.peak.ev6 input.source 60 sim-outorder 256.bzip2/bzip200.peak.ev6 input.source 58 sim-outorder 164.gzip/gzip00.peak.ev6 input.source 60 sim-outorder 164.gzip/gzip00.peak.ev6 2000000: input.source 60 sim-outorder  2000000: 181.mcf/mcf00.peak.ev6 inp.in sim-outorder 186.crafty/crafty00.peak.ev6 < crafty.in sim-outorder 197.parser/parser00.peak.ev6 2.1.dict -batch < 197.parser/ref.in sim-outorder x175.vpr/vpr00.peak.ev6 < x175.vpr/net.in sim-outorder 183.equake/equake00.peak.ev6 < 183.equake/inp.in sim-outorder _177.mesa/mesa00.peak.ev6 < _177.mesa/mesa.in Percentage of instructions that are fetched from the same page: int/bzip2: 99% int/gzip:  99% int/mcf: 95% int/crafty: 99% int/parser: 95% int/x175.vp

SimpleScalar Simulator - Part 3

Problem: Can you detect when current page is left for the instruction stream? Inside cache.c we know if the hit is fast (same block) or slow. /*cache.c  line 533*/ printf("Cache tagset: %d  Last tagset: %d\n", CACHE_TAGSET(cp, addr), cp->last_tagset);   /* check for a fast hit: access to same block */   if (CACHE_TAGSET(cp, addr) == cp->last_tagset)     {       printf("Same block hit!\n");       /* hit in the same block */       blk = cp->last_blk;       goto cache_fast_hit;     } printf("Slow hit or miss!\n"); Before cache access, we control the nature of the access and set the iTLB power mode:           if (itlb)   {    if (CACHE_TAGSET(itlb, IACOMPRESS(fetch_regs_PC)) == itlb->last_tagset) {        low_power = 1;        ++low_power_count;    } else {                 low_power = 0;                 ++normal_power_count;    }    printf("Low count = %d, normal count = %d\n", low_power_count

Simplescalar Simulator - Part 2: sim-outorder.c

sim-outorder implements a very detailed out-of-order issue superscalar processor with a two-level memory system and speculative execution support. This simulator is a performance simulator, tracking the latency of all pipeline operations. Let's have a look at SimpleScalar simulator's code related to iTLB. (Instruction Translation Lookaside Buffer) First, there are simulator options related to iTLB: /* register simulator-specific options */ void sim_reg_options(struct opt_odb_t *odb) { /* TLB options */ opt_reg_string(odb, "-tlb:itlb", "instruction TLB config, i.e., { |none}", &itlb_opt, "itlb:16:4096:4:l", /* print */TRUE, NULL); opt_reg_int(odb, "-tlb:lat", "inst/data TLB miss latency (in cycles)", &tlb_miss_lat, /* default */30, /* print */TRUE, /* format */NULL); } /* check simulator-specific option values */ void  sim_check_options(... ) { /* sim-outorder.c  line: 1098*/   /* u

Building and Testing Rest services with Spring

I realized that I need to learn more on Spring Boot/Spring REST and integration testing stuff. Here it goes! Let us remember: Spring Boot project aims at making it easier to build Spring applications by eliminating the need for extensive configuration. With default settings, you can feel magic tricks like implementing your interface behind the scenes etc. About REST : Have you ever worked with SOAP? How did it feel? For me, it always felt like something wrong was going on. Something simpler is needed. Then I was able to see in practice that REST services offer cleaner solutions and with the great capabilities of Java platform and Spring, you have a far better structure. HTTP is the Platform You describe the relationships using URIs. For example, you access the Bookmark's of a User with: /alice/bookmarks Clients and services agree upon a mutually understood data representation. So we send HTTP GET/POST/DELETE requests. There is usually a status code about the result of

Sharpening Regex Skills

Image
I needed to revisit regexes and found this sites useful: https://regexone.com https://regex101.com/ (Regex debugger is cool) Below is a useful summary: Groups: Parsing XML.. Following code creates 2 groups, then references to group 1.          boolean matchFound = false;          Pattern r = Pattern.compile("<(.+)>([^<]+)</\\1>");          Matcher m = r.matcher(line);          while (m.find()) {              System.out.println(m.group(2));              matchFound = true;          }                    if ( ! matchFound) {              System.out.println("None");          }

Java Interview Preparation

https://blog.udemy.com/java-interview-questions/ 1- What is JVM? Why is Java called the ‘Platform Independent Programming Language’? 2. What is the Difference between JDK and JRE? 3. What does the ‘static’ keyword mean? 4. What are the Data Types supported by Java? What is Autoboxing and Unboxing? 5. What is the difference between STRINGBUFFER and STRING? 6. What is Function Over-Riding and Over-Loading in Java? 7. What is Constructors, Constructor Overloading in Java and Copy-Constructor? 8. What is Java Exception Handling? What is the difference between Errors, Unchecked Exception and Checked Exception? Throwable       Error ( serious problems that a reasonable application  should not try to catch, out of memory etc. )       Exception             Checked / Unchecked 10. What is the Difference between byte stream and Character streams? A stream is a way of sequentially accessing a file. A byte stream access the file byte by byte. A byte stream is suitable for

Understanding SimpleScalar codebase

Among others, sim-safe is the most user-friendly simulator and the implementation is crafted for clarity. Generally there are two types of simulators: Functional simulators implement architecture (what programmers see) perform the actual execution sim-fast, sim-safe , sim-profile, sim-cache Performance simulators implement micro-architecture model system internals measure time sim-outorder Question: What is Dlite debugger? How can we debug a simulator?? DLite is a symbolic debugger. To use it, start the simulator with -i option Then user the debugger commands, for example: "step" Question: To work with TLB, do I have to fully understand sim-outorder ?? http://www.simplescalar.com/docs/simple_tutorial_v2.pdf page:14 http://www.simplescalar.com/docs/hack_guide_v2.pdf Question: How does sim-safe count number of instructions? Where is iTLB related code? In main.c file: /* options database*/ struct opt_odb_t *sim_odb; /* simulated re

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