Doubts related to session " OOP Design Pattern Examples "

Hi all ,

I was going through the following :: OOP Design Pattern Examples

I have a few questions ::

[ A ] " Static properties do not get allocated until specialized "

(a) Allocation ::

(1) Does allocation mean Appropriate Space is reserved for static property ’ counter ’ ?

(2) Can I say allocation occurs at Elaboration time ( for class Specialization ) OR

   at  Compilation Time  (  for  static  property  in  Non - Parameterized  class  ) ?

(b) Initialization ::

(1) Which one of the following 2 statements is correct ::

   Static  property  are  initialized  at  Time 0   OR

   Static  property  are  initialized  before  Time 0 

(2) Does static property initialization occur before ALL procedural blocks and before continous assignment

  statements  (  assign  statements  )  ?

( c ) " The compiler resolves all class Specializations as part of elaboration process "

      Does  it  mean  the  following  ::

(1) It identifies ALL unique Specializations ( irrespective of the Time during which the statements would be executed )
and initializes their static properties ?


       Eg ::   initial  begin
               #10 ;              
               $display( Stack #( bit ) :: counter ) ;
               end

  So  even  though  the  $display  statement  gets  executed  at  Time : 10  the  compiler  identifies  the  class

  Specialization  at  elaboration time  and initializes  it  at / before  Time : 0  

[ B ] Static variable initialization ordering ::


         Root  my_root  =  Root  ::  get() ; 

         MyComponent  me  =  new( "me"  ,  my_root ) ;

(1) Do initialization during declaration occur at the same time static properties are initialized ?

    i.e  Possible  race  condition  between  them

[ C ] Static property initialization in Non - Parameterized class ( via Specialization ) V/S

     **Static  property  initialization  in  Parameterized  class**

(1)     Do  both  occur  at  Same  time  OR  are  static  properties  in  Non - Parameterized  initialized  before 

       static  property  initialization  in  Parameterized  class ?

     Eg ::  If  I  were  to  assign a  static  property  (  LHS  )  a   static  property  of  Non - Parameterized  class ( RHS ) 

       **Will  there  exist  a  Race  Condition  ?**

In reply to ABD_91:

That’s a lot of questions. See my answers inline marked with [Dave_59]. I do think you are confusing the way the elaboration process determines how many static variables get created by parameterized classes, versus static variable initialization. They are independent of each other.

Hi all ,
I was going through the following :: OOP Design Pattern Examples
I have a few questions ::
[ A ] " Static properties do not get allocated until specialized "
(a) Allocation ::
(1) Does allocation mean Appropriate Space is reserved for static property ’ counter ’ ?
[dave_59] Yes.
(2) Can I say allocation occurs at Elaboration time ( for class Specialization ) OR
at Compilation Time ( for static property in Non - Parameterized class ) ?
[dave_59]Allocation occurs at the same point regardless of parameterized class specialization or non-paramterized class—just before the start of simulation.
(b) Initialization ::
(1) Which one of the following 2 statements is correct ::
Static property are initialized at Time 0 OR
Static property are initialized before Time 0
[dave_59]There is no difference. Actually, there is no way to observe the difference.
(2) Does static property initialization occur before ALL procedural blocks and before continous assignment
statements ( assign statements ) ?
[dave_59]The LRM does not specify when the process associated with continuous assignments begin.
( c ) " The compiler resolves all class Specializations as part of elaboration process "
Does it mean the following ::
(1) It identifies ALL unique Specializations ( irrespective of the Time during which the statements would be executed )
and initializes their static properties ?


Eg ::   initial  begin
#10 ;              
$display( Stack #( bit ) :: counter ) ;
end

So even though the $display statement gets executed at Time : 10 the compiler identifies the class
Specialization at elaboration time and initializes it at / before Time : 0
[dave_59]Correct.
[ B ] Static variable initialization ordering ::


Root  my_root  =  Root  ::  get() ; 
MyComponent  me  =  new( "me"  ,  my_root ) ;

(1) Do initialization during declaration occur at the same time static properties are initialized ?
[dave_59]Correct.
[dave_59]The LRM is not completely clear here. But you can assume the allocation step creates a space for a variable with it’s default uninitialized value (like X for logic), and then at some later point the RHS of the initialization gets evaluated.
i.e Possible race condition between them
[ C ] Static property initialization in Non - Parameterized class ( via Specialization ) V/S
Static property initialization in Parameterized class
(1) Do both occur at Same time OR are static properties in Non - Parameterized initialized before
static property initialization in Parameterized class ?
Eg :: If I were to assign a static property ( LHS ) a static property of Non - Parameterized class ( RHS )
Will there exist a Race Condition ?

In reply to dave_59:

Thanks Dave for the clarification .

I have final 3 questions to conclude this thread

[ A ] For the following code ::


class  non_param ;
   static  int  cnt =  1 ;
  endclass

  class  stack  #( type T = int ) ;

     static  int  counter  =  non_param::cnt++ ;   //   Possible  Race ?
 
 //   Initialized  based  on  static  property  of   non_param  

  endclass

  typedef  stack #( byte )  stack_byte ;

As LRM doesn’t define the order of static variable initialization ,

( Q1 ) Can I say there is a possible race condition in above initialization ?

So I should define a static function in class ’ non_param ’ which returns the
value of static property ’ cnt ’ to overcome the race condition

[ B ] Type Compatibility Issues from " Yin and Yang of OOV "


  class  Base ;

  endclass
  
  class  SubType  extends  Base ;

  endclass

  class  PC  #( type T = int ) ;

  endclass

  PC #( Base )  P ;
  
  PC #( SubType )  C  =  new() ;
  
  PC #( int )  P_int ;
  
  PC #( bit signed [31:0] )  P_bs_31_0  =  new() ;   
  
  PC #( bit signed [0:31] )  P_bs_0_31  =  new() ;  

  initial  begin

   $display(" initial  block  starts ") ;

        P = C  ;             //  (a)

   P_int  =  P_bs_31_0 ;     //  (b) 
   
   P_int  =  P_bs_0_31 ;     //  (c)  

  end 

  

Assignment (a) N (c) are illegal .

( Q2 ) Does the LRM define whether this is a Elaboration OR Run - Time Error ?

( Q3 ) ( b ) is Legal as the type parameter are Matching types , right ?

In reply to ABD_91:

[A1] Yes, the LRM does not define an order, although most tools will use the source text order. But that breaks down when there are multiple specializations of the class.

[A2] The LRM does not mandate when an error should occur, only that it should be detected. The operation of steps for compilation, elaboration and simulation is tool specific.

[A3] Yes, Section 6.22.1 Matching types explains why int/byte matches the synonymous packed array.