Total Pageviews

Thursday, September 30, 2010

Hazards of Copy/Paste

Copy/Paste is way of coding for many. Copy/Paste can be from websites or another source within company or project. I am not talking about that.

While you write code there are many times you have to repeat some things with slight changes. What you do is simply copy/paste. These are cases that you cannot get to write as subroutine. What happens is if the slight change is required at multiple places its quite likely that you may forget at one place. One's attention is lesser while one is doing copy/paste of code than while one is writing.

Now starts the most dangerous phase. This program since it does not have syntax issues will compile nicely(or will have same syntax error at two places :-)). Well as it goes in programming world its not as much about the programming as it is about debugging. Nightmare starts once you run the program. It will result is some unexpected signature. Since the context of your debug might be totally focused on the conceptual change you have done, you might have tough time getting to the bug that creep in due to copy/paste.

Time saved during copy/paste you might end up paying in the ugly debug which will take far longer time. Unless you are highly diligent and can maintain most of the time its not worth copy/paste small chunks of the code. Better write them again. It will not only reduce silly bugs but also improve the familiarity with the language.

Say No to small copy/paste and even when you have to do pay full attention as if you are writing it fresh. You cannot take it easy, Be Alert !

Wednesday, September 22, 2010

SystemVerilog’s Garbage Collection – Dont forget Threads !

Humans generally like symmetry. C++ has constructor and destructor. Memory allocated in the constructor is to be released in the destructor.

SystemVerilog is not so symmetrical in this context. Systemverilog has constructor but there is no destructor. The memory allocated to the object is garbage collected automatically.

Well in the context of VMM there are thousands of the transactions are created and typically handful of the transactors are crated. While transactions dont last the entire simulation time, typically transactors last the entire simulation time.

Now the transactions are data and they don’t have their own threads. So the garbage collection works perfect.

Now the Systemverilog in contrast to C++ has one more dimension. That is Thread. Class can have their own threads.  These threads are resources of the class that started it. Now what happens is if the thread is active even if the object handle is not referenced by any component the garbage collection will not happen till all threads are terminated.

Now one such scenario is hot plug systems. There could be a model that may have their own  threads. Now to detach and attach with the same class handle could lead to issues.

Since the class handle is not really freed up unless all threads of the class are completed.

VMM xactors have stop_xactor to address it. Although if the main of the xactor thread launched multiple threads by itself with the dangerous join_none will also have issues when the transactor needs to be stopped.

Stopping the xactor will be my next post.