summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp')
-rw-r--r--cpp/include/Ice/GCShared.h15
-rw-r--r--cpp/include/Ice/Object.h21
-rw-r--r--cpp/include/Ice/ObjectF.h5
-rw-r--r--cpp/src/Ice/GC.cpp56
-rw-r--r--cpp/src/Ice/Object.cpp2
-rw-r--r--cpp/src/slice2cpp/Gen.cpp22
6 files changed, 36 insertions, 85 deletions
diff --git a/cpp/include/Ice/GCShared.h b/cpp/include/Ice/GCShared.h
index b53f628eded..63909ac8868 100644
--- a/cpp/include/Ice/GCShared.h
+++ b/cpp/include/Ice/GCShared.h
@@ -30,11 +30,8 @@ public:
return *this;
}
- virtual void __incRef(); // First derived class with class data members overrides this.
- virtual void __decRef(); // Ditto.
- virtual void __addObject(GCCountMap&) {} // Ditto.
- virtual bool __usesClasses() { return false; } // Ditto.
-
+ virtual void __incRef();
+ virtual void __decRef();
virtual int __getRef() const;
virtual void __setNoDelete(bool);
@@ -46,16 +43,8 @@ public:
return _ref;
}
- void __decRefUnsafe()
- {
- --_ref;
- }
-
protected:
- void __gcIncRef();
- void __gcDecRef();
-
friend class IceInternal::GC; // Allows IceInternal::GC to read value of _ref.
};
diff --git a/cpp/include/Ice/Object.h b/cpp/include/Ice/Object.h
index 325ffa35ba3..ca0886b85e1 100644
--- a/cpp/include/Ice/Object.h
+++ b/cpp/include/Ice/Object.h
@@ -58,16 +58,7 @@ public:
virtual const Current& getCurrent() = 0;
};
-//
-// We should not need virtual inheritance here since Object is the only class
-// that derives from GCShared. However, Visual C++ seems to generate bad code
-// without 'virtual'. This needs to be investigated further.
-//
-#ifdef _MSC_VER
-class ICE_API Object : public virtual IceInternal::GCShared
-#else
-class ICE_API Object : public IceInternal::GCShared
-#endif
+class ICE_API Object : virtual public IceUtil::Shared
{
public:
@@ -113,8 +104,14 @@ public:
virtual void __write(const OutputStreamPtr&) const;
virtual void __read(const InputStreamPtr&, bool);
- virtual void __gcReachable(IceInternal::GCCountMap&) const {}
- virtual void __gcClear() {}
+ // Virtual methods to support garbage collection of Slice class instances. These
+ // methods are overriden by Slice classes which can have cycles.
+ virtual void __addObject(IceInternal::GCCountMap&) {}
+ virtual bool __usesClasses() { return false; }
+ void __decRefUnsafe()
+ {
+ --_ref;
+ }
protected:
diff --git a/cpp/include/Ice/ObjectF.h b/cpp/include/Ice/ObjectF.h
index 1d83231b4a2..a3d461a10d2 100644
--- a/cpp/include/Ice/ObjectF.h
+++ b/cpp/include/Ice/ObjectF.h
@@ -10,9 +10,8 @@
#ifndef ICE_OBJECT_F_H
#define ICE_OBJECT_F_H
+#include <IceUtil/Shared.h>
#include <Ice/Handle.h>
-#include <Ice/GCCountMap.h>
-#include <Ice/GCShared.h>
namespace Ice
{
@@ -24,7 +23,7 @@ class Object;
namespace IceInternal
{
-ICE_API GCShared* upCast(::Ice::Object*);
+ICE_API IceUtil::Shared* upCast(::Ice::Object*);
}
diff --git a/cpp/src/Ice/GC.cpp b/cpp/src/Ice/GC.cpp
index 40372534131..83b282c9473 100644
--- a/cpp/src/Ice/GC.cpp
+++ b/cpp/src/Ice/GC.cpp
@@ -78,52 +78,11 @@ using namespace IceInternal;
//
// GCShared
//
-
void
IceInternal::GCShared::__incRef()
{
IceUtilInternal::MutexPtrLock<IceUtil::RecMutex> lock(gcRecMutex);
assert(_ref >= 0);
- ++_ref;
-}
-
-void
-IceInternal::GCShared::__decRef()
-{
- IceUtilInternal::MutexPtrLock<IceUtil::RecMutex> lock(gcRecMutex);
- bool doDelete = false;
- assert(_ref > 0);
- if(--_ref == 0)
- {
- doDelete = !_noDelete;
- _noDelete = true;
- }
- lock.release();
- if(doDelete)
- {
- delete this;
- }
-}
-
-int
-IceInternal::GCShared::__getRef() const
-{
- IceUtilInternal::MutexPtrLock<IceUtil::RecMutex> lock(gcRecMutex);
- return _ref;
-}
-
-void
-IceInternal::GCShared::__setNoDelete(bool b)
-{
- IceUtilInternal::MutexPtrLock<IceUtil::RecMutex> lock(gcRecMutex);
- _noDelete = b;
-}
-
-void
-IceInternal::GCShared::__gcIncRef()
-{
- IceUtilInternal::MutexPtrLock<IceUtil::RecMutex> lock(gcRecMutex);
- assert(_ref >= 0);
if(_ref == 0 && gcObjects != 0)
{
#ifdef NDEBUG // To avoid annoying warnings about variables that are not used...
@@ -137,7 +96,7 @@ IceInternal::GCShared::__gcIncRef()
}
void
-IceInternal::GCShared::__gcDecRef()
+IceInternal::GCShared::__decRef()
{
IceUtilInternal::MutexPtrLock<IceUtil::RecMutex> lock(gcRecMutex);
bool doDelete = false;
@@ -160,6 +119,19 @@ IceInternal::GCShared::__gcDecRef()
}
}
+int
+IceInternal::GCShared::__getRef() const
+{
+ IceUtilInternal::MutexPtrLock<IceUtil::RecMutex> lock(gcRecMutex);
+ return _ref;
+}
+
+void
+IceInternal::GCShared::__setNoDelete(bool b)
+{
+ IceUtilInternal::MutexPtrLock<IceUtil::RecMutex> lock(gcRecMutex);
+ _noDelete = b;
+}
//
// GC
diff --git a/cpp/src/Ice/Object.cpp b/cpp/src/Ice/Object.cpp
index 0d102ae1a63..0fd4c42c0a1 100644
--- a/cpp/src/Ice/Object.cpp
+++ b/cpp/src/Ice/Object.cpp
@@ -19,7 +19,7 @@ using namespace std;
using namespace Ice;
using namespace IceInternal;
-IceInternal::GCShared* IceInternal::upCast(Object* p) { return p; }
+IceUtil::Shared* IceInternal::upCast(Object* p) { return p; }
bool
Ice::Object::operator==(const Object& r) const
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 6822f587487..3533a2a790b 100644
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -3822,6 +3822,14 @@ Slice::Gen::ObjectVisitor::visitClassDefStart(const ClassDefPtr& p)
}
}
}
+
+ bool hasBaseClass = !bases.empty() && !bases.front()->isInterface();
+ bool override = p->canBeCyclic() && (!hasBaseClass || !bases.front()->canBeCyclic());
+ if(override)
+ {
+ H << ", private IceInternal::GCShared";
+ }
+
H.restoreIndent();
H << sb;
H.dec();
@@ -4827,20 +4835,6 @@ Slice::Gen::ObjectVisitor::emitGCFunctions(const ClassDefPtr& p)
if(override)
{
- H << nl << "virtual void __incRef();";
-
- C << sp << nl << "void" << nl << scoped.substr(2) << "::__incRef()";
- C << sb;
- C << nl << "__gcIncRef();";
- C << eb;
-
- H << nl << "virtual void __decRef();";
-
- C << sp << nl << "void" << nl << scoped.substr(2) << "::__decRef()";
- C << sb;
- C << nl << "__gcDecRef();";
- C << eb;
-
H << nl << "virtual void __addObject(::IceInternal::GCCountMap&);";
C << sp << nl << "void" << nl << scoped.substr(2) << "::__addObject(::IceInternal::GCCountMap& _c)";