chromium/third_party/blink/renderer/platform/heap/BUILD.gn

# Copyright 2014 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/buildflag_header.gni")
import("//build/config/compiler/compiler.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//testing/test.gni")
import("//third_party/blink/public/public_features.gni")
import("//third_party/blink/renderer/platform/platform.gni")
import("//v8/gni/v8.gni")

declare_args() {
  # Whether the blink heap code is compiled into a shared library.
  # Embedders like CEF use this flag to include blink in a shared library under
  # non-component build.
  blink_heap_inside_shared_library = is_component_build
}

assert(blink_heap_inside_shared_library || !is_component_build,
       "blink_heap_inside_shared_library can not be false in component build.")

buildflag_header("blink_heap_buildflags") {
  header = "heap_buildflags.h"
  header_dir = "third_party/blink/renderer/platform/heap"

  flags = [
    "VERBOSE_PERSISTENT=$cppgc_enable_object_names",
    "BLINK_HEAP_INSIDE_SHARED_LIBRARY=$blink_heap_inside_shared_library",
  ]
}

blink_platform_sources("heap") {
  sources = [
    "blink_gc_memory_dump_provider.cc",
    "blink_gc_memory_dump_provider.h",
    "collection_support/clear_collection_scope.h",
    "collection_support/heap_deque.h",
    "collection_support/heap_hash_counted_set.h",
    "collection_support/heap_hash_map.h",
    "collection_support/heap_hash_set.h",
    "collection_support/heap_hash_table_backing.h",
    "collection_support/heap_linked_hash_set.h",
    "collection_support/heap_linked_stack.h",
    "collection_support/heap_vector.h",
    "collection_support/heap_vector_backing.h",
    "cross_thread_handle.h",
    "cross_thread_handle_internal.h",
    "cross_thread_persistent.h",
    "custom_spaces.cc",
    "custom_spaces.h",
    "disallow_new_wrapper.h",
    "forward.h",
    "garbage_collected.h",
    "heap_allocator_impl.h",
    "heap_barrier_callback.h",
    "heap_traits.h",
    "member.h",
    "persistent.h",
    "prefinalizer.h",
    "process_heap.cc",
    "process_heap.h",
    "self_keep_alive.h",
    "thread_local.h",
    "thread_state.cc",
    "thread_state.h",
    "thread_state_scopes.h",
    "thread_state_storage.cc",
    "thread_state_storage.h",
    "trace_traits.h",
    "visitor.h",
    "weak_cell.h",
    "write_barrier.h",
  ]

  deps = [
    ":blink_heap_buildflags",
    "//base",
    "//gin:gin",
    "//third_party/blink/renderer/platform:make_platform_generated",
    "//third_party/icu",

    # Dependency on V8 which transitively depends on cppgc but exposes
    # JS-related C++ heap through V8's Isolate.
    "//v8",
  ]

  if (!is_debug && !optimize_for_size) {
    configs -= [ "//build/config/compiler:default_optimization" ]
    configs += [ "//build/config/compiler:optimize_max" ]
  } else if (using_mismatched_sample_profile) {
    configs -= [ "//build/config/compiler:afdo_optimize_size" ]
  }

  visibility = [
    "//third_party/blink/renderer/platform:platform",
    "//third_party/blink/renderer/platform/instrumentation:instrumentation",
    "//third_party/blink/renderer/platform/loader:loader",
    "//third_party/blink/renderer/platform/scheduler:scheduler",
  ]
}

source_set("test_support") {
  testonly = true

  sources = [
    "heap_test_objects.cc",
    "heap_test_objects.h",
    "heap_test_platform.h",
    "heap_test_utilities.cc",
    "heap_test_utilities.h",
  ]

  deps = [
    ":blink_heap_buildflags",
    "//testing/gtest",
    "//third_party/blink/public/mojom:mojom_platform_blink_headers",
    "//third_party/blink/renderer/platform:bindings_buildflags",
    "//third_party/blink/renderer/platform:platform",
  ]

  # TODO(v8:11952): Switch to `//v8:v8_for_testing` as target once it properly
  # depends on v8 without duplicating the whole library which causes ODR
  # violations when `//v8:v8` is also pulled in otherwise.
  deps += [ "//v8:v8" ]

  public_deps = [ "//base/test:test_support" ]
}

test("blink_heap_unittests") {
  deps = [ ":blink_heap_unittests_sources" ]

  if (is_android) {
    deps += [
      "//content/shell/android:content_shell_assets",
      "//net/android:net_java",
      "//ui/android:ui_full_java",
    ]
  }

  if (is_fuchsia) {
    additional_manifest_fragments = [
      "//build/config/fuchsia/test/test_fonts.shard.test-cml",

      # Oilpan reuses V8's v8::PageAllocator which generally requires JIT
      # permissions.
      "//build/config/fuchsia/test/mark_vmo_executable.shard.test-cml",
    ]
  }
}

source_set("blink_heap_unittests_sources") {
  testonly = true

  sources = [
    "../testing/run_all_tests.cc",
    "test/blink_gc_memory_dump_provider_test.cc",
    "test/concurrent_marking_test.cc",
    "test/cross_thread_handle_test.cc",
    "test/heap_compact_test.cc",
    "test/heap_linked_stack_test.cc",
    "test/heap_test.cc",
    "test/heap_traits_test.cc",
    "test/incremental_marking_test.cc",
    "test/persistent_test.cc",
    "test/weak_cell_test.cc",
    "test/weakness_marking_test.cc",
  ]

  if (cppgc_enable_young_generation) {
    sources += [ "test/minor_gc_test.cc" ]
  }

  configs += [
    "//third_party/blink/renderer/platform/wtf:wtf_config",
    "//third_party/blink/renderer:config",
    "//third_party/blink/renderer:inside_blink",
  ]

  deps = [
    ":test_support",
    "//base",
    "//base/test:test_support",
    "//gin:gin",
    "//mojo/core/embedder:embedder",
    "//skia:test_fonts",
    "//testing/gmock",
    "//testing/gtest",
    "//third_party/blink/renderer/platform:test_support",
    "//third_party/blink/renderer/platform/wtf",
  ]
}

test("blink_heap_perftests") {
  configs += [ "//build/config/compiler:thinlto_optimize_max" ]

  deps = [ ":blink_heap_perftests_sources" ]

  if (is_android) {
    deps += [
      "//content/shell/android:content_shell_assets",
      "//net/android:net_java",
      "//ui/android:ui_full_java",
    ]
  }

  if (is_fuchsia) {
    # Oilpan reuses V8's v8::PageAllocator which generally requires JIT
    # permissions.
    additional_manifest_fragments =
        [ "//build/config/fuchsia/test/mark_vmo_executable.shard.test-cml" ]
  }
}

source_set("blink_heap_perftests_sources") {
  testonly = true

  sources = [
    "../testing/blink_perf_test_suite.cc",
    "../testing/blink_perf_test_suite.h",
    "../testing/run_all_perf_tests.cc",
    "test/allocation_perftest.cc",
    "test/write_barrier_perftest.cc",
  ]

  configs += [
    "//third_party/blink/renderer/platform/wtf:wtf_config",
    "//third_party/blink/renderer:config",
    "//third_party/blink/renderer:inside_blink",
  ]

  deps = [
    "//gin:gin",
    "//testing/gtest",
    "//testing/perf",
    "//third_party/blink/renderer/platform:test_support",
    "//third_party/blink/renderer/platform/wtf",
  ]
}