00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "typeHandle.h"
00016 #include "typeRegistryNode.h"
00017 #include "atomicAdjust.h"
00018
00019
00020 TypeHandle TypeHandle::_none;
00021
00022 #ifdef HAVE_PYTHON
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 PyObject *TypeHandle::
00037 make(PyObject *classobj) {
00038 return PyObject_CallMethod(classobj, (char *)"getClassType", (char *)"");
00039 }
00040 #endif // HAVE_PYTHON
00041
00042 #ifdef DO_MEMORY_USAGE
00043
00044
00045
00046
00047
00048
00049
00050
00051 int TypeHandle::
00052 get_memory_usage(MemoryClass memory_class) const {
00053 assert((int)memory_class >= 0 && (int)memory_class < (int)MC_limit);
00054 if ((*this) == TypeHandle::none()) {
00055 return 0;
00056 } else {
00057 TypeRegistryNode *rnode = TypeRegistry::ptr()->look_up(*this, NULL);
00058 assert(rnode != (TypeRegistryNode *)NULL);
00059 return (size_t)AtomicAdjust::get(rnode->_memory_usage[memory_class]);
00060 }
00061 }
00062 #endif // DO_MEMORY_USAGE
00063
00064 #ifdef DO_MEMORY_USAGE
00065
00066
00067
00068
00069
00070
00071 void TypeHandle::
00072 inc_memory_usage(MemoryClass memory_class, int size) {
00073 assert((int)memory_class >= 0 && (int)memory_class < (int)MC_limit);
00074 if ((*this) != TypeHandle::none()) {
00075 TypeRegistryNode *rnode = TypeRegistry::ptr()->look_up(*this, NULL);
00076 assert(rnode != (TypeRegistryNode *)NULL);
00077 AtomicAdjust::add(rnode->_memory_usage[memory_class], (AtomicAdjust::Integer)size);
00078
00079 assert(rnode->_memory_usage[memory_class] >= 0);
00080 }
00081 }
00082 #endif // DO_MEMORY_USAGE
00083
00084 #ifdef DO_MEMORY_USAGE
00085
00086
00087
00088
00089
00090
00091 void TypeHandle::
00092 dec_memory_usage(MemoryClass memory_class, int size) {
00093 assert((int)memory_class >= 0 && (int)memory_class < (int)MC_limit);
00094 if ((*this) != TypeHandle::none()) {
00095 TypeRegistryNode *rnode = TypeRegistry::ptr()->look_up(*this, NULL);
00096 assert(rnode != (TypeRegistryNode *)NULL);
00097 AtomicAdjust::add(rnode->_memory_usage[memory_class], -(AtomicAdjust::Integer)size);
00098
00099 assert(rnode->_memory_usage[memory_class] >= 0);
00100 }
00101 }
00102 #endif // DO_MEMORY_USAGE
00103
00104 ostream &
00105 operator << (ostream &out, TypeHandle::MemoryClass mem_class) {
00106 switch (mem_class) {
00107 case TypeHandle::MC_singleton:
00108 return out << "singleton";
00109
00110 case TypeHandle::MC_array:
00111 return out << "array";
00112
00113 case TypeHandle::MC_deleted_chain_active:
00114 return out << "deleted_chain_active";
00115
00116 case TypeHandle::MC_deleted_chain_inactive:
00117 return out << "deleted_chain_inactive";
00118
00119 case TypeHandle::MC_limit:
00120 return out << "limit";
00121 }
00122
00123 return out
00124 << "**invalid TypeHandle::MemoryClass (" << (int)mem_class
00125 << ")**\n";
00126 }