UVM Object and Core Methods

uvm_object is the base class for most non-component UVM classes. It provides essential functionality such as printing, copying, comparing, packing, unpacking, and factory-based object creation.


What is uvm_object?

uvm_object is the base class for:

  • Sequence items
  • Sequences
  • RAL objects
  • Configuration objects
  • Transaction-level data structures
Important: uvm_object does NOT have phases and does NOT live in the UVM hierarchy. It is lightweight and used mainly for data modeling.

Core Methods of uvm_object

The power of uvm_object comes from its built-in utility methods. These methods enable automation and consistency in verification environments.

1️⃣ create()

Used for factory-based object creation.

my_item item;
item = my_item::type_id::create("item");

This enables factory overrides and polymorphism.


2️⃣ copy()

Copies the contents of one object into another.

item2.copy(item1);

Internally calls do_copy(), which users can override.


3️⃣ compare()

Compares two objects field-by-field.

if (item1.compare(item2))
  `uvm_info("COMPARE", "Objects match", UVM_LOW)

Internally calls do_compare(). Extremely useful in scoreboards.


4️⃣ print()

Prints object fields using a printer policy.

item.print();

Internally calls do_print(). Useful for debugging transactions.


5️⃣ pack() / unpack()

Converts object data into a bitstream and vice versa.

bit bits[];
item.pack(bits);
item.unpack(bits);

Internally calls:

  • do_pack()
  • do_unpack()

Used in predictors, reference models, and advanced TLM use cases.


Automation with Macros

UVM provides field automation macros to avoid manually implementing do_copy(), do_compare(), etc.

class my_item extends uvm_sequence_item;

  rand bit [7:0] addr;
  rand bit [31:0] data;

  `uvm_object_utils_begin(my_item)
    `uvm_field_int(addr, UVM_ALL_ON)
    `uvm_field_int(data, UVM_ALL_ON)
  `uvm_object_utils_end

  function new(string name = "my_item");
    super.new(name);
  endfunction

endclass
These macros automatically implement:
  • Factory registration
  • Print
  • Copy
  • Compare
  • Pack / Unpack

uvm_object vs uvm_component

Feature uvm_object uvm_component
Hierarchy No Yes
Phases No Yes
Factory Support Yes Yes
Used for Data / Transactions Structural elements (env, agent, driver)

Expert Insight

As a verification engineer, mastering uvm_object is critical. Scoreboards, sequences, RAL models, and predictors all rely heavily on it. If you understand how do_copy(), do_compare(), and factory registration work internally, you are no longer a beginner in UVM.