mem: Use shared_ptr for Ruby Message classes
authorAndreas Hansson <andreas.hansson@arm.com>
Thu, 16 Oct 2014 09:49:49 +0000 (05:49 -0400)
committerAndreas Hansson <andreas.hansson@arm.com>
Thu, 16 Oct 2014 09:49:49 +0000 (05:49 -0400)
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.

src/mem/ruby/slicc_interface/Message.hh
src/mem/ruby/slicc_interface/NetworkMessage.hh
src/mem/ruby/slicc_interface/RubyRequest.hh
src/mem/ruby/system/DMASequencer.cc
src/mem/ruby/system/DMASequencer.hh
src/mem/ruby/system/Sequencer.cc
src/mem/slicc/ast/EnqueueStatementAST.py
src/mem/slicc/symbols/Type.py

index 1c842ae691995a02f31f5dfb0d3c0d6ffe025d84..786c656bcb299258fced464c5e777704408be618 100644 (file)
 #define __MEM_RUBY_SLICC_INTERFACE_MESSAGE_HH__
 
 #include <iostream>
+#include <memory>
 
-#include "base/refcnt.hh"
 #include "mem/packet.hh"
 
 class Message;
-typedef RefCountingPtr<Message> MsgPtr;
+typedef std::shared_ptr<Message> MsgPtr;
 
-class Message : public RefCounted
+class Message
 {
   public:
     Message(Tick curTime)
@@ -54,7 +54,7 @@ class Message : public RefCounted
 
     virtual ~Message() { }
 
-    virtual Message* clone() const = 0;
+    virtual MsgPtr clone() const = 0;
     virtual void print(std::ostream& out) const = 0;
     virtual void setIncomingLink(int) {}
     virtual void setVnet(int) {}
index 10d78251aac9aa0628ef950422747fbe6e53b100..1b5edcfcd0c6993b9ebdd64fb04f1b9b76c893c1 100644 (file)
 #define __MEM_RUBY_SLICC_INTERFACE_NETWORKMESSAGE_HH__
 
 #include <iostream>
+#include <memory>
 
 #include "mem/protocol/MessageSizeType.hh"
 #include "mem/ruby/common/NetDest.hh"
 #include "mem/ruby/slicc_interface/Message.hh"
 
 class NetworkMessage;
-typedef RefCountingPtr<NetworkMessage> NetMsgPtr;
+typedef std::shared_ptr<NetworkMessage> NetMsgPtr;
 
 class NetworkMessage : public Message
 {
index 49964ebb92cd122e4acfc10c918f7ddfa5419ec9..357eddbb537fdfe90c2fe207c03d4c49ff096bd3 100644 (file)
@@ -71,7 +71,8 @@ class RubyRequest : public Message
     }
 
     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& getPhysicalAddress() const { return m_PhysicalAddress; }
index 9b0157b45336d3f73fc23af6fa10fdee35ea80b7..2a458a4085b8f86724da7c2ef34812ae0aa66bf8 100644 (file)
@@ -26,6 +26,8 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <memory>
+
 #include "debug/RubyDma.hh"
 #include "debug/RubyStats.hh"
 #include "mem/protocol/SequencerMsg.hh"
@@ -69,7 +71,8 @@ DMASequencer::makeRequest(PacketPtr pkt)
     active_request.bytes_issued = 0;
     active_request.pkt = pkt;
 
-    SequencerMsg *msg = new SequencerMsg(clockEdge());
+    std::shared_ptr<SequencerMsg> msg =
+        std::make_shared<SequencerMsg>(clockEdge());
     msg->getPhysicalAddress() = Address(paddr);
     msg->getLineAddress() = line_address(msg->getPhysicalAddress());
     msg->getType() = write ? SequencerRequestType_ST : SequencerRequestType_LD;
@@ -107,7 +110,8 @@ DMASequencer::issueNext()
         return;
     }
 
-    SequencerMsg *msg = new SequencerMsg(clockEdge());
+    std::shared_ptr<SequencerMsg> msg =
+        std::make_shared<SequencerMsg>(clockEdge());
     msg->getPhysicalAddress() = Address(active_request.start_paddr +
                                        active_request.bytes_completed);
 
index b3ba0be8c2e10a5cab05f21febc82e373aeb6052..13d79182d4caf580ad005d03d9cc1ff252bdbefa 100644 (file)
@@ -30,6 +30,7 @@
 #define __MEM_RUBY_SYSTEM_DMASEQUENCER_HH__
 
 #include <ostream>
+#include <memory>
 
 #include "mem/protocol/DMASequencerRequestType.hh"
 #include "mem/ruby/common/DataBlock.hh"
index dcdaf6a6f775042ef6ebcac6e0897fbbc709d891..bd82d946889777e1efa9aa65d239d2d9bba349b6 100644 (file)
@@ -679,11 +679,12 @@ Sequencer::issueRequest(PacketPtr pkt, RubyRequestType secondary_type)
         pc = pkt->req->getPC();
     }
 
-    RubyRequest *msg = new RubyRequest(clockEdge(), pkt->getAddr(),
-                                       pkt->getPtr<uint8_t>(true),
-                                       pkt->getSize(), pc, secondary_type,
-                                       RubyAccessMode_Supervisor, pkt,
-                                       PrefetchBit_No, proc_id);
+    std::shared_ptr<RubyRequest> msg =
+        std::make_shared<RubyRequest>(clockEdge(), pkt->getAddr(),
+                                      pkt->getPtr<uint8_t>(true),
+                                      pkt->getSize(), pc, secondary_type,
+                                      RubyAccessMode_Supervisor, pkt,
+                                      PrefetchBit_No, proc_id);
 
     DPRINTFR(ProtocolTrace, "%15s %3s %10s%20s %6s>%-6s %s %s\n",
             curTick(), m_version, "Seq", "Begin", "", "",
index c4f2ac06c6407f059e9328f086d90d451c6c645b..e08e498087ab4ac3d84ed6c8a07a76428a825712 100644 (file)
@@ -54,8 +54,8 @@ class EnqueueStatementAST(StatementAST):
         self.symtab.newSymbol(v)
 
         # Declare message
-        code("${{msg_type.ident}} *out_msg = "\
-             "new ${{msg_type.ident}}(clockEdge());")
+        code("std::shared_ptr<${{msg_type.ident}}> out_msg = "\
+             "std::make_shared<${{msg_type.ident}}>(clockEdge());")
 
         # The other statements
         t = self.statements.generate(code, None)
index d9bd85c0184c847264ea3d00e94f96e26064339e..2afd9958cba8598904620a663ee7ce63456e050d 100644 (file)
@@ -283,7 +283,16 @@ $klass ${{self.c_ident}}$parent
             code('}')
 
         # create a clone member
-        code('''
+        if self.isMessage:
+            code('''
+MsgPtr
+clone() const
+{
+     return std::shared_ptr<Message>(new ${{self.c_ident}}(*this));
+}
+''')
+        else:
+            code('''
 ${{self.c_ident}}*
 clone() const
 {
@@ -391,6 +400,7 @@ operator<<(std::ostream& out, const ${{self.c_ident}}& obj)
  */
 
 #include <iostream>
+#include <memory>
 
 #include "mem/protocol/${{self.c_ident}}.hh"
 #include "mem/ruby/common/Global.hh"