mem: Use shared_ptr for Ruby Message classes

This patch transitions the Ruby Message and its derived classes from
the ad-hoc RefCountingPtr to the c++11 shared_ptr. There are no
changes in behaviour, and the code modifications are mainly replacing
"new" with "make_shared".

The cloning of derived messages is slightly changed as they previously
relied on overriding the base-class through covariant return types.
This commit is contained in:
Andreas Hansson 2014-10-16 05:49:49 -04:00
parent acdfcad30d
commit db3739682d
8 changed files with 34 additions and 16 deletions

View file

@ -30,14 +30,14 @@
#define __MEM_RUBY_SLICC_INTERFACE_MESSAGE_HH__ #define __MEM_RUBY_SLICC_INTERFACE_MESSAGE_HH__
#include <iostream> #include <iostream>
#include <memory>
#include "base/refcnt.hh"
#include "mem/packet.hh" #include "mem/packet.hh"
class Message; class Message;
typedef RefCountingPtr<Message> MsgPtr; typedef std::shared_ptr<Message> MsgPtr;
class Message : public RefCounted class Message
{ {
public: public:
Message(Tick curTime) Message(Tick curTime)
@ -54,7 +54,7 @@ class Message : public RefCounted
virtual ~Message() { } virtual ~Message() { }
virtual Message* clone() const = 0; virtual MsgPtr clone() const = 0;
virtual void print(std::ostream& out) const = 0; virtual void print(std::ostream& out) const = 0;
virtual void setIncomingLink(int) {} virtual void setIncomingLink(int) {}
virtual void setVnet(int) {} virtual void setVnet(int) {}

View file

@ -30,13 +30,14 @@
#define __MEM_RUBY_SLICC_INTERFACE_NETWORKMESSAGE_HH__ #define __MEM_RUBY_SLICC_INTERFACE_NETWORKMESSAGE_HH__
#include <iostream> #include <iostream>
#include <memory>
#include "mem/protocol/MessageSizeType.hh" #include "mem/protocol/MessageSizeType.hh"
#include "mem/ruby/common/NetDest.hh" #include "mem/ruby/common/NetDest.hh"
#include "mem/ruby/slicc_interface/Message.hh" #include "mem/ruby/slicc_interface/Message.hh"
class NetworkMessage; class NetworkMessage;
typedef RefCountingPtr<NetworkMessage> NetMsgPtr; typedef std::shared_ptr<NetworkMessage> NetMsgPtr;
class NetworkMessage : public Message class NetworkMessage : public Message
{ {

View file

@ -71,7 +71,8 @@ class RubyRequest : public Message
} }
RubyRequest(Tick curTime) : Message(curTime) {} RubyRequest(Tick curTime) : Message(curTime) {}
RubyRequest* clone() const { return new RubyRequest(*this); } MsgPtr clone() const
{ return std::shared_ptr<Message>(new RubyRequest(*this)); }
const Address& getLineAddress() const { return m_LineAddress; } const Address& getLineAddress() const { return m_LineAddress; }
const Address& getPhysicalAddress() const { return m_PhysicalAddress; } const Address& getPhysicalAddress() const { return m_PhysicalAddress; }

View file

@ -26,6 +26,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <memory>
#include "debug/RubyDma.hh" #include "debug/RubyDma.hh"
#include "debug/RubyStats.hh" #include "debug/RubyStats.hh"
#include "mem/protocol/SequencerMsg.hh" #include "mem/protocol/SequencerMsg.hh"
@ -69,7 +71,8 @@ DMASequencer::makeRequest(PacketPtr pkt)
active_request.bytes_issued = 0; active_request.bytes_issued = 0;
active_request.pkt = pkt; active_request.pkt = pkt;
SequencerMsg *msg = new SequencerMsg(clockEdge()); std::shared_ptr<SequencerMsg> msg =
std::make_shared<SequencerMsg>(clockEdge());
msg->getPhysicalAddress() = Address(paddr); msg->getPhysicalAddress() = Address(paddr);
msg->getLineAddress() = line_address(msg->getPhysicalAddress()); msg->getLineAddress() = line_address(msg->getPhysicalAddress());
msg->getType() = write ? SequencerRequestType_ST : SequencerRequestType_LD; msg->getType() = write ? SequencerRequestType_ST : SequencerRequestType_LD;
@ -107,7 +110,8 @@ DMASequencer::issueNext()
return; return;
} }
SequencerMsg *msg = new SequencerMsg(clockEdge()); std::shared_ptr<SequencerMsg> msg =
std::make_shared<SequencerMsg>(clockEdge());
msg->getPhysicalAddress() = Address(active_request.start_paddr + msg->getPhysicalAddress() = Address(active_request.start_paddr +
active_request.bytes_completed); active_request.bytes_completed);

View file

@ -30,6 +30,7 @@
#define __MEM_RUBY_SYSTEM_DMASEQUENCER_HH__ #define __MEM_RUBY_SYSTEM_DMASEQUENCER_HH__
#include <ostream> #include <ostream>
#include <memory>
#include "mem/protocol/DMASequencerRequestType.hh" #include "mem/protocol/DMASequencerRequestType.hh"
#include "mem/ruby/common/DataBlock.hh" #include "mem/ruby/common/DataBlock.hh"

View file

@ -679,7 +679,8 @@ Sequencer::issueRequest(PacketPtr pkt, RubyRequestType secondary_type)
pc = pkt->req->getPC(); pc = pkt->req->getPC();
} }
RubyRequest *msg = new RubyRequest(clockEdge(), pkt->getAddr(), std::shared_ptr<RubyRequest> msg =
std::make_shared<RubyRequest>(clockEdge(), pkt->getAddr(),
pkt->getPtr<uint8_t>(true), pkt->getPtr<uint8_t>(true),
pkt->getSize(), pc, secondary_type, pkt->getSize(), pc, secondary_type,
RubyAccessMode_Supervisor, pkt, RubyAccessMode_Supervisor, pkt,

View file

@ -54,8 +54,8 @@ class EnqueueStatementAST(StatementAST):
self.symtab.newSymbol(v) self.symtab.newSymbol(v)
# Declare message # Declare message
code("${{msg_type.ident}} *out_msg = "\ code("std::shared_ptr<${{msg_type.ident}}> out_msg = "\
"new ${{msg_type.ident}}(clockEdge());") "std::make_shared<${{msg_type.ident}}>(clockEdge());")
# The other statements # The other statements
t = self.statements.generate(code, None) t = self.statements.generate(code, None)

View file

@ -283,6 +283,15 @@ $klass ${{self.c_ident}}$parent
code('}') code('}')
# create a clone member # create a clone member
if self.isMessage:
code('''
MsgPtr
clone() const
{
return std::shared_ptr<Message>(new ${{self.c_ident}}(*this));
}
''')
else:
code(''' code('''
${{self.c_ident}}* ${{self.c_ident}}*
clone() const clone() const
@ -391,6 +400,7 @@ operator<<(std::ostream& out, const ${{self.c_ident}}& obj)
*/ */
#include <iostream> #include <iostream>
#include <memory>
#include "mem/protocol/${{self.c_ident}}.hh" #include "mem/protocol/${{self.c_ident}}.hh"
#include "mem/ruby/common/Global.hh" #include "mem/ruby/common/Global.hh"