Static in SystemVerilog: Static Properties, Static Methods and Static Variables, Tested on VCS
In short: A static property in a SystemVerilog class has one copy shared by every object, and it exists before any object is created. A static method belongs to the class, so you call it as ClassName::method() with no object. It can only use static members: this and super are illegal inside it. Static methods are never virtual, and each specialization of a parameterized class gets its own copy of every static.
Most things in a class belong to one object. Every new() gets its own copy. Static is the exception, and it’s behind a lot of “why did this counter jump?” bugs in testbenches.
I put every static rule I could think of into one UVM test and ran it on VCS. A second small file holds four mistakes on purpose, so you can see the compiler’s own words. Every result below is a line from those logs.
A simple way to picture it
Think of a shop. Each customer carries their own bag: that’s a normal property, one per object. The people counter above the door is shared: one counter for the whole shop, whoever walks in. That’s a static property.
A static method is the price list on the wall. You can read it without being a customer, and it can’t see inside anyone’s bag.
Static at a glance
| You write | What you get | Shown in |
|---|---|---|
static int total; in a class | one copy for the class, there before any new() | parts 1, 2 |
static function | callable as Class::f(), no object needed | part 3 |
static int x; inside a normal method | one copy shared by every object and every call | part 4 |
a static in class C #(int W) | one copy per specialization | part 5 |
| a static in a base class | shared with every derived class | part 6 |
| the same static name in a derived class | a new copy that hides the base one | part 6 |
| a static method called through a base handle | the base version, always | part 7 |
static const | a class constant | part 8 |
1. The static exists before any object
[TAV_1] before any new(): tav_car::total = 0
No tav_car object existed yet, and tav_car::total was already there with its default of 0. A static is created with the class, not with an object.
2. One copy, shared by every object
The constructor does total++ and then copies total into the object’s own id. I made three cars.
[TAV_2] after 3 new(): tav_car::total = 3
[TAV_2] c1.total = 3, c2.total = 3, c3.total = 3
[TAV_2] c1.id = 1, c2.id = 2, c3.id = 3
[TAV_2] after c1.total = 50: c3.total = 50, tav_car::total = 50
The three handles all read 3, because there is only one total. The id values differ, because id is per object.
The last line is the trap. I wrote c1.total = 50, and c3 saw 50 too. Writing a static through a handle looks like you’re changing one object. You’re changing all of them.
3. Static methods: no object needed
[TAV_3] tav_car::get_total() = 3
[TAV_3] cnull is null: 1, cnull.get_total() = 3
[TAV_3] cnull.total = 3
tav_car::get_total() ran with the class scope operator :: and no object. Then I called it through cnull, a handle that was still null. VCS returned 3 with no null-handle error, and reading cnull.total worked the same way.
That makes sense: a static member doesn’t need an object, so the handle is only used for its type. I still write tav_car::get_total() in real code. It says at a glance that no object is involved, and it doesn’t depend on how a tool treats null handles.
4. A static variable inside a normal method
This one catches people who know static class members well. honk() is a normal method, but it declares static int honks; inside it.
function int honk();
static int honks; // one copy, shared by every tav_car object
int calls; // automatic: a fresh copy on every call
honks++;
calls++;
return honks * 100 + calls;
endfunction
[TAV_4] c1.honk(): honks = 1, calls = 1
[TAV_4] c2.honk(): honks = 2, calls = 1
[TAV_4] c1.honk(): honks = 3, calls = 1
calls started fresh each time, so it was always 1. honks kept counting, and it counted across c1 and c2. A static local variable isn’t per object. It’s one copy for the whole class, hidden inside one method.
This is the class-method side of static vs automatic lifetime. Class methods are automatic by default, and static on a local variable switches that one variable back.
5. Parameterized classes get one copy per specialization
[TAV_5] tav_pkt#(8)::count = 2, tav_pkt#(16)::count = 1
I made two tav_pkt#(8) objects and one tav_pkt#(16). They didn’t share a counter. Each specialization is its own class, with its own statics.
It matters in UVM, where so much is parameterized. A static counter in my_driver #(REQ) counts per REQ type, not across all your drivers.
6. Statics and inheritance
[TAV_6] after tav_derived::shared_cnt = 7: tav_base::shared_cnt = 7
[TAV_6] after tav_derived::shadow_cnt = 9: tav_base::shadow_cnt = 0
shared_cnt is declared only in the base class. Writing it through tav_derived:: changed the base value too. A derived class shares the base class’s statics. It doesn’t get a copy.
shadow_cnt is declared in both classes. The derived one hides the base one, so writing 9 through tav_derived:: left tav_base::shadow_cnt at 0. Same name, two separate variables. That’s a hard bug to spot in review, so I avoid reusing a static name in a derived class.
7. A static method is never virtual
b is a tav_base handle pointing to a tav_derived object. Both classes have a virtual who_virtual() and a static who_static().
[TAV_7] b.who_virtual() = tav_derived::who_virtual
[TAV_7] b.who_static() = tav_base::who_static
[TAV_7] d.who_static() = tav_derived::who_static
The virtual call followed the object and ran the derived version. The static call followed the handle’s type and ran the base version, even though the object was a tav_derived.
A static method has no object to look at, so there’s nothing to dispatch on. If you need polymorphism, you need a virtual method.
8. Class constants with static const
[TAV_8] tav_limits::MAX_BURST = 16
static const int MAX_BURST = 16; gives one read-only value for the class, readable with :: and no object. It’s a tidy home for protocol limits that belong to one class.
9. The singleton: where UVM uses static
class tav_cfg;
local static tav_cfg m_inst;
local function new(); endfunction
static function tav_cfg get();
if (m_inst == null) m_inst = new();
return m_inst;
endfunction
endclass
[TAV_9] cfg_a == cfg_b: 1, cfg_b.verbosity_level = 3
Two calls to get() returned the same object, so a value set through cfg_a showed up in cfg_b. The local constructor stops anyone outside the class from calling new().
That’s the same pattern UVM uses for uvm_root and the factory: one static handle and a static get(). When you call uvm_factory::get(), you’re calling a static method.
10. A static id in a UVM sequence item
tav_item has static int next_id;, and its constructor does item_id = next_id++;. Two sequences each created three items.
[TAV_10] s1 item ids = '{0, 1, 2} , s2 item ids = '{3, 4, 5}
The second sequence didn’t start again at 0. The counter belongs to the class, so it kept going across sequences. That’s what you want for a unique transaction id in a log, and it’s what surprises you if you expected each sequence to count from 0.
The four static mistakes, and what VCS said
The second file, tav_static_errors.sv, must not compile. Here is what VCS X-2025.06-SP1 printed:
Error-[SV-IUTS] Illegal use of this and super
testbench.sv, 21
Use of 'this' and 'super' is not allowed inside 'static' class-method or
class-member
Error-[SV-IUTS] Illegal use of this and super
testbench.sv, 26
Use of 'this' and 'super' is not allowed inside 'static' class-method or
class-member
Error-[WUCIQ] Invalid qualifier usage
testbench.sv, 30
Invalid use of class item qualifiers. Cannot use virtual and static keywords
together for method declarations.
3 errors
- Line 21,
thisin a static method: there’s no object, so there’s nothis. - Line 26,
superin a static method: the same reason. To reach a base class’s static method, call it by name, liketav_err_base::show_static(), neversuper.. - Line 30,
virtual static: a method can’t be both, as part 7 showed.
The fourth mistake, line 16, is a static method reading the non-static gear. VCS said nothing about it in that compile. Once I moved it into a file of its own, it was caught:
Error-[SV-AMC] Non-static member access
testbench.sv, 9
$unit, "gear"
Illegal access of non-static member 'gear' from static method
'tav_err_a::bad_a'.
1 error
So VCS reports this one in a later pass, after the other three are fixed. The lesson for daily work: the first error list isn’t always complete. Fix the errors you see, then compile again.
Which one should you use?
- A count, id or limit shared by every object: a static property.
- A helper that doesn’t need any object’s data: a static method, called with
::. - A value one method remembers between calls: a static local variable, knowing it’s shared by every object.
- One object that everything shares: a singleton with a static
get(). - Behaviour that changes with the object’s type: a virtual method, never a static one.
The bench: one file, one run
Everything above comes from tav_static_members.sv: one UVM test with ten parts, every result printed with `uvm_info. The mistakes come from tav_static_errors.sv.
On EDA Playground, paste the first file into testbench.sv, leave design.sv empty, pick UVM 1.2 and press Run. Paste the second file on its own to see the errors (download both as a zip).
// tav_static_members.sv
// The Art of Verification: static properties and methods in SystemVerilog
// One UVM test, 10 parts. Every result is printed with `uvm_info.
// EDA Playground: paste into testbench.sv, leave design.sv empty,
// pick UVM 1.2 and press Run.
`include "uvm_macros.svh"
import uvm_pkg::*;
// ---------------------------------------------------------------
// Part 1 to 4: a shared counter, a per-object id, static methods
// ---------------------------------------------------------------
class tav_car;
static int total; // one copy for the whole class
int id; // one copy per object
function new();
total++;
id = total;
endfunction
static function int get_total();
return total; // a static method may read static members
endfunction
// a normal (automatic) method with a static local variable
function int honk();
static int honks; // one copy, shared by every tav_car object
int calls; // automatic: a fresh copy on every call
honks++;
calls++;
return honks * 100 + calls; // pack both counts into one number
endfunction
endclass
// ---------------------------------------------------------------
// Part 5: a parameterized class gets one static per specialization
// ---------------------------------------------------------------
class tav_pkt #(int W = 8);
static int count;
function new();
count++;
endfunction
endclass
// ---------------------------------------------------------------
// Part 6 and 7: statics and inheritance
// ---------------------------------------------------------------
class tav_base;
static int shared_cnt; // inherited, not copied
static int shadow_cnt;
static function string who_static();
return "tav_base::who_static";
endfunction
virtual function string who_virtual();
return "tav_base::who_virtual";
endfunction
endclass
class tav_derived extends tav_base;
static int shadow_cnt; // redeclared: hides tav_base::shadow_cnt
static function string who_static();
return "tav_derived::who_static";
endfunction
virtual function string who_virtual();
return "tav_derived::who_virtual";
endfunction
endclass
// ---------------------------------------------------------------
// Part 8: a class constant
// ---------------------------------------------------------------
class tav_limits;
static const int MAX_BURST = 16;
endclass
// ---------------------------------------------------------------
// Part 9: singleton (the pattern behind uvm_root and the factory)
// ---------------------------------------------------------------
class tav_cfg;
local static tav_cfg m_inst;
int verbosity_level;
local function new(); // nobody outside can call new()
endfunction
static function tav_cfg get();
if (m_inst == null) m_inst = new();
return m_inst;
endfunction
endclass
// ---------------------------------------------------------------
// Part 10: a static id in a UVM sequence item
// ---------------------------------------------------------------
class tav_item extends uvm_sequence_item;
static int next_id;
int item_id;
`uvm_object_utils(tav_item)
function new(string name = "tav_item");
super.new(name);
item_id = next_id++;
endfunction
endclass
class tav_seq extends uvm_sequence #(tav_item);
`uvm_object_utils(tav_seq)
int ids[$];
function new(string name = "tav_seq");
super.new(name);
endfunction
virtual task body();
tav_item it;
repeat (3) begin
it = tav_item::type_id::create("it");
ids.push_back(it.item_id);
end
endtask
endclass
// ---------------------------------------------------------------
// The test
// ---------------------------------------------------------------
class tav_static_test extends uvm_test;
`uvm_component_utils(tav_static_test)
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
virtual task run_phase(uvm_phase phase);
tav_car c1, c2, c3, cnull;
tav_pkt #(8) p8a, p8b;
tav_pkt #(16) p16;
tav_base b;
tav_derived d;
tav_cfg cfg_a, cfg_b;
tav_seq s1, s2;
int r;
phase.raise_objection(this);
// Part 1: the static exists before any object
`uvm_info("TAV_1", $sformatf("before any new(): tav_car::total = %0d", tav_car::total), UVM_LOW)
// Part 2: one shared copy, one id per object
c1 = new(); c2 = new(); c3 = new();
`uvm_info("TAV_2", $sformatf("after 3 new(): tav_car::total = %0d", tav_car::total), UVM_LOW)
`uvm_info("TAV_2", $sformatf("c1.total = %0d, c2.total = %0d, c3.total = %0d", c1.total, c2.total, c3.total), UVM_LOW)
`uvm_info("TAV_2", $sformatf("c1.id = %0d, c2.id = %0d, c3.id = %0d", c1.id, c2.id, c3.id), UVM_LOW)
c1.total = 50; // write through one handle...
`uvm_info("TAV_2", $sformatf("after c1.total = 50: c3.total = %0d, tav_car::total = %0d", c3.total, tav_car::total), UVM_LOW)
tav_car::total = 3; // put it back
// Part 3: static method, with no object and through a null handle
`uvm_info("TAV_3", $sformatf("tav_car::get_total() = %0d", tav_car::get_total()), UVM_LOW)
`uvm_info("TAV_3", $sformatf("cnull is null: %0d, cnull.get_total() = %0d", cnull == null, cnull.get_total()), UVM_LOW)
`uvm_info("TAV_3", $sformatf("cnull.total = %0d", cnull.total), UVM_LOW)
// Part 4: a static local variable inside a normal method
r = c1.honk(); `uvm_info("TAV_4", $sformatf("c1.honk(): honks = %0d, calls = %0d", r / 100, r % 100), UVM_LOW)
r = c2.honk(); `uvm_info("TAV_4", $sformatf("c2.honk(): honks = %0d, calls = %0d", r / 100, r % 100), UVM_LOW)
r = c1.honk(); `uvm_info("TAV_4", $sformatf("c1.honk(): honks = %0d, calls = %0d", r / 100, r % 100), UVM_LOW)
// Part 5: parameterized class, one static per specialization
p8a = new(); p8b = new(); p16 = new();
`uvm_info("TAV_5", $sformatf("tav_pkt#(8)::count = %0d, tav_pkt#(16)::count = %0d", tav_pkt#(8)::count, tav_pkt#(16)::count), UVM_LOW)
// Part 6: statics and inheritance
tav_derived::shared_cnt = 7;
`uvm_info("TAV_6", $sformatf("after tav_derived::shared_cnt = 7: tav_base::shared_cnt = %0d", tav_base::shared_cnt), UVM_LOW)
tav_derived::shadow_cnt = 9;
`uvm_info("TAV_6", $sformatf("after tav_derived::shadow_cnt = 9: tav_base::shadow_cnt = %0d", tav_base::shadow_cnt), UVM_LOW)
// Part 7: a static method is not virtual
d = new(); b = d; // base handle, derived object
`uvm_info("TAV_7", $sformatf("b.who_virtual() = %s", b.who_virtual()), UVM_LOW)
`uvm_info("TAV_7", $sformatf("b.who_static() = %s", b.who_static()), UVM_LOW)
`uvm_info("TAV_7", $sformatf("d.who_static() = %s", d.who_static()), UVM_LOW)
// Part 8: a class constant
`uvm_info("TAV_8", $sformatf("tav_limits::MAX_BURST = %0d", tav_limits::MAX_BURST), UVM_LOW)
// Part 9: singleton
cfg_a = tav_cfg::get();
cfg_a.verbosity_level = 3;
cfg_b = tav_cfg::get();
`uvm_info("TAV_9", $sformatf("cfg_a == cfg_b: %0d, cfg_b.verbosity_level = %0d", cfg_a == cfg_b, cfg_b.verbosity_level), UVM_LOW)
// Part 10: static id in a sequence item, across two sequences
s1 = tav_seq::type_id::create("s1");
s2 = tav_seq::type_id::create("s2");
s1.start(null);
s2.start(null);
`uvm_info("TAV_10", $sformatf("s1 item ids = %p, s2 item ids = %p", s1.ids, s2.ids), UVM_LOW)
phase.drop_objection(this);
endtask
endclass
module tb;
initial run_test("tav_static_test");
endmodule
What VCS printed
VCS X-2025.06-SP1 with UVM 1.2. The run ended at time 0, since nothing in it consumes time, with UVM_ERROR : 0 and UVM_WARNING : 0. Every TAV line is shown in its part above, with the UVM_INFO testbench.sv(NN) @ 0: uvm_test_top prefix trimmed.
Common mistakes (and the fix for each)
1. Writing a static through a handle. In part 2, c1.total = 50 changed total for every car. Fix: write statics as tav_car::total so the code says what it does.
2. Thinking a static local variable is per object. In part 4, honks counted across c1 and c2. Fix: if it must be per object, make it a normal class property.
3. Expecting one counter across a parameterized class. In part 5, #(8) and #(16) kept separate counts. Fix: put the counter in a non-parameterized base class that every specialization extends.
4. Reusing a static name in a derived class. In part 6, the derived shadow_cnt hid the base one. Fix: give it a different name, or drop the redeclaration.
5. Expecting a static method to act virtual. In part 7, the base handle ran the base version. Fix: make it a virtual method if the object’s type should decide.
6. Using this or super in a static method. VCS stopped with SV-IUTS. Fix: use the class name and ::.
Where AI helps, and where it doesn’t
An AI assistant is quick at spotting a static counter that should be per object, and at explaining a compile error like SV-IUTS in plain words. It also writes a decent singleton on the first try.
Where I’d check it is the edge cases: per-specialization statics, a static local variable inside a class method, and calls through a null handle. Those are exactly the questions where a confident answer and the simulator can disagree. That’s why every claim here comes from a log line.
Practice challenge
Add a non-parameterized base class tav_pkt_base with static int total;, and make tav_pkt #(int W) extend it. Count every packet in total and each width in count. Then print both for two #(8) packets and one #(16) packet. You should see 3 for total, and 2 and 1 for the counts.
FAQ
What is a static property in SystemVerilog? A class property declared with static. There is one copy for the whole class, shared by every object, and it exists before any object is created.
What is a static method in SystemVerilog? A method declared with static. It belongs to the class, so you call it as ClassName::method() without an object, and it can only use static members.
Can a static method access non-static properties? No. It has no object, so it has no non-static properties to read. VCS reports SV-AMC, “Illegal access of non-static member”. this is illegal inside it too, and VCS reports SV-IUTS.
Can I use super in a static method? No. VCS reported “Use of ‘this’ and ‘super’ is not allowed inside ‘static’ class-method”. Call the base class’s static method by name with :: instead.
Can a static method be virtual? No. VCS rejects virtual static with WUCIQ, and a static method called through a base handle always runs the base version.
Is a static variable inside a class method shared between objects? Yes. In my run, honks counted 1, 2, 3 across two different objects.
Do parameterized classes share static variables? No. Each specialization gets its own copy: tav_pkt#(8)::count was 2 while tav_pkt#(16)::count was 1.
References
- IEEE 1800-2023, SystemVerilog standard: clause 8.9 (static class properties), clause 8.10 (static methods), clauses 8.11 and 8.15 (
thisandsuper), clause 8.25 (parameterized classes) and clause 6.21 (scope and lifetime). - IEEE 1800.2, UVM class reference:
uvm_root::get()anduvm_factory::get().
Keep learning
Static sits next to lifetime, so read static vs automatic lifetime next. For why a static method can’t use this, see the this keyword in SystemVerilog.
Part 7 is easier after inheritance, polymorphism and virtual vs pure virtual methods. To see a static get() at work, read the UVM factory and the UVM testbench architecture.
Part of the learning path SystemVerilog for verification

static function int PKT_ID;
pkt_id++;
return pkt_id ;
endfunction: PKT_ID
endclass
There is a small mistake. The output of static function will be 1,2,3,4,5
Hi Hardik,
Firstly, Thank you for the blogs. Really nice.
I tried to run the 2nd chunk of code (static method). Saw the below output.
# dynapkt[0].id = 0
# dynapkt[1].id = 0
# dynapkt[2].id = 0
# dynapkt[3].id = 0
# dynapkt[4].id = 0
(Tool: Questa)
I am not able to ascertain the reason. Can you please explain that?