code-object-registry-unittest.cc 2.46 KB
Newer Older
1 2 3 4
// Copyright 2015 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.

5 6
#include "src/heap/code-object-registry.h"

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
#include "testing/gtest/include/gtest/gtest.h"

namespace v8 {
namespace internal {

TEST(CodeObjectRegistry, RegisterAlreadyExistingObjectsAndContains) {
  CodeObjectRegistry registry;
  const int elements = 10;
  const int offset = 100;
  for (int i = 0; i < elements; i++) {
    registry.RegisterAlreadyExistingCodeObject(i * offset);
  }

  for (int i = 0; i < elements; i++) {
    CHECK(registry.Contains(i * offset));
  }
}

TEST(CodeObjectRegistry, RegisterNewlyAllocatedObjectsAndContains) {
  CodeObjectRegistry registry;
  const int elements = 10;
  const int offset = 100;
  for (int i = 0; i < elements; i++) {
    registry.RegisterNewlyAllocatedCodeObject(i * offset);
  }

  for (int i = 0; i < elements; i++) {
    CHECK(registry.Contains(i * offset));
  }
}

TEST(CodeObjectRegistry, FindAlreadyExistingObjects) {
  CodeObjectRegistry registry;
  const int elements = 10;
  const int offset = 100;
  const int inner = 2;
  for (int i = 1; i <= elements; i++) {
    registry.RegisterAlreadyExistingCodeObject(i * offset);
  }

  for (int i = 1; i <= elements; i++) {
    for (int j = 0; j < inner; j++) {
      CHECK_EQ(registry.GetCodeObjectStartFromInnerAddress(i * offset + j),
               i * offset);
    }
  }
}

TEST(CodeObjectRegistry, FindNewlyAllocatedObjects) {
  CodeObjectRegistry registry;
  const int elements = 10;
  const int offset = 100;
  const int inner = 2;
  for (int i = 1; i <= elements; i++) {
    registry.RegisterNewlyAllocatedCodeObject(i * offset);
  }

  for (int i = 1; i <= elements; i++) {
    for (int j = 0; j < inner; j++) {
      CHECK_EQ(registry.GetCodeObjectStartFromInnerAddress(i * offset + j),
               i * offset);
    }
  }
}

TEST(CodeObjectRegistry, FindAlternatingObjects) {
  CodeObjectRegistry registry;
  const int elements = 10;
  const int offset = 100;
  const int inner = 2;
  for (int i = 1; i <= elements; i++) {
    if (i % 2 == 0) {
      registry.RegisterAlreadyExistingCodeObject(i * offset);
    } else {
      registry.RegisterNewlyAllocatedCodeObject(i * offset);
    }
  }

  for (int i = 1; i <= elements; i++) {
    for (int j = 0; j < inner; j++) {
      CHECK_EQ(registry.GetCodeObjectStartFromInnerAddress(i * offset + j),
               i * offset);
    }
  }
}
}  // namespace internal
}  // namespace v8