This is off the top of my head, but I'd say that this is reasonable
place to put a refcount if *all* instances will need to have it.  If you
had an optimization in place for "objects with a refcount of anything
but one" or some other thing, then you might consider using the
syncblock record (which is where the monitor and the hash value hang
out, lazily).  The syncblock index is found at a negative offset from
the pointer to the MethodTable - this accounts for the second DWORD that
you are seeing.

You *are* going to have to grind through a lot of asserts, I'd bet.
Remember that there will be multiple places in the runtime (such as
RuntimeHelpers.cs in System.Runtime.CompilerServices, where
OffsetToStringData will need to be changed to return the correct size).
The GC also depends upon the size of the object header when it walks the
heap.  There may also be stubs or places in the JIT's codegen where
assumptions about size have leaked in...

The right way to look at this particular project: an adventure!  (I hope
:)

-- David Stutz

-----Original Message-----
From: Chris Tavares [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, July 18, 2002 2:11 PM
To: [EMAIL PROTECTED]
Subject: [DOTNET-ROTOR] Hacking ObjHeader, hitting a wall


Hi all. I was hoping I could get some guidance from the folks here that
have been playing with the Rotor code a bit longer than I have.

All this is with the latest Rotor drop on WinXP.

As part of an experiement in adding refcounting to Rotor, the first
step, of course, is adding the refcount field itself. It seems that the
ObjHeader structure is the appropriate place to put these precious four
bytes. So I went ahead and added my DWORD, just before the
m_SyncBlockValue field. I also updated the SIZEOF_OBJHEADER macro to 8
just above the ObjHeader class definition. (BTW - is there a reason for
SIZEOF_OBJHEADER to exist? What's wrong with plain old sizeof()?)

I got an assertion error about MIN_OBJECT_SIZE (defined in object.h) not
being the right size anymore. I looked at the definition, and it looked
like there were four bytes of padding in there anyway, so I took out the
"2 * " from MIN_OBJECT_SIZE, and fixed that assertion.

Now, I'm hitting an assertion in binder.cpp, line 636. It looks like
there's a table of field offsets, and it's comparing the actual offset
to the ones in the table. I'm kinda stuck here - I'm not sure why they
don't match.

So, my questions are:

1) Was the change I make to the MIN_OBJECT_SIZE ok?

2) What's the deal with the offset tables in the Binder class? How do I
update those tables so things line up properly again?

3) Is there a better place to put the ref count?

Thanks,

-Chris Tavares

Reply via email to