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