TracingStatus.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef TOOLS_BLINK_GC_PLUGIN_TRACING_STATUS_H_
  5. #define TOOLS_BLINK_GC_PLUGIN_TRACING_STATUS_H_
  6. // TracingStatus is a four-point value ordered by
  7. // illegal < unneeded < unknown < needed
  8. //
  9. // It is used to categorize tracing of fields:
  10. //
  11. // * illegal field is invalid/illegal to trace.
  12. // * unneeded field has type with no traceable fields of its own;
  13. // it may have an empty trace() method. Not harmful
  14. // to trace, but not needed.
  15. // * unknown initial TracingStatus value.
  16. // * needed field is a heap reference or an object containing
  17. // traceable fields.
  18. //
  19. // Tracing status |illegal| is considered an error; treating |unneeded| also
  20. // as an error would detect and report unnecessary tracing of objects that
  21. // probably don't need to be on the Blink GC heap. However, template use
  22. // and instantiation can leave us with classes that do have empty trace
  23. // methods and no traceable fields -- reporting these as errors/warnings
  24. // wouldn't work. Hence, only consider |illegal| as an error TracingStatus
  25. // state.
  26. class TracingStatus {
  27. public:
  28. static TracingStatus Illegal() { return kIllegal; }
  29. static TracingStatus Unneeded() { return kUnneeded; }
  30. static TracingStatus Unknown() { return kUnknown; }
  31. static TracingStatus Needed() { return kNeeded; }
  32. bool IsIllegal() const { return status_ == kIllegal; }
  33. bool IsUnneeded() const { return status_ == kUnneeded; }
  34. bool IsUnknown() const { return status_ == kUnknown; }
  35. bool IsNeeded() const { return status_ == kNeeded; }
  36. TracingStatus LUB(const TracingStatus& other) const {
  37. return status_ > other.status_ ? status_ : other.status_;
  38. }
  39. bool operator==(const TracingStatus& other) const {
  40. return status_ == other.status_;
  41. }
  42. private:
  43. enum Status { kIllegal, kUnneeded, kUnknown, kNeeded };
  44. TracingStatus(Status status) : status_(status) {}
  45. Status status_;
  46. };
  47. #endif // TOOLS_BLINK_GC_PLUGIN_TRACING_STATUS_H_