Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to implements the GC by using visitor pattern ? #9

Open
xiaoma20082008 opened this issue Dec 31, 2021 · 1 comment
Open

Comments

@xiaoma20082008
Copy link

xiaoma20082008 commented Dec 31, 2021

code maybe like this:

class JavaTypeVisitor;
struct JavaType {
  // ... other fields
  virtual void accept(JavaTypeVisitor* visitor) = 0;
};
struct JavaInt : public JavaType {
  virtual void accept(JavaTypeVisitor* visitor) override;
};

struct JavaLong : public JavaType {
  virtual void accept(JavaTypeVisitor* visitor) override;
};

struct JavaObject : public JavaType {
  virtual void accept(JavaTypeVisitor* visitor) override;
};

// ... other JavaType struct definitions

// visitor
class JavaTypeVisitor {
public:
  virtual void visit(JavaInt* ji) = 0;
  virtual void visit(JavaLong* jl) = 0;
  virtual void visit(JavaObject* jo) = 0;
  // ... visit other JavaTypes
};

// region gc

class GC {
public:
  virtual void gc() = 0;
protected:
  // ... some fields
};

class CMS_GC : public GC, public JavaTypeVisitor {
// ... some implementations
};

class G1_GC : public GC, public JavaTypeVisitor {
// ... some implementations
};

// ... other GC Implementation, eg: zgc

// endregion gc
@y1yang1
Copy link
Contributor

y1yang1 commented Mar 12, 2023

It looks good but may take some effort to do so..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants