[Warped-devel] Re: Warped errors

William Voorsluys williamvoor at gmail.com
Mon Dec 13 17:15:59 EST 2004


Hi,

This one was tough... But I kind of figured out what was going on.
Actually, it was tough to figure out where the problem was, as the
solution is pretty simple.

It happens that when an event is sent X from object A to object B, it
is inserted in two different lists. First it is inserted by the Output
Manager in the list of output events of A. When the system is doing
garbage collect the same event is also in the list of Processed Events
of B.
What happened here was that during B's garbage collecting (before
A's), event X would eventually be deleted by the application since the
method "DefaultTimeWarpEventSet::EventContainer::garbageCollect" make
the method "SimulationObject::reclaimEvent" to be called.
Then two situations may arise. 
1. The application simply deletes the event, freeing its allocated memory.
2. The event object is inserted in a stack to be reused.

In either case a problem occurs when object A is performing its
garbage collecting, specifically when the Output Manager is removing
the events with SendTime <= GVT from its OutputEvents vector.
If event X has been deallocated the Output Manager gets a segmentation
fault when trying to call Event::getSendTime().
Now, even when the event object is not deallocated the system is not
able to access the correct Event::getSendTime(), which is a virtual
method. Instead, it calls the method from the abstract base call
Event, making the system abort with a message "pure virtual method
called". It seems (I don't know how it's possible) the system is
losing the link with the derived class when the object is pushed into
the AllocatorStack. I'm sure the address of the object pointer is the
same, but the correct virtual method getSendTime() is not being
invoked.

To correct the problem I modified the code of
TimeWarpSimulationManager.cpp to make the OutputManagers of all
objects to collect their garbage (in a different loop) before the
Eventsets deletes the objects. Here's how the new code looks like:

...
void
TimeWarpSimulationManager::garbageCollect(const VTime& garbageCollectTime){
...
for( unsigned int i = 0; i < objects->size(); i++ ){
	    myStateManager->garbageCollect(garbageCollectTime, (*objects)[i]);
	    myOutputManager->garbageCollect(garbageCollectTime, (*objects)[i]);
    }

for( unsigned int i = 0; i < objects->size(); i++ ){
      myEventSet->garbageCollect( (*objects)[i], garbageCollectTime );
...

It seems the problem is corrected, but I'd still like to know why is
the system losing the "dynamic binding" of virtual functions when the
object is inserted on the stack!

That's it.

Thanks,

William.




On Wed, 8 Dec 2004 21:06:20 -0200, William Voorsluys
<williamvoor at gmail.com> wrote:
> Hello,
> 
> I've been running the PHOLD model on Warped 2.0 with many different
> configurations. In some situations Warped is reporting some strange
> error messages.
> 
> When the system is collecting the garbage after having computed the
> GVT, the following message appears: "pure virtual method called".
> Prior to this message some objects have their garbages successfully
> collected, as can be seen in the following messages:
> 
> 1. OutputManager garbage collecting PHOLD(0,0) for events prior to time 15
> 2. OutputManager garbage collecting PHOLD(0,1) for events prior to time 15
> 3. OutputManager garbage collecting PHOLD(0,2) for events prior to time 15
> 4. OutputManager garbage collecting PHOLD(0,3) for events prior to time 15
> 5. OutputManager garbage collecting PHOLD(0,4) for events prior to time 15
> 6. pure virtual method called
> 
> But the number of successful collections varies from one execution to another.
> 
> According to gdb, the last portion of code executed is line 73 of
> EventFunctors.h (I think):
> 
> class sendTimeLessThanEqual :
>   public std::unary_function<const Event *, bool > {
> public:
>   sendTimeLessThanEqual( const VTime &initCompareTime ) :
>     compareTime( initCompareTime ){}
> 73:  bool operator()( const Event *a ){
>     return a->getSendTime() <= compareTime;
>   }
> private:
>   const VTime &compareTime;
> };
> 
> I cannot see where a pure virtual function, that has not been
> implemented, is being called. Actually, I didn't even understand in
> which situations this message may appear.
> 
> Other relevant information:
> The StateManager is periodic with a period of 0 (values greater than 0
> make the program crash during coasting forward).
> The Matter GVT Manager is configured with a period of 20.
> I'm using two PCs to run the tests.
> 
> The gdb stack:
> 
> #0  0x003f87a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
> #1  0x00bc9e59 in raise () from /lib/tls/libc.so.6
> #2  0x00bcb882 in abort () from /lib/tls/libc.so.6
> #3  0x008f2007 in __cxa_call_unexpected () from /usr/lib/libstdc++.so.5
> #4  0x008f2044 in std::terminate () from /usr/lib/libstdc++.so.5
> #5  0x008f2568 in __cxa_pure_virtual () from /usr/lib/libstdc++.so.5
> #6  0x08088abb in std::find_if<__gnu_cxx::__normal_iterator<Event
> const**, std::vector<Event const*, std::allocator<Event const*> > >,
> sendTimeLessThanEqual> (__first=
>       {<std::iterator<std::random_access_iterator_tag, Event const*,
> int, Event const**, Event const*&>> = {<No data fields>}, _M_current =
> 0x9f62d20}) at EventFunctors.h:73
> #7  0x080889f3 in std::remove_if<__gnu_cxx::__normal_iterator<Event
> const**, std::vector<Event const*, std::allocator<Event const*> > >,
> sendTimeLessThanEqual> () at stl_iterator_base_types.h:160
> #8  0x08088716 in OutputEvents::garbageCollect (this=0x9f5d870,
> gCollectTime=@0x9f5d850) at stl_vector.h:355
> #9  0x080895f1 in OutputManagerImplementationBase::garbageCollect
> (this=0x9f5d1c0,
>     garbageCollectTime=@0x9f5d850, object=0x9f59dd0) at
> warped/OutputManagerImplementationBase.cpp:67
> #10 0x0805b742 in TimeWarpSimulationManager::garbageCollect
> (this=0x9f46af8, garbageCollectTime=@0x9f5d850)
>     at stl_vector.h:501
> #11 0x080598b2 in TimeWarpSimulationManager::executeObjects (this=0x9f46af8)
>     at warped/TimeWarpSimulationManager.cpp:394
> #12 0x08059a62 in TimeWarpSimulationManager::simulate (this=0x9f46af8,
> simulateUntil=@0x9f47cc0)
>     at warped/TimeWarpSimulationManager.cpp:417
> #13 0x0806e669 in Simulation::simulate (this=0x9f47478,
> simulateUntil=@0x9f47cc0) at warped/Simulation.cpp:129
> #14 0x080627da in WarpedMain::main (this=0xfee23370, argc=13,
> argv=0xfee23434) at warped/WarpedMain.cpp:329
> #15 0x08052c5c in main (argc=13, argv=0xfee23434) at phold2/main.cpp:30
> 
> I hope the problem description is comprehensive. Any clue would be very useful.
> 
> Thanks in advance,
> 
> William.
>




More information about the warped-devel mailing list