protectors.cc 2.55 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/execution/protectors.h"

#include "src/execution/isolate-inl.h"
#include "src/execution/protectors-inl.h"
#include "src/handles/handles-inl.h"
#include "src/objects/contexts.h"
#include "src/objects/property-cell.h"
#include "src/objects/smi.h"
#include "src/tracing/trace-event.h"
#include "src/utils/utils.h"

namespace v8 {
namespace internal {

19
namespace {
20

21 22 23 24 25 26 27 28 29
void TraceProtectorInvalidation(const char* protector_name) {
  DCHECK(FLAG_trace_protector_invalidation);
  static constexpr char kInvalidateProtectorTracingCategory[] =
      "V8.InvalidateProtector";
  static constexpr char kInvalidateProtectorTracingArg[] = "protector-name";

  DCHECK(FLAG_trace_protector_invalidation);

  // TODO(jgruber): Remove the PrintF once tracing can output to stdout.
30
  i::PrintF("Invalidating protector cell %s\n", protector_name);
31 32 33 34
  TRACE_EVENT_INSTANT1("v8", kInvalidateProtectorTracingCategory,
                       TRACE_EVENT_SCOPE_THREAD, kInvalidateProtectorTracingArg,
                       protector_name);
}
35 36 37 38 39 40 41 42 43 44 45

// Static asserts to ensure we have a use counter for every protector. If this
// fails, add the use counter in V8 and chromium. Note: IsDefined is not
// strictly needed but clarifies the intent of the static assert.
constexpr bool IsDefined(v8::Isolate::UseCounterFeature) { return true; }
#define V(Name, ...) \
  STATIC_ASSERT(IsDefined(v8::Isolate::kInvalidated##Name##Protector));

DECLARED_PROTECTORS_ON_ISOLATE(V)
#undef V

46 47
}  // namespace

48 49 50 51
#define INVALIDATE_PROTECTOR_ON_ISOLATE_DEFINITION(name, unused_index, cell) \
  void Protectors::Invalidate##name(Isolate* isolate) {                      \
    DCHECK(isolate->factory()->cell()->value().IsSmi());                     \
    DCHECK(Is##name##Intact(isolate));                                       \
52 53 54
    if (FLAG_trace_protector_invalidation) {                                 \
      TraceProtectorInvalidation(#name);                                     \
    }                                                                        \
55
    isolate->CountUsage(v8::Isolate::kInvalidated##name##Protector);         \
56
    isolate->factory()->cell()->InvalidateProtector();                       \
57 58 59 60
    DCHECK(!Is##name##Intact(isolate));                                      \
  }
DECLARED_PROTECTORS_ON_ISOLATE(INVALIDATE_PROTECTOR_ON_ISOLATE_DEFINITION)
#undef INVALIDATE_PROTECTOR_ON_ISOLATE_DEFINITION
61 62 63

}  // namespace internal
}  // namespace v8