Skip to content

Commit

Permalink
Remove serialization (#805)
Browse files Browse the repository at this point in the history
* Remove all code guarded by SERIALIZATION_DISABLED
* Remove code protected by cap_serialization
* Remove serialize-bin
* Remove serialization classes and their uses
* Simplify Symtab::getObject
    Because serialization doesn't exist, their is only one codepath here
    now.
  • Loading branch information
hainest committed Nov 17, 2020
1 parent a659ef7 commit 392518e
Show file tree
Hide file tree
Showing 36 changed files with 19 additions and 7,337 deletions.
273 changes: 3 additions & 270 deletions common/h/Annotatable.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,11 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "Serialization.h"
#include "util.h"

namespace Dyninst
{


class SerializerBase;
class Serializable;
typedef Serializable * (*ser_func_t) (void *, SerializerBase *, const char *);

#if !defined(SERIALIZATION_DISABLED)
#define serialize_printf serializer_printf
COMMON_EXPORT int serializer_printf(const char *format, ...);
COMMON_EXPORT Serializable * ser_func_wrapper(void *it, SerializerBase *sb, const char *tag);
#endif
COMMON_EXPORT bool annotation_debug_flag();
COMMON_EXPORT int annotatable_printf(const char *format, ...);

Expand All @@ -70,7 +59,6 @@ extern bool void_ptr_cmp_func(void *, void *);

class COMMON_EXPORT AnnotationClassBase
{
friend class Serializable;
private:
static std::vector<AnnotationClassBase *> *annotation_types;
static dyn_hash_map<std::string, AnnotationClassID> *annotation_ids_by_name;
Expand All @@ -80,11 +68,8 @@ class COMMON_EXPORT AnnotationClassBase

protected:

ser_func_t serialize_func;

AnnotationClassBase(std::string n,
anno_cmp_func_t cmp_func_ = NULL,
ser_func_t sf_ = NULL);
anno_cmp_func_t cmp_func_ = NULL);

virtual ~AnnotationClassBase();

Expand All @@ -96,7 +81,6 @@ class COMMON_EXPORT AnnotationClassBase
AnnotationClassID getID() { return id; }
std::string &getName() {return name;}
anno_cmp_func_t getCmpFunc() {return cmp_func;}
ser_func_t getSerializeFunc() {return serialize_func;}
virtual const char *getTypeName() = 0;
virtual void *allocate() = 0;
};
Expand All @@ -106,31 +90,9 @@ class AnnotationClass : public AnnotationClassBase {
public:

AnnotationClass(std::string n,
anno_cmp_func_t cmp_func_ = NULL,
ser_func_t s = NULL) :
AnnotationClassBase(n, cmp_func_, s)
anno_cmp_func_t cmp_func_ = NULL) :
AnnotationClassBase(n, cmp_func_)
{
#if !defined(SERIALIZATION_DISABLED)
if (NULL == s)
{
// if the type is Serializable, use its serialization function
// otherwise, leave it NULL so we don't accidentally dereference
// a random pointer as if it were automatcally descended from
// Serializable
if (boost::is_base_of<Serializable, T>::value)
{
serialize_func = ser_func_wrapper;
} else
if (boost::is_pointer<T>::value)
{
if (boost::is_base_of<Serializable,
typename boost::remove_pointer<T>::type>::value)
{
serialize_func = ser_func_wrapper;
}
}
}
#endif
}

const char *getTypeName() { return typeid(T).name();}
Expand Down Expand Up @@ -168,26 +130,8 @@ typedef enum {

COMMON_EXPORT const char *serPostOp2Str(ser_post_op_t);


class AnnotatableDense;
class AnnotatableSparse;
COMMON_EXPORT bool is_input(SerializerBase *sb);
COMMON_EXPORT bool is_output(SerializerBase *sb);
COMMON_EXPORT unsigned short get_serializer_index(SerializerBase *sb);
COMMON_EXPORT bool ser_operation(SerializerBase *, ser_post_op_t &, const char *);
COMMON_EXPORT bool add_annotations(SerializerBase *, AnnotatableDense *, std::vector<ser_rec_t> &);
COMMON_EXPORT bool add_annotations(SerializerBase *, AnnotatableSparse *, std::vector<ser_rec_t> &);
#if !defined(SERIALIZATION_DISABLED)
COMMON_EXPORT bool serialize_annotation_list(void *, std::vector<ser_rec_t> &, SerializerBase *sb, const char *);
COMMON_EXPORT SerializerBase *getExistingOutputSB(unsigned short);
COMMON_EXPORT bool serialize_post_annotation(void *, void *, SerializerBase *, AnnotationClassBase *acb, sparse_or_dense_anno_t, const char *);
#endif

class COMMON_EXPORT AnnotatableDense
{
friend bool COMMON_EXPORT add_annotations(SerializerBase *, AnnotatableDense *, std::vector<ser_rec_t> &);
friend class SerializerBase;
friend class Serializable;
typedef void *anno_list_t;

/**
Expand All @@ -203,15 +147,10 @@ class COMMON_EXPORT AnnotatableDense
struct aInfo {
anno_map_t *data;
AnnotationClassID max;
unsigned short serializer_index;
};

aInfo *annotations;

// private version of addAnnotation exists for deserialize functions
// to reconstruct annotations without explicit type info -- don't use in
// other contexts

bool addAnnotation(const void *a, AnnotationClassID id)
{
if (annotation_debug_flag())
Expand All @@ -227,7 +166,6 @@ class COMMON_EXPORT AnnotatableDense
{
annotations = (aInfo *) malloc(sizeof(aInfo));
annotations->data = NULL;
annotations->serializer_index = (unsigned short) -1;
}

// can have case where we have allocated annotations struct but not the
Expand Down Expand Up @@ -286,37 +224,6 @@ class COMMON_EXPORT AnnotatableDense
fprintf(stderr, "%s[%d]: failed to add annotation\n", FILE__, __LINE__);
return ret;
}


#if !defined(SERIALIZATION_DISABLED)
// If serialization is not enabled, there will be no serializer specified,
// so none of the below code will be executed.

serialize_printf("%s[%d]: %p addAnnotation: serializer_index = %d\n",
FILE__, __LINE__, this, annotations->serializer_index);

if (annotations && ( (unsigned short) -1 != annotations->serializer_index))
{
SerializerBase *sb = getExistingOutputSB(annotations->serializer_index);
if (!sb)
{
// definitely should have a serializer since we have an index
fprintf(stderr, "%s[%d]: FIXME: no existing serializer!\n", FILE__, __LINE__);
return false;
}
ser_func_t sf = a_id.getSerializeFunc();
if (sf)
{
// FIXME: for xml support, ser_operation should have a corresponding
// "ser_operation_end()" routine to close out the xml field.
ser_post_op_t op = sp_add_anno;
ser_operation(sb, op, "AnnotationAdd");
void * aa = (void *) const_cast<T *>(a);
serialize_post_annotation(this, aa, sb, &a_id, dense, "PostAnnotation");
}
}
#endif

return true;
}

Expand Down Expand Up @@ -365,83 +272,6 @@ class COMMON_EXPORT AnnotatableDense
return true;
}

#if !defined(SERIALIZATION_DISABLED)
void serializeAnnotations(SerializerBase *sb, const char *tag)
{
serialize_printf("%s[%d]: welcome to serializeAnotations:\n", FILE__, __LINE__);
// iterator over possible annotation types
// if we have any, lookup the serialization function and call it

std::vector<ser_rec_t> my_sers;
if (is_output(sb))
{
// need to figure out how many annotations will be serialized apriori
// so we can output the size of the list as a header.
// To avoid iterating over the full list twice, make a local copy
// of all serializations/deserializations that need to be performed
// as we go, and do them in bulk afterwards.

if (annotations)
{
for (AnnotationClassID id = 0; id < annotations->max; ++id)
{
void *anno = annotations->data[id];
if (anno)
{
AnnotationClassBase *acb = AnnotationClassBase::findAnnotationClass(id);

if (!acb)
{
fprintf(stderr, "%s[%d]: FIXME: no annotation class for id %d\n",
FILE__, __LINE__, id);
continue;
}

ser_func_t sf = acb->getSerializeFunc();

if (NULL != sf)
{
ser_rec_t sr;
sr.data = anno;
sr.acb = acb;
sr.parent_id = (void *) this;
sr.sod = dense;
my_sers.push_back(sr);
}
}
}

annotations->serializer_index = get_serializer_index(sb);
serialize_printf("%s[%d]: %p set serializer index to %d\n",
FILE__, __LINE__, this, annotations->serializer_index);
}
else
{
// need to alloc struct to store serializer index
annotations = (aInfo *) malloc(sizeof(aInfo));
annotations->data = NULL;
annotations->max = 0;
annotations->serializer_index = get_serializer_index(sb);
serialize_printf("%s[%d]: %p set serializer index to %d\n",
FILE__, __LINE__, this, annotations->serializer_index);
}
}

if (!serialize_annotation_list(this, my_sers, sb, tag))
{
fprintf(stderr, "%s[%d]: FIXME: failed to serialize annotation list\n",
FILE__, __LINE__);
}
if (!add_annotations(sb, this, my_sers))
{
fprintf(stderr, "%s[%d]: failed to update annotation list after deserialize\n",
FILE__, __LINE__);
}
}
#else
void serializeAnnotations(SerializerBase *, const char *) {
}
#endif
void annotationsReport()
{
std::vector<AnnotationClassBase *> atypes;
Expand Down Expand Up @@ -480,11 +310,6 @@ class COMMON_EXPORT AnnotatableDense

class COMMON_EXPORT AnnotatableSparse
{
friend class SerializerBase;
friend class Serializable;
friend bool COMMON_EXPORT add_annotations(SerializerBase *,
AnnotatableSparse *, std::vector<ser_rec_t> &);

public:
struct void_ptr_hasher
{
Expand Down Expand Up @@ -616,8 +441,6 @@ class COMMON_EXPORT AnnotatableSparse
return target;
}

// private version of addAnnotation used by deserialize function to restore
// annotation set without explicitly specifying types
AN_INLINE bool addAnnotation(const void *a, AnnotationClassID aid)
{
if (annotation_debug_flag())
Expand Down Expand Up @@ -780,33 +603,6 @@ class COMMON_EXPORT AnnotatableSparse

return true;
}

#if !defined(SERIALIZATION_DISABLED)
dyn_hash_map<void *, unsigned short>::iterator seriter;
seriter = ser_ndx_map.find(this);
if (seriter != ser_ndx_map.end())
{
if (seriter->second != (unsigned short) -1)
{
SerializerBase *sb = getExistingOutputSB(seriter->second);
if (!sb)
{
fprintf(stderr, "%s[%d]: FIXME: no existing output SB\n",
FILE__, __LINE__);
return false;
}

ser_func_t sf = a_id.getSerializeFunc();
if (sf)
{
ser_post_op_t op = sp_add_anno;
ser_operation(sb, op, "AnnotationAdd");
void *aa = (void *) const_cast<T *>(a);
serialize_post_annotation(this, aa, sb, &a_id, sparse, "PostAnnotation");
}
}
}
#endif

return true;
}
Expand Down Expand Up @@ -863,69 +659,6 @@ class COMMON_EXPORT AnnotatableSparse
return false;
}

void serializeAnnotations(SerializerBase *sb, const char *)
{
annos_t &l_annos = *getAnnos();
std::vector<ser_rec_t> my_sers;
void *obj = this;
if (is_output(sb))
{
for (AnnotationClassID id = 0; id < l_annos.size(); ++id)
{
annos_by_type_t *abt = getAnnosOfType(id, false /*don't do create */);
if (NULL == abt) continue;

annos_by_type_t::iterator iter = abt->find(obj);

if (iter == abt->end())
{
// fprintf(stderr, "%s[%d]: nothing for this obj\n", FILE__, __LINE__);
continue;
}

// we have an annotation of this type for this object, find the serialization
// function and call it (if it exists)

AnnotationClassBase *acb = AnnotationClassBase::findAnnotationClass(id);
if (!acb)
{
fprintf(stderr, "%s[%d]: FIXME, cannot find annotation class base for id %d, mode = %s\n", FILE__, __LINE__, id, is_input(sb) ? "deserialize" : "serialize");
continue;
}

ser_func_t sf = acb->getSerializeFunc();

if (NULL == sf)
{
continue;
}

ser_rec_t sr;
sr.acb = acb;
sr.data = iter->second;
sr.parent_id = (void *) this;
sr.sod = sparse;
my_sers.push_back(sr);
}

ser_ndx_map[this] = get_serializer_index(sb);
}

#if !defined(SERIALIZATION_DISABLED)
if (!serialize_annotation_list(this, my_sers, sb, tag))
{
fprintf(stderr, "%s[%d]: FIXME: failed to serialize annotation list\n",
FILE__, __LINE__);
}
#endif

if (!add_annotations(sb, this, my_sers))
{
fprintf(stderr, "%s[%d]: failed to update annotation list after deserialize\n",
FILE__, __LINE__);
}
}

void annotationsReport()
{
std::vector<AnnotationClassBase *> atypes;
Expand Down

0 comments on commit 392518e

Please sign in to comment.